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:
1 parent
61be766634
commit
3e2d9b63a7
35 files changed
+1170
-106
No files matched your search
+30
-1
@@ -50,6 +50,35 @@ Growth never blocks a merge automatically; a complex feature can be justified, b
|
||||
|
||||
RFC 0011 crossed the 10 % warning line (its own estimate said "below 10 %"): four new sections in spec 04 (tasks, loans, `Send`/`Share` table, scheduler). Below the 20 % review threshold. RFC 0012 (+15.8 %, estimate 12–16 %): five sections in spec 04 (waits and cancellation, channels, select, mutex, critical-section rule). Implementation-time spec corrections (mutex linearity, `mutex.take` rules): +0.6 %. Phase 3 total since the Phase 2 baseline: +29.2 %. Next measurement: after the E-S smoke test, or with the next RFC.
|
||||
|
||||
## Source Reference Bundle (condition `Aji/source`)
|
||||
|
||||
The `.aji` condition does not get the AIR bundle as its documentation. It gets a directory mounted at `/docs` with a small front door, and the agent reads the rest only when it needs it. That tests a second hypothesis: a model can work from a small reference and selective reading.
|
||||
|
||||
| Path | Contents | cl100k tokens |
|
||||
|---|---|---:|
|
||||
| `QUICK.md` | the Quick Reference, then a table of which file to open for what | ~4.4k |
|
||||
| `language/syntax.md` | grammar, spec 15 §1, §2, §4–§6 | ~5.4k |
|
||||
| `language/types.md` | spec 15 §3, integer semantics, type properties, traps | ~1.0k |
|
||||
| `language/ownership.md` | spec 15 §9, aliasing, borrow lifetime, stack storage, slices, initialization (spec 03) | ~1.0k |
|
||||
| `language/memory.md` | `Own<T>`, regions, allocation authority (spec 03) | ~1.4k |
|
||||
| `language/effects-capabilities.md` | spec 05 §2–§5, §9–§10, effect and capability registries | ~4.4k |
|
||||
| `language/io-resources.md` | spec 15 §8, spec 06 §1–§3, §7, intrinsic registry | ~3.0k |
|
||||
| `language/concurrency.md` | implementation status, spec 15 §7, `Send`/`Share`, scheduler | ~2.2k |
|
||||
| `language/tooling.md` | spec 15 §11, execution limits and profiles (spec 11) | ~2.2k |
|
||||
| `diagnostics/errors.md` | spec 15 §10, stable codes, repair loop, error-code registry | ~1.9k |
|
||||
| `air/reference.md` | the whole AIR bundle, for reading `aji lower` output only | ~35.7k |
|
||||
|
||||
Without `air/` it comes to about 26.8k tokens. The manifest is [`source-bundle.txt`](source-bundle.txt): the `bundle.txt` syntax, plus `> path` to start an output file and `@manifest` to include another bundle. Text that exists only for this bundle (navigation, implementation status) is in [`source-notes.md`](source-notes.md).
|
||||
|
||||
```sh
|
||||
zig build agent-reference # also writes zig-out/agent/source/ and source-report.json
|
||||
uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source
|
||||
```
|
||||
|
||||
The groups `quick_reference`, `source_docs` and `air_docs` come from the `doc_groups` of the language profile `tools/eval/languages/aji_source.json`. The harness reports reading per group with the same definition (`docs/evaluation/harness.md`, context metrics). An agent writing `.aji` that reads much of `air/` is a signal: either the source documentation is not self-sufficient, or diagnostics are still too AIR-centric.
|
||||
|
||||
## Quick Reference (`.aji`)
|
||||
|
||||
[`quick-reference.md`](quick-reference.md) is the agent's first entry for the condition `Aji/source`. It is 4–6k tokens (currently about 3.6k, cl100k), covers most programs and has an index into the full reference (owner decision after the native smoke). It is kept consistent with spec 15. Its size and the `unique_reference_tokens` that agents actually read are measured alongside the bundle. The source-condition bundle, with the semantic rules restated in source terms, follows once the frontend exists.
|
||||
[`quick-reference.md`](quick-reference.md) is the front door of the Source Reference Bundle (`QUICK.md`). It targets 4–6k tokens (about 4.4k with the navigation table, cl100k), covers most programs, and is kept consistent with spec 15.
|
||||
|
||||
**Its examples are checked.** Every ```aji block must be an excerpt of a program in `tests/conformance/source/quickref/`. Comments and whitespace are ignored, and `…` matches any text. Those programs are conformance tests, so each example is part of a program that verifies and runs. `zig build test` and `zig build agent-reference` fail on an example that is not. The concurrency programs (§7) are PENDING until layers 7–8 exist.
|
||||
@@ -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` |
|
||||
@@ -0,0 +1,78 @@
|
||||
# Source Reference Bundle manifest (condition Aji/source, spec 14 §3.7).
|
||||
#
|
||||
# A directory mounted at /docs. QUICK.md is the front door: it covers most
|
||||
# programs and says which file to open for the rest. The agent reads the
|
||||
# other files only when it needs them; air/ is the AIR reference, for
|
||||
# reading the output of `aji lower` only. Entry syntax: bundle.txt, plus
|
||||
# > <path> starts the output file <path>
|
||||
# @<manifest> the single output of another manifest
|
||||
|
||||
> QUICK.md
|
||||
docs/agent/quick-reference.md
|
||||
docs/agent/source-notes.md :: ## 9. Where to read more
|
||||
|
||||
> language/syntax.md
|
||||
docs/reference/grammar.ebnf
|
||||
docs/spec/15-source-language.md :: ## 1. Principle
|
||||
docs/spec/15-source-language.md :: ## 2. Modules and declarations
|
||||
docs/spec/15-source-language.md :: ## 4. Statements and control flow
|
||||
docs/spec/15-source-language.md :: ## 5. Expressions
|
||||
docs/spec/15-source-language.md :: ## 6. Fallible operations and `match`
|
||||
|
||||
> language/types.md
|
||||
docs/spec/15-source-language.md :: ## 3. Types
|
||||
docs/spec/02-types-and-values.md :: ## 2. Integer semantics
|
||||
docs/reference/type-properties.md
|
||||
docs/spec/01-language-overview.md :: ## 6. Trap
|
||||
|
||||
> language/ownership.md
|
||||
docs/spec/15-source-language.md :: ## 9. Frame storage, borrow scopes and features
|
||||
docs/spec/03-memory-model.md :: ## 3. Safe-reference aliasing rule
|
||||
docs/spec/03-memory-model.md :: ## 4. Borrow lifetime
|
||||
docs/spec/03-memory-model.md :: ## 6. Stack storage
|
||||
docs/spec/03-memory-model.md :: ## 9. Slices
|
||||
docs/spec/03-memory-model.md :: ## 10. Initialization policy
|
||||
|
||||
> language/memory.md
|
||||
docs/spec/03-memory-model.md :: ## 7. Own<T>
|
||||
docs/spec/03-memory-model.md :: ## 8. Regions
|
||||
docs/spec/03-memory-model.md :: ## 18. Allocation authority in AIR
|
||||
|
||||
> language/effects-capabilities.md
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 2. Effects
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 3. Capabilities
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 4. Narrowing
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 5. Capability transfer
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 9. Effects in AIR
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 10. Capabilities in AIR
|
||||
docs/reference/effects.md
|
||||
docs/reference/capabilities.md
|
||||
|
||||
> language/io-resources.md
|
||||
docs/spec/15-source-language.md :: ## 8. Allocation, resources and intrinsics
|
||||
docs/spec/06-resources-and-errors.md :: ## 1. Linear resources
|
||||
docs/spec/06-resources-and-errors.md :: ## 2. Typestate
|
||||
docs/spec/06-resources-and-errors.md :: ## 3. Cleanup
|
||||
docs/spec/06-resources-and-errors.md :: ## 7. I/O errors
|
||||
docs/reference/intrinsics.md
|
||||
|
||||
> language/concurrency.md
|
||||
docs/agent/source-notes.md :: ## Concurrency status
|
||||
docs/spec/15-source-language.md :: ## 7. Tasks, cancellation, channels, select and mutex
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 35. Send and Share in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 36. The deterministic scheduler
|
||||
|
||||
> language/tooling.md
|
||||
docs/spec/15-source-language.md :: ## 11. Tooling
|
||||
docs/spec/11-determinism-and-replay.md :: ## 7. Execution limits
|
||||
docs/spec/11-determinism-and-replay.md :: ## 8. Execution profiles
|
||||
|
||||
> diagnostics/errors.md
|
||||
docs/spec/15-source-language.md :: ## 10. Diagnostics
|
||||
docs/spec/10-diagnostics-and-agent-protocol.md :: ## 2. Stable codes
|
||||
docs/spec/10-diagnostics-and-agent-protocol.md :: ## 5. Expected repair loop
|
||||
docs/reference/error-codes.md
|
||||
|
||||
> air/reference.md
|
||||
docs/agent/source-notes.md :: ## The AIR reference
|
||||
@docs/agent/bundle.txt
|
||||
@@ -0,0 +1,30 @@
|
||||
# Source Reference Bundle notes
|
||||
|
||||
Text that exists only for the Source Reference Bundle (`source-bundle.txt`). Non-normative: it points at the normative files and states which source layers are implemented.
|
||||
|
||||
## 9. Where to read more
|
||||
|
||||
The other files in `/docs` hold the full rules. Open one only when this page is not enough.
|
||||
|
||||
| Need | Read |
|
||||
|---|---|
|
||||
| exact syntax, every construct, `match` and outcomes | `/docs/language/syntax.md` |
|
||||
| integer semantics, conversions, Copy/Send/Share, traps | `/docs/language/types.md` |
|
||||
| borrows, scopes, frame storage, slices, initialization | `/docs/language/ownership.md` |
|
||||
| `own`, regions, allocation budgets | `/docs/language/memory.md` |
|
||||
| effects, capabilities, grants, narrowing | `/docs/language/effects-capabilities.md` |
|
||||
| files, streams, stdin/stdout, intrinsic operand tables, `io_error` | `/docs/language/io-resources.md` |
|
||||
| tasks, channels, select, mutex, cancellation | `/docs/language/concurrency.md` |
|
||||
| `aji` commands, run records, fuel, profiles | `/docs/language/tooling.md` |
|
||||
| a diagnostic code (`E2101`, `T0008`, …) | `/docs/diagnostics/errors.md` |
|
||||
| the AIR printed by `aji lower`, `air_line`/`air_col` in a diagnostic | `/docs/air/reference.md` |
|
||||
|
||||
You write `.aji`; you never need to write AIR. Diagnostics point at your source (`file`, `line`, `col`).
|
||||
|
||||
## Concurrency status
|
||||
|
||||
The source frontend implements layers 1–6 of spec 15. Layers 7 (tasks, channels) and 8 (`lock`, `select`, cancellation, shields) are not implemented yet: a program that uses `scope`, `task.*`, `channel.*`, `mutex.*`, `lock`, `select` or `shield` is reported as not implemented (exit code 3). The rules below describe the language as specified.
|
||||
|
||||
## The AIR reference
|
||||
|
||||
This file is the reference for text AIR format 0, the language `.aji` lowers to. You do not need it to write `.aji`. It explains what `aji lower` prints and the `air_line`/`air_col` fields of diagnostics.
|
||||
Reference in new issue
Block a user