From bb1e79e5d19a43beeebe8f858019131c57f99c65 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 04:22:23 -0800 Subject: [PATCH] fix(tvix/eval): propagate catchables through `&&` Change-Id: I7bb5ac1ef47b41c47269e64cee0e90eb64c6fcce Reviewed-on: https://cl.tvl.fyi/c/depot/+/10322 Autosubmit: Adam Joseph Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/compiler/mod.rs | 2 ++ .../src/tests/tvix_tests/eval-okay-logical-and-catchable.exp | 1 + .../src/tests/tvix_tests/eval-okay-logical-and-catchable.nix | 1 + 3 files changed, 4 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 451fa44de..f6d6ca7c0 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -546,6 +546,7 @@ impl Compiler<'_> { self.compile(slot, node.lhs().unwrap()); self.emit_force(&node.lhs().unwrap()); + let throw_idx = self.push_op(OpCode::OpJumpIfCatchable(JumpOffset(0)), node); // If this value is false, jump over the right-hand side - the // whole expression is false. let end_idx = self.push_op(OpCode::OpJumpIfFalse(JumpOffset(0)), node); @@ -559,6 +560,7 @@ impl Compiler<'_> { self.patch_jump(end_idx); self.push_op(OpCode::OpAssertBool, node); + self.patch_jump(throw_idx); } fn compile_or(&mut self, slot: LocalIdx, node: &ast::BinOp) { diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp new file mode 100644 index 000000000..c508d5366 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix new file mode 100644 index 000000000..f731f0924 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-logical-and-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval ( (throw "fred") && (throw "jill") )).success