pub enum Node {
Show 14 variants
Sort(LevelId),
Var(Symbol),
Global(Symbol),
Const {
name: Symbol,
levels: Box<[LevelId]>,
},
Pi {
param: Symbol,
param_type: TermId,
body_type: TermId,
},
Lambda {
param: Symbol,
param_type: TermId,
body: TermId,
},
App(TermId, TermId),
Match {
discriminant: TermId,
motive: TermId,
cases: Box<[TermId]>,
},
Fix {
name: Symbol,
body: TermId,
},
MutualFix {
defs: Box<[(Symbol, TermId)]>,
index: usize,
},
Let {
name: Symbol,
ty: TermId,
value: TermId,
body: TermId,
},
Lit(LitId),
Hole,
Bound(u32),
}Expand description
One term node with its children replaced by handles — the flat shape that makes the store a DAG rather than a tree.
The match arms below mirror Term’s thirteen kernel variants ONE FOR ONE, and every match over
Node in this file is wildcard-free on purpose: a new Term variant must answer here
rather than slip past under a _. Term::Annotated has no node: the store keys on the erased
term, so an annotated term interns to its term’s node.
Variants§
Sort(LevelId)
Term::Sort.
Var(Symbol)
Term::Var.
Global(Symbol)
Term::Global.
Const
Term::Const.
Pi
Term::Pi.
Fields
Lambda
Term::Lambda.
Fields
App(TermId, TermId)
Term::App.
Match
Term::Match.
Fields
Fix
Term::Fix.
MutualFix
Term::MutualFix.
Fields
Let
Term::Let.
Fields
Lit(LitId)
Term::Lit.
Hole
Term::Hole.
Bound(u32)
A DE BRUIJN LEVEL — a bound-variable occurrence in an α-CANONICAL form.
TermStore::intern never produces this: no Term can spell it, which is exactly why
it is a node and not a reserved NAME. A reserved name could collide with a free variable
a user actually wrote, and the collision would silently conflate two terms that are not
α-equivalent. A node shape cannot collide with anything.
Implementations§
Source§impl Node
impl Node
Sourcepub fn for_each_child(&self, f: &mut impl FnMut(TermId))
pub fn for_each_child(&self, f: &mut impl FnMut(TermId))
Visit this node’s term children, in their canonical order.
This is the SINGLE source of truth for child order. Node::child_count and
Node::rebuild_with are both defined against it, and
term_store_extra::rebuild_with_round_trips_every_variant locks the three together.
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
How many term children this node has.
Sourcepub fn rebuild_with(&self, children: &[TermId]) -> Node
pub fn rebuild_with(&self, children: &[TermId]) -> Node
This node with its children replaced, positionally, by children.
§Panics
Panics if children.len() != self.child_count() — a caller that miscounts is a bug,
not a recoverable condition.