- 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
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
// Quick Reference §4: borrows and moves.
|
|
// expect: run
|
|
// result: 36
|
|
// phase: 6
|
|
// spec: docs/agent/quick-reference.md
|
|
module demo.borrows
|
|
|
|
struct P {
|
|
a: u64,
|
|
b: u64,
|
|
}
|
|
|
|
fn main() -> u64
|
|
effects []
|
|
{
|
|
let i = 2usize;
|
|
var out: [u64; 4] = zero;
|
|
var total: u64 = 0;
|
|
var data: [u64; 8] = zero;
|
|
data[0] = 7; // element write (array variables get frame storage automatically)
|
|
{
|
|
mut s = data; // exclusive borrow to the end of this block
|
|
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
|
|
l[3] = n as! u64;
|
|
r[0] = 9;
|
|
}
|
|
slice.copy(mut out[0..4], ref data[4..8]); // borrows as arguments end after the call
|
|
total = total + out[0];
|
|
var p: P = P { a: 1, b: 2 };
|
|
{
|
|
ref q = p; // shared borrow of a struct; q.a reads a field
|
|
total = total + q.a + q.b;
|
|
}
|
|
var count: u64 = 0;
|
|
bump(mut count);
|
|
total + count + data[0] + data[1] + data[3]
|
|
}
|
|
|
|
fn bump(c: mut<u64>) -> void
|
|
effects []
|
|
{
|
|
*c = *c + 1; // through c: mut<u64>
|
|
}
|