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:
1 parent
ce9ef03bc0
commit
4242132b2a
70 files changed
+2630
-80
No files matched your search
@@ -559,6 +559,7 @@ fn step(w: *Walker, inst: air.Inst) !void {
|
||||
w.live[inst.result.?] = true;
|
||||
},
|
||||
.mutex_take => |m| {
|
||||
if (try takeLent(w, m)) return;
|
||||
try w.consume(m, .closed);
|
||||
if (w.isResource(inst.result.?)) w.live[inst.result.?] = true;
|
||||
},
|
||||
@@ -599,6 +600,14 @@ fn step(w: *Walker, inst: air.Inst) !void {
|
||||
try lendArgs(w, &.{v});
|
||||
w.live[inst.result.?] = true;
|
||||
},
|
||||
// Atomics (spec 04 §23, §28): a cell is a linear value; operations go
|
||||
// through a shared borrow of it (interior mutability), `take` consumes
|
||||
// it and needs every borrow ended.
|
||||
.atomic_new => w.live[inst.result.?] = true,
|
||||
.atomic_take => |v| if (!try takeLent(w, v)) try w.consume(v, .closed),
|
||||
.atomic_load => |x| try w.useThrough(x.cell, .shared),
|
||||
inline .atomic_store, .atomic_rmw => |x| try w.useThrough(x.cell, .shared),
|
||||
.atomic_cmpxchg => |x| try w.useThrough(x.cell, .shared),
|
||||
// Values of these instructions are not borrows; any borrow operand
|
||||
// here was already rejected by the type stage.
|
||||
else => {},
|
||||
@@ -606,6 +615,19 @@ fn step(w: *Walker, inst: air.Inst) !void {
|
||||
_ = f;
|
||||
}
|
||||
|
||||
/// Taking a mutex or an atomic cell while a borrow of it is lent to a live
|
||||
/// task races with that task: `E4101` rather than `E2101` (spec 04 §28, §40).
|
||||
fn takeLent(w: *Walker, v: ValueId) !bool {
|
||||
for (w.loans.items) |l| if (w.live[l.task] and l.root == v) {
|
||||
try w.report("E4101", "taken while a borrow of it is lent to a live task", v, .{ "task", l.task });
|
||||
// Consumed all the same, so the mistake is not reported again as a leak.
|
||||
w.live[v] = false;
|
||||
w.dead[v] = .closed;
|
||||
return true;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
/// The critical-section rule (spec 04 §41): no operation that may wait or
|
||||
/// spawn while a lock guard is live.
|
||||
fn noWaitUnderLock(w: *Walker, op: []const u8) !void {
|
||||
|
||||
Reference in new issue
Block a user