commit bdbfc7de3fd3a05f338ec8beaa29894547a9df4c (tree)
parent 5358af7ba4cf16bef1734729646b99842e439916
Author: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Date: Sat, 8 Nov 2025 20:27:28 +0100
std.zig.Zir: remove ref_start_index from enum fields of Index and OptionalIndex
This change removes the ref_start_index from the possible enum values of
Index and OptionalIndex. It is not really a index, but a constant that
tells the offset of static Refs, so lets move it where such constant
belongs i.e. to the Ref.
Diffstat:
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig
@@ -2142,13 +2142,10 @@ pub const Inst = struct {
/// ZIR is structured so that the outermost "main" struct of any file
/// is always at index 0.
main_struct_inst = 0,
- ref_start_index = static_len,
_,
- pub const static_len = 124;
-
pub fn toRef(i: Index) Inst.Ref {
- return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
+ return @enumFromInt(Ref.static_len + @intFromEnum(i));
}
pub fn toOptional(i: Index) OptionalIndex {
@@ -2160,7 +2157,6 @@ pub const Inst = struct {
/// ZIR is structured so that the outermost "main" struct of any file
/// is always at index 0.
main_struct_inst = 0,
- ref_start_index = Index.static_len,
none = std.math.maxInt(u32),
_,
@@ -2309,11 +2305,13 @@ pub const Inst = struct {
_,
+ pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1;
+
pub fn toIndex(inst: Ref) ?Index {
assert(inst != .none);
const ref_int = @intFromEnum(inst);
- if (ref_int >= @intFromEnum(Index.ref_start_index)) {
- return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));
+ if (ref_int >= static_len) {
+ return @enumFromInt(ref_int - static_len);
} else {
return null;
}
diff --git a/src/InternPool.zig b/src/InternPool.zig
@@ -5386,7 +5386,7 @@ pub const static_keys: [static_len]Key = .{
/// This is specified with an integer literal and a corresponding comptime
/// assert below to break an unfortunate and arguably incorrect dependency loop
/// when compiling.
-pub const static_len = Zir.Inst.Index.static_len;
+pub const static_len = Zir.Inst.Ref.static_len;
pub const Tag = enum(u8) {
/// This special tag represents a value which was removed from this pool via