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

+75 -96
View File
@@ -1,118 +1,97 @@
# Implementation Plan
## Phase 0 — Semantic skeleton
Non-normative. The order in which the Zig reference implementation is built, and how work is split into tasks. The spec defines what to build; this plan defines when.
Deliver:
## Sequencing principles
- AIR value/type model;
- text AIR parser and serializer;
- basic blocks and SSA validation;
- integer operations;
- structs/enums;
- interpreter;
- stable diagnostic envelope.
1. **Semantics before speed.** Interpreter and verifier define the language. No native code until the conformance corpus is stable (DD-007).
2. **AIR before source.** AIR is the conformance format. The `.aji` frontend comes after the core semantics are executable.
3. **Spec gate first in every phase.** Each phase opens by resolving its open questions (`../design/open-questions.md`) and writing the instruction contracts (spec 07 §4) for the opcodes it introduces. Code that implements unspecified behavior is not merged.
4. **Tests before code.** Every verifier rule lands with an `accept`/`reject` conformance pair and a stable diagnostic code.
5. **Exit criteria are executable.** A phase is done when its exit criterion passes in `zig build conformance`, not when its tasks are ticked.
6. **One task, one change.** A task is sized for one agent session and one reviewable change.
Exit criterion: AIR `hello` and arithmetic tests execute identically across runs.
## Milestones
## Phase 1 — Ownership and memory
| Milestone | Phases | Result |
|---|---|---|
| M1 — Verified core | P0, P1, P2 | Single-threaded Aji: ownership, regions, effects, capabilities and resources verified; file-copy and TCP echo run in the interpreter |
| M2 — Concurrent Aji | P3, P4, P5 | Structured tasks, channels, locks, islands and atomics with deterministic and randomized scheduling |
| M3 — Source language | P6 | All reference programs written as `.aji` |
| M4 — Native | P7 | LLVM backend; interpreter and native agree on the whole corpus |
| M5 — Agent-ready | P8 | `ajid` protocol and benchmark; candidate for Aji 0.1 |
Deliver:
## Phases
- `Own<T>`;
- `ref<T>` / `mut<T>`;
- slices;
- initialization tracking;
- `Region` and generation semantics;
- bounds/range facts;
- ownership/borrow diagnostics.
| Phase | File | Goal | Exit criterion | Blocking questions |
|---|---|---|---|---|
| P0 | [phase-0-semantic-skeleton.md](phase-0-semantic-skeleton.md) | AIR model, text parser, CFG/SSA/type verifier, interpreter | AIR `hello` and arithmetic tests execute identically across runs | Q-001…Q-008, Q-016 |
| P1 | [phase-1-ownership-and-memory.md](phase-1-ownership-and-memory.md) | `Own`, borrows, slices, init tracking, regions, bounds | file-copy core implemented; UAF/alias/OOB rejected | Q-009, Q-010 |
| P2 | [phase-2-effects-capabilities-resources.md](phase-2-effects-capabilities-resources.md) | Effects, capabilities, linear resources, runtime intrinsics | safe file-copy and basic TCP echo | Q-011, Q-012, Q-018 |
| P3 | [phase-3-structured-concurrency.md](phase-3-structured-concurrency.md) | Task scopes, Send/Share, channels, mutex, cancellation, deterministic scheduler | parallel-map and channel ownership-transfer examples | Q-013, Q-014 |
| P4 | [phase-4-islands.md](phase-4-islands.md) | Islands, `iref`, transfer, freeze, `Frozen`, `Arc` | cyclic graph moves between tasks with no deep copy and no shared mutation | — |
| P5 | [phase-5-atomics-and-memory-model.md](phase-5-atomics-and-memory-model.md) | Atomics, orderings, fences, weak-memory interpreter, schedule exploration, replay | atomic publication litmus/conformance tests | Q-015, Q-017 |
| P6 | [phase-6-source-language.md](phase-6-source-language.md) | `.aji` parser, lowering, generics, contracts, formatter | all reference programs authored primarily as `.aji` | — |
| P7 | [phase-7-native-backend.md](phase-7-native-backend.md) | LLVM lowering, native runtime, three targets, ABI tests | interpreted and native executions pass the same corpus | — |
| P8 | [phase-8-agent-protocol.md](phase-8-agent-protocol.md) | `ajid`, inspect/trace, verification report, benchmark | external agent implements/repairs a reference task using only protocol + spec | — |
Exit criterion: file-copy can be implemented and verifier rejects representative UAF/alias/OOB cases.
## Dependency graph
## Phase 2 — Effects, capabilities and resources
```text
P0 ──► P1 ──► P2 ──► P3 ──► P4
│ │
└──────┴──► P5 ──► P6 ──► P7 ──► P8
```
Deliver:
Allowed overlap:
- effects;
- capability values;
- linear File/Socket resources;
- runtime intrinsics;
- explicit cleanup lowering.
- spec-gate tasks of a later phase may start any time;
- P6 grammar work (P6-1) may start after P2, since syntax does not affect AIR semantics;
- P8 protocol design (P8-1) may start after P2; `ajid` wraps `check.zig`, which exists from P0.
Exit criterion: safe file-copy and basic TCP echo.
## Error code coverage
## Phase 3 — Structured concurrency
Every registry code (`../reference/error-codes.md`) has a phase that must implement it with an accept/reject pair.
Deliver:
| Code | Phase | | Code | Phase |
|---|---|---|---|---|
| E1001 type.mismatch | P0 | | E3101 effect.undeclared | P2 |
| E1002 type.invalid_cast | P0 | | E3201 capability.missing | P2 |
| E1010 init.read_uninitialized | P1 | | E3202 capability.widen | P2 |
| E2001 ownership.use_after_move | P1 | | E4001 concurrency.not_send | P3 |
| E2002 ownership.double_consume | P1 | | E4002 concurrency.not_share | P3 |
| E2101 borrow.mutable_alias | P1 | | E4101 concurrency.possible_data_race | P3 |
| E2102 borrow.outlives_owner | P1 | | E4201 atomic.invalid_order | P5 |
| E2103 memory.out_of_bounds | P1 | | E4301 task.live_child_escape | P3 |
| E2104 memory.region_generation | P1 | | E4302 task.borrow_escape | P3 |
| E2110 island.escape | P4 | | E4303 io.buffer_in_flight | P3 |
| E2111 island.foreign_mutable_edge | P4 | | E5001 air.invalid_ssa | P0 |
| E3001 resource.use_after_consume | P2 | | E5002 air.invalid_cfg | P0 |
| E3002 resource.leak | P2 | | E5101 verifier.resource_limit | P0 |
| E6001 unsafe.required | P2 | | E6101 abi.unaligned_reference | P7 |
- task scopes;
- spawn/join;
- `Send` / `Share` derivation;
- scoped borrowing;
- bounded channels;
- mutex;
- cancellation;
- deterministic scheduler.
## Cross-cutting tracks
Exit criterion: parallel-map and channel ownership-transfer examples.
These run through all phases rather than belonging to one.
## Phase 4 — Islands
| Track | Rule |
|---|---|
| Spec | Each phase's first tasks update `../spec/` and the open-questions log. RFCs 0001–0004 move to Accepted in the phase that implements them (P1, P3, P5, P0 respectively). |
| Diagnostics | New codes are added to `../reference/error-codes.md` and `src/diag.zig` together; structured fields per code are documented in the spec section that defines the rule. |
| Determinism | Every run test is executed twice and compared from P0-12 on; concurrency tests add schedule stress from P3. |
| Audit reports | Each phase that adds an auditable fact (unsafe sites, effects, capabilities, weak atomics, eliminated checks) extends the report in `src/report/` (spec 10 §6, spec 13 §5). |
| Packages | Minimal `aji.toml` reading for capabilities in P2; dependencies, lockfile and sandboxed build extensions in P8 (spec 12). |
Deliver:
## Task conventions
- island allocator;
- `iref<T>`;
- closure verification;
- move/transfer;
- freeze;
- `Frozen<T>`.
- IDs are `P<phase>-<n>` and never reused. A task split later becomes `P1-4a`, `P1-4b`.
- Status lives in the phase file's task table: `todo`, `doing`, `done`, `dropped`. Update it in the same change that completes the task.
- `Done when` is the acceptance test. If it cannot be checked mechanically, rewrite it.
- Discovered work goes into the current phase file as a new task, or into `../design/open-questions.md` if it is a spec gap.
Exit criterion: cyclic graph can move between tasks with no deep copy and no shared mutation.
## Status
## Phase 5 — Atomics and memory model
Deliver:
- atomic scalar types;
- all five orderings;
- fences;
- happens-before model in interpreter/testing tools;
- weak-atomic audit marking;
- schedule exploration.
Exit criterion: atomic publication litmus/conformance tests.
## Phase 6 — Source language
Deliver:
- source parser;
- source-to-AIR lowering;
- generics/monomorphization;
- contracts syntax;
- formatter.
Exit criterion: all reference programs authored primarily as `.aji`.
## Phase 7 — Native backend
Deliver:
- LLVM lowering;
- Linux x86_64;
- Linux aarch64;
- macOS aarch64;
- ABI tests.
Exit criterion: interpreted and native executions pass the same conformance corpus.
## Phase 8 — Agent protocol
Deliver:
- `ajid`;
- structured diagnostics;
- inspect/trace endpoints;
- machine-readable verifier state summaries;
- benchmark protocol.
Exit criterion: an external coding agent can implement/repair a reference task using only the protocol and repository spec.
| Phase | Status |
|---|---|
| P0 | not started |
| P1–P8 | not started |