Skip to content

Refactor canonical IR authoring with typed algebraic contracts - #10

Merged
reiase merged 2 commits into
mainfrom
refactor/typed-algebraic-ir
Aug 12, 2026
Merged

Refactor canonical IR authoring with typed algebraic contracts#10
reiase merged 2 commits into
mainfrom
refactor/typed-algebraic-ir

Conversation

@reiase

@reiase reiase commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a narrow canonical authoring surface for frozen records, enums, sealed ADTs, variants, and reusable structural refinements
  • migrate canonical IR, binding, workload, system, and cost contracts away from duplicated dataclass/codec boilerplate while preserving stable wire identities
  • make runtime contract digests cover complete record shape, defaults, enum members, and sealed ADT membership
  • model collective specifications as a closed ADT and enforce abstract roots, late-variant rejection, and exact closure membership
  • keep cross-field semantic invariants explicit while deriving scalar and container checks from annotations
  • centralize Transformer datatype widths, target-dialect policy, inference cost-operation classification, and performance-record identity rules
  • update negative, round-trip, lineage, package-boundary, and bilingual design documentation coverage

Why

Canonical contracts previously mixed raw dataclasses, low-level codec decorators, handwritten single-field validation, and repeated domain facts. That made the schema shape harder to audit, allowed authoring styles to drift, and left some runtime contract changes outside the digest.

This refactor establishes one typed algebraic authoring path. Mechanical structure is derived; independent semantic relations remain executable and visible.

Impact

  • existing canonical codec tags and wire identities are preserved
  • invalid scalar/container shapes fail at construction
  • relational invariants such as layout permutations, collective roots, and schedule uniqueness remain explicit
  • production code no longer imports low-level codec decorators outside the schema implementation
  • explicit __post_init__ methods are reduced from 110 to 49; the remainder are relational invariants or intentional boundary normalization
  • the runtime layer remains independent of mypy

Validation

  • .venv/bin/pytest -q — passed; one optional pyarrow test skipped because pyarrow is not installed
  • .venv/bin/mypy src/blueprinting — passed for 97 source files
  • .venv/bin/ruff check src tests examples/calculon_calibration.py — passed
  • .venv/bin/ruff format --check src tests examples/calculon_calibration.py — passed
  • .venv/bin/python scripts/check_docs_i18n.py — validated 49 bilingual page pairs
  • .venv/bin/mkdocs build --strict — passed
  • .venv/bin/python scripts/check_rendered_code_docs.py — passed
  • git diff --check — passed

reiase added 2 commits August 12, 2026 00:17
- Introduce algebraic data type framework in schema/ (deriving, result, frozen, diagnostics)
- Replace legacy synthesizer/ir/ with typed stage modules (stages/model, stages/distributed_task, etc.)
- Add @adt/@variant/@record decorators for closed-world codec and structural validation
- Add Result/Checked type for diagnostic-accumulating error handling
- Add PassContract with typed rules, analysis cache invalidation, and TransitionVerifier
- Separate IO-free derivation from stateful synthesis (passes/authoring, passes/deriving)
- Add typed scalar expression ADT with symbolic substitution and evaluation
- Add dialect-specific semantics and derivation modules (transformer/semantics, inference_derivation, training_derivation)
- Add runtime contract compilation (schema/contracts, contracts.py)
- Add ADR documents for wire identities, expression schemas, and progressive typed contracts
- Update docs, tests, and examples to match the new API
@reiase
reiase marked this pull request as ready for review August 12, 2026 02:08
@reiase
reiase merged commit 9f4ea74 into main Aug 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant