Phase 5: atomics through every layer (RFC 0015)
AIR: linear atomic<T> (AtomicScalar), atomic.new/take/load/store/RMW/ cmpxchg (two results)/fence with explicit orderings; feature atomics published. Verifier: ordering tables (E4201), ordinary access (E4202), effects [atomic] / [atomic, atomic.weak], linearity, take while lent (E4101, also for mutex.take). Interpreter: timestamped message machine (src/interp/weak.zig); views travel through spawn/join, channels, mutexes, close and cancel; seq_cst reads the latest message and programs without weak reads make no extra draw (existing records unchanged). aji explore: exhaustive exploration that branches only before visible operations. Litmus: 20/20 tests give exactly the oracle's sets; differential test (1500 random programs) found no unsound outcome. .aji layer 10, Quick Reference atomics, source coverage 67/67, audit report atomic_operations. AIR bundle +5.9 %, QUICK.md +0.5k.
This commit is contained in:
1 parent
ce9ef03bc0
commit
4242132b2a
70 files changed
+2630
-80
No files matched your search
@@ -50,6 +50,7 @@ Growth never blocks a merge automatically; a complex feature can be justified, b
|
||||
| RFC 0014 islands, frozen graphs, arc (Phase 4) | 19 | 41 | 142 918 | 22 212 | 37 785 (+7.0 %) | — | — |
|
||||
| P4-11 AIR text grammar for Phases 2–4 | 19 | 41 | 149 279 | 22 945 | 39 154 (+3.6 %) | 39 306 | 40 382 |
|
||||
| RFC 0015 spec integration (atomics reserved) | 19 | 41 | 151 929 | 23 311 | 39 904 (+1.9 %) | 40 049 | 41 186 |
|
||||
| Phase 5 atomics implemented (layer 10) | 19 | 48 | 160 428 | 24 607 | 42 275 (+5.9 %) | 42 422 | 43 644 |
|
||||
|
||||
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). Implementation-time spec corrections (mutex linearity, `mutex.take` rules): +0.6 %. Phase 3 total since the Phase 2 baseline: +29.2 %. Next measurement: after the E-S smoke test, or with the next RFC.
|
||||
|
||||
|
||||
@@ -45,6 +45,15 @@ 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
|
||||
|
||||
# Atomics: types, orderings, effects, mixing, instructions (the formal model of §20 is not included)
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 22. DRF-SC guarantee
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 23. Atomic types
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 24. Atomic ordering
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 25. Weak atomics
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 28. Mixing atomic and ordinary access
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 42. Atomics in AIR
|
||||
docs/spec/05-effects-and-capabilities.md :: ## 13. Atomic effects
|
||||
|
||||
# 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
|
||||
|
||||
@@ -110,5 +110,21 @@
|
||||
"o200k_base": 40049,
|
||||
"qwen2.5": 41186
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Phase 5 atomics implemented (layer 10)",
|
||||
"language": "aji",
|
||||
"air": 0,
|
||||
"phase": 3,
|
||||
"files": 19,
|
||||
"sections": 48,
|
||||
"bytes": 160428,
|
||||
"lines": 2413,
|
||||
"words": 24607,
|
||||
"tokens": {
|
||||
"cl100k_base": 42275,
|
||||
"o200k_base": 42422,
|
||||
"qwen2.5": 43644
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -262,6 +262,34 @@ scope s { // every task spawned in s must
|
||||
```
|
||||
|
||||
Inside a `lock` block no operation may wait or spawn, and no function may be called whose effects include `task.wait` or `task.spawn` (`E4304`). One lock at a time, so lock-order deadlocks cannot happen.
|
||||
- **Atomics** (the last resort, after channels and mutexes):
|
||||
|
||||
```aji
|
||||
let count = atomic.new(0u64); // atomic<T>: bool or an integer up to 64 bits; linear
|
||||
{
|
||||
ref c = count; // every operation takes `ref`; lend `c` to tasks
|
||||
let old = atomic.add.wrap(c, 1u64, relaxed); // swap, add.wrap, sub.wrap, and, or, xor return the old value
|
||||
atomic.store(c, 5u64, release);
|
||||
let v = atomic.load(c, acquire);
|
||||
let (prev, exchanged) = atomic.compare_exchange(c, 5u64, 6u64, acq_rel, acquire);
|
||||
atomic.fence(seq_cst);
|
||||
}
|
||||
let total = atomic.take(move count); // needs no live borrow of count
|
||||
```
|
||||
|
||||
- **Every operation names its ordering** (`E4201` otherwise):
|
||||
- load: `relaxed`, `acquire`, `seq_cst`;
|
||||
- store: `relaxed`, `release`, `seq_cst`;
|
||||
- read-modify-write: any of the five;
|
||||
- fence: `acquire`, `release`, `acq_rel`, `seq_cst`;
|
||||
- `compare_exchange` failure ordering, by success ordering: `relaxed` → `relaxed`; `acquire` or `acq_rel` → `relaxed`, `acquire`; `release` → `relaxed`; `seq_cst` → `relaxed`, `acquire`, `seq_cst`.
|
||||
- **Effects:**
|
||||
- `seq_cst` only: `effects [atomic]`, and every run is an interleaving;
|
||||
- any other ordering: `effects [atomic, atomic.weak]`.
|
||||
- **Publication:**
|
||||
- the writer does `atomic.store(data, v, relaxed); atomic.store(flag, true, release);`;
|
||||
- a reader whose `atomic.load(flag, acquire)` is `true` then sees `data`.
|
||||
- `*c` is `E4202`: read a cell with `atomic.load(c, …)`.
|
||||
|
||||
## 9. Common diagnostics → repair
|
||||
|
||||
@@ -283,6 +311,8 @@ scope s { // every task spawned in s must
|
||||
| E4101 | data race with a task | lend disjoint parts (`split_at`, fields) or join first |
|
||||
| E4301 | task not joined at scope end | `task.join(move t)` before the `scope` block ends |
|
||||
| E4304 | wait inside `lock` | move the wait out of the `lock` block |
|
||||
| E4201 | ordering not valid for the operation | use one listed in `allowed` |
|
||||
| E4202 | ordinary read of an atomic cell | `atomic.load(c, ordering)` |
|
||||
| E2111 | graph content not plain data | store only integers, booleans, enums, structs/arrays of them and `iref`s in a graph |
|
||||
| T0010 | `iref` of another graph | use a handle with the graph it came from |
|
||||
| T0001–T0009 | runtime trap | see `kind` and `source_location` |
|
||||
@@ -67,6 +67,10 @@ docs/agent/source-notes.md :: ## Concurrency status
|
||||
docs/spec/15-source-language.md :: ## 7. Tasks, cancellation, channels, select and mutex
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 35. Send and Share in AIR
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 36. The deterministic scheduler
|
||||
docs/spec/15-source-language.md :: ## 12. Atomics
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 22. DRF-SC guarantee
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 24. Atomic ordering
|
||||
docs/spec/04-concurrency-and-atomics.md :: ## 25. Weak atomics
|
||||
|
||||
> language/tooling.md
|
||||
docs/spec/15-source-language.md :: ## 11. Tooling
|
||||
|
||||
@@ -23,7 +23,7 @@ You write `.aji`; you never need to write AIR. Diagnostics point at your source
|
||||
|
||||
## Concurrency status
|
||||
|
||||
The source frontend implements every layer of spec 15, concurrency included: task scopes, spawn and join, channels, `select`, `lock` and mutexes, `shield`, `task.check_cancel` and `task.join_cancel`.
|
||||
The source frontend implements every layer of spec 15, concurrency included: task scopes, spawn and join, channels, `select`, `lock` and mutexes, `shield`, `task.check_cancel`, `task.join_cancel` and atomics (layer 10).
|
||||
|
||||
## The AIR reference
|
||||
|
||||
|
||||
@@ -79,15 +79,16 @@ Phase 4 commit frozen (tag p4-frozen)
|
||||
| P5-1 | done | RFC 0015: scalar atomics and the Aji memory model (supersedes RFC 0003); closes the owner's question list; resolves Q-015; scope of Q-017 | — | `docs/rfcs/0015-…` | Accepted by the owner and integrated into spec 04, 05, 07a, 11, 15 |
|
||||
| P5-1a | done (corpus normative, owner 2026-10-06) | Litmus enumerator `tools/litmus` (an executable oracle derived from spec 04 §20, not the definition) and the normative corpus: the classes MP, SB, LB, release/acquire publication, `seq_cst` ordering (IRIW, SB with `seq_cst`), relaxed counter, CAS success/failure, fence publication, forbidden non-atomic race, atomic/non-atomic mixing, plus the handoffs (mutex, channel, spawn/join). Each test has allowed and forbidden outcome sets | P5-1 | `tools/litmus/`, `reference/concurrency-litmus.md`, `tests/litmus/` | the enumerator's allowed set equals every stated set, disagreements diagnosed (spec 04 §20.5); owner review |
|
||||
| P5-2 | done | Contract tables: `atomic.new`, `atomic.take`, `atomic.load`, `atomic.store`, RMW, `atomic.cmpxchg`, `atomic.fence` | P5-1 | spec 04 §42, spec 07a | all spec 07 §4 fields present, with the ordering tables of spec 04 §24 (integrated with RFC 0015) |
|
||||
| P5-2a | todo | Publish feature `atomics` (depends on `effects`, `ownership`) | P5-3 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
|
||||
| P5-3 | todo | AIR parse/print, types (linear `atomic<T>`, AtomicScalar, not IslandSafe), ordering tables, `E4202` | P5-1a | `src/air/`, `src/verifier/` | `E4201` accept/reject for every operation and every cmpxchg success/failure pair; `E4202`; `E1001`, `E2111`, `E0006` cases |
|
||||
| P5-4 | todo | `atomic` / `atomic.weak` effects (spec 05 §13); weak sites in `aji report` | P5-3 | verifier + report | each non-`seq_cst` ordering without `atomic.weak` is `E3101`; `seq_cst` needs only `atomic`; weak sites listed |
|
||||
| P5-5 | todo | Interpreter: atomic cells with message histories, views, weak reads drawn from the schedule stream; atomic operations are scheduling points | P5-3 | `src/interp/` | sound on the corpus and the differential test; no extra draw without weak accesses; existing records unchanged |
|
||||
| P5-2a | done | Publish feature `atomics` (depends on `effects`, `ownership`) | P5-3 | `reference/air-features.md`, `src/air/features.zig` | feature_not_declared / missing_dependency tests |
|
||||
| P5-3 | done | AIR parse/print, types (linear `atomic<T>`, AtomicScalar, not IslandSafe), ordering tables, `E4202` | P5-1a | `src/air/`, `src/verifier/` | `E4201` accept/reject for every operation and every cmpxchg success/failure pair; `E4202`; `E1001`, `E2111`, `E0006` cases |
|
||||
| P5-4 | done | `atomic` / `atomic.weak` effects (spec 05 §13); weak sites in `aji report` | P5-3 | verifier + report | each non-`seq_cst` ordering without `atomic.weak` is `E3101`; `seq_cst` needs only `atomic`; weak sites listed |
|
||||
| P5-5 | done | Interpreter: atomic cells with message histories, views, weak reads drawn from the schedule stream; atomic operations are scheduling points | P5-3 | `src/interp/` | sound on the corpus and the differential test; no extra draw without weak accesses; existing records unchanged |
|
||||
| P5-6 | todo | Happens-before tracking and dynamic race detector (validates the verifier) | P5-5 | `src/interp/` | any race the verifier missed aborts the test run with a diagnostic |
|
||||
| P5-7 | todo | Exhaustive bounded exploration of schedules and weak-read choices | P5-5 | `src/interp/` | for each litmus test, the outcome set observed equals the oracle's allowed set exactly |
|
||||
| P5-7 | done | Exhaustive bounded exploration of schedules and weak-read choices | P5-5 | `src/interp/` | for each litmus test, the outcome set observed equals the oracle's allowed set exactly |
|
||||
| P5-8 | dropped | Record and replay: moved to Phase 8 (P8-10) by RFC 0015 D13 | — | — | — |
|
||||
| P5-9 | todo | Litmus runner and differential test (random small programs; interpreter outcomes ⊆ oracle outcomes) | P5-7 | `tests/litmus/`, `zig build litmus` | all corpus tests pass with exact equality; differential test in CI |
|
||||
| P5-9a | todo | `.aji` layer 10 (spec 15 §12), Quick Reference subsection after mutexes, source coverage rows, bundle measurement | P5-4 | `src/frontend/`, `docs/agent/` | `.aji` run/reject tests for every row; Quick Reference excerpts checked; growth recorded against RFC 0015's estimate |
|
||||
| P5-9 | done | Litmus runner and differential test (random small programs; interpreter outcomes ⊆ oracle outcomes) | P5-7 | `tests/litmus/`, `zig build litmus` | all corpus tests pass with exact equality; differential test in CI |
|
||||
| P5-9a | done | `.aji` layer 10 (spec 15 §12), Quick Reference subsection after mutexes, source coverage rows, bundle measurement | P5-4 | `src/frontend/`, `docs/agent/` | `.aji` run/reject tests for every row; Quick Reference excerpts checked; growth recorded against RFC 0015's estimate |
|
||||
| P5-9b | todo | Reference program with atomics in AIR (written by an independent author from the spec) and `.aji`, with `equivalent:` | P5-9a | `tests/conformance/` | passes under all stress modes and under `aji explore` with no forbidden outcome |
|
||||
| P5-10 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||||
|
||||
## Regression gate (P5-0)
|
||||
|
||||
@@ -32,7 +32,7 @@ Declaring `features [capabilities, effects, ownership]` grants no authority. It
|
||||
|---|---|---|---|---|
|
||||
| `arc` | published | 4 | `capabilities`, `effects`, `heap`, `islands`, `ownership`, `resources` | `arc<T>`, `arc.*`, `ArcSafe` (spec 03 §24) |
|
||||
| `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 | `effects`, `ownership` | linear `atomic<T>` for AtomicScalar `T`, `atomic.new`, `atomic.take`, `atomic.load`/`store`/RMW/`cmpxchg`/`fence` with explicit orderings, effects `atomic`/`atomic.weak`, `E4201`, `E4202` (spec 04 §20–§30, §42); specified by RFC 0015, published with its implementation (P5-2a) |
|
||||
| `atomics` | published | 5 | `effects`, `ownership` | linear `atomic<T>` for AtomicScalar `T`, `atomic.new`, `atomic.take`, `atomic.load`/`store`/RMW/`cmpxchg`/`fence` with explicit orderings, effects `atomic`/`atomic.weak`, `E4201`, `E4202` (spec 04 §20–§30, §42) |
|
||||
| `borrow_joins` | reserved | — | `ownership` | borrow-typed block parameters (spec 08 §11.6); unscheduled |
|
||||
| `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) |
|
||||
|
||||
@@ -119,7 +119,8 @@ The toolchain should emit an audit artifact containing:
|
||||
"allocations": 0,
|
||||
"runtime_checks": {"overflow": 0, "division": 0, "shift": 0, "cast": 0, "bounds": 0, "assert": 0, "guard": 0},
|
||||
"proven_checks": {"bounds": 0},
|
||||
"unsafe_operations": [{"block": "entry", "inst": 0, "op": "borrow.index.unchecked"}]
|
||||
"unsafe_operations": [{"block": "entry", "inst": 0, "op": "borrow.index.unchecked"}],
|
||||
"atomic_operations": [{"block": "entry", "inst": 3, "op": "atomic.load", "ordering": "acquire", "weak": true}]
|
||||
}
|
||||
],
|
||||
"capability_kinds": ["…"],
|
||||
@@ -134,7 +135,8 @@ Fields:
|
||||
- `calls`, `intrinsics`: distinct callees and intrinsic names in order of first occurrence; together with `effects_*` this is the effect graph.
|
||||
- `runtime_checks`: instructions whose safety condition is checked at runtime and may trap — `overflow` (checked `add`/`sub`/`mul`, and `div`/`rem` for signed `MIN / -1`), `division` (`div`/`rem` by zero), `shift` (`shl`/`shr`), `cast` (`cast.checked`), `bounds` (`borrow.index`, `slice.sub`, `slice.split`, `slice.copy`), `assert`, `guard`.
|
||||
- `proven_checks.bounds`: `borrow.index.proven` instructions, whose check the verifier eliminated.
|
||||
- `atomic_operations` (feature `atomics`, spec 04 §25): every atomic memory operation in order. `ordering` is the operation's ordering, or `success.failure` for `atomic.cmpxchg`. `weak` is true for a non-`seq_cst` access: a site where interleaving reasoning is not enough. `effects_used` contains `atomic` for every such operation and `atomic.weak` for every weak one.
|
||||
- `capability_kinds`: distinct capability kinds appearing in any type of the module, sorted.
|
||||
- All lists of names are in order of first occurrence in the module unless stated otherwise; effect lists are sorted.
|
||||
|
||||
Ownership/borrow proof summaries, weak atomic sites, lock-order findings and contract status are added to this document by the phases that introduce them, as new fields; existing fields keep their meaning.
|
||||
Ownership/borrow proof summaries, lock-order findings and contract status are added to this document by the phases that introduce them, as new fields; existing fields keep their meaning.
|
||||
@@ -435,7 +435,7 @@ Lowering is deterministic: the same source and compiler give byte-identical AIR,
|
||||
|
||||
## 12. Atomics
|
||||
|
||||
Spec 04 §20–§30, §42; layer 10, RFC 0015. This layer is specified now and implemented in Phase 5, together with the publication of feature `atomics`. Until then the frontend rejects it as an unknown construct. The section enters the Source Reference Bundle with the implementation (P5-9a).
|
||||
Spec 04 §20–§30, §42; layer 10, RFC 0015. Implemented with the publication of feature `atomics` (Phase 5).
|
||||
|
||||
| Source | AIR |
|
||||
|---|---|
|
||||
|
||||
Reference in new issue
Block a user