From 4a058a9c00d772c22a4ddbe256e8a95c19bfaacb Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 10 Oct 2022 19:37:25 -0400 Subject: fix(tvix/eval): Pop frames even if running op fails Previously, the VM assumed that if an error was returned from `run()`, the evaluation was "finished" and the state of the VM didn't matter. This used to be a reasonable assumption, but now that we've got `tryEval` around we need to actually make sure that we clean up after ourselves if we're about to return an error. Specifically, if the *last* instruction in an evaluation frame returns an error, we previously wouldn't pop that evaluation frame, which could cause all sorts of bizarre errors based on what happened to be in the stack at the time. This commit splits out a `run_op` method from `VM::run`, and uses that to check the evaluation frame return condition even if the op we're running is about to return an error, and pop the evaluation frame if we're at the last instruction. Change-Id: Ib40649d8915ee1571153cb71e3d76492542fc3d7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6940 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp | 2 +- tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/tests') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp index 770a5b6db405..8b6ed7dbac6b 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.exp @@ -1 +1 @@ -{ w = { success = false; value = false; }; x = { success = true; value = "x"; }; y = { success = false; value = false; }; z = { success = false; value = false; }; } +{ v = false; w = { success = false; value = false; }; x = { success = true; value = "x"; }; y = { success = false; value = false; }; z = { success = false; value = false; }; } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix index 8915032abd6f..e2357c798753 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-tryeval.nix @@ -1,4 +1,5 @@ { + v = (builtins.tryEval (toString )).value; w = builtins.tryEval ; x = builtins.tryEval "x"; y = builtins.tryEval (assert false; "y"); -- cgit 1.4.1