仕組み
ADR-0007: The T0 IR is a typed, structured tree serialised as JSON
これらのページは英語です。仕様は一つの言語で保つことで、一つのことだけを語ります。
Status: accepted (2026-10-09)
Context#
The IR must be independently validated, executed by a reference interpreter, inspected by people and agents, and later compiled to native code.
Decision#
- Structured control flow (
if,while,for,return,break,continue) over typed expressions; every expression carries its type; locals are numbered slots with declared types; every operator is resolved (AddMoney,MulPriceQty, …) so the validator can re-check it against the shared dimension table without re-running inference. - Host calls name
{ contract, version, operation }; strategy graphs are a separate section (ADR-0004). - Serialisation: JSON (
serde), with a header carrying format name, IR version, compiler and language versions, source hash, requirements, and a body hash. - The validator trusts nothing in the artifact: it re-checks every type, operator, local index, function reference, and capability reference against the declared requirements.
Alternatives#
- SSA / basic blocks now -- better for optimisation and Cranelift, worse for inspection and validation; lowering the tree to SSA is the natural first step of the native backend (Phase 7) and does not need to be the canonical form.
- Binary encoding -- not needed at current sizes; JSON is inspectable.
Consequences#
- IR evolution follows
docs/versioning/compatibility-policy.md.