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 <grfn@gws.fyi> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
8e122574c2
commit
76e0c37b9e
2 changed files with 22 additions and 8 deletions
|
@ -42,7 +42,7 @@ pub trait RuntimeObserver {
|
|||
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) {}
|
||||
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<W: Write> RuntimeObserver for TracingObserver<W> {
|
|||
);
|
||||
}
|
||||
|
||||
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<Lambda>) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue