P5-1a: independent axiomatic oracle and the litmus corpus (20 tests agree)

tools/litmus/enumerate.py was written by an independent author from spec 04
§20 alone, with the programs blind (outcome sets removed). check.py compares
its allowed sets with tests/litmus/*.lit: 20/20 equal. 21 self-tests derived
from the axioms. Both run in CI. The author's spec findings are Q-024.
This commit is contained in:
dev committed 2026-10-06 00:40:09 +03:00
1 parent cfee89ff19
commit f8d2a99249
28 files changed
+1278 -5

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
# 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.
- From Phase 5 on, the interpreter's exhaustive exploration of each test MUST give exactly the allowed set.
## 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.
+9
View File
@@ -0,0 +1,9 @@
name: CAS-exclusion
init: x=0
T0:
r0 = cas x 0 1 rlx rlx
T1:
r1 = cas x 0 2 rlx rlx
observe: T0.r0 T1.r1
allowed: (0,1) (2,0)
forbidden: (0,0)
+11
View File
@@ -0,0 +1,11 @@
name: CAS-failure-acquire
init: d=0 f=0
T0:
store d 1 rlx
store f 1 rel
T1:
r0 = cas f 0 5 acq acq
r1 = load d rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,1)
forbidden: (1,0)
+10
View File
@@ -0,0 +1,10 @@
name: CAS-failure-relaxed
init: d=0 f=0
T0:
store d 1 rlx
store f 1 rel
T1:
r0 = cas f 0 5 acq rlx
r1 = load d rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,0) (1,1)
+11
View File
@@ -0,0 +1,11 @@
name: channel-handoff
init: x=0
T0:
store x 1 rlx
send c
T1:
recv c
r0 = load x rlx
observe: T1.r0
allowed: (1)
forbidden: (0)
+10
View File
@@ -0,0 +1,10 @@
name: CoRR
init: x=0
T0:
store x 1 rlx
T1:
r0 = load x rlx
r1 = load x rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,1)
forbidden: (1,0)
+11
View File
@@ -0,0 +1,11 @@
name: relaxed-counter
init: x=0
T0:
r0 = rmw add x 1 rlx
r1 = rmw add x 1 rlx
T1:
r2 = rmw add x 1 rlx
r3 = rmw add x 1 rlx
observe: final x
allowed: (4)
forbidden: (2) (3)
+8
View File
@@ -0,0 +1,8 @@
name: CoWW
init: x=0
T0:
store x 1 rlx
store x 2 rlx
observe: final x
allowed: (2)
forbidden: (1)
+14
View File
@@ -0,0 +1,14 @@
name: IRIW+acq
init: x=0 y=0
T0:
store x 1 rel
T1:
store y 1 rel
T2:
r0 = load x acq
r1 = load y acq
T3:
r2 = load y acq
r3 = load x acq
observe: T2.r0 T2.r1 T3.r2 T3.r3
allowed: (0,0,0,0) (0,0,0,1) (0,0,1,0) (0,0,1,1) (0,1,0,0) (0,1,0,1) (0,1,1,0) (0,1,1,1) (1,0,0,0) (1,0,0,1) (1,0,1,0) (1,0,1,1) (1,1,0,0) (1,1,0,1) (1,1,1,0) (1,1,1,1)
+15
View File
@@ -0,0 +1,15 @@
name: IRIW+sc
init: x=0 y=0
T0:
store x 1 sc
T1:
store y 1 sc
T2:
r0 = load x sc
r1 = load y sc
T3:
r2 = load y sc
r3 = load x sc
observe: T2.r0 T2.r1 T3.r2 T3.r3
allowed: (0,0,0,0) (0,0,0,1) (0,0,1,0) (0,0,1,1) (0,1,0,0) (0,1,0,1) (0,1,1,0) (0,1,1,1) (1,0,0,0) (1,0,0,1) (1,0,1,1) (1,1,0,0) (1,1,0,1) (1,1,1,0) (1,1,1,1)
forbidden: (1,0,1,0)
+11
View File
@@ -0,0 +1,11 @@
name: LB+rlx
init: x=0 y=0
T0:
r0 = load x rlx
store y 1 rlx
T1:
r1 = load y rlx
store x 1 rlx
observe: T0.r0 T1.r1
allowed: (0,0) (0,1) (1,0)
forbidden: (1,1)
+13
View File
@@ -0,0 +1,13 @@
name: MP+fences
init: x=0 y=0
T0:
store x 1 rlx
fence rel
store y 1 rlx
T1:
r0 = load y rlx
fence acq
r1 = load x rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,1)
forbidden: (1,0)
+11
View File
@@ -0,0 +1,11 @@
name: MP+rel+acq
init: x=0 y=0
T0:
store x 1 rlx
store y 1 rel
T1:
r0 = load y acq
r1 = load x rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,1)
forbidden: (1,0)
+10
View File
@@ -0,0 +1,10 @@
name: MP+rlx
init: x=0 y=0
T0:
store x 1 rlx
store y 1 rlx
T1:
r0 = load y rlx
r1 = load x rlx
observe: T1.r0 T1.r1
allowed: (0,0) (0,1) (1,0) (1,1)
+15
View File
@@ -0,0 +1,15 @@
name: mutex-handoff
init: x=0 f=0
T0:
lock m
store x 1 rlx
store f 1 rlx
unlock m
T1:
lock m
r0 = load f rlx
r1 = load x rlx
unlock m
observe: T1.r0 T1.r1
allowed: (0,0) (1,1)
forbidden: (1,0) (0,1)
+13
View File
@@ -0,0 +1,13 @@
name: release-sequence
init: d=0 f=0
T0:
store d 1 rlx
store f 1 rel
T1:
r2 = rmw add f 2 rlx
T2:
r0 = load f acq
r1 = load d rlx
observe: T2.r0 T2.r1
allowed: (0,0) (0,1) (1,1) (2,0) (2,1) (3,1)
forbidden: (1,0) (3,0)
+13
View File
@@ -0,0 +1,13 @@
name: SB+fences
init: x=0 y=0
T0:
store x 1 rlx
fence sc
r0 = load y rlx
T1:
store y 1 rlx
fence sc
r1 = load x rlx
observe: T0.r0 T1.r1
allowed: (0,1) (1,0) (1,1)
forbidden: (0,0)
+10
View File
@@ -0,0 +1,10 @@
name: SB+rel+acq
init: x=0 y=0
T0:
store x 1 rel
r0 = load y acq
T1:
store y 1 rel
r1 = load x acq
observe: T0.r0 T1.r1
allowed: (0,0) (0,1) (1,0) (1,1)
+10
View File
@@ -0,0 +1,10 @@
name: SB+rlx+rlx
init: x=0 y=0
T0:
store x 1 rlx
r0 = load y rlx
T1:
store y 1 rlx
r1 = load x rlx
observe: T0.r0 T1.r1
allowed: (0,0) (0,1) (1,0) (1,1)
+11
View File
@@ -0,0 +1,11 @@
name: SB+sc
init: x=0 y=0
T0:
store x 1 sc
r0 = load y sc
T1:
store y 1 sc
r1 = load x sc
observe: T0.r0 T1.r1
allowed: (0,1) (1,0) (1,1)
forbidden: (0,0)
+13
View File
@@ -0,0 +1,13 @@
name: spawn-join
init: x=0
T0:
store x 1 rlx
spawn T1
join T1
r1 = load x rlx
T1 (spawned):
r0 = load x rlx
store x 2 rlx
observe: T1.r0 T0.r1
allowed: (1,2)
forbidden: (0,2) (1,1)