atomics A.0.5: full ordering surface (comptime $o: Ordering)
Migrate Atomic methods from seq_cst-only to the explicit ordering surface now that comptime value params work on generic-struct methods (workers3c4305f/d7a6857/d95ba0a): - atomic.sx: load/store take a comptime $o: Ordering (explicit, Rust-style; no default, matching design 4.6). a.load(.acquire) -> 'load atomic .. acquire'. - call.zig: atomicOrderingFromNode resolves a comptime-bound ordering identifier via comptimeIntNamed (+ atomicOrderingFromTag); documents the sx-Ordering <-> IR-AtomicOrdering declaration-order invariant. The per-op validity guard fires through the method path (a.load(.release) is a compile error). - 1700 migrated to explicit orderings (output unchanged 7/42/43). Suite green (715/0).
This commit is contained in:
@@ -1678,18 +1678,39 @@ pub fn lowerRuntimeDispatchCall(
|
||||
return self.builder.constInt(0, .void);
|
||||
}
|
||||
|
||||
/// Map a bare ordering enum literal (`.seq_cst`) to the IR `AtomicOrdering`.
|
||||
/// Returns null for anything that is not one of the five constant literals —
|
||||
/// the caller turns that into a loud "must be a constant ordering literal"
|
||||
/// diagnostic (never a silent default).
|
||||
fn atomicOrderingFromNode(node: *const Node) ?inst_mod.AtomicOrdering {
|
||||
if (node.data != .enum_literal) return null;
|
||||
const n = node.data.enum_literal.name;
|
||||
if (std.mem.eql(u8, n, "relaxed")) return .relaxed;
|
||||
if (std.mem.eql(u8, n, "acquire")) return .acquire;
|
||||
if (std.mem.eql(u8, n, "release")) return .release;
|
||||
if (std.mem.eql(u8, n, "acq_rel")) return .acq_rel;
|
||||
if (std.mem.eql(u8, n, "seq_cst")) return .seq_cst;
|
||||
/// The five `Ordering` variants by declaration-order tag. INVARIANT: the sx
|
||||
/// `Ordering` enum (library/modules/std/atomic.sx) and the IR `AtomicOrdering`
|
||||
/// enum (inst.zig) declare these variants in the SAME order, so a comptime-bound
|
||||
/// ordering's tag indexes this list. Keep all three in sync.
|
||||
fn atomicOrderingFromTag(tag: i64) ?inst_mod.AtomicOrdering {
|
||||
return switch (tag) {
|
||||
0 => .relaxed,
|
||||
1 => .acquire,
|
||||
2 => .release,
|
||||
3 => .acq_rel,
|
||||
4 => .seq_cst,
|
||||
else => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// Resolve an ordering argument to the IR `AtomicOrdering`. Accepts a bare enum
|
||||
/// literal (`.seq_cst`) OR a comptime-bound identifier (a `$o: Ordering` param
|
||||
/// forwarded into the intrinsic — read its bound variant tag via
|
||||
/// `comptimeIntNamed`). Returns null for a non-constant ordering — the caller
|
||||
/// turns that into a loud diagnostic (never a silent default).
|
||||
fn atomicOrderingFromNode(self: *Lowering, node: *const Node) ?inst_mod.AtomicOrdering {
|
||||
if (node.data == .enum_literal) {
|
||||
const n = node.data.enum_literal.name;
|
||||
if (std.mem.eql(u8, n, "relaxed")) return .relaxed;
|
||||
if (std.mem.eql(u8, n, "acquire")) return .acquire;
|
||||
if (std.mem.eql(u8, n, "release")) return .release;
|
||||
if (std.mem.eql(u8, n, "acq_rel")) return .acq_rel;
|
||||
if (std.mem.eql(u8, n, "seq_cst")) return .seq_cst;
|
||||
return null;
|
||||
}
|
||||
if (node.data == .identifier) {
|
||||
if (self.comptimeIntNamed(node.data.identifier.name)) |tag| return atomicOrderingFromTag(tag);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1729,7 +1750,7 @@ pub fn tryLowerAtomicIntrinsic(self: *Lowering, name: []const u8, c: *const ast.
|
||||
}
|
||||
|
||||
const ord_node = c.args[expected - 1];
|
||||
const ordering = atomicOrderingFromNode(ord_node) orelse {
|
||||
const ordering = atomicOrderingFromNode(self, ord_node) orelse {
|
||||
if (self.diagnostics) |d| d.addFmt(.err, ord_node.span, "atomic ordering must be a constant ordering literal (.relaxed / .acquire / .release / .acq_rel / .seq_cst)", .{});
|
||||
return Ref.none;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user