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 <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-27 19:35:34 +03:00 committed by tazjin
parent 27bc8cb3d4
commit 4bf096ee6e

View file

@ -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());