about summary refs log tree commit diff
path: root/tvix/eval/src/observer.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-04T20·16+0300
committertazjin <tazjin@tvl.su>2022-09-10T21·57+0000
commit2e018a50a74040d8db5c0dfeae5f829a5c7c0cf2 (patch)
treeda42791a36627e16f403b2434b13ec8b408134bd /tvix/eval/src/observer.rs
parent6deaa0d6cef081ea9399918611ba57142f7255b5 (diff)
feat(tvix/eval): implement OpTailCall r/4783
If the last operation within a chunk is a function call, the call can
be executed in the same call frame without increasing the depth of the
call stack.

To enable this, a new OpTailCall instruction (similar to OpCall) is
introduced, but not yet emitted by the compiler.

Change-Id: I9ffbd7da6d2d6a8ec7a724646435dc6ee89712f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6457
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/observer.rs')
-rw-r--r--tvix/eval/src/observer.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs
index 677c3f0811..8dc2a6a0ca 100644
--- a/tvix/eval/src/observer.rs
+++ b/tvix/eval/src/observer.rs
@@ -41,6 +41,10 @@ pub trait Observer {
     /// Called when the runtime exits a call frame.
     fn observe_exit_frame(&mut self, _frame_at: usize) {}
 
+    /// Called when the runtime replaces the current call frame for a
+    /// tail call.
+    fn observe_tail_call(&mut self, _frame_at: usize, _: &Rc<Lambda>) {}
+
     /// Called when the runtime enters a builtin.
     fn observe_enter_builtin(&mut self, _name: &'static str) {}
 
@@ -150,6 +154,14 @@ impl<W: Write> Observer for TracingObserver<W> {
         let _ = writeln!(&mut self.writer, "=== exiting builtin {} ===", name);
     }
 
+    fn observe_tail_call(&mut self, frame_at: usize, lambda: &Rc<Lambda>) {
+        let _ = writeln!(
+            &mut self.writer,
+            "=== tail-calling {:p} in frame[{}] ===",
+            lambda, frame_at
+        );
+    }
+
     fn observe_execute_op(&mut self, ip: usize, op: &OpCode, stack: &[Value]) {
         let _ = write!(&mut self.writer, "{:04} {:?}\t[ ", ip, op);