diff options
author | Vincent Ambo <mail@tazj.in> | 2022-09-29T15·07+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-30T07·07+0000 |
commit | 9cd5f03835d9fcc5b3c8fb0173c4a46c10519bc5 (patch) | |
tree | 13a1e3275138316eaf87de93e52c240afd7b14d4 /tvix/eval/src/compiler/bindings.rs | |
parent | 9e9dde01065cd6c1ceab83b08a7cd044b50f5f77 (diff) |
refactor(tvix/eval): split out AttributeSet::from_ast helper r/5001
Change-Id: Id43dbd06aef14cf01b4901d9b3668d790cd2b5ae Reviewed-on: https://cl.tvl.fyi/c/depot/+/6805 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/compiler/bindings.rs')
-rw-r--r-- | tvix/eval/src/compiler/bindings.rs | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/tvix/eval/src/compiler/bindings.rs b/tvix/eval/src/compiler/bindings.rs index 0f12511df12c..7bbf41b205e9 100644 --- a/tvix/eval/src/compiler/bindings.rs +++ b/tvix/eval/src/compiler/bindings.rs @@ -51,6 +51,36 @@ impl ToSpan for AttributeSet { } } +impl AttributeSet { + fn from_ast(c: &Compiler, node: &ast::AttrSet) -> Self { + AttributeSet { + span: c.span_for(node), + + // Kind of the attrs depends on the first time it is + // encountered. We actually believe this to be a Nix + // bug: https://github.com/NixOS/nix/issues/7111 + kind: if node.rec_token().is_some() { + BindingsKind::RecAttrs + } else { + BindingsKind::Attrs + }, + + inherits: ast::HasEntry::inherits(node).collect(), + + entries: ast::HasEntry::attrpath_values(node) + .map(|entry| { + let span = c.span_for(&entry); + ( + span, + entry.attrpath().unwrap().attrs(), + entry.value().unwrap(), + ) + }) + .collect(), + } + } +} + // Data structures to track the bindings observed in the second pass, and // forward the information needed to compile their value. enum Binding { @@ -78,32 +108,7 @@ impl Binding { // and recurse. Binding::Plain { expr } => match expr { ast::Expr::AttrSet(existing) => { - let nested = AttributeSet { - span: c.span_for(existing), - - // Kind of the attrs depends on the first time it is - // encountered. We actually believe this to be a Nix - // bug: https://github.com/NixOS/nix/issues/7111 - kind: if existing.rec_token().is_some() { - BindingsKind::RecAttrs - } else { - BindingsKind::Attrs - }, - - inherits: ast::HasEntry::inherits(existing).collect(), - - entries: ast::HasEntry::attrpath_values(existing) - .map(|entry| { - let span = c.span_for(&entry); - ( - span, - entry.attrpath().unwrap().attrs(), - entry.value().unwrap(), - ) - }) - .collect(), - }; - + let nested = AttributeSet::from_ast(c, existing); *self = Binding::Set(nested); self.merge(c, value); } |