Files
aji/tests/conformance/source/quickref/tasks.aji
T
dev 179dee3c3a Phase 6A: .aji layer 7 (task scopes, spawn/join, channels)
- scope s { … }: task.scope.begin, task.scope.end at every normal exit
  (scope ends generalized: borrow.end or task.scope.end, innermost first)
- task.spawn(s, f, args): call-like; named linear values moved (E7003);
  lent borrows are bound first (inline borrow E7006); scope operand E7005
- task.join/cancel/cancelled; task<T>, sender<T>, receiver<T>, scope types
- channels: make<T>, dup, send, recv, close_sender, close_receiver; send,
  recv and close_receiver are outcome matches; endpoints by name, borrowed
  for the operation and ended on every edge (written `mut tx`: E7006)
- outcome rebinding: a value coming back under the name of a variable of
  its type becomes the variable's value (pending(r))
- joins carry live variables only (pruned SSA): a linear value consumed
  before a join does not travel to it; ordered after-walk over the
  enclosing statement or tail, sibling arms not counted
- parser: a keyword after `.` is a member name (task.cancelled)
- conformance equivalence ignores schedule.choices (quantum counts AIR
  instructions)
- tests: 10 run tests with AIR equivalence (Phase 3 programs), 12 rejects
  (E4301, E4101 x2, E4002, E2001, E3101, E3002, E7006 x2, E7003, E0006,
  E7005); Quick Reference tasks/channels programs now pass
- spec 15 §4/§6/§7, grammar, quick reference, bundle notes, plan
2026-10-05 17:55:30 +03:00

41 lines
1.0 KiB
Rust

// Quick Reference §7: a scope with two tasks over disjoint halves (layer 7).
// expect: run
// result: 32
// phase: 6
// spec: docs/agent/quick-reference.md
module demo.qrtasks
fn square(s: slice_mut<u64>) -> u64
effects []
{
var sum: u64 = 0;
for i in 0..s.len {
s[i] = s[i] * s[i];
sum = sum + s[i];
}
sum
}
fn main() -> u64
effects [task.spawn, task.wait]
{
var data: [u64; 8] = [1; 8];
data[4] = 2;
data[5] = 2;
data[6] = 2;
data[7] = 4;
var total: u64 = 0;
{
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);
total = x + y;
}
}
total
}