From 1cf07051cbc31d869502641ba9afba8f55763398 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 16 Sep 2022 18:37:51 +0300 Subject: refactor(tvix/eval): extract recursive scope logic into a helper This needs to be reused between let & `rec` attrs. Change-Id: I4a3bb90af4be32771b0f9e405c19370e105c0fef Reviewed-on: https://cl.tvl.fyi/c/depot/+/6608 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/compiler/mod.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index cd8f46aec8..bafbad6795 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -520,12 +520,10 @@ impl Compiler<'_, '_> { self.patch_jump(else_idx); // patch jump *over* else body } - /// Compile a standard `let ...; in ...` statement. - /// - /// Unless in a non-standard scope, the encountered values are - /// simply pushed on the stack and their indices noted in the - /// entries vector. - fn compile_let_in(&mut self, slot: LocalIdx, node: ast::LetIn) { + fn compile_recursive_scope(&mut self, slot: LocalIdx, node: &N) + where + N: AstNode + ast::HasEntry, + { self.scope_mut().begin_scope(); // First pass to find all plain inherits (if they are not useless). @@ -638,9 +636,18 @@ impl Compiler<'_, '_> { for idx in indices { if self.scope()[idx].needs_finaliser { let stack_idx = self.scope().stack_index(idx); - self.push_op(OpCode::OpFinalise(stack_idx), &node); + self.push_op(OpCode::OpFinalise(stack_idx), node); } } + } + + /// Compile a standard `let ...; in ...` statement. + /// + /// Unless in a non-standard scope, the encountered values are + /// simply pushed on the stack and their indices noted in the + /// entries vector. + fn compile_let_in(&mut self, slot: LocalIdx, node: ast::LetIn) { + self.compile_recursive_scope(slot, &node); // Deal with the body, then clean up the locals afterwards. self.compile(slot, node.body().unwrap()); -- cgit 1.4.1