Expand description
Generic desugaring pipeline.
Transforms File<Raw> (parser output, with all surface sugar) into
File<Desugared> (canonical form consumed by name resolution, IR lowering,
TIR, and evaluation).
§Architecture
Each surface sugar implements DesugarSugar — a node-level transform
that maps one raw sugar variant to its desugared equivalent. The generic
walker in this module traverses the AST, dispatching Sugar(_) arms to
the appropriate DesugarSugar impl while every other variant is
rebuilt phase-by-phase with its children desugared recursively.
File<Raw> ──┬─► (walker) ──┬─► File<Desugared>
│ │
├─ MultiDecl ───┘ via DesugarSugar
└─ TableLiteral ──► (desugar to MapLiteral)§Adding a new customer
- Add a variant to
crate::syntax::ast::RawDeclSugarorcrate::syntax::ast::RawExprSugar. - Implement
DesugarSugarfor that variant in a submodule of this module. - Wire it into the walker’s
Sugar(_)dispatch.
No changes to downstream consumers are needed — they only see
File<Desugared> and never observed the sugar in the first place.
§Span fidelity
Desugaring preserves source spans: every synthesized node carries the span of the surface construct it came from. Diagnostics emitted on desugared AST still point at the original source.
Modules§
- convert
From<X<Raw>> for X<Desugared>impls.- desugared_
ast - Type aliases pinning every phase-parameterized AST node to
crate::syntax::phase::Desugared.
Traits§
- Desugar
Sugar - Single-node desugaring step.