Expand description
Numbering every expression in a file.
The parser leaves every Expr holding ExprId::UNSET, and this pass
replaces those with 0, 1, … in one walk of the finished tree. Keeping
it separate from the parser is what makes the ids a property of the file:
they follow source order, not the order the parser happened to build
things in, so re-parsing the same text gives the same numbers and a
parser change that reorders its own work does not renumber anything.
The walk is deliberately exhaustive and deliberately written without a
catch-all arm. Every variant of ExprKind is named here, so a variant
added to the tree later stops compiling in this file rather than quietly
leaving its children unnumbered — which is the one failure this pass can
have, and the one that would be hardest to notice downstream.
Recursion here is bounded by the parser’s MAX_NESTING_DEPTH: a tree only
exists because the parser built it, and a walker spends less stack per
level than the parser did.
Functions§
- number_
unit - Assigns every expression in
unitan id unique within it.