From 9b52e5b9c2917bffc8405433a2c373a26cfe0c6e Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 22 Oct 2022 19:29:02 +0300 Subject: refactor(tvix/eval): simplify check for deferring upvalue resolution This check is now actually simply equivalent to checking whether the target has been initialised or not. Change-Id: I30660d11073ba313358f3a64234a90ed81abf74c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7062 Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/compiler/mod.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'tvix') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index cd2a669013bc..9c8f0078f36a 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -996,20 +996,15 @@ impl Compiler<'_> { upvalues: Vec, capture_with: bool, ) { - let this_depth = self.scope()[slot].depth; - let this_stack_slot = self.scope().stack_index(slot); - for upvalue in upvalues { match upvalue.kind { UpvalueKind::Local(idx) => { - let target_depth = self.scope()[idx].depth; + let target = &self.scope()[idx]; let stack_idx = self.scope().stack_index(idx); - // If the upvalue slot is located at the same - // depth, but *after* the closure, the upvalue - // resolution must be deferred until the scope is - // fully initialised and can be finalised. - if this_depth == target_depth && this_stack_slot < stack_idx { + // If the target is not yet initialised, we need to defer + // the local access + if !target.initialised { self.push_op(OpCode::DataDeferredLocal(stack_idx), &upvalue.span); self.scope_mut().mark_needs_finaliser(slot); } else { -- cgit 1.4.1