From 4e24bd56b47b2b5d7bc588d536b881ccff9ed8aa Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 3 Sep 2022 03:12:37 +0300 Subject: fix(tvix/eval): only pop initialised locals when closing scopes 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 Tested-by: BuildkiteCI --- tvix/eval/src/compiler/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index caf326828f..a9ba218df8 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); } -- cgit 1.4.1