Phase 2: I/O intrinsics, linear resources, deterministic profile (RFC 0007)

- air: resource types file<read|write|append>, listener, stream; io_error;
  intrinsic registry (19 intrinsics) synced with reference/intrinsics.md;
  fallible intrinsics as ok/err terminators; fs prefix narrowing;
  linear_aggregates gating
- verifier: intrinsic form, operand, result and capability-kind checks
  (E1001, E3201, E5002); intrinsic effects (E3101); resource linearity
  in the borrow walker with per-edge moves: E3002 leaks and join
  mismatches, E3001, E2001, E2002, E2101 for close while borrowed;
  resources as borrow roots
- interp: deterministic world (captured console, VFS, loopback TCP,
  instruction clock, pinned xoshiro256 PRNG), blocked outcome, run
  record with stdout/stderr/files
- CLI: --stdin, --vfs, --seed, --result-file, --profile (hosted: exit 3),
  exit code 7; runner: stdin/vfs/seed/stdout/stderr/file/blocked headers
- conformance: hello, file copy and TCP echo exit programs; 37 new tests;
  4000 mutants without a crash
This commit is contained in:
dev committed 2026-10-04 14:02:17 +03:00
1 parent 571cc6e362
commit d405d4ea50
49 files changed
+2325 -81

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@ Reason: Zig's standard library changes between minor versions; an unpinned toolc
## DD-009 — CLI diagnostics are JSON Lines on stdout
`aji` writes one JSON diagnostic per line on stdout, human notes on stderr, and uses fixed exit codes (0 accepted or returned, 1 rejected, 2 usage/I/O, 3 not yet implemented, 4 trapped, 5 execution limit exceeded, 6 not instantiated).
`aji` writes one JSON diagnostic per line on stdout, human notes on stderr, and uses fixed exit codes (0 accepted or returned, 1 rejected, 2 usage/I/O, 3 not yet implemented, 4 trapped, 5 execution limit exceeded, 6 not instantiated, 7 blocked).
Reason: agents consume diagnostics programmatically (spec 10); mixing prose into the machine channel breaks repair loops.
+1
View File
@@ -32,6 +32,7 @@ Planned header extensions (added by the phase that needs them):
|---|---|---|
| `expect: run` + `result:` / `trap:` | P0 (implemented) | module must verify; run record must match |
| `stdout:` | P2 | expected output, `\n`-escaped (needs `io.write`) |
| `stdin:` / `vfs:` / `seed:` / `stdout:` / `stderr:` / `file:` / `blocked:` | P2 (implemented) | deterministic world inputs and expected observable output |
| `grant:` / `not_instantiated:` | P2 (implemented) | capability grants for `@main`; expected instantiation failure |
| `fuel:` | P0 (implemented) | instruction limit; default 1 000 000 (spec 11 §7.1) |
| `seed:` / `schedules:` / `quantum:` | P3 | scheduler seed / schedule budget / instructions per forced scheduling point (spec 11 §7.2) |
+1 -1
View File
@@ -99,5 +99,5 @@ These run through all phases rather than belonging to one.
|---|---|
| P0 | done; AIR format 0 frozen as the semantic baseline (spec 07 §8.7) |
| P1 | done (exit review in the phase file) |
| P2 | in progress: RFC 0006 (effects, capabilities) accepted and implemented; next RFC 0007 (I/O) and RFC 0008 (heap, regions) |
| P2 | in progress: RFC 0006 (effects, capabilities) and RFC 0007 (I/O, resources, deterministic profile) implemented; next RFC 0008 (heap, regions), hosted profile, unsafe boundaries |
| P3–P8 | not started |
@@ -21,21 +21,22 @@ Out: tasks, threads, async I/O (P3); FFI to native code (P7).
| 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 | todo | 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-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 | todo | 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 | todo | 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 | todo | 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 | todo | Interpreter heap and regions | P2-2b | `src/interp/memory.zig` | run tests; file-copy with a heap-backed region buffer |
| P2-3 | todo | Contract tables for `intrinsic.call`, `resource.consume`, `call.indirect` | P2-1 | spec 07 appendix | all spec 07 §4 fields present |
| P2-4 | doing | Effect verifier (calls done; intrinsics with RFC 0007) | P2-1 | `src/verifier/effects.zig` | E3101 accept/reject, including transitive callees |
| P2-5 | doing | Capability verifier: unforgeability, narrowing, transfer rules (types, E3202, instantiation done; E3201 with intrinsics) | P2-1 | `src/verifier/caps.zig` | E3201, E3202 accept/reject |
| P2-6 | todo | Linear resource and typestate verifier | P2-3 | `src/verifier/resource.zig` | E3001, E3002 accept/reject; leak on an error path detected |
| 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 | todo | Unsafe boundary verifier | P2-3 | `src/verifier/unsafe.zig` | E6001 accept/reject |
| P2-8 | todo | 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-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 | todo | 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-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 | 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
+1 -1
View File
@@ -242,4 +242,4 @@ Resource types and their consumption rules: spec 06 §6. Resources are used thro
On a trap it reports `{"status":"trapped", "code":…, "kind":…, "function":…, "block":…, "inst":…}` (spec 01 §6).
Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (captured output) and `"files"` (files written in the virtual file system) in the record of the `deterministic` profile (spec 11 §8). When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
Programs that declare `capabilities` also get `"stdout"` and `"stderr"` (captured output) and `"files"` (files written in the virtual file system, keyed by path in byte order) in the record of the `deterministic` profile (spec 11 §8). These byte strings are written as JSON strings in which printable ASCII other than `"` and `\` appears as is, `"`, `\` and newline are escaped as `\"`, `\\` and `\n`, and every other byte `b` as `\u00XX`, so any output is valid, deterministic JSON. When the deterministic runtime detects quiescence it reports `{"status":"blocked","kind":"no_future_event",…}` (spec 11 §8). When instantiation fails (spec 05 §10.2) the program does not start and the runner reports `{"status":"not_instantiated","reason":…,…}`. When the runner stops execution because an execution limit is exhausted (spec 11 §7), it reports `{"status":"limit_exceeded","kind":"fuel","limit":N,"steps":N}`. This is an outcome of the execution environment, not of the program, and is not a trap.
+1 -1
View File
@@ -115,7 +115,7 @@ The run record gains fields for observable output. `aji run` uses the **determin
| files | in-memory file system seeded by `--vfs PATH=TEXT`; files written during the run are reported as `"files"` in the run record | real file system, limited by capability scopes |
| network | in-process loopback: `net.connect` to a listening address of the same run queues a connection that `net.accept` returns; sends are buffered; an operation that would wait for an event that can never occur ends the run with the environment outcome `blocked` (below) | real sockets |
| clock | the number of instructions executed so far (1 ns per instruction) | real monotonic clock |
| random | PRNG seeded by `--seed N` (default 0), algorithm fixed by the spec | host CSPRNG |
| random | xoshiro256\*\* whose state is initialized by SplitMix64 from `--seed N` (default 0); bytes are taken from successive 64-bit outputs, least significant byte first | host CSPRNG |
**Quiescence.** In the `deterministic` profile, when an operation would wait, no other execution unit can run, and no future deterministic event can complete the wait, the run ends with the environment outcome