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 <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Adam Joseph 2023-12-15 02:50:33 -08:00 committed by tazjin
parent 8a52c7f1c5
commit 0c22454bb9

View file

@ -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(())
}