From 9792920f8cdec92aa2c650de8cfd0a85fa7dce52 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 11 Dec 2023 21:17:22 -0800 Subject: fix(tvix/eval): fix branching on catchable defaults (b/343) This commit adds Opcode::OpJumpIfCatchable, which can be inserted ahead of most VM operations which expect a boolean on the stack, in order to handle catchables in branching position properly. Other than remembering to patch the jump, no other changes should be required. This commit also fixes b/343 by emitting this new opcode when compiling if-then-else. There are probably other places where we need to do the same thing. Change-Id: I48de3010014c0bbeba15d34fc0d4800e0bb5a1ef Reviewed-on: https://cl.tvl.fyi/c/depot/+/10288 Tested-by: BuildkiteCI Reviewed-by: tazjin Autosubmit: Adam Joseph --- tvix/eval/src/vm/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tvix/eval/src/vm') diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 6128e3a601a0..642b6317caee 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -562,6 +562,13 @@ impl<'o> VM<'o> { } } + OpCode::OpJumpIfCatchable(JumpOffset(offset)) => { + debug_assert!(offset != 0); + if self.stack_peek(0).is_catchable() { + frame.ip += offset; + } + } + OpCode::OpJumpIfNoFinaliseRequest(JumpOffset(offset)) => { debug_assert!(offset != 0); match self.stack_peek(0) { -- cgit 1.4.1