authorgravatar for mpoliwczak34@gmail.comMateusz Poliwczak <mpoliwczak34@gmail.com> 2025-11-08 20:27:28+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-09 10:45:14+00:00
logbdbfc7de3fd3a05f338ec8beaa29894547a9df4c
tree7e63dbaf94a83e0117a2763658fda261d60a53c2
parent5358af7ba4cf16bef1734729646b99842e439916

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.

2 files changed, 6 insertions(+), 8 deletions(-)

lib/std/zig/Zir.zig+5-7
......@@ -2142,13 +2142,10 @@ pub const Inst = struct {
21422142 /// ZIR is structured so that the outermost "main" struct of any file
21432143 /// is always at index 0.
21442144 main_struct_inst = 0,
2145 ref_start_index = static_len,
21462145 _,
21472146
2148 pub const static_len = 124;
2149
21502147 pub fn toRef(i: Index) Inst.Ref {
2151 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
2148 return @enumFromInt(Ref.static_len + @intFromEnum(i));
21522149 }
21532150
21542151 pub fn toOptional(i: Index) OptionalIndex {
......@@ -2160,7 +2157,6 @@ pub const Inst = struct {
21602157 /// ZIR is structured so that the outermost "main" struct of any file
21612158 /// is always at index 0.
21622159 main_struct_inst = 0,
2163 ref_start_index = Index.static_len,
21642160 none = std.math.maxInt(u32),
21652161 _,
21662162
......@@ -2309,11 +2305,13 @@ pub const Inst = struct {
23092305
23102306 _,
23112307
2308 pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1;
2309
23122310 pub fn toIndex(inst: Ref) ?Index {
23132311 assert(inst != .none);
23142312 const ref_int = @intFromEnum(inst);
2315 if (ref_int >= @intFromEnum(Index.ref_start_index)) {
2316 return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));
2313 if (ref_int >= static_len) {
2314 return @enumFromInt(ref_int - static_len);
23172315 } else {
23182316 return null;
23192317 }
src/InternPool.zig+1-1
......@@ -5386,7 +5386,7 @@ pub const static_keys: [static_len]Key = .{
53865386/// This is specified with an integer literal and a corresponding comptime
53875387/// assert below to break an unfortunate and arguably incorrect dependency loop
53885388/// when compiling.
5389pub const static_len = Zir.Inst.Index.static_len;
5389pub const static_len = Zir.Inst.Ref.static_len;
53905390
53915391pub const Tag = enum(u8) {
53925392 /// This special tag represents a value which was removed from this pool via