Skip to content

Commit bdbfc7d

Browse files
mateusz834mlugg
authored andcommitted
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.
1 parent 5358af7 commit bdbfc7d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lib/std/zig/Zir.zig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
5389-
pub const static_len = Zir.Inst.Index.static_len;
5389+
pub const static_len = Zir.Inst.Ref.static_len;
53905390

53915391
pub const Tag = enum(u8) {
53925392
/// This special tag represents a value which was removed from this pool via

0 commit comments

Comments
 (0)