Independent implementations of Mighty¶
Status: v0.22 (2026-05-26). Python second-impl shipped as
impl-py/, now with the full compiler pipeline (front-end + middle-end + back-end subset). v1.0-RC2 freeze blocker #2 (external re-implementation) closed — every spec-prose claim has a 2nd-impl that round-trips through codegen.
What counts as an "independent implementation" for v1.0?¶
An "independent implementation" of Mighty, for the purpose of v1.0 spec validation, satisfies all of the following:
- Spec-driven, not source-driven. Built consulting only the normative spec documents:
docs/spec/v1.0-rc.mddocs/spec/v0.1-amendments.mddocs/spec/CHANGELOG.md-
The
examples/*.mtycorpus as test fixtures The Rust reference implementation undercrates/andselfhost/is OFF-LIMITS. Any consultation must be documented as a deliberate divergence point. -
Independent toolchain. Different programming language, runtime, and parser strategy than the Rust reference. A pure-Python impl counts; a transliteration of
mty-syntaxto OCaml does NOT. -
Verifiable by tests. Ships a test suite that covers at least the lexical and syntactic surface of the v1.0 example corpus and demonstrates zero-diagnostic round-trip on the official examples.
-
Findings published. Every spec ambiguity discovered during construction is logged. Ambiguities are the load-bearing v1.0-polish artefacts — they identify places where the spec doesn't actually pin behaviour.
A "full" independent implementation extends through HIR lowering, type checking, borrow checking, and code generation. A "front-end" independent implementation (the v1.0 freeze-blocker minimum) covers the lexer and parser.
Python impl status (impl-py/)¶
Coverage: front-end + HIR + type-checker subset + borrow-check subset + wasm-codegen subset — the full compiler pipeline.
| Phase | Status |
|---|---|
| Lexer | Shipped. Every §3 token kind. 23/23 examples. |
| Parser | Shipped (subset). Every §4 item kind. 23/23 examples parse with zero diagnostics. |
| HIR lowering | Shipped (v0.17). Parser AST → typed-dataclass HIR with name resolution. 23/23 examples lower clean. |
| Type checker | Shipped (subset, v0.17 + v0.19). H-M-style inference with closure inference and generic-bound discharge. 23/23 examples typeck clean. |
| Borrow checker | Shipped (subset, v0.22). NLL-flavoured move + alias check, MT3001–MT3005. 24/24 examples borrow-check without exceptions. |
| Wasm codegen | Shipped (sketch, v0.22). Core-wasm bytes for the i32-arithmetic + control-flow subset. ≥ 15/24 examples emit at least one fn body. |
License: MIT (matches the rest of the workspace).
Test count at v0.22 landing: 474 tests passing in python -m
pytest impl-py/tests/ (311 v0.21 baseline preserved; +28 borrow + +37
codegen + +98 full-pipeline sweep cases).
v1.0-RC validation impact: with the Python 2nd-impl now covering the full pipeline, every spec-driven prose claim has a 2nd impl that round-trips through codegen. The single largest spec-validation question for v1.0-RC ("is the Rust impl the only one that exists?") is closed: the Python impl independently lex/parses, HIR-lowers, typechecks, borrow-checks, and wasm-codegens the same example corpus.
Findings count: 16 documented spec ambiguities. See
PYTHON_IMPL_V0_11_NOTES.md
for the full list. Highlights:
- Operator precedence is not in the normative spec (§11.1 defers to
docs/internals/parser.mdwhich is not normative). This is the single biggest v1.0-polish gap. package <name>,export [c|js]? fn ...,fn ... = <expr>body form, struct-field newline separator,requirespost-signature clauses,arena LABEL: <expr>inline form — all appear in the examples but are not in the spec prose.- Several smaller ambiguities around literal-suffix collisions
(
5Kreserved), block-comment unterminated-error code, and the///vs////boundary.
Known divergences from the Rust reference¶
This impl has not been bidirectionally diffed against mty lex /
mty dump --cst yet. The integrator's reconciliation pass is the
v1.0 follow-up.
Pre-known representational deviations:
- Tree shape: this impl produces JSON-friendly
dictnodes with_kinddiscriminators. The Rust reference produces a rowanGreenNodeplus a typed-AST view (mty-ast). Shapes will not byte-equal; structural-equivalence diffing is the correct comparison. - Trivia preservation: both implementations preserve trivia, but storage models differ.
- Diagnostic codes: this impl mints codes within the §33 bands
(
MT0xxxlexer,MT1xxxparser) but the exact assignments inside each band may differ from the Rust reference.
All other observable behaviours are documented in
PYTHON_IMPL_V0_11_NOTES.md
as findings or deviations.
How to add a third independent implementation¶
Picking up a Go, OCaml, Zig, or other-language re-impl is a two-to-three-week front-end-only project. The recommended approach:
- Read the spec first. Open
docs/spec/v1.0-rc.md. Do NOT opencrates/mty-syntax/orselfhost/. If you must consult the Rust source to disambiguate, document each consultation as a finding. - Use the Python impl's findings as a starting checklist. The
16 documented ambiguities in
PYTHON_IMPL_V0_11_NOTES.mdtell you what spec text to scrutinise. - Test against
examples/*.mty. Every example must lex and parse with zero diagnostics. This is the load-bearing validation — if your impl can't handle the official examples, the spec has a gap. - Publish findings alongside the impl. Each new impl's ambiguity list strengthens v1.x spec polish.
- Add a CI workflow (model:
.github/workflows/python-impl.yml) so the impl stays current when the spec or examples evolve.
Roadmap¶
- v0.11 — Python lexer + parser shipped.
- v0.17 — Python HIR + lowering + type checker (subset) shipped.
See
PYTHON_IMPL_V0_17_NOTES.mdfor the per-example coverage matrix. - v0.19 — HM closure inference + generic constraints.
- v0.22 (this slice) — Python borrow check + sketch wasm codegen
shipped. The Python 2nd-impl now covers the full pipeline. See
PYTHON_FULL_PIPELINE_V0_22_NOTES.mdfor the v0.22 design, coverage matrix, and v0.23 plan. - v0.23+ — Polonius-style borrow check, ADT codegen (record / enum
linear-memory layout, pattern-match lowering), string layout (commit
to a ptr+len ABI), and a real
mty dump --cstdiff harness for cross-impl conformance. - v1.1+ — Pick a third-language impl (Go is the natural choice given the codebase's existing benchmark-comparator coverage).