From babc2493160ea5f25492b281161bdd19660c8261 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 24 Aug 2022 20:25:08 +0300 Subject: [PATCH] refactor(tvix/eval): separate out `let inherit ...` logic Compilation of `let`-expressions is going to become a lot more complicated due to attempts to avoid thunking when encountering internal references, so this is just being moved out of the way. Change-Id: Iecfa4b13d14532e21c2540e6561b4235ce29736a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6266 Reviewed-by: grfn Tested-by: BuildkiteCI --- tvix/eval/src/compiler.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 6eca088ec..5cb02a66b 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -656,15 +656,9 @@ 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, node: ast::LetIn) { - self.begin_scope(); - - for inherit in node.inherits() { + // Compile an `inherit` node of a `let`-expression. + fn compile_let_inherit>(&mut self, inherits: I) { + for inherit in inherits { match inherit.from() { // Within a `let` binding, inheriting from the outer // scope is a no-op *if* the identifier can be @@ -708,6 +702,17 @@ impl Compiler { } } } + } + + // 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, node: ast::LetIn) { + self.begin_scope(); + + self.compile_let_inherit(node.inherits()); for entry in node.attrpath_values() { let mut path = match normalise_ident_path(entry.attrpath().unwrap().attrs()) {