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 <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-09-03 03:12:37 +03:00 committed by tazjin
parent ecbd7c6ca1
commit 4e24bd56b4

View file

@ -1061,12 +1061,17 @@ impl Compiler<'_> {
while !self.scope().locals.is_empty() while !self.scope().locals.is_empty()
&& self.scope().locals[self.scope().locals.len() - 1].above(self.scope().scope_depth) && 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() { 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() { if !local.used && !local.is_ignored() {
self.emit_warning(local.span, WarningKind::UnusedBinding); self.emit_warning(local.span, WarningKind::UnusedBinding);
} }