From 4bf096ee6e4318c3ed9049bb2226fc89a6bf4059 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Aug 2022 19:35:34 +0300 Subject: fix(tvix/eval): Account for uninitialised variables in with_idx 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 --- tvix/eval/src/compiler/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src') 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()); -- cgit 1.4.1