From a2303da01fb6de2e081ab93bf3944e8fcc1476a7 Mon Sep 17 00:00:00 2001 From: sterni Date: Fri, 2 Jun 2023 23:05:32 +0200 Subject: fix(tvix/eval): use normal thunking behavior for default in formals When comparing to C++ Nix, we notice that the thunking of default expressions in function formals corresponds to their normal thunking, e.g. literals are not thunked. This means that we can just invoke compile() without much of a care and trust that it will sort it out correctly. If function formals blow up as a result of this, it likely indicates that the expression is treated incorrectly by compile(), not compile_param_pattern(). Change-Id: I64acbff2f251423eb72ce43e56a0603379305e1d Reviewed-on: https://cl.tvl.fyi/c/depot/+/8704 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/compiler/mod.rs | 11 ++--------- tvix/eval/tests/nix_oracle.rs | 5 +++++ 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 450799d683..43dab506c5 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -950,15 +950,8 @@ impl Compiler<'_> { self.patch_jump(jump_to_default); - // Thunk the default expression, but only if it is something - // other than an identifier. - if let ast::Expr::Ident(_) = &default_expr { - self.compile(*idx, default_expr); - } else { - self.thunk(*idx, &self.span_for(&default_expr), move |c, s| { - c.compile(s, default_expr) - }); - } + // Does not need to thunked since compile() already does so when necessary + self.compile(*idx, default_expr); self.patch_jump(jump_over_default); } else { diff --git a/tvix/eval/tests/nix_oracle.rs b/tvix/eval/tests/nix_oracle.rs index ecaf53a1b2..386d49c51c 100644 --- a/tvix/eval/tests/nix_oracle.rs +++ b/tvix/eval/tests/nix_oracle.rs @@ -154,4 +154,9 @@ compare_lazy_eval_tests! { thunked_lambda_in_list("[ (x: x) ]"); thunked_function_application_in_list("[ (builtins.add 1 2) ]"); thunked_legacy_let_in_list("[ (let { foo = 12; body = foo; }) ]"); + + unthunked_formals_fallback_literal("({ foo ? 12 }: [ foo ]) { }"); + unthunked_formals_fallback_string_literal("({ foo ? \"wiggly\" }: [ foo ]) { }"); + thunked_formals_fallback_application("({ foo ? builtins.add 1 2 }: [ foo ]) { }"); + thunked_formals_fallback_name_resolution_literal("({ foo ? bar, bar ? 12 }: [ foo ]) { }"); } -- cgit 1.4.1