P6A-7 for the freeze: three reference programs in source; source construct coverage

- programs/parallel_map, channel_transfer, tcp_echo_tasks: the Phase 3 exit
  programs in .aji, with AIR equivalence on every schedule seed
- tools/source_coverage.py: every .aji construct (56) has a run/accept test
  and, where it rejects, a reject test; CI step
- gaps filled: wrapping arithmetic run test, break outside a loop (E7006),
  close_receiver without pending (E7004)
- plan: P6A-7 freeze criterion (owner decision); further twins gradually
This commit is contained in:
dev committed 2026-10-05 18:15:48 +03:00
1 parent 748eddf4e5
commit 591f0aea19
9 files changed
+372 -1

No files matched your search

@@ -0,0 +1,78 @@
// Reference program (Phase 3 exit, in source): ownership transfer through a bounded
// channel. The producer allocates each message on the heap and moves the owner into
// the channel; the consumer takes it. The budget (64 bytes) only fits the channel and
// three live messages: bounded capacity bounds memory. 10 + 20 + 30 = 60.
// expect: run
// grant: heap=mem.alloc:64
// schedules: 30
// quantum: 2
// result: 60
// equivalent: phase3/run/program_channel_transfer.air
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.channeltransfer
struct Message {
id: u64,
size: u64,
}
fn producer(tx: sender<own<Message>>, heap: cap<mem.alloc>) -> u8
effects [mem.alloc, task.wait]
{
var id: u64 = 10;
while id != 40 {
let o = own.new(Message { id: id, size: 16 }, heap) or trap;
match channel.send(tx, move o) {
ok => {}
closed(back) => {
own.free(move back);
break;
}
cancelled(back) => {
own.free(move back);
break;
}
}
id = id + 10;
}
channel.close_sender(move tx);
0
}
fn main(heap: cap<mem.alloc>) -> u64
effects [mem.alloc, task.spawn, task.wait]
{
match channel.make<own<Message>>(2, heap) {
ok(tx, rx) => {
var acc: u64 = 0;
scope sc {
let p = task.spawn(sc, producer, move tx, heap);
var r: receiver<own<Message>> = move rx;
loop {
match channel.recv(r) {
ok(o) => {
let msg = own.take(move o);
acc = acc + msg.id;
}
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 p);
}
acc
}
err(e) => { trap; }
}
}
@@ -0,0 +1,50 @@
// Reference program (Phase 3 exit, in source): parallel map. One buffer is split into
// four disjoint quarters; four tasks square their quarter in place through exclusive
// loans; the parent sums the result after joining. 1² + … + 8² = 204.
// expect: run
// schedules: 30
// quantum: 3
// result: 204
// equivalent: phase3/run/program_parallel_map.air
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.parallelmap
fn square(q: slice_mut<u64>) -> u8
effects []
{
for i in 0..q.len {
q[i] = q[i] * q[i];
}
0
}
fn main() -> u64
effects [task.spawn]
{
var buf: [u64; 8] = zero;
mut s = buf;
for i in 0..s.len {
s[i] = i as! u64 + 1;
}
{
let (l, r) = s.split_at(4);
let (a, b) = l.split_at(2);
let (c, d) = r.split_at(2);
scope sc {
let ta = task.spawn(sc, square, a);
let tb = task.spawn(sc, square, b);
let tc = task.spawn(sc, square, c);
let td = task.spawn(sc, square, d);
task.join(move ta);
task.join(move tb);
task.join(move tc);
task.join(move td);
}
}
var acc: u64 = 0;
for k in 0..s.len {
acc = acc + s[k];
}
acc
}
@@ -0,0 +1,78 @@
// Reference program (Phase 3 exit, in source): TCP echo with tasks over the
// deterministic loopback. A server task accepts two connections and spawns one echo
// task per connection; two client tasks share the address and the message through
// shared loans. The bytes echoed to both clients: 2 × (112+105+110+103) = 860.
// expect: run
// grant: listen=net.listen
// grant: connect=net.connect
// schedules: 30
// quantum: 5
// result: 860
// equivalent: phase3/run/program_tcp_echo_tasks.air
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.tcpechotasks
// Receives up to 4 bytes and sends them back, then closes the stream.
fn echo(s: stream) -> u8
effects [net.read, net.write]
{
var buf: [u8; 4] = zero;
let n = net.recv(s, mut buf) or trap;
net.send_all(s, ref buf[0..n]) or trap;
net.close_stream(move s) or trap;
0
}
// Accepts two connections; each is moved into its own echo task.
fn serve(l: listener) -> u8
effects [net.listen, net.read, net.write, task.spawn]
{
scope sc {
let s1 = net.accept(l) or trap;
let t1 = task.spawn(sc, echo, move s1);
let s2 = net.accept(l) or trap;
let t2 = task.spawn(sc, echo, move s2);
task.join(move t1);
task.join(move t2);
}
net.close_listener(move l) or trap;
0
}
// Connects, sends the message, and returns the sum of the bytes echoed back.
fn client(connect: cap<net.connect>, addr: slice<u8>, msg: slice<u8>) -> u64
effects [net.connect, net.read, net.write]
{
var back: [u8; 4] = zero;
let c = net.connect(connect, addr) or trap;
net.send_all(c, msg) or trap;
let n = net.recv(c, mut back) or trap;
net.close_stream(move c) or trap;
var acc: u64 = 0;
for i in 0..n {
acc = acc + back[i] as u64;
}
acc
}
fn main(listen: cap<net.listen>, connect: cap<net.connect>) -> u64
effects [net.listen, net.connect, net.read, net.write, task.spawn]
{
let addr_bytes = b"127.0.0.1:7";
let ping_bytes = b"ping";
ref addr = addr_bytes;
ref ping = ping_bytes;
let l = net.listen(listen, addr) or trap;
var sum: u64 = 0;
scope sc {
let srv = task.spawn(sc, serve, move l);
let c1 = task.spawn(sc, client, connect, addr, ping);
let c2 = task.spawn(sc, client, connect, addr, ping);
task.join(move srv);
let a = task.join(move c1);
let b = task.join(move c2);
sum = a + b;
}
sum
}