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)
44 lines
3.9 KiB
Markdown
44 lines
3.9 KiB
Markdown
# Phase 3 — Structured concurrency
|
||
|
||
Non-normative. Part of the [implementation plan](README.md).
|
||
|
||
**Goal:** tasks that cannot outlive their scopes, ownership transfer through bounded channels, synchronized shared state, cooperative cancellation, and a deterministic scheduler.
|
||
|
||
**Exit criterion:** `parallel_map` and `channel_transfer` examples run under deterministic and randomized schedules.
|
||
|
||
**Spec inputs:** spec 04 §1–19, 11 §3, §5–6. RFC 0002 is proposed for acceptance (owner decision); acceptance integrates it into the spec.
|
||
|
||
**Blocking questions:** Q-013 deterministic `select` and seeds, Q-014 Send/Share for capability-holding aggregates. (Q-019 is resolved: fuel, schedule budget and quantum are defined in spec 11 §7.)
|
||
|
||
## Invariants (AGENTS.md change checklist applies to every task here)
|
||
|
||
- no child task outlives its scope; no silent detachment;
|
||
- values moved into migratable tasks are `Send`; concurrently read values are `Share`;
|
||
- concurrent mutable borrows are proven disjoint;
|
||
- buffers owned by in-flight async operations are inaccessible;
|
||
- every interpreter run is reproducible from its seed.
|
||
|
||
## Tasks
|
||
|
||
| 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-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-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 |
|
||
| P3-14 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||
|
||
## Conformance tests to add
|
||
|
||
Negative corpus entries owned by this phase: non-Send transfer, non-Share concurrent read, task escape, async buffer use while in flight. Plus E4101, E4302. Scheduler tests for every synchronization primitive (testing policy in AGENTS.md).
|