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
@@ -279,17 +279,17 @@ select {
|
||||
}
|
||||
```
|
||||
|
||||
Arms bind the send values not sent on their edge, in the order of first appearance (spec 04 §39).
|
||||
Every edge binds its own value (the received `T` of a `recv` arm's `ok`) and then the send values not sent on it, distinct values in the order of first appearance (spec 04 §39). With `send(tx_b, move job)` in the `select`, the `recv` arm's edges are `ok(x, job)` and `closed(job)`, the send arm's are `ok` and `closed(job)`, and the `select`'s own is `cancelled(job)`. A wrong number of names is `E7005`, a missing outcome `E7004`. Each endpoint is borrowed `mut` once for the `select`, even when several arms name it, and the borrow ends on every edge.
|
||||
|
||||
**Mutex:**
|
||||
|
||||
- `mutex.make(v)`;
|
||||
- `mutex.make(v)`; to share a mutex with tasks, bind `ref mr = m;` and pass `mr` (a `ref<mutex<T>>`);
|
||||
- `mutex.take(move m)`, which needs no live borrow of `m`;
|
||||
- `lock ref m as x { … } cancelled { … }`.
|
||||
|
||||
**The `lock` block** lowers to:
|
||||
|
||||
1. `mutex.lock` on the borrow `ref m`;
|
||||
1. `mutex.lock` on the borrow `ref m`: `m` is a `mutex<T>` (borrowed for the lock, the borrow ending after the unlock and on the `cancelled` edge) or a `ref<mutex<T>>` binding (used as it is);
|
||||
2. on the `ok` edge: `mutex.borrow` of the guard, bound as `x: mut<T>`;
|
||||
3. the block;
|
||||
4. `borrow.end x` and `mutex.unlock` of the guard.
|
||||
@@ -348,7 +348,7 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
|
||||
|
||||
## 9. Frame storage, borrow scopes and features
|
||||
|
||||
- **Frame storage.** Addressability is a property of lowering, not of source types. A variable whose name is borrowed, indexed, or written through a field or element anywhere in the function lowers to `local<T>` storage, allocated in the entry block (spec 08 §11.5). Every other variable is an SSA value. The decision is by name, so the same source always gives the same placement. The frame-size limit applies to the lowered AIR. There is no implicit heap allocation.
|
||||
- **Frame storage.** Addressability is a property of lowering, not of source types. Linear values (owners, regions, resources, endpoints, tasks, mutexes) never get frame storage: they are borrowed in place. A variable whose name is borrowed, indexed, or written through a field or element anywhere in the function lowers to `local<T>` storage, allocated in the entry block (spec 08 §11.5). Every other variable is an SSA value. The decision is by name, so the same source always gives the same placement. The frame-size limit applies to the lowered AIR. There is no implicit heap allocation.
|
||||
- **Borrow scopes.** A borrow bound by `ref`/`mut` ends at the end of the block that contains the binding. Because a borrow's name is not visible after its scope, a use after the borrow ended (`E2106`) cannot be written in source. A temporary borrow, used directly as an operand, ends at the end of its statement. Both end at every normal exit from their scope. The frontend emits `borrow.end` in reverse order of creation. A borrow that must end earlier is placed in an inner block. Borrows lent to tasks end at the join (spec 04 §34).
|
||||
- **Features.** The frontend emits the `features [...]` header as the dependency closure of the constructs used, always including `effects`.
|
||||
- **Effects.** They are declared by the programmer. `E3101` names the missing effect and suggests the complete effect list (`suggested_effects`).
|
||||
|
||||
Reference in new issue
Block a user