From 7b9eea71d021315a1d29c2bcca84de72cc507e04 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 04:07:20 -0800 Subject: fix(tvix/eval): fix nested assertions b/340 This commit fixes our handling of `throw` within an `assert` condition. Fixes: b/340 Change-Id: I40a383639ec266da50a853f16216b1b7868495da Reviewed-on: https://cl.tvl.fyi/c/depot/+/10318 Autosubmit: Adam Joseph Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/compiler/mod.rs | 2 ++ tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix | 1 + .../src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.exp | 1 - .../src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.nix | 1 - 5 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix delete mode 100644 tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.exp delete mode 100644 tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.nix (limited to 'tvix/eval') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index b6b5bc6860f9..831b92b67a11 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -836,6 +836,7 @@ impl Compiler<'_> { // Compile the assertion condition to leave its value on the stack. self.compile(slot, node.condition().unwrap()); self.emit_force(&node.condition().unwrap()); + let throw_idx = self.push_op(OpCode::OpJumpIfCatchable(JumpOffset(0)), node); let then_idx = self.push_op(OpCode::OpJumpIfFalse(JumpOffset(0)), node); self.push_op(OpCode::OpPop, node); @@ -848,6 +849,7 @@ impl Compiler<'_> { self.push_op(OpCode::OpAssertFail, &node.condition().unwrap()); self.patch_jump(else_idx); + self.patch_jump(throw_idx); } /// Compile conditional expressions using jumping instructions in the VM. diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp new file mode 100644 index 000000000000..c508d5366f70 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix new file mode 100644 index 000000000000..b0397e268e41 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-nested-assertions.nix @@ -0,0 +1 @@ +(builtins.tryEval (assert (assert false; true); true)).success diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.exp b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.exp deleted file mode 100644 index c508d5366f70..000000000000 --- a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.exp +++ /dev/null @@ -1 +0,0 @@ -false diff --git a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.nix b/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.nix deleted file mode 100644 index b0397e268e41..000000000000 --- a/tvix/eval/src/tests/tvix_tests/notyetpassing/eval-okay-nested-assertions.nix +++ /dev/null @@ -1 +0,0 @@ -(builtins.tryEval (assert (assert false; true); true)).success -- cgit 1.4.1