rfc: 0015 scalar atomics and the Aji memory model accepted (revision 2) and integrated into the spec

The Aji RC11 profile (RC11 with NO-THIN-AIR; stronger than ISO C11/C++20) as
normative axioms in spec 04 §20; DRF-SC; linear atomic<T> for AtomicScalar
with atomic.new/atomic.take; ref<atomic<T>> operands; ordering tables incl.
cmpxchg failure table and two results; effects [atomic] / [atomic, atomic.weak];
target atomic_widths and E4203; E4202; enumerator as oracle (observed ⊆ allowed,
exact equality on the normative litmus corpus). Feature atomics stays reserved
until P5-2a. Q-015 resolved; record/replay and Q-017 moved to Phase 8.
RFC 0003 superseded. AIR bundle +1.9 %.
This commit is contained in:
dev committed 2026-10-06 00:30:35 +03:00
1 parent 702d69b2c1
commit 2bbbd2135c
24 files changed
+927 -142

No files matched your search

+1 -1
View File
@@ -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 | `ownership` | atomic types, the five orderings, fences, `atomic.*` instructions |
| `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) |
| `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) |
+16 -1
View File
@@ -52,7 +52,8 @@ block = ident [ "(" [ param_list ] ")" ] ":" NL { instruction NL } ;
(* The first block is the entry block and takes no parameters. *)
instruction = [ local { "," local } "=" ] operation ;
(* More than one result only for instructions specified with several results (slice.split). *)
(* More than one result only for instructions specified with several results
(slice.split; atomic.cmpxchg with feature atomics). *)
operation = "const." int_type int_lit
| "const.bool" ( "true" | "false" )
@@ -74,6 +75,7 @@ operation = "const." int_type int_lit
| channel_op
| sync_op
| graph_op
| atomic_op
| terminator ;
(* Several instructions are terminators with named outgoing edges (spec 07a).
@@ -171,6 +173,18 @@ graph_op = "island.create" local "," local ok_err (* ter
| "arc.new" local "," local ok_err (* feature arc; terminator: root value, cap<mem.alloc> *)
| ( "arc.from_frozen" | "arc.clone" | "arc.release" ) local ; (* feature arc *)
(* Feature atomics (spec 04 §20–§30, §42). Each opcode is one dotted word; the
allowed orderings per operation are spec 04 §24 (E4201 otherwise). *)
atomic_op = "atomic.new" local
| "atomic.take" local
| "atomic.load." ordering local
| "atomic.store." ordering local "," local
| "atomic." rmw_op "." ordering local "," local
| "atomic.cmpxchg." ordering "." ordering local "," local "," local (* two results: old, exchanged *)
| "atomic.fence." ordering ;
rmw_op = "xchg" | "add.wrap" | "sub.wrap" | "and" | "or" | "xor" ;
ordering = "relaxed" | "acquire" | "release" | "acq_rel" | "seq_cst" ;
arith_op = ( "add" | "sub" | "mul" ) "." ( "checked" | "wrap" ) "." int_type
| ( "div" | "rem" ) ".checked." int_type
| ( "and" | "or" | "xor" ) "." ( int_type | "bool" )
@@ -204,6 +218,7 @@ type = int_type | "bool" | "void" | "never" | global
| ( "mutex" | "guard" ) "<" type ">" (* feature sync *)
| ( "island" | "frozen" | "iref" ) "<" type ">" (* feature islands *)
| "arc" "<" type ">" (* feature arc *)
| "atomic" "<" type ">" (* feature atomics; bool or an integer type up to 64 bits *)
| builtin_type ;
builtin_type = "cap_error" (* feature capabilities *)
| "alloc_error" (* feature heap *)
+49 -46
View File
@@ -1,59 +1,62 @@
# Concurrency Litmus Tests
These are semantic tests for the interpreter, verifier and native backend. Syntax is illustrative.
Litmus tests for the memory model of spec 04 §20–§30 (RFC 0015). They are semantic tests for the oracle, the interpreter and native backends.
## MP — message publication
The tests do not define the model; spec 04 §20 does. They are its consequences, and the normative conformance corpus for the interpreter (spec 04 §20.5).
Writer:
**Status:** draft corpus. The sets below were derived by hand from the axioms. P5-1a makes the corpus normative: every set is confirmed with the enumerator, the test files go into `tests/litmus/`, and the owner reviews the result. When the enumerator, the interpreter and a stated set disagree, the cause is diagnosed (spec 04 §20.5). A set is never edited to match a tool without a diagnosis.
```aji
atomic.store(ref value, 42, relaxed);
atomic.store(ref ready, true, release);
```
## Rules
Reader:
- Each test states its **allowed** outcome set and its **forbidden** outcome set. A test never states a single expected result.
- **Oracle:** the enumerator's allowed set MUST equal the stated allowed set.
- **Interpreter:**
- under exhaustive exploration, the observed outcomes MUST equal the allowed set, for these tests;
- for any program, under any exploration, no outcome outside the allowed set may appear.
- Unless stated otherwise:
- locations start at 0;
- tasks run in parallel under one scope;
- `rlx`, `acq`, `rel`, `ar`, `sc` abbreviate the five orderings.
```aji
if atomic.load(ref ready, acquire) {
let v = atomic.load(ref value, relaxed);
assert v == 42;
}
```
## Notation
If the reader observes the release publication, observing the prior value store must be consistent with the happens-before relation.
- `‖` separates tasks.
- A tuple lists the reading registers in program order of the tasks, task by task.
- `final x` is the value `atomic.take` reads after all joins.
## SB — store buffering
## Corpus
Initially `x = 0`, `y = 0`, both atomic.
| Test | Shape | Allowed | Forbidden |
|---|---|---|---|
| MP rel/acq | `x=1 rlx; y=1 rel` ‖ `r0=y acq; r1=x rlx` | (0,0) (0,1) (1,1) | (1,0) |
| MP rlx | all `rlx` | all four | — |
| MP fences | `x=1 rlx; fence rel; y=1 rlx` ‖ `r0=y rlx; fence acq; r1=x rlx` | (0,0) (0,1) (1,1) | (1,0) |
| SB rlx | `x=1; r0=y` ‖ `y=1; r1=x`, all `rlx` | all four | — |
| SB rel/acq | stores `rel`, loads `acq` | all four, including (0,0) | — |
| SB sc | all `sc` | (0,1) (1,0) (1,1) | (0,0) |
| SB fences | `rlx` accesses, `fence sc` between store and load on both sides | (0,1) (1,0) (1,1) | (0,0) |
| LB rlx | `r0=x; y=1` ‖ `r1=y; x=1`, all `rlx` | (0,0) (0,1) (1,0) | (1,1), a consequence of NO-THIN-AIR |
| IRIW acq | `x=1 rel` ‖ `y=1 rel` ‖ `r0=x acq; r1=y acq` ‖ `r2=y acq; r3=x acq` | includes (1,0,1,0) | — |
| IRIW sc | all `sc` | every tuple except (1,0,1,0) | (1,0,1,0) |
| CoRR | `x=1 rlx` ‖ `r0=x rlx; r1=x rlx` | (0,0) (0,1) (1,1) | (1,0) |
| CoWW | `x=1 rlx; x=2 rlx`, final `x` | 2 | 1 |
| relaxed counter | 2 tasks × 2 `add.wrap(x,1) rlx`, final `x` | 4 | 2, 3 |
| CAS exclusion | `r0=cas.rlx.rlx(x,0→1)` ‖ `r1=cas.rlx.rlx(x,0→2)` (old values) | (0,1) (2,0) | (0,0) |
| CAS failure acquire | `d=1 rlx; f=1 rel` ‖ `r0=cas.acq.acq(f,0→5); r1=d rlx` | (0,0) (0,1) (1,1) | (1,0) |
| CAS failure relaxed | as above with `cas.acq.rlx` | (0,0) (0,1) (1,0) (1,1) | — |
| release sequence | `d=1 rlx; f=1 rel` ‖ `add.wrap(f,2) rlx` ‖ `r0=f acq; r1=d rlx` | (0,0) (0,1) (1,1) (2,0) (2,1) (3,1) | (1,0) (3,0) |
| channel handoff | `x=1 rlx; send(t)` ‖ `recv; r0=x rlx` | (1) | (0) |
| mutex handoff | `lock; x=1 rlx; unlock` ‖ `lock; r0=x rlx; unlock`, in that lock order | (1) | (0) |
| spawn/join | `x=1 rlx`; spawn ‖ child: `r0=x rlx; x=2 rlx`; after join `r1=x rlx` | (1,2) | (0,·) (·,1) |
Task A:
## Rejected programs
```text
store x=1 relaxed
r1 = load y relaxed
```
These are verifier tests, not outcome tests.
Task B:
```text
store y=1 relaxed
r2 = load x relaxed
```
Outcome `r1=0, r2=0` is permitted under relaxed ordering. The interpreter's weak-memory test mode must not incorrectly forbid it.
## Mutex handoff
Writes performed while holding a mutex before unlock must be visible to a later holder after successful lock acquisition.
## Channel handoff
Writes sequenced before successful `channel.send` are visible after the matching receive. Ownership of the moved message belongs only to the receiver after transfer.
## Spawn/join
Parent operations sequenced before spawn happen-before child start. Child operations happen-before successful join return.
## Invalid ordinary race
Two tasks writing the same ordinary `u64` through overlapping unsynchronized aliases must be rejected before execution.
| Test | Program | Code |
|---|---|---|
| ordinary race | two tasks `store` the same ordinary `u64` through overlapping borrows | `E4101` |
| mixing | ordinary `load` through `ref<atomic<u64>>` | `E4202` |
| invalid ordering | `atomic.load.release` | `E4201` |
| invalid failure ordering | `atomic.cmpxchg.relaxed.acquire` | `E4201` |
| take while lent | `atomic.take` of a cell whose `ref` is lent to a live task | `E4101` |
+2 -2
View File
@@ -4,8 +4,8 @@ Normative registry of effect names for AIR format 0 (spec 05 §9). Effects are f
| Effect | Authority required | Introduced by |
|---|---|---|
| `atomic` | none | Phase 5 |
| `atomic.weak` | none | Phase 5 |
| `atomic` | none | RFC 0015: every atomic memory operation (spec 04 §25) |
| `atomic.weak` | none | RFC 0015: every atomic access whose ordering is not `seq_cst` (spec 04 §25) |
| `clock.read` | `cap<clock.read>` | RFC 0007 |
| `ffi` | none (unsafe boundary, spec 13) | Phase 7 |
| `fs.read` | `cap<fs.read>` | RFC 0007 |
+2
View File
@@ -57,6 +57,8 @@ Draft registry. Codes are stable once released in a tagged compiler version.
| E4002 | concurrency.not_share | Non-Share value concurrently shared |
| E4101 | concurrency.possible_data_race | Conflicting ordinary access not ordered/synchronized |
| E4201 | atomic.invalid_order | Memory ordering invalid for atomic operation |
| E4202 | atomic.ordinary_access | Atomic cell accessed by an ordinary load |
| E4203 | atomic.unsupported_width | Atomic width not implemented lock-free by the target |
| E4301 | task.live_child_escape | Scope exits with live child task |
| E4302 | task.borrow_escape | Child task borrow can outlive parent storage |
| E4303 | io.buffer_in_flight | Buffer accessed while async operation owns/borrows it |
+3 -3
View File
@@ -8,7 +8,7 @@ A `Copy` value may be duplicated without changing ownership semantics.
Typical examples: integers, booleans, small aggregates containing only `Copy` fields.
Not `Copy`: `Own<T>`, `Region`, `Island<T>`, `File`, `Socket`, task/thread handles.
Not `Copy`: `Own<T>`, `Region`, `Island<T>`, `atomic<T>`, `File`, `Socket`, task/thread handles.
## Send
@@ -22,7 +22,7 @@ A `Share` value may be observed concurrently through immutable access.
Deeply immutable values are normally `Share`.
Interior-mutability wrappers must establish their own synchronization semantics to qualify.
Interior-mutability wrappers must establish their own synchronization semantics to qualify. `mutex<T>` does so by locking. `atomic<T>` does so because every access through a shared borrow is an atomic operation with an explicit ordering (spec 04 §23).
## Freeze
@@ -41,7 +41,7 @@ Examples may include thread-local handles, event-loop-local registrations or pla
An `IslandSafe` value may be stored in an island graph (spec 03 §22). Derived structurally:
- **IslandSafe:** integers, `bool`, built-in enums, `iref<U>`, and arrays, structs and enums of `IslandSafe` values.
- **Not IslandSafe:** borrows, owners, regions, graph owners (`island`, `frozen`, `arc`), resources, endpoints, `task`, `scope`, `shield`, `guard`, `mutex`, `cap<K>`.
- **Not IslandSafe:** borrows, owners, regions, graph owners (`island`, `frozen`, `arc`), resources, endpoints, `task`, `scope`, `shield`, `guard`, `mutex`, `atomic<T>`, `cap<K>`.
Because of it, a graph never holds outside authority or a mutable ownership edge, so freeze, conversion and transfer are O(1).