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

+19 -1
View File
@@ -24,6 +24,9 @@ const FnInfo = struct {
checks: Checks = .{},
proven_bounds: u32 = 0,
unsafe_ops: std.ArrayList(struct { block: []const u8, inst: u32, op: []const u8 }) = .empty,
/// Atomic memory operations (spec 04 §25): `weak` marks the sites that
/// need `atomic.weak`, where interleaving reasoning is not enough.
atomic_ops: std.ArrayList(struct { block: []const u8, inst: u32, op: []const u8, ordering: []const u8, weak: bool }) = .empty,
/// Effects performed directly (intrinsics, allocation, unsafe operations).
direct: std.ArrayList([]const u8) = .empty,
/// Fixed point of `direct` over callees.
@@ -90,6 +93,19 @@ fn analyze(arena: std.mem.Allocator, m: air.Module, f: air.Function) !FnInfo {
if (x.unchecked) {} else if (x.proven) info.proven_bounds += 1 else info.checks.bounds += 1;
},
.slice_sub, .slice_split, .slice_copy => info.checks.bounds += 1,
.atomic_load, .atomic_store, .atomic_rmw, .atomic_cmpxchg, .atomic_fence => {
const op: []const u8, const ord: []const u8, const weak = switch (inst.op) {
.atomic_load => |x| .{ "atomic.load", @tagName(x.ord), x.ord != .seq_cst },
.atomic_store => |x| .{ "atomic.store", @tagName(x.ord), x.ord != .seq_cst },
.atomic_rmw => |x| .{ try std.fmt.allocPrint(arena, "atomic.{s}", .{x.op.text()}), @tagName(x.ord), x.ord != .seq_cst },
.atomic_cmpxchg => |x| .{ "atomic.cmpxchg", try std.fmt.allocPrint(arena, "{s}.{s}", .{ @tagName(x.success), @tagName(x.failure) }), x.success != .seq_cst or x.failure != .seq_cst },
.atomic_fence => |o| .{ "atomic.fence", @tagName(o), false },
else => unreachable,
};
try info.atomic_ops.append(arena, .{ .block = b.name, .inst = @intCast(ii), .op = op, .ordering = ord, .weak = weak });
_ = try addOnce(arena, &info.direct, "atomic");
if (weak) _ = try addOnce(arena, &info.direct, "atomic.weak");
},
else => {},
}
if (unsafe_.unsafeOp(m, inst.op)) |what| {
@@ -181,6 +197,8 @@ pub fn write(arena: std.mem.Allocator, m: air.Module, w: *Writer) !void {
try s.write(.{ .bounds = i.proven_bounds });
try s.objectField("unsafe_operations");
try s.write(i.unsafe_ops.items);
try s.objectField("atomic_operations");
try s.write(i.atomic_ops.items);
try s.endObject();
}
try s.endArray();
@@ -248,6 +266,6 @@ test "audit report" {
var out: Writer.Allocating = .init(arena);
try write(arena, parsed.module.?, &out.writer);
try std.testing.expectEqualStrings(
\\{"report":"audit","air":0,"module":"demo","features":["arrays","capabilities","effects","ownership","resources","unsafe"],"entry":{"function":"main","capabilities":[{"parameter":"out","kind":"io.write"},{"parameter":"fs","kind":"fs.read"}]},"functions":[{"name":"main","trusted":null,"effects_declared":["fs.read","io.write"],"effects_used":[],"effects_unused":["fs.read","io.write"],"calls":["peek"],"intrinsics":[],"allocations":0,"runtime_checks":{"overflow":1,"division":0,"shift":0,"cast":0,"bounds":0,"assert":0,"guard":0},"proven_checks":{"bounds":0},"unsafe_operations":[]},{"name":"peek","trusted":"only reads","effects_declared":[],"effects_used":["unsafe"],"effects_unused":[],"calls":[],"intrinsics":[],"allocations":0,"runtime_checks":{"overflow":0,"division":0,"shift":0,"cast":0,"bounds":0,"assert":0,"guard":0},"proven_checks":{"bounds":0},"unsafe_operations":[{"block":"entry","inst":1,"op":"assume"}]}],"capability_kinds":["fs.read","io.write"],"unsafe":{"trusted_functions":["peek"],"unsafe_functions":[],"operations":1}}
\\{"report":"audit","air":0,"module":"demo","features":["arrays","capabilities","effects","ownership","resources","unsafe"],"entry":{"function":"main","capabilities":[{"parameter":"out","kind":"io.write"},{"parameter":"fs","kind":"fs.read"}]},"functions":[{"name":"main","trusted":null,"effects_declared":["fs.read","io.write"],"effects_used":[],"effects_unused":["fs.read","io.write"],"calls":["peek"],"intrinsics":[],"allocations":0,"runtime_checks":{"overflow":1,"division":0,"shift":0,"cast":0,"bounds":0,"assert":0,"guard":0},"proven_checks":{"bounds":0},"unsafe_operations":[],"atomic_operations":[]},{"name":"peek","trusted":"only reads","effects_declared":[],"effects_used":["unsafe"],"effects_unused":[],"calls":[],"intrinsics":[],"allocations":0,"runtime_checks":{"overflow":0,"division":0,"shift":0,"cast":0,"bounds":0,"assert":0,"guard":0},"proven_checks":{"bounds":0},"unsafe_operations":[{"block":"entry","inst":1,"op":"assume"}],"atomic_operations":[]}],"capability_kinds":["fs.read","io.write"],"unsafe":{"trusted_functions":["peek"],"unsafe_functions":[],"operations":1}}
, out.written());
}