Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/std/zig/Zir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
_,

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down