From 5c4e102ac8551f6aaa58d54778a2442dc470b0e5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 28 Aug 2022 17:50:16 +0300 Subject: feat(tvix/eval): track whether locals needs to be finalised When encountering a deferred local upvalue, the compiler will now mark the corresponding local as needing a finaliser which makes it possible to emit the OpFinalise instruction for this stack slot a little bit down the line. Change-Id: I3962066f10fc6c6e1472722b8bdb415a811e0740 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6338 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/compiler/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tvix/eval/src/compiler/mod.rs') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 85a2309eb3..458c7b4328 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -844,6 +844,7 @@ impl Compiler { // and can be finalised. if slot.unwrap() < idx.0 { self.chunk().push_op(OpCode::DataDeferredLocal(idx)); + self.mark_needs_finaliser(slot.unwrap()); } else { self.chunk().push_op(OpCode::DataLocalIdx(idx)); } @@ -987,6 +988,7 @@ impl Compiler { name, depth, initialised: false, + needs_finaliser: false, node: Some(node), phantom: false, used: false, @@ -1002,6 +1004,7 @@ impl Compiler { self.scope_mut().locals.push(Local { depth, initialised: true, + needs_finaliser: false, name: "".into(), node: None, phantom: true, @@ -1014,6 +1017,11 @@ impl Compiler { self.scope_mut().locals[local_idx].initialised = true; } + /// Mark local as needing a finaliser. + fn mark_needs_finaliser(&mut self, local_idx: usize) { + self.scope_mut().locals[local_idx].needs_finaliser = true; + } + fn resolve_upvalue(&mut self, ctx_idx: usize, name: &str) -> Option { if ctx_idx == 0 { // There can not be any upvalue at the outermost context. -- cgit 1.4.1