0033. Keep nongeneric signatures and call targets compact
- Status: Accepted
- Date: 2026-10-30
- Plan: M4.4 (CP-4.2 review fixes)
- Review: Compiler and backend; Performance
Context
The CP-4.2 review measured scalar compiler overhead against main 7d7d0fe. Even without discovery, every function carried an optional generic-details pointer and every lowering call target used a composite name/type-argument key. The calls-40000 workload exposes these costs. Before/after measurements live in the review performance report.
Decision
Extend ADR-0029's compact scalar representation to generic declaration metadata: store function generic parameters/spans in a sparse side table, leaving scalar signatures at 32 bytes. Freeze signature parameters, AST generic parameters and AST type arguments as boxed slices after collection. Empty slices allocate nothing; TypeName shrinks from 64 to 56 bytes and FnDecl from 208 to 192 bytes.
Keep ordinary function targets in a name-only map and specialized targets in a separate name/type-argument map. Consult the sparse checked instance table at calls instead of looking up a signature just to learn that it is nongeneric. Skip empty generic-list parsing, scalar type-site recording, type-declaration passes when no declarations exist, and empty substitutions. Reuse argument hints instead of cloning them twice. Return operand validity from the existing check to preserve error recovery without repeating structural type comparisons.
This refines the implementation of ADR-0024, with identical types, discovery order, limits, IR, emitted C and runtime semantics. No new dependencies or unsafe.
Alternatives considered
- Optional details in every signature and composite keys for every function — simple, but the metadata inflates scalar programs that cannot use it.
- A second scalar compiler pipeline — duplicates semantics and diagnostics; compact data and local fast paths retain the shared front end and IR.
- Intern all types — a broader representation change than the measured scalar metadata/call-lookup costs require.
Consequences
Three regression tests pin signature/AST size budgets and empty scalar mono metadata. Generic inference and both backends keep their existing golden tests. Scalar calls no longer create or search generic target keys; missing checked generic instances still fail lowering as compiler bugs rather than misdispatch.