P6A-8: Source Reference Bundle and harness profile aji_source

- source bundle: a /docs directory with QUICK.md (Quick Reference plus a
  where-to-read table), language/*.md, diagnostics/errors.md and the AIR
  bundle only under air/; built from docs/agent/source-bundle.txt
  (> output files, @manifest includes) by zig build agent-reference
- Quick Reference examples are checked: every aji block must be an
  excerpt of a conformance program in tests/conformance/source/quickref
  (zig build test fails otherwise); QR fixes found by the check
  (mut d = data, region not auto-borrowed, statement/borrow blocks that
  could not verify, io_error match)
- frontend: task.*/channel.*/mutex.* are not-yet-implemented, not E7006
- aji lower --stats: mechanical_air_eliminated_raw and _normalized (each
  byte-string materialization counted as one constant; spec 15 §11)
- harness: profile aji_source (doc_groups), per-file and per-group docs
  metrics on distinctive lines, profile columns (tool calls, lowered AIR
  raw/normalized, docs files read, IR-form and type-mismatch counts),
  dev-echo aji_source variant, scripted run and test, source token report
- plan: P6A-8 done, P6A-9 criteria; Q-021/Q-022 resolved; unsafe block
  deferred
This commit is contained in:
dev committed 2026-10-05 13:16:51 +03:00
1 parent 61be766634
commit 3e2d9b63a7
35 files changed
+1170 -106

No files matched your search

