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:
parent
27bc8cb3d4
commit
4bf096ee6e
1 changed files with 11 additions and 1 deletions
|
@ -894,7 +894,17 @@ impl Compiler {
|
||||||
|
|
||||||
self.scope_mut().with_stack.push(With {});
|
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.chunk().push_op(OpCode::OpPushWith(StackIdx(with_idx)));
|
||||||
|
|
||||||
self.compile(node.body().unwrap());
|
self.compile(node.body().unwrap());
|
||||||
|
|
Loading…
Reference in a new issue