Files
aji/tests/litmus/README.md
dev 4242132b2a 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.
2026-10-06 08:05:01 +03:00

56 lines
2.8 KiB
Markdown

# Litmus corpus
The normative litmus corpus of the memory model (spec 04 §20, §20.5; `docs/reference/concurrency-litmus.md`). Each `.lit` file is one test: a small program and its outcome sets.
- `tools/litmus/enumerate.py` is the axiomatic oracle. It computes the allowed outcomes of a program from the axioms of spec 04 §20 alone.
- `tools/litmus/check.py` compares the oracle's result with the stated sets. They MUST be equal.
- `tools/litmus/run_interp.py` translates each test to AIR (`tools/litmus/to_air.py`), explores it exhaustively with `aji explore`, and requires the interpreter's outcomes to equal the allowed set exactly.
- `tools/litmus/differential.py` generates small random programs and requires the interpreter's outcomes to be a subset of the oracle's (soundness on programs outside the corpus).
## File format
Line-based. `#` starts a comment. Blank lines are ignored.
```text
name: MP+rel+acq
init: x=0 y=0 # every location used, with its initial value
T0: # a task; its operations follow, one per line, indented
store x 1 rlx
store y 1 rel
T1:
r0 = load y acq
r1 = load x rlx
observe: T1.r0 T1.r1 # the outcome tuple, in this order
allowed: (a,b) (c,d) … # every allowed outcome: the complete set
forbidden: (e,f) … # outcomes the test exists to exclude (disjoint from allowed; documentation)
```
### Tasks
- `Tn:` declares a task that starts when the program starts.
- `Tn (spawned):` declares a task that starts only when another task executes `spawn Tn`.
All tasks run concurrently.
### Operations
`LOC` and `CH`/`M` are names, `V` is a non-negative integer, `ORD` is `rlx`, `acq`, `rel`, `ar` (acq_rel) or `sc` (seq_cst), and `rN` names a register of the task.
| Operation | Meaning (spec 04) |
|---|---|
| `store LOC V ORD` | atomic store |
| `rN = load LOC ORD` | atomic load |
| `rN = rmw OP LOC V ORD` | atomic read-modify-write, `OP` ∈ `xchg add sub and or xor` (`add`/`sub` modular); `rN` gets the value read |
| `rN = cas LOC EXP NEW SUCC FAIL` | strong compare-exchange; `rN` gets the value read; it writes `NEW` with `SUCC` iff the value read equals `EXP`, otherwise it is a read with `FAIL` |
| `fence ORD` | fence |
| `send CH` / `recv CH` | send a message on channel `CH` / receive one (a `recv` takes exactly one message sent on `CH`; every message is received at most once) |
| `lock M` / `unlock M` | mutex operations (critical sections on `M` do not overlap) |
| `spawn Tn` / `join Tn` | start a spawned task / wait for its completion |
There is no control flow, so every task executes all of its operations. Programs in the corpus are such that every `recv` and `join` can complete.
### Observations
- `Tn.rK` is a register value.
- `final LOC` is the value of the last write to `LOC` in modification order.