Phase 3: owner decisions on RFC 0012 implementation
- spec 04 §40: mutex<T> always linear, never copyable; mutex.take is the only way to dismantle it and needs no live borrow (hence no guard and no waiter); no unlock or destructor - P3-10 (async buffer claims, E4303) moved to P7-10 with task-aware I/O; E4303 stays reserved; Phase 3 scope closed - RFC 0012 erratum: consumption after send is E2002, use is E2001 - tests: take while borrowed (E2101), use after take (E3001)
This commit is contained in:
1 parent
aaf32b6853
commit
929132c81d
8 files changed
+50
-8
No files matched your search
+1
-1
@@ -64,7 +64,7 @@ Every registry code (`../reference/error-codes.md`) has a phase that must implem
|
||||
| E2102 borrow.outlives_owner | P1 | | E4201 atomic.invalid_order | P5 |
|
||||
| E2103 memory.out_of_bounds | P1 | | E4301 task.live_child_escape | P3 |
|
||||
| E2104 memory.region_generation | P2 | | E4302 task.borrow_escape | P3 |
|
||||
| E2110 island.escape | P4 | | E4303 io.buffer_in_flight | P3 |
|
||||
| E2110 island.escape | P4 | | E4303 io.buffer_in_flight | P7 (reserved) |
|
||||
| E2111 island.foreign_mutable_edge | P4 | | E5001 air.invalid_ssa | P0 |
|
||||
| E3001 resource.use_after_consume | P2 | | E5002 air.invalid_cfg | P0 |
|
||||
| E3002 resource.leak | P2 | | E5101 verifier.resource_limit | P0 |
|
||||
|
||||
@@ -67,7 +67,7 @@ Must include:
|
||||
- non-Send transfer;
|
||||
- non-Share concurrent read;
|
||||
- task escape;
|
||||
- async buffer use while in flight;
|
||||
- async buffer use while in flight (P7, with task-aware I/O);
|
||||
- invalid atomic ordering;
|
||||
- missing capability;
|
||||
- undeclared effect;
|
||||
|
||||
@@ -4,6 +4,8 @@ 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.
|
||||
|
||||
**Out of scope (owner decision):** async I/O and its buffer claims (`E4303` stays reserved; P7-10); `RwLock`, several receivers and atomics (later RFCs). No further features are added to Phase 3.
|
||||
|
||||
**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.
|
||||
@@ -15,7 +17,6 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
- 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
|
||||
@@ -32,7 +33,7 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
| 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-10 | moved | Async I/O buffer claims: moved to P7-10 (owner decision; needs task-aware I/O) | 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 |
|
||||
@@ -40,4 +41,4 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
|
||||
## 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).
|
||||
Negative corpus entries owned by this phase: non-Send transfer, non-Share concurrent read, task escape. Plus E4101, E4302. Scheduler tests for every synchronization primitive (testing policy in AGENTS.md).
|
||||
@@ -22,4 +22,5 @@ Non-normative. Part of the [implementation plan](README.md).
|
||||
| P7-6 | todo | FFI (`extern "C"`), `@repr(C)`, `@align`, packed fields | P7-3 | backend | E6101 accept/reject; ABI tests against C |
|
||||
| P7-7 | todo | Targets: Linux aarch64, macOS aarch64 | P7-5 | CI matrix | corpus passes on all three targets |
|
||||
| P7-8 | todo | Parity runner: interpreter vs native on the full corpus | P7-5 | `zig build parity` | identical stdout and trap records |
|
||||
| P7-10 | todo | Task-aware I/O (`io.read_start`, `io.write_start`, `io.wait`) and async buffer claims: buffer state `available → IN_FLIGHT → available`; access while `IN_FLIGHT` is `E4303` (moved from P3-10; needs an RFC) | P7-5 | RFC, verifier + runtime | E4303 accept/reject; deterministic completion order |
|
||||
| P7-9 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||||
@@ -5,7 +5,8 @@ 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: —
|
||||
Supersedes: —
|
||||
Erratum (owner decision after implementation): rejected example 3 corrected to `E2002` (consumption after `send`); `E2001` is a non-consuming use. `mutex<T>` is always linear (spec 04 §40).
|
||||
|
||||
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).
|
||||
|
||||
@@ -364,7 +365,8 @@ locked(%g: guard<u64>):
|
||||
```text
|
||||
channel.send %txb, %v, ok -> @sent, closed -> @closed, cancelled -> @c
|
||||
sent:
|
||||
%w = own.take %v ; E2001: %v was consumed by the send
|
||||
%w = own.take %v ; E2002: %v was already consumed by the send
|
||||
; (a non-consuming use, e.g. borrow.ref %v, is E2001)
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
@@ -658,13 +658,15 @@ Decision record: RFC 0012. Depends on `cancellation`. `RwLock` is deferred (rese
|
||||
| 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 | — |
|
||||
| `%v = mutex.take %m` | `mutex<T>` (consumed) → `T` | — | no live borrow of `%m` (`E2101`; `E4101` if lent to a live task) | returns the contents; no unlock, no destructor |
|
||||
| `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`.
|
||||
|
||||
`mutex<T>` is always linear and never copyable, whatever `T` is; `mutex.take` is the only way to dismantle it. It requires that no borrow of the mutex is live. A guard is a child of the `ref<mutex<T>>` it was locked through (ending that borrow while the guard lives is `E2102`), and a task waiting in `mutex.lock` holds such a borrow, so no guard and no waiter can exist at `mutex.take`. Afterwards the mutex is dead, by the ordinary rules for a dismantled linear value (as after `own.take`): a further use is `E3001` and a further consumption `E2002`.
|
||||
|
||||
## 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).
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
; mutex.take needs no live borrow of the mutex, so no guard or waiter can exist.
|
||||
; expect: reject E2101
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md
|
||||
module test.sync_take_while_borrowed
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, effects, ownership, sync, tasks]
|
||||
|
||||
fn @f() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%z = const.u64 0
|
||||
%m = mutex.make %z
|
||||
%mr = borrow.ref %m
|
||||
%v = mutex.take %m
|
||||
borrow.end %mr
|
||||
ret %v
|
||||
@@ -0,0 +1,18 @@
|
||||
; After mutex.take the mutex is dead: borrowing it again is a use after consumption (as after own.take).
|
||||
; expect: reject E3001
|
||||
; phase: 3
|
||||
; spec: docs/spec/04-concurrency-and-atomics.md
|
||||
module test.sync_use_after_take
|
||||
air 0
|
||||
lang 0.1
|
||||
features [cancellation, effects, ownership, sync, tasks]
|
||||
|
||||
fn @f() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%z = const.u64 0
|
||||
%m = mutex.make %z
|
||||
%v = mutex.take %m
|
||||
%mr = borrow.ref %m
|
||||
borrow.end %mr
|
||||
ret %v
|
||||
Reference in new issue
Block a user