Phase 3: channels, mutex, select and cancellation points (RFC 0012)
- features cancellation, channels, sync supported - AIR model/parser/printer: shield, sender<T>, receiver<T>, mutex<T>, guard<T>; task.check_cancel, task.join.cancel, task.shield.*, channel.*, select (bracketed arms), mutex.* - verifier: arities (E5002), element rules (E4001/E1001, E0006 channel_transfer), guard_transfer gating, task.wait effect (gated for task.join by cancellation), per-edge consumption with values and handles returned as block parameters, loans moved to the handle on task.join.cancel's cancelled edge, shield order (E4305), guard children (E2102), critical-section rule (E4304) - interpreter: waiting-operation rule (ready, else cancelled if observable, else wait), shield depth, bounded and rendezvous channels with FIFO offers, drain-then-close receiver, budget release at the last close, select with seeded draw among ready arms, mutex wakeups; schedule record also after a select draw - report counts task.spawn, task.wait and channel allocations - spec erratum: mutex<T> is linear (format 0 has no droppable move-only class) - 30 new conformance tests (10 run with schedules, 4 accept, 16 reject); 6000-run schedule stress and 4350 mutants without failure
This commit is contained in:
1 parent
b82bc35c5f
commit
aaf32b6853
45 files changed
+2077
-43
No files matched your search
@@ -23,16 +23,16 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
| ID | Status | Task | Depends | Output | Done when |
|
||||
|---|---|---|---|---|---|
|
||||
| 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), `cancellation`, `channels`, `sync` (specified by RFC 0012) | P3-2 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
|
||||
| P3-2 | done | Contract tables: `task.*` (RFC 0011), `channel.*`, `mutex.*`, select, cancellation (RFC 0012, spec 04 §37–§41); `rwlock.*` deferred (reserved `rwlock`); `thread.*` deferred to native backends | P3-1 | spec 07 appendix | all spec 07 §4 fields including synchronization effects |
|
||||
| P3-2a | done | Publish features `tasks`, `cancellation`, `channels`, `sync` | 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 |
|
||||
| P3-6 | done | Concurrent alias / data-race rejection | P3-5 | `src/verifier/borrow.zig` | E4101 accept/reject; disjoint `split_mut` halves accepted in two tasks |
|
||||
| P3-7 | doing | Interpreter tasks: spawn, join, cancel, cancellation points, shields, task failure | P3-3 | `src/interp/` | cancellation observed only at defined points; shield defers it |
|
||||
| P3-8 | todo | Bounded and rendezvous channels with ownership transfer | P3-7 | interpreter + verifier | sender cannot use moved message (E2001); capacity 0 rendezvous test |
|
||||
| P3-9 | todo | Mutex and RwLock with linear guards | P3-7 | interpreter + verifier | guard not `Send`; unlock consumes guard; E3002 on leaked guard |
|
||||
| P3-10 | todo | Async I/O buffer claims | P3-7 | verifier + runtime | E4303 accept/reject |
|
||||
| P3-7 | done | Interpreter tasks: spawn, join, cancel, cancellation points, shields, task failure | P3-3 | `src/interp/` | cancellation observed only at defined points; shield defers it |
|
||||
| P3-8 | done | Bounded and rendezvous channels with ownership transfer | P3-7 | interpreter + verifier | sender cannot use moved message (E2001); capacity 0 rendezvous test |
|
||||
| P3-9 | done | Mutex with linear guards and the critical-section rule (E4304); RwLock deferred | P3-7 | interpreter + verifier | guard not `Send`; unlock consumes guard; E3002 on leaked guard |
|
||||
| P3-10 | todo | Async I/O buffer claims (depends on task-aware I/O, spec 04 §36.1; deferral proposed to the owner) | P3-7 | verifier + runtime | E4303 accept/reject |
|
||||
| P3-11 | todo | Blocking effect and blocking pool policy | P3-7 | spec 04 §18, runtime | `thread.block` from ordinary task handled per spec |
|
||||
| P3-12 | doing | Runner: `seed:`/`schedules:`/`quantum:` headers (schedule budget kept separate from fuel); stress modes (1/2/N workers, random, forced yield, slow consumer, cancellation during waits, I/O reordering) | P3-3 | `tools/conformance.zig` | stress modes selectable; failing seed printed for replay |
|
||||
| P3-13 | todo | Reference programs: parallel-map, channel transfer, tcp-echo with tasks | P3-8, P3-9 | `tests/programs/` | pass under all stress modes |
|
||||
|
||||
@@ -650,10 +650,10 @@ Decision record: RFC 0012. Depends on `cancellation`. `RwLock` is deferred (rese
|
||||
|
||||
| Type | Meaning | Class |
|
||||
|---|---|---|
|
||||
| `mutex<T>` | mutual exclusion around a `T` (element rules of §38.1) | move-only; linear if `T` is |
|
||||
| `mutex<T>` | mutual exclusion around a `T` (element rules of §38.1) | linear: consumed by `mutex.take` |
|
||||
| `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`).
|
||||
`mutex<T>` is opaque: no `borrow.field`, `load` or `store` reaches its contents; it is the verifier-known interior-mutability abstraction of §8. It is a linear SSA value like a resource (format 0 has no droppable move-only class): `borrow.ref %m` gives the `ref<mutex<T>>` that tasks share through a loan (§34), and `mutex.take` consumes it once no borrow is live. `guard<T>` as a parameter, return type or aggregate member is the reserved feature `guard_transfer` (`E0006`).
|
||||
|
||||
| Instruction | Operands → result | Effect | Verifier | Runtime |
|
||||
|---|---|---|---|---|
|
||||
|
||||
+1
-1
@@ -268,7 +268,7 @@ A function header may carry, after its `effects` line, a line `trusted "<obligat
|
||||
|
||||
### 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.
|
||||
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>` and `mutex<T>` are linear. 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`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user