From 627dfabef1dd3b640d07777de5535d074fb12f19 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 6 Sep 2022 23:20:44 +0300 Subject: fix(tvix/eval): thunk all uses of `with` With this all other "weird scope" logic starts working for `with` as well. Change-Id: I0ea1d8c5fbd9cec5084bd574224f77b71ff2b487 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6487 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/compiler/mod.rs | 4 +++- tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix | 8 ++++++++ tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix (limited to 'tvix') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 8c06db9810..1ac5ae7fec 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -172,7 +172,9 @@ impl Compiler<'_, '_> { ast::Expr::IfElse(if_else) => self.compile_if_else(slot, if_else), ast::Expr::LetIn(let_in) => self.compile_let_in(slot, let_in), ast::Expr::Ident(ident) => self.compile_ident(slot, ident), - ast::Expr::With(with) => self.compile_with(slot, with), + ast::Expr::With(with) => { + self.thunk(slot, &with, |c, w, s| c.compile_with(s, w.clone())) + } ast::Expr::Lambda(lambda) => self.compile_lambda(slot, lambda), ast::Expr::Apply(apply) => { self.thunk(slot, &apply, move |c, a, s| c.compile_apply(s, a.clone())) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix new file mode 100644 index 0000000000..af227ae28e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deferred-with.nix @@ -0,0 +1,8 @@ +# Tests using `with` on a set that does not yet exist on the stack. + +let + result = with set; value; + set = { + value = 42; + }; +in result diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.exp new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.exp @@ -0,0 +1 @@ +42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix new file mode 100644 index 0000000000..8e1256d764 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-manual-rec.nix @@ -0,0 +1,9 @@ +# Manual desugaring of something similar to `rec`, to test lower level +# recursion primitives. + +let + set = with set; { + a = 21; + b = a * 2; + }; +in set.b -- cgit 1.4.1