- air: string literals (trusted line only), trusted obligation on functions, assume, borrow.index.unchecked - verifier: unsafe stage (E6001 outside_boundary / trusted_declares_unsafe); effect stage leaves unsafe to it, so trusted functions discharge it; assume establishes bounds facts - interp: T0009 for detected unsafe precondition violations - aji check --report unsafe: trusted functions with obligations, unsafe functions, unsafe operations with their boundary - feature unsafe published and supported; 10 conformance tests; 3000 mutants without a crash
49 lines
4.9 KiB
Markdown
49 lines
4.9 KiB
Markdown
# Phase 2 — Effects, capabilities and resources
|
||
|
||
Non-normative. Part of the [implementation plan](README.md).
|
||
|
||
**Goal:** authority, allocation and external resources become verifiable: heap allocation (`Own<T>`) and regions (moved here from Phase 1, RFC 0005), effect sets, unforgeable capabilities with narrowing, linear resources with typestate, capability-gated runtime intrinsics, unsafe boundaries.
|
||
|
||
**Exit criterion:** safe file-copy and a basic (single-task) TCP echo run in the interpreter.
|
||
|
||
**Spec inputs:** spec 05, 06, 09 §1–3, 12 §1, 13 §3–5; `reference/intrinsics.md`.
|
||
|
||
**Blocking questions:** Q-011 effect hierarchy, Q-012 capability representation, Q-018 runtime diagnostics.
|
||
|
||
## Scope
|
||
|
||
In: effect declarations and transitive checking; `cap<…>` values, delegation and narrowing; linear `File`, `Socket` with typestate; `resource.consume`; `intrinsic.call`; explicit cleanup edges; `unsafe` boundaries in AIR; filesystem, console, network, clock and random intrinsics; `hosted` and `deterministic` profiles for I/O.
|
||
|
||
Out: tasks, threads, async I/O (P3); FFI to native code (P7).
|
||
|
||
## Tasks
|
||
|
||
| ID | Status | Task | Depends | Output | Done when |
|
||
|---|---|---|---|---|---|
|
||
| P2-1 | done | Resolve Q-011, Q-012, Q-018 (RFC 0006; Q-018 resolved in P0) | — | spec 05, 07, 10 | questions resolved; runtime record format defined |
|
||
| P2-2 | done | Formal signatures for fs, io, net, clock, random intrinsics | P2-1 | `reference/intrinsics.md` | each intrinsic lists types, effects, capabilities, ownership, failure, blocking (spec 09 §2) |
|
||
| P2-2a | done | Publish features `effects` and `capabilities` (spec text, registry status, `supported`); effect checking applies to modules declaring `effects` | P2-1 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests; baseline modules unaffected |
|
||
| P2-2b | done | Specify and publish `heap` (`Own<T>`, `own.alloc`, `own.free`, move-only values) and `regions` (static generations per Q-010); contracts in spec 07a | P2-2a | spec 03, 07a, 08; registry | features published |
|
||
| P2-2c | done | Ownership verifier for move-only values: use after move, double consume | P2-2b | `src/verifier/ownership.zig` | E2001, E2002 accept/reject (incl. `phase2/reject/use_after_move.air`) |
|
||
| P2-2d | done | Region verifier: reset/destroy with live borrows, prior-generation use; region-derived borrows as an escapable `from` source | P2-2b | `src/verifier/region.zig` | E2104 accept/reject |
|
||
| P2-2e | done | Interpreter heap and regions | P2-2b | `src/interp/memory.zig` | run tests; file-copy with a heap-backed region buffer |
|
||
| P2-3 | done | Contract tables for `intrinsic.call`, `resource.consume`, `call.indirect` | P2-1 | spec 07 appendix | all spec 07 §4 fields present |
|
||
| P2-4 | done | Effect verifier (calls and intrinsics) | P2-1 | `src/verifier/effects.zig` | E3101 accept/reject, including transitive callees |
|
||
| P2-5 | done | Capability verifier: unforgeability, narrowing, transfer rules (E3201, E3202, instantiation) | P2-1 | `src/verifier/caps.zig` | E3201, E3202 accept/reject |
|
||
| P2-6 | done | Linear resource and typestate verifier | P2-3 | `src/verifier/resource.zig` | E3001, E3002 accept/reject; leak on an error path detected |
|
||
| P2-7 | done | Unsafe boundary verifier (RFC 0009: assume, borrow.index.unchecked, trusted, unsafe report) | P2-3 | `src/verifier/unsafe.zig` | E6001 accept/reject |
|
||
| P2-8 | doing | Runtime intrinsics in the interpreter; virtual filesystem and loopback network for the `deterministic` profile | P2-2 | `src/runtime/` | intrinsic unit tests pass under both profiles; deterministic profile output identical across runs |
|
||
| P2-9 | doing | Entry-point capability instantiation (`--grant` done; `aji.toml` `[capabilities]` pending) | P2-5 | `src/runtime/host.zig` | missing grant fails instantiation, not execution (spec 05 §6) |
|
||
| P2-10 | todo | Reports: effect graph, capability requirements, unsafe sites | P2-4, P2-5, P2-7 | `src/report/` | deterministic JSON report; snapshot test |
|
||
| P2-11 | done | Reference programs: hello (real `io.write` if deferred from P0), file-copy, tcp-echo (single task) | P2-8 | `tests/programs/` | all three run; cleanup on every error path verified |
|
||
| P2-8a | todo | (after heap and regions, unsafe) Hosted profile: real console, files and TCP; run record through `--result-file` (spec 11 §8) | P2-8 | `src/interp/host.zig` | hello, file-copy and tcp-echo run against the real OS in CI |
|
||
| P2-12 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||
|
||
## Conformance tests to add
|
||
|
||
Negative corpus entries owned by this phase: missing capability, undeclared effect, linear resource leak. Plus E3001, E3202, E6001.
|
||
|
||
## Remaining order (owner decision)
|
||
|
||
RFC 0008 heap and regions → implementation and conformance → unsafe boundaries (P2-7) → hosted profile (P2-8a) → audit reports (P2-10) → `aji.toml` grants (P2-9). The memory model is completed in the deterministic world before the real OS widens the bug surface.
|