- 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
27 lines
938 B
Rust
27 lines
938 B
Rust
// Quick Reference §7: a bounded channel, every outcome handled (layer 7).
|
|
// expect: run
|
|
// grant: heap=mem.alloc:1024
|
|
// result: 5
|
|
// phase: 6
|
|
// spec: docs/agent/quick-reference.md
|
|
module demo.qrchannels
|
|
|
|
fn main(heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc, task.wait]
|
|
{
|
|
let v = 5u64;
|
|
var got: u64 = 0;
|
|
match channel.make<u64>(2, heap) { // effect mem.alloc
|
|
ok(tx, rx) => {
|
|
let tx2 = channel.dup(tx);
|
|
channel.close_sender(move tx2);
|
|
match channel.send(tx, v) { ok => {} closed(v) => { trap; } cancelled(v) => { trap; } } // a linear v: `move v`
|
|
match channel.recv(rx) { ok(v) => { got = v; } closed => { trap; } cancelled => { trap; } }
|
|
channel.close_sender(move tx);
|
|
match channel.close_receiver(move rx) { ok => {} pending(rx) => { trap; } } // drain, then close again
|
|
}
|
|
err(e) => { trap; }
|
|
}
|
|
got
|
|
}
|