From 27bc8cb3d4f4274dd45c810d8d1a789076bcb9f5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Aug 2022 19:33:41 +0300 Subject: fix(tvix/eval): open/close additional scope around `with` This is required to correctly clean up the `with` values. At the moment, the attrset from which identifiers are being taken is always pushed on the stack. This means that it must also be removed again, otherwise in an expression like with { a = 15; }; a The final stack is `[ { a = 15; } 15 ]` *after the last operation*, which means that the attrset is still on there as garbage. This has little practical impact right now because it is always shadowed by the fact that the actual expression value is at the right location, but becomes relevant when accounting for upvalue captures. Change-Id: I69e9745bfaa4d6bbcb60ee71f4dc3f8d8695d16a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6303 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/compiler/mod.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tvix/eval/src/compiler') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 6f48e8f3d5ba..928d39bae595 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -885,6 +885,7 @@ impl Compiler { // pop/remove the indices of attribute sets that are implicitly in // scope through `with` on the "with-stack". fn compile_with(&mut self, node: ast::With) { + self.begin_scope(); // TODO: Detect if the namespace is just an identifier, and // resolve that directly (thus avoiding duplication on the // stack). @@ -900,6 +901,7 @@ impl Compiler { self.chunk().push_op(OpCode::OpPopWith); self.scope_mut().with_stack.pop(); + self.end_scope(); } fn compile_lambda(&mut self, node: ast::Lambda) { -- cgit 1.4.1