On this page

0033. Keep nongeneric signatures and call targets compact

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

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.