Summary
Introduce a target-agnostic Intermediate Representation (IR) into the Metano compiler pipeline so that semantic lowering logic is expressed once and consumed by multiple backends.
Current pipeline: Roslyn Compilation → TS AST → Printer → .ts
Target pipeline: Roslyn Compilation → Extraction → IR → Bridge → Target AST → Printer
Motivation
The TypeScript backend currently owns both semantic decisions (constructor shape detection, record synthesis, type mapping) and syntax emission. This coupling prevents adding new targets (Dart, Kotlin) without duplicating semantic logic.
Key problems:
RecordClassTransformer (1469 lines) mixes semantic analysis with TS emission
TypeMapper uses 5 [ThreadStatic] fields as implicit global state
ImportCollector walks the TS AST post-generation to discover runtime needs
Phased Approach
- Phase 1: Define IR type hierarchy (data types only)
- Phase 2: Eliminate TypeMapper static state
- Phase 3: Build Roslyn-to-IR extractors for enums/interfaces
- Phase 4: Bridge IR-to-TypeScript with parallel old/new assertion
- Phase 5: Extract class/record semantic analysis into IR
- Phase 6: Model runtime requirements in IR
- Phase 7: Migrate complex features + pilot second target
See docs/compiler-refactor-plan.md for the full design document.
Constraints
- Every step preserves the 357 existing tests
- Adapters and parallel paths, not big-bang rewrite
- IR must be genuinely target-agnostic (not renamed TS AST)
Summary
Introduce a target-agnostic Intermediate Representation (IR) into the Metano compiler pipeline so that semantic lowering logic is expressed once and consumed by multiple backends.
Current pipeline:
Roslyn Compilation → TS AST → Printer → .tsTarget pipeline:
Roslyn Compilation → Extraction → IR → Bridge → Target AST → PrinterMotivation
The TypeScript backend currently owns both semantic decisions (constructor shape detection, record synthesis, type mapping) and syntax emission. This coupling prevents adding new targets (Dart, Kotlin) without duplicating semantic logic.
Key problems:
RecordClassTransformer(1469 lines) mixes semantic analysis with TS emissionTypeMapperuses 5[ThreadStatic]fields as implicit global stateImportCollectorwalks the TS AST post-generation to discover runtime needsPhased Approach
See
docs/compiler-refactor-plan.mdfor the full design document.Constraints