about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-16T15·37+0300
committertazjin <tazjin@tvl.su>2022-09-16T18·02+0000
commit1cf07051cbc31d869502641ba9afba8f55763398 (patch)
tree4774d2c8798bc59a230fda7f63709146698daef1 /tvix
parent01a239c95597808eabde0fac3a2c3ab421abec3a (diff)
refactor(tvix/eval): extract recursive scope logic into a helper r/4874
This needs to be reused between let & `rec` attrs.

Change-Id: I4a3bb90af4be32771b0f9e405c19370e105c0fef
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6608
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/compiler/mod.rs21
1 files 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<N>(&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());