- 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
65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
// Two producers share one channel through channel.dup; the receiver sees closed
|
|
// only after both senders are closed.
|
|
// expect: run
|
|
// grant: heap=mem.alloc:64
|
|
// schedules: 20
|
|
// quantum: 2
|
|
// result: 20
|
|
// equivalent: phase3/run/channels_mpsc_dup.air
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.mpscdup
|
|
|
|
fn produce(tx: sender<u64>) -> u8
|
|
effects [task.wait]
|
|
{
|
|
var i: u64 = 1;
|
|
while i != 5 {
|
|
match channel.send(tx, i) {
|
|
ok => {}
|
|
closed(w) => { break; }
|
|
cancelled(w) => { break; }
|
|
}
|
|
i = i + 1;
|
|
}
|
|
channel.close_sender(move tx);
|
|
0
|
|
}
|
|
|
|
fn main(heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc, task.spawn, task.wait]
|
|
{
|
|
match channel.make<u64>(1, heap) {
|
|
ok(tx, rx) => {
|
|
let tx2 = channel.dup(tx);
|
|
var acc: u64 = 0;
|
|
scope sc {
|
|
let a = task.spawn(sc, produce, move tx);
|
|
let b = task.spawn(sc, produce, move tx2);
|
|
var r: receiver<u64> = move rx;
|
|
loop {
|
|
match channel.recv(r) {
|
|
ok(v) => { acc = acc + v; }
|
|
closed => {
|
|
match channel.close_receiver(move r) {
|
|
ok => { break; }
|
|
pending(r) => {}
|
|
}
|
|
}
|
|
cancelled => {
|
|
match channel.close_receiver(move r) {
|
|
ok => { break; }
|
|
pending(r) => {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let x = task.join(move a);
|
|
let y = task.join(move b);
|
|
}
|
|
acc
|
|
}
|
|
err(e) => { trap; }
|
|
}
|
|
}
|