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.
This commit is contained in:
Mateusz Poliwczak 2025-11-08 20:27:28 +01:00 committed by Matthew Lugg
parent 5358af7ba4
commit bdbfc7de3f
2 changed files with 6 additions and 8 deletions

View file

@ -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;
}

View file

@ -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