From c98c5399b9ce7729a48e5ab5a1e389f31917aeb7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 13 Feb 2023 10:54:36 +0300 Subject: fix(tvix/eval): skip runtime completely on compiler errors This branch was missing, and an assumption elsewhere just executed the returned (broken) bytecode. This fixes b/253. Change-Id: I015023ba921bc08ea03882167f1f560feca25e50 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8090 Tested-by: BuildkiteCI Reviewed-by: flokli Autosubmit: tazjin --- tvix/eval/src/lib.rs | 6 ++++++ tvix/eval/src/tests/one_offs.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) (limited to 'tvix/eval') diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs index f903a078ff3b..44fe8af2ccc5 100644 --- a/tvix/eval/src/lib.rs +++ b/tvix/eval/src/lib.rs @@ -317,6 +317,12 @@ fn parse_compile_internal( result.warnings = compiler_result.warnings; result.errors.extend(compiler_result.errors); + // Short-circuit if errors exist at this point (do not pass broken + // bytecode to the runtime). + if !result.errors.is_empty() { + return None; + } + // Return the lambda (for execution) and the globals map (to // ensure the invariant that the globals outlive the runtime). Some((compiler_result.lambda, compiler_result.globals)) diff --git a/tvix/eval/src/tests/one_offs.rs b/tvix/eval/src/tests/one_offs.rs index 13b87267a987..23bc9465d6bb 100644 --- a/tvix/eval/src/tests/one_offs.rs +++ b/tvix/eval/src/tests/one_offs.rs @@ -22,3 +22,15 @@ fn test_source_builtin() { value, ); } + +#[test] +fn skip_broken_bytecode() { + let result = Evaluation::new(/* code = */ "x", None).evaluate(); + + assert_eq!(result.errors.len(), 1); + + assert!(matches!( + result.errors[0].kind, + ErrorKind::UnknownStaticVariable + )); +} -- cgit 1.4.1