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:
dev committed 2026-10-06 08:05:01 +03:00
1 parent ce9ef03bc0
commit 4242132b2a
70 files changed
+2630 -80

No files matched your search

+30
View File
@@ -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` |