Skip to main content

Phase 4. Sum types and Maranget pattern matching

FieldValue
MEPMEP-45 §Phases · Phase 4
StatusNOT STARTED
Started
Landed
Tracking issue
Tracking PR

Gate

ADT + match fixture suite (~40 cases including option<T>, result<T,E>, nested ADTs, exhaustive + non-exhaustive matches) compiles + runs byte-equal vs vm3 on host triple.

Goal-alignment audit

To be written before sub-phase 4.0 starts. Sum types and pattern matching are core to idiomatic Mochi; without them the language is a stranger to its own programs. Aligns.

Sub-phases

#ScopeStatusCommitPR
4.0Sum-type lowering: struct pkg_S { uint8_t tag; union { ... } u; }; recursive variants box payload; niche optimisation for pointer-shaped ?TNOT STARTED
4.1Maranget decision-tree pass: transpiler3/c/lower/match.go lowers match e { ... } to chained switch/if treeNOT STARTED
4.2Exhaustiveness check at type-check time (already in MEP-13); panic on non-exhaustive in --debug, UB in --fastNOT STARTED
4.3Property test: theft-generated random pattern set decides identically to reference naive matcher (10000 cases per CI run)NOT STARTED

Decisions made

Fill in along the way.

Deferred work

GADT support: not in v1.

Closeout notes

Fill in after gate green.