From edf411a86cddecc953ef4be621ae527d5269a800 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 11 Dec 2023 22:41:52 -0800 Subject: fix(tvix/eval): fix recovering from throws in implications This fixes b/345. Change-Id: Ic0d3b6ffacd2a5e0050d22354d08320b69a4fe13 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10290 Tested-by: BuildkiteCI Reviewed-by: tazjin Autosubmit: Adam Joseph --- tvix/eval/src/compiler/mod.rs | 2 ++ .../src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp | 1 + .../src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix | 1 + .../notyetpassing/eval-okay-test-catchables-in-implications.exp | 1 - .../notyetpassing/eval-okay-test-catchables-in-implications.nix | 1 - 5 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix delete mode 100644 tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.exp delete mode 100644 tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.nix diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 4edb5f204533..211fd079a047 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -593,6 +593,7 @@ impl Compiler<'_> { // Leave left-hand side value on the stack and invert it. self.compile(slot, node.lhs().unwrap()); self.emit_force(&node.lhs().unwrap()); + let throw_idx = self.push_op(OpCode::OpJumpIfCatchable(JumpOffset(0)), node); self.push_op(OpCode::OpInvert, node); // Exactly as `||` (because `a -> b` = `!a || b`). @@ -603,6 +604,7 @@ impl Compiler<'_> { self.patch_jump(end_idx); self.push_op(OpCode::OpAssertBool, node); + self.patch_jump(throw_idx); } /// Compile list literals into equivalent bytecode. List diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp new file mode 100644 index 000000000000..c508d5366f70 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix new file mode 100644 index 000000000000..126738d88329 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-test-catchables-in-implications.nix @@ -0,0 +1 @@ +(builtins.tryEval (({ foo ? throw "up" }: foo -> true) { })).success diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.exp deleted file mode 100644 index c508d5366f70..000000000000 --- a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.exp +++ /dev/null @@ -1 +0,0 @@ -false diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.nix deleted file mode 100644 index 126738d88329..000000000000 --- a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-test-catchables-in-implications.nix +++ /dev/null @@ -1 +0,0 @@ -(builtins.tryEval (({ foo ? throw "up" }: foo -> true) { })).success -- cgit 1.4.1