0029. Keep scalar compiler values compact
- Status: Accepted
- Date: 2026-10-30
- Plan: M4.3 (CP-4.1 compiler regression review)
- Review: Compiler and backend
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
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
- Keep every payload inline — measured scalar regressions breach CP-4.1.
- Intern all types or AST nodes — unnecessary ownership and indexing changes; boxed trees retain the agreed structural equality, ordering and simple cloning.
- Box every call's callee — shrinks Expr, but allocates for every nullary call; boxed argument slices achieve the size budget without that allocation.
- Skip declaration passes on scalar programs — profiling found insufficient time there to explain or recover the regression.
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.