Skip to content

Introduce shared IR for multi-target backend support #56

@danfma

Description

@danfma

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

  1. Phase 1: Define IR type hierarchy (data types only)
  2. Phase 2: Eliminate TypeMapper static state
  3. Phase 3: Build Roslyn-to-IR extractors for enums/interfaces
  4. Phase 4: Bridge IR-to-TypeScript with parallel old/new assertion
  5. Phase 5: Extract class/record semantic analysis into IR
  6. Phase 6: Model runtime requirements in IR
  7. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions