From 0c22454bb93648155b8be4b45fb5d5c8f0389673 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 15 Dec 2023 02:50:33 -0800 Subject: [PATCH] fix(tvix/eval): add stack depth assertion to OpReturn I'm still trying to work out the exact stack invariants for tvix. We really should add assertions for them; getting the stack messed up is no fun. This commit adds one simple assertion. It also adds a missing stack-push (my mistake) in one place, which was uncovered by the assertion. Change-Id: I9d8b4bd1702d954e325832c5935b0d7e3eb68422 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10369 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/vm/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 0ac5024d6..c3c0b259b 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -486,6 +486,9 @@ impl<'o> VM<'o> { // Discard the current frame. OpCode::OpReturn => { + // TODO(amjoseph): I think this should assert `==` rather + // than `<=` but it fails with the stricter condition. + debug_assert!(self.stack.len() - 1 <= frame.stack_offset); return Ok(true); } @@ -1081,6 +1084,10 @@ impl<'o> VM<'o> { } val @ Value::Catchable(_) => { + // the argument that we tried to apply a catchable to + self.stack.pop(); + // applying a `throw` to anything is still a `throw`, so we just + // push it back on the stack. self.stack.push(val); Ok(()) }