Skip to content

Morrow v2.4.15 — Where generic types are lost, and why the monomorphizer cannot help

Choose a tag to compare

@LeTrollologist LeTrollologist released this 02 Nov 11:26
· 22 commits to main since this release

Morrow v2.4.15 — Where generic types are lost, and why the monomorphizer cannot help

Release date: 2026-11-02
Toolchain: forge 2.4.15 (morrow standalone 2026)
Self-hosting fixed point: EBD9E24CBD561FC05B222071B98A0237685BC33CAEA1C76F7D5BE426E907F78A
(stage2.ll == stage3.ll, stage2.exe == stage3.exe, 467968 bytes)

Investigation only. No compiler code changed — docs/GENERIC-TYPES.md records the
answer, the evidence, and the design direction for v2.4.16.

The answer

A reusable representation does not exist — and the monomorphizer is not the reason.
The parser destroys generic arguments before monomorphization ever runs:

// compiler/parser.mw:117-131, parse_type
if check(p, tok_lt()) {
    advance(p);                       // consume '<'
    ...                               // consume to the matching '>'
}                                     // and return only the base symbol

Vec<i64>, Vec<String>, Vec<T> — as annotation, parameter, or return type — all become
the single symbol Vec. Whatever a later phase does, it never received the argument.

The three criteria, answered

Criterion Answer Evidence
Vec<String> vs Vec<i64> distinct identities No, for types parser erasure; TcType has kind/sym/left/right, no type arguments. Only functions get identity, as mangled symbols (identity__i64, forge.mw:278-287)
survival through params/calls/returns No a call keeps its turbofish in expr.int_val until monomorphization rewrites it; parameters and returns never had it
reachable without a later phase No monomorphization runs before typechecking on the build path (forge.mw:875-878) but is not run on check, argkinds or lsp (forge.mw:1018, :1000, lsp.mw:325), and its output is a mutated AST, not a type table

The lifetime caution was warranted: the representation that does exist is produced only on
one of four paths, so "it distinguishes instantiations" was true and still insufficient.

Chosen direction (for v2.4.16, not this release)

Intern the concrete type name in parse_type — Vec<i64> as its own symbol — reusing
the mechanism the monomorphizer already trusts (a fresh interned symbol per distinct name).
TcType.sym already holds a name symbol, so no TcType change is needed;
tc_resolve_type gains one fallback to find the template's fields by stripping the argument
list.

Rejected: reusing monomorphizer output (would change what forge check means and is absent
on three paths) and a type-argument list on TcType (touches every allocation and
comparison).

Risks recorded before any code is written

  1. Refinement intervals (u8[0..100]) share parse_type and must keep working.
  2. tc_resolve_type has two plain-name maps (types, struct_defs) that will both miss
    instantiated names — the parser change and the fallback are one unit.
  3. Vec<i64> (parser) and Vec__i64 (monomorphizer) will be different symbols for the same
    concept; acceptable, but must be documented or conflated later.
  4. &mut Vec<T> must keep producing ty_ref/ty_ptr exactly as today — the region-escape
    rules depend on those kinds.

Verification

Gate Result
Compiler changes none
Corpus 21 files unchanged and green as recorded
Native / compile-fail suites 23/23, 18/18
Fixed point 3-stage closure, stage2.exe == stage3.exe