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

@@ -0,0 +1,19 @@
; add.wrap is defined for integers only (spec 04 §24.2).
; expect: reject E1001
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.add_bool
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> bool
effects [atomic]
entry:
%t = const.bool true
%c = atomic.new %t
%r = borrow.ref %c
%x = atomic.add.wrap.seq_cst %r, %t
borrow.end %r
%v = atomic.take %c
ret %v
@@ -0,0 +1,21 @@
; A failed compare-exchange is a read: no release part (spec 04 §24.1).
; expect: reject E4201
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.cmpxchg_failure_release
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%one = const.u64 1
%o, %ok = atomic.cmpxchg.acq_rel.acq_rel %r, %z, %one
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,21 @@
; A compare-exchange failure ordering is never stronger than its success ordering (spec 04 §24.1).
; expect: reject E4201
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.cmpxchg_failure_stronger
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%one = const.u64 1
%o, %ok = atomic.cmpxchg.relaxed.acquire %r, %z, %one
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; There is no relaxed fence (spec 04 §27).
; expect: reject E4201
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.fence_relaxed
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
atomic.fence.relaxed
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; An atomic cell is not IslandSafe: a frozen graph is deeply immutable (spec 02 §6).
; expect: reject E2111
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.island_content
air 0
lang 0.1
features [atomics, capabilities, effects, heap, islands, ownership, resources]
fn @main(%heap: cap<mem.alloc>) -> u64
effects [mem.alloc]
entry:
%z = const.u64 0
%c = atomic.new %z
island.create %c, %heap, ok -> @made, err -> @oom
made(%i: island<atomic<u64>>):
island.destroy %i
ret %z
oom(%e: alloc_error):
trap
+15
View File
@@ -0,0 +1,15 @@
; An atomic cell is linear: it is taken, moved or returned (spec 04 §23).
; expect: reject E3002
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.leak
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects []
entry:
%z = const.u64 0
%c = atomic.new %z
ret %z
@@ -0,0 +1,20 @@
; A load cannot be release (spec 04 §24).
; expect: reject E4201
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.load_release
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%x = atomic.load.release %r
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; Every atomic memory operation needs the effect atomic (spec 04 §25).
; expect: reject E3101
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.missing_atomic_effect
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects []
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%x = atomic.load.seq_cst %r
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; A non-seq_cst access needs atomic.weak besides atomic (spec 04 §25).
; expect: reject E3101
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.missing_weak_effect
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%x = atomic.load.acquire %r
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,21 @@
; Atomic operations take ref<atomic<T>>, never mut (spec 04 §23).
; expect: reject E1001
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.mut_operand
air 0
lang 0.1
features [atomics, effects, ownership]
fn @peek(%c: mut<atomic<u64>>) -> u64
effects [atomic]
entry:
%x = atomic.load.seq_cst %c
%k = const.u64 0
ret %k
fn @main() -> u64
effects []
entry:
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; atomic<T> needs the feature atomics in the header (spec 07 §8.1).
; expect: reject E0006
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.not_declared
air 0
lang 0.1
features [effects, ownership]
fn @peek(%c: ref<atomic<u64>>) -> u64
effects []
entry:
%k = const.u64 0
ret %k
fn @main() -> u64
effects []
entry:
%k = const.u64 0
ret %k
@@ -0,0 +1,20 @@
; An atomic cell is read only by atomic operations (spec 04 §28).
; expect: reject E4202
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.ordinary_load
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%x = load %r
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,21 @@
; A store cannot be acquire (spec 04 §24).
; expect: reject E4201
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.store_acquire
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%one = const.u64 1
atomic.store.acquire %r, %one
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k
@@ -0,0 +1,16 @@
; atomic<T> is linear: as a struct field it needs linear_aggregates (spec 04 §23).
; expect: reject E0006
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.struct_field
air 0
lang 0.1
features [atomics, effects, ownership]
type @S = struct { n: atomic<u64> }
fn @main() -> u64
effects []
entry:
%k = const.u64 0
ret %k
@@ -0,0 +1,19 @@
; atomic.take needs every borrow of the cell ended (spec 04 §28).
; expect: reject E2101
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.take_while_borrowed
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%v = atomic.take %c
%x = atomic.load.seq_cst %r
borrow.end %r
ret %v
@@ -0,0 +1,28 @@
; atomic.take while the cell is lent to a live task is a race (spec 04 §28).
; expect: reject E4101
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.take_while_lent
air 0
lang 0.1
features [atomics, cancellation, effects, ownership, tasks]
fn @reader(%c: ref<atomic<u64>>) -> u64
effects [atomic]
entry:
%x = atomic.load.seq_cst %c
ret %x
fn @main() -> u64
effects [atomic, task.spawn, task.wait]
entry:
%z = const.u64 0
%c = atomic.new %z
%r = borrow.ref %c
%s = task.scope.begin
%t = task.spawn %s, @reader(%r)
%v = atomic.take %c
%x = task.join %t
task.scope.end %s
borrow.end %r
ret %v
@@ -0,0 +1,20 @@
; atomic<T> holds bool or an integer of at most 64 bits (spec 04 §23).
; expect: reject E1001
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.u128_cell
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic]
entry:
%z = const.u128 0
%c = atomic.new %z
%r = borrow.ref %c
%x = atomic.load.seq_cst %r
borrow.end %r
%v = atomic.take %c
%k = const.u64 0
ret %k