diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-24T17·25+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-02T15·45+0000 |
commit | babc2493160ea5f25492b281161bdd19660c8261 (patch) | |
tree | c6fd24421a53d73ede9d1cb0659a72b3d795c2a3 /tvix/eval/src/compiler.rs | |
parent | b8f36ba09778145bcc04017ebcb8d4f9a0e9da8a (diff) |
refactor(tvix/eval): separate out `let inherit ...` logic r/4600
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 <grfn@gws.fyi> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler.rs')
-rw-r--r-- | tvix/eval/src/compiler.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 6eca088ec254..5cb02a66b96a 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<I: Iterator<Item = ast::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()) { |