about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-03T00·12+0300
committertazjin <tazjin@tvl.su>2022-09-08T19·54+0000
commit4e24bd56b47b2b5d7bc588d536b881ccff9ed8aa (patch)
treef8f9cd77b81d1afef985a4cd6ccab0470ebbe586 /tvix/eval/src
parentecbd7c6ca1e8331e7ef7f94bb4a196d78bcc895c (diff)
fix(tvix/eval): only pop initialised locals when closing scopes r/4758
This avoids emitting OpPop instructions for locals that only existed
virtually (as uninitialised phantoms).

Change-Id: I8105afcca80c3f7b7ef93ce5e2f0d08a93f4ad27
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6425
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/compiler/mod.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index caf326828fd7..a9ba218df859 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -1061,12 +1061,17 @@ impl Compiler<'_> {
         while !self.scope().locals.is_empty()
             && self.scope().locals[self.scope().locals.len() - 1].above(self.scope().scope_depth)
         {
-            pops += 1;
-
-            // While removing the local, analyse whether it has been
-            // accessed while it existed and emit a warning to the
-            // user otherwise.
             if let Some(local) = self.scope_mut().locals.pop() {
+                // pop the local from the stack if it was actually
+                // initialised
+                if local.initialised {
+                    pops += 1;
+                }
+
+                // analyse whether the local was accessed during its
+                // lifetime, and emit a warning otherwise (unless the
+                // user explicitly chose to ignore it by prefixing the
+                // identifier with `_`)
                 if !local.used && !local.is_ignored() {
                     self.emit_warning(local.span, WarningKind::UnusedBinding);
                 }