From 76e0c37b9eb9e2ddf6cedbbf0b5a1d2a603de0c4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 11 Oct 2022 02:24:37 +0300 Subject: feat(tvix/eval): observe stack after exiting call frames/builtins Change-Id: I1937d37551503a0b6bb0ac899d067302e4791e5f Reviewed-on: https://cl.tvl.fyi/c/depot/+/6939 Reviewed-by: grfn Autosubmit: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/observer.rs | 24 ++++++++++++++++++------ tvix/eval/src/vm.rs | 6 ++++-- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs index 8572c2c1eb42..74ed316a6ac9 100644 --- a/tvix/eval/src/observer.rs +++ b/tvix/eval/src/observer.rs @@ -42,7 +42,7 @@ pub trait RuntimeObserver { fn observe_enter_frame(&mut self, _arg_count: usize, _: &Rc, _call_depth: usize) {} /// Called when the runtime exits a call frame. - fn observe_exit_frame(&mut self, _frame_at: usize) {} + fn observe_exit_frame(&mut self, _frame_at: usize, _stack: &[Value]) {} /// Called when the runtime replaces the current call frame for a /// tail call. @@ -52,7 +52,7 @@ pub trait RuntimeObserver { 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) {} + fn observe_exit_builtin(&mut self, _name: &'static str, _stack: &[Value]) {} /// Called when the runtime *begins* executing an instruction. The /// provided stack is the state at the beginning of the operation. @@ -146,16 +146,28 @@ impl RuntimeObserver for TracingObserver { ); } - fn observe_exit_frame(&mut self, frame_at: usize) { - let _ = writeln!(&mut self.writer, "=== exiting frame {} ===", frame_at); + fn observe_exit_frame(&mut self, frame_at: usize, stack: &[Value]) { + let _ = write!(&mut self.writer, "=== exiting frame {} ===\t[ ", frame_at); + + for val in stack { + let _ = write!(&mut self.writer, "{} ", val); + } + + let _ = writeln!(&mut self.writer, "]"); } fn observe_enter_builtin(&mut self, name: &'static str) { let _ = writeln!(&mut self.writer, "=== entering builtin {} ===", name); } - fn observe_exit_builtin(&mut self, name: &'static str) { - let _ = writeln!(&mut self.writer, "=== exiting builtin {} ===", name); + fn observe_exit_builtin(&mut self, name: &'static str, stack: &[Value]) { + let _ = write!(&mut self.writer, "=== exiting builtin {} ===\t[ ", name); + + for val in stack { + let _ = write!(&mut self.writer, "{} ", val); + } + + let _ = writeln!(&mut self.writer, "]"); } fn observe_tail_call(&mut self, frame_at: usize, lambda: &Rc) { diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 9a8d07ea63eb..daee8c886c84 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -336,7 +336,8 @@ impl<'o> VM<'o> { self.frames.push(frame); let result = self.run(); - self.observer.observe_exit_frame(self.frames.len() + 1); + self.observer + .observe_exit_frame(self.frames.len() + 1, &self.stack); result } @@ -855,7 +856,8 @@ impl<'o> VM<'o> { let arg = self.pop(); let result = fallible!(self, builtin.apply(self, arg)); - self.observer.observe_exit_builtin(builtin_name); + self.observer + .observe_exit_builtin(builtin_name, &self.stack); self.push(result); -- cgit 1.4.1