Files
aji/docs/plan/phase-0-semantic-skeleton.md
T
dev c7c5e4f521 plan: Phase 0 exit review (P0-13)
- all Phase 0 tasks done; exit criterion met (41 conformance tests,
  run records compared across two runs)
- RFC 0004 Amendment 1 documents format-0 additions; status stays
  Proposed pending owner acceptance
- open question Q-019: non-terminating programs in test tooling
- README/CONTRIBUTING: current state and `aji run`
2026-10-04 12:33:17 +03:00

51 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Phase 0 — Semantic skeleton
Non-normative. Part of the [implementation plan](README.md).
**Goal:** an executable core: AIR data model, text parser and serializer, CFG/SSA/type verification, and a deterministic interpreter for integer programs.
**Exit criterion:** AIR `hello` and arithmetic tests execute identically across runs. Per Q-008, Phase 0 `hello` is a `@main` returning a value; output to stdout arrives in P2-11.
**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.
**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 and enums as values; functions and direct calls; `br`, `cbr`, `switch`, `ret`, `trap`, `assert`; checked and wrapping arithmetic, bitwise ops, comparisons, explicit casts.
Out: floats (reserved until Q-016 is answered), fixed arrays (moved to P1 with slices and bounds), borrows, memory, effect checking, concurrency.
## Tasks
| ID | Status | Task | Depends | Output | Done when |
|---|---|---|---|---|---|
| P0-1 | done | 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 | done | 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 | done | 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 | done | AIR data model | P0-1 | `src/air/{types,module,ops}.zig` | unit tests build the seed-test modules programmatically |
| P0-5 | done | Text AIR lexer and parser | P0-4 | `src/air/parse.zig` | all seed tests parse; malformed input yields registered diagnostics with spans |
| P0-6 | done | 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 | done | CFG verifier | P0-5 | `src/verifier/cfg.zig` | E5002 accept/reject tests pass (missing terminator, branch to unknown block, block-argument arity) |
| P0-8 | done | SSA/dominance verifier | P0-7 | `src/verifier/ssa.zig` | E5001 accept/reject tests pass (undefined value, use not dominated, double definition) |
| P0-9 | done | Type verifier | P0-5, P0-3 | `src/verifier/types.zig` | E1001 and E1002 accept/reject tests pass |
| P0-10 | done | Deterministic verifier budget | P0-7 | `src/verifier/budget.zig` | E5101 test with an oversized module; budget value matches spec |
| P0-11 | done | 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 | done | `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 | done | Phase exit review | all | plan status, RFC 0004 status | `hello` and arithmetic suite pass; RFC 0004 amended for format 0 (acceptance is an owner decision); 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`.
## Exit review
- Exit criterion met: `zig build conformance` runs 41 Phase 0 tests (3 accept, 19 reject, 15 run); every run test is executed twice and the run records compared byte-for-byte.
- Every code introduced in Phase 0 has a reject test: E0001–E0006, E1001–E1003, E5001, E5002, E5101; traps T0001–T0007 each have a run test.
- Parser and verifier survived 6 000 mutated corpus inputs through `aji check` and `aji run` without a crash (one crash found and fixed).
- RFC 0004 received Amendment 1 describing the format-0 additions; its status stays Proposed until the language owner accepts it.
- Deferred: interpreter memory grows with the number of calls and aggregates created, because everything lives in one arena per run. Acceptable for conformance tests; revisit with the Phase 1 memory model.
- New open question Q-019 (non-terminating programs in test tooling).