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 {...@@ -2142,13 +2142,10 @@ pub const Inst = struct {
2142 /// ZIR is structured so that the outermost "main" struct of any file2142 /// ZIR is structured so that the outermost "main" struct of any file
2143 /// is always at index 0.2143 /// is always at index 0.
2144 main_struct_inst = 0,2144 main_struct_inst = 0,
2145 ref_start_index = static_len,
2146 _,2145 _,
21472146
2148 pub const static_len = 124;
2149
2150 pub fn toRef(i: Index) Inst.Ref {2147 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));
2152 }2149 }
21532150
2154 pub fn toOptional(i: Index) OptionalIndex {2151 pub fn toOptional(i: Index) OptionalIndex {
...@@ -2160,7 +2157,6 @@ pub const Inst = struct {...@@ -2160,7 +2157,6 @@ pub const Inst = struct {
2160 /// ZIR is structured so that the outermost "main" struct of any file2157 /// ZIR is structured so that the outermost "main" struct of any file
2161 /// is always at index 0.2158 /// is always at index 0.
2162 main_struct_inst = 0,2159 main_struct_inst = 0,
2163 ref_start_index = Index.static_len,
2164 none = std.math.maxInt(u32),2160 none = std.math.maxInt(u32),
2165 _,2161 _,
21662162
...@@ -2309,11 +2305,13 @@ pub const Inst = struct {...@@ -2309,11 +2305,13 @@ pub const Inst = struct {
23092305
2310 _,2306 _,
23112307
2308 pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1;
2309
2312 pub fn toIndex(inst: Ref) ?Index {2310 pub fn toIndex(inst: Ref) ?Index {
2313 assert(inst != .none);2311 assert(inst != .none);
2314 const ref_int = @intFromEnum(inst);2312 const ref_int = @intFromEnum(inst);
2315 if (ref_int >= @intFromEnum(Index.ref_start_index)) {2313 if (ref_int >= static_len) {
2316 return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));2314 return @enumFromInt(ref_int - static_len);
2317 } else {2315 } else {
2318 return null;2316 return null;
2319 }2317 }
src/InternPool.zig+1-1
...@@ -5386,7 +5386,7 @@ pub const static_keys: [static_len]Key = .{...@@ -5386,7 +5386,7 @@ pub const static_keys: [static_len]Key = .{
5386/// This is specified with an integer literal and a corresponding comptime5386/// This is specified with an integer literal and a corresponding comptime
5387/// assert below to break an unfortunate and arguably incorrect dependency loop5387/// assert below to break an unfortunate and arguably incorrect dependency loop
5388/// when compiling.5388/// when compiling.
5389pub const static_len = Zir.Inst.Index.static_len;5389pub const static_len = Zir.Inst.Ref.static_len;
53905390
5391pub const Tag = enum(u8) {5391pub const Tag = enum(u8) {
5392 /// This special tag represents a value which was removed from this pool via5392 /// This special tag represents a value which was removed from this pool via