Owner rules: addressability is decided by lowering (a variable that is borrowed, indexed or written through a place gets frame storage in the entry block; otherwise SSA; by name, deterministic); borrows are bound only by 'ref r = place;' / 'mut r = place;' and live to the end of the block (borrow.end at every normal exit, including break/continue/return); no shadowing of an active borrow in the same scope; ref/mut as call arguments are temporaries ended after the call; *r only for scalar and struct referents, slices via s[i], s[a..b], s.len; writes *r = v, r.f = v, s[i] = v with the value evaluated first; split_at as the only multi-result binding; slice.copy(mut dst, ref src) as the only copy; [e; N] evaluates e once; byte strings as [u8; N] in frame storage with a fixed escape set; borrow.index.proven only for the verifier's own fact form (if i < s.len, same SSA values), otherwise checked. Diagnostics on lowered AIR are deduplicated per code and source location. aji lower --stats counts code only (no comment lines). Tests: 10 run (architecture goldens: value-only has no local.alloc, borrowed has local.alloc, proven indexing), 6 rejects incl. verifier-caught E2101 (aliasing; parent used after split_at). Expansion on these programs: 4-9x bytes, 2.2-6.6x lines.
63 lines
6.4 KiB
Markdown
63 lines
6.4 KiB
Markdown
# Phase 6 — Source language
|
||
|
||
Non-normative. Part of the [implementation plan](README.md).
|
||
|
||
**Goal:** `.aji` source that lowers deterministically and explicitly to AIR, with diagnostics mapped back to source spans.
|
||
|
||
**Phase 6A (brought forward, owner decision 2026-10-05).** First a minimal frontend for the frozen semantics of Phases 0–3, with no new semantics. Its principle: `.aji` removes mechanical work but never hides a semantically significant action.
|
||
|
||
| | |
|
||
|---|---|
|
||
| **Removed** | SSA values, block parameters, the hand-written CFG, the `features [...]` header (inferred), intermediate values, boilerplate |
|
||
| **Kept explicit** | move, borrow and mutable borrow, allocation, resource ownership, capabilities, effects, task spawn and join, channel ownership transfer, locking, cancellation, fallible I/O |
|
||
|
||
Targets and the evaluation order are in `README.md`. Phase 6A is specified by RFC 0013. Generics, contracts, modules and the formatter (P6-4, P6-6, P6-8) stay for the full Phase 6.
|
||
|
||
**Exit criterion:** all reference programs and `examples/` are authored primarily as `.aji` and pass the conformance corpus through the frontend.
|
||
|
||
**Spec inputs:** spec 01, 02, 03 §4, 06 §3–4, 13 §1–2; `reference/grammar.ebnf`.
|
||
|
||
**Rule:** a source feature is acceptable only if its lowering to AIR is deterministic, explicit and mechanically verifiable (spec 01 §8). The frontend is outside the TCB; the verifier still checks its output.
|
||
|
||
## Phase 6A tasks (RFC 0013, spec 15)
|
||
|
||
| ID | Status | Task | Depends | Output | Done when |
|
||
|---|---|---|---|---|---|
|
||
| P6A-1 | done | Spec 15, grammar, `E7xxx`, `E3101` `suggested_effects`, `E0006` `canonical_header`, Quick Reference | — | spec 15, `reference/grammar.ebnf`, `docs/agent/quick-reference.md` | RFC 0013 accepted |
|
||
| P6A-2 | done | Lexer and parser with spans (full 6A grammar; one precise `E7001`, no recovery) | P6A-1 | `src/frontend/{lex,parse}.zig` | every spec 15 example parses; syntax errors are `E7001` |
|
||
| P6A-3 | doing | Names and source types: variables, functions, types, built-in operations, outcome arms | P6A-2 | `src/frontend/check.zig` | `E7002`–`E7007` accept/reject tests |
|
||
| P6A-4 | doing | Lowering: control flow, variables → SSA/block parameters, frame storage, lexical borrow ends, outcome matches, block forms (`scope`, `shield`, `lock`), `select`, byte literals, feature closure | P6A-3 | `src/frontend/lower.zig` | lowered AIR verifies; lowering is a pure function |
|
||
| P6A-5 | done | Source spans on lowered AIR; verifier diagnostics and trap records carry `source_location` and `air_location` | P6A-4 | `src/frontend/spans.zig`, `src/diag.zig` | every diagnostic of a `.aji` file points at source |
|
||
| P6A-6 | done | CLI: `aji check/run/lower file.aji` | P6A-4 | `src/main.zig` | same flags and run record as for `.air` |
|
||
| P6A-7 | todo | `.aji` twins for the Phase 0–3 conformance tests (same outcome or code) and the reference programs | P6A-5 | `tests/conformance/*/source/` | twins pass; the reference programs in `.aji` pass `--stress` |
|
||
| P6A-8 | todo | Source bundle and harness profile `aji_source` (Quick Reference first, full material indexed) | P6A-6 | `docs/agent/`, `tools/eval/languages/aji_source.json` | bundle measured |
|
||
| P6A-9 | todo | Dev regression on tasks M and C: `Aji/AIR` vs `Aji/source` (size, output tokens, tool calls, bundle use, diagnostics) | P6A-8 | results note | targets checked (≤ 1.5× Rust size, ≤ 2× output tokens, no SSA/CFG or `E0006` diagnostics) |
|
||
| P6A-10 | todo | Phase 6A exit review | all | plan status | targets reported |
|
||
|
||
Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) and verifier-caught tests in `tests/conformance/source/`:
|
||
|
||
| Layer | Content | Status |
|
||
|---|---|---|
|
||
| 1 | scalars, expressions, functions, control flow, variables carried across joins, short-circuit `and`/`or`, casts | done |
|
||
| 2 | structs (named construction, declaration-order lowering), enums (`Enum::Variant`), exhaustive `match` over enums (no `_`) and integers (`_` required), `match` as an expression; outcome matches and `or trap` move to layer 5 with the fallible operations | done |
|
||
| 3–4 | addressable values (frame storage chosen by lowering), lexical borrows (`ref r = …;`/`mut r = …;`), places and writes, arrays, slices, `split_at`, `slice.copy`, byte strings, proven indexing for the verifier's fact form; `move` comes with linear values in layer 5 | done |
|
||
| 5 | `own`, regions, resources, unsafe | todo |
|
||
| 6 | capabilities, intrinsics, I/O | todo |
|
||
| 7 | tasks, channels | todo |
|
||
| 8 | `lock`, `select`, cancellation, shields | todo |
|
||
|
||
## Tasks (full Phase 6)
|
||
|
||
| ID | Status | Task | Depends | Output | Done when |
|
||
|---|---|---|---|---|---|
|
||
| P6-1 | todo | Complete the source grammar: expressions, `match`, `borrow` blocks, `task.scope`, `select`, `defer`, `?`, generics, lifetimes, contracts, attributes | — (may start after P2) | `reference/grammar.ebnf`, spec 01 | every construct in `examples/` is covered; grammar is LL(k) or otherwise documented as unambiguous |
|
||
| P6-2 | todo | Lexer and parser with spans | P6-1 | `src/frontend/{lex,parse}.zig` | all `examples/` parse; syntax errors are registered diagnostics |
|
||
| P6-3 | todo | Modules, imports, name resolution | P6-2 | `src/frontend/resolve.zig` | unresolved names produce registered diagnostics |
|
||
| P6-4 | todo | Type checking and monomorphized generics with structural constraints (`Copy`, `Send`, `Share`, `Freeze`, `Local`) | P6-3 | `src/frontend/types.zig` | generic code instantiates deterministically; constraint violations diagnosed |
|
||
| P6-5 | todo | Lowering to AIR: control flow, `?`, `defer` cleanup edges, borrow blocks, task scopes | P6-4 | `src/frontend/lower.zig` | lowered AIR verifies; lowering is a pure function (same input ⇒ same AIR bytes) |
|
||
| P6-6 | todo | Contracts: `requires`/`ensures`/invariants → contract table; status classification | P6-5 | frontend + verifier | each contract reported as PROVEN_STATICALLY / CHECKED_AT_RUNTIME / ASSUMED_UNSAFE / UNPROVEN |
|
||
| P6-7 | todo | Source spans in diagnostics for verifier errors on lowered AIR | P6-5 | `src/diag.zig`, lowering | every conformance reject test has a source-level twin with the same code |
|
||
| P6-8 | todo | Formatter | P6-2 | `aji fmt` | idempotent; output parses to the same AST |
|
||
| P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes |
|
||
| P6-10 | todo | Phase exit review | all | plan status | exit criterion passes |
|