diff --git a/README.md b/README.md index 0964153..49a904a 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ zig build test # unit tests zig build conformance # conformance suite ``` -Current state: Phase 0 (semantic skeleton) is complete. `aji check` parses and verifies text AIR format 0, and `aji run` executes it deterministically. Phase 1 (ownership and memory) is next; see [`docs/plan/README.md`](docs/plan/README.md). +Current state: Phases 0 and 1 are complete. `aji check` parses and verifies text AIR format 0 with the features `ownership` (frame storage, second-class borrows) and `arrays` (arrays, slices, bounds proofs); `aji run` executes it deterministically. Phase 2 (effects, capabilities, heap, regions) is next; see [`docs/plan/README.md`](docs/plan/README.md). ```sh zig build run -- run tests/conformance/phase0/run/fibonacci.air diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 9087ee3..b024a43 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -25,6 +25,7 @@ Status values: `open`, `resolved`. | Q-017 | open | P5 | Replay file format | | Q-018 | resolved | P2 | Runtime diagnostics (traps) vs verifier diagnostics | | Q-019 | resolved | P3 | Non-terminating programs in test tooling | +| Q-020 | open | P2 | Size bound for SSA array values | ## Q-001 — Text AIR grammar @@ -129,3 +130,7 @@ The error registry covers verifier/compiler errors. Traps and runtime check fail A program may legitimately loop forever, so the language cannot bound execution. The conformance runner and `ajid` still need a way to stop a run without making the outcome depend on wall-clock time. Options: a deterministic step budget that is a tooling parameter (reported as "budget exhausted", never as a language trap), or explicit `fuel:` in test headers. Must be decided before scheduler stress tests (P3), which multiply run counts. **Resolved:** deterministic instruction fuel (spec 11 §7). Wall-clock time is never used to determine semantic test termination. Fuel exhaustion is an execution-runner outcome (`limit_exceeded`, CLI exit code 5), not an Aji trap. + +## Q-020 — Size bound for SSA array values + +Frame storage is bounded (`max_local_frame`, spec 08 §11.5), but an SSA value of type `array` (for example from `array.splat`) is bounded only by `N ≤ 2^32`. A module can therefore ask the interpreter for gigabytes in one instruction, and the outcome then depends on host memory. Options: apply the same accounted-size limit to every type in the module (E5101), or a separate `max_value_bytes`. Needs an owner decision; changing it later would turn accepted modules into rejected ones, so it should be settled before format 0 is released. diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index 0ab783d..f7e732d 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md @@ -33,25 +33,23 @@ src/ main.zig ✓ `aji` CLI check.zig ✓ parse → verify front door diag.zig ✓ diagnostic envelope, error-code registry - air.zig ✓ (stub) → air/ + air.zig ✓ re-exports air/ - types.zig type table, primitive and composite types - module.zig module, function, block, instruction, value ids - ops.zig opcode enum + per-opcode metadata (from contract tables) - parse.zig text AIR lexer and parser - print.zig canonical text serializer + module.zig ✓ types, module, function, block, instruction, value ids + features.zig ✓ feature registry and validation + parse.zig ✓ text AIR lexer and parser + print.zig ✓ canonical text serializer binary.zig binary AIR (after opcode freeze, RFC 0004) - verifier.zig ✓ (stub) → verifier/ + verifier.zig ✓ stage pipeline verifier/ - cfg.zig ssa.zig types.zig init.zig - ownership.zig borrow.zig region.zig island.zig + cfg.zig ✓ ssa.zig ✓ types.zig ✓ init.zig ✓ borrow.zig ✓ bounds.zig ✓ budget.zig ✓ + ownership.zig region.zig island.zig resource.zig effects.zig caps.zig send_share.zig tasks.zig atomics.zig - bounds.zig unsafe.zig - budget.zig deterministic resource budget (E5101) - interp.zig ✓ (stub) → interp/ + unsafe.zig + interp.zig ✓ re-exports interp/ - machine.zig values, frames, instruction dispatch + machine.zig ✓ values, frames, frame storage and borrows, dispatch memory.zig heap, regions, islands, provenance, generations sched.zig deterministic scheduler, seeds, choice recording weak.zig weak-memory model for atomics (P5) diff --git a/docs/plan/README.md b/docs/plan/README.md index 2a6e855..14ae0be 100644 --- a/docs/plan/README.md +++ b/docs/plan/README.md @@ -98,5 +98,6 @@ These run through all phases rather than belonging to one. | Phase | Status | |---|---| | P0 | done; AIR format 0 frozen as the semantic baseline (spec 07 §8.7) | -| P1 | in progress: RFC 0005 accepted and integrated (P1-1, P1-2) | -| P2–P8 | not started | +| P1 | done (exit review in the phase file) | +| P2 | next | +| P3–P8 | not started | diff --git a/docs/plan/phase-1-ownership-and-memory.md b/docs/plan/phase-1-ownership-and-memory.md index d99dbf0..e455ffe 100644 --- a/docs/plan/phase-1-ownership-and-memory.md +++ b/docs/plan/phase-1-ownership-and-memory.md @@ -22,12 +22,22 @@ Out: heap, regions, move-only values, borrow-typed block parameters (`borrow_joi |---|---|---|---|---|---| | P1-1 | done | Resolve Q-009 and Q-010; RFC 0005 accepted | — | RFC 0005 | owner accepted revision 2 | | P1-2 | done | Integrate RFC 0005 into the spec and registries | P1-1 | spec 03/07/07a/08, reference files | features `ownership`, `arrays` published | -| P1-3 | todo | Data model, parser and printer: new types, `from`, multi-result, opcodes; feature gating | P1-2 | `src/air/` | round-trip fuzz covers new forms; `feature_not_declared` tests | -| P1-4 | todo | Type rules: second-class rule, borrow/slice typing, zeroable types, `from` mode | P1-3 | `src/verifier/types.zig` | E1001 accept/reject pairs for each rule | -| P1-5 | todo | Frame rules: `local.alloc` only in entry (E5002), frame size limit (E5101) | P1-3 | `cfg.zig`, `budget.zig` | reject tests for both | -| P1-6 | todo | Initialization verifier | P1-4 | `src/verifier/init.zig` | E1010 accept/reject, including joins | -| P1-7 | todo | Borrow verifier | P1-6 | `src/verifier/borrow.zig` | E2101, E2102, E2105–E2108 accept/reject; path linearity across branches; join state equality | -| P1-8 | todo | Bounds facts for `borrow.index.proven` | P1-7 | `src/verifier/bounds.zig` | every row of the fact table accepted; `le i n` and other non-facts rejected (E2103) | -| P1-9 | todo | Interpreter: frame storage, borrows, slices, bounds traps (T0008) | P1-4 | `src/interp/` | run tests for every instruction; T0008 for each checked operation | -| P1-10 | todo | `aji features` lists `arrays`, `ownership`; conformance corpus for Phase 1 | P1-7…P1-9 | `tests/conformance/phase1/` | accept/reject/run tests for every new code and trap | -| P1-11 | todo | Phase exit review | all | plan status | exit criterion passes | +| P1-3 | done | Data model, parser and printer: new types, `from`, multi-result, opcodes; feature gating | P1-2 | `src/air/` | round-trip fuzz covers new forms; `feature_not_declared` tests | +| P1-4 | done | Type rules: second-class rule, borrow/slice typing, zeroable types, `from` mode | P1-3 | `src/verifier/types.zig` | E1001 accept/reject pairs for each rule | +| P1-5 | done | Frame rules: `local.alloc` only in entry (E5002), frame size limit (E5101) | P1-3 | `cfg.zig`, `budget.zig` | reject tests for both | +| P1-6 | done | Initialization verifier | P1-4 | `src/verifier/init.zig` | E1010 accept/reject, including joins | +| P1-7 | done | Borrow verifier | P1-6 | `src/verifier/borrow.zig` | E2101, E2102, E2105–E2108 accept/reject; path linearity across branches; join state equality | +| P1-8 | done | Bounds facts for `borrow.index.proven` | P1-7 | `src/verifier/bounds.zig` | every row of the fact table accepted; `le i n` and other non-facts rejected (E2103) | +| P1-9 | done | Interpreter: frame storage, borrows, slices, bounds traps (T0008) | P1-4 | `src/interp/` | run tests for every instruction; T0008 for each checked operation | +| P1-10 | done | `aji features` lists `arrays`, `ownership`; conformance corpus for Phase 1 | P1-7…P1-9 | `tests/conformance/phase1/` | accept/reject/run tests for every new code and trap | +| P1-11 | done | Phase exit review | all | plan status | exit criterion passes | + +## Exit review + +- Exit criterion met: `tests/conformance/phase1/run/file_copy_core.air` fills a local buffer, copies it into a second one in chunks with `slice.sub` + `slice.copy`, and returns `[0,1,…,9]`; every run is executed twice and compared. +- Corpus: 5 accept, 18 reject, 11 run tests. Every Phase 1 code has a reject test (E1001 rules, E1010, E2101, E2102, E2103, E2105–E2108, E5002, E5101, E0006 `feature_not_declared` and `borrow_joins`); T0008 has run tests for `borrow.index`, `slice.sub` (including the overflow case) and `slice.copy`. +- Every row of the fact table and the non-facts (`le i n`, `ge n i`, wrong edge, guard on a false-edge comparison, other slice, shared target block) have unit tests. +- 6 000 mutated Phase 1 modules through `aji check` and `aji run --fuel` without a crash. +- Spec clarification made during implementation: borrow, initialization and fact analysis cover blocks reachable from the entry block (spec 08 §11.4). Erratum: the array type is spelled `array` in text AIR (RFC 0005 header). +- Known limitation, not a soundness issue: the interpreter stores every element as a tagged value, so large arrays are memory-hungry; acceptable for conformance programs. +- Open for the owner: SSA array values (`array.splat`) are bounded only by `N ≤ 2^32`, not by the frame limit; see Q-020.