about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-12-15T10·50-0800
committertazjin <tazjin@tvl.su>2023-12-29T21·34+0000
commit0c22454bb93648155b8be4b45fb5d5c8f0389673 (patch)
treee968e82c352bd56e18f29dde347823b0bde2b531 /tvix/eval/src
parent8a52c7f1c54937c44ed1cdb6f7e7c84070828623 (diff)
fix(tvix/eval): add stack depth assertion to OpReturn r/7271
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 <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/vm/mod.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs
index 0ac5024d6b..c3c0b259bc 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(())
             }