On this page

0029. Keep scalar compiler values compact

Context

M4's inline named-type payload made every Type 48 bytes; recursive annotations and aggregate syntax made statements 224 bytes and expressions 96 bytes on x86-64. Scalar programs paid for these unused features in parsing, checking, tree copies and destruction. Phase timing found parsing dominant, not layout DFS. Paired measurements and output-identity evidence are recorded in the performance report.

Decision

Keep Type non-Copy and structurally owned, with Named(Box) holding the name and Vec arguments. This refines the M4 plan's inline Named representation without introducing an interner or changing type ordering. Borrow types for comparisons and AST names in transient scope tables.

Box optional local annotations and the names in record/method expressions. Store ordinary call arguments as Box<[Expr]>: their length is final after parsing, and empty calls need no allocation. Together these keep Expr at 88 bytes and Stmt below its pre-fix 224 bytes. Add size-budget tests so new variants cannot silently restore the regression.

Keep literal/name parsing on the direct return path; only postfix expressions enter the suffix parser. Keep tiny ID/height checks inline and diagnostic construction out of hot paths. Literal checking avoids the recursive frame.

Alternatives considered

Consequences

Scalar flows and tree traversal stay compact; named types and explicit local annotations gain one box each. Future generics still use an owned type tree. AST consumers borrow slices rather than requiring growable argument vectors. Syntax, diagnostics, both backends and all emitted bytes stay identical.