Phase 6A: .aji layer 8 (lock and mutexes, select, shields, cancellation)
- lock ref m as x { … } cancelled { … }: mutex.lock on a ref<mutex<T>>
(a mutex is borrowed for the lock, a ref binding used as is); ok edge:
mutex.borrow bound as x; at every normal exit borrow.end x then
mutex.unlock; the guard is never a source value
- mutex.make/mutex.take; mutex<T> type; ref mr = m lends a mutex
- shield { … }: task.shield.begin/end at every exit (nesting by construction)
- task.check_cancel and task.join_cancel as outcome matches
- select: one borrow per endpoint, send values evaluated first and
deduplicated, every edge binds its own value then the unsent values;
bind count E7005, missing outcome E7004
- linear values never get frame storage (borrowed in place)
- liveness: select handled in the read and after walks
- Quick Reference: select edges bind `job` back (ok(x, job), closed(job));
every Quick Reference example now passes (no PENDING)
- tests: 6 run tests with AIR equivalence (mutex counter, select draw,
select same value, shield, join_cancel forwarding, cancelled recv), 10
rejects (E4304 x3, E3001, E2101, E7005 x2, E7004, E3101 x2, E4101)
- spec 15 §7/§9, quick reference, bundle notes, plan
This commit is contained in:
1 parent
609b6bf86e
commit
154c39865f
24 files changed
+912
-50
No files matched your search
@@ -0,0 +1,89 @@
|
||||
module demo.selectsamevalue
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks]
|
||||
|
||||
fn @main(%heap: cap<mem.alloc>) -> u64
|
||||
effects [mem.alloc, task.wait]
|
||||
entry:
|
||||
%c_1 = const.usize 1
|
||||
channel.make own<u64>, %c_1, %heap, ok -> @ok_2, err -> @err_5
|
||||
ok_2(%ok_3: sender<own<u64>>, %ok_4: receiver<own<u64>>):
|
||||
%c_7 = const.usize 1
|
||||
channel.make own<u64>, %c_7, %heap, ok -> @ok_8, err -> @err_11
|
||||
err_5(%err_6: alloc_error):
|
||||
trap
|
||||
ok_8(%ok_9: sender<own<u64>>, %ok_10: receiver<own<u64>>):
|
||||
%c_13 = const.u64 42
|
||||
own.new %c_13, %heap, ok -> @ok_14, err -> @err_16
|
||||
err_11(%err_12: alloc_error):
|
||||
trap
|
||||
ok_14(%ok_15: own<u64>):
|
||||
%ta_18 = borrow.mut %ok_3
|
||||
%tb_19 = borrow.mut %ok_9
|
||||
select [send %ta_18, %ok_15, ok -> @ok_20, closed -> @closed_21], [send %tb_19, %ok_15, ok -> @ok_23, closed -> @closed_24], cancelled -> @cancelled_26
|
||||
err_16(%err_17: alloc_error):
|
||||
trap
|
||||
ok_20:
|
||||
borrow.end %tb_19
|
||||
borrow.end %ta_18
|
||||
br @endselect_28()
|
||||
closed_21(%closed_22: own<u64>):
|
||||
borrow.end %tb_19
|
||||
borrow.end %ta_18
|
||||
trap
|
||||
ok_23:
|
||||
borrow.end %tb_19
|
||||
borrow.end %ta_18
|
||||
br @endselect_28()
|
||||
closed_24(%closed_25: own<u64>):
|
||||
borrow.end %tb_19
|
||||
borrow.end %ta_18
|
||||
trap
|
||||
cancelled_26(%cancelled_27: own<u64>):
|
||||
borrow.end %tb_19
|
||||
borrow.end %ta_18
|
||||
trap
|
||||
endselect_28:
|
||||
%c_29 = const.u64 0
|
||||
%ra_30 = borrow.mut %ok_4
|
||||
%rb_31 = borrow.mut %ok_10
|
||||
select [recv %ra_30, ok -> @ok_32, closed -> @closed_34], [recv %rb_31, ok -> @ok_35, closed -> @closed_37], cancelled -> @cancelled_38
|
||||
ok_32(%ok_33: own<u64>):
|
||||
borrow.end %rb_31
|
||||
borrow.end %ra_30
|
||||
%v_39 = own.take %ok_33
|
||||
br @endselect_41(%v_39)
|
||||
closed_34:
|
||||
borrow.end %rb_31
|
||||
borrow.end %ra_30
|
||||
trap
|
||||
ok_35(%ok_36: own<u64>):
|
||||
borrow.end %rb_31
|
||||
borrow.end %ra_30
|
||||
%v_40 = own.take %ok_36
|
||||
br @endselect_41(%v_40)
|
||||
closed_37:
|
||||
borrow.end %rb_31
|
||||
borrow.end %ra_30
|
||||
trap
|
||||
cancelled_38:
|
||||
borrow.end %rb_31
|
||||
borrow.end %ra_30
|
||||
trap
|
||||
endselect_41(%r_42: u64):
|
||||
channel.close_sender %ok_3
|
||||
channel.close_sender %ok_9
|
||||
channel.close_receiver %ok_4, ok -> @ok_43, pending -> @pending_44
|
||||
ok_43:
|
||||
channel.close_receiver %ok_10, ok -> @ok_46, pending -> @pending_47
|
||||
pending_44(%pending_45: receiver<own<u64>>):
|
||||
trap
|
||||
ok_46:
|
||||
br @endmatch_49(%r_42)
|
||||
pending_47(%pending_48: receiver<own<u64>>):
|
||||
trap
|
||||
endmatch_49(%match_50: u64):
|
||||
br @endmatch_51(%match_50)
|
||||
endmatch_51(%match_52: u64):
|
||||
ret %match_52
|
||||
Reference in new issue
Block a user