plan: implementation plan with per-phase task breakdowns

- plan/README.md: sequencing principles, milestones M1-M5, phase table
  with exit criteria and blocking questions, dependency graph, error-code
  -> phase coverage, cross-cutting tracks, task conventions
- phase-0..phase-8 files: scope, invariants, task tables (P<N>-<k>) with
  dependencies, outputs and mechanical "done when" checks
This commit is contained in:
dev committed 2026-10-04 12:05:40 +03:00
1 parent 4e4d753090
commit 11ce6cb38c
11 files changed
+377 -117

No files matched your search

+36 -20
View File
@@ -1,25 +1,41 @@
# Phase 0 — Semantic skeleton: task breakdown
# Phase 0 — Semantic skeleton
Non-normative. Breaks Phase 0 of [`README.md`](README.md) into tasks small enough for one agent session each.
Non-normative. Part of the [implementation plan](README.md).
Exit criterion (from the plan): AIR `hello` and arithmetic tests execute identically across runs.
**Goal:** an executable core: AIR data model, text parser and serializer, CFG/SSA/type verification, and a deterministic interpreter for integer programs.
| ID | Task | Depends on | Output | Done when |
|---|---|---|---|---|
| P0-1 | Specify text AIR grammar | — | `docs/reference/air-text.ebnf`, updates to `docs/spec/07-air.md` | grammar covers module header, functions, `effects`, blocks with parameters, instructions, comments; seed tests in `tests/conformance/phase0` match it |
| P0-2 | AIR data model | P0-1 | `src/air.zig` (types, values, instructions, blocks, functions, module) | round-trips through P0-4 |
| P0-3 | Text AIR lexer + parser | P0-1, P0-2 | `src/air/parse.zig` | parse errors are diagnostics with spans; new parse codes registered in `error-codes.md` |
| P0-4 | Canonical serializer | P0-2 | `src/air/print.zig` | `parse ∘ print` is identity on the data model; output is byte-stable |
| P0-5 | CFG verifier | P0-3 | `src/verifier/cfg.zig` | `E5002` accept/reject tests pass |
| P0-6 | SSA/dominance verifier | P0-5 | `src/verifier/ssa.zig` | `E5001` accept/reject tests pass |
| P0-7 | Type verifier for integer ops, structs, enums | P0-3 | `src/verifier/types.zig` | `E1001` accept/reject tests pass |
| P0-8 | Verifier resource budget | P0-5 | budget in `src/verifier.zig` | `E5101` emitted deterministically; budget documented in spec 08 |
| P0-9 | Interpreter core | P0-6, P0-7 | `src/interp.zig` | arithmetic programs run; checked overflow traps per spec |
| P0-10 | `aji run` + run tests in conformance runner | P0-9 | `expect: run` header with expected stdout/trap | `hello` and arithmetic tests pass, output identical across 100 runs |
**Exit criterion:** AIR `hello` and arithmetic tests execute identically across runs.
## Open questions to resolve in P0-1
**Spec inputs:** spec 00 §5–6, 01 §6, 02 §1–3, 07, 08 §1–2, §7, 10 §2, 11 §1. RFC 0004 moves to Accepted at the end of this phase.
- Comment syntax in text AIR (the conformance runner currently strips leading `;` lines itself).
- Spelling of constants (`const.u64 0` is provisional) and comparison results (`bool` vs `u1`).
- How `hello` reaches stdout before Phase 2 capabilities exist: a test-only intrinsic, or Phase 2 `io.write` brought forward.
- Whether parse errors get their own `E0xxx` range or join `E5xxx`.
**Blocking questions:** Q-001 grammar, Q-002 contracts, Q-003 parse codes, Q-004 traps, Q-005 budget, Q-006 target description, Q-007 integer edge cases, Q-008 `hello`, Q-016 floats.
## Scope
In: integer types, `bool`, `void`, `never`; structs, enums, fixed arrays as values; functions and direct calls; `br`, `cbr`, `switch`, `ret`, `trap`, `assert`; checked and wrapping arithmetic, bitwise ops, comparisons, explicit casts.
Out: floats (deferred until Q-016 is answered), borrows, memory, effects other than `[]`, concurrency.
## Tasks
| ID | Status | Task | Depends | Output | Done when |
|---|---|---|---|---|---|
| P0-1 | todo | Specify text AIR grammar (Q-001) and parse-error codes (Q-003) | — | `docs/reference/air-text.ebnf`, spec 07, error-codes.md | grammar covers module header with version/feature bits, type declarations, functions, `effects`, blocks with parameters, instructions, comments; seed tests in `tests/conformance/phase0` conform to it |
| P0-2 | todo | Specify traps (Q-004), integer edge cases and casts (Q-007), target description (Q-006), verifier budget (Q-005), `hello` strategy (Q-008) | — | spec 01, 02, 08, 11 | each question marked resolved in `open-questions.md` |
| P0-3 | todo | Write contract tables for Phase 0 opcodes; add aggregate opcodes (struct/enum construct and access) if needed, via RFC 0004 amendment | P0-1 | spec 07 appendix | every in-scope opcode has all fields required by spec 07 §4 |
| P0-4 | todo | AIR data model | P0-1 | `src/air/{types,module,ops}.zig` | unit tests build the seed-test modules programmatically |
| P0-5 | todo | Text AIR lexer and parser | P0-4 | `src/air/parse.zig` | all seed tests parse; malformed input yields registered diagnostics with spans |
| P0-6 | todo | Canonical serializer | P0-4 | `src/air/print.zig` | `print(parse(x))` is a fixed point after one round; fuzz test on parser round-trip |
| P0-7 | todo | CFG verifier | P0-5 | `src/verifier/cfg.zig` | E5002 accept/reject tests pass (missing terminator, branch to unknown block, block-argument arity) |
| P0-8 | todo | SSA/dominance verifier | P0-7 | `src/verifier/ssa.zig` | E5001 accept/reject tests pass (undefined value, use not dominated, double definition) |
| P0-9 | todo | Type verifier | P0-5, P0-3 | `src/verifier/types.zig` | E1001 and E1002 accept/reject tests pass |
| P0-10 | todo | Deterministic verifier budget | P0-7 | `src/verifier/budget.zig` | E5101 test with an oversized module; budget value matches spec |
| P0-11 | todo | Interpreter core | P0-8, P0-9 | `src/interp/machine.zig` | arithmetic programs run; overflow, assert and explicit `trap` produce the trap records defined in P0-2 |
| P0-12 | todo | `aji run`; `expect: run` / `stdout:` / `trap:` in the conformance runner; double-run determinism check | P0-11 | `src/main.zig`, `tools/conformance.zig` | runner fails a test whose two runs differ |
| P0-13 | todo | Phase exit review | all | plan status, RFC 0004 status | `hello` and arithmetic suite pass; RFC 0004 marked Accepted; P0 status set to done |
## Conformance tests to add
- accept: arithmetic on every integer width; loops via block parameters; `switch`; nested calls; recursion.
- reject: E5001 ×3, E5002 ×3, E1001 (operand, result, block argument, return), E1002.
- run: checked overflow traps; wrapping does not trap; division by zero (per Q-007); `hello`.