about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-29T20·02+0300
committertazjin <tazjin@tvl.su>2022-09-30T12·31+0000
commit68a4d4a759f4e71832d99db15ceccc992b1fa0dd (patch)
tree15aa83858f61acda6e0e69abe8d92d32ba425050 /tvix
parent746f1ee702a6508a6c7d18cc5c046aecc87a929f (diff)
fix(tvix/eval): fix thunk borrowing error in force_for_output r/5006
This function previously kept a borrow in the form of the
`Thunk::value` result alive while performing arbitrary actions in the
VM, which caused a borrowing error in the test case attached.

The `Ref` value must never be used in cases where control flow is
passed to other parts of the VM.

Change-Id: I41d10aa1882a2166614b670e8ba77aab0e67deca
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6825
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp1
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix4
-rw-r--r--tvix/eval/src/vm.rs3
3 files changed, 7 insertions, 1 deletions
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp
new file mode 100644
index 000000000000..a1dca9bb6860
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.exp
@@ -0,0 +1 @@
+{ a = { b = 1; c = 2; }; }
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix
new file mode 100644
index 000000000000..7d037c6b37bc
--- /dev/null
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-rec-nested-access.nix
@@ -0,0 +1,4 @@
+rec {
+  a.b = 1;
+  a.c = a.b * 2;
+}
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index a71ab14c412c..c5b892d78d6f 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -712,7 +712,8 @@ impl<'o> VM<'o> {
 
             Value::Thunk(thunk) => {
                 fallible!(self, thunk.force(self));
-                self.force_for_output(&thunk.value())
+                let value = thunk.value().clone();
+                self.force_for_output(&value)
             }
 
             // If any of these internal values are encountered here a