+28 -31
View File
@@ -1,6 +1,6 @@
# Aji Quick Reference (`.aji` 0.1)
Read this first; it covers most programs. The full rules live in the reference index at the end. `aji check file.aji` verifies, `aji run file.aji` verifies and runs, `aji lower file.aji` prints the AIR it becomes. Diagnostics are JSON lines; fix the first one first.
Read this first; it covers most programs. Where to find the full rules is at the end. Every example below is part of a program the conformance suite checks. `aji check file.aji` verifies, `aji run file.aji` verifies and runs, `aji lower file.aji` prints the AIR it becomes. Diagnostics are JSON lines; fix the first one first.
Aji makes every significant action explicit — moves, borrows, allocation, closing, authority, effects, tasks, channel transfers, locking, cancellation, every failure outcome — and checks them all before running. The compiler writes the mechanics: SSA, control flow, borrow ends, frame storage, the feature header.
@@ -50,15 +50,16 @@ var i: usize = 0; // variable; reassign with i = i + 1;
var buf: [u8; 16] = zero; // zero-initialized storage
if c { … } else if d { … } else { … }
while i < n { … }
for i in 0..n { … } // 0 ≤ i < n
for k in 0..n { … } // 0 ≤ k < n
loop { … break; … continue; … }
return v; trap; assert(c);
let y = if c { 1 } else { 2 }; // value-producing if/match: tail expression without `;`
let w: u64 = match m { // enum match: exhaustive, one arm per variant
Message::Stop => 0,
Message::Value(x) => x, // x exists only in this arm
Message::Value(v) => v, // v exists only in this arm
};
match d { 0 => { … } 1 => { … } _ => { … } } // integer match: `_` required
match t { 0 => { … } 1 => { … } _ => { … } } // integer match: `_` required
assert(c); // traps T0002 when false
return x + y + w; // also: `trap;`
```
| Operation | Meaning |
@@ -80,14 +81,19 @@ There is one spelling per construct: no `+=`, no alternative syntax.
```aji
var data: [u64; 8] = zero;
data[0] = 7; // element write (array variables get frame storage automatically)
mut s = data; // bind an exclusive borrow (an array is borrowed as slice_mut<u64>)
s[1] = s[0] + 1; // checked index; out of range traps T0008
let n = s.len;
if i < s.len { s[i] = 0; } // no runtime check here: the verifier proves i < s.len
let (l, r) = s.split_at(4); // two disjoint halves of s
{
mut s = data; // exclusive borrow to the end of this block (an array is borrowed as slice_mut<u64>)
s[1] = s[0] + 1; // checked index; out of range traps T0008
let n = s.len;
if i < s.len { s[i] = 0; } // no runtime check here: the verifier proves i < s.len
let (l, r) = s.split_at(4); // two disjoint halves of s
…
}
slice.copy(mut out[0..4], ref data[4..8]); // borrows as arguments end after the call
…
ref q = p; // shared borrow of a struct; q.a reads a field
*c = *c + 1; // through mut<u64>
…
*c = *c + 1; // through c: mut<u64>
```
Rules (checked by the verifier):
@@ -103,9 +109,10 @@ Rules (checked by the verifier):
```aji
match fs.open_read(c, b"/data/in.txt") {
ok(f) => { … use f … ; fs.close(move f) or trap; }
ok(f) => { …; fs.close(move f) or trap; }
err(e) => { return 1u8; }
}
…
let n = net.recv(conn, mut buf) or trap; // any non-ok outcome traps
```
@@ -134,6 +141,7 @@ A region allocation needs an explicit borrow of the region that outlives the all
ref arena = r;
let item = region.new(arena, 1u64) or trap; // item: mut<u64>, ends with this block
*item = *item + 1;
…
}
region.reset(r);
```
@@ -141,19 +149,22 @@ region.reset(r);
`err(e)` binds a real value: `match e { alloc_error::budget_exceeded => …, alloc_error::out_of_memory => … }`.
- **Narrowing:** `cap.narrow.prefix(c, b"/data")` and `cap.narrow.budget(heap, 4096)`, each giving `ok(c2) / err(e)`.
- Resource operands (`f`, `s`, `l`, `r`, endpoints) are borrowed automatically for an operation; data borrows (`mut buf`, `ref bytes`) are always written.
- Resource operands (`f`, `s`, `l`, endpoints) are borrowed automatically for an operation; a region is not (bind `ref arena = r;`); data borrows (`mut buf`, `ref bytes`) are always written.
- Memory budgets count live bytes, so freeing returns them. In the deterministic profile `mem.alloc` needs a grant with a budget: `--grant heap=mem.alloc:4096`.
## 7. Concurrency
Not implemented in the source frontend yet (layers 7–8): `aji check` reports these constructs as not implemented (exit code 3). They are shown as specified.
```aji
let d = mut data; // data: [u64; 8]
mut d = data; // data: [u64; 8]
scope s { // every task spawned in s must be joined before the block ends (E4301)
let (l, r) = d.split_at(4);
let a = task.spawn(s, square, l); // borrows are lent to the task until its join
let b = task.spawn(s, square, r);
let x = task.join(move a);
let y = task.join(move b);
…
}
```
@@ -174,11 +185,12 @@ scope s { // every task spawned in s must
```aji
match channel.make<u64>(2, heap) { // effect mem.alloc
ok(tx, rx) => {
let tx2 = channel.dup(tx);
let tx2 = channel.dup(tx); // another sender; close it too
…
match channel.send(tx, v) { ok => {} closed(v) => { … } cancelled(v) => { … } } // a linear v: `move v`
match channel.recv(rx) { ok(v) => { … } closed => { … } cancelled => { … } }
channel.close_sender(move tx);
match channel.close_receiver(move rx) { ok => {} pending(rx) => { … receive until closed, close again … } }
match channel.close_receiver(move rx) { ok => {} pending(rx) => { … } } // drain, then close again
}
err(e) => { trap; }
}
@@ -231,18 +243,3 @@ scope s { // every task spawned in s must
| E4301 | task not joined at scope end | `task.join(move t)` before the `scope` block ends |
| E4304 | wait inside `lock` | move the wait out of the `lock` block |
| T0001–T0009 | runtime trap | see `kind` and `source_location` |
## 9. Index into the full reference
| Topic | Section |
|---|---|
| source language, every construct | spec 15 |
| types, Send/Share | spec 02 §6; spec 04 §35 |
| borrows, frame storage | spec 08 §11; spec 15 §5, §9 |
| heap, regions, budgets | spec 03 §18–§20 |
| effects, capabilities, narrowing | spec 05 §9–§11; `reference/capabilities.md` |
| resources, I/O errors | spec 06 §6–§7; `reference/intrinsics.md` |
| tasks, loans, scheduler | spec 04 §33–§36 |
| waits, cancellation, channels, select, mutex | spec 04 §37–§41 |
| determinism, run records, profiles | spec 11 §7–§8 |
| all codes | `reference/error-codes.md` |