about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-27T16·35+0300
committertazjin <tazjin@tvl.su>2022-09-04T17·53+0000
commit4bf096ee6e4318c3ed9049bb2226fc89a6bf4059 (patch)
tree4852a434adf8711114740a8ba7d0f1fc5de5260d /tvix/eval
parent27bc8cb3d4f4274dd45c810d8d1a789076bcb9f5 (diff)
fix(tvix/eval): Account for uninitialised variables in with_idx r/4640
Calculating the with_idx (i.e. the stack offset of the "phantom"
variable from which a `with` dynamically reads at runtime) needs to
account for unitialised variables the same way as the resolution of
normal locals does.

Change-Id: I9ffe404535bf1c3cb5dfe8d9e005798c857fff94
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6308
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/compiler/mod.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 928d39bae595..8defea9a4988 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -894,7 +894,17 @@ impl Compiler {
 
         self.scope_mut().with_stack.push(With {});
 
-        let with_idx = self.scope().locals.len() - 1;
+        let with_idx = self
+            .scope()
+            .locals
+            .iter()
+            // Calculate the with_idx without taking into account
+            // uninitialised variables that are not yet in their stack
+            // slots.
+            .filter(|l| matches!(l.depth, Depth::At(_)))
+            .count()
+            - 1;
+
         self.chunk().push_op(OpCode::OpPushWith(StackIdx(with_idx)));
 
         self.compile(node.body().unwrap());