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-04T16·38+0300
committertazjin <tazjin@tvl.su>2022-09-09T21·10+0000
commit14ff889d607635083a030fc73d76b0263759be83 (patch)
tree42b84f7ea79a51ffe64b033ef105e6f04738733e /tvix/eval/src/observer.rs
parentcbf2d2d29293af56d60fa7e04ee1969c18b9845f (diff)
feat(tvix/eval): implement runtime tracing methods for Observer r/4778
These methods make it possible to trace the runtime execution of the
VM through an observer.

Change-Id: I90e26853ba2fe44748613e7f761ed5c1c5fc9ff7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6452
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/observer.rs')
-rw-r--r--tvix/eval/src/observer.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs
index 62312a74ad36..427fc2c3996a 100644
--- a/tvix/eval/src/observer.rs
+++ b/tvix/eval/src/observer.rs
@@ -10,8 +10,9 @@ use std::rc::Rc;
 use tabwriter::TabWriter;
 
 use crate::chunk::Chunk;
-use crate::opcode::CodeIdx;
+use crate::opcode::{CodeIdx, OpCode};
 use crate::value::Lambda;
+use crate::Value;
 
 /// Implemented by types that wish to observe internal happenings of
 /// Tvix.
@@ -33,6 +34,22 @@ pub trait Observer {
 
     /// Called when the compiler finishes compilation of a thunk.
     fn observe_compiled_thunk(&mut self, _: &Rc<Lambda>) {}
+
+    /// Called when the runtime enters a new call frame.
+    fn observe_enter_frame(&mut self, _arg_count: usize, _: &Rc<Lambda>, _call_depth: usize) {}
+
+    /// Called when the runtime exits a call frame.
+    fn observe_exit_frame(&mut self, _frame_at: usize) {}
+
+    /// Called when the runtime enters a builtin.
+    fn observe_enter_builtin(&mut self, _name: &'static str) {}
+
+    /// Called when the runtime exits a builtin.
+    fn observe_exit_builtin(&mut self, _name: &'static str) {}
+
+    /// Called when the runtime *begins* executing an instruction. The
+    /// provided stack is the state at the beginning of the operation.
+    fn observe_execute_op(&mut self, _ip: usize, _: &OpCode, _: &[Value]) {}
 }
 
 #[derive(Default)]