spec: accept RFC 0012 and integrate waits, channels, select and mutex
revision 2 per owner review: reserved-feature dependencies may change until publication (general rule, DD-014); task.join.cancel returns the handle on cancelled with loans still LOANED; channel.sender.dup from ref<sender<T>> (MPSC, receiver_dup reserved); task.wait required by every suspending operation, task.join included, only in modules declaring cancellation; sent values and handles come back as block parameters on closed/cancelled edges; explicit channel states spec 04 §37-§41 and pointers in §11-§16, §35, §36; spec 05 §9, 07 §8.11, 07a, 08 §14, 11 §6-§7; features cancellation, channels, sync published (implementation pending); rwlock, channel_transfer, receiver_dup, guard_transfer reserved; effect task.wait; E4304, E4305; Q-013 resolved; bundle +15.8 % tokens (recorded)
This commit is contained in:
1 parent
4230c78dd1
commit
b82bc35c5f
19 files changed
+387
-67
No files matched your search
@@ -45,4 +45,6 @@ Growth never blocks a merge automatically; a complex feature can be justified, b
|
||||
| Phase 2 baseline (AIR format 0) | 18 | 29 | 104 250 | 16 197 | 27 347 | 27 445 | 28 230 |
|
||||
| RFC 0011 tasks (Phase 3, part 1) | 19 | 33 | 116 126 | 18 082 | 30 333 (+10.9 %) | 30 433 (+10.9 %) | 31 316 (+10.9 %) |
|
||||
|
||||
RFC 0011 crossed the 10 % warning line (its own estimate said "below 10 %"): four new sections in spec 04 (tasks, loans, `Send`/`Share` table, scheduler). Below the 20 % review threshold. Next measurement: after RFC 0012 (channels, synchronization).
|
||||
| RFC 0012 waits, channels, select, mutex | 19 | 38 | 133 781 | 20 748 | 35 119 (+15.8 %) | 35 219 (+15.7 %) | 36 238 (+15.7 %) |
|
||||
|
||||
RFC 0011 crossed the 10 % warning line (its own estimate said "below 10 %"): four new sections in spec 04 (tasks, loans, `Send`/`Share` table, scheduler). Below the 20 % review threshold. RFC 0012 (+15.8 %, estimate 12–16 %): five sections in spec 04 (waits and cancellation, channels, select, mutex, critical-section rule). Phase 3 total since the Phase 2 baseline: +28.4 %. Next measurement: after the Phase 3 reference programs.
|
||||
@@ -38,6 +38,13 @@ docs/spec/04-concurrency-and-atomics.md :: ## 34. Lending borrows to tasks
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 35. Send and Share in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 36. The deterministic scheduler
|
||||
|
||||
# Waiting, cancellation, channels, select, mutex
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 37. Waiting and cancellation
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 38. Channels in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 39. `select` in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 40. Mutex in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 41. The critical-section rule
|
||||
|
||||
# Effects, capabilities, intrinsics
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 9. Effects in AIR
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 10. Capabilities in AIR
|
||||
|
||||
@@ -30,5 +30,21 @@
|
||||
"o200k_base": 30433,
|
||||
"qwen2.5": 31316
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "rfc-0012 waits, channels, select, mutex (spec)",
|
||||
"language": "aji",
|
||||
"air": 0,
|
||||
"phase": 2,
|
||||
"files": 19,
|
||||
"sections": 38,
|
||||
"bytes": 133781,
|
||||
"lines": 2000,
|
||||
"words": 20748,
|
||||
"tokens": {
|
||||
"cl100k_base": 35119,
|
||||
"o200k_base": 35219,
|
||||
"qwen2.5": 36238
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -78,7 +78,7 @@ Reason: timeouts make test outcomes depend on machine speed; a trap code for exh
|
||||
|
||||
## DD-014 — AIR feature negotiation
|
||||
|
||||
AIR format 0 uses the mandatory `features [...]` header as an explicit semantic compatibility contract. Every post-baseline AIR 0 extension belongs to a registered feature (`reference/air-features.md`). Modules MUST declare every feature they use and its dependency closure. Implementations MUST validate the feature set before validating the module body. Unknown, unsupported, undeclared, duplicated or dependency-incomplete features are reported as `E0006` with a structured `reason`. Feature semantics are immutable once published. `aji features` reports what a toolchain supports.
|
||||
AIR format 0 uses the mandatory `features [...]` header as an explicit semantic compatibility contract. Every post-baseline AIR 0 extension belongs to a registered feature (`reference/air-features.md`). Modules MUST declare every feature they use and its dependency closure. Implementations MUST validate the feature set before validating the module body. Unknown, unsupported, undeclared, duplicated or dependency-incomplete features are reported as `E0006` with a structured `reason`. Feature semantics are immutable once published. `aji features` reports what a toolchain supports. While a feature is reserved, no valid module can use it, so its dependency set may change; on publication the dependencies freeze with its semantics (owner decision on RFC 0012).
|
||||
|
||||
Reason: format 0 is frozen; features make it an extensible protocol without an older implementation half-parsing a module it cannot understand. One code with a reason keeps the §8.7 exception for `E0006` intact.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ Status values: `open`, `resolved`.
|
||||
| Q-010 | resolved | P1 | Region generation checks: static, dynamic, or both |
|
||||
| Q-011 | resolved | P2 | Effect hierarchy and discharge |
|
||||
| Q-012 | resolved | P2 | Capability representation and host instantiation |
|
||||
| Q-013 | open | P3 | Deterministic `select` rule and scheduler seed |
|
||||
| Q-013 | resolved | P3 | Deterministic `select` rule and scheduler seed |
|
||||
| Q-014 | resolved | P3 | `Send`/`Share` derivation for aggregates holding capabilities |
|
||||
| Q-015 | open | P5 | Operational weak-memory model for the interpreter |
|
||||
| Q-016 | open | P0 | Floating-point determinism |
|
||||
@@ -107,7 +107,7 @@ Binary AIR has a `CAPABILITY_TABLE` (spec 07 §6). Undecided: how capabilities a
|
||||
|
||||
Spec 04 §14 and spec 11 §6 require a stable rule in deterministic mode but do not define it. Also undecided: scheduler seed format and which choice points are recorded.
|
||||
|
||||
**Proposed (RFC 0012):** ready arms chosen by a draw from the schedule generator (not textual order); task choices and arm choices share one stream and one `choices` count. The schedule seed was settled by RFC 0011.
|
||||
**Resolved (RFC 0012, spec 04 §39):** ready arms chosen by a draw from the schedule generator (not textual order); task choices and arm choices share one stream and one `choices` count. The schedule seed was settled by RFC 0011.
|
||||
|
||||
## Q-014 — `Send`/`Share` for aggregates holding capabilities
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
|
||||
| ID | Status | Task | Depends | Output | Done when |
|
||||
|---|---|---|---|---|---|
|
||||
| P3-1 | doing | Resolve Q-013, Q-014; propose RFC 0002 for acceptance (Q-014 resolved by RFC 0011; Q-013 proposed in RFC 0012) | — | spec 04, 11 | questions resolved |
|
||||
| P3-1 | done | Resolve Q-013, Q-014 (RFC 0011, RFC 0012) | — | spec 04, 11 | questions resolved |
|
||||
| P3-2 | doing | Contract tables: `task.*` (RFC 0011, done), `channel.*`, `mutex.*`, `rwlock.*`, select (RFC 0012); `thread.*` deferred to native backends | P3-1 | spec 07 appendix | all spec 07 §4 fields including synchronization effects |
|
||||
| P3-2a | doing | Publish features `tasks` (done), `channels`, `sync` | P3-2 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
|
||||
| P3-2a | doing | Publish features `tasks` (done), `cancellation`, `channels`, `sync` (specified by RFC 0012) | P3-2 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
|
||||
| P3-3 | done | Deterministic scheduler: seeds, choice points, choice log; global fuel across tasks and a separate `quantum` (spec 11 §7.2) | P3-2 | `src/interp/sched.zig` | same seed ⇒ identical trace; choice log replays a run; fuel is the sum over all tasks |
|
||||
| P3-4 | done | Send/Share/Local derivation | P3-1 | `src/verifier/send_share.zig` | E4001, E4002 accept/reject |
|
||||
| P3-5 | done | Task-scope verifier and scoped borrows | P3-2 | `src/verifier/tasks.zig` | E4301, E4302 accept/reject |
|
||||
|
||||
@@ -22,7 +22,7 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It
|
||||
- Every post-baseline construct belongs to exactly one feature. A feature is a whole semantic block, not one instruction.
|
||||
- A module MUST declare every feature whose constructs it uses, plus the full dependency closure; nothing is implied.
|
||||
- Canonical form: names sorted lexicographically, no duplicates.
|
||||
- Status `reserved`: the name and dependencies are fixed, semantics are not yet specified; modules MUST NOT use it (`unsupported_feature`).
|
||||
- Status `reserved`: the name is fixed, semantics are not yet specified; modules MUST NOT use it (`unsupported_feature`). Because no valid module can use a reserved feature, its dependency set MAY change until it is published (DD-014, RFC 0012); from publication on the dependencies are part of the frozen semantics.
|
||||
- Status `published`: semantics are specified in spec 07a and the relevant spec files, and are immutable. Incompatible evolution needs a new feature name or a new AIR format version.
|
||||
- A dependency is listed only when the feature's semantics cannot be stated without it.
|
||||
|
||||
@@ -32,21 +32,26 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It
|
||||
|---|---|---|---|---|
|
||||
| `arrays` | published | 1 | `ownership` | `array<T, N>`, `slice<T>`, `slice_mut<T>`, `array.splat`, `borrow.index[.proven]`, `slice.*`, `guard`, bounds facts (spec 07a, spec 08 §12) |
|
||||
| `atomics` | reserved | 5 | `ownership` | atomic types, the five orderings, fences, `atomic.*` instructions |
|
||||
| `capabilities` | published | 2 | `effects`, `ownership` | `cap<K>`, built-in `cap_error`, `cap.narrow`, `intrinsic`, instantiation of `@main` (spec 05 §10–§12) |
|
||||
| `borrow_joins` | reserved | — | `ownership` | borrow-typed block parameters (spec 08 §11.6); unscheduled |
|
||||
| `channels` | reserved | 3 | `ownership` | bounded and rendezvous channels with ownership transfer |
|
||||
| `cancellation` | published | 3 | `effects`, `ownership`, `tasks` | effect `task.wait` (required by suspending operations, `task.join` included), waiting-operation rule, `shield`, `task.shield.*`, `task.check_cancel`, `task.join.cancel` (spec 04 §37) |
|
||||
| `capabilities` | published | 2 | `effects`, `ownership` | `cap<K>`, built-in `cap_error`, `cap.narrow`, `intrinsic`, instantiation of `@main` (spec 05 §10–§12) |
|
||||
| `channel_transfer` | reserved | — | `cancellation`, `capabilities`, `channels`, `effects`, `heap`, `ownership`, `resources`, `tasks` | endpoints inside channel elements or mutex contents; unscheduled |
|
||||
| `channels` | published | 3 | `cancellation`, `capabilities`, `effects`, `heap`, `ownership`, `resources`, `tasks` | `sender<T>`, `receiver<T>`, `channel.*`, `select` (spec 04 §38–§39) |
|
||||
| `effects` | published | 2 | — | flat effect checking of `effects [...]` for `call` and `intrinsic` (E3101, spec 05 §9) |
|
||||
| `guard_transfer` | reserved | — | `cancellation`, `effects`, `ownership`, `sync`, `tasks` | `guard<T>` as parameter, return type or aggregate member; unscheduled |
|
||||
| `heap` | published | 2 | `capabilities`, `effects`, `ownership`, `resources` | `own<T>`, `own_array<T>`, `own.*`, built-in `alloc_error`, `mem.alloc` budgets and `budget` narrowing (spec 03 §18–§19) |
|
||||
| `islands` | reserved | 4 | `capabilities`, `effects`, `heap`, `ownership`, `regions`, `resources` | `Island<T>`, `iref<T>`, transfer, freeze, `Frozen<T>` |
|
||||
| `linear_aggregates` | reserved | — | `capabilities`, `effects`, `ownership`, `resources` | resource types as struct fields, enum payloads and array elements; unscheduled |
|
||||
| `ownership` | published | 1 | — | frame storage `local<T>`, second-class borrows `ref<T>`/`mut<T>`, `from` returns, initialization (spec 07 §8.8, spec 07a, spec 08 §11, §13) |
|
||||
| `receiver_dup` | reserved | — | `cancellation`, `capabilities`, `channels`, `effects`, `heap`, `ownership`, `resources`, `tasks` | several receivers of one channel (MPMC); unscheduled |
|
||||
| `regions` | published | 2 | `capabilities`, `effects`, `heap`, `ownership`, `resources` | `region`, `region.*`, static generations (spec 03 §20) |
|
||||
| `resource_joins` | reserved | — | `capabilities`, `effects`, `ownership`, `resources` | joins whose incoming edges carry different resource states (spec 06 §6.3); unscheduled |
|
||||
| `resources` | published | 2 | `capabilities`, `effects`, `ownership` | linear resources `file<read>`, `file<write>`, `file<append>`, `listener`, `stream`; built-in `io_error`; I/O intrinsics (spec 06 §6–§7, `reference/intrinsics.md`) |
|
||||
| `sync` | reserved | 3 | `ownership` | `Mutex<T>`, `RwLock<T>`, linear guards |
|
||||
| `tasks` | published | 3 | `ownership` | `scope`, `task<T>`, `task.*`, loans, `Send`/`Share`, deterministic scheduler (spec 04 §33–§36) |
|
||||
| `rwlock` | reserved | — | `cancellation`, `effects`, `ownership`, `sync`, `tasks` | `rwlock<T>`, read and write guards, no upgrade/downgrade; unscheduled |
|
||||
| `sync` | published | 3 | `cancellation`, `effects`, `ownership`, `tasks` | `mutex<T>`, `guard<T>`, `mutex.*`, critical-section rule (spec 04 §40–§41) |
|
||||
| `task_borrow_returns` | reserved | — | `ownership`, `tasks` | spawned functions returning borrows; unscheduled |
|
||||
| `task_transfer` | reserved | — | `ownership`, `tasks` | `scope` and `task<T>` as parameters, return types, aggregate members or heap contents; unscheduled |
|
||||
| `tasks` | published | 3 | `ownership` | `scope`, `task<T>`, `task.*`, loans, `Send`/`Share`, deterministic scheduler (spec 04 §33–§36) |
|
||||
| `unsafe` | published | 2 | `arrays`, `effects`, `ownership` | `assume`, `borrow.index.unchecked`, the `trusted` boundary, the effect `unsafe` (spec 13 §6–§8) |
|
||||
|
||||
`capabilities` depends on `effects` so that every module that can perform an external operation is also effect-checked.
|
||||
|
||||
@@ -22,6 +22,7 @@ Normative registry of effect names for AIR format 0 (spec 05 §9). Effects are f
|
||||
| `process.spawn` | `cap<process.spawn>` | later |
|
||||
| `random.read` | `cap<random.read>` | RFC 0007 |
|
||||
| `task.spawn` | none | Phase 3 |
|
||||
| `task.wait` | none | RFC 0012 (required by suspending operations in modules declaring `cancellation`, spec 04 §37.4) |
|
||||
| `thread.block` | none | Phase 3 |
|
||||
| `thread.spawn` | none | Phase 3 |
|
||||
| `unsafe` | none (unsafe boundary, spec 13) | Phase 2 |
|
||||
@@ -60,6 +60,8 @@ Draft registry. Codes are stable once released in a tagged compiler version.
|
||||
| E4301 | task.live_child_escape | Scope exits with live child task |
|
||||
| E4302 | task.borrow_escape | Child task borrow can outlive parent storage |
|
||||
| E4303 | io.buffer_in_flight | Buffer accessed while async operation owns/borrows it |
|
||||
| E4304 | sync.wait_while_locked | Suspending operation, spawn, or call of a waiting/spawning function while a lock guard is live |
|
||||
| E4305 | task.shield_order | Shield ended while a more inner shield is live |
|
||||
|
||||
## E5xxx — AIR/verifier
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# RFC 0012: Channels, Mutex, Select and Cancellation Points
|
||||
|
||||
Status: Proposed
|
||||
Status: Accepted (revision 2, after owner review: D1–D3 decided; `task.wait` gated by `cancellation`; values and handles returned as block parameters)
|
||||
Scope: AIR format 0, features `cancellation`, `channels`, `sync`
|
||||
Language version: 0.1
|
||||
Measured Agent Reference Bundle growth on integration: +15.8 % tokens (estimate: 12–16 %).
|
||||
Integrated into: spec 04 §37–§41; spec 04 §35; spec 05 §9; spec 07 §8.11; spec 07a; spec 08 §14; spec 11 §8; `reference/air-features.md`, `effects.md`, `error-codes.md`; `docs/design/decisions.md` DD-014; `docs/agent/bundle.txt`
|
||||
Supersedes: —
|
||||
|
||||
Resolves: Q-013 (deterministic `select` and the scheduler's choice points). Realizes spec 04 §7–§9, §12, §14–§16 for AIR. Builds on RFC 0011 (spec 04 §33–§36).
|
||||
@@ -14,7 +16,7 @@ RFC 0011: who may execute concurrently?
|
||||
RFC 0012: how do concurrent tasks communicate, wait and coordinate?
|
||||
```
|
||||
|
||||
Out of scope: `RwLock` (deferred, reserved feature `rwlock`), atomics (own RFC: after atomics the "every native outcome is an interleaving" model no longer suffices, spec 04 §36.1), timers, task-aware I/O and async buffer claims (`E4303`), multiple receivers.
|
||||
Out of scope: `RwLock` (deferred, reserved feature `rwlock`), atomics (own RFC: after atomics the "every native outcome is an interleaving" model no longer suffices, spec 04 §36.1), timers, task-aware I/O and async buffer claims (`E4303`), several receivers (channels are MPSC).
|
||||
|
||||
## Motivation
|
||||
|
||||
@@ -30,7 +32,7 @@ The design goal is a concurrency core that a weaker model can use safely. So the
|
||||
## Invariants
|
||||
|
||||
1. **Explicit outcomes.** Every waiting operation completes on exactly one of its declared edges. Cancellation is never a trap.
|
||||
2. **Ownership transfer.** A value sent on a channel is owned by the sending operation until the operation completes. On `ok` it belongs to the channel and then to the receiver. On `closed` or `cancelled` it is still the sender's. A value is never observable by two tasks.
|
||||
2. **Ownership transfer.** A value sent on a channel is owned by the sending operation until the operation completes. On `ok` it belongs to the channel and then to the receiver. On `closed` or `cancelled` it is handed back to the sender as a block parameter of the target. A value is never observable by two tasks.
|
||||
3. **No silent drop.** A value is removed from a channel only by `channel.recv` or a `select` receive arm. A receiver is consumed only when the channel is empty and no more values can enter it.
|
||||
4. **No wait under a lock.** While a task holds a `guard<T>`, it executes no waiting operation. This is checked statically, including through calls.
|
||||
5. **Cooperative cancellation.** Cancellation is observed only at the cancellation points of §2.2. An operation that can complete without waiting completes, even if cancellation is pending. Inside a shield, cancellation is never observed. Shields nest properly.
|
||||
@@ -39,11 +41,13 @@ The design goal is a concurrency core that a weaker model can use safely. So the
|
||||
|
||||
## 1. Features and dependencies
|
||||
|
||||
All three features are new to this RFC. `channels` and `sync` are reserved today with dependencies `[ownership]`. Their semantics cannot be stated without the task model, effects and, for channels, allocation budgets, so this RFC changes their reserved dependency lists (see decision D1 under Unresolved questions).
|
||||
All three features are new to this RFC. `channels` and `sync` were reserved with dependencies `[ownership]`; their semantics cannot be stated without the task model, effects and, for channels, allocation budgets.
|
||||
|
||||
**Rule for reserved dependencies (D1).** While a feature is `reserved`, no valid module can use it, so its dependency set MAY change. When the feature is published, its dependencies become part of the frozen semantics of AIR 0. This is a general registry rule (`reference/air-features.md`, DD-014), not an exception for these two features.
|
||||
|
||||
| Feature | Depends on | Semantic block |
|
||||
|---|---|---|
|
||||
| `cancellation` | `effects`, `tasks` | effect `task.wait`; the waiting-operation rule (§2); `shield`, `task.shield.*`; `task.check_cancel`; the waiting form of `task.join` |
|
||||
| `cancellation` | `effects`, `tasks` | effect `task.wait` and its gated requirement (§2.4); the waiting-operation rule (§2); `shield`, `task.shield.*`; `task.check_cancel`; `task.join.cancel` |
|
||||
| `channels` | `cancellation`, `heap` | `sender<T>`, `receiver<T>`, `channel.*`, `select` |
|
||||
| `sync` | `cancellation` | `mutex<T>`, `guard<T>`, `mutex.*`, the critical-section rule (E4304) |
|
||||
|
||||
@@ -52,16 +56,17 @@ Reserved by this RFC (all unscheduled):
|
||||
| Feature | Depends on | Semantic block |
|
||||
|---|---|---|
|
||||
| `rwlock` | `sync` | `rwlock<T>`, read and write guards (only `read_lock`, `write_lock` and `unlock`; no upgrade or downgrade) |
|
||||
| `channel_transfer` | `channels` | `sender<…>`/`receiver<…>` inside channel elements or mutex contents; several receivers |
|
||||
| `channel_transfer` | `channels` | `sender<…>`/`receiver<…>` inside channel elements or mutex contents |
|
||||
| `receiver_dup` | `channels` | several receivers of one channel (MPMC) |
|
||||
| `guard_transfer` | `sync` | `guard<T>` as a parameter, a return type or an aggregate member |
|
||||
|
||||
The published feature `tasks` is not changed (spec 07 §8.7). The new cancellation behavior applies only to new instructions. The plain `task.join` keeps its meaning, and `task.cancelled` keeps returning the raw request flag.
|
||||
The published feature `tasks` is not changed (spec 07 §8.7). The plain `task.join` is never a cancellation point, and `task.cancelled` keeps returning the raw request flag. The only rule that touches a `tasks` instruction, the `task.wait` effect of `task.join`, applies only in modules declaring `cancellation` (§2.4). A module that does not declare it keeps the RFC 0011 semantics exactly.
|
||||
|
||||
## 2. Waiting and cancellation (feature `cancellation`)
|
||||
|
||||
### 2.1 The waiting-operation rule
|
||||
|
||||
A **waiting operation** is one of `task.join` in its terminator form, `channel.send`, `channel.recv`, `select` and `mutex.lock`. Each has a **ready condition** that may hold now or later. One rule covers all of them:
|
||||
A **waiting operation** is one of `task.join.cancel`, `channel.send`, `channel.recv`, `select` and `mutex.lock`. Each has a **ready condition** that may hold now or later. One rule covers all of them:
|
||||
|
||||
```text
|
||||
1. If the operation is ready, it completes with that outcome (ok or closed).
|
||||
@@ -82,26 +87,58 @@ The plain `task.join` and the I/O intrinsics (`net.accept`, reads on streams) ar
|
||||
| Point | Observes cancellation |
|
||||
|---|---|
|
||||
| `task.check_cancel` | always when observable |
|
||||
| `task.join` (terminator form), `channel.send`, `channel.recv`, `select`, `mutex.lock` | only when it would otherwise wait (§2.1 step 2) |
|
||||
| `task.join.cancel`, `channel.send`, `channel.recv`, `select`, `mutex.lock` | only when it would otherwise wait (§2.1 step 2) |
|
||||
|
||||
### 2.3 Instructions
|
||||
|
||||
| Instruction | Operands → result | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
| `task.check_cancel, ok -> @ok, cancelled -> @c` (terminator) | — ; both targets have no parameters | — | — | `@c` if cancellation is observable, else `@ok`; a scheduling point |
|
||||
| `task.join %t, ok -> @ok, cancelled -> @c` (terminator) | `task<T>`; `@ok(T)`, `@c()` | — | on the `ok` edge as plain `task.join` (consumes `%t`, ends its loans); on the `cancelled` edge `%t` and its loans stay live | waiting operation; ready when the task has returned |
|
||||
| `task.join.cancel %t, ok -> @ok, cancelled -> @c` (terminator) | `task<T>` (consumed on both edges); `@ok(T)`, `@c(task<T>)` | `task.wait` | `ok` edge: as `task.join` — the task is joined and its loans end. `cancelled` edge: the same task comes back as the parameter of `@c`; it is not joined, and its loans stay `LOANED`, now owned by the new handle value | waiting operation; ready when the task has returned |
|
||||
| `%sh = task.shield.begin` | → `shield` | — | pushes `%sh` on the function's shield stack | increments the task's shield depth |
|
||||
| `task.shield.end %sh` | `shield` (consumed) | — | `%sh` must be the innermost live shield (`E4305`) | decrements the shield depth |
|
||||
|
||||
`shield` is linear, function-bound (as `scope` in spec 04 §33.1) and `Local`. The stack of live shields is part of the verifier state and must be identical on every edge into a block (`E3002`, like other linear state). Together with the innermost-first rule this makes shields properly nested regions. The depth is dynamic per task, so a function called inside a shield runs shielded.
|
||||
|
||||
The cancelled edge of the waiting `task.join` lets a parent react to its own cancellation, for example by forwarding it with `task.cancel %t` and then joining. Downward propagation is not automatic: changing `task.cancel` would change the published `tasks` feature.
|
||||
`task.join.cancel` is a new instruction, not a form of `task.join`. Its loan state machine extends spec 04 §34:
|
||||
|
||||
```text
|
||||
task<T> --task.join.cancel--+-- ok --------> joined; loans end; result T
|
||||
+-- cancelled -> same task<T> as a block parameter;
|
||||
not joined; loans stay LOANED
|
||||
```
|
||||
|
||||
If the child has already returned, the join completes on `ok` even when cancellation is pending (§2.1 step 1). The usual reaction on `cancelled` forwards the request and then waits:
|
||||
|
||||
```text
|
||||
cancelled(%t2: task<u64>):
|
||||
task.cancel %t2
|
||||
%r = task.join %t2
|
||||
```
|
||||
|
||||
Downward propagation is not automatic: changing `task.cancel` would change the published `tasks` feature.
|
||||
|
||||
**Shield invariant.** `task.shield.begin` pushes a token; `task.shield.end` accepts only the innermost live token:
|
||||
|
||||
```text
|
||||
%a = task.shield.begin
|
||||
%b = task.shield.begin
|
||||
task.shield.end %a ; E4305
|
||||
task.shield.end %b ; ok
|
||||
task.shield.end %a ; ok
|
||||
```
|
||||
|
||||
Every shield token is ended before `ret` (`E3002`). A trap needs no cleanup.
|
||||
|
||||
### 2.4 Effect `task.wait`
|
||||
|
||||
The new effect `task.wait` (no capability) is required by `channel.send`, `channel.recv`, `select` and `mutex.lock`. It is checked like every effect (spec 05 §9; `E3101`). It exists so that a function's public contract says whether it may wait for another task, which §4.4 needs.
|
||||
The new effect `task.wait` (no capability) says in a function's public contract that it may wait for another task. §4.4 needs that.
|
||||
|
||||
Joins do not need it. A function can join only tasks it spawned itself, because handles are function-bound, and spawning already requires `task.spawn`.
|
||||
**Gated requirement.** In a module declaring `cancellation`, every operation that may suspend requires `task.wait`: `task.join` (from `tasks`), `task.join.cancel`, `channel.send`, `channel.recv`, `select` and `mutex.lock`. It is checked like every effect (spec 05 §9; `E3101`).
|
||||
|
||||
A module that does not declare `cancellation` is unaffected. A published `tasks` module whose function joins without declaring `task.wait` stays valid with the same run record. Only modules that opt into the new feature get the extended effect semantics, and `channels` and `sync` imply it. This is an addition under spec 07 §8.7, because the stricter rule is attached to a feature that older modules do not declare.
|
||||
|
||||
A separate verifier-level "may suspend" analysis was rejected: it would add a second transitive property next to effects.
|
||||
|
||||
## 3. Channels (feature `channels`)
|
||||
|
||||
@@ -124,32 +161,41 @@ Linear element types such as `own<T>`, `file<…>` and `stream` are allowed. Mov
|
||||
|
||||
### 3.2 Instructions
|
||||
|
||||
All endpoint operations take a `mut` borrow of the endpoint. Only the close operations consume it.
|
||||
`send` and `recv` take a `mut` borrow of the endpoint, `dup` takes a `ref`, and the close operations consume it.
|
||||
|
||||
| Instruction | Operands → targets | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
| `channel.make T, %n, %mem, ok -> @ok, err -> @err` (terminator) | `%n: usize` capacity, `%mem: cap<mem.alloc>`; `@ok(sender<T>, receiver<T>)`, `@err(alloc_error)` | `mem.alloc` | element rules of §3.1 | charges `%n × size(T)` bytes to `%mem` (spec 03 §19); a capacity of 0 creates a rendezvous channel. Never waits |
|
||||
| `%tx2 = channel.sender.dup %txb` | `mut<sender<T>>` → `sender<T>` | — | — | one more sender of the same channel |
|
||||
| `channel.send %txb, %v, ok -> @ok, closed -> @closed, cancelled -> @c` (terminator) | `mut<sender<T>>`, `T`; targets without parameters | `task.wait` | `%v` is consumed on the `ok` edge only. On `closed` and `cancelled` it is still live and owned by the caller | waiting operation (§3.3) |
|
||||
| `%tx2 = channel.sender.dup %txr` | `ref<sender<T>>` → `sender<T>` | — | — | a new, separately linear sender of the same channel; `open_senders += 1`; the original stays live |
|
||||
| `channel.send %txb, %v, ok -> @ok, closed -> @closed, cancelled -> @c` (terminator) | `mut<sender<T>>`, `T` (consumed on every edge); `@ok()`, `@closed(T)`, `@c(T)` | `task.wait` | on `closed` and `cancelled` the value comes back as the target's parameter; on `ok` it is gone | waiting operation (§3.3) |
|
||||
| `channel.recv %rxb, ok -> @ok, closed -> @closed, cancelled -> @c` (terminator) | `mut<receiver<T>>`; `@ok(T)` | `task.wait` | — | waiting operation (§3.3) |
|
||||
| `channel.close_sender %tx` | `sender<T>` (consumed) | — | — | if it was the last sender, a drained receiver now sees `closed`; a scheduling point |
|
||||
| `channel.close_sender %tx` | `sender<T>` (consumed) | — | — | `open_senders -= 1`; at 0 no new value can ever enter; a scheduling point |
|
||||
| `channel.close_receiver %rx, ok -> @ok, pending -> @pending` (terminator) | `receiver<T>` (consumed on both edges); `@pending(receiver<T>)` | — | — | §3.4; a scheduling point |
|
||||
| `select …` (terminator) | §3.5 | `task.wait` | §3.5 | §3.5 |
|
||||
|
||||
### 3.3 Ready conditions
|
||||
### 3.3 Channel states and ready conditions
|
||||
|
||||
Values are delivered in FIFO order.
|
||||
A channel has a FIFO buffer, a count `open_senders` of live senders and a receiver state:
|
||||
|
||||
| State | Meaning |
|
||||
|---|---|
|
||||
| `OPEN` | the receiver is open and `open_senders > 0`: sends are accepted |
|
||||
| `RECEIVER_CLOSING` | the receiver has started closing (§3.4): no send is accepted; buffered values remain and must be received |
|
||||
| `DRAINED` | no future value can arrive (`open_senders = 0`, or `RECEIVER_CLOSING`) and the buffer is empty: `recv` reports `closed`, `close_receiver` takes `ok` |
|
||||
| `CLOSED` | the receiver has been consumed; sends report `closed` |
|
||||
|
||||
New values stop arriving in exactly two ways: the last sender closes, or the receiver starts closing. In both cases values already buffered are received, never destroyed: the runtime never silently drops an owned value.
|
||||
|
||||
| Operation | `ok`-ready | `closed`-ready |
|
||||
|---|---|---|
|
||||
| send, capacity `n > 0` | fewer than `n` values buffered | the receiver is closed or closing |
|
||||
| send, capacity 0 | the receiver is waiting in `channel.recv` or in a `select` with a receive arm on this channel | the receiver is closed or closing |
|
||||
| recv, capacity `n > 0` | a value is buffered | the buffer is empty and every sender is closed, or the receiver is closing |
|
||||
| recv, capacity 0 | a sender is waiting in `channel.send` or in a `select` with a send arm on this channel | as above |
|
||||
| send, capacity `n > 0` | `OPEN` and fewer than `n` values buffered | `RECEIVER_CLOSING` or `CLOSED` |
|
||||
| send, capacity 0 | `OPEN` and the receiver is waiting in `channel.recv` or in a `select` with a receive arm on this channel | `RECEIVER_CLOSING` or `CLOSED` |
|
||||
| recv, capacity `n > 0` | a value is buffered | `DRAINED` |
|
||||
| recv, capacity 0 | `OPEN` and a sender is waiting in `channel.send` or in a `select` with a send arm on this channel | `DRAINED` |
|
||||
|
||||
`closed` takes precedence for a send: a send to a closed receiver is `closed` even if there is space. For a receive, buffered values take precedence: `closed` is reported only after the channel is drained. This is the RFC's answer to "last sender closed → recv after the queue is drained → closed". It is a concurrency state, not an `io_error`.
|
||||
|
||||
On a rendezvous channel, a sender waiting in `channel.send` holds its value until a receiver takes it. A sender that leaves on `cancelled` or `closed` keeps the value. Waiting rendezvous senders are matched in the order they began to wait. When a send completes against a waiting `select`, that `select` resumes on the matched arm without a draw.
|
||||
On a rendezvous channel, a sender waiting in `channel.send` holds its value until a receiver takes it. A sender that leaves on `cancelled` or `closed` gets the value back as a block parameter. Waiting rendezvous senders are matched in the order they began to wait. When a send completes against a waiting `select`, that `select` resumes on the matched arm without a draw.
|
||||
|
||||
A **synchronization edge** runs from a successful send to the receive that obtains the value (spec 04 §12). In the cooperative interpreter this is immediate; native backends must provide acquire/release ordering.
|
||||
|
||||
@@ -157,12 +203,12 @@ A **synchronization edge** runs from a successful send to the receive that obtai
|
||||
|
||||
`channel.close_receiver` never drops a value:
|
||||
|
||||
- if the buffer is empty, the receiver is consumed and the channel is closed for sending. Waiting and future sends end `closed`. The program continues at `@ok`;
|
||||
- otherwise the channel enters the **closing** state. Sends end `closed` from now on, and waiting rendezvous senders also end `closed`. The receiver comes back on `@pending`. The program drains it with `channel.recv` until `closed` (buffered values first) and then closes it again, which now takes `@ok`.
|
||||
- if the buffer is empty, the receiver is consumed and the channel becomes `CLOSED`. Waiting and future sends end `closed`. The program continues at `@ok`;
|
||||
- otherwise the channel enters `RECEIVER_CLOSING`. Sends end `closed` from now on, and waiting rendezvous senders also end `closed`. The receiver comes back on `@pending`. The program drains it with `channel.recv` until `closed` (buffered values first) and then closes it again, which now takes `@ok`.
|
||||
|
||||
Because the closing state admits no new values, the drain loop terminates. A receiver can therefore stop early without leaking linear values, and the verifier needs no knowledge of the buffer contents.
|
||||
|
||||
The channel's memory is returned to the `mem.alloc` budget when the receiver and the last sender have both been closed, at whichever of those closes comes last. That is an explicit instruction, so there is no hidden destructor.
|
||||
The channel's memory is returned to the `mem.alloc` budget when the channel is `CLOSED` and `open_senders = 0`, at whichever of those closes comes last. That is an explicit instruction, so there is no hidden destructor.
|
||||
|
||||
### 3.5 `select`
|
||||
|
||||
@@ -177,13 +223,16 @@ select [recv %rxb1, ok -> @a, closed -> @a_done],
|
||||
- **Arms** are channel operations, nothing else: `[recv %rxb, ok -> @x, closed -> @y]` with `@x(T)`, and `[send %txb, %v, ok -> @x, closed -> @y]`. A `select` has at least one arm and exactly one `cancelled` target. The arm targets have the parameters of the corresponding `channel.recv`/`channel.send` targets.
|
||||
- **Readiness.** An arm is ready when its operation is `ok`-ready or `closed`-ready (§3.3). The `select` as a whole is a waiting operation (§2.1) whose ready condition is "at least one arm is ready".
|
||||
- **Choice.** If exactly one arm is ready, it is taken. If `k ≥ 2` arms are ready, the scheduler draws `x = next()` from the schedule generator and takes the ready arm number `x mod k`, in textual order. The draw counts as a scheduler choice. It is not "first in text", so schedule exploration covers alternative ready branches. With `schedules: N`, task scheduling and arm selection vary together, from one stream.
|
||||
- **Ownership along edges.** A value in a send arm is consumed only on that arm's `ok` edge. On every other edge of the `select` it is still live. The same value may therefore appear in several send arms:
|
||||
- **Ownership along edges.** Let `V` be the distinct values named by the send arms, in order of first appearance. The `select` consumes every value of `V` on every edge. Each target receives, after its own parameters (the received `T` on a receive arm's `ok`), the values of `V` that were not sent on that edge, in the order of `V`. So ownership is visible in the CFG; nothing is restored implicitly:
|
||||
|
||||
```text
|
||||
select [send %tx1, %x, ok -> @to1, closed -> @c1], [send %tx2, %x, ok -> @to2, closed -> @c2], cancelled -> @c
|
||||
; V = (%x)
|
||||
; @to1() @to2() %x was sent
|
||||
; @c1(%x) @c2(%x) @c(%x) %x comes back
|
||||
```
|
||||
|
||||
This is the branch-edge ownership rule (spec 06 §6.3) applied per arm. The verifier applies the transfer function of the chosen arm to each edge.
|
||||
The same value may appear in several send arms, because only one arm runs. This is the branch-edge ownership rule (spec 06 §6.3) applied per arm. A plain `channel.send` is the one-arm case.
|
||||
- **Borrows.** Arms may name the same endpoint borrow more than once. Only one arm runs.
|
||||
|
||||
## 4. Mutex (feature `sync`)
|
||||
@@ -219,19 +268,18 @@ A trap terminates the whole execution (spec 04 §33.2), so there is no state whe
|
||||
|
||||
On every path where a `guard<T>` is live, the function MUST NOT execute:
|
||||
|
||||
- a waiting operation (§2.1), including `mutex.lock`;
|
||||
- `task.spawn`, or `task.join` in either form;
|
||||
- an instruction that requires the effect `task.wait` or `task.spawn` (in a `sync` module these are every suspending operation of §2.4, `task.join` included, and `task.spawn`);
|
||||
- a `call` (or an indirect call) of a function whose declared effects include `task.wait` or `task.spawn`.
|
||||
|
||||
Violations are `E4304` (`sync.wait_while_locked`), naming the guard and the instruction.
|
||||
|
||||
Consequences, by construction:
|
||||
|
||||
- a task holds at most one guard at a time, since `mutex.lock` is itself a waiting operation;
|
||||
- a task holds at most one guard at a time, since `mutex.lock` requires `task.wait`: `lock A; lock B` is `E4304`, and the classic lock-order deadlock cannot be expressed in safe AIR 0;
|
||||
- the holder of a lock never waits for another task. Every wait in `mutex.lock` ends when the holder runs to its `mutex.unlock`, unless the holder runs forever (fuel bounds that) or traps (which ends the run). **Mutexes alone cannot deadlock**, and no lock-ordering discipline is needed;
|
||||
- a critical section may call ordinary functions and pass them the `mut<T>` from `mutex.borrow`. Their effect sets say whether they may wait.
|
||||
|
||||
The check reads only the caller's guard state and the callees' declared effects, so it stays intraprocedural (spec 04 §33 invariant 6). `sync` depends on `effects` through `cancellation`, so callee effect sets are always available. This is stricter than common runtimes. A future feature may relax it if evaluation shows the need. It is deliberately not reserved now.
|
||||
The check reads only the caller's guard state and the callees' declared effects, so it stays intraprocedural (spec 04 §33 invariant 6). `sync` depends on `cancellation`, so callee effect sets are always available and `task.join` carries `task.wait`. This is stricter than common runtimes. A future feature may relax it if evaluation shows the need. It is deliberately not reserved now.
|
||||
|
||||
## 5. Scheduler and run record (resolves Q-013)
|
||||
|
||||
@@ -250,7 +298,9 @@ effects [task.wait]
|
||||
entry:
|
||||
%txb = borrow.mut %tx
|
||||
%v = const.u64 7
|
||||
channel.send %txb, %v, ok -> @done, closed -> @done, cancelled -> @done
|
||||
channel.send %txb, %v, ok -> @done, closed -> @back, cancelled -> @back
|
||||
back(%w: u64): ; the value comes back; u64 needs no cleanup
|
||||
br @done
|
||||
done:
|
||||
borrow.end %txb
|
||||
channel.close_sender %tx
|
||||
@@ -294,6 +344,8 @@ locked(%g: guard<u64>):
|
||||
|
||||
```text
|
||||
select [send %a, %job, ok -> @sent_a, closed -> @a_gone], [send %b, %job, ok -> @sent_b, closed -> @b_gone], cancelled -> @stop
|
||||
; @sent_a() @sent_b() — %job went to one worker
|
||||
; @a_gone(%j: own<@Job>) @b_gone(%j: own<@Job>) @stop(%j: own<@Job>) — the job comes back
|
||||
```
|
||||
|
||||
## Rejected examples
|
||||
@@ -312,7 +364,7 @@ locked(%g: guard<u64>):
|
||||
```text
|
||||
channel.send %txb, %v, ok -> @sent, closed -> @closed, cancelled -> @c
|
||||
sent:
|
||||
%w = struct.get @Msg.id, %v ; E2001: %v was moved on the ok edge
|
||||
%w = own.take %v ; E2001: %v was consumed by the send
|
||||
```
|
||||
|
||||
```text
|
||||
@@ -337,11 +389,11 @@ New codes:
|
||||
Existing codes used:
|
||||
|
||||
- `E4001` and `E1001` for element rules;
|
||||
- `E2001` and `E2002` for moved send values;
|
||||
- `E2001` and `E2002` for values consumed by `send`/`select`;
|
||||
- `E2102` for guard and access borrows;
|
||||
- `E3002` for leaked endpoints, guards and shields, and for differing shield stacks at a join;
|
||||
- `E3101` for `task.wait`;
|
||||
- `E0006` for `rwlock`, `channel_transfer` and `guard_transfer`.
|
||||
- `E0006` for `rwlock`, `channel_transfer`, `receiver_dup` and `guard_transfer`.
|
||||
|
||||
No new trap codes. No new environment outcomes: deadlocks remain `blocked`.
|
||||
|
||||
@@ -352,16 +404,22 @@ On acceptance:
|
||||
- spec 04: new §37 (waiting and cancellation), §38 (channels), §39 (select), §40 (mutex), §41 (critical-section rule); §14–§16 point to them; §11 marks RwLock as deferred;
|
||||
- spec 02 §6 / spec 04 §35: Send/Share rows for the new types;
|
||||
- spec 05: effect `task.wait`;
|
||||
- spec 07 §8: types and the `select` syntax; spec 07a: contract rows;
|
||||
- spec 07 §8.11: types and the `select` syntax; spec 07a: contract rows;
|
||||
- spec 08: verifier stages (shield stack, guard state, E4304);
|
||||
- spec 11 §8: choice points, record;
|
||||
- `reference/air-text.ebnf`, `air-features.md`, `effects.md`, `error-codes.md`;
|
||||
- `reference/air-features.md`, `effects.md`, `error-codes.md`;
|
||||
- `docs/agent/bundle.txt`;
|
||||
- Q-013 marked resolved.
|
||||
|
||||
## Compatibility and migration
|
||||
|
||||
Additive under spec 07 §8.7: three new features, new types, instructions, one effect and two diagnostic codes. `tasks` and every published feature keep their meaning. The plain `task.join` is not a cancellation point, and `task.cancelled` ignores shields (it reads the raw flag). The only change to the registry beyond additions is the dependency lists of the reserved `channels` and `sync` (decision D1). No module can use a reserved feature today, so no accepted or rejected module changes status.
|
||||
Additive under spec 07 §8.7: three new features, new types, instructions, one effect and two diagnostic codes. `tasks` and every published feature keep their meaning:
|
||||
|
||||
- the plain `task.join` is not a cancellation point;
|
||||
- `task.cancelled` ignores shields (it reads the raw flag);
|
||||
- `task.join` requires `task.wait` only in modules declaring `cancellation`, which no existing module does.
|
||||
|
||||
The dependency lists of the reserved `channels` and `sync` change under the general rule of §1 (D1). No module can use a reserved feature, so no accepted or rejected module changes status.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
@@ -379,7 +437,7 @@ Additive under spec 07 §8.7: three new features, new types, instructions, one e
|
||||
- per-edge consumption for `channel.send` and `select`, which reuses the existing per-edge linear machinery (as for `fs.close`).
|
||||
- **New syntax:**
|
||||
- 3 features, 5 types, 1 effect;
|
||||
- 13 instructions: `task.check_cancel`, waiting `task.join`, `task.shield.begin`/`end`, `channel.make`/`sender.dup`/`send`/`recv`/`close_sender`/`close_receiver`, `select`, `mutex.make`/`take`/`lock`/`borrow`/`unlock` (counting `select` once).
|
||||
- 17 instructions: `task.check_cancel`, `task.join.cancel`, `task.shield.begin`/`end`, `channel.make`/`sender.dup`/`send`/`recv`/`close_sender`/`close_receiver`, `select`, `mutex.make`/`take`/`lock`/`borrow`/`unlock` (counting `select` once).
|
||||
- **Interactions:** loans (sharing a `ref<mutex>`), effects (`task.wait`, the E4304 call rule), linearity (endpoints, guards, shields), heap budgets (channel buffers), the scheduler (choices).
|
||||
- **Repairability:**
|
||||
- each outcome is an edge the agent must route, so a forgotten case is a CFG error, not a runtime surprise;
|
||||
@@ -398,15 +456,14 @@ Additive under spec 07 §8.7: three new features, new types, instructions, one e
|
||||
- **`select` picks the first ready arm in text**: reproducible, but schedule exploration would never see the other branch. Rejected for a seeded draw.
|
||||
- **`select` over arbitrary expressions**: rejected; arms are operations with fixed transfer functions.
|
||||
- **Cancellation as a trap or a universal `TaskError`**: rejected; outcomes are edges.
|
||||
- **Automatic downward cancellation propagation**: would change the published `task.cancel`. Instead the waiting `task.join` lets a parent forward cancellation explicitly.
|
||||
- **Automatic downward cancellation propagation**: would change the published `task.cancel`. Instead `task.join.cancel` lets a parent forward cancellation explicitly.
|
||||
- **A cancellable form of `task.join`** (same opcode with edges): a new instruction is clearer and keeps the published opcode's contract untouched.
|
||||
- **Restoring a sent value implicitly on `closed`/`cancelled`** (the same SSA value stays live): ownership would not be visible in the CFG; rejected for block parameters.
|
||||
- **`task.wait` required by `task.join` unconditionally**: would make published `tasks` modules fail with `E3101`; rejected for the gated rule (§2.4).
|
||||
- **Shield as a lexical block or a separate task**: AIR has no lexical blocks; a linear token with innermost-first ending gives proper nesting with existing machinery.
|
||||
- **`RwLock` now**: read and write guards, fairness, starvation and several concurrent guards add little expressive power over a mutex, ownership partitioning and channels. Deferred (reserved `rwlock`).
|
||||
- **Channel capacity in the type, buffer in frame storage**: avoids the heap but makes endpoints borrows, which cannot be moved into tasks or returned. Rejected for linear endpoints with an explicit `mem.alloc` charge.
|
||||
|
||||
## Unresolved questions
|
||||
|
||||
Decisions requested from the owner:
|
||||
|
||||
- **D1 — dependencies of the reserved `channels` and `sync`.** The registry says a reserved feature's name and dependencies are fixed, but `[ownership]` cannot state the semantics, and §1 needs `cancellation`/`heap` and `cancellation`. No module is affected, since reserved features are unusable. Proposal: allow the change this once, recorded in DD-014's log.
|
||||
- **D2 — waiting `task.join`.** Proposal: a new terminator form in `cancellation`, with no automatic propagation. Alternative: no cancellable join at all; parents must poll `task.check_cancel` between joins.
|
||||
- **D3 — `channel.sender.dup` in format 0.** Proposal: yes. Several producers into one receiver is the common fan-in, and "last sender closed" needs it to be meaningful. Alternative: one sender per channel; fan-in uses one channel per producer and `select`.
|
||||
None. Owner decisions: D1 general rule for reserved dependencies; D2 `task.join.cancel` as a new instruction returning the handle on `cancelled`; D3 `channel.sender.dup` from `ref<sender<T>>`, no receiver duplication (`receiver_dup` reserved). Deferred: `RwLock`, several receivers, atomics.
|
||||
@@ -119,6 +119,8 @@ This profile can eliminate a class of lock-order deadlocks but is not required f
|
||||
|
||||
Fairness is runtime-specific unless a runtime profile promises otherwise.
|
||||
|
||||
AIR format 0 defers `RwLock` (reserved feature `rwlock`; RFC 0012). The AIR mutex is specified in §40–§41.
|
||||
|
||||
## 12. Channels
|
||||
|
||||
Channels transfer ownership.
|
||||
@@ -137,6 +139,8 @@ Unbounded queues are library constructs whose allocation behavior must be explic
|
||||
|
||||
A successful send synchronizes with the receive that obtains the transferred value.
|
||||
|
||||
AIR realization: §38 (separate `sender<T>`/`receiver<T>` endpoints, MPSC).
|
||||
|
||||
## 13. Island messaging
|
||||
|
||||
`Island<T>` is the preferred representation for large mutable messages and object graphs.
|
||||
@@ -158,6 +162,8 @@ select {
|
||||
|
||||
When multiple branches are ready, normal mode does not promise source-order selection. Deterministic mode must define a stable choice.
|
||||
|
||||
AIR realization: §39 (channel arms only; seeded choice among ready arms).
|
||||
|
||||
## 15. Cancellation
|
||||
|
||||
Cancellation is cooperative.
|
||||
@@ -168,6 +174,8 @@ Cancellation is observed only at explicit cancellation points, including selecte
|
||||
|
||||
Structured cancellation propagates from parent to descendants.
|
||||
|
||||
AIR realization: §37. In format 0 propagation is explicit: `task.join.cancel` lets a parent observe its own cancellation and forward it with `task.cancel`.
|
||||
|
||||
## 16. Cancellation shielding
|
||||
|
||||
A bounded scope may defer cancellation observation:
|
||||
@@ -180,6 +188,8 @@ task.cancel_shield {
|
||||
|
||||
The cancellation request remains pending and is observed after leaving the shield.
|
||||
|
||||
AIR realization: `task.shield.begin`/`task.shield.end` (§37.3).
|
||||
|
||||
## 17. Task failure
|
||||
|
||||
Task functions return normal values or `Result<T, E>`.
|
||||
@@ -419,7 +429,9 @@ Example: two workers square the two halves of one buffer in parallel; both loans
|
||||
| `ref<T>` | if `T` is `Share` | if `T` is `Share` |
|
||||
| `mut<T>` | if `T` is `Send` | no |
|
||||
| `slice<T>` / `slice_mut<T>` | as `ref<array>` / `mut<array>` | as `ref` / `mut` |
|
||||
| `task<T>`, `scope` | no (`Local`) | no |
|
||||
| `task<T>`, `scope`, `shield`, `guard<T>` | no (`Local`) | no |
|
||||
| `sender<T>`, `receiver<T>` | yes | no |
|
||||
| `mutex<T>` | if `T` is | if `T` is `Send` (the lock synchronizes access) |
|
||||
| struct, enum, array | if every field/payload/element is | if every field/payload/element is |
|
||||
|
||||
So an aggregate holding capabilities is `Send` and `Share` exactly when its other members are (Q-014).
|
||||
@@ -438,7 +450,7 @@ mut<T> → T: Send otherwise E4001
|
||||
|
||||
### 36.1 Model
|
||||
|
||||
In both profiles of the reference interpreter, tasks are cooperative execution units on one host thread. A task runs until it reaches a **scheduling point** — `task.spawn`, `task.join`, `task.cancel`, `task.cancelled`, a waiting operation (RFC 0012, I/O), or the end of its **quantum** — and then the scheduler chooses the next task to run among the runnable ones.
|
||||
In both profiles of the reference interpreter, tasks are cooperative execution units on one host thread. A task runs until it reaches a **scheduling point** — `task.spawn`, `task.join`, `task.cancel`, `task.cancelled`, a waiting operation or another scheduling point of §37–§40, I/O, or the end of its **quantum** — and then the scheduler chooses the next task to run among the runnable ones.
|
||||
|
||||
Native backends (Phase 7) may run tasks in parallel; by invariant 5 they may only produce outcomes that some interleaving of this model produces. This guarantee applies to safe programs that use neither the future weak-memory atomic facilities nor unsafe code; atomic memory ordering is governed by the Aji memory model (spec 04 §20–§31).
|
||||
|
||||
@@ -468,8 +480,199 @@ Varying the schedule seed while keeping `--seed` explores interleavings without
|
||||
|
||||
### 36.4 Run record
|
||||
|
||||
The record of a run that spawned tasks adds `"schedule":{"seed":S,"quantum":Q,"choices":C}`, where `S` is the schedule seed and `C` the number of scheduler choices made; two runs with equal records made the same choices.
|
||||
The record of a run that spawned tasks or drew among `select` arms adds `"schedule":{"seed":S,"quantum":Q,"choices":C}`, where `S` is the schedule seed and `C` the number of scheduler choices made, including draws among ready `select` arms (§39); two runs with equal records made the same choices. No draw is made when there is only one candidate.
|
||||
|
||||
### 36.5 Schedule exploration
|
||||
|
||||
The conformance runner gains `schedules: N`: the test runs with schedule seeds `0 … N−1` and an unchanged program seed, and every run must satisfy the expectation. Systematic exploration (DPOR) is Phase 5 work.
|
||||
The conformance runner gains `schedules: N`: the test runs with schedule seeds `0 … N−1` and an unchanged program seed, and every run must satisfy the expectation. Task choices and `select` choices vary together, from one stream. Systematic exploration (DPOR) is Phase 5 work.
|
||||
|
||||
## 37. Waiting and cancellation in AIR (feature `cancellation`)
|
||||
|
||||
Decision record: RFC 0012. Depends on `effects`, `tasks`.
|
||||
|
||||
Invariants of §37–§41:
|
||||
|
||||
1. **Explicit outcomes.** Every waiting operation completes on exactly one of its declared edges (`ok`, `closed`, `cancelled`). Cancellation is never a trap.
|
||||
2. **Ownership transfer.** A value sent on a channel is owned by the sending operation until it completes. On `ok` it belongs to the channel and then to the receiver; on `closed` or `cancelled` it is handed back as a block parameter. A value is never observable by two tasks.
|
||||
3. **No silent drop.** A value leaves a channel only through a receive. A receiver is consumed only when the channel is empty and no further value can enter it.
|
||||
4. **No wait under a lock.** While a task holds a `guard<T>`, it executes no operation that may suspend. This is checked statically, including through calls (§41).
|
||||
5. **Cooperative cancellation.** Cancellation is observed only at cancellation points (§37.2). An operation that can complete without waiting completes. Inside a shield cancellation is never observed. Shields nest properly.
|
||||
6. **Reproducibility.** Task choices and choices among ready `select` arms are drawn from the one schedule generator (§36.2).
|
||||
7. **No hidden cleanup.** Nothing is unlocked, closed or dropped implicitly. A trap while holding a guard terminates the whole execution (§33.2).
|
||||
|
||||
### 37.1 The waiting-operation rule
|
||||
|
||||
The **waiting operations** are `task.join.cancel`, `channel.send`, `channel.recv`, `select` and `mutex.lock`. Each has a ready condition. One rule covers all of them:
|
||||
|
||||
```text
|
||||
1. If the operation is ready, it completes with that outcome (ok or closed).
|
||||
Pending cancellation is not consulted.
|
||||
2. Otherwise, if cancellation is observable, it completes on its cancelled edge.
|
||||
3. Otherwise the task waits. It becomes runnable when the operation becomes ready
|
||||
or cancellation becomes observable. When it resumes, go to 1.
|
||||
```
|
||||
|
||||
**Cancellation is observable** in a task when its cancellation-request flag (§33.2) is set and its shield depth is 0. A waiting operation is a scheduling point when it completes and when it begins to wait; fuel is paid once, when it first begins (§36.3). A waiting task counts as waiting for global quiescence (spec 11 §8). The plain `task.join` and the I/O intrinsics are not cancellation points in format 0.
|
||||
|
||||
### 37.2 Cancellation points
|
||||
|
||||
| Point | Observes cancellation |
|
||||
|---|---|
|
||||
| `task.check_cancel` | always when observable |
|
||||
| `task.join.cancel`, `channel.send`, `channel.recv`, `select`, `mutex.lock` | only when it would otherwise wait (§37.1 step 2) |
|
||||
|
||||
`task.cancelled` (§33.2) is not a cancellation point: it returns the raw request flag and ignores shields.
|
||||
|
||||
### 37.3 Instructions
|
||||
|
||||
| Instruction | Operands → result | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
| `task.check_cancel, ok -> @ok, cancelled -> @c` (terminator) | targets without parameters | — | — | `@c` if cancellation is observable, else `@ok`; a scheduling point |
|
||||
| `task.join.cancel %t, ok -> @ok, cancelled -> @c` (terminator) | `task<T>` (consumed on both edges); `@ok(T)`, `@c(task<T>)` | `task.wait` | `ok`: as `task.join`, the task is joined and its loans end. `cancelled`: the same task is the parameter of `@c`; it is not joined and its loans stay `LOANED`, owned by the new handle value | waiting operation; ready when the task has returned |
|
||||
| `%sh = task.shield.begin` | → `shield` | — | pushes `%sh` on the function's shield stack | increments the task's shield depth |
|
||||
| `task.shield.end %sh` | `shield` (consumed) | — | `%sh` MUST be the innermost live shield (`E4305`) | decrements the shield depth |
|
||||
|
||||
Loan state machine of `task.join.cancel` (extends §34):
|
||||
|
||||
```text
|
||||
task<T> --task.join.cancel--+-- ok --------> joined; loans end; result T
|
||||
+-- cancelled -> same task<T> as a block parameter;
|
||||
not joined; loans stay LOANED
|
||||
```
|
||||
|
||||
If the child has already returned, the join completes on `ok` even when cancellation is pending. Cancellation does not propagate to children automatically; a parent forwards it explicitly:
|
||||
|
||||
```text
|
||||
cancelled(%t2: task<u64>):
|
||||
task.cancel %t2
|
||||
%r = task.join %t2
|
||||
```
|
||||
|
||||
`shield` is linear, function-bound (§33.1) and `Local`. The stack of live shields is part of the verifier state and MUST be identical on every edge into a block (`E3002`); every shield is ended before `ret` (`E3002`). Shield depth is dynamic per task, so a function called inside a shield runs shielded.
|
||||
|
||||
```text
|
||||
%a = task.shield.begin
|
||||
%b = task.shield.begin
|
||||
task.shield.end %a ; E4305
|
||||
task.shield.end %b ; ok
|
||||
task.shield.end %a ; ok
|
||||
```
|
||||
|
||||
### 37.4 Effect `task.wait`
|
||||
|
||||
The effect `task.wait` (no capability) states that a function may wait for another task. **In a module declaring `cancellation`**, every operation that may suspend requires it: `task.join`, `task.join.cancel`, `channel.send`, `channel.recv`, `select` and `mutex.lock` (`E3101`, spec 05 §9.3). A module that does not declare `cancellation` keeps the semantics of §33 unchanged; `channels` and `sync` imply `cancellation`.
|
||||
|
||||
## 38. Channels in AIR (feature `channels`)
|
||||
|
||||
Decision record: RFC 0012. Depends on `cancellation`, `heap`.
|
||||
|
||||
### 38.1 Types
|
||||
|
||||
| Type | Meaning | Class |
|
||||
|---|---|---|
|
||||
| `sender<T>` | a sending endpoint | linear |
|
||||
| `receiver<T>` | the receiving endpoint, exactly one per channel | linear |
|
||||
|
||||
Endpoints may be block arguments, function parameters and return values, and may be moved into tasks. They may not be aggregate members (reserved `linear_aggregates`) or heap contents. Channels are MPSC: several receivers are the reserved feature `receiver_dup`.
|
||||
|
||||
**Element rules** for `T` (also used by `mutex<T>`, §40):
|
||||
|
||||
- `T: Send` (`E4001`);
|
||||
- `T` contains no borrow, `scope`, `task<…>`, `shield` or `guard<…>` (`E1001`);
|
||||
- `T` contains no `sender<…>` or `receiver<…>`: reserved feature `channel_transfer` (`E0006`).
|
||||
|
||||
Linear elements (`own<T>`, `file<…>`, `stream`, …) are allowed.
|
||||
|
||||
### 38.2 Instructions
|
||||
|
||||
| Instruction | Operands → targets | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
| `channel.make T, %n, %mem, ok -> @ok, err -> @err` (terminator) | `%n: usize`, `%mem: cap<mem.alloc>`; `@ok(sender<T>, receiver<T>)`, `@err(alloc_error)` | `mem.alloc` | element rules | charges `%n × size(T)` bytes (spec 03 §19); capacity 0 is a rendezvous channel; never waits |
|
||||
| `%tx2 = channel.sender.dup %txr` | `ref<sender<T>>` → `sender<T>` | — | — | a new, separately linear sender of the same channel; `open_senders += 1` |
|
||||
| `channel.send %txb, %v, ok -> @ok, closed -> @closed, cancelled -> @c` (terminator) | `mut<sender<T>>`, `T` (consumed on every edge); `@ok()`, `@closed(T)`, `@c(T)` | `task.wait` | on `closed` and `cancelled` the value comes back as the target's parameter | waiting operation (§38.3) |
|
||||
| `channel.recv %rxb, ok -> @ok, closed -> @closed, cancelled -> @c` (terminator) | `mut<receiver<T>>`; `@ok(T)`, `@closed()`, `@c()` | `task.wait` | — | waiting operation (§38.3) |
|
||||
| `channel.close_sender %tx` | `sender<T>` (consumed) | — | — | `open_senders -= 1`; a scheduling point |
|
||||
| `channel.close_receiver %rx, ok -> @ok, pending -> @pending` (terminator) | `receiver<T>` (consumed on both edges); `@ok()`, `@pending(receiver<T>)` | — | — | §38.4; a scheduling point |
|
||||
|
||||
### 38.3 States and ready conditions
|
||||
|
||||
A channel has a FIFO buffer, a count `open_senders` and a receiver state:
|
||||
|
||||
| State | Meaning |
|
||||
|---|---|
|
||||
| `OPEN` | receiver open and `open_senders > 0`: sends are accepted |
|
||||
| `RECEIVER_CLOSING` | the receiver has started closing: no send is accepted; buffered values remain and MUST be received |
|
||||
| `DRAINED` | no future value can arrive (`open_senders = 0`, or `RECEIVER_CLOSING`) and the buffer is empty |
|
||||
| `CLOSED` | the receiver has been consumed |
|
||||
|
||||
New values stop arriving in exactly two ways: the last sender closes, or the receiver starts closing. In both cases buffered values are received, never destroyed.
|
||||
|
||||
| Operation | `ok`-ready | `closed`-ready |
|
||||
|---|---|---|
|
||||
| send, capacity `n > 0` | `OPEN` and fewer than `n` values buffered | `RECEIVER_CLOSING` or `CLOSED` |
|
||||
| send, capacity 0 | `OPEN` and the receiver waits in `channel.recv` or in a `select` with a receive arm on this channel | `RECEIVER_CLOSING` or `CLOSED` |
|
||||
| recv, capacity `n > 0` | a value is buffered | `DRAINED` |
|
||||
| recv, capacity 0 | `OPEN` and a sender waits in `channel.send` or in a `select` with a send arm on this channel | `DRAINED` |
|
||||
|
||||
A waiting rendezvous sender holds its value until a receiver takes it; waiting rendezvous senders are matched in the order they began to wait. When an operation completes against a waiting `select`, that `select` resumes on the matched arm without a draw. A successful send synchronizes with the receive that obtains the value (§12).
|
||||
|
||||
### 38.4 Closing the receiver
|
||||
|
||||
- If the buffer is empty, the receiver is consumed, the channel becomes `CLOSED` (waiting and future sends end `closed`) and control continues at `@ok`.
|
||||
- Otherwise the channel becomes `RECEIVER_CLOSING` (sends end `closed`, including waiting rendezvous senders) and the receiver comes back on `@pending`. The program receives until `closed` and closes again.
|
||||
|
||||
The drain terminates because no value can enter. The channel's memory returns to the `mem.alloc` budget at the close that leaves the channel `CLOSED` with `open_senders = 0`.
|
||||
|
||||
## 39. `select` in AIR (feature `channels`)
|
||||
|
||||
Decision record: RFC 0012. Resolves Q-013.
|
||||
|
||||
```text
|
||||
select [recv %rxb, ok -> @a, closed -> @a_done], [send %txb, %v, ok -> @sent, closed -> @gone], cancelled -> @c
|
||||
```
|
||||
|
||||
- **Arms** are channel operations only: `[recv %rxb, ok -> @x, closed -> @y]` and `[send %txb, %v, ok -> @x, closed -> @y]`. A `select` has at least one arm and exactly one `cancelled` target. It requires `task.wait`.
|
||||
- **Readiness.** An arm is ready when its operation is `ok`-ready or `closed`-ready (§38.3). The `select` is a waiting operation (§37.1) that is ready when at least one arm is.
|
||||
- **Choice.** One ready arm is taken. With `k ≥ 2` ready arms the scheduler draws `x = next()` from the schedule generator (§36.2) and takes ready arm `x mod k` in textual order. The draw is a scheduler choice; textual order alone never decides.
|
||||
- **Ownership along edges.** Let `V` be the distinct values named by send arms, in order of first appearance. The `select` consumes every value of `V` on every edge. Each target receives, after its own parameters (the received `T` on a receive arm's `ok`), the values of `V` not sent on that edge, in the order of `V`:
|
||||
|
||||
```text
|
||||
select [send %tx1, %x, ok -> @to1, closed -> @c1], [send %tx2, %x, ok -> @to2, closed -> @c2], cancelled -> @c
|
||||
; @to1() @to2() %x was sent
|
||||
; @c1(%x) @c2(%x) @c(%x) %x comes back
|
||||
```
|
||||
|
||||
A plain `channel.send` is the one-arm case. Arms may name the same endpoint borrow more than once.
|
||||
|
||||
## 40. Mutex in AIR (feature `sync`)
|
||||
|
||||
Decision record: RFC 0012. Depends on `cancellation`. `RwLock` is deferred (reserved feature `rwlock`).
|
||||
|
||||
| Type | Meaning | Class |
|
||||
|---|---|---|
|
||||
| `mutex<T>` | mutual exclusion around a `T` (element rules of §38.1) | move-only; linear if `T` is |
|
||||
| `guard<T>` | the current task holds the lock | linear, function-bound, `Local` |
|
||||
|
||||
`mutex<T>` is opaque: no `borrow.field`, `load` or `store` reaches its contents; it is the verifier-known interior-mutability abstraction of §8. Tasks share it through a `ref<mutex<T>>` loan (§34). `guard<T>` as a parameter, return type or aggregate member is the reserved feature `guard_transfer` (`E0006`).
|
||||
|
||||
| Instruction | Operands → result | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
| `%m = mutex.make %v` | `T` (consumed) → `mutex<T>` | — | element rules | unlocked; no allocation |
|
||||
| `%v = mutex.take %m` | `mutex<T>` (consumed) → `T` | — | move rules | — |
|
||||
| `mutex.lock %mr, ok -> @ok, cancelled -> @c` (terminator) | `ref<mutex<T>>`; `@ok(guard<T>)`, `@c()` | `task.wait` | the guard is a child of `%mr` (ending `%mr` while it is live is `E2102`); §41 | waiting operation; ready when unlocked; acquire |
|
||||
| `%p = mutex.borrow %g` | `guard<T>` (not consumed) → `mut<T>` | — | child borrow of `%g`, ended before `mutex.unlock %g` (`E2102`) | — |
|
||||
| `mutex.unlock %g` | `guard<T>` (consumed) | — | — | release; all tasks waiting on this mutex become runnable and the first scheduled takes it; a scheduling point |
|
||||
|
||||
No fairness is promised (§32). There is no poisoning and no implicit unlock; an unconsumed guard is `E3002`.
|
||||
|
||||
## 41. The critical-section rule
|
||||
|
||||
On every path where a `guard<T>` is live, a function MUST NOT execute an instruction that requires the effect `task.wait` or `task.spawn`, nor call a function whose declared effects include `task.wait` or `task.spawn` (`E4304`, `sync.wait_while_locked`, naming the guard and the instruction).
|
||||
|
||||
Consequences:
|
||||
|
||||
- a task holds at most one guard: `mutex.lock` requires `task.wait`, so `lock A; lock B` is `E4304` and lock-order deadlock cannot be expressed in safe AIR 0;
|
||||
- a lock holder never waits for another task, so mutexes alone cannot deadlock;
|
||||
- a critical section may call functions without those effects and pass them the `mut<T>` from `mutex.borrow`.
|
||||
|
||||
The check uses only the guard state and the callees' declared effects, so it stays intraprocedural (§33 invariant 6).
|
||||
@@ -130,7 +130,7 @@ Effect names come from a closed registry, `reference/effects.md`, initially the
|
||||
| `net.connect`, `net.listen`, `net.read`, `net.write` | `cap<net.connect>`, `cap<net.listen>`, `cap<net.read>`, `cap<net.write>` |
|
||||
| `clock.read`, `random.read` | `cap<clock.read>`, `cap<random.read>` |
|
||||
| `process.spawn`, `process.env` | `cap<process.spawn>`, `cap<process.env>` |
|
||||
| `task.spawn`, `thread.spawn`, `thread.block` | none |
|
||||
| `task.spawn`, `task.wait`, `thread.spawn`, `thread.block` | none |
|
||||
| `atomic`, `atomic.weak` | none |
|
||||
| `ffi`, `unsafe` | none (governed by unsafe boundaries, spec 13) |
|
||||
|
||||
@@ -150,6 +150,7 @@ In a module that declares `effects`:
|
||||
|
||||
- For every `call @g(…)` in function `f`: `effects(g) ⊆ effects(f)`, otherwise `E3101` for each missing effect.
|
||||
- For every `intrinsic` in `f` (§11): the intrinsic's effect is in `effects(f)`, otherwise `E3101`.
|
||||
- For every other instruction whose contract names an effect (for example `task.spawn`, `channel.make`, and in a module declaring `cancellation` every suspending operation, spec 04 §37.4): that effect is in `effects(f)`, otherwise `E3101`.
|
||||
- Because every function is checked against its direct callees, the rule holds transitively, including for recursion.
|
||||
|
||||
**Indirect calls (normative for future features).** When function values are introduced, the effect set MUST be part of the function type, for example `fnptr<(u8) -> void effects [io.write]>`, and an indirect call is checked against that set exactly like a direct call. Otherwise dynamic calls would break transitivity.
|
||||
|
||||
@@ -266,6 +266,12 @@ Feature `heap`: `own<T>` and `own_array<T>` (linear owners, `T` a value type) an
|
||||
|
||||
A function header may carry, after its `effects` line, a line `trusted "<obligation>"`. String literals exist only in this position: `"` … `"` with the escapes `\"`, `\\` and `\n`, no line breaks inside, not empty (`E0001`). Rules: spec 13 §6.
|
||||
|
||||
### 8.11 Types and syntax of the features `cancellation`, `channels` and `sync`
|
||||
|
||||
Types: `shield` (`cancellation`), `sender<T>` and `receiver<T>` (`channels`), `mutex<T>` and `guard<T>` (`sync`). `shield` and `guard<T>` are linear and function-bound; `sender<T>`, `receiver<T>` are linear; `mutex<T>` is move-only, linear if `T` is. Rules: spec 04 §37–§41.
|
||||
|
||||
`select` is a terminator written on one line: one or more bracketed arms `[recv %b, ok -> @x, closed -> @y]` or `[send %b, %v, ok -> @x, closed -> @y]`, separated by commas, followed by `, cancelled -> @c`. `channel.make` takes a type operand first, like `local.alloc`.
|
||||
|
||||
### 8.8 Types and syntax of the features `ownership` and `arrays`
|
||||
|
||||
Feature membership: `local<T>`, `ref<T>`, `mut<T>` and the `from` clause belong to `ownership`; `array<T, N>`, `slice<T>`, `slice_mut<T>` and multi-result binding belong to `arrays`. Using them without declaring the feature is `E0006` reason `feature_not_declared`.
|
||||
|
||||
@@ -259,6 +259,16 @@ Allowed only in functions that declare the effect `unsafe` or are `trusted` (`E6
|
||||
|
||||
Types `scope` and `task<T>` (linear, function-bound), instructions `task.scope.begin`, `task.spawn %s, @f(…)`, `task.join`, `task.cancel`, `task.cancelled`, `task.scope.end`; loans, `Send`/`Share` and the scheduler: spec 04 §33–§36.
|
||||
|
||||
## Features `cancellation`, `channels`, `sync`
|
||||
|
||||
`cancellation`: type `shield`, effect `task.wait`, instructions `task.check_cancel`, `task.join.cancel`, `task.shield.begin`, `task.shield.end`; the waiting-operation rule: spec 04 §37.
|
||||
|
||||
`channels`: types `sender<T>`, `receiver<T>`, instructions `channel.make`, `channel.sender.dup`, `channel.send`, `channel.recv`, `channel.close_sender`, `channel.close_receiver`, `select`: spec 04 §38–§39.
|
||||
|
||||
`sync`: types `mutex<T>`, `guard<T>`, instructions `mutex.make`, `mutex.take`, `mutex.lock`, `mutex.borrow`, `mutex.unlock`; the critical-section rule: spec 04 §40–§41.
|
||||
|
||||
Every terminator of these features follows spec 07 §8.2: each named target receives exactly the parameters its contract lists.
|
||||
|
||||
## Run result
|
||||
|
||||
`aji run` executes the function `@main`, whose parameters MUST all be capabilities, bound by name at instantiation (spec 05 §10.2); without the `capabilities` feature it takes no parameters. On return it reports `{"status":"returned","value":V}` where `V` renders the returned value as JSON:
|
||||
|
||||
@@ -243,4 +243,4 @@ A `local<T>` is uninitialized after `local.alloc` and becomes initialized by `lo
|
||||
|
||||
## 14. Stage order
|
||||
|
||||
Verification stages run in this order, stopping after the first stage that reports an error (spec 07 §8.6): resource limits (including value and frame size), CFG structure (including `local.alloc` placement), SSA, types (including capability kinds and narrowing forms), effects, unsafe boundaries (spec 13 §6.4), initialization, borrows (including task loans and scope structure, spec 04 §33–§34), bounds.
|
||||
Verification stages run in this order, stopping after the first stage that reports an error (spec 07 §8.6): resource limits (including value and frame size), CFG structure (including `local.alloc` placement), SSA, types (including capability kinds and narrowing forms), effects, unsafe boundaries (spec 13 §6.4), initialization, borrows (including task loans and scope structure, spec 04 §33–§34; shield stacks, guards and the critical-section rule, spec 04 §37–§41), bounds.
|
||||
@@ -62,6 +62,8 @@ aji test --interleavings=10000
|
||||
|
||||
When `select` has multiple ready branches, deterministic mode must choose according to a stable rule and record the decision.
|
||||
|
||||
Rule (RFC 0012, spec 04 §39): a draw from the schedule generator among the ready arms, counted in the run record's `schedule.choices`.
|
||||
|
||||
## 7. Execution limits
|
||||
|
||||
Wall-clock time MUST NOT determine whether a run, test or verification terminates or what its outcome is.
|
||||
@@ -102,7 +104,7 @@ With several tasks, fuel is global: the sum of instructions executed by all task
|
||||
| schedule budget | how many interleavings schedule exploration examines |
|
||||
| quantum | how many instructions a task executes before a forced scheduling point |
|
||||
|
||||
The scheduler, its choice rule, the schedule seed (independent of the program seed), the task limit and the run-record fields are specified in spec 04 §36.
|
||||
The scheduler, its choice rule, the schedule seed (independent of the program seed), the task limit and the run-record fields are specified in spec 04 §36; waits, cancellation and `select` choices in spec 04 §37–§39.
|
||||
|
||||
## 8. Execution profiles
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ pub const effects = [_]Effect{
|
||||
.{ .name = "process.spawn", .authority = "process.spawn" },
|
||||
.{ .name = "random.read", .authority = "random.read" },
|
||||
.{ .name = "task.spawn", .authority = null },
|
||||
.{ .name = "task.wait", .authority = null },
|
||||
.{ .name = "thread.block", .authority = null },
|
||||
.{ .name = "thread.spawn", .authority = null },
|
||||
.{ .name = "unsafe", .authority = null },
|
||||
|
||||
@@ -25,17 +25,22 @@ pub const registry = [_]Feature{
|
||||
.{ .name = "arrays", .depends = &.{"ownership"}, .status = .published, .phase = 1 },
|
||||
.{ .name = "atomics", .depends = &.{"ownership"}, .status = .reserved, .phase = 5 },
|
||||
.{ .name = "borrow_joins", .depends = &.{"ownership"}, .status = .reserved, .phase = null },
|
||||
.{ .name = "cancellation", .depends = &.{ "effects", "ownership", "tasks" }, .status = .published, .phase = 3 },
|
||||
.{ .name = "capabilities", .depends = &.{ "effects", "ownership" }, .status = .published, .phase = 2 },
|
||||
.{ .name = "channels", .depends = &.{"ownership"}, .status = .reserved, .phase = 3 },
|
||||
.{ .name = "channel_transfer", .depends = &.{ "cancellation", "capabilities", "channels", "effects", "heap", "ownership", "resources", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "channels", .depends = &.{ "cancellation", "capabilities", "effects", "heap", "ownership", "resources", "tasks" }, .status = .published, .phase = 3 },
|
||||
.{ .name = "effects", .depends = &.{}, .status = .published, .phase = 2 },
|
||||
.{ .name = "guard_transfer", .depends = &.{ "cancellation", "effects", "ownership", "sync", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "heap", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .published, .phase = 2 },
|
||||
.{ .name = "islands", .depends = &.{ "capabilities", "effects", "heap", "ownership", "regions", "resources" }, .status = .reserved, .phase = 4 },
|
||||
.{ .name = "linear_aggregates", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "ownership", .depends = &.{}, .status = .published, .phase = 1 },
|
||||
.{ .name = "receiver_dup", .depends = &.{ "cancellation", "capabilities", "channels", "effects", "heap", "ownership", "resources", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "regions", .depends = &.{ "capabilities", "effects", "heap", "ownership", "resources" }, .status = .published, .phase = 2 },
|
||||
.{ .name = "resource_joins", .depends = &.{ "capabilities", "effects", "ownership", "resources" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "resources", .depends = &.{ "capabilities", "effects", "ownership" }, .status = .published, .phase = 2 },
|
||||
.{ .name = "sync", .depends = &.{"ownership"}, .status = .reserved, .phase = 3 },
|
||||
.{ .name = "rwlock", .depends = &.{ "cancellation", "effects", "ownership", "sync", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "sync", .depends = &.{ "cancellation", "effects", "ownership", "tasks" }, .status = .published, .phase = 3 },
|
||||
.{ .name = "task_borrow_returns", .depends = &.{ "ownership", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "task_transfer", .depends = &.{ "ownership", "tasks" }, .status = .reserved, .phase = null },
|
||||
.{ .name = "tasks", .depends = &.{"ownership"}, .status = .published, .phase = 3 },
|
||||
|
||||
@@ -55,6 +55,8 @@ pub const registry = [_]Code{
|
||||
.{ .id = "E4301", .kind = "task.live_child_escape", .meaning = "Scope exits with live child task" },
|
||||
.{ .id = "E4302", .kind = "task.borrow_escape", .meaning = "Child task borrow can outlive parent storage" },
|
||||
.{ .id = "E4303", .kind = "io.buffer_in_flight", .meaning = "Buffer accessed while async operation owns/borrows it" },
|
||||
.{ .id = "E4304", .kind = "sync.wait_while_locked", .meaning = "Suspending operation, spawn, or call of a waiting/spawning function while a lock guard is live" },
|
||||
.{ .id = "E4305", .kind = "task.shield_order", .meaning = "Shield ended while a more inner shield is live" },
|
||||
// E5xxx — AIR/verifier
|
||||
.{ .id = "E5001", .kind = "air.invalid_ssa", .meaning = "SSA definition/dominance failure" },
|
||||
.{ .id = "E5002", .kind = "air.invalid_cfg", .meaning = "Invalid block/terminator structure" },
|
||||
|
||||
Reference in new issue
Block a user