diff options
author | sterni <sternenseemann@systemli.org> | 2023-06-02T19·31+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-06-07T15·17+0000 |
commit | 617130b08818aba0db5836ce9a71adae4991fb0a (patch) | |
tree | 97a387e7124cf281aa1380d32da771317b855d5e /tvix/eval/src/compiler | |
parent | e6a37b27b0e256300062bd27619430aa473c3ea0 (diff) |
refactor(tvix/eval): don't track idx twice in compile_param_pattern r/6242
Change-Id: I27f9105ddb20d84342550b2a73b479a7764ee3fe Reviewed-on: https://cl.tvl.fyi/c/depot/+/8699 Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler')
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 478d132758e8..75d9d94475a2 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -920,7 +920,6 @@ impl Compiler<'_> { // the bindings to first declare them, then populate them, and // then finalise any necessary recursion into the scope. let mut entries: Vec<(LocalIdx, ast::PatEntry)> = vec![]; - let mut indices: Vec<LocalIdx> = vec![]; let mut arguments = HashMap::default(); for entry in pattern.pat_entries() { @@ -928,14 +927,13 @@ impl Compiler<'_> { let idx = self.declare_local(&ident, ident.to_string()); let has_default = entry.default().is_some(); entries.push((idx, entry)); - indices.push(idx); arguments.insert(ident.into(), has_default); } // For each of the bindings, push the set on the stack and // attempt to select from it. let stack_idx = self.scope().stack_index(set_idx); - for (idx, entry) in entries.into_iter() { + for (idx, entry) in (&entries).into_iter() { self.push_op(OpCode::OpGetLocal(stack_idx), pattern); self.emit_literal_ident(&entry.ident().unwrap()); @@ -954,9 +952,9 @@ impl Compiler<'_> { // Thunk the default expression, but only if it is something // other than an identifier. if let ast::Expr::Ident(_) = &default_expr { - self.compile(idx, default_expr); + self.compile(*idx, default_expr); } else { - self.thunk(idx, &self.span_for(&default_expr), move |c, s| { + self.thunk(*idx, &self.span_for(&default_expr), move |c, s| { c.compile(s, default_expr) }); } @@ -966,12 +964,12 @@ impl Compiler<'_> { self.push_op(OpCode::OpAttrsSelect, &entry.ident().unwrap()); } - self.scope_mut().mark_initialised(idx); + self.scope_mut().mark_initialised(*idx); } - for idx in indices { - if self.scope()[idx].needs_finaliser { - let stack_idx = self.scope().stack_index(idx); + for (idx, _) in (&entries).into_iter() { + if self.scope()[*idx].needs_finaliser { + let stack_idx = self.scope().stack_index(*idx); self.push_op(OpCode::OpFinalise(stack_idx), pattern); } } |