From 4d8f35353b41080c57f7a65093c29060877f646c Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 7 Sep 2022 15:37:29 +0200 Subject: fix(tvix/eval): declare let inherit (from) locals before compiling The recent change that split declaration of let based locals and the compilation of their values did not touch locals bound by inherit in let. These were previously declared and compiled immediately before starting to work on the other locals introduced in a let. In the case of plain inherits, this behavior is kept in this change, because there's nothing wrong with it: The value of a plain inherit will always resolve to a higher scope, either statically or dynamically. Since inherit (from) expression might refer to other locals bound in the same let, we need to handle them in the same three steps as ordinary let based locals: 1. We need to declare the (uninitialised) locals. 2. We need to compile the expression that obtains their value. For this, we create a new thunk, since the from expression may very well return a thunk which we need to force before selecting the value we are interested in. 3. Thunks need to be finalised. For 1., we create an extra pass over the inherits that already declares and initialises plain inherits and notes inherit (from) expressions in the entries vector after declaring them. 2. only needs a bit of adapting to create the thunks for selecting if appropriate, the rest of the existing code can be reused. Change-Id: Ie4ac1c0f9ffcbf7c07c452036aa8e577443af773 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6490 Tested-by: BuildkiteCI Reviewed-by: sterni Reviewed-by: tazjin --- .../tvix_tests/eval-okay-let-inherit-from-later-bound.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit-from-later-bound.nix (limited to 'tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit-from-later-bound.nix') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit-from-later-bound.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit-from-later-bound.nix new file mode 100644 index 000000000000..21196f48bcbe --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-let-inherit-from-later-bound.nix @@ -0,0 +1,13 @@ +let + inherit (c) d; + inherit (a) b c; + + a = { + b = 20; + c = { + d = 3; + }; + }; +in + +b + d -- cgit 1.4.1