authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-28 13:14:40-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-28 13:14:40-04:00
loge69fd4d696b7e24c66a50adb3bf3fe011ee1a626
treec0fef2d53bcd71009e6dc4f90a9aeb0f35386ca7
parent256ab68a97cb6a84278c78d93917ab5e8ae53209
parent62f45b802cab1337590d5c3397fca7b84d3a819b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17762 from ziglang/zir-index-type-safety

make Zir.Inst.Index typed

8 files changed, 1033 insertions(+), 941 deletions(-)

lib/std/mem.zig+22-10
......@@ -3527,21 +3527,33 @@ test "max" {
35273527/// Finds the smallest and largest number in a slice. O(n).
35283528/// Returns an anonymous struct with the fields `min` and `max`.
35293529/// `slice` must not be empty.
3530pub fn minMax(comptime T: type, slice: []const T) struct { min: T, max: T } {
3530pub fn minMax(comptime T: type, slice: []const T) struct { T, T } {
35313531 assert(slice.len > 0);
3532 var minVal = slice[0];
3533 var maxVal = slice[0];
3532 var running_minimum = slice[0];
3533 var running_maximum = slice[0];
35343534 for (slice[1..]) |item| {
3535 minVal = @min(minVal, item);
3536 maxVal = @max(maxVal, item);
3535 running_minimum = @min(running_minimum, item);
3536 running_maximum = @max(running_maximum, item);
35373537 }
3538 return .{ .min = minVal, .max = maxVal };
3538 return .{ running_minimum, running_maximum };
35393539}
35403540
3541test "minMax" {
3542 try testing.expectEqual(minMax(u8, "abcdefg"), .{ .min = 'a', .max = 'g' });
3543 try testing.expectEqual(minMax(u8, "bcdefga"), .{ .min = 'a', .max = 'g' });
3544 try testing.expectEqual(minMax(u8, "a"), .{ .min = 'a', .max = 'a' });
3541test minMax {
3542 {
3543 const actual_min, const actual_max = minMax(u8, "abcdefg");
3544 try testing.expectEqual(@as(u8, 'a'), actual_min);
3545 try testing.expectEqual(@as(u8, 'g'), actual_max);
3546 }
3547 {
3548 const actual_min, const actual_max = minMax(u8, "bcdefga");
3549 try testing.expectEqual(@as(u8, 'a'), actual_min);
3550 try testing.expectEqual(@as(u8, 'g'), actual_max);
3551 }
3552 {
3553 const actual_min, const actual_max = minMax(u8, "a");
3554 try testing.expectEqual(@as(u8, 'a'), actual_min);
3555 try testing.expectEqual(@as(u8, 'a'), actual_max);
3556 }
35453557}
35463558
35473559/// Returns the index of the smallest number in a slice. O(n).
src/AstGen.zig+182-175
......@@ -13,8 +13,6 @@ const StringIndexContext = std.hash_map.StringIndexContext;
1313const isPrimitive = std.zig.primitives.isPrimitive;
1414
1515const Zir = @import("Zir.zig");
16const refToIndex = Zir.refToIndex;
17const indexToRef = Zir.indexToRef;
1816const trace = @import("tracy.zig").trace;
1917const BuiltinFn = @import("BuiltinFn.zig");
2018const AstRlAnnotate = @import("AstRlAnnotate.zig");
......@@ -86,13 +84,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
8684 inline for (fields) |field| {
8785 astgen.extra.items[i] = switch (field.type) {
8886 u32 => @field(extra, field.name),
89 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),
87
88 Zir.Inst.Ref,
89 Zir.Inst.Index,
90 => @intFromEnum(@field(extra, field.name)),
91
9092 i32,
9193 Zir.Inst.Call.Flags,
9294 Zir.Inst.BuiltinCall.Flags,
9395 Zir.Inst.SwitchBlock.Bits,
9496 Zir.Inst.FuncFancy.Bits,
9597 => @bitCast(@field(extra, field.name)),
98
9699 else => @compileError("bad field type"),
97100 };
98101 i += 1;
......@@ -166,7 +169,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
166169 .Auto,
167170 0,
168171 )) |struct_decl_ref| {
169 assert(refToIndex(struct_decl_ref).? == 0);
172 assert(struct_decl_ref.toIndex().? == .main_struct_inst);
170173 } else |err| switch (err) {
171174 error.OutOfMemory => return error.OutOfMemory,
172175 error.AnalysisFail => {}, // Handled via compile_errors below.
......@@ -1200,7 +1203,7 @@ fn suspendExpr(
12001203 }
12011204 try suspend_scope.setBlockBody(suspend_inst);
12021205
1203 return indexToRef(suspend_inst);
1206 return suspend_inst.toRef();
12041207}
12051208
12061209fn awaitExpr(
......@@ -1316,7 +1319,7 @@ fn fnProtoExpr(
13161319 var param_gz = block_scope.makeSubBlock(scope);
13171320 defer param_gz.unstack();
13181321 const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node);
1319 const param_inst_expected: u32 = @intCast(astgen.instructions.len + 1);
1322 const param_inst_expected: Zir.Inst.Index = @enumFromInt(astgen.instructions.len + 1);
13201323 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
13211324 const main_tokens = tree.nodes.items(.main_token);
13221325 const name_token = param.name_token orelse main_tokens[param_type_node];
......@@ -1386,7 +1389,7 @@ fn fnProtoExpr(
13861389 try block_scope.setBlockBody(block_inst);
13871390 try gz.instructions.append(astgen.gpa, block_inst);
13881391
1389 return rvalue(gz, ri, indexToRef(block_inst), fn_proto.ast.proto_node);
1392 return rvalue(gz, ri, block_inst.toRef(), fn_proto.ast.proto_node);
13901393}
13911394
13921395fn arrayInitExpr(
......@@ -1625,7 +1628,7 @@ fn arrayInitExprPtr(
16251628 .ptr = array_ptr_inst,
16261629 .index = @intCast(i),
16271630 });
1628 astgen.extra.items[extra_index] = refToIndex(elem_ptr_inst).?;
1631 astgen.extra.items[extra_index] = @intFromEnum(elem_ptr_inst.toIndex().?);
16291632 extra_index += 1;
16301633 _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = elem_ptr_inst } } }, elem_init);
16311634 }
......@@ -1825,7 +1828,7 @@ fn structInitExprTyped(
18251828 .name_start = str_index,
18261829 });
18271830 setExtra(astgen, extra_index, Zir.Inst.StructInit.Item{
1828 .field_type = refToIndex(field_ty_inst).?,
1831 .field_type = field_ty_inst.toIndex().?,
18291832 .init = try expr(gz, scope, .{ .rl = .{ .coerced_ty = field_ty_inst } }, field_init),
18301833 });
18311834 extra_index += field_size;
......@@ -1860,7 +1863,7 @@ fn structInitExprPtr(
18601863 .lhs = struct_ptr_inst,
18611864 .field_name_start = str_index,
18621865 });
1863 astgen.extra.items[extra_index] = refToIndex(field_ptr).?;
1866 astgen.extra.items[extra_index] = @intFromEnum(field_ptr.toIndex().?);
18641867 extra_index += 1;
18651868 _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = field_ptr } } }, field_init);
18661869 }
......@@ -1962,7 +1965,7 @@ fn comptimeExpr(
19621965 try block_scope.setBlockBody(block_inst);
19631966 try gz.instructions.append(gz.astgen.gpa, block_inst);
19641967
1965 return rvalue(gz, ri, indexToRef(block_inst), node);
1968 return rvalue(gz, ri, block_inst.toRef(), node);
19661969}
19671970
19681971/// This one is for an actual `comptime` syntax, and will emit a compile error if
......@@ -2048,8 +2051,8 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
20482051 break :blk label.block_inst;
20492052 }
20502053 }
2051 } else if (block_gz.break_block != 0) {
2052 break :blk block_gz.break_block;
2054 } else if (block_gz.break_block.unwrap()) |i| {
2055 break :blk i;
20532056 }
20542057 // If not the target, start over with the parent
20552058 scope = block_gz.parent;
......@@ -2135,11 +2138,10 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
21352138 ),
21362139 });
21372140 }
2138 const continue_block = gen_zir.continue_block;
2139 if (continue_block == 0) {
2141 const continue_block = gen_zir.continue_block.unwrap() orelse {
21402142 scope = gen_zir.parent;
21412143 continue;
2142 }
2144 };
21432145 if (break_label != 0) blk: {
21442146 if (gen_zir.label) |*label| {
21452147 if (try astgen.tokenIdentEql(label.token, break_label)) {
......@@ -2157,7 +2159,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
21572159 else
21582160 .@"break";
21592161 if (break_tag == .break_inline) {
2160 _ = try parent_gz.addUnNode(.check_comptime_control_flow, Zir.indexToRef(continue_block), node);
2162 _ = try parent_gz.addUnNode(.check_comptime_control_flow, continue_block.toRef(), node);
21612163 }
21622164
21632165 // As our last action before the continue, "pop" the error trace if needed
......@@ -2333,9 +2335,9 @@ fn labeledBlockExpr(
23332335
23342336 try block_scope.setBlockBody(block_inst);
23352337 if (need_result_rvalue) {
2336 return rvalue(gz, ri, indexToRef(block_inst), block_node);
2338 return rvalue(gz, ri, block_inst.toRef(), block_node);
23372339 } else {
2338 return indexToRef(block_inst);
2340 return block_inst.toRef();
23392341 }
23402342}
23412343
......@@ -2438,15 +2440,15 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
24382440
24392441fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: Ast.Node.Index) InnerError!Ast.Node.Index {
24402442 var noreturn_src_node: Ast.Node.Index = 0;
2441 const elide_check = if (refToIndex(maybe_unused_result)) |inst| b: {
2443 const elide_check = if (maybe_unused_result.toIndex()) |inst| b: {
24422444 // Note that this array becomes invalid after appending more items to it
24432445 // in the above while loop.
24442446 const zir_tags = gz.astgen.instructions.items(.tag);
2445 switch (zir_tags[inst]) {
2447 switch (zir_tags[@intFromEnum(inst)]) {
24462448 // For some instructions, modify the zir data
24472449 // so we can avoid a separate ensure_result_used instruction.
24482450 .call, .field_call => {
2449 const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2451 const break_extra = gz.astgen.instructions.items(.data)[@intFromEnum(inst)].pl_node.payload_index;
24502452 comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") ==
24512453 std.meta.fieldIndex(Zir.Inst.FieldCall, "flags"));
24522454 const flags: *Zir.Inst.Call.Flags = @ptrCast(&gz.astgen.extra.items[
......@@ -2456,7 +2458,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
24562458 break :b true;
24572459 },
24582460 .builtin_call => {
2459 const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2461 const break_extra = gz.astgen.instructions.items(.data)[@intFromEnum(inst)].pl_node.payload_index;
24602462 const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[
24612463 break_extra + std.meta.fieldIndex(Zir.Inst.BuiltinCall, "flags").?
24622464 ]);
......@@ -2670,7 +2672,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26702672 .array_init_elem_ptr,
26712673 => break :b false,
26722674
2673 .extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) {
2675 .extended => switch (gz.astgen.instructions.items(.data)[@intFromEnum(inst)].extended.opcode) {
26742676 .breakpoint,
26752677 .fence,
26762678 .set_float_mode,
......@@ -2783,7 +2785,7 @@ fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct {
27832785
27842786 have_err = true;
27852787
2786 const have_err_payload = defer_scope.remapped_err_code != 0;
2788 const have_err_payload = defer_scope.remapped_err_code != .none;
27872789 need_err_code = need_err_code or have_err_payload;
27882790 },
27892791 .namespace, .enum_namespace => unreachable,
......@@ -2831,18 +2833,16 @@ fn genDefers(
28312833 try gz.addDefer(defer_scope.index, defer_scope.len);
28322834 },
28332835 .both => |err_code| {
2834 if (defer_scope.remapped_err_code == 0) {
2835 try gz.addDefer(defer_scope.index, defer_scope.len);
2836 } else {
2836 if (defer_scope.remapped_err_code.unwrap()) |remapped_err_code| {
28372837 try gz.instructions.ensureUnusedCapacity(gpa, 1);
28382838 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
28392839
28402840 const payload_index = try gz.astgen.addExtra(Zir.Inst.DeferErrCode{
2841 .remapped_err_code = defer_scope.remapped_err_code,
2841 .remapped_err_code = remapped_err_code,
28422842 .index = defer_scope.index,
28432843 .len = defer_scope.len,
28442844 });
2845 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
2845 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
28462846 gz.astgen.instructions.appendAssumeCapacity(.{
28472847 .tag = .defer_err_code,
28482848 .data = .{ .defer_err_code = .{
......@@ -2851,6 +2851,8 @@ fn genDefers(
28512851 } },
28522852 });
28532853 gz.instructions.appendAssumeCapacity(new_index);
2854 } else {
2855 try gz.addDefer(defer_scope.index, defer_scope.len);
28542856 }
28552857 },
28562858 .normal_only => continue,
......@@ -2916,12 +2918,13 @@ fn deferStmt(
29162918
29172919 const payload_token = node_datas[node].lhs;
29182920 var local_val_scope: Scope.LocalVal = undefined;
2919 var remapped_err_code: Zir.Inst.Index = 0;
2921 var opt_remapped_err_code: Zir.Inst.OptionalIndex = .none;
29202922 const have_err_code = scope_tag == .defer_error and payload_token != 0;
29212923 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {
29222924 try gz.addDbgBlockBegin();
29232925 const ident_name = try gz.astgen.identAsString(payload_token);
2924 remapped_err_code = @intCast(gz.astgen.instructions.len);
2926 const remapped_err_code: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
2927 opt_remapped_err_code = remapped_err_code.toOptional();
29252928 try gz.astgen.instructions.append(gz.astgen.gpa, .{
29262929 .tag = .extended,
29272930 .data = .{ .extended = .{
......@@ -2930,7 +2933,7 @@ fn deferStmt(
29302933 .operand = undefined,
29312934 } },
29322935 });
2933 const remapped_err_code_ref = Zir.indexToRef(remapped_err_code);
2936 const remapped_err_code_ref = remapped_err_code.toRef();
29342937 local_val_scope = .{
29352938 .parent = &defer_gen.base,
29362939 .gen_zir = gz,
......@@ -2945,13 +2948,13 @@ fn deferStmt(
29452948 _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node);
29462949 try checkUsed(gz, scope, sub_scope);
29472950 if (have_err_code) try gz.addDbgBlockEnd();
2948 _ = try defer_gen.addBreak(.break_inline, 0, .void_value);
2951 _ = try defer_gen.addBreak(.break_inline, @enumFromInt(0), .void_value);
29492952
29502953 // We must handle ref_table for remapped_err_code manually.
29512954 const body = defer_gen.instructionsSlice();
29522955 const body_len = blk: {
29532956 var refs: u32 = 0;
2954 if (have_err_code) {
2957 if (opt_remapped_err_code.unwrap()) |remapped_err_code| {
29552958 var cur_inst = remapped_err_code;
29562959 while (gz.astgen.ref_table.get(cur_inst)) |ref_inst| {
29572960 refs += 1;
......@@ -2963,7 +2966,7 @@ fn deferStmt(
29632966
29642967 const index: u32 = @intCast(gz.astgen.extra.items.len);
29652968 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);
2966 if (have_err_code) {
2969 if (opt_remapped_err_code.unwrap()) |remapped_err_code| {
29672970 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {
29682971 gz.astgen.appendPossiblyRefdBodyInst(&gz.astgen.extra, kv.value);
29692972 }
......@@ -2977,7 +2980,7 @@ fn deferStmt(
29772980 .parent = scope,
29782981 .index = index,
29792982 .len = body_len,
2980 .remapped_err_code = remapped_err_code,
2983 .remapped_err_code = opt_remapped_err_code,
29812984 };
29822985 return &defer_scope.base;
29832986}
......@@ -3226,9 +3229,9 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void {
32263229 if (gz.instructions.items.len > 0) {
32273230 const last = gz.instructions.items[gz.instructions.items.len - 1];
32283231 const zir_tags = astgen.instructions.items(.tag);
3229 if (zir_tags[last] == .dbg_stmt) {
3232 if (zir_tags[@intFromEnum(last)] == .dbg_stmt) {
32303233 const zir_datas = astgen.instructions.items(.data);
3231 zir_datas[last].dbg_stmt = .{
3234 zir_datas[@intFromEnum(last)].dbg_stmt = .{
32323235 .line = line,
32333236 .column = column,
32343237 };
......@@ -3721,8 +3724,8 @@ fn ptrType(
37213724 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));
37223725 }
37233726
3724 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
3725 const result = indexToRef(new_index);
3727 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
3728 const result = new_index.toRef();
37263729 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{
37273730 .ptr_type = .{
37283731 .flags = .{
......@@ -4049,7 +4052,7 @@ fn fnDecl(
40494052 var param_gz = decl_gz.makeSubBlock(scope);
40504053 defer param_gz.unstack();
40514054 const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node);
4052 const param_inst_expected: u32 = @intCast(astgen.instructions.len + 1);
4055 const param_inst_expected: Zir.Inst.Index = @enumFromInt(astgen.instructions.len + 1);
40534056 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
40544057
40554058 const main_tokens = tree.nodes.items(.main_token);
......@@ -4057,7 +4060,7 @@ fn fnDecl(
40574060 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;
40584061 const param_inst = try decl_gz.addParam(&param_gz, tag, name_token, param_name, param.first_doc_comment);
40594062 assert(param_inst_expected == param_inst);
4060 break :param indexToRef(param_inst);
4063 break :param param_inst.toRef();
40614064 };
40624065
40634066 if (param_name == 0 or is_extern) continue;
......@@ -4102,7 +4105,7 @@ fn fnDecl(
41024105 // In this case we will send a len=0 body which can be encoded more efficiently.
41034106 break :inst inst;
41044107 }
4105 _ = try align_gz.addBreak(.break_inline, 0, inst);
4108 _ = try align_gz.addBreak(.break_inline, @enumFromInt(0), inst);
41064109 break :inst inst;
41074110 };
41084111
......@@ -4114,7 +4117,7 @@ fn fnDecl(
41144117 // In this case we will send a len=0 body which can be encoded more efficiently.
41154118 break :inst inst;
41164119 }
4117 _ = try addrspace_gz.addBreak(.break_inline, 0, inst);
4120 _ = try addrspace_gz.addBreak(.break_inline, @enumFromInt(0), inst);
41184121 break :inst inst;
41194122 };
41204123
......@@ -4126,7 +4129,7 @@ fn fnDecl(
41264129 // In this case we will send a len=0 body which can be encoded more efficiently.
41274130 break :inst inst;
41284131 }
4129 _ = try section_gz.addBreak(.break_inline, 0, inst);
4132 _ = try section_gz.addBreak(.break_inline, @enumFromInt(0), inst);
41304133 break :inst inst;
41314134 };
41324135
......@@ -4151,7 +4154,7 @@ fn fnDecl(
41514154 // In this case we will send a len=0 body which can be encoded more efficiently.
41524155 break :blk inst;
41534156 }
4154 _ = try cc_gz.addBreak(.break_inline, 0, inst);
4157 _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst);
41554158 break :blk inst;
41564159 } else if (is_extern) {
41574160 // note: https://github.com/ziglang/zig/issues/5269
......@@ -4171,7 +4174,7 @@ fn fnDecl(
41714174 // In this case we will send a len=0 body which can be encoded more efficiently.
41724175 break :inst inst;
41734176 }
4174 _ = try ret_gz.addBreak(.break_inline, 0, inst);
4177 _ = try ret_gz.addBreak(.break_inline, @enumFromInt(0), inst);
41754178 break :inst inst;
41764179 };
41774180
......@@ -4271,7 +4274,7 @@ fn fnDecl(
42714274 wip_members.appendToDecl(line_delta);
42724275 }
42734276 wip_members.appendToDecl(fn_name_str_index);
4274 wip_members.appendToDecl(block_inst);
4277 wip_members.appendToDecl(@intFromEnum(block_inst));
42754278 wip_members.appendToDecl(doc_comment_index);
42764279}
42774280
......@@ -4421,7 +4424,7 @@ fn globalVarDecl(
44214424 wip_members.appendToDecl(line_delta);
44224425 }
44234426 wip_members.appendToDecl(name_str_index);
4424 wip_members.appendToDecl(block_inst);
4427 wip_members.appendToDecl(@intFromEnum(block_inst));
44254428 wip_members.appendToDecl(doc_comment_index); // doc_comment wip
44264429 if (align_inst != .none) {
44274430 wip_members.appendToDecl(@intFromEnum(align_inst));
......@@ -4475,7 +4478,7 @@ fn comptimeDecl(
44754478 wip_members.appendToDecl(line_delta);
44764479 }
44774480 wip_members.appendToDecl(0);
4478 wip_members.appendToDecl(block_inst);
4481 wip_members.appendToDecl(@intFromEnum(block_inst));
44794482 wip_members.appendToDecl(0); // no doc comments on comptime decls
44804483}
44814484
......@@ -4526,7 +4529,7 @@ fn usingnamespaceDecl(
45264529 wip_members.appendToDecl(line_delta);
45274530 }
45284531 wip_members.appendToDecl(0);
4529 wip_members.appendToDecl(block_inst);
4532 wip_members.appendToDecl(@intFromEnum(block_inst));
45304533 wip_members.appendToDecl(0); // no doc comments on usingnamespace decls
45314534}
45324535
......@@ -4715,7 +4718,7 @@ fn testDecl(
47154718 wip_members.appendToDecl(2) // 2 here means that it is a decltest, look at doc comment for name
47164719 else
47174720 wip_members.appendToDecl(test_name);
4718 wip_members.appendToDecl(block_inst);
4721 wip_members.appendToDecl(@intFromEnum(block_inst));
47194722 if (is_decltest)
47204723 wip_members.appendToDecl(test_name) // the doc comment on a decltest represents it's name
47214724 else
......@@ -4747,7 +4750,7 @@ fn structDeclInner(
47474750 .any_default_inits = false,
47484751 .any_aligned_fields = false,
47494752 });
4750 return indexToRef(decl_inst);
4753 return decl_inst.toRef();
47514754 }
47524755
47534756 const astgen = gz.astgen;
......@@ -4993,7 +4996,7 @@ fn structDeclInner(
49934996
49944997 block_scope.unstack();
49954998 try gz.addNamespaceCaptures(&namespace);
4996 return indexToRef(decl_inst);
4999 return decl_inst.toRef();
49975000}
49985001
49995002fn unionDeclInner(
......@@ -5154,7 +5157,7 @@ fn unionDeclInner(
51545157
51555158 block_scope.unstack();
51565159 try gz.addNamespaceCaptures(&namespace);
5157 return indexToRef(decl_inst);
5160 return decl_inst.toRef();
51585161}
51595162
51605163fn containerDecl(
......@@ -5404,7 +5407,7 @@ fn containerDecl(
54045407
54055408 block_scope.unstack();
54065409 try gz.addNamespaceCaptures(&namespace);
5407 return rvalue(gz, ri, indexToRef(decl_inst), node);
5410 return rvalue(gz, ri, decl_inst.toRef(), node);
54085411 },
54095412 .keyword_opaque => {
54105413 assert(container_decl.ast.arg == 0);
......@@ -5455,7 +5458,7 @@ fn containerDecl(
54555458
54565459 block_scope.unstack();
54575460 try gz.addNamespaceCaptures(&namespace);
5458 return rvalue(gz, ri, indexToRef(decl_inst), node);
5461 return rvalue(gz, ri, decl_inst.toRef(), node);
54595462 },
54605463 else => unreachable,
54615464 }
......@@ -5642,7 +5645,7 @@ fn tryExpr(
56425645 _ = try else_scope.addUnNode(.ret_node, err_code, node);
56435646
56445647 try else_scope.setTryBody(try_inst, operand);
5645 const result = indexToRef(try_inst);
5648 const result = try_inst.toRef();
56465649 switch (ri.rl) {
56475650 .ref, .ref_coerced_ty => return result,
56485651 else => return rvalue(parent_gz, ri, result, node),
......@@ -5755,9 +5758,9 @@ fn orelseCatchExpr(
57555758 try setCondBrPayload(condbr, cond, &then_scope, &else_scope);
57565759
57575760 if (need_result_rvalue) {
5758 return rvalue(parent_gz, ri, indexToRef(block), node);
5761 return rvalue(parent_gz, ri, block.toRef(), node);
57595762 } else {
5760 return indexToRef(block);
5763 return block.toRef();
57615764 }
57625765}
57635766
......@@ -5916,7 +5919,7 @@ fn boolBinOp(
59165919 }
59175920 try rhs_scope.setBoolBrBody(bool_br);
59185921
5919 const block_ref = indexToRef(bool_br);
5922 const block_ref = bool_br.toRef();
59205923 return rvalue(gz, ri, block_ref, node);
59215924}
59225925
......@@ -6116,9 +6119,9 @@ fn ifExpr(
61166119 try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope);
61176120
61186121 if (need_result_rvalue) {
6119 return rvalue(parent_gz, ri, indexToRef(block), node);
6122 return rvalue(parent_gz, ri, block.toRef(), node);
61206123 } else {
6121 return indexToRef(block);
6124 return block.toRef();
61226125 }
61236126}
61246127
......@@ -6142,7 +6145,7 @@ fn setCondBrPayload(
61426145 );
61436146
61446147 const zir_datas = astgen.instructions.items(.data);
6145 zir_datas[condbr].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{
6148 zir_datas[@intFromEnum(condbr)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{
61466149 .condition = cond,
61476150 .then_body_len = then_body_len,
61486151 .else_body_len = else_body_len,
......@@ -6245,7 +6248,7 @@ fn whileExpr(
62456248
62466249 var dbg_var_name: ?u32 = null;
62476250 var dbg_var_inst: Zir.Inst.Ref = undefined;
6248 var payload_inst: Zir.Inst.Index = 0;
6251 var opt_payload_inst: Zir.Inst.OptionalIndex = .none;
62496252 var payload_val_scope: Scope.LocalVal = undefined;
62506253 const then_sub_scope = s: {
62516254 if (while_full.error_token != null) {
......@@ -6255,7 +6258,8 @@ fn whileExpr(
62556258 else
62566259 .err_union_payload_unsafe;
62576260 // will add this instruction to then_scope.instructions below
6258 payload_inst = try then_scope.makeUnNode(tag, cond.inst, while_full.ast.cond_expr);
6261 const payload_inst = try then_scope.makeUnNode(tag, cond.inst, while_full.ast.cond_expr);
6262 opt_payload_inst = payload_inst.toOptional();
62596263 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
62606264 const ident_bytes = tree.tokenSlice(ident_token);
62616265 if (mem.eql(u8, "_", ident_bytes))
......@@ -6267,12 +6271,12 @@ fn whileExpr(
62676271 .parent = &then_scope.base,
62686272 .gen_zir = &then_scope,
62696273 .name = ident_name,
6270 .inst = indexToRef(payload_inst),
6274 .inst = payload_inst.toRef(),
62716275 .token_src = payload_token,
62726276 .id_cat = .capture,
62736277 };
62746278 dbg_var_name = ident_name;
6275 dbg_var_inst = indexToRef(payload_inst);
6279 dbg_var_inst = payload_inst.toRef();
62766280 break :s &payload_val_scope.base;
62776281 } else {
62786282 _ = try then_scope.addUnNode(.ensure_err_union_payload_void, cond.inst, node);
......@@ -6285,7 +6289,8 @@ fn whileExpr(
62856289 else
62866290 .optional_payload_unsafe;
62876291 // will add this instruction to then_scope.instructions below
6288 payload_inst = try then_scope.makeUnNode(tag, cond.inst, while_full.ast.cond_expr);
6292 const payload_inst = try then_scope.makeUnNode(tag, cond.inst, while_full.ast.cond_expr);
6293 opt_payload_inst = payload_inst.toOptional();
62896294 const ident_name = try astgen.identAsString(ident_token);
62906295 const ident_bytes = tree.tokenSlice(ident_token);
62916296 if (mem.eql(u8, "_", ident_bytes))
......@@ -6295,12 +6300,12 @@ fn whileExpr(
62956300 .parent = &then_scope.base,
62966301 .gen_zir = &then_scope,
62976302 .name = ident_name,
6298 .inst = indexToRef(payload_inst),
6303 .inst = payload_inst.toRef(),
62996304 .token_src = ident_token,
63006305 .id_cat = .capture,
63016306 };
63026307 dbg_var_name = ident_name;
6303 dbg_var_inst = indexToRef(payload_inst);
6308 dbg_var_inst = payload_inst.toRef();
63046309 break :s &payload_val_scope.base;
63056310 } else {
63066311 break :s &then_scope.base;
......@@ -6316,8 +6321,8 @@ fn whileExpr(
63166321 _ = try loop_scope.addNode(repeat_tag, node);
63176322
63186323 try loop_scope.setBlockBody(loop_block);
6319 loop_scope.break_block = loop_block;
6320 loop_scope.continue_block = continue_block;
6324 loop_scope.break_block = loop_block.toOptional();
6325 loop_scope.continue_block = continue_block.toOptional();
63216326 if (while_full.label_token) |label_token| {
63226327 loop_scope.label = .{
63236328 .token = label_token,
......@@ -6330,7 +6335,9 @@ fn whileExpr(
63306335
63316336 try then_scope.addDbgBlockBegin();
63326337 const then_node = while_full.ast.then_expr;
6333 if (payload_inst != 0) try then_scope.instructions.append(astgen.gpa, payload_inst);
6338 if (opt_payload_inst.unwrap()) |payload_inst| {
6339 try then_scope.instructions.append(astgen.gpa, payload_inst);
6340 }
63346341 if (dbg_var_name) |name| try then_scope.addDbgVar(.dbg_var_val, name, dbg_var_inst);
63356342 try then_scope.instructions.append(astgen.gpa, continue_block);
63366343 // This code could be improved to avoid emitting the continue expr when there
......@@ -6386,8 +6393,8 @@ fn whileExpr(
63866393 };
63876394 // Remove the continue block and break block so that `continue` and `break`
63886395 // control flow apply to outer loops; not this one.
6389 loop_scope.continue_block = 0;
6390 loop_scope.break_block = 0;
6396 loop_scope.continue_block = .none;
6397 loop_scope.break_block = .none;
63916398 const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node);
63926399 if (is_statement) {
63936400 _ = try addEnsureResult(&else_scope, else_result, else_node);
......@@ -6412,9 +6419,9 @@ fn whileExpr(
64126419 try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope);
64136420
64146421 const result = if (need_result_rvalue)
6415 try rvalue(parent_gz, ri, indexToRef(loop_block), node)
6422 try rvalue(parent_gz, ri, loop_block.toRef(), node)
64166423 else
6417 indexToRef(loop_block);
6424 loop_block.toRef();
64186425
64196426 if (is_statement) {
64206427 _ = try parent_gz.addUnNode(.ensure_result_used, result, node);
......@@ -6577,8 +6584,8 @@ fn forExpr(
65776584 const cond_block = try loop_scope.makeBlockInst(block_tag, node);
65786585 try cond_scope.setBlockBody(cond_block);
65796586
6580 loop_scope.break_block = loop_block;
6581 loop_scope.continue_block = cond_block;
6587 loop_scope.break_block = loop_block.toOptional();
6588 loop_scope.continue_block = cond_block.toOptional();
65826589 if (for_full.label_token) |label_token| {
65836590 loop_scope.label = .{
65846591 .token = label_token,
......@@ -6671,8 +6678,8 @@ fn forExpr(
66716678 const sub_scope = &else_scope.base;
66726679 // Remove the continue block and break block so that `continue` and `break`
66736680 // control flow apply to outer loops; not this one.
6674 loop_scope.continue_block = 0;
6675 loop_scope.break_block = 0;
6681 loop_scope.continue_block = .none;
6682 loop_scope.break_block = .none;
66766683 const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node);
66776684 if (is_statement) {
66786685 _ = try addEnsureResult(&else_scope, else_result, else_node);
......@@ -6696,7 +6703,7 @@ fn forExpr(
66966703 // then_block and else_block unstacked now, can resurrect loop_scope to finally finish it
66976704 {
66986705 loop_scope.instructions_top = loop_scope.instructions.items.len;
6699 try loop_scope.instructions.appendSlice(gpa, &.{ Zir.refToIndex(index).?, cond_block });
6706 try loop_scope.instructions.appendSlice(gpa, &.{ index.toIndex().?, cond_block });
67006707
67016708 // Increment the index variable.
67026709 const index_plus_one = try loop_scope.addPlNode(.add_unsafe, node, Zir.Inst.Bin{
......@@ -6711,9 +6718,9 @@ fn forExpr(
67116718 }
67126719
67136720 const result = if (need_result_rvalue)
6714 try rvalue(parent_gz, ri, indexToRef(loop_block), node)
6721 try rvalue(parent_gz, ri, loop_block.toRef(), node)
67156722 else
6716 indexToRef(loop_block);
6723 loop_block.toRef();
67176724
67186725 if (is_statement) {
67196726 _ = try parent_gz.addUnNode(.ensure_result_used, result, node);
......@@ -6912,7 +6919,7 @@ fn switchExpr(
69126919
69136920 // If any prong has an inline tag capture, allocate a shared dummy instruction for it
69146921 const tag_inst = if (any_has_tag_capture) tag_inst: {
6915 const inst: Zir.Inst.Index = @intCast(astgen.instructions.len);
6922 const inst: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
69166923 try astgen.instructions.append(astgen.gpa, .{
69176924 .tag = .extended,
69186925 .data = .{ .extended = .{
......@@ -6967,12 +6974,12 @@ fn switchExpr(
69676974 .parent = &case_scope.base,
69686975 .gen_zir = &case_scope,
69696976 .name = capture_name,
6970 .inst = indexToRef(switch_block),
6977 .inst = switch_block.toRef(),
69716978 .token_src = payload_token,
69726979 .id_cat = .capture,
69736980 };
69746981 dbg_var_name = capture_name;
6975 dbg_var_inst = indexToRef(switch_block);
6982 dbg_var_inst = switch_block.toRef();
69766983 payload_sub_scope = &capture_val_scope.base;
69776984 }
69786985
......@@ -6996,12 +7003,12 @@ fn switchExpr(
69967003 .parent = payload_sub_scope,
69977004 .gen_zir = &case_scope,
69987005 .name = tag_name,
6999 .inst = indexToRef(tag_inst),
7006 .inst = tag_inst.toRef(),
70007007 .token_src = tag_token,
70017008 .id_cat = .@"switch tag capture",
70027009 };
70037010 dbg_var_tag_name = tag_name;
7004 dbg_var_tag_inst = indexToRef(tag_inst);
7011 dbg_var_tag_inst = tag_inst.toRef();
70057012 break :blk &tag_scope.base;
70067013 };
70077014
......@@ -7136,11 +7143,11 @@ fn switchExpr(
71367143 }
71377144
71387145 if (any_has_tag_capture) {
7139 astgen.extra.appendAssumeCapacity(tag_inst);
7146 astgen.extra.appendAssumeCapacity(@intFromEnum(tag_inst));
71407147 }
71417148
71427149 const zir_datas = astgen.instructions.items(.data);
7143 zir_datas[switch_block].pl_node.payload_index = payload_index;
7150 zir_datas[@intFromEnum(switch_block)].pl_node.payload_index = payload_index;
71447151
71457152 for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| {
71467153 var body_len_index = start_index;
......@@ -7163,9 +7170,9 @@ fn switchExpr(
71637170 }
71647171
71657172 if (need_result_rvalue) {
7166 return rvalue(parent_gz, ri, indexToRef(switch_block), switch_node);
7173 return rvalue(parent_gz, ri, switch_block.toRef(), switch_node);
71677174 } else {
7168 return indexToRef(switch_block);
7175 return switch_block.toRef();
71697176 }
71707177}
71717178
......@@ -7524,13 +7531,13 @@ fn tunnelThroughClosure(
75247531) !Zir.Inst.Ref {
75257532 // For trivial values, we don't need a tunnel.
75267533 // Just return the ref.
7527 if (num_tunnels == 0 or refToIndex(value) == null) {
7534 if (num_tunnels == 0 or value.toIndex() == null) {
75287535 return value;
75297536 }
75307537
75317538 // Otherwise we need a tunnel. Check if this namespace
75327539 // already has one for this value.
7533 const gop = try ns.?.captures.getOrPut(gpa, refToIndex(value).?);
7540 const gop = try ns.?.captures.getOrPut(gpa, value.toIndex().?);
75347541 if (!gop.found_existing) {
75357542 // Make a new capture for this value but don't add it to the declaring_gz yet
75367543 try gz.astgen.instructions.append(gz.astgen.gpa, .{
......@@ -7540,7 +7547,7 @@ fn tunnelThroughClosure(
75407547 .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token),
75417548 } },
75427549 });
7543 gop.value_ptr.* = @intCast(gz.astgen.instructions.len - 1);
7550 gop.value_ptr.* = @enumFromInt(gz.astgen.instructions.len - 1);
75447551 }
75457552
75467553 // Add an instruction to get the value from the closure into
......@@ -8032,7 +8039,7 @@ fn typeOf(
80328039
80338040 // typeof_scope unstacked now, can add new instructions to gz
80348041 try gz.instructions.append(gpa, typeof_inst);
8035 return rvalue(gz, ri, indexToRef(typeof_inst), node);
8042 return rvalue(gz, ri, typeof_inst.toRef(), node);
80368043 }
80378044 const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len;
80388045 const payload_index = try reserveExtra(astgen, payload_size + args.len);
......@@ -8047,7 +8054,7 @@ fn typeOf(
80478054 const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node);
80488055 astgen.extra.items[args_index + i] = @intFromEnum(param_ref);
80498056 }
8050 _ = try typeof_scope.addBreak(.break_inline, refToIndex(typeof_inst).?, .void_value);
8057 _ = try typeof_scope.addBreak(.break_inline, typeof_inst.toIndex().?, .void_value);
80518058
80528059 const body = typeof_scope.instructionsSlice();
80538060 const body_len = astgen.countBodyLenAfterFixups(body);
......@@ -8401,7 +8408,7 @@ fn builtinCall(
84018408 .node = gz.nodeIndexToRelative(node),
84028409 .operand = operand,
84038410 });
8404 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
8411 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
84058412 gz.astgen.instructions.appendAssumeCapacity(.{
84068413 .tag = .extended,
84078414 .data = .{ .extended = .{
......@@ -8411,7 +8418,7 @@ fn builtinCall(
84118418 } },
84128419 });
84138420 gz.instructions.appendAssumeCapacity(new_index);
8414 const result = indexToRef(new_index);
8421 const result = new_index.toRef();
84158422 return rvalue(gz, ri, result, node);
84168423 },
84178424 .panic => {
......@@ -8993,7 +9000,7 @@ fn cImport(
89939000 // block_scope unstacked now, can add new instructions to gz
89949001 try gz.instructions.append(gpa, block_inst);
89959002
8996 return indexToRef(block_inst);
9003 return block_inst.toRef();
89979004}
89989005
89999006fn overflowArithmetic(
......@@ -9056,8 +9063,8 @@ fn callExpr(
90569063 }
90579064 assert(node != 0);
90589065
9059 const call_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
9060 const call_inst = Zir.indexToRef(call_index);
9066 const call_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
9067 const call_inst = call_index.toRef();
90619068 try gz.astgen.instructions.append(astgen.gpa, undefined);
90629069 try gz.instructions.append(astgen.gpa, call_index);
90639070
......@@ -9104,7 +9111,7 @@ fn callExpr(
91049111 if (call.ast.params.len != 0) {
91059112 try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]);
91069113 }
9107 gz.astgen.instructions.set(call_index, .{
9114 gz.astgen.instructions.set(@intFromEnum(call_index), .{
91089115 .tag = .call,
91099116 .data = .{ .pl_node = .{
91109117 .src_node = gz.nodeIndexToRelative(node),
......@@ -9125,7 +9132,7 @@ fn callExpr(
91259132 if (call.ast.params.len != 0) {
91269133 try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]);
91279134 }
9128 gz.astgen.instructions.set(call_index, .{
9135 gz.astgen.instructions.set(@intFromEnum(call_index), .{
91299136 .tag = .field_call,
91309137 .data = .{ .pl_node = .{
91319138 .src_node = gz.nodeIndexToRelative(node),
......@@ -10062,10 +10069,10 @@ fn rvalueInner(
1006210069 allow_coerce_pre_ref: bool,
1006310070) InnerError!Zir.Inst.Ref {
1006410071 const result = r: {
10065 if (refToIndex(raw_result)) |result_index| {
10072 if (raw_result.toIndex()) |result_index| {
1006610073 const zir_tags = gz.astgen.instructions.items(.tag);
10067 const data = gz.astgen.instructions.items(.data)[result_index];
10068 if (zir_tags[result_index].isAlwaysVoid(data)) {
10074 const data = gz.astgen.instructions.items(.data)[@intFromEnum(result_index)];
10075 if (zir_tags[@intFromEnum(result_index)].isAlwaysVoid(data)) {
1006910076 break :r Zir.Inst.Ref.void_value;
1007010077 }
1007110078 }
......@@ -10094,16 +10101,16 @@ fn rvalueInner(
1009410101 const astgen = gz.astgen;
1009510102 const tree = astgen.tree;
1009610103 const src_token = tree.firstToken(src_node);
10097 const result_index = refToIndex(coerced_result) orelse
10104 const result_index = coerced_result.toIndex() orelse
1009810105 return gz.addUnTok(.ref, coerced_result, src_token);
1009910106 const zir_tags = gz.astgen.instructions.items(.tag);
10100 if (zir_tags[result_index].isParam() or astgen.isInferred(coerced_result))
10107 if (zir_tags[@intFromEnum(result_index)].isParam() or astgen.isInferred(coerced_result))
1010110108 return gz.addUnTok(.ref, coerced_result, src_token);
1010210109 const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index);
1010310110 if (!gop.found_existing) {
1010410111 gop.value_ptr.* = try gz.makeUnTok(.ref, coerced_result, src_token);
1010510112 }
10106 return indexToRef(gop.value_ptr.*);
10113 return gop.value_ptr.*.toRef();
1010710114 },
1010810115 .ty => |ty_inst| {
1010910116 // Quickly eliminate some common, unnecessary type coercion.
......@@ -10849,7 +10856,7 @@ const Scope = struct {
1084910856 parent: *Scope,
1085010857 index: u32,
1085110858 len: u32,
10852 remapped_err_code: Zir.Inst.Index = 0,
10859 remapped_err_code: Zir.Inst.OptionalIndex = .none,
1085310860 };
1085410861
1085510862 /// Represents a global scope that has any number of declarations in it.
......@@ -10919,8 +10926,8 @@ const GenZir = struct {
1091910926 /// if use is strictly nested. This saves prior size of list for unstacking.
1092010927 instructions_top: usize,
1092110928 label: ?Label = null,
10922 break_block: Zir.Inst.Index = 0,
10923 continue_block: Zir.Inst.Index = 0,
10929 break_block: Zir.Inst.OptionalIndex = .none,
10930 continue_block: Zir.Inst.OptionalIndex = .none,
1092410931 /// Only valid when setBreakResultInfo is called.
1092510932 break_result_info: AstGen.ResultInfo = undefined,
1092610933
......@@ -10995,14 +11002,14 @@ const GenZir = struct {
1099511002 if (gz.isEmpty()) return false;
1099611003 const tags = gz.astgen.instructions.items(.tag);
1099711004 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
10998 return tags[last_inst].isNoReturn();
11005 return tags[@intFromEnum(last_inst)].isNoReturn();
1099911006 }
1100011007
1100111008 /// TODO all uses of this should be replaced with uses of `endsWithNoReturn`.
1100211009 fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool {
1100311010 if (inst_ref == .unreachable_value) return true;
11004 if (refToIndex(inst_ref)) |inst_index| {
11005 return gz.astgen.instructions.items(.tag)[inst_index].isNoReturn();
11011 if (inst_ref.toIndex()) |inst_index| {
11012 return gz.astgen.instructions.items(.tag)[@intFromEnum(inst_index)].isNoReturn();
1100611013 }
1100711014 return false;
1100811015 }
......@@ -11053,7 +11060,7 @@ const GenZir = struct {
1105311060 @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len,
1105411061 );
1105511062 const zir_datas = astgen.instructions.items(.data);
11056 zir_datas[inst].bool_br.payload_index = astgen.addExtraAssumeCapacity(
11063 zir_datas[@intFromEnum(inst)].bool_br.payload_index = astgen.addExtraAssumeCapacity(
1105711064 Zir.Inst.Block{ .body_len = body_len },
1105811065 );
1105911066 astgen.appendBodyWithFixups(body);
......@@ -11071,7 +11078,7 @@ const GenZir = struct {
1107111078 @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len,
1107211079 );
1107311080 const zir_datas = astgen.instructions.items(.data);
11074 zir_datas[inst].pl_node.payload_index = astgen.addExtraAssumeCapacity(
11081 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
1107511082 Zir.Inst.Block{ .body_len = body_len },
1107611083 );
1107711084 astgen.appendBodyWithFixups(body);
......@@ -11089,7 +11096,7 @@ const GenZir = struct {
1108911096 @typeInfo(Zir.Inst.Try).Struct.fields.len + body_len,
1109011097 );
1109111098 const zir_datas = astgen.instructions.items(.data);
11092 zir_datas[inst].pl_node.payload_index = astgen.addExtraAssumeCapacity(
11099 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
1109311100 Zir.Inst.Try{
1109411101 .operand = operand,
1109511102 .body_len = body_len,
......@@ -11139,7 +11146,7 @@ const GenZir = struct {
1113911146 const astgen = gz.astgen;
1114011147 const gpa = astgen.gpa;
1114111148 const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref;
11142 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11149 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1114311150
1114411151 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1114511152
......@@ -11235,9 +11242,9 @@ const GenZir = struct {
1123511242 if (align_body.len != 0) {
1123611243 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body));
1123711244 astgen.appendBodyWithFixups(align_body);
11238 const break_extra = zir_datas[align_body[align_body.len - 1]].@"break".payload_index;
11245 const break_extra = zir_datas[@intFromEnum(align_body[align_body.len - 1])].@"break".payload_index;
1123911246 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11240 new_index;
11247 @intFromEnum(new_index);
1124111248 } else if (args.align_ref != .none) {
1124211249 astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref));
1124311250 }
......@@ -11245,9 +11252,9 @@ const GenZir = struct {
1124511252 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body));
1124611253 astgen.appendBodyWithFixups(addrspace_body);
1124711254 const break_extra =
11248 zir_datas[addrspace_body[addrspace_body.len - 1]].@"break".payload_index;
11255 zir_datas[@intFromEnum(addrspace_body[addrspace_body.len - 1])].@"break".payload_index;
1124911256 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11250 new_index;
11257 @intFromEnum(new_index);
1125111258 } else if (args.addrspace_ref != .none) {
1125211259 astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref));
1125311260 }
......@@ -11255,27 +11262,27 @@ const GenZir = struct {
1125511262 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body));
1125611263 astgen.appendBodyWithFixups(section_body);
1125711264 const break_extra =
11258 zir_datas[section_body[section_body.len - 1]].@"break".payload_index;
11265 zir_datas[@intFromEnum(section_body[section_body.len - 1])].@"break".payload_index;
1125911266 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11260 new_index;
11267 @intFromEnum(new_index);
1126111268 } else if (args.section_ref != .none) {
1126211269 astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref));
1126311270 }
1126411271 if (cc_body.len != 0) {
1126511272 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body));
1126611273 astgen.appendBodyWithFixups(cc_body);
11267 const break_extra = zir_datas[cc_body[cc_body.len - 1]].@"break".payload_index;
11274 const break_extra = zir_datas[@intFromEnum(cc_body[cc_body.len - 1])].@"break".payload_index;
1126811275 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11269 new_index;
11276 @intFromEnum(new_index);
1127011277 } else if (args.cc_ref != .none) {
1127111278 astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref));
1127211279 }
1127311280 if (ret_body.len != 0) {
1127411281 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body));
1127511282 astgen.appendBodyWithFixups(ret_body);
11276 const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index;
11283 const break_extra = zir_datas[@intFromEnum(ret_body[ret_body.len - 1])].@"break".payload_index;
1127711284 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11278 new_index;
11285 @intFromEnum(new_index);
1127911286 } else if (ret_ref != .none) {
1128011287 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));
1128111288 }
......@@ -11307,7 +11314,7 @@ const GenZir = struct {
1130711314 } },
1130811315 });
1130911316 gz.instructions.appendAssumeCapacity(new_index);
11310 return indexToRef(new_index);
11317 return new_index.toRef();
1131111318 } else {
1131211319 try astgen.extra.ensureUnusedCapacity(
1131311320 gpa,
......@@ -11330,9 +11337,9 @@ const GenZir = struct {
1133011337 if (ret_body.len != 0) {
1133111338 astgen.appendBodyWithFixups(ret_body);
1133211339
11333 const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index;
11340 const break_extra = zir_datas[@intFromEnum(ret_body[ret_body.len - 1])].@"break".payload_index;
1133411341 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11335 new_index;
11342 @intFromEnum(new_index);
1133611343 } else if (ret_ref != .none) {
1133711344 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));
1133811345 }
......@@ -11358,7 +11365,7 @@ const GenZir = struct {
1135811365 } },
1135911366 });
1136011367 gz.instructions.appendAssumeCapacity(new_index);
11361 return indexToRef(new_index);
11368 return new_index.toRef();
1136211369 }
1136311370 }
1136411371
......@@ -11402,7 +11409,7 @@ const GenZir = struct {
1140211409 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));
1140311410 }
1140411411
11405 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11412 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1140611413 astgen.instructions.appendAssumeCapacity(.{
1140711414 .tag = .extended,
1140811415 .data = .{ .extended = .{
......@@ -11418,7 +11425,7 @@ const GenZir = struct {
1141811425 } },
1141911426 });
1142011427 gz.instructions.appendAssumeCapacity(new_index);
11421 return indexToRef(new_index);
11428 return new_index.toRef();
1142211429 }
1142311430
1142411431 /// Note that this returns a `Zir.Inst.Index` not a ref.
......@@ -11433,7 +11440,7 @@ const GenZir = struct {
1143311440 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1143411441 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1143511442
11436 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11443 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1143711444 gz.astgen.instructions.appendAssumeCapacity(.{
1143811445 .tag = tag,
1143911446 .data = .{ .bool_br = .{
......@@ -11459,7 +11466,7 @@ const GenZir = struct {
1145911466 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1146011467 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);
1146111468
11462 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11469 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1146311470 astgen.instructions.appendAssumeCapacity(.{
1146411471 .tag = .int_big,
1146511472 .data = .{ .str = .{
......@@ -11469,7 +11476,7 @@ const GenZir = struct {
1146911476 });
1147011477 gz.instructions.appendAssumeCapacity(new_index);
1147111478 astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs));
11472 return indexToRef(new_index);
11479 return new_index.toRef();
1147311480 }
1147411481
1147511482 fn addFloat(gz: *GenZir, number: f64) !Zir.Inst.Ref {
......@@ -11504,7 +11511,7 @@ const GenZir = struct {
1150411511 src_node: Ast.Node.Index,
1150511512 ) !Zir.Inst.Index {
1150611513 assert(operand != .none);
11507 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11514 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1150811515 try gz.astgen.instructions.append(gz.astgen.gpa, .{
1150911516 .tag = tag,
1151011517 .data = .{ .un_node = .{
......@@ -11527,7 +11534,7 @@ const GenZir = struct {
1152711534 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1152811535
1152911536 const payload_index = try gz.astgen.addExtra(extra);
11530 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11537 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1153111538 gz.astgen.instructions.appendAssumeCapacity(.{
1153211539 .tag = tag,
1153311540 .data = .{ .pl_node = .{
......@@ -11536,7 +11543,7 @@ const GenZir = struct {
1153611543 } },
1153711544 });
1153811545 gz.instructions.appendAssumeCapacity(new_index);
11539 return indexToRef(new_index);
11546 return new_index.toRef();
1154011547 }
1154111548
1154211549 fn addPlNodePayloadIndex(
......@@ -11584,7 +11591,7 @@ const GenZir = struct {
1158411591 gz.astgen.appendBodyWithFixups(param_body);
1158511592 param_gz.unstack();
1158611593
11587 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11594 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1158811595 gz.astgen.instructions.appendAssumeCapacity(.{
1158911596 .tag = tag,
1159011597 .data = .{ .pl_tok = .{
......@@ -11612,7 +11619,7 @@ const GenZir = struct {
1161211619 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1161311620
1161411621 const payload_index = try gz.astgen.addExtra(extra);
11615 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11622 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1161611623 gz.astgen.instructions.appendAssumeCapacity(.{
1161711624 .tag = .extended,
1161811625 .data = .{ .extended = .{
......@@ -11622,7 +11629,7 @@ const GenZir = struct {
1162211629 } },
1162311630 });
1162411631 gz.instructions.appendAssumeCapacity(new_index);
11625 return indexToRef(new_index);
11632 return new_index.toRef();
1162611633 }
1162711634
1162811635 fn addExtendedMultiOp(
......@@ -11644,7 +11651,7 @@ const GenZir = struct {
1164411651 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
1164511652 .src_node = gz.nodeIndexToRelative(node),
1164611653 });
11647 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11654 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1164811655 astgen.instructions.appendAssumeCapacity(.{
1164911656 .tag = .extended,
1165011657 .data = .{ .extended = .{
......@@ -11655,7 +11662,7 @@ const GenZir = struct {
1165511662 });
1165611663 gz.instructions.appendAssumeCapacity(new_index);
1165711664 astgen.appendRefsAssumeCapacity(operands);
11658 return indexToRef(new_index);
11665 return new_index.toRef();
1165911666 }
1166011667
1166111668 fn addExtendedMultiOpPayloadIndex(
......@@ -11669,7 +11676,7 @@ const GenZir = struct {
1166911676
1167011677 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1167111678 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
11672 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11679 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1167311680 astgen.instructions.appendAssumeCapacity(.{
1167411681 .tag = .extended,
1167511682 .data = .{ .extended = .{
......@@ -11679,7 +11686,7 @@ const GenZir = struct {
1167911686 } },
1168011687 });
1168111688 gz.instructions.appendAssumeCapacity(new_index);
11682 return indexToRef(new_index);
11689 return new_index.toRef();
1168311690 }
1168411691
1168511692 fn addUnTok(
......@@ -11707,7 +11714,7 @@ const GenZir = struct {
1170711714 abs_tok_index: Ast.TokenIndex,
1170811715 ) !Zir.Inst.Index {
1170911716 const astgen = gz.astgen;
11710 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11717 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1171111718 assert(operand != .none);
1171211719 try astgen.instructions.append(astgen.gpa, .{
1171311720 .tag = tag,
......@@ -11771,7 +11778,7 @@ const GenZir = struct {
1177111778 .data = .{ .restore_err_ret_index = .{
1177211779 .block = switch (bt) {
1177311780 .ret => .none,
11774 .block => |b| Zir.indexToRef(b),
11781 .block => |b| b.toRef(),
1177511782 },
1177611783 .operand = if (cond == .if_non_error) cond.if_non_error else .none,
1177711784 } },
......@@ -11837,7 +11844,7 @@ const GenZir = struct {
1183711844 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1183811845 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).Struct.fields.len);
1183911846
11840 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
11847 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1184111848 gz.astgen.instructions.appendAssumeCapacity(.{
1184211849 .tag = tag,
1184311850 .data = .{ .@"break" = .{
......@@ -11978,7 +11985,7 @@ const GenZir = struct {
1197811985 const is_comptime: u4 = @intFromBool(args.is_comptime);
1197911986 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);
1198011987
11981 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11988 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1198211989 astgen.instructions.appendAssumeCapacity(.{
1198311990 .tag = .extended,
1198411991 .data = .{ .extended = .{
......@@ -11988,7 +11995,7 @@ const GenZir = struct {
1198811995 } },
1198911996 });
1199011997 gz.instructions.appendAssumeCapacity(new_index);
11991 return indexToRef(new_index);
11998 return new_index.toRef();
1199211999 }
1199312000
1199412001 fn addAsm(
......@@ -12037,7 +12044,7 @@ const GenZir = struct {
1203712044 @as(u16, @intCast(args.clobbers.len << 10)) |
1203812045 (@as(u16, @intFromBool(args.is_volatile)) << 15);
1203912046
12040 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
12047 const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len);
1204112048 astgen.instructions.appendAssumeCapacity(.{
1204212049 .tag = .extended,
1204312050 .data = .{ .extended = .{
......@@ -12047,14 +12054,14 @@ const GenZir = struct {
1204712054 } },
1204812055 });
1204912056 gz.instructions.appendAssumeCapacity(new_index);
12050 return indexToRef(new_index);
12057 return new_index.toRef();
1205112058 }
1205212059
1205312060 /// Note that this returns a `Zir.Inst.Index` not a ref.
1205412061 /// Does *not* append the block instruction to the scope.
1205512062 /// Leaves the `payload_index` field undefined.
1205612063 fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
12057 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
12064 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1205812065 const gpa = gz.astgen.gpa;
1205912066 try gz.astgen.instructions.append(gpa, .{
1206012067 .tag = tag,
......@@ -12071,7 +12078,7 @@ const GenZir = struct {
1207112078 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
1207212079 const gpa = gz.astgen.gpa;
1207312080 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12074 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
12081 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1207512082 try gz.astgen.instructions.append(gpa, .{
1207612083 .tag = tag,
1207712084 .data = .{ .pl_node = .{
......@@ -12119,7 +12126,7 @@ const GenZir = struct {
1211912126 astgen.extra.appendAssumeCapacity(@intFromEnum(args.backing_int_ref));
1212012127 }
1212112128 }
12122 astgen.instructions.set(inst, .{
12129 astgen.instructions.set(@intFromEnum(inst), .{
1212312130 .tag = .extended,
1212412131 .data = .{ .extended = .{
1212512132 .opcode = .struct_decl,
......@@ -12174,7 +12181,7 @@ const GenZir = struct {
1217412181 if (args.decls_len != 0) {
1217512182 astgen.extra.appendAssumeCapacity(args.decls_len);
1217612183 }
12177 astgen.instructions.set(inst, .{
12184 astgen.instructions.set(@intFromEnum(inst), .{
1217812185 .tag = .extended,
1217912186 .data = .{ .extended = .{
1218012187 .opcode = .union_decl,
......@@ -12224,7 +12231,7 @@ const GenZir = struct {
1222412231 if (args.decls_len != 0) {
1222512232 astgen.extra.appendAssumeCapacity(args.decls_len);
1222612233 }
12227 astgen.instructions.set(inst, .{
12234 astgen.instructions.set(@intFromEnum(inst), .{
1222812235 .tag = .extended,
1222912236 .data = .{ .extended = .{
1223012237 .opcode = .enum_decl,
......@@ -12259,7 +12266,7 @@ const GenZir = struct {
1225912266 if (args.decls_len != 0) {
1226012267 astgen.extra.appendAssumeCapacity(args.decls_len);
1226112268 }
12262 astgen.instructions.set(inst, .{
12269 astgen.instructions.set(@intFromEnum(inst), .{
1226312270 .tag = .extended,
1226412271 .data = .{ .extended = .{
1226512272 .opcode = .opaque_decl,
......@@ -12274,7 +12281,7 @@ const GenZir = struct {
1227412281 }
1227512282
1227612283 fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref {
12277 return indexToRef(try gz.addAsIndex(inst));
12284 return (try gz.addAsIndex(inst)).toRef();
1227812285 }
1227912286
1228012287 fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index {
......@@ -12282,7 +12289,7 @@ const GenZir = struct {
1228212289 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1228312290 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1228412291
12285 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
12292 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1228612293 gz.astgen.instructions.appendAssumeCapacity(inst);
1228712294 gz.instructions.appendAssumeCapacity(new_index);
1228812295 return new_index;
......@@ -12293,7 +12300,7 @@ const GenZir = struct {
1229312300 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1229412301 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1229512302
12296 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
12303 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1229712304 gz.astgen.instructions.len += 1;
1229812305 gz.instructions.appendAssumeCapacity(new_index);
1229912306 return new_index;
......@@ -12340,12 +12347,12 @@ const GenZir = struct {
1234012347 const tags = gz.astgen.instructions.items(.tag);
1234112348 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
1234212349 // remove dbg_block_begin immediately followed by dbg_block_end
12343 if (tags[last_inst] == .dbg_block_begin) {
12350 if (tags[@intFromEnum(last_inst)] == .dbg_block_begin) {
1234412351 _ = gz.instructions.pop();
1234512352 return;
1234612353 }
1234712354
12348 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
12355 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1234912356 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
1235012357 try gz.instructions.append(gpa, new_index);
1235112358 }
......@@ -12622,9 +12629,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast.
1262212629}
1262312630
1262412631fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
12625 const inst = refToIndex(ref) orelse return false;
12632 const inst = ref.toIndex() orelse return false;
1262612633 const zir_tags = astgen.instructions.items(.tag);
12627 return switch (zir_tags[inst]) {
12634 return switch (zir_tags[@intFromEnum(inst)]) {
1262812635 .alloc_inferred,
1262912636 .alloc_inferred_mut,
1263012637 .alloc_inferred_comptime,
......@@ -12633,8 +12640,8 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
1263312640
1263412641 .extended => {
1263512642 const zir_data = astgen.instructions.items(.data);
12636 if (zir_data[inst].extended.opcode != .alloc) return false;
12637 const small: Zir.Inst.AllocExtended.Small = @bitCast(zir_data[inst].extended.small);
12643 if (zir_data[@intFromEnum(inst)].extended.opcode != .alloc) return false;
12644 const small: Zir.Inst.AllocExtended.Small = @bitCast(zir_data[@intFromEnum(inst)].extended.small);
1263812645 return !small.has_type;
1263912646 },
1264012647
......@@ -12663,7 +12670,7 @@ fn appendPossiblyRefdBodyInst(
1266312670 list: *std.ArrayListUnmanaged(u32),
1266412671 body_inst: Zir.Inst.Index,
1266512672) void {
12666 list.appendAssumeCapacity(body_inst);
12673 list.appendAssumeCapacity(@intFromEnum(body_inst));
1266712674 const kv = astgen.ref_table.fetchRemove(body_inst) orelse return;
1266812675 const ref_inst = kv.value;
1266912676 return appendPossiblyRefdBodyInst(astgen, list, ref_inst);
src/Autodoc.zig+221-191
......@@ -333,7 +333,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
333333 file,
334334 &root_scope,
335335 .{},
336 Zir.main_struct_inst,
336 .main_struct_inst,
337337 false,
338338 null,
339339 );
......@@ -464,14 +464,14 @@ const Scope = struct {
464464 /// Another reason is that in some places we use the pointer to uniquely
465465 /// refer to a decl, as we wait for it to be analyzed. This means that
466466 /// those pointers must stay stable.
467 pub fn resolveDeclName(self: Scope, string_table_idx: u32, file: *File, inst_index: usize) *DeclStatus {
467 pub fn resolveDeclName(self: Scope, string_table_idx: u32, file: *File, inst: Zir.Inst.OptionalIndex) *DeclStatus {
468468 var cur: ?*const Scope = &self;
469469 return while (cur) |s| : (cur = s.parent) {
470470 break s.map.get(string_table_idx) orelse continue;
471471 } else {
472 printWithContext(
472 printWithOptionalContext(
473473 file,
474 inst_index,
474 inst,
475475 "Could not find `{s}`\n\n",
476476 .{file.zir.nullTerminatedString(string_table_idx)},
477477 );
......@@ -937,7 +937,7 @@ const AutodocErrors = error{
937937/// This type is used to keep track of dangerous instruction
938938/// numbers that we definitely don't want to recurse into.
939939const CallContext = struct {
940 inst: usize,
940 inst: Zir.Inst.Index,
941941 prev: ?*const CallContext,
942942};
943943
......@@ -954,14 +954,14 @@ fn walkInstruction(
954954 file: *File,
955955 parent_scope: *Scope,
956956 parent_src: SrcLocInfo,
957 inst_index: usize,
957 inst: Zir.Inst.Index,
958958 need_type: bool, // true if the caller needs us to provide also a typeRef
959959 call_ctx: ?*const CallContext,
960960) AutodocErrors!DocData.WalkResult {
961961 const tags = file.zir.instructions.items(.tag);
962962 const data = file.zir.instructions.items(.data);
963963
964 if (self.repurposed_insts.contains(@intCast(inst_index))) {
964 if (self.repurposed_insts.contains(inst)) {
965965 // TODO: better handling here
966966 return .{ .expr = .{ .comptimeExpr = 0 } };
967967 }
......@@ -969,18 +969,18 @@ fn walkInstruction(
969969 // We assume that the topmost ast_node entry corresponds to our decl
970970 const self_ast_node_index = self.ast_nodes.items.len - 1;
971971
972 switch (tags[inst_index]) {
972 switch (tags[@intFromEnum(inst)]) {
973973 else => {
974974 printWithContext(
975975 file,
976 inst_index,
976 inst,
977977 "TODO: implement `{s}` for walkInstruction\n\n",
978 .{@tagName(tags[inst_index])},
978 .{@tagName(tags[@intFromEnum(inst)])},
979979 );
980 return self.cteTodo(@tagName(tags[inst_index]));
980 return self.cteTodo(@tagName(tags[@intFromEnum(inst)]));
981981 },
982982 .import => {
983 const str_tok = data[inst_index].str_tok;
983 const str_tok = data[@intFromEnum(inst)].str_tok;
984984 var path = str_tok.get(file.zir);
985985
986986 // importFile cannot error out since all files
......@@ -1048,7 +1048,7 @@ fn walkInstruction(
10481048 new_file,
10491049 &root_scope,
10501050 .{},
1051 Zir.main_struct_inst,
1051 .main_struct_inst,
10521052 false,
10531053 call_ctx,
10541054 );
......@@ -1080,7 +1080,7 @@ fn walkInstruction(
10801080 new_file.file,
10811081 &new_scope,
10821082 .{},
1083 Zir.main_struct_inst,
1083 .main_struct_inst,
10841084 need_type,
10851085 call_ctx,
10861086 );
......@@ -1092,7 +1092,7 @@ fn walkInstruction(
10921092 };
10931093 },
10941094 .ret_node => {
1095 const un_node = data[inst_index].un_node;
1095 const un_node = data[@intFromEnum(inst)].un_node;
10961096 return self.walkRef(
10971097 file,
10981098 parent_scope,
......@@ -1103,9 +1103,9 @@ fn walkInstruction(
11031103 );
11041104 },
11051105 .ret_load => {
1106 const un_node = data[inst_index].un_node;
1106 const un_node = data[@intFromEnum(inst)].un_node;
11071107 const res_ptr_ref = un_node.operand;
1108 const res_ptr_inst = Zir.refToIndex(res_ptr_ref).?;
1108 const res_ptr_inst = @intFromEnum(res_ptr_ref.toIndex().?);
11091109 // TODO: this instruction doesn't let us know trivially if there's
11101110 // branching involved or not. For now here's the strat:
11111111 // We search backwarts until `ret_ptr` for `store_node`,
......@@ -1113,7 +1113,7 @@ fn walkInstruction(
11131113 // than one, then it means that there's branching involved.
11141114 // Maybe.
11151115
1116 var i = inst_index - 1;
1116 var i = @intFromEnum(inst) - 1;
11171117 var result_ref: ?Ref = null;
11181118 while (i > res_ptr_inst) : (i -= 1) {
11191119 if (tags[i] == .store_node) {
......@@ -1146,7 +1146,7 @@ fn walkInstruction(
11461146 };
11471147 },
11481148 .closure_get => {
1149 const inst_node = data[inst_index].inst_node;
1149 const inst_node = data[@intFromEnum(inst)].inst_node;
11501150 return try self.walkInstruction(
11511151 file,
11521152 parent_scope,
......@@ -1157,7 +1157,7 @@ fn walkInstruction(
11571157 );
11581158 },
11591159 .closure_capture => {
1160 const un_tok = data[inst_index].un_tok;
1160 const un_tok = data[@intFromEnum(inst)].un_tok;
11611161 return try self.walkRef(
11621162 file,
11631163 parent_scope,
......@@ -1168,7 +1168,7 @@ fn walkInstruction(
11681168 );
11691169 },
11701170 .str => {
1171 const str = data[inst_index].str.get(file.zir);
1171 const str = data[@intFromEnum(inst)].str.get(file.zir);
11721172
11731173 const tRef: ?DocData.Expr = if (!need_type) null else blk: {
11741174 const arrTypeId = self.types.items.len;
......@@ -1204,7 +1204,7 @@ fn walkInstruction(
12041204 };
12051205 },
12061206 .compile_error => {
1207 const un_node = data[inst_index].un_node;
1207 const un_node = data[@intFromEnum(inst)].un_node;
12081208
12091209 var operand: DocData.WalkResult = try self.walkRef(
12101210 file,
......@@ -1223,7 +1223,7 @@ fn walkInstruction(
12231223 };
12241224 },
12251225 .enum_literal => {
1226 const str_tok = data[inst_index].str_tok;
1226 const str_tok = data[@intFromEnum(inst)].str_tok;
12271227 const literal = file.zir.nullTerminatedString(str_tok.start);
12281228 const type_index = self.types.items.len;
12291229 try self.types.append(self.arena, .{
......@@ -1236,7 +1236,7 @@ fn walkInstruction(
12361236 };
12371237 },
12381238 .int => {
1239 const int = data[inst_index].int;
1239 const int = data[@intFromEnum(inst)].int;
12401240 return DocData.WalkResult{
12411241 .typeRef = .{ .type = @intFromEnum(Ref.comptime_int_type) },
12421242 .expr = .{ .int = .{ .value = int } },
......@@ -1244,7 +1244,7 @@ fn walkInstruction(
12441244 },
12451245 .int_big => {
12461246 // @check
1247 const str = data[inst_index].str; //.get(file.zir);
1247 const str = data[@intFromEnum(inst)].str; //.get(file.zir);
12481248 const byte_count = str.len * @sizeOf(std.math.big.Limb);
12491249 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
12501250
......@@ -1271,7 +1271,7 @@ fn walkInstruction(
12711271 },
12721272
12731273 .slice_start => {
1274 const pl_node = data[inst_index].pl_node;
1274 const pl_node = data[@intFromEnum(inst)].pl_node;
12751275 const extra = file.zir.extraData(Zir.Inst.SliceStart, pl_node.payload_index);
12761276
12771277 const slice_index = self.exprs.items.len;
......@@ -1311,7 +1311,7 @@ fn walkInstruction(
13111311 };
13121312 },
13131313 .slice_end => {
1314 const pl_node = data[inst_index].pl_node;
1314 const pl_node = data[@intFromEnum(inst)].pl_node;
13151315 const extra = file.zir.extraData(Zir.Inst.SliceEnd, pl_node.payload_index);
13161316
13171317 const slice_index = self.exprs.items.len;
......@@ -1361,7 +1361,7 @@ fn walkInstruction(
13611361 };
13621362 },
13631363 .slice_sentinel => {
1364 const pl_node = data[inst_index].pl_node;
1364 const pl_node = data[@intFromEnum(inst)].pl_node;
13651365 const extra = file.zir.extraData(Zir.Inst.SliceSentinel, pl_node.payload_index);
13661366
13671367 const slice_index = self.exprs.items.len;
......@@ -1426,7 +1426,7 @@ fn walkInstruction(
14261426 };
14271427 },
14281428 .slice_length => {
1429 const pl_node = data[inst_index].pl_node;
1429 const pl_node = data[@intFromEnum(inst)].pl_node;
14301430 const extra = file.zir.extraData(Zir.Inst.SliceLength, pl_node.payload_index);
14311431
14321432 const slice_index = self.exprs.items.len;
......@@ -1498,7 +1498,7 @@ fn walkInstruction(
14981498 },
14991499
15001500 .load => {
1501 const un_node = data[inst_index].un_node;
1501 const un_node = data[@intFromEnum(inst)].un_node;
15021502 const operand = try self.walkRef(
15031503 file,
15041504 parent_scope,
......@@ -1529,7 +1529,7 @@ fn walkInstruction(
15291529 };
15301530 },
15311531 .ref => {
1532 const un_tok = data[inst_index].un_tok;
1532 const un_tok = data[@intFromEnum(inst)].un_tok;
15331533 const operand = try self.walkRef(
15341534 file,
15351535 parent_scope,
......@@ -1565,7 +1565,7 @@ fn walkInstruction(
15651565 .array_cat,
15661566 .array_mul,
15671567 => {
1568 const pl_node = data[inst_index].pl_node;
1568 const pl_node = data[@intFromEnum(inst)].pl_node;
15691569 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
15701570
15711571 const binop_index = self.exprs.items.len;
......@@ -1593,7 +1593,7 @@ fn walkInstruction(
15931593 const rhs_index = self.exprs.items.len;
15941594 try self.exprs.append(self.arena, rhs.expr);
15951595 self.exprs.items[binop_index] = .{ .binOp = .{
1596 .name = @tagName(tags[inst_index]),
1596 .name = @tagName(tags[@intFromEnum(inst)]),
15971597 .lhs = lhs_index,
15981598 .rhs = rhs_index,
15991599 } };
......@@ -1611,7 +1611,7 @@ fn walkInstruction(
16111611 .cmp_lt,
16121612 .cmp_lte,
16131613 => {
1614 const pl_node = data[inst_index].pl_node;
1614 const pl_node = data[@intFromEnum(inst)].pl_node;
16151615 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
16161616
16171617 const binop_index = self.exprs.items.len;
......@@ -1639,7 +1639,7 @@ fn walkInstruction(
16391639 const rhs_index = self.exprs.items.len;
16401640 try self.exprs.append(self.arena, rhs.expr);
16411641 self.exprs.items[binop_index] = .{ .binOp = .{
1642 .name = @tagName(tags[inst_index]),
1642 .name = @tagName(tags[@intFromEnum(inst)]),
16431643 .lhs = lhs_index,
16441644 .rhs = rhs_index,
16451645 } };
......@@ -1684,7 +1684,7 @@ fn walkInstruction(
16841684 .byte_swap,
16851685 .bit_reverse,
16861686 => {
1687 const un_node = data[inst_index].un_node;
1687 const un_node = data[@intFromEnum(inst)].un_node;
16881688 const bin_index = self.exprs.items.len;
16891689 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
16901690 const param = try self.walkRef(
......@@ -1701,7 +1701,7 @@ fn walkInstruction(
17011701
17021702 self.exprs.items[bin_index] = .{
17031703 .builtin = .{
1704 .name = @tagName(tags[inst_index]),
1704 .name = @tagName(tags[@intFromEnum(inst)]),
17051705 .param = param_index,
17061706 },
17071707 };
......@@ -1715,7 +1715,7 @@ fn walkInstruction(
17151715 .bool_not,
17161716 .negate_wrap,
17171717 => {
1718 const un_node = data[inst_index].un_node;
1718 const un_node = data[@intFromEnum(inst)].un_node;
17191719 const un_index = self.exprs.items.len;
17201720 try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } });
17211721 const param = try self.walkRef(
......@@ -1732,7 +1732,7 @@ fn walkInstruction(
17321732
17331733 self.exprs.items[un_index] = .{
17341734 .unOp = .{
1735 .name = @tagName(tags[inst_index]),
1735 .name = @tagName(tags[@intFromEnum(inst)]),
17361736 .param = param_index,
17371737 },
17381738 };
......@@ -1743,7 +1743,7 @@ fn walkInstruction(
17431743 };
17441744 },
17451745 .bool_br_and, .bool_br_or => {
1746 const bool_br = data[inst_index].bool_br;
1746 const bool_br = data[@intFromEnum(inst)].bool_br;
17471747
17481748 const bin_index = self.exprs.items.len;
17491749 try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
......@@ -1764,14 +1764,14 @@ fn walkInstruction(
17641764 file,
17651765 parent_scope,
17661766 parent_src,
1767 file.zir.extra[extra.end..][extra.data.body_len - 1],
1767 @enumFromInt(file.zir.extra[extra.end..][extra.data.body_len - 1]),
17681768 false,
17691769 call_ctx,
17701770 );
17711771 const rhs_index = self.exprs.items.len;
17721772 try self.exprs.append(self.arena, rhs.expr);
17731773
1774 self.exprs.items[bin_index] = .{ .binOp = .{ .name = @tagName(tags[inst_index]), .lhs = lhs_index, .rhs = rhs_index } };
1774 self.exprs.items[bin_index] = .{ .binOp = .{ .name = @tagName(tags[@intFromEnum(inst)]), .lhs = lhs_index, .rhs = rhs_index } };
17751775
17761776 return DocData.WalkResult{
17771777 .typeRef = .{ .type = @intFromEnum(Ref.bool_type) },
......@@ -1780,7 +1780,7 @@ fn walkInstruction(
17801780 },
17811781 .truncate => {
17821782 // in the ZIR this node is a builtin `bin` but we want send it as a `un` builtin
1783 const pl_node = data[inst_index].pl_node;
1783 const pl_node = data[@intFromEnum(inst)].pl_node;
17841784 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
17851785
17861786 var rhs: DocData.WalkResult = try self.walkRef(
......@@ -1807,7 +1807,7 @@ fn walkInstruction(
18071807 call_ctx,
18081808 );
18091809
1810 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };
1810 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[@intFromEnum(inst)]), .param = rhs_index } };
18111811
18121812 return DocData.WalkResult{
18131813 .typeRef = lhs.expr,
......@@ -1841,7 +1841,7 @@ fn walkInstruction(
18411841 .min,
18421842 .max,
18431843 => {
1844 const pl_node = data[inst_index].pl_node;
1844 const pl_node = data[@intFromEnum(inst)].pl_node;
18451845 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
18461846
18471847 const binop_index = self.exprs.items.len;
......@@ -1868,7 +1868,7 @@ fn walkInstruction(
18681868 try self.exprs.append(self.arena, lhs.expr);
18691869 const rhs_index = self.exprs.items.len;
18701870 try self.exprs.append(self.arena, rhs.expr);
1871 self.exprs.items[binop_index] = .{ .builtinBin = .{ .name = @tagName(tags[inst_index]), .lhs = lhs_index, .rhs = rhs_index } };
1871 self.exprs.items[binop_index] = .{ .builtinBin = .{ .name = @tagName(tags[@intFromEnum(inst)]), .lhs = lhs_index, .rhs = rhs_index } };
18721872
18731873 return DocData.WalkResult{
18741874 .typeRef = .{ .type = @intFromEnum(Ref.type_type) },
......@@ -1876,7 +1876,7 @@ fn walkInstruction(
18761876 };
18771877 },
18781878 .mul_add => {
1879 const pl_node = data[inst_index].pl_node;
1879 const pl_node = data[@intFromEnum(inst)].pl_node;
18801880 const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index);
18811881
18821882 var mul1: DocData.WalkResult = try self.walkRef(
......@@ -1927,7 +1927,7 @@ fn walkInstruction(
19271927 };
19281928 },
19291929 .union_init => {
1930 const pl_node = data[inst_index].pl_node;
1930 const pl_node = data[@intFromEnum(inst)].pl_node;
19311931 const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index);
19321932
19331933 var union_type: DocData.WalkResult = try self.walkRef(
......@@ -1974,7 +1974,7 @@ fn walkInstruction(
19741974 };
19751975 },
19761976 .builtin_call => {
1977 const pl_node = data[inst_index].pl_node;
1977 const pl_node = data[@intFromEnum(inst)].pl_node;
19781978 const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index);
19791979
19801980 var modifier: DocData.WalkResult = try self.walkRef(
......@@ -2022,7 +2022,7 @@ fn walkInstruction(
20222022 };
20232023 },
20242024 .error_union_type => {
2025 const pl_node = data[inst_index].pl_node;
2025 const pl_node = data[@intFromEnum(inst)].pl_node;
20262026 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
20272027
20282028 var lhs: DocData.WalkResult = try self.walkRef(
......@@ -2054,7 +2054,7 @@ fn walkInstruction(
20542054 };
20552055 },
20562056 .merge_error_sets => {
2057 const pl_node = data[inst_index].pl_node;
2057 const pl_node = data[@intFromEnum(inst)].pl_node;
20582058 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
20592059
20602060 var lhs: DocData.WalkResult = try self.walkRef(
......@@ -2085,7 +2085,7 @@ fn walkInstruction(
20852085 };
20862086 },
20872087 // .elem_type => {
2088 // const un_node = data[inst_index].un_node;
2088 // const un_node = data[@intFromEnum(inst)].un_node;
20892089
20902090 // var operand: DocData.WalkResult = try self.walkRef(
20912091 // file,
......@@ -2097,7 +2097,7 @@ fn walkInstruction(
20972097 // return operand;
20982098 // },
20992099 .ptr_type => {
2100 const ptr = data[inst_index].ptr_type;
2100 const ptr = data[@intFromEnum(inst)].ptr_type;
21012101 const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index);
21022102 var extra_index = extra.end;
21032103
......@@ -2208,7 +2208,7 @@ fn walkInstruction(
22082208 };
22092209 },
22102210 .array_type => {
2211 const pl_node = data[inst_index].pl_node;
2211 const pl_node = data[@intFromEnum(inst)].pl_node;
22122212
22132213 const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
22142214 const len = try self.walkRef(
......@@ -2242,7 +2242,7 @@ fn walkInstruction(
22422242 };
22432243 },
22442244 .array_type_sentinel => {
2245 const pl_node = data[inst_index].pl_node;
2245 const pl_node = data[@intFromEnum(inst)].pl_node;
22462246 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
22472247 const len = try self.walkRef(
22482248 file,
......@@ -2283,7 +2283,7 @@ fn walkInstruction(
22832283 };
22842284 },
22852285 .array_init => {
2286 const pl_node = data[inst_index].pl_node;
2286 const pl_node = data[@intFromEnum(inst)].pl_node;
22872287 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
22882288 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
22892289 const array_data = try self.arena.alloc(usize, operands.len - 1);
......@@ -2318,7 +2318,7 @@ fn walkInstruction(
23182318 };
23192319 },
23202320 .array_init_anon => {
2321 const pl_node = data[inst_index].pl_node;
2321 const pl_node = data[@intFromEnum(inst)].pl_node;
23222322 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
23232323 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
23242324 const array_data = try self.arena.alloc(usize, operands.len);
......@@ -2343,7 +2343,7 @@ fn walkInstruction(
23432343 };
23442344 },
23452345 .array_init_ref => {
2346 const pl_node = data[inst_index].pl_node;
2346 const pl_node = data[@intFromEnum(inst)].pl_node;
23472347 const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index);
23482348 const operands = file.zir.refSlice(extra.end, extra.data.operands_len);
23492349 const array_data = try self.arena.alloc(usize, operands.len - 1);
......@@ -2389,7 +2389,7 @@ fn walkInstruction(
23892389 };
23902390 },
23912391 .float => {
2392 const float = data[inst_index].float;
2392 const float = data[@intFromEnum(inst)].float;
23932393 return DocData.WalkResult{
23942394 .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) },
23952395 .expr = .{ .float = float },
......@@ -2397,7 +2397,7 @@ fn walkInstruction(
23972397 },
23982398 // @check: In frontend I'm handling float128 with `.toFixed(2)`
23992399 .float128 => {
2400 const pl_node = data[inst_index].pl_node;
2400 const pl_node = data[@intFromEnum(inst)].pl_node;
24012401 const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index);
24022402 return DocData.WalkResult{
24032403 .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) },
......@@ -2405,7 +2405,7 @@ fn walkInstruction(
24052405 };
24062406 },
24072407 .negate => {
2408 const un_node = data[inst_index].un_node;
2408 const un_node = data[@intFromEnum(inst)].un_node;
24092409
24102410 var operand: DocData.WalkResult = try self.walkRef(
24112411 file,
......@@ -2425,7 +2425,7 @@ fn walkInstruction(
24252425 try self.exprs.append(self.arena, operand.expr);
24262426 self.exprs.items[un_index] = .{
24272427 .unOp = .{
2428 .name = @tagName(tags[inst_index]),
2428 .name = @tagName(tags[@intFromEnum(inst)]),
24292429 .param = param_index,
24302430 },
24312431 };
......@@ -2438,7 +2438,7 @@ fn walkInstruction(
24382438 return operand;
24392439 },
24402440 .size_of => {
2441 const un_node = data[inst_index].un_node;
2441 const un_node = data[@intFromEnum(inst)].un_node;
24422442
24432443 const operand = try self.walkRef(
24442444 file,
......@@ -2457,7 +2457,7 @@ fn walkInstruction(
24572457 },
24582458 .bit_size_of => {
24592459 // not working correctly with `align()`
2460 const un_node = data[inst_index].un_node;
2460 const un_node = data[@intFromEnum(inst)].un_node;
24612461
24622462 const operand = try self.walkRef(
24632463 file,
......@@ -2477,7 +2477,7 @@ fn walkInstruction(
24772477 },
24782478 .int_from_enum => {
24792479 // not working correctly with `align()`
2480 const un_node = data[inst_index].un_node;
2480 const un_node = data[@intFromEnum(inst)].un_node;
24812481 const operand = try self.walkRef(
24822482 file,
24832483 parent_scope,
......@@ -2492,7 +2492,7 @@ fn walkInstruction(
24922492 try self.exprs.append(self.arena, operand.expr);
24932493 self.exprs.items[builtin_index] = .{
24942494 .builtin = .{
2495 .name = @tagName(tags[inst_index]),
2495 .name = @tagName(tags[@intFromEnum(inst)]),
24962496 .param = operand_index,
24972497 },
24982498 };
......@@ -2504,7 +2504,7 @@ fn walkInstruction(
25042504 },
25052505 .switch_block => {
25062506 // WIP
2507 const pl_node = data[inst_index].pl_node;
2507 const pl_node = data[@intFromEnum(inst)].pl_node;
25082508 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);
25092509
25102510 const switch_cond = try self.walkRef(
......@@ -2553,7 +2553,7 @@ fn walkInstruction(
25532553 },
25542554
25552555 .typeof => {
2556 const un_node = data[inst_index].un_node;
2556 const un_node = data[@intFromEnum(inst)].un_node;
25572557
25582558 const operand = try self.walkRef(
25592559 file,
......@@ -2572,7 +2572,7 @@ fn walkInstruction(
25722572 };
25732573 },
25742574 .typeof_builtin => {
2575 const pl_node = data[inst_index].pl_node;
2575 const pl_node = data[@intFromEnum(inst)].pl_node;
25762576 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
25772577 const body = file.zir.extra[extra.end..][extra.data.body_len - 1];
25782578 var operand: DocData.WalkResult = try self.walkRef(
......@@ -2593,11 +2593,11 @@ fn walkInstruction(
25932593 };
25942594 },
25952595 .as_node, .as_shift_operand => {
2596 const pl_node = data[inst_index].pl_node;
2596 const pl_node = data[@intFromEnum(inst)].pl_node;
25972597 const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);
25982598
25992599 // Skip the as_node if the destination type is a call instruction
2600 if (Zir.refToIndex(extra.data.dest_type)) |dti| {
2600 if (extra.data.dest_type.toIndex()) |dti| {
26012601 var maybe_cc = call_ctx;
26022602 while (maybe_cc) |cc| : (maybe_cc = cc.prev) {
26032603 if (cc.inst == dti) {
......@@ -2650,7 +2650,7 @@ fn walkInstruction(
26502650 };
26512651 },
26522652 .optional_type => {
2653 const un_node = data[inst_index].un_node;
2653 const un_node = data[@intFromEnum(inst)].un_node;
26542654
26552655 const operand: DocData.WalkResult = try self.walkRef(
26562656 file,
......@@ -2672,14 +2672,14 @@ fn walkInstruction(
26722672 };
26732673 },
26742674 .decl_val, .decl_ref => {
2675 const str_tok = data[inst_index].str_tok;
2676 const decl_status = parent_scope.resolveDeclName(str_tok.start, file, inst_index);
2675 const str_tok = data[@intFromEnum(inst)].str_tok;
2676 const decl_status = parent_scope.resolveDeclName(str_tok.start, file, inst.toOptional());
26772677 return DocData.WalkResult{
26782678 .expr = .{ .declRef = decl_status },
26792679 };
26802680 },
26812681 .field_val, .field_ptr => {
2682 const pl_node = data[inst_index].pl_node;
2682 const pl_node = data[@intFromEnum(inst)].pl_node;
26832683 const extra = file.zir.extraData(Zir.Inst.Field, pl_node.payload_index);
26842684
26852685 var path: std.ArrayListUnmanaged(DocData.Expr) = .{};
......@@ -2692,12 +2692,15 @@ fn walkInstruction(
26922692 const lhs_ref = blk: {
26932693 var lhs_extra = extra;
26942694 while (true) {
2695 const lhs = Zir.refToIndex(lhs_extra.data.lhs) orelse {
2695 const lhs = @intFromEnum(lhs_extra.data.lhs.toIndex() orelse {
26962696 break :blk lhs_extra.data.lhs;
2697 };
2697 });
26982698
26992699 if (tags[lhs] != .field_val and
2700 tags[lhs] != .field_ptr) break :blk lhs_extra.data.lhs;
2700 tags[lhs] != .field_ptr)
2701 {
2702 break :blk lhs_extra.data.lhs;
2703 }
27012704
27022705 lhs_extra = file.zir.extraData(
27032706 Zir.Inst.Field,
......@@ -2721,15 +2724,16 @@ fn walkInstruction(
27212724 // TODO: double check that we really don't need type info here
27222725
27232726 const wr = blk: {
2724 if (Zir.refToIndex(lhs_ref)) |lhs_inst| {
2725 if (tags[lhs_inst] == .call or tags[lhs_inst] == .field_call) {
2727 if (lhs_ref.toIndex()) |lhs_inst| switch (tags[@intFromEnum(lhs_inst)]) {
2728 .call, .field_call => {
27262729 break :blk DocData.WalkResult{
27272730 .expr = .{
27282731 .comptimeExpr = 0,
27292732 },
27302733 };
2731 }
2732 }
2734 },
2735 else => {},
2736 };
27332737
27342738 break :blk try self.walkRef(
27352739 file,
......@@ -2758,11 +2762,11 @@ fn walkInstruction(
27582762 // - (2) Paths can sometimes never resolve fully. This means that
27592763 // any value that depends on that will have to become a
27602764 // comptimeExpr.
2761 try self.tryResolveRefPath(file, inst_index, path.items);
2765 try self.tryResolveRefPath(file, inst, path.items);
27622766 return DocData.WalkResult{ .expr = .{ .refPath = path.items } };
27632767 },
27642768 .int_type => {
2765 const int_type = data[inst_index].int_type;
2769 const int_type = data[@intFromEnum(inst)].int_type;
27662770 const sign = if (int_type.signedness == .unsigned) "u" else "i";
27672771 const bits = int_type.bit_count;
27682772 const name = try std.fmt.allocPrint(self.arena, "{s}{}", .{ sign, bits });
......@@ -2781,7 +2785,7 @@ fn walkInstruction(
27812785 .typeRef = .{ .type = @intFromEnum(Ref.type_type) },
27822786 .expr = .{ .comptimeExpr = self.comptime_exprs.items.len },
27832787 };
2784 const pl_node = data[inst_index].pl_node;
2788 const pl_node = data[@intFromEnum(inst)].pl_node;
27852789 const block_expr = try self.getBlockSource(file, parent_src, pl_node.src_node);
27862790 try self.comptime_exprs.append(self.arena, .{
27872791 .code = block_expr,
......@@ -2793,12 +2797,12 @@ fn walkInstruction(
27932797 file,
27942798 parent_scope,
27952799 parent_src,
2796 getBlockInlineBreak(file.zir, inst_index) orelse {
2800 getBlockInlineBreak(file.zir, inst) orelse {
27972801 const res = DocData.WalkResult{
27982802 .typeRef = .{ .type = @intFromEnum(Ref.type_type) },
27992803 .expr = .{ .comptimeExpr = self.comptime_exprs.items.len },
28002804 };
2801 const pl_node = data[inst_index].pl_node;
2805 const pl_node = data[@intFromEnum(inst)].pl_node;
28022806 const block_inline_expr = try self.getBlockSource(file, parent_src, pl_node.src_node);
28032807 try self.comptime_exprs.append(self.arena, .{
28042808 .code = block_inline_expr,
......@@ -2810,7 +2814,7 @@ fn walkInstruction(
28102814 );
28112815 },
28122816 .break_inline => {
2813 const @"break" = data[inst_index].@"break";
2817 const @"break" = data[@intFromEnum(inst)].@"break";
28142818 return try self.walkRef(
28152819 file,
28162820 parent_scope,
......@@ -2821,7 +2825,7 @@ fn walkInstruction(
28212825 );
28222826 },
28232827 .struct_init => {
2824 const pl_node = data[inst_index].pl_node;
2828 const pl_node = data[@intFromEnum(inst)].pl_node;
28252829 const extra = file.zir.extraData(Zir.Inst.StructInit, pl_node.payload_index);
28262830 const field_vals = try self.arena.alloc(
28272831 DocData.Expr.FieldVal,
......@@ -2835,7 +2839,7 @@ fn walkInstruction(
28352839 defer idx = init_extra.end;
28362840
28372841 const field_name = blk: {
2838 const field_inst_index = init_extra.data.field_type;
2842 const field_inst_index = @intFromEnum(init_extra.data.field_type);
28392843 if (tags[field_inst_index] != .struct_init_field_type) unreachable;
28402844 const field_pl_node = data[field_inst_index].pl_node;
28412845 const field_extra = file.zir.extraData(
......@@ -2881,7 +2885,7 @@ fn walkInstruction(
28812885 .struct_init_empty,
28822886 .struct_init_empty_result,
28832887 => {
2884 const un_node = data[inst_index].un_node;
2888 const un_node = data[@intFromEnum(inst)].un_node;
28852889
28862890 var operand: DocData.WalkResult = try self.walkRef(
28872891 file,
......@@ -2898,7 +2902,7 @@ fn walkInstruction(
28982902 };
28992903 },
29002904 .struct_init_empty_ref_result => {
2901 const un_node = data[inst_index].un_node;
2905 const un_node = data[@intFromEnum(inst)].un_node;
29022906
29032907 var operand: DocData.WalkResult = try self.walkRef(
29042908 file,
......@@ -2918,7 +2922,7 @@ fn walkInstruction(
29182922 };
29192923 },
29202924 .struct_init_anon => {
2921 const pl_node = data[inst_index].pl_node;
2925 const pl_node = data[@intFromEnum(inst)].pl_node;
29222926 const extra = file.zir.extraData(Zir.Inst.StructInitAnon, pl_node.payload_index);
29232927
29242928 const field_vals = try self.arena.alloc(
......@@ -2947,7 +2951,7 @@ fn walkInstruction(
29472951 };
29482952 },
29492953 .error_set_decl => {
2950 const pl_node = data[inst_index].pl_node;
2954 const pl_node = data[@intFromEnum(inst)].pl_node;
29512955 const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index);
29522956 const fields = try self.arena.alloc(
29532957 DocData.Type.Field,
......@@ -2986,7 +2990,7 @@ fn walkInstruction(
29862990 // This switch case handles the case where an expression depends
29872991 // on an anytype field. E.g.: `fn foo(bar: anytype) @TypeOf(bar)`.
29882992 // This means that we're looking at a generic expression.
2989 const str_tok = data[inst_index].str_tok;
2993 const str_tok = data[@intFromEnum(inst)].str_tok;
29902994 const name = str_tok.get(file.zir);
29912995 const cte_slot_index = self.comptime_exprs.items.len;
29922996 try self.comptime_exprs.append(self.arena, .{
......@@ -2996,7 +3000,7 @@ fn walkInstruction(
29963000 },
29973001 .param, .param_comptime => {
29983002 // See .param_anytype for more information.
2999 const pl_tok = data[inst_index].pl_tok;
3003 const pl_tok = data[@intFromEnum(inst)].pl_tok;
30003004 const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index);
30013005 const name = file.zir.nullTerminatedString(extra.data.name);
30023006
......@@ -3007,7 +3011,7 @@ fn walkInstruction(
30073011 return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } };
30083012 },
30093013 .call => {
3010 const pl_node = data[inst_index].pl_node;
3014 const pl_node = data[@intFromEnum(inst)].pl_node;
30113015 const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index);
30123016
30133017 const callee = try self.walkRef(
......@@ -3023,8 +3027,8 @@ fn walkInstruction(
30233027 var args = try self.arena.alloc(DocData.Expr, args_len);
30243028 const body = file.zir.extra[extra.end..];
30253029
3026 try self.repurposed_insts.put(self.arena, @intCast(inst_index), {});
3027 defer _ = self.repurposed_insts.remove(@intCast(inst_index));
3030 try self.repurposed_insts.put(self.arena, inst, {});
3031 defer _ = self.repurposed_insts.remove(inst);
30283032
30293033 var i: usize = 0;
30303034 while (i < args_len) : (i += 1) {
......@@ -3042,7 +3046,7 @@ fn walkInstruction(
30423046 ref,
30433047 false,
30443048 &.{
3045 .inst = inst_index,
3049 .inst = inst,
30463050 .prev = call_ctx,
30473051 },
30483052 );
......@@ -3068,7 +3072,7 @@ fn walkInstruction(
30683072 else => blk: {
30693073 printWithContext(
30703074 file,
3071 inst_index,
3075 inst,
30723076 "unexpected callee type in walkInstruction.call: `{s}`\n",
30733077 .{@tagName(self.types.items[func_type_idx])},
30743078 );
......@@ -3089,10 +3093,10 @@ fn walkInstruction(
30893093 file,
30903094 parent_scope,
30913095 parent_src,
3092 inst_index,
3096 inst,
30933097 self_ast_node_index,
30943098 type_slot_index,
3095 tags[inst_index] == .func_inferred,
3099 tags[@intFromEnum(inst)] == .func_inferred,
30963100 call_ctx,
30973101 );
30983102
......@@ -3106,7 +3110,7 @@ fn walkInstruction(
31063110 file,
31073111 parent_scope,
31083112 parent_src,
3109 inst_index,
3113 inst,
31103114 self_ast_node_index,
31113115 type_slot_index,
31123116 call_ctx,
......@@ -3115,7 +3119,7 @@ fn walkInstruction(
31153119 return result;
31163120 },
31173121 .optional_payload_safe, .optional_payload_unsafe => {
3118 const un_node = data[inst_index].un_node;
3122 const un_node = data[@intFromEnum(inst)].un_node;
31193123 const operand = try self.walkRef(
31203124 file,
31213125 parent_scope,
......@@ -3135,7 +3139,7 @@ fn walkInstruction(
31353139 switch (t) {
31363140 .Optional => |opt| typeRef = opt.child,
31373141 else => {
3138 printWithContext(file, inst_index, "Invalid type for optional_payload_*: {}\n", .{t});
3142 printWithContext(file, inst, "Invalid type for optional_payload_*: {}\n", .{t});
31393143 },
31403144 }
31413145 },
......@@ -3149,7 +3153,7 @@ fn walkInstruction(
31493153 };
31503154 },
31513155 .elem_val_node => {
3152 const pl_node = data[inst_index].pl_node;
3156 const pl_node = data[@intFromEnum(inst)].pl_node;
31533157 const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
31543158 const lhs = try self.walkRef(
31553159 file,
......@@ -3181,12 +3185,12 @@ fn walkInstruction(
31813185 };
31823186 },
31833187 .extended => {
3184 const extended = data[inst_index].extended;
3188 const extended = data[@intFromEnum(inst)].extended;
31853189 switch (extended.opcode) {
31863190 else => {
31873191 printWithContext(
31883192 file,
3189 inst_index,
3193 inst,
31903194 "TODO: implement `walkInstruction.extended` for {s}",
31913195 .{@tagName(extended.opcode)},
31923196 );
......@@ -3265,7 +3269,7 @@ fn walkInstruction(
32653269 extra_index = try self.analyzeAllDecls(
32663270 file,
32673271 &scope,
3268 inst_index,
3272 inst,
32693273 src_info,
32703274 &decl_indexes,
32713275 &priv_decl_indexes,
......@@ -3285,7 +3289,7 @@ fn walkInstruction(
32853289 for (paths.items) |resume_info| {
32863290 try self.tryResolveRefPath(
32873291 resume_info.file,
3288 inst_index,
3292 inst,
32893293 resume_info.ref_path,
32903294 );
32913295 }
......@@ -3393,7 +3397,7 @@ fn walkInstruction(
33933397 extra_index = try self.analyzeAllDecls(
33943398 file,
33953399 &scope,
3396 inst_index,
3400 inst,
33973401 src_info,
33983402 &decl_indexes,
33993403 &priv_decl_indexes,
......@@ -3452,7 +3456,7 @@ fn walkInstruction(
34523456 for (paths.items) |resume_info| {
34533457 try self.tryResolveRefPath(
34543458 resume_info.file,
3455 inst_index,
3459 inst,
34563460 resume_info.ref_path,
34573461 );
34583462 }
......@@ -3524,7 +3528,7 @@ fn walkInstruction(
35243528 extra_index = try self.analyzeAllDecls(
35253529 file,
35263530 &scope,
3527 inst_index,
3531 inst,
35283532 src_info,
35293533 &decl_indexes,
35303534 &priv_decl_indexes,
......@@ -3604,7 +3608,7 @@ fn walkInstruction(
36043608 for (paths.items) |resume_info| {
36053609 try self.tryResolveRefPath(
36063610 resume_info.file,
3607 inst_index,
3611 inst,
36083612 resume_info.ref_path,
36093613 );
36103614 }
......@@ -3668,9 +3672,9 @@ fn walkInstruction(
36683672 backing_int = backing_int_res.expr;
36693673 extra_index += 1; // backing_int_ref
36703674 } else {
3671 const backing_int_body = file.zir.extra[extra_index..][0..backing_int_body_len];
3675 const backing_int_body = file.zir.bodySlice(extra_index, backing_int_body_len);
36723676 const break_inst = backing_int_body[backing_int_body.len - 1];
3673 const operand = data[break_inst].@"break".operand;
3677 const operand = data[@intFromEnum(break_inst)].@"break".operand;
36743678 const backing_int_res = try self.walkRef(
36753679 file,
36763680 &scope,
......@@ -3695,7 +3699,7 @@ fn walkInstruction(
36953699 extra_index = try self.analyzeAllDecls(
36963700 file,
36973701 &scope,
3698 inst_index,
3702 inst,
36993703 src_info,
37003704 &decl_indexes,
37013705 &priv_decl_indexes,
......@@ -3739,7 +3743,7 @@ fn walkInstruction(
37393743 for (paths.items) |resume_info| {
37403744 try self.tryResolveRefPath(
37413745 resume_info.file,
3742 inst_index,
3746 inst,
37433747 resume_info.ref_path,
37443748 );
37453749 }
......@@ -3883,7 +3887,7 @@ fn walkInstruction(
38833887
38843888 const cmpxchg_index = self.exprs.items.len;
38853889 try self.exprs.append(self.arena, .{ .cmpxchg = .{
3886 .name = @tagName(tags[inst_index]),
3890 .name = @tagName(tags[@intFromEnum(inst)]),
38873891 .type = type_index,
38883892 .ptr = ptr_index,
38893893 .expected_value = expected_value_index,
......@@ -3912,14 +3916,14 @@ fn analyzeAllDecls(
39123916 self: *Autodoc,
39133917 file: *File,
39143918 scope: *Scope,
3915 parent_inst_index: usize,
3919 parent_inst: Zir.Inst.Index,
39163920 parent_src: SrcLocInfo,
39173921 decl_indexes: *std.ArrayListUnmanaged(usize),
39183922 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
39193923 call_ctx: ?*const CallContext,
39203924) AutodocErrors!usize {
39213925 const first_decl_indexes_slot = decl_indexes.items.len;
3922 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));
3926 const original_it = file.zir.declIterator(parent_inst);
39233927
39243928 // First loop to discover decl names
39253929 {
......@@ -4038,7 +4042,7 @@ fn analyzeDecl(
40384042 const decl_name_index = file.zir.extra[extra_index];
40394043
40404044 extra_index += 1;
4041 const value_index = file.zir.extra[extra_index];
4045 const value_index: Zir.Inst.Index = @enumFromInt(file.zir.extra[extra_index]);
40424046
40434047 extra_index += 1;
40444048 const doc_comment_index = file.zir.extra[extra_index];
......@@ -4066,7 +4070,7 @@ fn analyzeDecl(
40664070 _ = addrspace_inst;
40674071
40684072 // This is known to work because decl values are always block_inlines
4069 const value_pl_node = data[value_index].pl_node;
4073 const value_pl_node = data[@intFromEnum(value_index)].pl_node;
40704074 const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src);
40714075
40724076 const name: []const u8 = switch (decl_name_index) {
......@@ -4124,7 +4128,7 @@ fn analyzeDecl(
41244128 try priv_decl_indexes.append(self.arena, decls_slot_index);
41254129 }
41264130
4127 const decl_status_ptr = scope.resolveDeclName(decl_name_index, file, 0);
4131 const decl_status_ptr = scope.resolveDeclName(decl_name_index, file, .none);
41284132 std.debug.assert(decl_status_ptr.* == .Pending);
41294133 decl_status_ptr.* = .{ .Analyzed = decls_slot_index };
41304134
......@@ -4158,11 +4162,11 @@ fn analyzeUsingnamespaceDecl(
41584162 const data = file.zir.instructions.items(.data);
41594163
41604164 const is_pub = @as(u1, @truncate(d.flags)) != 0;
4161 const value_index = file.zir.extra[@intFromEnum(d.sub_index) + 6];
4165 const value_index: Zir.Inst.Index = @enumFromInt(file.zir.extra[@intFromEnum(d.sub_index) + 6]);
41624166 const doc_comment_index = file.zir.extra[@intFromEnum(d.sub_index) + 7];
41634167
41644168 // This is known to work because decl values are always block_inlines
4165 const value_pl_node = data[value_index].pl_node;
4169 const value_pl_node = data[@intFromEnum(value_index)].pl_node;
41664170 const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src);
41674171
41684172 const doc_comment: ?[]const u8 = if (doc_comment_index != 0)
......@@ -4244,7 +4248,7 @@ fn analyzeDecltest(
42444248 break :idx idx;
42454249 };
42464250
4247 const decl_status = scope.resolveDeclName(decl_name_index, file, 0);
4251 const decl_status = scope.resolveDeclName(decl_name_index, file, .none);
42484252
42494253 switch (decl_status.*) {
42504254 .Analyzed => |idx| {
......@@ -4277,7 +4281,7 @@ fn tryResolveRefPath(
42774281 self: *Autodoc,
42784282 /// File from which the decl path originates.
42794283 file: *File,
4280 inst_index: usize, // used only for panicWithContext
4284 inst: Zir.Inst.Index, // used only for panicWithContext
42814285 path: []DocData.Expr,
42824286) AutodocErrors!void {
42834287 var i: usize = 0;
......@@ -4374,7 +4378,7 @@ fn tryResolveRefPath(
43744378 } else {
43754379 panicWithContext(
43764380 file,
4377 inst_index,
4381 inst,
43784382 "exhausted eval quota for `{}`in tryResolveRefPath\n",
43794383 .{resolved_parent},
43804384 );
......@@ -4386,7 +4390,7 @@ fn tryResolveRefPath(
43864390 // in the switch above this one!
43874391 printWithContext(
43884392 file,
4389 inst_index,
4393 inst,
43904394 "TODO: handle `{s}`in tryResolveRefPath\nInfo: {}",
43914395 .{ @tagName(resolved_parent), resolved_parent },
43924396 );
......@@ -4403,7 +4407,7 @@ fn tryResolveRefPath(
44034407 else => {
44044408 panicWithContext(
44054409 file,
4406 inst_index,
4410 inst,
44074411 "TODO: handle `{s}` in tryResolveDeclPath.type\nInfo: {}",
44084412 .{ @tagName(self.types.items[t_index]), resolved_parent },
44094413 );
......@@ -4442,7 +4446,7 @@ fn tryResolveRefPath(
44424446 } else {
44434447 panicWithContext(
44444448 file,
4445 inst_index,
4449 inst,
44464450 "TODO: handle `{s}` in tryResolveDeclPath.type.Array\nInfo: {}",
44474451 .{ child_string, resolved_parent },
44484452 );
......@@ -4500,7 +4504,7 @@ fn tryResolveRefPath(
45004504 // if we got here, our search failed
45014505 printWithContext(
45024506 file,
4503 inst_index,
4507 inst,
45044508 "failed to match `{s}` in enum",
45054509 .{child_string},
45064510 );
......@@ -4557,7 +4561,7 @@ fn tryResolveRefPath(
45574561 // if we got here, our search failed
45584562 printWithContext(
45594563 file,
4560 inst_index,
4564 inst,
45614565 "failed to match `{s}` in union",
45624566 .{child_string},
45634567 );
......@@ -4614,7 +4618,7 @@ fn tryResolveRefPath(
46144618 // if we got here, our search failed
46154619 // printWithContext(
46164620 // file,
4617 // inst_index,
4621 // inst,
46184622 // "failed to match `{s}` in struct",
46194623 // .{child_string},
46204624 // );
......@@ -4659,7 +4663,7 @@ fn tryResolveRefPath(
46594663 // if we got here, our search failed
46604664 printWithContext(
46614665 file,
4662 inst_index,
4666 inst,
46634667 "failed to match `{s}` in opaque",
46644668 .{child_string},
46654669 );
......@@ -4679,7 +4683,7 @@ fn tryResolveRefPath(
46794683 // if we got here, our search failed
46804684 printWithContext(
46814685 file,
4682 inst_index,
4686 inst,
46834687 "failed to match `{s}` in struct",
46844688 .{child_string},
46854689 );
......@@ -4696,7 +4700,7 @@ fn tryResolveRefPath(
46964700 _ = self.pending_ref_paths.remove(&path[path.len - 1]);
46974701
46984702 for (waiter_list.items) |resume_info| {
4699 try self.tryResolveRefPath(resume_info.file, inst_index, resume_info.ref_path);
4703 try self.tryResolveRefPath(resume_info.file, inst, resume_info.ref_path);
47004704 }
47014705 // TODO: this is where we should free waiter_list, but its in the arena
47024706 // that said, we might want to store it elsewhere and reclaim memory asap
......@@ -4805,14 +4809,14 @@ fn analyzeFancyFunction(
48054809 file: *File,
48064810 scope: *Scope,
48074811 parent_src: SrcLocInfo,
4808 inst_index: usize,
4812 inst: Zir.Inst.Index,
48094813 self_ast_node_index: usize,
48104814 type_slot_index: usize,
48114815 call_ctx: ?*const CallContext,
48124816) AutodocErrors!DocData.WalkResult {
48134817 const tags = file.zir.instructions.items(.tag);
48144818 const data = file.zir.instructions.items(.data);
4815 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
4819 const fn_info = file.zir.getFnInfo(inst);
48164820
48174821 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
48184822 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
......@@ -4826,18 +4830,18 @@ fn analyzeFancyFunction(
48264830
48274831 // TODO: handle scope rules for fn parameters
48284832 for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| {
4829 switch (tags[param_index]) {
4833 switch (tags[@intFromEnum(param_index)]) {
48304834 else => {
48314835 panicWithContext(
48324836 file,
48334837 param_index,
48344838 "TODO: handle `{s}` in walkInstruction.func\n",
4835 .{@tagName(tags[param_index])},
4839 .{@tagName(tags[@intFromEnum(param_index)])},
48364840 );
48374841 },
48384842 .param_anytype, .param_anytype_comptime => {
48394843 // TODO: where are the doc comments?
4840 const str_tok = data[param_index].str_tok;
4844 const str_tok = data[@intFromEnum(param_index)].str_tok;
48414845
48424846 const name = str_tok.get(file.zir);
48434847
......@@ -4845,7 +4849,7 @@ fn analyzeFancyFunction(
48454849 self.ast_nodes.appendAssumeCapacity(.{
48464850 .name = name,
48474851 .docs = "",
4848 .@"comptime" = tags[param_index] == .param_anytype_comptime,
4852 .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime,
48494853 });
48504854
48514855 param_type_refs.appendAssumeCapacity(
......@@ -4853,7 +4857,7 @@ fn analyzeFancyFunction(
48534857 );
48544858 },
48554859 .param, .param_comptime => {
4856 const pl_tok = data[param_index].pl_tok;
4860 const pl_tok = data[@intFromEnum(param_index)].pl_tok;
48574861 const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index);
48584862 const doc_comment = if (extra.data.doc_comment != 0)
48594863 file.zir.nullTerminatedString(extra.data.doc_comment)
......@@ -4865,7 +4869,7 @@ fn analyzeFancyFunction(
48654869 try self.ast_nodes.append(self.arena, .{
48664870 .name = name,
48674871 .docs = doc_comment,
4868 .@"comptime" = tags[param_index] == .param_comptime,
4872 .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime,
48694873 });
48704874
48714875 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
......@@ -4886,7 +4890,7 @@ fn analyzeFancyFunction(
48864890
48874891 self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items;
48884892
4889 const pl_node = data[inst_index].pl_node;
4893 const pl_node = data[@intFromEnum(inst)].pl_node;
48904894 const extra = file.zir.extraData(Zir.Inst.FuncFancy, pl_node.payload_index);
48914895
48924896 var extra_index: usize = extra.end;
......@@ -4971,7 +4975,7 @@ fn analyzeFancyFunction(
49714975
49724976 var cc_index: ?usize = null;
49734977 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
4974 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4978 const cc_ref: Zir.Inst.Ref = @enumFromInt(file.zir.extra[extra_index]);
49754979 const cc_expr = try self.walkRef(
49764980 file,
49774981 scope,
......@@ -4988,11 +4992,11 @@ fn analyzeFancyFunction(
49884992 } else if (extra.data.bits.has_cc_body) {
49894993 const cc_body_len = file.zir.extra[extra_index];
49904994 extra_index += 1;
4991 const cc_body = file.zir.extra[extra_index..][0..cc_body_len];
4995 const cc_body = file.zir.bodySlice(extra_index, cc_body_len);
49924996
49934997 // We assume the body ends with a break_inline
49944998 const break_index = cc_body[cc_body.len - 1];
4995 const break_operand = data[break_index].@"break".operand;
4999 const break_operand = data[@intFromEnum(break_index)].@"break".operand;
49965000 const cc_expr = try self.walkRef(
49975001 file,
49985002 scope,
......@@ -5029,7 +5033,7 @@ fn analyzeFancyFunction(
50295033 },
50305034 else => blk: {
50315035 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
5032 const break_operand = data[last_instr_index].@"break".operand;
5036 const break_operand = data[@intFromEnum(last_instr_index)].@"break".operand;
50335037 const wr = try self.walkRef(
50345038 file,
50355039 scope,
......@@ -5096,7 +5100,7 @@ fn analyzeFunction(
50965100 file: *File,
50975101 scope: *Scope,
50985102 parent_src: SrcLocInfo,
5099 inst_index: usize,
5103 inst: Zir.Inst.Index,
51005104 self_ast_node_index: usize,
51015105 type_slot_index: usize,
51025106 ret_is_inferred_error_set: bool,
......@@ -5104,7 +5108,7 @@ fn analyzeFunction(
51045108) AutodocErrors!DocData.WalkResult {
51055109 const tags = file.zir.instructions.items(.tag);
51065110 const data = file.zir.instructions.items(.data);
5107 const fn_info = file.zir.getFnInfo(@as(u32, @intCast(inst_index)));
5111 const fn_info = file.zir.getFnInfo(inst);
51085112
51095113 try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len);
51105114 var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity(
......@@ -5118,18 +5122,18 @@ fn analyzeFunction(
51185122
51195123 // TODO: handle scope rules for fn parameters
51205124 for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| {
5121 switch (tags[param_index]) {
5125 switch (tags[@intFromEnum(param_index)]) {
51225126 else => {
51235127 panicWithContext(
51245128 file,
51255129 param_index,
51265130 "TODO: handle `{s}` in walkInstruction.func\n",
5127 .{@tagName(tags[param_index])},
5131 .{@tagName(tags[@intFromEnum(param_index)])},
51285132 );
51295133 },
51305134 .param_anytype, .param_anytype_comptime => {
51315135 // TODO: where are the doc comments?
5132 const str_tok = data[param_index].str_tok;
5136 const str_tok = data[@intFromEnum(param_index)].str_tok;
51335137
51345138 const name = str_tok.get(file.zir);
51355139
......@@ -5137,7 +5141,7 @@ fn analyzeFunction(
51375141 self.ast_nodes.appendAssumeCapacity(.{
51385142 .name = name,
51395143 .docs = "",
5140 .@"comptime" = tags[param_index] == .param_anytype_comptime,
5144 .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime,
51415145 });
51425146
51435147 param_type_refs.appendAssumeCapacity(
......@@ -5145,7 +5149,7 @@ fn analyzeFunction(
51455149 );
51465150 },
51475151 .param, .param_comptime => {
5148 const pl_tok = data[param_index].pl_tok;
5152 const pl_tok = data[@intFromEnum(param_index)].pl_tok;
51495153 const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index);
51505154 const doc_comment = if (extra.data.doc_comment != 0)
51515155 file.zir.nullTerminatedString(extra.data.doc_comment)
......@@ -5157,7 +5161,7 @@ fn analyzeFunction(
51575161 try self.ast_nodes.append(self.arena, .{
51585162 .name = name,
51595163 .docs = doc_comment,
5160 .@"comptime" = tags[param_index] == .param_comptime,
5164 .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime,
51615165 });
51625166
51635167 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
......@@ -5195,7 +5199,7 @@ fn analyzeFunction(
51955199 },
51965200 else => blk: {
51975201 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
5198 const break_operand = data[last_instr_index].@"break".operand;
5202 const break_operand = data[@intFromEnum(last_instr_index)].@"break".operand;
51995203 const wr = try self.walkRef(
52005204 file,
52015205 scope,
......@@ -5266,7 +5270,7 @@ fn getGenericReturnType(
52665270 file: *File,
52675271 scope: *Scope,
52685272 parent_src: SrcLocInfo, // function decl line
5269 body_main_block: usize,
5273 body_main_block: Zir.Inst.Index,
52705274 call_ctx: ?*const CallContext,
52715275) !DocData.Expr {
52725276 const tags = file.zir.instructions.items(.tag);
......@@ -5274,25 +5278,27 @@ fn getGenericReturnType(
52745278
52755279 // We expect `body_main_block` to be the first instruction
52765280 // inside the function body, and for it to be a block instruction.
5277 const pl_node = data[body_main_block].pl_node;
5281 const pl_node = data[@intFromEnum(body_main_block)].pl_node;
52785282 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
5279 const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];
5280 switch (tags[maybe_ret_node]) {
5281 .ret_node, .ret_load => {
5282 const wr = try self.walkInstruction(
5283 file,
5284 scope,
5285 parent_src,
5286 maybe_ret_node,
5287 false,
5288 call_ctx,
5289 );
5290 return wr.expr;
5291 },
5292 else => {
5293 return DocData.Expr{ .comptimeExpr = 0 };
5294 },
5283 const body = file.zir.bodySlice(extra.end, extra.data.body_len);
5284 if (body.len >= 4) {
5285 const maybe_ret_inst = body[body.len - 4];
5286 switch (tags[@intFromEnum(maybe_ret_inst)]) {
5287 .ret_node, .ret_load => {
5288 const wr = try self.walkInstruction(
5289 file,
5290 scope,
5291 parent_src,
5292 maybe_ret_inst,
5293 false,
5294 call_ctx,
5295 );
5296 return wr.expr;
5297 },
5298 else => {},
5299 }
52955300 }
5301 return DocData.Expr{ .comptimeExpr = 0 };
52965302}
52975303
52985304fn collectUnionFieldInfo(
......@@ -5470,11 +5476,11 @@ fn collectStructFieldInfo(
54705476 }
54715477
54725478 std.debug.assert(field.type_body_len != 0);
5473 const body = file.zir.extra[extra_index..][0..field.type_body_len];
5479 const body = file.zir.bodySlice(extra_index, field.type_body_len);
54745480 extra_index += body.len;
54755481
54765482 const break_inst = body[body.len - 1];
5477 const operand = data[break_inst].@"break".operand;
5483 const operand = data[@intFromEnum(break_inst)].@"break".operand;
54785484 try self.ast_nodes.append(self.arena, .{
54795485 .file = self.files.getIndex(file).?,
54805486 .line = parent_src.line,
......@@ -5499,11 +5505,11 @@ fn collectStructFieldInfo(
54995505 break :def null;
55005506 }
55015507
5502 const body = file.zir.extra[extra_index..][0..field.init_body_len];
5508 const body = file.zir.bodySlice(extra_index, field.init_body_len);
55035509 extra_index += body.len;
55045510
55055511 const break_inst = body[body.len - 1];
5506 const operand = data[break_inst].@"break".operand;
5512 const operand = data[@intFromEnum(break_inst)].@"break".operand;
55075513 const walk_result = try self.walkRef(
55085514 file,
55095515 scope,
......@@ -5559,7 +5565,7 @@ fn walkRef(
55595565 .typeRef = .{ .type = @intFromEnum(std.builtin.TypeId.Type) },
55605566 .expr = .{ .type = @intFromEnum(ref) },
55615567 };
5562 } else if (Zir.refToIndex(ref)) |zir_index| {
5568 } else if (ref.toIndex()) |zir_index| {
55635569 return self.walkInstruction(
55645570 file,
55655571 parent_scope,
......@@ -5571,9 +5577,9 @@ fn walkRef(
55715577 } else {
55725578 switch (ref) {
55735579 else => {
5574 panicWithContext(
5580 panicWithOptionalContext(
55755581 file,
5576 0,
5582 .none,
55775583 "TODO: handle {s} in walkRef",
55785584 .{@tagName(ref)},
55795585 );
......@@ -5664,10 +5670,10 @@ fn walkRef(
56645670 }
56655671}
56665672
5667fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref {
5673fn getBlockInlineBreak(zir: Zir, inst: Zir.Inst.Index) ?Zir.Inst.Ref {
56685674 const tags = zir.instructions.items(.tag);
56695675 const data = zir.instructions.items(.data);
5670 const pl_node = data[inst_index].pl_node;
5676 const pl_node = data[@intFromEnum(inst)].pl_node;
56715677 const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index);
56725678 const break_index = zir.extra[extra.end..][extra.data.body_len - 1];
56735679 if (tags[break_index] == .condbr_inline) return null;
......@@ -5675,12 +5681,36 @@ fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref {
56755681 return data[break_index].@"break".operand;
56765682}
56775683
5678fn printWithContext(file: *File, inst: usize, comptime fmt: []const u8, args: anytype) void {
5684fn printWithContext(
5685 file: *File,
5686 inst: Zir.Inst.Index,
5687 comptime fmt: []const u8,
5688 args: anytype,
5689) void {
5690 return printWithOptionalContext(file, inst.toOptional(), fmt, args);
5691}
5692
5693fn printWithOptionalContext(file: *File, inst: Zir.Inst.OptionalIndex, comptime fmt: []const u8, args: anytype) void {
56795694 log.debug("Context [{s}] % {} \n " ++ fmt, .{ file.sub_file_path, inst } ++ args);
56805695}
56815696
5682fn panicWithContext(file: *File, inst: usize, comptime fmt: []const u8, args: anytype) noreturn {
5683 printWithContext(file, inst, fmt, args);
5697fn panicWithContext(
5698 file: *File,
5699 inst: Zir.Inst.Index,
5700 comptime fmt: []const u8,
5701 args: anytype,
5702) noreturn {
5703 printWithOptionalContext(file, inst.toOptional(), fmt, args);
5704 unreachable;
5705}
5706
5707fn panicWithOptionalContext(
5708 file: *File,
5709 inst: Zir.Inst.OptionalIndex,
5710 comptime fmt: []const u8,
5711 args: anytype,
5712) noreturn {
5713 printWithOptionalContext(file, inst, fmt, args);
56845714 unreachable;
56855715}
56865716
src/InternPool.zig+14-5
......@@ -580,7 +580,7 @@ pub const Key = union(enum) {
580580 pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: Zir.Inst.Index) void {
581581 assert(s.layout != .Packed);
582582 const field_index = std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?;
583 ip.extra.items[s.extra_index + field_index] = new_zir_index;
583 ip.extra.items[s.extra_index + field_index] = @intFromEnum(new_zir_index);
584584 }
585585
586586 pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool {
......@@ -2481,7 +2481,14 @@ pub const static_keys = [_]Key{
24812481};
24822482
24832483/// How many items in the InternPool are statically known.
2484pub const static_len: u32 = static_keys.len;
2484/// This is specified with an integer literal and a corresponding comptime
2485/// assert below to break an unfortunate and arguably incorrect dependency loop
2486/// when compiling.
2487pub const static_len = 84;
2488comptime {
2489 //@compileLog(static_keys.len);
2490 assert(static_len == static_keys.len);
2491}
24852492
24862493pub const Tag = enum(u8) {
24872494 /// An integer type.
......@@ -3658,7 +3665,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
36583665 .extra_index = 0,
36593666 .namespace = .none,
36603667 .decl = .none,
3661 .zir_index = @as(u32, undefined),
3668 .zir_index = undefined,
36623669 .layout = .Auto,
36633670 .field_names = .{ .start = 0, .len = 0 },
36643671 .field_types = .{ .start = 0, .len = 0 },
......@@ -3674,7 +3681,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
36743681 .extra_index = 0,
36753682 .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(),
36763683 .decl = .none,
3677 .zir_index = @as(u32, undefined),
3684 .zir_index = undefined,
36783685 .layout = .Auto,
36793686 .field_names = .{ .start = 0, .len = 0 },
36803687 .field_types = .{ .start = 0, .len = 0 },
......@@ -6403,6 +6410,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
64036410 NullTerminatedString,
64046411 OptionalNullTerminatedString,
64056412 Tag.TypePointer.VectorIndex,
6413 Zir.Inst.Index,
64066414 => @intFromEnum(@field(extra, field.name)),
64076415
64086416 u32,
......@@ -6477,6 +6485,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct
64776485 NullTerminatedString,
64786486 OptionalNullTerminatedString,
64796487 Tag.TypePointer.VectorIndex,
6488 Zir.Inst.Index,
64806489 => @enumFromInt(int32),
64816490
64826491 u32,
......@@ -8191,7 +8200,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index {
81918200 },
81928201 else => unreachable,
81938202 };
8194 return ip.extra.items[extra_index];
8203 return @enumFromInt(ip.extra.items[extra_index]);
81958204}
81968205
81978206pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
src/Module.zig+13-14
......@@ -389,7 +389,7 @@ pub const Decl = struct {
389389 /// Index to ZIR `extra` array to the entry in the parent's decl structure
390390 /// (the part that says "for every decls_len"). The first item at this index is
391391 /// the contents hash, followed by line, name, etc.
392 /// For anonymous decls and also the root Decl for a File, this is 0.
392 /// For anonymous decls and also the root Decl for a File, this is `none`.
393393 zir_decl_index: Zir.OptionalExtraIndex,
394394
395395 /// Represents the "shallow" analysis status. For example, for decls that are functions,
......@@ -547,7 +547,7 @@ pub const Decl = struct {
547547 pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index {
548548 assert(decl.zir_decl_index != .none);
549549 const zir = decl.getFileScope(mod).zir;
550 return zir.extra[@intFromEnum(decl.zir_decl_index) + 6];
550 return @enumFromInt(zir.extra[@intFromEnum(decl.zir_decl_index) + 6]);
551551 }
552552
553553 pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref {
......@@ -1205,9 +1205,8 @@ pub const File = struct {
12051205 if (imports_index == 0) return;
12061206 const extra = file.zir.extraData(Zir.Inst.Imports, imports_index);
12071207
1208 var import_i: u32 = 0;
12091208 var extra_index = extra.end;
1210 while (import_i < extra.data.imports_len) : (import_i += 1) {
1209 for (0..extra.data.imports_len) |_| {
12111210 const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
12121211 extra_index = item.end;
12131212
......@@ -3206,8 +3205,8 @@ pub fn mapOldZirToNew(
32063205
32073206 // Main struct inst is always the same
32083207 try match_stack.append(gpa, .{
3209 .old_inst = Zir.main_struct_inst,
3210 .new_inst = Zir.main_struct_inst,
3208 .old_inst = .main_struct_inst,
3209 .new_inst = .main_struct_inst,
32113210 });
32123211
32133212 var old_decls = std.ArrayList(Zir.Inst.Index).init(gpa);
......@@ -3622,11 +3621,10 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
36223621 };
36233622 defer sema.deinit();
36243623
3625 const main_struct_inst = Zir.main_struct_inst;
36263624 const struct_ty = sema.getStructType(
36273625 new_decl_index,
36283626 new_namespace_index,
3629 main_struct_inst,
3627 .main_struct_inst,
36303628 ) catch |err| switch (err) {
36313629 error.OutOfMemory => return error.OutOfMemory,
36323630 };
......@@ -3754,11 +3752,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
37543752 defer block_scope.instructions.deinit(gpa);
37553753
37563754 const zir_block_index = decl.zirBlockIndex(mod);
3757 const inst_data = zir_datas[zir_block_index].pl_node;
3755 const inst_data = zir_datas[@intFromEnum(zir_block_index)].pl_node;
37583756 const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index);
37593757 const body = zir.extra[extra.end..][0..extra.data.body_len];
3760 const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;
3761 // We'll do some other bits with the Sema. Clear the type target index just in case they analyze any type.
3758 const result_ref = (try sema.analyzeBodyBreak(&block_scope, @ptrCast(body))).?.operand;
3759 // We'll do some other bits with the Sema. Clear the type target index just
3760 // in case they analyze any type.
37623761 sema.builtin_type_target_index = .none;
37633762 for (comptime_mutable_decls.items) |ct_decl_index| {
37643763 const ct_decl = mod.declPtr(ct_decl_index);
......@@ -6471,13 +6470,13 @@ pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0]
64716470 const param_body = file.zir.getParamBody(func.zir_body_inst);
64726471 const param = param_body[index];
64736472
6474 return switch (tags[param]) {
6473 return switch (tags[@intFromEnum(param)]) {
64756474 .param, .param_comptime => blk: {
6476 const extra = file.zir.extraData(Zir.Inst.Param, data[param].pl_tok.payload_index);
6475 const extra = file.zir.extraData(Zir.Inst.Param, data[@intFromEnum(param)].pl_tok.payload_index);
64776476 break :blk file.zir.nullTerminatedString(extra.data.name);
64786477 },
64796478 .param_anytype, .param_anytype_comptime => blk: {
6480 const param_data = data[param].str_tok;
6479 const param_data = data[@intFromEnum(param)].str_tok;
64816480 break :blk param_data.get(file.zir);
64826481 },
64836482 else => unreachable,
src/Sema.zig+370-362
......@@ -226,7 +226,7 @@ pub const InferredErrorSet = struct {
226226/// be called safely for any of the instructions passed in.
227227pub const InstMap = struct {
228228 items: []Air.Inst.Ref = &[_]Air.Inst.Ref{},
229 start: Zir.Inst.Index = 0,
229 start: Zir.Inst.Index = @enumFromInt(0),
230230
231231 pub fn deinit(map: InstMap, allocator: mem.Allocator) void {
232232 allocator.free(map.items);
......@@ -234,7 +234,7 @@ pub const InstMap = struct {
234234
235235 pub fn get(map: InstMap, key: Zir.Inst.Index) ?Air.Inst.Ref {
236236 if (!map.contains(key)) return null;
237 return map.items[key - map.start];
237 return map.items[@intFromEnum(key) - @intFromEnum(map.start)];
238238 }
239239
240240 pub fn putAssumeCapacity(
......@@ -242,7 +242,7 @@ pub const InstMap = struct {
242242 key: Zir.Inst.Index,
243243 ref: Air.Inst.Ref,
244244 ) void {
245 map.items[key - map.start] = ref;
245 map.items[@intFromEnum(key) - @intFromEnum(map.start)] = ref;
246246 }
247247
248248 pub fn putAssumeCapacityNoClobber(
......@@ -263,7 +263,7 @@ pub const InstMap = struct {
263263 map: *InstMap,
264264 key: Zir.Inst.Index,
265265 ) GetOrPutResult {
266 const index = key - map.start;
266 const index = @intFromEnum(key) - @intFromEnum(map.start);
267267 return GetOrPutResult{
268268 .value_ptr = &map.items[index],
269269 .found_existing = map.items[index] != .none,
......@@ -272,12 +272,12 @@ pub const InstMap = struct {
272272
273273 pub fn remove(map: InstMap, key: Zir.Inst.Index) bool {
274274 if (!map.contains(key)) return false;
275 map.items[key - map.start] = .none;
275 map.items[@intFromEnum(key) - @intFromEnum(map.start)] = .none;
276276 return true;
277277 }
278278
279279 pub fn contains(map: InstMap, key: Zir.Inst.Index) bool {
280 return map.items[key - map.start] != .none;
280 return map.items[@intFromEnum(key) - @intFromEnum(map.start)] != .none;
281281 }
282282
283283 pub fn ensureSpaceForInstructions(
......@@ -285,13 +285,12 @@ pub const InstMap = struct {
285285 allocator: mem.Allocator,
286286 insts: []const Zir.Inst.Index,
287287 ) !void {
288 const min_max = mem.minMax(Zir.Inst.Index, insts);
289 const start = min_max.min;
290 const end = min_max.max;
291 if (map.start <= start and end < map.items.len + map.start)
288 const start, const end = mem.minMax(u32, @ptrCast(insts));
289 const map_start = @intFromEnum(map.start);
290 if (map_start <= start and end < map.items.len + map_start)
292291 return;
293292
294 const old_start = if (map.items.len == 0) start else map.start;
293 const old_start = if (map.items.len == 0) start else map_start;
295294 var better_capacity = map.items.len;
296295 var better_start = old_start;
297296 while (true) {
......@@ -310,7 +309,7 @@ pub const InstMap = struct {
310309
311310 allocator.free(map.items);
312311 map.items = new_items;
313 map.start = @intCast(better_start);
312 map.start = @enumFromInt(better_start);
314313 }
315314};
316315
......@@ -350,7 +349,7 @@ pub const Block = struct {
350349 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
351350 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
352351 runtime_index: Value.RuntimeIndex = .zero,
353 inline_block: Zir.Inst.Index = 0,
352 inline_block: Zir.Inst.OptionalIndex = .none,
354353
355354 comptime_reason: ?*const ComptimeReason = null,
356355 // TODO is_comptime and comptime_reason should probably be merged together.
......@@ -897,7 +896,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In
897896 _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
898897 error.ComptimeBreak => {
899898 const zir_datas = sema.code.instructions.items(.data);
900 const break_data = zir_datas[sema.comptime_break_inst].@"break";
899 const break_data = zir_datas[@intFromEnum(sema.comptime_break_inst)].@"break";
901900 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;
902901 try sema.addRuntimeBreak(block, .{
903902 .block_inst = extra.block_inst,
......@@ -938,7 +937,7 @@ pub fn analyzeBodyBreak(
938937 if (block.instructions.items.len != 0 and
939938 sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1])))
940939 return null;
941 const break_data = sema.code.instructions.items(.data)[break_inst].@"break";
940 const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break";
942941 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;
943942 return BreakData{
944943 .block_inst = extra.block_inst,
......@@ -998,7 +997,7 @@ fn analyzeBodyInner(
998997 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{
999998 mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst,
1000999 });
1001 const air_inst: Air.Inst.Ref = switch (tags[inst]) {
1000 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
10021001 // zig fmt: off
10031002 .alloc => try sema.zirAlloc(block, inst),
10041003 .alloc_inferred => try sema.zirAllocInferred(block, inst, true),
......@@ -1220,7 +1219,7 @@ fn analyzeBodyInner(
12201219 // zig fmt: on
12211220
12221221 .extended => ext: {
1223 const extended = datas[inst].extended;
1222 const extended = datas[@intFromEnum(inst)].extended;
12241223 break :ext switch (extended.opcode) {
12251224 // zig fmt: off
12261225 .variable => try sema.zirVarExtended( block, extended),
......@@ -1477,13 +1476,13 @@ fn analyzeBodyInner(
14771476 },
14781477 .check_comptime_control_flow => {
14791478 if (!block.is_comptime) {
1480 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1479 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
14811480 const src = inst_data.src();
1482 const inline_block = Zir.refToIndex(inst_data.operand).?;
1481 const inline_block = inst_data.operand.toIndex().?;
14831482
14841483 var check_block = block;
14851484 const target_runtime_index = while (true) {
1486 if (check_block.inline_block == inline_block) {
1485 if (check_block.inline_block == inline_block.toOptional()) {
14871486 break check_block.runtime_index;
14881487 }
14891488 check_block = check_block.parent.?;
......@@ -1534,7 +1533,7 @@ fn analyzeBodyInner(
15341533 .repeat => {
15351534 if (block.is_comptime) {
15361535 // Send comptime control flow back to the beginning of this block.
1537 const src = LazySrcLoc.nodeOffset(datas[inst].node);
1536 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
15381537 try sema.emitBackwardBranch(block, src);
15391538
15401539 // We need to construct new capture scopes for the next loop iteration so it
......@@ -1549,7 +1548,7 @@ fn analyzeBodyInner(
15491548 },
15501549 .repeat_inline => {
15511550 // Send comptime control flow back to the beginning of this block.
1552 const src = LazySrcLoc.nodeOffset(datas[inst].node);
1551 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
15531552 try sema.emitBackwardBranch(block, src);
15541553
15551554 // We need to construct new capture scopes for the next loop iteration so it
......@@ -1562,9 +1561,9 @@ fn analyzeBodyInner(
15621561 .loop => blk: {
15631562 if (!block.is_comptime) break :blk try sema.zirLoop(block, inst);
15641563 // Same as `block_inline`. TODO https://github.com/ziglang/zig/issues/8220
1565 const inst_data = datas[inst].pl_node;
1564 const inst_data = datas[@intFromEnum(inst)].pl_node;
15661565 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1567 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
1566 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
15681567 const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
15691568 break always_noreturn;
15701569 if (inst == break_data.block_inst) {
......@@ -1575,12 +1574,12 @@ fn analyzeBodyInner(
15751574 },
15761575 .block, .block_comptime => blk: {
15771576 if (!block.is_comptime) {
1578 break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
1577 break :blk try sema.zirBlock(block, inst, tags[@intFromEnum(inst)] == .block_comptime);
15791578 }
15801579 // Same as `block_inline`. TODO https://github.com/ziglang/zig/issues/8220
1581 const inst_data = datas[inst].pl_node;
1580 const inst_data = datas[@intFromEnum(inst)].pl_node;
15821581 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1583 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
1582 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
15841583 // If this block contains a function prototype, we need to reset the
15851584 // current list of parameters and restore it later.
15861585 // Note: this probably needs to be resolved in a more general manner.
......@@ -1601,9 +1600,9 @@ fn analyzeBodyInner(
16011600 // through a runtime conditional branch, we must retroactively emit
16021601 // a block, so we remember the block index here just in case.
16031602 const block_index = block.instructions.items.len;
1604 const inst_data = datas[inst].pl_node;
1603 const inst_data = datas[@intFromEnum(inst)].pl_node;
16051604 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1606 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
1605 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
16071606 const gpa = sema.gpa;
16081607
16091608 const opt_break_data = b: {
......@@ -1614,8 +1613,11 @@ fn analyzeBodyInner(
16141613 // If this block contains a function prototype, we need to reset the
16151614 // current list of parameters and restore it later.
16161615 // Note: this probably needs to be resolved in a more general manner.
1617 child_block.inline_block =
1618 if (tags[inline_body[inline_body.len - 1]] == .repeat_inline) inline_body[0] else inst;
1616 const tag_index = @intFromEnum(inline_body[inline_body.len - 1]);
1617 child_block.inline_block = (if (tags[tag_index] == .repeat_inline)
1618 inline_body[0]
1619 else
1620 inst).toOptional();
16191621
16201622 var label: Block.Label = .{
16211623 .zir_block = inst,
......@@ -1682,11 +1684,14 @@ fn analyzeBodyInner(
16821684 .condbr => blk: {
16831685 if (!block.is_comptime) break sema.zirCondbr(block, inst);
16841686 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
1685 const inst_data = datas[inst].pl_node;
1687 const inst_data = datas[@intFromEnum(inst)].pl_node;
16861688 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
16871689 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1688 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
1689 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1690 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1691 const else_body = sema.code.bodySlice(
1692 extra.end + then_body.len,
1693 extra.data.else_body_len,
1694 );
16901695 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
16911696 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
16921697 .block_comptime_reason = block.comptime_reason,
......@@ -1703,11 +1708,14 @@ fn analyzeBodyInner(
17031708 }
17041709 },
17051710 .condbr_inline => blk: {
1706 const inst_data = datas[inst].pl_node;
1711 const inst_data = datas[@intFromEnum(inst)].pl_node;
17071712 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
17081713 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1709 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
1710 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1714 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1715 const else_body = sema.code.bodySlice(
1716 extra.end + then_body.len,
1717 extra.data.else_body_len,
1718 );
17111719 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
17121720 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
17131721 .block_comptime_reason = block.comptime_reason,
......@@ -1727,11 +1735,11 @@ fn analyzeBodyInner(
17271735 },
17281736 .@"try" => blk: {
17291737 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
1730 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1738 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17311739 const src = inst_data.src();
17321740 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17331741 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1734 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
1742 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17351743 const err_union = try sema.resolveInst(extra.data.operand);
17361744 const err_union_ty = sema.typeOf(err_union);
17371745 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
......@@ -1758,11 +1766,11 @@ fn analyzeBodyInner(
17581766 },
17591767 .try_ptr => blk: {
17601768 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
1761 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1769 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17621770 const src = inst_data.src();
17631771 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17641772 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1765 const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
1773 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17661774 const operand = try sema.resolveInst(extra.data.operand);
17671775 const err_union = try sema.analyzeLoad(block, src, operand, operand_src);
17681776 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
......@@ -1783,8 +1791,8 @@ fn analyzeBodyInner(
17831791 }
17841792 },
17851793 .@"defer" => blk: {
1786 const inst_data = sema.code.instructions.items(.data)[inst].@"defer";
1787 const defer_body = sema.code.extra[inst_data.index..][0..inst_data.len];
1794 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
1795 const defer_body = sema.code.bodySlice(inst_data.index, inst_data.len);
17881796 const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) {
17891797 error.ComptimeBreak => sema.comptime_break_inst,
17901798 else => |e| return e,
......@@ -1793,9 +1801,9 @@ fn analyzeBodyInner(
17931801 break :blk .void_value;
17941802 },
17951803 .defer_err_code => blk: {
1796 const inst_data = sema.code.instructions.items(.data)[inst].defer_err_code;
1804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
17971805 const extra = sema.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
1798 const defer_body = sema.code.extra[extra.index..][0..extra.len];
1806 const defer_body = sema.code.bodySlice(extra.index, extra.len);
17991807 const err_code = try sema.resolveInst(inst_data.err_code);
18001808 map.putAssumeCapacity(extra.remapped_err_code, err_code);
18011809 const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) {
......@@ -1846,14 +1854,14 @@ pub fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
18461854
18471855pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
18481856 assert(zir_ref != .none);
1849 const i = @intFromEnum(zir_ref);
1857 if (zir_ref.toIndex()) |i| {
1858 const inst = sema.inst_map.get(i).?;
1859 if (inst == .generic_poison) return error.GenericPoison;
1860 return inst;
1861 }
18501862 // First section of indexes correspond to a set number of constant values.
18511863 // We intentionally map the same indexes to the same values between ZIR and AIR.
1852 if (i < InternPool.static_len) return @enumFromInt(i);
1853 // The last section of indexes refers to the map of ZIR => AIR.
1854 const inst = sema.inst_map.get(i - InternPool.static_len).?;
1855 if (inst == .generic_poison) return error.GenericPoison;
1856 return inst;
1864 return @enumFromInt(@intFromEnum(zir_ref));
18571865}
18581866
18591867fn resolveConstBool(
......@@ -1968,30 +1976,30 @@ const GenericPoisonReason = union(enum) {
19681976fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
19691977 var cur = ref;
19701978 while (true) {
1971 const inst = Zir.refToIndex(cur) orelse return .unknown;
1972 switch (sema.code.instructions.items(.tag)[inst]) {
1979 const inst = cur.toIndex() orelse return .unknown;
1980 switch (sema.code.instructions.items(.tag)[@intFromEnum(inst)]) {
19731981 .validate_array_init_ref_ty => {
1974 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
1982 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19751983 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
19761984 cur = extra.ptr_ty;
19771985 },
19781986 .array_init_elem_type => {
1979 const bin = sema.code.instructions.items(.data)[inst].bin;
1987 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
19801988 cur = bin.lhs;
19811989 },
19821990 .indexable_ptr_elem_type, .vector_elem_type => {
1983 const un_node = sema.code.instructions.items(.data)[inst].un_node;
1991 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19841992 cur = un_node.operand;
19851993 },
19861994 .struct_init_field_type => {
1987 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
1995 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19881996 const extra = sema.code.extraData(Zir.Inst.FieldType, pl_node.payload_index).data;
19891997 cur = extra.container_type;
19901998 },
19911999 .elem_type => {
19922000 // There are two cases here: the pointer type may already have been
19932001 // generic poison, or it may have been an anyopaque pointer.
1994 const un_node = sema.code.instructions.items(.data)[inst].un_node;
2002 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19952003 const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) {
19962004 error.GenericPoison => unreachable, // this is a type, not a value
19972005 };
......@@ -2008,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason {
20082016 // A function call can never return generic poison, so we must be
20092017 // evaluating an `anytype` function parameter.
20102018 // TODO: better source location - function decl rather than call
2011 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
2019 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20122020 return .{ .anytype_param = pl_node.src() };
20132021 },
20142022 else => return .unknown,
......@@ -2651,7 +2659,7 @@ pub fn getStructType(
26512659 const mod = sema.mod;
26522660 const gpa = sema.gpa;
26532661 const ip = &mod.intern_pool;
2654 const extended = sema.code.instructions.items(.data)[zir_index].extended;
2662 const extended = sema.code.instructions.items(.data)[@intFromEnum(zir_index)].extended;
26552663 assert(extended.opcode == .struct_decl);
26562664 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
26572665
......@@ -2801,7 +2809,7 @@ fn createAnonymousDeclTypeNamed(
28012809 try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)});
28022810
28032811 var arg_i: usize = 0;
2804 for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) {
2812 for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) {
28052813 .param, .param_comptime, .param_anytype, .param_anytype_comptime => {
28062814 const arg = sema.inst_map.get(zir_inst).?;
28072815 // If this is being called in a generic function then analyzeCall will
......@@ -2827,11 +2835,10 @@ fn createAnonymousDeclTypeNamed(
28272835 return new_decl_index;
28282836 },
28292837 .dbg_var => {
2830 const ref = Zir.indexToRef(inst.?);
2838 const ref = inst.?.toRef();
28312839 const zir_tags = sema.code.instructions.items(.tag);
28322840 const zir_data = sema.code.instructions.items(.data);
2833 var i = inst.?;
2834 while (i < zir_tags.len) : (i += 1) switch (zir_tags[i]) {
2841 for (@intFromEnum(inst.?)..zir_tags.len) |i| switch (zir_tags[i]) {
28352842 .dbg_var_ptr, .dbg_var_val => {
28362843 if (zir_data[i].str_op.operand != ref) continue;
28372844
......@@ -2917,7 +2924,7 @@ fn zirEnumDecl(
29172924
29182925 extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);
29192926
2920 const body = sema.code.extra[extra_index..][0..body_len];
2927 const body = sema.code.bodySlice(extra_index, body_len);
29212928 extra_index += body.len;
29222929
29232930 const bit_bags_count = std.math.divCeil(usize, fields_len, 32) catch unreachable;
......@@ -3296,7 +3303,7 @@ fn zirErrorSetDecl(
32963303
32973304 const mod = sema.mod;
32983305 const gpa = sema.gpa;
3299 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3306 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
33003307 const src = inst_data.src();
33013308 const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
33023309
......@@ -3359,7 +3366,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
33593366 const tracy = trace(@src());
33603367 defer tracy.end();
33613368
3362 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
3369 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
33633370 const operand = try sema.resolveInst(inst_data.operand);
33643371 return sema.analyzeRef(block, inst_data.src(), operand);
33653372}
......@@ -3368,7 +3375,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
33683375 const tracy = trace(@src());
33693376 defer tracy.end();
33703377
3371 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3378 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
33723379 const operand = try sema.resolveInst(inst_data.operand);
33733380 const src = inst_data.src();
33743381
......@@ -3411,7 +3418,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
34113418 defer tracy.end();
34123419
34133420 const mod = sema.mod;
3414 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3421 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
34153422 const operand = try sema.resolveInst(inst_data.operand);
34163423 const src = inst_data.src();
34173424 const operand_ty = sema.typeOf(operand);
......@@ -3434,7 +3441,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
34343441 defer tracy.end();
34353442
34363443 const mod = sema.mod;
3437 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3444 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
34383445 const src = inst_data.src();
34393446 const operand = try sema.resolveInst(inst_data.operand);
34403447 const operand_ty = sema.typeOf(operand);
......@@ -3459,7 +3466,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
34593466 const tracy = trace(@src());
34603467 defer tracy.end();
34613468
3462 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3469 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
34633470 const src = inst_data.src();
34643471 const object = try sema.resolveInst(inst_data.operand);
34653472
......@@ -3578,7 +3585,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
35783585 const tracy = trace(@src());
35793586 defer tracy.end();
35803587
3581 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3588 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
35823589 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
35833590 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
35843591 return sema.analyzeComptimeAlloc(block, var_ty, .none);
......@@ -3586,7 +3593,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
35863593
35873594fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
35883595 const mod = sema.mod;
3589 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3596 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
35903597 const alloc = try sema.resolveInst(inst_data.operand);
35913598 const alloc_ty = sema.typeOf(alloc);
35923599 const ptr_info = alloc_ty.ptrInfo(mod);
......@@ -3883,7 +3890,7 @@ fn zirAllocInferredComptime(
38833890 is_const: bool,
38843891) CompileError!Air.Inst.Ref {
38853892 const gpa = sema.gpa;
3886 const src_node = sema.code.instructions.items(.data)[inst].node;
3893 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
38873894 const src = LazySrcLoc.nodeOffset(src_node);
38883895 sema.src = src;
38893896
......@@ -3902,7 +3909,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
39023909 const tracy = trace(@src());
39033910 defer tracy.end();
39043911
3905 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3912 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
39063913 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
39073914 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
39083915 if (block.is_comptime) {
......@@ -3925,7 +3932,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
39253932 const tracy = trace(@src());
39263933 defer tracy.end();
39273934
3928 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3935 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
39293936 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
39303937 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
39313938 if (block.is_comptime) {
......@@ -3951,7 +3958,7 @@ fn zirAllocInferred(
39513958 defer tracy.end();
39523959
39533960 const gpa = sema.gpa;
3954 const src_node = sema.code.instructions.items(.data)[inst].node;
3961 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
39553962 const src = LazySrcLoc.nodeOffset(src_node);
39563963 sema.src = src;
39573964
......@@ -3986,7 +3993,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39863993
39873994 const mod = sema.mod;
39883995 const gpa = sema.gpa;
3989 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3996 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
39903997 const src = inst_data.src();
39913998 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
39923999 const ptr = try sema.resolveInst(inst_data.operand);
......@@ -4027,7 +4034,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40274034 } });
40284035
40294036 // Remap the ZIR operand to the resolved pointer value
4030 sema.inst_map.putAssumeCapacity(Zir.refToIndex(inst_data.operand).?, Air.internedToRef(interned));
4037 sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(interned));
40314038 },
40324039 .inferred_alloc => {
40334040 const ia1 = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc;
......@@ -4061,7 +4068,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40614068 } });
40624069
40634070 // Remap the ZIR oeprand to the resolved pointer value
4064 sema.inst_map.putAssumeCapacity(Zir.refToIndex(inst_data.operand).?, Air.internedToRef(new_const_ptr));
4071 sema.inst_map.putAssumeCapacity(inst_data.operand.toIndex().?, Air.internedToRef(new_const_ptr));
40654072
40664073 // Unless the block is comptime, `alloc_inferred` always produces
40674074 // a runtime constant. The final inferred type needs to be
......@@ -4125,7 +4132,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41254132 const mod = sema.mod;
41264133 const gpa = sema.gpa;
41274134 const ip = &mod.intern_pool;
4128 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4135 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
41294136 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
41304137 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
41314138 const src = inst_data.src();
......@@ -4264,14 +4271,14 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL
42644271}
42654272
42664273fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4267 const un_node = sema.code.instructions.items(.data)[inst].un_node;
4274 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
42684275 const ptr = try sema.resolveInst(un_node.operand);
42694276 return sema.optEuBasePtrInit(block, ptr, un_node.src());
42704277}
42714278
42724279fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
42734280 const mod = sema.mod;
4274 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
4281 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
42754282 const src = pl_node.src();
42764283 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
42774284 const uncoerced_val = try sema.resolveInst(extra.rhs);
......@@ -4322,7 +4329,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
43224329
43234330fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
43244331 const mod = sema.mod;
4325 const un_tok = sema.code.instructions.items(.data)[inst].un_tok;
4332 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
43264333 const src = un_tok.src();
43274334 // In case of GenericPoison, we don't actually have a type, so this will be
43284335 // treated as an untyped address-of operator.
......@@ -4353,7 +4360,7 @@ fn zirValidateArrayInitRefTy(
43534360 inst: Zir.Inst.Index,
43544361) CompileError!Air.Inst.Ref {
43554362 const mod = sema.mod;
4356 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
4363 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
43574364 const src = pl_node.src();
43584365 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
43594366 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) {
......@@ -4389,7 +4396,7 @@ fn zirValidateArrayInitTy(
43894396 is_result_ty: bool,
43904397) CompileError!void {
43914398 const mod = sema.mod;
4392 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4399 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
43934400 const src = inst_data.src();
43944401 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
43954402 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
......@@ -4452,7 +4459,7 @@ fn zirValidateStructInitTy(
44524459 is_result_ty: bool,
44534460) CompileError!void {
44544461 const mod = sema.mod;
4455 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4462 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
44564463 const src = inst_data.src();
44574464 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
44584465 // It's okay for the type to be unknown: this will result in an anonymous struct init.
......@@ -4477,11 +4484,11 @@ fn zirValidatePtrStructInit(
44774484 defer tracy.end();
44784485
44794486 const mod = sema.mod;
4480 const validate_inst = sema.code.instructions.items(.data)[inst].pl_node;
4487 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
44814488 const init_src = validate_inst.src();
44824489 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
4483 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
4484 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
4490 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
4491 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
44854492 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
44864493 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
44874494 const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod);
......@@ -4525,7 +4532,7 @@ fn validateUnionInit(
45254532 errdefer msg.destroy(gpa);
45264533
45274534 for (instrs[1..]) |inst| {
4528 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
4535 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
45294536 const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };
45304537 try sema.errNote(block, inst_src, msg, "additional initializer here", .{});
45314538 }
......@@ -4543,7 +4550,7 @@ fn validateUnionInit(
45434550 }
45444551
45454552 const field_ptr = instrs[0];
4546 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4553 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
45474554 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
45484555 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
45494556 const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start));
......@@ -4662,14 +4669,14 @@ fn validateStructInit(
46624669 defer gpa.free(field_indices);
46634670
46644671 // Maps field index to field_ptr index of where it was already initialized.
4665 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount(mod));
4672 const found_fields = try gpa.alloc(Zir.Inst.OptionalIndex, struct_ty.structFieldCount(mod));
46664673 defer gpa.free(found_fields);
4667 @memset(found_fields, 0);
4674 @memset(found_fields, .none);
46684675
46694676 var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;
46704677
46714678 for (instrs, field_indices) |field_ptr, *field_index| {
4672 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4679 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
46734680 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
46744681 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
46754682 struct_ptr_zir_ref = field_ptr_extra.lhs;
......@@ -4681,9 +4688,8 @@ fn validateStructInit(
46814688 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)
46824689 else
46834690 try sema.structFieldIndex(block, struct_ty, field_name, field_src);
4684 if (found_fields[field_index.*] != 0) {
4685 const other_field_ptr = found_fields[field_index.*];
4686 const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node;
4691 if (found_fields[field_index.*].unwrap()) |other_field_ptr| {
4692 const other_field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(other_field_ptr)].pl_node;
46874693 const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_ptr_data.src_node };
46884694 const msg = msg: {
46894695 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
......@@ -4693,7 +4699,7 @@ fn validateStructInit(
46934699 };
46944700 return sema.failWithOwnedErrorMsg(block, msg);
46954701 }
4696 found_fields[field_index.*] = field_ptr;
4702 found_fields[field_index.*] = field_ptr.toOptional();
46974703 }
46984704
46994705 var root_msg: ?*Module.ErrorMsg = null;
......@@ -4709,7 +4715,7 @@ fn validateStructInit(
47094715 // Avoid the cost of the extra machinery for detecting a comptime struct init value.
47104716 for (found_fields, 0..) |field_ptr, i_usize| {
47114717 const i: u32 = @intCast(i_usize);
4712 if (field_ptr != 0) continue;
4718 if (field_ptr != .none) continue;
47134719
47144720 const default_val = struct_ty.structFieldDefaultValue(i, mod);
47154721 if (default_val.toIntern() == .unreachable_value) {
......@@ -4770,9 +4776,9 @@ fn validateStructInit(
47704776 // ends up being comptime-known.
47714777 const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod));
47724778
4773 field: for (found_fields, 0..) |field_ptr, i_usize| {
4779 field: for (found_fields, 0..) |opt_field_ptr, i_usize| {
47744780 const i: u32 = @intCast(i_usize);
4775 if (field_ptr != 0) {
4781 if (opt_field_ptr.unwrap()) |field_ptr| {
47764782 // Determine whether the value stored to this pointer is comptime-known.
47774783 const field_ty = struct_ty.structFieldType(i, mod);
47784784 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
......@@ -4831,7 +4837,7 @@ fn validateStructInit(
48314837 if (try sema.resolveValue(bin_op.rhs)) |val| {
48324838 field_values[i] = val.toIntern();
48334839 } else if (require_comptime) {
4834 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4840 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
48354841 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
48364842 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
48374843 });
......@@ -4931,7 +4937,7 @@ fn validateStructInit(
49314937
49324938 // Our task is to insert `store` instructions for all the default field values.
49334939 for (found_fields, 0..) |field_ptr, i| {
4934 if (field_ptr != 0) continue;
4940 if (field_ptr != .none) continue;
49354941
49364942 const field_src = init_src; // TODO better source location
49374943 const default_field_ptr = if (struct_ty.isTuple(mod))
......@@ -4950,11 +4956,11 @@ fn zirValidatePtrArrayInit(
49504956 inst: Zir.Inst.Index,
49514957) CompileError!void {
49524958 const mod = sema.mod;
4953 const validate_inst = sema.code.instructions.items(.data)[inst].pl_node;
4959 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
49544960 const init_src = validate_inst.src();
49554961 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
4956 const instrs = sema.code.extra[validate_extra.end..][0..validate_extra.data.body_len];
4957 const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
4962 const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len);
4963 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
49584964 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
49594965 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
49604966 const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod);
......@@ -5147,7 +5153,7 @@ fn zirValidatePtrArrayInit(
51475153
51485154fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
51495155 const mod = sema.mod;
5150 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5156 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
51515157 const src = inst_data.src();
51525158 const operand = try sema.resolveInst(inst_data.operand);
51535159 const operand_ty = sema.typeOf(operand);
......@@ -5190,7 +5196,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
51905196
51915197fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
51925198 const mod = sema.mod;
5193 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5199 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
51945200 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
51955201 const src = inst_data.src();
51965202 const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node);
......@@ -5328,7 +5334,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
53285334 defer tracy.end();
53295335
53305336 const src: LazySrcLoc = sema.src;
5331 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
5337 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
53325338 const ptr = try sema.resolveInst(bin_inst.lhs);
53335339 const operand = try sema.resolveInst(bin_inst.rhs);
53345340 const ptr_inst = Air.refToIndex(ptr).?;
......@@ -5387,7 +5393,7 @@ fn storeToInferredAllocComptime(
53875393}
53885394
53895395fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5390 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5396 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
53915397 const src = inst_data.src();
53925398 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{
53935399 .needed_comptime_reason = "eval branch quota must be comptime-known",
......@@ -5399,7 +5405,7 @@ fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
53995405 const tracy = trace(@src());
54005406 defer tracy.end();
54015407
5402 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
5408 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
54035409 const ptr = try sema.resolveInst(bin_inst.lhs);
54045410 const value = try sema.resolveInst(bin_inst.rhs);
54055411 return sema.storePtr(block, sema.src, ptr, value);
......@@ -5412,14 +5418,14 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
54125418 const mod = sema.mod;
54135419 const zir_tags = sema.code.instructions.items(.tag);
54145420 const zir_datas = sema.code.instructions.items(.data);
5415 const inst_data = zir_datas[inst].pl_node;
5421 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
54165422 const src = inst_data.src();
54175423 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
54185424 const ptr = try sema.resolveInst(extra.lhs);
54195425 const operand = try sema.resolveInst(extra.rhs);
54205426
5421 const is_ret = if (Zir.refToIndex(extra.lhs)) |ptr_index|
5422 zir_tags[ptr_index] == .ret_ptr
5427 const is_ret = if (extra.lhs.toIndex()) |ptr_index|
5428 zir_tags[@intFromEnum(ptr_index)] == .ret_ptr
54235429 else
54245430 false;
54255431
......@@ -5445,7 +5451,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
54455451}
54465452
54475453fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5448 const bytes = sema.code.instructions.items(.data)[inst].str.get(sema.code);
5454 const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code);
54495455 return sema.addStrLitNoAlias(bytes);
54505456}
54515457
......@@ -5497,7 +5503,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
54975503 const tracy = trace(@src());
54985504 defer tracy.end();
54995505
5500 const int = sema.code.instructions.items(.data)[inst].int;
5506 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].int;
55015507 return sema.mod.intRef(Type.comptime_int, int);
55025508}
55035509
......@@ -5507,7 +5513,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
55075513 defer tracy.end();
55085514
55095515 const mod = sema.mod;
5510 const int = sema.code.instructions.items(.data)[inst].str;
5516 const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].str;
55115517 const byte_count = int.len * @sizeOf(std.math.big.Limb);
55125518 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
55135519
......@@ -5525,7 +5531,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
55255531
55265532fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
55275533 _ = block;
5528 const number = sema.code.instructions.items(.data)[inst].float;
5534 const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float;
55295535 return Air.internedToRef((try sema.mod.floatValue(
55305536 Type.comptime_float,
55315537 number,
......@@ -5534,7 +5540,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
55345540
55355541fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
55365542 _ = block;
5537 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
55385544 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
55395545 const number = extra.get();
55405546 return Air.internedToRef((try sema.mod.floatValue(Type.comptime_float, number)).toIntern());
......@@ -5544,7 +5550,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
55445550 const tracy = trace(@src());
55455551 defer tracy.end();
55465552
5547 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5553 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
55485554 const src = inst_data.src();
55495555 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
55505556 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
......@@ -5594,7 +5600,7 @@ fn zirCompileLog(
55945600}
55955601
55965602fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
5597 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
5603 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
55985604 const src = inst_data.src();
55995605 const msg_inst = try sema.resolveInst(inst_data.operand);
56005606
......@@ -5606,7 +5612,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I
56065612}
56075613
56085614fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
5609 const src_node = sema.code.instructions.items(.data)[inst].node;
5615 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
56105616 const src = LazySrcLoc.nodeOffset(src_node);
56115617 sema.src = src;
56125618 _ = try block.addNoOp(.trap);
......@@ -5618,10 +5624,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
56185624 defer tracy.end();
56195625
56205626 const mod = sema.mod;
5621 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5627 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
56225628 const src = inst_data.src();
56235629 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
5624 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
5630 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
56255631 const gpa = sema.gpa;
56265632
56275633 // AIR expects a block outside the loop block too.
......@@ -5690,10 +5696,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
56905696 const mod = sema.mod;
56915697 const comp = mod.comp;
56925698 const gpa = sema.gpa;
5693 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
5699 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
56945700 const src = pl_node.src();
56955701 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
5696 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
5702 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
56975703
56985704 // we check this here to avoid undefined symbols
56995705 if (!@import("build_options").have_llvm)
......@@ -5768,7 +5774,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
57685774}
57695775
57705776fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5771 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
5777 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
57725778 const src = inst_data.src();
57735779 return sema.failWithUseOfAsync(parent_block, src);
57745780}
......@@ -5777,10 +5783,10 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
57775783 const tracy = trace(@src());
57785784 defer tracy.end();
57795785
5780 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
5786 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
57815787 const src = pl_node.src();
57825788 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
5783 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
5789 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
57845790 const gpa = sema.gpa;
57855791
57865792 // Reserve space for a Block instruction so that generated Break instructions can
......@@ -5852,7 +5858,7 @@ fn resolveBlockBody(
58525858 try parent_block.instructions.appendSlice(sema.gpa, child_block.instructions.items);
58535859
58545860 const break_inst = sema.comptime_break_inst;
5855 const break_data = sema.code.instructions.items(.data)[break_inst].@"break";
5861 const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break";
58565862 const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data;
58575863 if (extra.block_inst == body_inst) {
58585864 return try sema.resolveInst(break_data.operand);
......@@ -5991,7 +5997,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
59915997 defer tracy.end();
59925998
59935999 const mod = sema.mod;
5994 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6000 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
59956001 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
59966002 const src = inst_data.src();
59976003 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -6027,7 +6033,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
60276033 defer tracy.end();
60286034
60296035 const mod = sema.mod;
6030 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6036 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
60316037 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
60326038 const src = inst_data.src();
60336039 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -6198,7 +6204,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
61986204}
61996205
62006206fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
6201 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
6207 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
62026208 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
62036209 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
62046210 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
......@@ -6228,7 +6234,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
62286234 const tracy = trace(@src());
62296235 defer tracy.end();
62306236
6231 const inst_data = sema.code.instructions.items(.data)[inst].@"break";
6237 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
62326238 const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
62336239 const operand = try sema.resolveInst(inst_data.operand);
62346240 const zir_block = extra.block_inst;
......@@ -6264,7 +6270,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
62646270 // instructions.
62656271 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return;
62666272
6267 const inst_data = sema.code.instructions.items(.data)[inst].dbg_stmt;
6273 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
62686274
62696275 if (block.instructions.items.len != 0) {
62706276 const idx = block.instructions.items[block.instructions.items.len - 1];
......@@ -6313,7 +6319,7 @@ fn zirDbgVar(
63136319) CompileError!void {
63146320 if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return;
63156321
6316 const str_op = sema.code.instructions.items(.data)[inst].str_op;
6322 const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
63176323 const operand = try sema.resolveInst(str_op.operand);
63186324 const name = str_op.getStr(sema.code);
63196325 try sema.addDbgVar(block, operand, air_tag, name);
......@@ -6358,7 +6364,7 @@ fn addDbgVar(
63586364
63596365fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
63606366 const mod = sema.mod;
6361 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
6367 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
63626368 const src = inst_data.src();
63636369 const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
63646370 const decl_index = try sema.lookupIdentifier(block, src, decl_name);
......@@ -6368,7 +6374,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
63686374
63696375fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
63706376 const mod = sema.mod;
6371 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
6377 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
63726378 const src = inst_data.src();
63736379 const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
63746380 const decl = try sema.lookupIdentifier(block, src, decl_name);
......@@ -6637,7 +6643,7 @@ fn zirCall(
66376643 defer tracy.end();
66386644
66396645 const mod = sema.mod;
6640 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6646 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
66416647 const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };
66426648 const call_src = inst_data.src();
66436649 const ExtraType = switch (kind) {
......@@ -6685,12 +6691,12 @@ fn zirCall(
66856691 .call_inst = inst,
66866692 .call_node_offset = inst_data.src_node,
66876693 .num_args = args_len,
6688 .args_body = sema.code.extra[extra.end..],
6694 .args_body = @ptrCast(sema.code.extra[extra.end..]),
66896695 .any_arg_is_error = &input_is_error,
66906696 } };
66916697
66926698 // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction.
6693 const call_dbg_node = inst - 1;
6699 const call_dbg_node: Zir.Inst.Index = @enumFromInt(@intFromEnum(inst) - 1);
66946700 const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call);
66956701
66966702 if (sema.owner_func_index == .none or
......@@ -6961,11 +6967,11 @@ const CallArgsInfo = union(enum) {
69616967
69626968 const arg_body = if (real_arg_idx == 0) blk: {
69636969 const start = zir_call.num_args;
6964 const end = zir_call.args_body[0];
6970 const end = @intFromEnum(zir_call.args_body[0]);
69656971 break :blk zir_call.args_body[start..end];
69666972 } else blk: {
6967 const start = zir_call.args_body[real_arg_idx - 1];
6968 const end = zir_call.args_body[real_arg_idx];
6973 const start = @intFromEnum(zir_call.args_body[real_arg_idx - 1]);
6974 const end = @intFromEnum(zir_call.args_body[real_arg_idx]);
69696975 break :blk zir_call.args_body[start..end];
69706976 };
69716977
......@@ -7447,9 +7453,9 @@ fn analyzeCall(
74477453 try sema.emitDbgInline(block, prev_fn_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin);
74487454
74497455 const zir_tags = sema.code.instructions.items(.tag);
7450 for (fn_info.param_body) |param| switch (zir_tags[param]) {
7456 for (fn_info.param_body) |param| switch (zir_tags[@intFromEnum(param)]) {
74517457 .param, .param_comptime => {
7452 const inst_data = sema.code.instructions.items(.data)[param].pl_tok;
7458 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].pl_tok;
74537459 const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
74547460 const param_name = sema.code.nullTerminatedString(extra.data.name);
74557461 const inst = sema.inst_map.get(param).?;
......@@ -7457,7 +7463,7 @@ fn analyzeCall(
74577463 try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name);
74587464 },
74597465 .param_anytype, .param_anytype_comptime => {
7460 const inst_data = sema.code.instructions.items(.data)[param].str_tok;
7466 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].str_tok;
74617467 const param_name = inst_data.get(sema.code);
74627468 const inst = sema.inst_map.get(param).?;
74637469
......@@ -7640,18 +7646,18 @@ fn analyzeInlineCallArg(
76407646 const mod = ics.sema.mod;
76417647 const ip = &mod.intern_pool;
76427648 const zir_tags = ics.callee().code.instructions.items(.tag);
7643 switch (zir_tags[inst]) {
7649 switch (zir_tags[@intFromEnum(inst)]) {
76447650 .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true,
76457651 else => {},
76467652 }
7647 switch (zir_tags[inst]) {
7653 switch (zir_tags[@intFromEnum(inst)]) {
76487654 .param, .param_comptime => {
76497655 // Evaluate the parameter type expression now that previous ones have
76507656 // been mapped, and coerce the corresponding argument to it.
7651 const pl_tok = ics.callee().code.instructions.items(.data)[inst].pl_tok;
7657 const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
76527658 const param_src = pl_tok.src();
76537659 const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index);
7654 const param_body = ics.callee().code.extra[extra.end..][0..extra.data.body_len];
7660 const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len);
76557661 const param_ty = param_ty: {
76567662 const raw_param_ty = func_ty_info.param_types.get(ip)[arg_i.*];
76577663 if (raw_param_ty != .generic_poison_type) break :param_ty raw_param_ty;
......@@ -7670,7 +7676,7 @@ fn analyzeInlineCallArg(
76707676 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
76717677 .block_comptime_reason = param_block.comptime_reason,
76727678 });
7673 } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) {
7679 } else if (!is_comptime_call and zir_tags[@intFromEnum(inst)] == .param_comptime) {
76747680 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
76757681 .needed_comptime_reason = "parameter is comptime",
76767682 });
......@@ -7736,7 +7742,7 @@ fn analyzeInlineCallArg(
77367742 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
77377743 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod);
77387744 } else {
7739 if (zir_tags[inst] == .param_anytype_comptime) {
7745 if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) {
77407746 _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{
77417747 .needed_comptime_reason = "parameter is comptime",
77427748 });
......@@ -7864,7 +7870,7 @@ fn instantiateGenericCall(
78647870 try child_sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body);
78657871
78667872 for (fn_info.param_body[0..args_info.count()], 0..) |param_inst, arg_index| {
7867 const param_tag = fn_zir.instructions.items(.tag)[param_inst];
7873 const param_tag = fn_zir.instructions.items(.tag)[@intFromEnum(param_inst)];
78687874
78697875 const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) {
78707876 else => |ty| ty.toType(), // parameter is not generic, so type is already resolved
......@@ -7879,9 +7885,9 @@ fn instantiateGenericCall(
78797885 .param, .param_comptime => {
78807886 // We now know every prior parameter, so can resolve this
78817887 // parameter's type. The child sema has these types.
7882 const param_data = fn_zir.instructions.items(.data)[param_inst].pl_tok;
7888 const param_data = fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok;
78837889 const param_extra = fn_zir.extraData(Zir.Inst.Param, param_data.payload_index);
7884 const param_ty_body = fn_zir.extra[param_extra.end..][0..param_extra.data.body_len];
7890 const param_ty_body = fn_zir.bodySlice(param_extra.end, param_extra.data.body_len);
78857891
78867892 // Make sure any nested instructions don't clobber our work.
78877893 const prev_params = child_block.params;
......@@ -7937,8 +7943,8 @@ fn instantiateGenericCall(
79377943 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{});
79387944 errdefer msg.destroy(sema.gpa);
79397945 const param_src = switch (param_tag) {
7940 .param_comptime => fn_zir.instructions.items(.data)[param_inst].pl_tok.src(),
7941 .param_anytype_comptime => fn_zir.instructions.items(.data)[param_inst].str_tok.src(),
7946 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),
7947 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),
79427948 else => unreachable,
79437949 };
79447950 try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{});
......@@ -7952,8 +7958,8 @@ fn instantiateGenericCall(
79527958 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
79537959 errdefer msg.destroy(sema.gpa);
79547960 const param_src = switch (param_tag) {
7955 .param => fn_zir.instructions.items(.data)[param_inst].pl_tok.src(),
7956 .param_anytype => fn_zir.instructions.items(.data)[param_inst].str_tok.src(),
7961 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(),
7962 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(),
79577963 else => unreachable,
79587964 };
79597965 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});
......@@ -7975,9 +7981,9 @@ fn instantiateGenericCall(
79757981 } },
79767982 }));
79777983 const param_name: Zir.NullTerminatedString = switch (param_tag) {
7978 .param_anytype => @enumFromInt(fn_zir.instructions.items(.data)[param_inst].str_tok.start),
7984 .param_anytype => @enumFromInt(fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.start),
79797985 .param => name: {
7980 const inst_data = fn_zir.instructions.items(.data)[param_inst].pl_tok;
7986 const inst_data = fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok;
79817987 const extra = fn_zir.extraData(Zir.Inst.Param, inst_data.payload_index);
79827988 break :name @enumFromInt(extra.data.name);
79837989 },
......@@ -8094,7 +8100,7 @@ fn emitDbgInline(
80948100
80958101fn zirIntType(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
80968102 const mod = sema.mod;
8097 const int_type = sema.code.instructions.items(.data)[inst].int_type;
8103 const int_type = sema.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
80988104 const ty = try mod.intType(int_type.signedness, int_type.bit_count);
80998105 return Air.internedToRef(ty.toIntern());
81008106}
......@@ -8104,7 +8110,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
81048110 defer tracy.end();
81058111
81068112 const mod = sema.mod;
8107 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8113 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
81088114 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
81098115 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
81108116 if (child_type.zigTypeTag(mod) == .Opaque) {
......@@ -8119,7 +8125,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
81198125
81208126fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
81218127 const mod = sema.mod;
8122 const bin = sema.code.instructions.items(.data)[inst].bin;
8128 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
81238129 const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) {
81248130 // Since this is a ZIR instruction that returns a type, encountering
81258131 // generic poison should not result in a failed compilation, but the
......@@ -8142,7 +8148,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
81428148
81438149fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
81448150 const mod = sema.mod;
8145 const un_node = sema.code.instructions.items(.data)[inst].un_node;
8151 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
81468152 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
81478153 error.GenericPoison => return .generic_poison_type,
81488154 else => |e| return e,
......@@ -8160,7 +8166,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
81608166
81618167fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
81628168 const mod = sema.mod;
8163 const un_node = sema.code.instructions.items(.data)[inst].un_node;
8169 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
81648170 const src = un_node.src();
81658171 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {
81668172 error.GenericPoison => return .generic_poison_type,
......@@ -8176,7 +8182,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
81768182
81778183fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
81788184 const mod = sema.mod;
8179 const un_node = sema.code.instructions.items(.data)[inst].un_node;
8185 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
81808186 const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
81818187 // Since this is a ZIR instruction that returns a type, encountering
81828188 // generic poison should not result in a failed compilation, but the
......@@ -8193,7 +8199,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
81938199
81948200fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
81958201 const mod = sema.mod;
8196 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8202 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
81978203 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
81988204 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
81998205 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -8213,7 +8219,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
82138219 const tracy = trace(@src());
82148220 defer tracy.end();
82158221
8216 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8222 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
82178223 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
82188224 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
82198225 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
......@@ -8234,7 +8240,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
82348240 const tracy = trace(@src());
82358241 defer tracy.end();
82368242
8237 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8243 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
82388244 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
82398245 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
82408246 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };
......@@ -8271,7 +8277,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
82718277 const tracy = trace(@src());
82728278 defer tracy.end();
82738279
8274 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8280 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
82758281 if (true) {
82768282 return sema.failWithUseOfAsync(block, inst_data.src());
82778283 }
......@@ -8288,7 +8294,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
82888294 defer tracy.end();
82898295
82908296 const mod = sema.mod;
8291 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8297 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
82928298 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
82938299 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
82948300 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
......@@ -8321,7 +8327,7 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
83218327fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
83228328 _ = block;
83238329 const mod = sema.mod;
8324 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
8330 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
83258331 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
83268332 _ = try mod.getErrorValue(name);
83278333 // Create an error set type with only this error value, and return the value.
......@@ -8420,7 +8426,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
84208426
84218427 const mod = sema.mod;
84228428 const ip = &mod.intern_pool;
8423 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8429 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
84248430 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
84258431 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
84268432 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -8475,7 +8481,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
84758481 defer tracy.end();
84768482
84778483 const mod = sema.mod;
8478 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
8484 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
84798485 const name = inst_data.get(sema.code);
84808486 return Air.internedToRef((try mod.intern(.{
84818487 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name),
......@@ -8484,7 +8490,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
84848490
84858491fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84868492 const mod = sema.mod;
8487 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8493 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
84888494 const src = inst_data.src();
84898495 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
84908496 const operand = try sema.resolveInst(inst_data.operand);
......@@ -8529,7 +8535,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
85298535
85308536fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85318537 const mod = sema.mod;
8532 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8538 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
85338539 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
85348540 const src = inst_data.src();
85358541 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -8610,7 +8616,7 @@ fn zirOptionalPayloadPtr(
86108616 const tracy = trace(@src());
86118617 defer tracy.end();
86128618
8613 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8619 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
86148620 const optional_ptr = try sema.resolveInst(inst_data.operand);
86158621 const src = inst_data.src();
86168622
......@@ -8695,7 +8701,7 @@ fn zirOptionalPayload(
86958701 defer tracy.end();
86968702
86978703 const mod = sema.mod;
8698 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8704 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
86998705 const src = inst_data.src();
87008706 const operand = try sema.resolveInst(inst_data.operand);
87018707 const operand_ty = sema.typeOf(operand);
......@@ -8747,7 +8753,7 @@ fn zirErrUnionPayload(
87478753 defer tracy.end();
87488754
87498755 const mod = sema.mod;
8750 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8756 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
87518757 const src = inst_data.src();
87528758 const operand = try sema.resolveInst(inst_data.operand);
87538759 const operand_src = src;
......@@ -8799,7 +8805,7 @@ fn zirErrUnionPayloadPtr(
87998805 const tracy = trace(@src());
88008806 defer tracy.end();
88018807
8802 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8808 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
88038809 const operand = try sema.resolveInst(inst_data.operand);
88048810 const src = inst_data.src();
88058811
......@@ -8883,7 +8889,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
88838889 const tracy = trace(@src());
88848890 defer tracy.end();
88858891
8886 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8892 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
88878893 const src = inst_data.src();
88888894 const operand = try sema.resolveInst(inst_data.operand);
88898895 return sema.analyzeErrUnionCode(block, src, operand);
......@@ -8917,7 +8923,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
89178923 defer tracy.end();
89188924
89198925 const mod = sema.mod;
8920 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
8926 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
89218927 const src = inst_data.src();
89228928 const operand = try sema.resolveInst(inst_data.operand);
89238929 const operand_ty = sema.typeOf(operand);
......@@ -8949,7 +8955,7 @@ fn zirFunc(
89498955 inferred_error_set: bool,
89508956) CompileError!Air.Inst.Ref {
89518957 const mod = sema.mod;
8952 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
8958 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
89538959 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
89548960 const target = sema.mod.getTarget();
89558961 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };
......@@ -8971,7 +8977,7 @@ fn zirFunc(
89718977 }
89728978 },
89738979 else => blk: {
8974 const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len];
8980 const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_body_len);
89758981 extra_index += ret_ty_body.len;
89768982
89778983 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{
......@@ -9591,9 +9597,9 @@ fn finishFunc(
95919597 param_body[0..block.params.len],
95929598 ) |is_comptime, name_nts, param_index| {
95939599 if (!is_comptime) {
9594 const param_src = switch (tags[param_index]) {
9595 .param => data[param_index].pl_tok.src(),
9596 .param_anytype => data[param_index].str_tok.src(),
9600 const param_src = switch (tags[@intFromEnum(param_index)]) {
9601 .param => data[@intFromEnum(param_index)].pl_tok.src(),
9602 .param_anytype => data[@intFromEnum(param_index)].str_tok.src(),
95979603 else => unreachable,
95989604 };
95999605 const name = sema.code.nullTerminatedString2(name_nts);
......@@ -9667,11 +9673,11 @@ fn zirParam(
96679673 inst: Zir.Inst.Index,
96689674 comptime_syntax: bool,
96699675) CompileError!void {
9670 const inst_data = sema.code.instructions.items(.data)[inst].pl_tok;
9676 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
96719677 const src = inst_data.src();
96729678 const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
96739679 const param_name: Zir.NullTerminatedString = @enumFromInt(extra.data.name);
9674 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
9680 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
96759681
96769682 const param_ty = param_ty: {
96779683 const err = err: {
......@@ -9760,7 +9766,7 @@ fn zirParamAnytype(
97609766 inst: Zir.Inst.Index,
97619767 comptime_syntax: bool,
97629768) CompileError!void {
9763 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
9769 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
97649770 const param_name: Zir.NullTerminatedString = @enumFromInt(inst_data.start);
97659771
97669772 // We are evaluating a generic function without any comptime args provided.
......@@ -9777,7 +9783,7 @@ fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst
97779783 const tracy = trace(@src());
97789784 defer tracy.end();
97799785
9780 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
9786 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
97819787 return sema.analyzeAs(block, sema.src, bin_inst.lhs, bin_inst.rhs, false);
97829788}
97839789
......@@ -9785,7 +9791,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
97859791 const tracy = trace(@src());
97869792 defer tracy.end();
97879793
9788 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9794 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
97899795 const src = inst_data.src();
97909796 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
97919797 sema.src = src;
......@@ -9796,7 +9802,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
97969802 const tracy = trace(@src());
97979803 defer tracy.end();
97989804
9799 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9805 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
98009806 const src = inst_data.src();
98019807 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
98029808 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true);
......@@ -9828,8 +9834,8 @@ fn analyzeAs(
98289834 if (dest_ty_tag == .NoReturn) {
98299835 return sema.fail(block, src, "cannot cast to noreturn", .{});
98309836 }
9831 const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index|
9832 sema.code.instructions.items(.tag)[ptr_index] == .ret_type
9837 const is_ret = if (zir_dest_type.toIndex()) |ptr_index|
9838 sema.code.instructions.items(.tag)[@intFromEnum(ptr_index)] == .ret_type
98339839 else
98349840 false;
98359841 return sema.coerceExtra(block, dest_ty, operand, src, .{ .is_ret = is_ret, .no_cast_to_comptime_int = no_cast_to_comptime_int }) catch |err| switch (err) {
......@@ -9843,7 +9849,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
98439849 defer tracy.end();
98449850
98459851 const mod = sema.mod;
9846 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
9852 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
98479853 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
98489854 const operand = try sema.resolveInst(inst_data.operand);
98499855 const operand_ty = sema.typeOf(operand);
......@@ -9909,7 +9915,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
99099915 defer tracy.end();
99109916
99119917 const mod = sema.mod;
9912 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9918 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99139919 const src = inst_data.src();
99149920 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
99159921 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
......@@ -9923,7 +9929,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
99239929 defer tracy.end();
99249930
99259931 const mod = sema.mod;
9926 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9932 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99279933 const src = inst_data.src();
99289934 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
99299935 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
......@@ -9937,7 +9943,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
99379943 defer tracy.end();
99389944
99399945 const mod = sema.mod;
9940 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9946 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99419947 const src = inst_data.src();
99429948 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
99439949 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
......@@ -9958,7 +9964,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
99589964 const tracy = trace(@src());
99599965 defer tracy.end();
99609966
9961 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9967 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99629968 const src = inst_data.src();
99639969 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
99649970 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
......@@ -9973,7 +9979,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
99739979 const tracy = trace(@src());
99749980 defer tracy.end();
99759981
9976 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9982 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99779983 const src = inst_data.src();
99789984 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
99799985 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
......@@ -9988,7 +9994,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
99889994 const tracy = trace(@src());
99899995 defer tracy.end();
99909996
9991 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9997 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
99929998 const src = inst_data.src();
99939999 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
999410000 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -10149,7 +10155,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1014910155 defer tracy.end();
1015010156
1015110157 const mod = sema.mod;
10152 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1015310159 const src = inst_data.src();
1015410160 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1015510161 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -10292,7 +10298,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1029210298 defer tracy.end();
1029310299
1029410300 const mod = sema.mod;
10295 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10301 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1029610302 const src = inst_data.src();
1029710303 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1029810304 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -10371,7 +10377,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1037110377 const tracy = trace(@src());
1037210378 defer tracy.end();
1037310379
10374 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10380 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1037510381 const src = inst_data.src();
1037610382 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1037710383 const array = try sema.resolveInst(extra.lhs);
......@@ -10383,7 +10389,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1038310389 const tracy = trace(@src());
1038410390 defer tracy.end();
1038510391
10386 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10392 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1038710393 const src = inst_data.src();
1038810394 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
1038910395 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -10397,7 +10403,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1039710403 defer tracy.end();
1039810404
1039910405 const mod = sema.mod;
10400 const inst_data = sema.code.instructions.items(.data)[inst].elem_val_imm;
10406 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
1040110407 const array = try sema.resolveInst(inst_data.operand);
1040210408 const elem_index = try mod.intRef(Type.usize, inst_data.idx);
1040310409 return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false);
......@@ -10408,7 +10414,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1040810414 defer tracy.end();
1040910415
1041010416 const mod = sema.mod;
10411 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10417 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1041210418 const src = inst_data.src();
1041310419 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1041410420 const array_ptr = try sema.resolveInst(extra.lhs);
......@@ -10435,7 +10441,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1043510441 const tracy = trace(@src());
1043610442 defer tracy.end();
1043710443
10438 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10444 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1043910445 const src = inst_data.src();
1044010446 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
1044110447 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -10449,7 +10455,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1044910455 defer tracy.end();
1045010456
1045110457 const mod = sema.mod;
10452 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10458 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1045310459 const src = inst_data.src();
1045410460 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
1045510461 const array_ptr = try sema.resolveInst(extra.ptr);
......@@ -10468,7 +10474,7 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1046810474 const tracy = trace(@src());
1046910475 defer tracy.end();
1047010476
10471 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10477 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1047210478 const src = inst_data.src();
1047310479 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
1047410480 const array_ptr = try sema.resolveInst(extra.lhs);
......@@ -10484,7 +10490,7 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1048410490 const tracy = trace(@src());
1048510491 defer tracy.end();
1048610492
10487 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10493 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1048810494 const src = inst_data.src();
1048910495 const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
1049010496 const array_ptr = try sema.resolveInst(extra.lhs);
......@@ -10501,7 +10507,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1050110507 const tracy = trace(@src());
1050210508 defer tracy.end();
1050310509
10504 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10510 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1050510511 const src = inst_data.src();
1050610512 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
1050710513 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
......@@ -10520,7 +10526,7 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1052010526 const tracy = trace(@src());
1052110527 defer tracy.end();
1052210528
10523 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
10529 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1052410530 const src = inst_data.src();
1052510531 const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
1052610532 const array_ptr = try sema.resolveInst(extra.lhs);
......@@ -10581,7 +10587,7 @@ const SwitchProngAnalysis = struct {
1058110587 merges: *Block.Merges,
1058210588 ) CompileError!Air.Inst.Ref {
1058310589 const sema = spa.sema;
10584 const src = sema.code.instructions.items(.data)[spa.switch_block_inst].pl_node.src();
10590 const src = sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src();
1058510591
1058610592 if (has_tag_capture) {
1058710593 const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture);
......@@ -10684,7 +10690,7 @@ const SwitchProngAnalysis = struct {
1068410690 const operand_ty = sema.typeOf(spa.operand);
1068510691 if (operand_ty.zigTypeTag(mod) != .Union) {
1068610692 const zir_datas = sema.code.instructions.items(.data);
10687 const switch_node_offset = zir_datas[spa.switch_block_inst].pl_node.src_node;
10693 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;
1068810694 const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) {
1068910695 .scalar_capture => |i| .{ .scalar_tag_capture = i },
1069010696 .multi_capture => |i| .{ .multi_tag_capture = i },
......@@ -10720,7 +10726,7 @@ const SwitchProngAnalysis = struct {
1072010726 const ip = &mod.intern_pool;
1072110727
1072210728 const zir_datas = sema.code.instructions.items(.data);
10723 const switch_node_offset = zir_datas[spa.switch_block_inst].pl_node.src_node;
10729 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;
1072410730
1072510731 const operand_ty = sema.typeOf(spa.operand);
1072610732 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;
......@@ -11146,7 +11152,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1114611152 const mod = sema.mod;
1114711153 const gpa = sema.gpa;
1114811154 const ip = &mod.intern_pool;
11149 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
11155 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1115011156 const src = inst_data.src();
1115111157 const src_node_offset = inst_data.src_node;
1115211158 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
......@@ -11167,7 +11173,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1116711173
1116811174 // AstGen guarantees that the instruction immediately preceding
1116911175 // switch_block(_ref) is a dbg_stmt
11170 const cond_dbg_node_index = inst - 1;
11176 const cond_dbg_node_index: Zir.Inst.Index = @enumFromInt(@intFromEnum(inst) - 1);
1117111177
1117211178 var header_extra_index: usize = extra.end;
1117311179
......@@ -11179,7 +11185,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1117911185 } else 0;
1118011186
1118111187 const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: {
11182 const tag_capture_inst = sema.code.extra[header_extra_index];
11188 const tag_capture_inst: Zir.Inst.Index = @enumFromInt(sema.code.extra[header_extra_index]);
1118311189 header_extra_index += 1;
1118411190 // SwitchProngAnalysis wants inst_map to have space for the tag capture.
1118511191 // Note that the normal capture is referred to via the switch block
......@@ -11212,7 +11218,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1121211218 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]);
1121311219 const extra_body_start = header_extra_index + 1;
1121411220 break :blk .{
11215 .body = sema.code.extra[extra_body_start..][0..info.body_len],
11221 .body = sema.code.bodySlice(extra_body_start, info.body_len),
1121611222 .end = extra_body_start + info.body_len,
1121711223 .capture = info.capture,
1121811224 .is_inline = info.is_inline,
......@@ -11482,7 +11488,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1148211488 // else => |e| return e,
1148311489 // even if all the possible errors were already handled.
1148411490 const tags = sema.code.instructions.items(.tag);
11485 for (special.body) |else_inst| switch (tags[else_inst]) {
11491 for (special.body) |else_inst| switch (tags[@intFromEnum(else_inst)]) {
1148611492 .dbg_block_begin,
1148711493 .dbg_block_end,
1148811494 .dbg_stmt,
......@@ -11826,7 +11832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1182611832 extra_index += 1;
1182711833 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1182811834 extra_index += 1;
11829 const body = sema.code.extra[extra_index..][0..info.body_len];
11835 const body = sema.code.bodySlice(extra_index, info.body_len);
1183011836 extra_index += info.body_len;
1183111837
1183211838 const item = case_vals.items[scalar_i];
......@@ -11857,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1185711863 extra_index += 1;
1185811864 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1185911865 extra_index += 1 + items_len;
11860 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len];
11866 const body = sema.code.bodySlice(extra_index + 2 * ranges_len, info.body_len);
1186111867
1186211868 const items = case_vals.items[case_val_idx..][0..items_len];
1186311869 case_val_idx += items_len;
......@@ -11986,7 +11992,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1198611992 extra_index += 1;
1198711993 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1198811994 extra_index += 1;
11989 const body = sema.code.extra[extra_index..][0..info.body_len];
11995 const body = sema.code.bodySlice(extra_index, info.body_len);
1199011996 extra_index += info.body_len;
1199111997
1199211998 case_block.instructions.shrinkRetainingCapacity(0);
......@@ -12053,7 +12059,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1205312059 // Generate all possible cases as scalar prongs.
1205412060 if (info.is_inline) {
1205512061 const body_start = extra_index + 2 * ranges_len;
12056 const body = sema.code.extra[body_start..][0..info.body_len];
12062 const body = sema.code.bodySlice(body_start, info.body_len);
1205712063 var emit_bb = false;
1205812064
1205912065 var range_i: u32 = 0;
......@@ -12184,7 +12190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1218412190 else
1218512191 true;
1218612192
12187 const body = sema.code.extra[extra_index..][0..info.body_len];
12193 const body = sema.code.bodySlice(extra_index, info.body_len);
1218812194 extra_index += info.body_len;
1218912195 if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) {
1219012196 // nothing to do here
......@@ -12268,7 +12274,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1226812274 case_block.instructions.shrinkRetainingCapacity(0);
1226912275 case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope);
1227012276
12271 const body = sema.code.extra[extra_index..][0..info.body_len];
12277 const body = sema.code.bodySlice(extra_index, info.body_len);
1227212278 extra_index += info.body_len;
1227312279 if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) {
1227412280 // nothing to do here
......@@ -12493,8 +12499,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1249312499 case_block.instructions.shrinkRetainingCapacity(0);
1249412500 case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope);
1249512501
12496 if (mod.backendSupportsFeature(.is_named_enum_value) and special.body.len != 0 and block.wantSafety() and
12497 operand_ty.zigTypeTag(mod) == .Enum and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
12502 if (mod.backendSupportsFeature(.is_named_enum_value) and
12503 special.body.len != 0 and block.wantSafety() and
12504 operand_ty.zigTypeTag(mod) == .Enum and
12505 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
1249812506 {
1249912507 try sema.zirDbgStmt(&case_block, cond_dbg_node_index);
1250012508 const ok = try case_block.addUnOp(.is_named_enum_value, operand);
......@@ -12879,7 +12887,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1287912887
1288012888 const tags = sema.code.instructions.items(.tag);
1288112889 for (body) |inst| {
12882 switch (tags[inst]) {
12890 switch (tags[@intFromEnum(inst)]) {
1288312891 .@"unreachable" => if (!block.wantSafety()) return false,
1288412892 .save_err_ret_index,
1288512893 .dbg_block_begin,
......@@ -12895,7 +12903,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1289512903 }
1289612904
1289712905 for (body) |inst| {
12898 const air_inst = switch (tags[inst]) {
12906 const air_inst = switch (tags[@intFromEnum(inst)]) {
1289912907 .dbg_block_begin,
1290012908 .dbg_block_end,
1290112909 => continue,
......@@ -12923,7 +12931,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1292312931 return true;
1292412932 },
1292512933 .panic => {
12926 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
12934 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1292712935 const msg_inst = try sema.resolveInst(inst_data.operand);
1292812936
1292912937 const panic_fn = try sema.getBuiltin("panic");
......@@ -12943,10 +12951,10 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1294312951
1294412952fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void {
1294512953 const mod = sema.mod;
12946 const index = Zir.refToIndex(cond) orelse return;
12947 if (sema.code.instructions.items(.tag)[index] != .is_non_err) return;
12954 const index = cond.toIndex() orelse return;
12955 if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) return;
1294812956
12949 const err_inst_data = sema.code.instructions.items(.data)[index].un_node;
12957 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
1295012958 const err_operand = try sema.resolveInst(err_inst_data.operand);
1295112959 const operand_ty = sema.typeOf(err_operand);
1295212960 if (operand_ty.zigTypeTag(mod) == .ErrorSet) {
......@@ -12963,7 +12971,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind
1296312971fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !void {
1296412972 const tags = sema.code.instructions.items(.tag);
1296512973 const inst = for (body) |inst| {
12966 switch (tags[inst]) {
12974 switch (tags[@intFromEnum(inst)]) {
1296712975 .dbg_block_begin,
1296812976 .dbg_block_end,
1296912977 .dbg_stmt,
......@@ -12973,7 +12981,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1297312981 else => return,
1297412982 }
1297512983 } else return;
12976 const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable";
12984 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
1297712985 const src = inst_data.src();
1297812986
1297912987 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
......@@ -12985,7 +12993,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1298512993
1298612994fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1298712995 const mod = sema.mod;
12988 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
12996 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1298912997 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1299012998 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1299112999 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
......@@ -13036,7 +13044,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1303613044
1303713045fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1303813046 const mod = sema.mod;
13039 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13047 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1304013048 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1304113049 const src = inst_data.src();
1304213050 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -13064,7 +13072,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1306413072 defer tracy.end();
1306513073
1306613074 const mod = sema.mod;
13067 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
13075 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1306813076 const operand_src = inst_data.src();
1306913077 const operand = inst_data.get(sema.code);
1307013078
......@@ -13093,7 +13101,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1309313101 defer tracy.end();
1309413102
1309513103 const mod = sema.mod;
13096 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13104 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1309713105 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1309813106 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
1309913107 .needed_comptime_reason = "file path name must be comptime-known",
......@@ -13120,7 +13128,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1312013128
1312113129fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1312213130 const mod = sema.mod;
13123 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
13131 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1312413132 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
1312513133 _ = try mod.getErrorValue(name);
1312613134 const error_set_type = try mod.singleErrorSetType(name);
......@@ -13140,7 +13148,7 @@ fn zirShl(
1314013148 defer tracy.end();
1314113149
1314213150 const mod = sema.mod;
13143 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13151 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1314413152 const src = inst_data.src();
1314513153 sema.src = src;
1314613154 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -13323,7 +13331,7 @@ fn zirShr(
1332313331 defer tracy.end();
1332413332
1332513333 const mod = sema.mod;
13326 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13334 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1332713335 const src = inst_data.src();
1332813336 sema.src = src;
1332913337 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -13459,7 +13467,7 @@ fn zirBitwise(
1345913467 defer tracy.end();
1346013468
1346113469 const mod = sema.mod;
13462 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13470 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1346313471 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1346413472 sema.src = src;
1346513473 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -13514,7 +13522,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1351413522 defer tracy.end();
1351513523
1351613524 const mod = sema.mod;
13517 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13525 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1351813526 const src = inst_data.src();
1351913527 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1352013528
......@@ -13648,7 +13656,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1364813656 defer tracy.end();
1364913657
1365013658 const mod = sema.mod;
13651 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13659 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1365213660 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1365313661 const lhs = try sema.resolveInst(extra.lhs);
1365413662 const rhs = try sema.resolveInst(extra.rhs);
......@@ -13977,7 +13985,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1397713985 defer tracy.end();
1397813986
1397913987 const mod = sema.mod;
13980 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
13988 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1398113989 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1398213990 const lhs = try sema.resolveInst(extra.lhs);
1398313991 const lhs_ty = sema.typeOf(lhs);
......@@ -14116,7 +14124,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1411614124
1411714125fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1411814126 const mod = sema.mod;
14119 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14127 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1412014128 const src = inst_data.src();
1412114129 const lhs_src = src;
1412214130 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
......@@ -14148,7 +14156,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1414814156
1414914157fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1415014158 const mod = sema.mod;
14151 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14159 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1415214160 const src = inst_data.src();
1415314161 const lhs_src = src;
1415414162 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
......@@ -14176,7 +14184,7 @@ fn zirArithmetic(
1417614184 const tracy = trace(@src());
1417714185 defer tracy.end();
1417814186
14179 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14187 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1418014188 sema.src = .{ .node_offset_bin_op = inst_data.src_node };
1418114189 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1418214190 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
......@@ -14189,7 +14197,7 @@ fn zirArithmetic(
1418914197
1419014198fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1419114199 const mod = sema.mod;
14192 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14200 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1419314201 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1419414202 sema.src = src;
1419514203 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -14355,7 +14363,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1435514363
1435614364fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1435714365 const mod = sema.mod;
14358 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14366 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1435914367 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1436014368 sema.src = src;
1436114369 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -14521,7 +14529,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1452114529
1452214530fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1452314531 const mod = sema.mod;
14524 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14532 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1452514533 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1452614534 sema.src = src;
1452714535 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -14632,7 +14640,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1463214640
1463314641fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1463414642 const mod = sema.mod;
14635 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14643 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1463614644 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1463714645 sema.src = src;
1463814646 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -14874,7 +14882,7 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
1487414882
1487514883fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1487614884 const mod = sema.mod;
14877 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1487814886 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1487914887 sema.src = src;
1488014888 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -15059,7 +15067,7 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1505915067
1506015068fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1506115069 const mod = sema.mod;
15062 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
15070 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1506315071 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1506415072 sema.src = src;
1506515073 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -15155,7 +15163,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1515515163
1515615164fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1515715165 const mod = sema.mod;
15158 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
15166 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1515915167 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
1516015168 sema.src = src;
1516115169 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -16071,7 +16079,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In
1607116079 const tracy = trace(@src());
1607216080 defer tracy.end();
1607316081
16074 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16082 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1607516083 const src = inst_data.src();
1607616084 const ptr_src = src; // TODO better source location
1607716085 const ptr = try sema.resolveInst(inst_data.operand);
......@@ -16251,7 +16259,7 @@ fn zirCmpEq(
1625116259 defer tracy.end();
1625216260
1625316261 const mod = sema.mod;
16254 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
16262 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1625516263 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1625616264 const src: LazySrcLoc = inst_data.src();
1625716265 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -16367,7 +16375,7 @@ fn zirCmp(
1636716375 const tracy = trace(@src());
1636816376 defer tracy.end();
1636916377
16370 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
16378 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1637116379 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1637216380 const src: LazySrcLoc = inst_data.src();
1637316381 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -16512,7 +16520,7 @@ fn runtimeBoolCmp(
1651216520
1651316521fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1651416522 const mod = sema.mod;
16515 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16523 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1651616524 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1651716525 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1651816526 switch (ty.zigTypeTag(mod)) {
......@@ -16555,7 +16563,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1655516563
1655616564fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1655716565 const mod = sema.mod;
16558 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16566 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1655916567 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1656016568 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
1656116569 switch (operand_ty.zigTypeTag(mod)) {
......@@ -16607,7 +16615,7 @@ fn zirThis(
1660716615fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1660816616 const mod = sema.mod;
1660916617 const gpa = sema.gpa;
16610 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
16618 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
1661116619 // Closures are not necessarily constant values. For example, the
1661216620 // code might do something like this:
1661316621 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }
......@@ -16629,7 +16637,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1662916637fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1663016638 const mod = sema.mod;
1663116639 //const ip = &mod.intern_pool;
16632 const inst_data = sema.code.instructions.items(.data)[inst].inst_node;
16640 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
1663316641 var scope: CaptureScope.Index = mod.declPtr(block.src_decl).src_scope;
1663416642 assert(scope != .none);
1663516643 // Note: The target closure must be in this scope list.
......@@ -16818,7 +16826,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1681816826 const mod = sema.mod;
1681916827 const gpa = sema.gpa;
1682016828 const ip = &mod.intern_pool;
16821 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16829 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1682216830 const src = inst_data.src();
1682316831 const ty = try sema.resolveType(block, src, inst_data.operand);
1682416832 const type_info_ty = try sema.getBuiltinType("Type");
......@@ -17923,16 +17931,16 @@ fn typeInfoNamespaceDecls(
1792317931fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1792417932 _ = block;
1792517933 const zir_datas = sema.code.instructions.items(.data);
17926 const inst_data = zir_datas[inst].un_node;
17934 const inst_data = zir_datas[@intFromEnum(inst)].un_node;
1792717935 const operand = try sema.resolveInst(inst_data.operand);
1792817936 const operand_ty = sema.typeOf(operand);
1792917937 return Air.internedToRef(operand_ty.toIntern());
1793017938}
1793117939
1793217940fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17933 const pl_node = sema.code.instructions.items(.data)[inst].pl_node;
17941 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1793417942 const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index);
17935 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
17943 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1793617944
1793717945 var child_block: Block = .{
1793817946 .parent = block,
......@@ -17956,7 +17964,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1795617964}
1795717965
1795817966fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17959 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
17967 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1796017968 const src = inst_data.src();
1796117969 const operand = try sema.resolveInst(inst_data.operand);
1796217970 const operand_ty = sema.typeOf(operand);
......@@ -18010,7 +18018,7 @@ fn zirTypeofPeer(
1801018018
1801118019 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
1801218020 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
18013 const body = sema.code.extra[extra.data.body_index..][0..extra.data.body_len];
18021 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
1801418022
1801518023 var child_block: Block = .{
1801618024 .parent = block,
......@@ -18048,7 +18056,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1804818056 defer tracy.end();
1804918057
1805018058 const mod = sema.mod;
18051 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18059 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1805218060 const src = inst_data.src();
1805318061 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1805418062 const uncasted_operand = try sema.resolveInst(inst_data.operand);
......@@ -18074,11 +18082,11 @@ fn zirBoolBr(
1807418082
1807518083 const mod = sema.mod;
1807618084 const datas = sema.code.instructions.items(.data);
18077 const inst_data = datas[inst].bool_br;
18085 const inst_data = datas[@intFromEnum(inst)].bool_br;
1807818086 const lhs = try sema.resolveInst(inst_data.lhs);
1807918087 const lhs_src = sema.src;
1808018088 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
18081 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
18089 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1808218090 const gpa = sema.gpa;
1808318091
1808418092 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
......@@ -18193,7 +18201,7 @@ fn zirIsNonNull(
1819318201 const tracy = trace(@src());
1819418202 defer tracy.end();
1819518203
18196 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18204 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1819718205 const src = inst_data.src();
1819818206 const operand = try sema.resolveInst(inst_data.operand);
1819918207 try sema.checkNullableType(block, src, sema.typeOf(operand));
......@@ -18209,7 +18217,7 @@ fn zirIsNonNullPtr(
1820918217 defer tracy.end();
1821018218
1821118219 const mod = sema.mod;
18212 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18220 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1821318221 const src = inst_data.src();
1821418222 const ptr = try sema.resolveInst(inst_data.operand);
1821518223 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
......@@ -18234,7 +18242,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1823418242 const tracy = trace(@src());
1823518243 defer tracy.end();
1823618244
18237 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18245 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1823818246 const src = inst_data.src();
1823918247 const operand = try sema.resolveInst(inst_data.operand);
1824018248 try sema.checkErrorType(block, src, sema.typeOf(operand));
......@@ -18246,7 +18254,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1824618254 defer tracy.end();
1824718255
1824818256 const mod = sema.mod;
18249 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18257 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1825018258 const src = inst_data.src();
1825118259 const ptr = try sema.resolveInst(inst_data.operand);
1825218260 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));
......@@ -18258,7 +18266,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1825818266 const tracy = trace(@src());
1825918267 defer tracy.end();
1826018268
18261 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18269 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1826218270 const src = inst_data.src();
1826318271 const operand = try sema.resolveInst(inst_data.operand);
1826418272 return sema.analyzeIsNonErr(block, src, operand);
......@@ -18273,12 +18281,12 @@ fn zirCondbr(
1827318281 defer tracy.end();
1827418282
1827518283 const mod = sema.mod;
18276 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
18284 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1827718285 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
1827818286 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1827918287
18280 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
18281 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
18288 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
18289 const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
1828218290
1828318291 const uncasted_cond = try sema.resolveInst(extra.data.condition);
1828418292 const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src);
......@@ -18307,10 +18315,10 @@ fn zirCondbr(
1830718315 defer gpa.free(true_instructions);
1830818316
1830918317 const err_cond = blk: {
18310 const index = Zir.refToIndex(extra.data.condition) orelse break :blk null;
18311 if (sema.code.instructions.items(.tag)[index] != .is_non_err) break :blk null;
18318 const index = extra.data.condition.toIndex() orelse break :blk null;
18319 if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) break :blk null;
1831218320
18313 const err_inst_data = sema.code.instructions.items(.data)[index].un_node;
18321 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
1831418322 const err_operand = try sema.resolveInst(err_inst_data.operand);
1831518323 const operand_ty = sema.typeOf(err_operand);
1831618324 assert(operand_ty.zigTypeTag(mod) == .ErrorUnion);
......@@ -18341,11 +18349,11 @@ fn zirCondbr(
1834118349}
1834218350
1834318351fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18344 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
18352 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1834518353 const src = inst_data.src();
1834618354 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1834718355 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
18348 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
18356 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1834918357 const err_union = try sema.resolveInst(extra.data.operand);
1835018358 const err_union_ty = sema.typeOf(err_union);
1835118359 const mod = sema.mod;
......@@ -18387,11 +18395,11 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1838718395}
1838818396
1838918397fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
18390 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
18398 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1839118399 const src = inst_data.src();
1839218400 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1839318401 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
18394 const body = sema.code.extra[extra.end..][0..extra.data.body_len];
18402 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1839518403 const operand = try sema.resolveInst(extra.data.operand);
1839618404 const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src);
1839718405 const err_union_ty = sema.typeOf(err_union);
......@@ -18503,7 +18511,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1850318511}
1850418512
1850518513fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
18506 const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable";
18514 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
1850718515 const src = inst_data.src();
1850818516
1850918517 if (block.is_comptime) {
......@@ -18528,7 +18536,7 @@ fn zirRetErrValue(
1852818536 inst: Zir.Inst.Index,
1852918537) CompileError!Zir.Inst.Index {
1853018538 const mod = sema.mod;
18531 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
18539 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1853218540 const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
1853318541 _ = try mod.getErrorValue(err_name);
1853418542 const src = inst_data.src();
......@@ -18550,7 +18558,7 @@ fn zirRetImplicit(
1855018558 defer tracy.end();
1855118559
1855218560 const mod = sema.mod;
18553 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
18561 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
1855418562 const r_brace_src = inst_data.src();
1855518563 if (block.inlining == null and sema.func_is_naked) {
1855618564 assert(!block.is_comptime);
......@@ -18595,7 +18603,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1859518603 const tracy = trace(@src());
1859618604 defer tracy.end();
1859718605
18598 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18606 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1859918607 const operand = try sema.resolveInst(inst_data.operand);
1860018608 const src = inst_data.src();
1860118609
......@@ -18606,7 +18614,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1860618614 const tracy = trace(@src());
1860718615 defer tracy.end();
1860818616
18609 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
18617 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1861018618 const src = inst_data.src();
1861118619 const ret_ptr = try sema.resolveInst(inst_data.operand);
1861218620
......@@ -18693,7 +18701,7 @@ fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {
1869318701
1869418702fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1869518703 const mod = sema.mod;
18696 const inst_data = sema.code.instructions.items(.data)[inst].save_err_ret_index;
18704 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
1869718705
1869818706 if (!mod.backendSupportsFeature(.error_return_trace)) return;
1869918707 if (!mod.comp.bin_file.options.error_return_tracing) return;
......@@ -18712,7 +18720,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1871218720}
1871318721
1871418722fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void {
18715 const inst_data = sema.code.instructions.items(.data)[inst].restore_err_ret_index;
18723 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
1871618724 const src = sema.src; // TODO
1871718725
1871818726 // This is only relevant at runtime.
......@@ -18728,7 +18736,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)
1872818736 const tracy = trace(@src());
1872918737 defer tracy.end();
1873018738
18731 const saved_index = if (Zir.refToIndexAllowNone(inst_data.block)) |zir_block| b: {
18739 const saved_index = if (inst_data.block.toIndexAllowNone()) |zir_block| b: {
1873218740 var block = start_block;
1873318741 while (true) {
1873418742 if (block.label) |label| {
......@@ -18858,7 +18866,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1885818866 defer tracy.end();
1885918867
1886018868 const mod = sema.mod;
18861 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type;
18869 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
1886218870 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
1886318871 const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node };
1886418872 const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node };
......@@ -18998,7 +19006,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1899819006 const tracy = trace(@src());
1899919007 defer tracy.end();
1900019008
19001 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
19009 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1900219010 const src = inst_data.src();
1900319011 const obj_ty = try sema.resolveType(block, src, inst_data.operand);
1900419012 const mod = sema.mod;
......@@ -19017,7 +19025,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
1901719025 defer tracy.end();
1901819026
1901919027 const mod = sema.mod;
19020 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
19028 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1902119029 const src = inst_data.src();
1902219030 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
1902319031 // Generic poison means this is an untyped anonymous empty struct init
......@@ -19092,7 +19100,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
1909219100}
1909319101
1909419102fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19095 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19103 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1909619104 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1909719105 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1909819106 const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
......@@ -19154,14 +19162,14 @@ fn zirStructInit(
1915419162) CompileError!Air.Inst.Ref {
1915519163 const gpa = sema.gpa;
1915619164 const zir_datas = sema.code.instructions.items(.data);
19157 const inst_data = zir_datas[inst].pl_node;
19165 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
1915819166 const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
1915919167 const src = inst_data.src();
1916019168
1916119169 const mod = sema.mod;
1916219170 const ip = &mod.intern_pool;
1916319171 const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;
19164 const first_field_type_data = zir_datas[first_item.field_type].pl_node;
19172 const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node;
1916519173 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
1916619174 const result_ty = sema.resolveType(block, src, first_field_type_extra.container_type) catch |err| switch (err) {
1916719175 error.GenericPoison => {
......@@ -19194,7 +19202,7 @@ fn zirStructInit(
1919419202 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
1919519203 extra_index = item.end;
1919619204
19197 const field_type_data = zir_datas[item.data.field_type].pl_node;
19205 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
1919819206 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
1919919207 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
1920019208 const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));
......@@ -19204,7 +19212,7 @@ fn zirStructInit(
1920419212 try sema.structFieldIndex(block, resolved_ty, field_name, field_src);
1920519213 if (field_inits[field_index] != .none) {
1920619214 const other_field_type = found_fields[field_index];
19207 const other_field_type_data = zir_datas[other_field_type].pl_node;
19215 const other_field_type_data = zir_datas[@intFromEnum(other_field_type)].pl_node;
1920819216 const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_type_data.src_node };
1920919217 const msg = msg: {
1921019218 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
......@@ -19239,7 +19247,7 @@ fn zirStructInit(
1923919247
1924019248 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
1924119249
19242 const field_type_data = zir_datas[item.data.field_type].pl_node;
19250 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
1924319251 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
1924419252 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
1924519253 const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));
......@@ -19481,7 +19489,7 @@ fn zirStructInitAnon(
1948119489 block: *Block,
1948219490 inst: Zir.Inst.Index,
1948319491) CompileError!Air.Inst.Ref {
19484 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19492 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1948519493 const src = inst_data.src();
1948619494 const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
1948719495 return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false);
......@@ -19528,7 +19536,7 @@ fn structInitAnon(
1952819536 .anon_init => sema.code.nullTerminatedString(item.data.field_name),
1952919537 .typed_init => name: {
1953019538 // `item.data.field_type` references a `field_type` instruction
19531 const field_type_data = zir_datas[item.data.field_type].pl_node;
19539 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
1953219540 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index);
1953319541 break :name sema.code.nullTerminatedString(field_type_extra.data.name_start);
1953419542 },
......@@ -19650,7 +19658,7 @@ fn zirArrayInit(
1965019658) CompileError!Air.Inst.Ref {
1965119659 const mod = sema.mod;
1965219660 const gpa = sema.gpa;
19653 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19661 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1965419662 const src = inst_data.src();
1965519663
1965619664 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -19813,7 +19821,7 @@ fn zirArrayInitAnon(
1981319821 block: *Block,
1981419822 inst: Zir.Inst.Index,
1981519823) CompileError!Air.Inst.Ref {
19816 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19824 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1981719825 const src = inst_data.src();
1981819826 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
1981919827 const operands = sema.code.refSlice(extra.end, extra.data.operands_len);
......@@ -19911,7 +19919,7 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In
1991119919}
1991219920
1991319921fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19914 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19922 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1991519923 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
1991619924 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1991719925 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
......@@ -19925,7 +19933,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
1992519933fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1992619934 const mod = sema.mod;
1992719935 const ip = &mod.intern_pool;
19928 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19936 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1992919937 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
1993019938 const ty_src = inst_data.src();
1993119939 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
......@@ -20034,7 +20042,7 @@ fn zirFrame(
2003420042
2003520043fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2003620044 const mod = sema.mod;
20037 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20045 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2003820046 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2003920047 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
2004020048 if (ty.isNoReturn(mod)) {
......@@ -20049,7 +20057,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2004920057
2005020058fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2005120059 const mod = sema.mod;
20052 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20060 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2005320061 const src = inst_data.src();
2005420062 const operand = try sema.resolveInst(inst_data.operand);
2005520063 const operand_ty = sema.typeOf(operand);
......@@ -20098,7 +20106,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2009820106}
2009920107
2010020108fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20101 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20109 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2010220110 const operand = try sema.resolveInst(inst_data.operand);
2010320111 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2010420112
......@@ -20118,7 +20126,7 @@ fn zirAbs(
2011820126 inst: Zir.Inst.Index,
2011920127) CompileError!Air.Inst.Ref {
2012020128 const mod = sema.mod;
20121 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20129 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2012220130 const operand = try sema.resolveInst(inst_data.operand);
2012320131 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2012420132 const operand_ty = sema.typeOf(operand);
......@@ -20186,7 +20194,7 @@ fn zirUnaryMath(
2018620194 defer tracy.end();
2018720195
2018820196 const mod = sema.mod;
20189 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20197 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2019020198 const operand = try sema.resolveInst(inst_data.operand);
2019120199 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2019220200 const operand_ty = sema.typeOf(operand);
......@@ -20209,7 +20217,7 @@ fn zirUnaryMath(
2020920217}
2021020218
2021120219fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20212 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
20220 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2021320221 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2021420222 const src = inst_data.src();
2021520223 const operand = try sema.resolveInst(inst_data.operand);
......@@ -21385,7 +21393,7 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2138521393
2138621394fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2138721395 const mod = sema.mod;
21388 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
21396 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2138921397 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2139021398 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2139121399
......@@ -21395,20 +21403,20 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2139521403}
2139621404
2139721405fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21398 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
21406 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2139921407 const src = inst_data.src();
2140021408 return sema.failWithUseOfAsync(block, src);
2140121409}
2140221410
2140321411fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21404 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
21412 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2140521413 const src = inst_data.src();
2140621414 return sema.failWithUseOfAsync(block, src);
2140721415}
2140821416
2140921417fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2141021418 const mod = sema.mod;
21411 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21419 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2141221420 const src = inst_data.src();
2141321421 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2141421422 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -21490,7 +21498,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2149021498
2149121499fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2149221500 const mod = sema.mod;
21493 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21501 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2149421502 const src = inst_data.src();
2149521503 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2149621504 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -21532,7 +21540,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2153221540
2153321541fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2153421542 const mod = sema.mod;
21535 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2153621544 const src = inst_data.src();
2153721545
2153821546 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -21807,7 +21815,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2180721815}
2180821816
2180921817fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21810 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
21818 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2181121819 const src = inst_data.src();
2181221820 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2181321821 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22237,7 +22245,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2223722245
2223822246fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2223922247 const mod = sema.mod;
22240 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
22248 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2224122249 const src = inst_data.src();
2224222250 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2224322251 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22326,7 +22334,7 @@ fn zirBitCount(
2232622334 comptime comptimeOp: fn (val: Value, ty: Type, mod: *Module) u64,
2232722335) CompileError!Air.Inst.Ref {
2232822336 const mod = sema.mod;
22329 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
22337 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2233022338 const src = inst_data.src();
2233122339 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2233222340 const operand = try sema.resolveInst(inst_data.operand);
......@@ -22380,7 +22388,7 @@ fn zirBitCount(
2238022388
2238122389fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2238222390 const mod = sema.mod;
22383 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
22391 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2238422392 const src = inst_data.src();
2238522393 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2238622394 const operand = try sema.resolveInst(inst_data.operand);
......@@ -22436,7 +22444,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2243622444}
2243722445
2243822446fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22439 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
22447 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2244022448 const src = inst_data.src();
2244122449 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2244222450 const operand = try sema.resolveInst(inst_data.operand);
......@@ -22495,7 +22503,7 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2249522503}
2249622504
2249722505fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
22498 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
22506 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2249922507 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
2250022508 sema.src = src;
2250122509 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -23182,7 +23190,7 @@ fn zirCmpxchg(
2318223190
2318323191fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2318423192 const mod = sema.mod;
23185 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23193 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2318623194 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2318723195 const src = inst_data.src();
2318823196 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -23203,7 +23211,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2320323211}
2320423212
2320523213fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23206 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23214 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2320723215 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2320823216 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2320923217 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
......@@ -23275,7 +23283,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2327523283
2327623284fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2327723285 const mod = sema.mod;
23278 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23286 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2327923287 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
2328023288 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2328123289 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
......@@ -23552,7 +23560,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2355223560}
2355323561
2355423562fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23555 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23563 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2355623564 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
2355723565 // zig fmt: off
2355823566 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -23600,7 +23608,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2360023608
2360123609fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2360223610 const mod = sema.mod;
23603 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23611 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2360423612 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
2360523613 const src = inst_data.src();
2360623614 // zig fmt: off
......@@ -23685,7 +23693,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2368523693}
2368623694
2368723695fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
23688 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23696 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2368923697 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
2369023698 const src = inst_data.src();
2369123699 // zig fmt: off
......@@ -23721,7 +23729,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2372123729}
2372223730
2372323731fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23724 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2372523733 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
2372623734 const src = inst_data.src();
2372723735
......@@ -23789,7 +23797,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2378923797 defer tracy.end();
2379023798
2379123799 const mod = sema.mod;
23792 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23800 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2379323801 const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2379423802 const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
2379523803 const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
......@@ -23880,7 +23888,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2388023888}
2388123889
2388223890fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23883 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23891 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2388423892 const extra = sema.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data;
2388523893 const src = inst_data.src();
2388623894 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -24002,7 +24010,7 @@ fn zirMinMax(
2400224010 inst: Zir.Inst.Index,
2400324011 comptime air_tag: Air.Inst.Tag,
2400424012) CompileError!Air.Inst.Ref {
24005 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24013 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2400624014 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2400724015 const src = inst_data.src();
2400824016 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -24301,7 +24309,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
2430124309}
2430224310
2430324311fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
24304 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24312 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2430524313 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2430624314 const src = inst_data.src();
2430724315 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -24521,7 +24529,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2452124529 const mod = sema.mod;
2452224530 const gpa = sema.gpa;
2452324531 const ip = &mod.intern_pool;
24524 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24532 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2452524533 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2452624534 const src = inst_data.src();
2452724535 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -24607,7 +24615,7 @@ fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.I
2460724615}
2460824616
2460924617fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24610 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
24618 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2461124619 const src = inst_data.src();
2461224620 return sema.failWithUseOfAsync(block, src);
2461324621}
......@@ -24617,7 +24625,7 @@ fn zirAwait(
2461724625 block: *Block,
2461824626 inst: Zir.Inst.Index,
2461924627) CompileError!Air.Inst.Ref {
24620 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
24628 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2462124629 const src = inst_data.src();
2462224630
2462324631 return sema.failWithUseOfAsync(block, src);
......@@ -24702,7 +24710,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2470224710 defer tracy.end();
2470324711
2470424712 const mod = sema.mod;
24705 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
24713 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2470624714 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
2470724715 const target = mod.getTarget();
2470824716
......@@ -24731,7 +24739,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2473124739 const @"align": ?Alignment = if (extra.data.bits.has_align_body) blk: {
2473224740 const body_len = sema.code.extra[extra_index];
2473324741 extra_index += 1;
24734 const body = sema.code.extra[extra_index..][0..body_len];
24742 const body = sema.code.bodySlice(extra_index, body_len);
2473524743 extra_index += body.len;
2473624744
2473724745 const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{
......@@ -24762,7 +24770,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2476224770 const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: {
2476324771 const body_len = sema.code.extra[extra_index];
2476424772 extra_index += 1;
24765 const body = sema.code.extra[extra_index..][0..body_len];
24773 const body = sema.code.bodySlice(extra_index, body_len);
2476624774 extra_index += body.len;
2476724775
2476824776 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
......@@ -24790,7 +24798,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2479024798 const section: Section = if (extra.data.bits.has_section_body) blk: {
2479124799 const body_len = sema.code.extra[extra_index];
2479224800 extra_index += 1;
24793 const body = sema.code.extra[extra_index..][0..body_len];
24801 const body = sema.code.bodySlice(extra_index, body_len);
2479424802 extra_index += body.len;
2479524803
2479624804 const ty = Type.slice_const_u8;
......@@ -24818,7 +24826,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2481824826 const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: {
2481924827 const body_len = sema.code.extra[extra_index];
2482024828 extra_index += 1;
24821 const body = sema.code.extra[extra_index..][0..body_len];
24829 const body = sema.code.bodySlice(extra_index, body_len);
2482224830 extra_index += body.len;
2482324831
2482424832 const cc_ty = try sema.getBuiltinType("CallingConvention");
......@@ -24849,7 +24857,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2484924857 const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: {
2485024858 const body_len = sema.code.extra[extra_index];
2485124859 extra_index += 1;
24852 const body = sema.code.extra[extra_index..][0..body_len];
24860 const body = sema.code.bodySlice(extra_index, body_len);
2485324861 extra_index += body.len;
2485424862
2485524863 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{
......@@ -34821,7 +34829,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
3482134829 break :blk accumulator;
3482234830 };
3482334831
34824 const extended = zir.instructions.items(.data)[struct_type.zir_index].extended;
34832 const extended = zir.instructions.items(.data)[@intFromEnum(struct_type.zir_index)].extended;
3482534833 assert(extended.opcode == .struct_decl);
3482634834 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
3482734835
......@@ -34840,7 +34848,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
3484034848 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
3484134849 break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref);
3484234850 } else {
34843 const body = zir.extra[extra_index..][0..backing_int_body_len];
34851 const body = zir.bodySlice(extra_index, backing_int_body_len);
3484434852 const ty_ref = try sema.resolveBody(&block, body, struct_type.zir_index);
3484534853 break :blk try sema.analyzeAsType(&block, backing_int_src, ty_ref);
3484634854 }
......@@ -35409,7 +35417,7 @@ fn semaStructFields(
3540935417 const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace;
3541035418 const zir = mod.namespacePtr(namespace_index).file_scope.zir;
3541135419 const zir_index = struct_type.zir_index;
35412 const extended = zir.instructions.items(.data)[zir_index].extended;
35420 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
3541335421 assert(extended.opcode == .struct_decl);
3541435422 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
3541535423 var extra_index: usize = extended.operand;
......@@ -35590,7 +35598,7 @@ fn semaStructFields(
3559035598 };
3559135599 }
3559235600 assert(zir_field.type_body_len != 0);
35593 const body = zir.extra[extra_index..][0..zir_field.type_body_len];
35601 const body = zir.bodySlice(extra_index, zir_field.type_body_len);
3559435602 extra_index += body.len;
3559535603 const ty_ref = try sema.resolveBody(&block_scope, body, zir_index);
3559635604 break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) {
......@@ -35676,7 +35684,7 @@ fn semaStructFields(
3567635684 }
3567735685
3567835686 if (zir_field.align_body_len > 0) {
35679 const body = zir.extra[extra_index..][0..zir_field.align_body_len];
35687 const body = zir.bodySlice(extra_index, zir_field.align_body_len);
3568035688 extra_index += body.len;
3568135689 const align_ref = try sema.resolveBody(&block_scope, body, zir_index);
3568235690 const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {
......@@ -35706,7 +35714,7 @@ fn semaStructFields(
3570635714 extra_index += zir_field.type_body_len;
3570735715 extra_index += zir_field.align_body_len;
3570835716 if (zir_field.init_body_len > 0) {
35709 const body = zir.extra[extra_index..][0..zir_field.init_body_len];
35717 const body = zir.bodySlice(extra_index, zir_field.init_body_len);
3571035718 extra_index += body.len;
3571135719 const init = try sema.resolveBody(&block_scope, body, zir_index);
3571235720 const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) {
......@@ -35748,7 +35756,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3574835756 const ip = &mod.intern_pool;
3574935757 const decl_index = union_type.decl;
3575035758 const zir = mod.namespacePtr(union_type.namespace).file_scope.zir;
35751 const extended = zir.instructions.items(.data)[union_type.zir_index].extended;
35759 const extended = zir.instructions.items(.data)[@intFromEnum(union_type.zir_index)].extended;
3575235760 assert(extended.opcode == .union_decl);
3575335761 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
3575435762 var extra_index: usize = extended.operand;
......@@ -35785,7 +35793,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3578535793 while (decls_it.next()) |_| {}
3578635794 extra_index = decls_it.extra_index;
3578735795
35788 const body = zir.extra[extra_index..][0..body_len];
35796 const body = zir.bodySlice(extra_index, body_len);
3578935797 extra_index += body.len;
3579035798
3579135799 const decl = mod.declPtr(decl_index);
src/Zir.zig+102-77
......@@ -93,13 +93,18 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
9393 inline for (fields) |field| {
9494 @field(result, field.name) = switch (field.type) {
9595 u32 => code.extra[i],
96 Inst.Ref => @enumFromInt(code.extra[i]),
96
97 Inst.Ref,
98 Inst.Index,
99 => @enumFromInt(code.extra[i]),
100
97101 i32,
98102 Inst.Call.Flags,
99103 Inst.BuiltinCall.Flags,
100104 Inst.SwitchBlock.Bits,
101105 Inst.FuncFancy.Bits,
102106 => @bitCast(code.extra[i]),
107
103108 else => @compileError("bad field type"),
104109 };
105110 i += 1;
......@@ -134,6 +139,10 @@ pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
134139 return @ptrCast(code.extra[start..][0..len]);
135140}
136141
142pub fn bodySlice(zir: Zir, start: usize, len: usize) []Inst.Index {
143 return @ptrCast(zir.extra[start..][0..len]);
144}
145
137146pub fn hasCompileErrors(code: Zir) bool {
138147 return code.extra[@intFromEnum(ExtraIndex.compile_errors)] != 0;
139148}
......@@ -145,10 +154,6 @@ pub fn deinit(code: *Zir, gpa: Allocator) void {
145154 code.* = undefined;
146155}
147156
148/// ZIR is structured so that the outermost "main" struct of any file
149/// is always at index 0.
150pub const main_struct_inst: Inst.Index = 0;
151
152157/// These are untyped instructions generated from an Abstract Syntax Tree.
153158/// The data here is immutable because it is possible to have multiple
154159/// analyses on the same ZIR happening at the same time.
......@@ -2093,7 +2098,34 @@ pub const Inst = struct {
20932098 };
20942099
20952100 /// The position of a ZIR instruction within the `Zir` instructions array.
2096 pub const Index = u32;
2101 pub const Index = enum(u32) {
2102 /// ZIR is structured so that the outermost "main" struct of any file
2103 /// is always at index 0.
2104 main_struct_inst = 0,
2105 ref_start_index = InternPool.static_len,
2106 _,
2107
2108 pub fn toRef(i: Index) Inst.Ref {
2109 return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
2110 }
2111
2112 pub fn toOptional(i: Index) OptionalIndex {
2113 return @enumFromInt(@intFromEnum(i));
2114 }
2115 };
2116
2117 pub const OptionalIndex = enum(u32) {
2118 /// ZIR is structured so that the outermost "main" struct of any file
2119 /// is always at index 0.
2120 main_struct_inst = 0,
2121 ref_start_index = InternPool.static_len,
2122 none = std.math.maxInt(u32),
2123 _,
2124
2125 pub fn unwrap(oi: OptionalIndex) ?Index {
2126 return if (oi == .none) null else @enumFromInt(@intFromEnum(oi));
2127 }
2128 };
20972129
20982130 /// A reference to ZIR instruction, or to an InternPool index, or neither.
20992131 ///
......@@ -2196,6 +2228,21 @@ pub const Inst = struct {
21962228 /// value and may instead be used as a sentinel to indicate null.
21972229 none = @intFromEnum(InternPool.Index.none),
21982230 _,
2231
2232 pub fn toIndex(inst: Ref) ?Index {
2233 assert(inst != .none);
2234 const ref_int = @intFromEnum(inst);
2235 if (ref_int >= @intFromEnum(Index.ref_start_index)) {
2236 return @enumFromInt(ref_int - @intFromEnum(Index.ref_start_index));
2237 } else {
2238 return null;
2239 }
2240 }
2241
2242 pub fn toIndexAllowNone(inst: Ref) ?Index {
2243 if (inst == .none) return null;
2244 return toIndex(inst);
2245 }
21992246 };
22002247
22012248 /// All instructions have an 8-byte payload, which is contained within
......@@ -3286,7 +3333,7 @@ pub const Inst = struct {
32863333
32873334 /// Trailing: for each `imports_len` there is an Item
32883335 pub const Imports = struct {
3289 imports_len: Inst.Index,
3336 imports_len: u32,
32903337
32913338 pub const Item = struct {
32923339 /// null terminated string index
......@@ -3371,16 +3418,16 @@ pub const DeclIterator = struct {
33713418 }
33723419};
33733420
3374pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3421pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator {
33753422 const tags = zir.instructions.items(.tag);
33763423 const datas = zir.instructions.items(.data);
3377 switch (tags[decl_inst]) {
3424 switch (tags[@intFromEnum(decl_inst)]) {
33783425 // Functions are allowed and yield no iterations.
33793426 // There is one case matching this in the extended instruction set below.
33803427 .func, .func_inferred, .func_fancy => return declIteratorInner(zir, 0, 0),
33813428
33823429 .extended => {
3383 const extended = datas[decl_inst].extended;
3430 const extended = datas[@intFromEnum(decl_inst)].extended;
33843431 switch (extended.opcode) {
33853432 .struct_decl => {
33863433 const small: Inst.StructDecl.Small = @bitCast(extended.small);
......@@ -3469,7 +3516,7 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera
34693516/// The iterator would have to allocate memory anyway to iterate. So here we populate
34703517/// an ArrayList as the result.
34713518pub fn findDecls(zir: Zir, list: *std.ArrayList(Inst.Index), decl_sub_index: ExtraIndex) !void {
3472 const block_inst = zir.extra[@intFromEnum(decl_sub_index) + 6];
3519 const block_inst: Zir.Inst.Index = @enumFromInt(zir.extra[@intFromEnum(decl_sub_index) + 6]);
34733520 list.clearRetainingCapacity();
34743521
34753522 return zir.findDeclsInner(list, block_inst);
......@@ -3483,32 +3530,32 @@ fn findDeclsInner(
34833530 const tags = zir.instructions.items(.tag);
34843531 const datas = zir.instructions.items(.data);
34853532
3486 switch (tags[inst]) {
3533 switch (tags[@intFromEnum(inst)]) {
34873534 // Functions instructions are interesting and have a body.
34883535 .func,
34893536 .func_inferred,
34903537 => {
34913538 try list.append(inst);
34923539
3493 const inst_data = datas[inst].pl_node;
3540 const inst_data = datas[@intFromEnum(inst)].pl_node;
34943541 const extra = zir.extraData(Inst.Func, inst_data.payload_index);
34953542 var extra_index: usize = extra.end;
34963543 switch (extra.data.ret_body_len) {
34973544 0 => {},
34983545 1 => extra_index += 1,
34993546 else => {
3500 const body = zir.extra[extra_index..][0..extra.data.ret_body_len];
3547 const body = zir.bodySlice(extra_index, extra.data.ret_body_len);
35013548 extra_index += body.len;
35023549 try zir.findDeclsBody(list, body);
35033550 },
35043551 }
3505 const body = zir.extra[extra_index..][0..extra.data.body_len];
3552 const body = zir.bodySlice(extra_index, extra.data.body_len);
35063553 return zir.findDeclsBody(list, body);
35073554 },
35083555 .func_fancy => {
35093556 try list.append(inst);
35103557
3511 const inst_data = datas[inst].pl_node;
3558 const inst_data = datas[@intFromEnum(inst)].pl_node;
35123559 const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
35133560 var extra_index: usize = extra.end;
35143561 extra_index += @intFromBool(extra.data.bits.has_lib_name);
......@@ -3516,7 +3563,7 @@ fn findDeclsInner(
35163563 if (extra.data.bits.has_align_body) {
35173564 const body_len = zir.extra[extra_index];
35183565 extra_index += 1;
3519 const body = zir.extra[extra_index..][0..body_len];
3566 const body = zir.bodySlice(extra_index, body_len);
35203567 try zir.findDeclsBody(list, body);
35213568 extra_index += body.len;
35223569 } else if (extra.data.bits.has_align_ref) {
......@@ -3526,7 +3573,7 @@ fn findDeclsInner(
35263573 if (extra.data.bits.has_addrspace_body) {
35273574 const body_len = zir.extra[extra_index];
35283575 extra_index += 1;
3529 const body = zir.extra[extra_index..][0..body_len];
3576 const body = zir.bodySlice(extra_index, body_len);
35303577 try zir.findDeclsBody(list, body);
35313578 extra_index += body.len;
35323579 } else if (extra.data.bits.has_addrspace_ref) {
......@@ -3536,7 +3583,7 @@ fn findDeclsInner(
35363583 if (extra.data.bits.has_section_body) {
35373584 const body_len = zir.extra[extra_index];
35383585 extra_index += 1;
3539 const body = zir.extra[extra_index..][0..body_len];
3586 const body = zir.bodySlice(extra_index, body_len);
35403587 try zir.findDeclsBody(list, body);
35413588 extra_index += body.len;
35423589 } else if (extra.data.bits.has_section_ref) {
......@@ -3546,7 +3593,7 @@ fn findDeclsInner(
35463593 if (extra.data.bits.has_cc_body) {
35473594 const body_len = zir.extra[extra_index];
35483595 extra_index += 1;
3549 const body = zir.extra[extra_index..][0..body_len];
3596 const body = zir.bodySlice(extra_index, body_len);
35503597 try zir.findDeclsBody(list, body);
35513598 extra_index += body.len;
35523599 } else if (extra.data.bits.has_cc_ref) {
......@@ -3556,7 +3603,7 @@ fn findDeclsInner(
35563603 if (extra.data.bits.has_ret_ty_body) {
35573604 const body_len = zir.extra[extra_index];
35583605 extra_index += 1;
3559 const body = zir.extra[extra_index..][0..body_len];
3606 const body = zir.bodySlice(extra_index, body_len);
35603607 try zir.findDeclsBody(list, body);
35613608 extra_index += body.len;
35623609 } else if (extra.data.bits.has_ret_ty_ref) {
......@@ -3565,11 +3612,11 @@ fn findDeclsInner(
35653612
35663613 extra_index += @intFromBool(extra.data.bits.has_any_noalias);
35673614
3568 const body = zir.extra[extra_index..][0..extra.data.body_len];
3615 const body = zir.bodySlice(extra_index, extra.data.body_len);
35693616 return zir.findDeclsBody(list, body);
35703617 },
35713618 .extended => {
3572 const extended = datas[inst].extended;
3619 const extended = datas[@intFromEnum(inst)].extended;
35733620 switch (extended.opcode) {
35743621
35753622 // Decl instructions are interesting but have no body.
......@@ -3587,23 +3634,23 @@ fn findDeclsInner(
35873634 // Block instructions, recurse over the bodies.
35883635
35893636 .block, .block_comptime, .block_inline => {
3590 const inst_data = datas[inst].pl_node;
3637 const inst_data = datas[@intFromEnum(inst)].pl_node;
35913638 const extra = zir.extraData(Inst.Block, inst_data.payload_index);
3592 const body = zir.extra[extra.end..][0..extra.data.body_len];
3639 const body = zir.bodySlice(extra.end, extra.data.body_len);
35933640 return zir.findDeclsBody(list, body);
35943641 },
35953642 .condbr, .condbr_inline => {
3596 const inst_data = datas[inst].pl_node;
3643 const inst_data = datas[@intFromEnum(inst)].pl_node;
35973644 const extra = zir.extraData(Inst.CondBr, inst_data.payload_index);
3598 const then_body = zir.extra[extra.end..][0..extra.data.then_body_len];
3599 const else_body = zir.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
3645 const then_body = zir.bodySlice(extra.end, extra.data.then_body_len);
3646 const else_body = zir.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
36003647 try zir.findDeclsBody(list, then_body);
36013648 try zir.findDeclsBody(list, else_body);
36023649 },
36033650 .@"try", .try_ptr => {
3604 const inst_data = datas[inst].pl_node;
3651 const inst_data = datas[@intFromEnum(inst)].pl_node;
36053652 const extra = zir.extraData(Inst.Try, inst_data.payload_index);
3606 const body = zir.extra[extra.end..][0..extra.data.body_len];
3653 const body = zir.bodySlice(extra.end, extra.data.body_len);
36073654 try zir.findDeclsBody(list, body);
36083655 },
36093656 .switch_block => return findDeclsSwitch(zir, list, inst),
......@@ -3619,7 +3666,7 @@ fn findDeclsSwitch(
36193666 list: *std.ArrayList(Inst.Index),
36203667 inst: Inst.Index,
36213668) Allocator.Error!void {
3622 const inst_data = zir.instructions.items(.data)[inst].pl_node;
3669 const inst_data = zir.instructions.items(.data)[@intFromEnum(inst)].pl_node;
36233670 const extra = zir.extraData(Inst.SwitchBlock, inst_data.payload_index);
36243671
36253672 var extra_index: usize = extra.end;
......@@ -3634,7 +3681,7 @@ fn findDeclsSwitch(
36343681 if (special_prong != .none) {
36353682 const body_len: u31 = @truncate(zir.extra[extra_index]);
36363683 extra_index += 1;
3637 const body = zir.extra[extra_index..][0..body_len];
3684 const body = zir.bodySlice(extra_index, body_len);
36383685 extra_index += body.len;
36393686
36403687 try zir.findDeclsBody(list, body);
......@@ -3642,20 +3689,18 @@ fn findDeclsSwitch(
36423689
36433690 {
36443691 const scalar_cases_len = extra.data.bits.scalar_cases_len;
3645 var scalar_i: usize = 0;
3646 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3692 for (0..scalar_cases_len) |_| {
36473693 extra_index += 1;
36483694 const body_len: u31 = @truncate(zir.extra[extra_index]);
36493695 extra_index += 1;
3650 const body = zir.extra[extra_index..][0..body_len];
3696 const body = zir.bodySlice(extra_index, body_len);
36513697 extra_index += body_len;
36523698
36533699 try zir.findDeclsBody(list, body);
36543700 }
36553701 }
36563702 {
3657 var multi_i: usize = 0;
3658 while (multi_i < multi_cases_len) : (multi_i += 1) {
3703 for (0..multi_cases_len) |_| {
36593704 const items_len = zir.extra[extra_index];
36603705 extra_index += 1;
36613706 const ranges_len = zir.extra[extra_index];
......@@ -3672,7 +3717,7 @@ fn findDeclsSwitch(
36723717 extra_index += 1;
36733718 }
36743719
3675 const body = zir.extra[extra_index..][0..body_len];
3720 const body = zir.bodySlice(extra_index, body_len);
36763721 extra_index += body_len;
36773722
36783723 try zir.findDeclsBody(list, body);
......@@ -3699,12 +3744,12 @@ pub const FnInfo = struct {
36993744 total_params_len: u32,
37003745};
37013746
3702pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 {
3747pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const Zir.Inst.Index {
37033748 const tags = zir.instructions.items(.tag);
37043749 const datas = zir.instructions.items(.data);
3705 const inst_data = datas[fn_inst].pl_node;
3750 const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
37063751
3707 const param_block_index = switch (tags[fn_inst]) {
3752 const param_block_index = switch (tags[@intFromEnum(fn_inst)]) {
37083753 .func, .func_inferred => blk: {
37093754 const extra = zir.extraData(Inst.Func, inst_data.payload_index);
37103755 break :blk extra.data.param_block;
......@@ -3716,8 +3761,8 @@ pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 {
37163761 else => unreachable,
37173762 };
37183763
3719 const param_block = zir.extraData(Inst.Block, datas[param_block_index].pl_node.payload_index);
3720 return zir.extra[param_block.end..][0..param_block.data.body_len];
3764 const param_block = zir.extraData(Inst.Block, datas[@intFromEnum(param_block_index)].pl_node.payload_index);
3765 return zir.bodySlice(param_block.end, param_block.data.body_len);
37213766}
37223767
37233768pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
......@@ -3728,9 +3773,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
37283773 body: []const Inst.Index,
37293774 ret_ty_ref: Inst.Ref,
37303775 ret_ty_body: []const Inst.Index,
3731 } = switch (tags[fn_inst]) {
3776 } = switch (tags[@intFromEnum(fn_inst)]) {
37323777 .func, .func_inferred => blk: {
3733 const inst_data = datas[fn_inst].pl_node;
3778 const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
37343779 const extra = zir.extraData(Inst.Func, inst_data.payload_index);
37353780
37363781 var extra_index: usize = extra.end;
......@@ -3746,12 +3791,12 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
37463791 extra_index += 1;
37473792 },
37483793 else => {
3749 ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len];
3794 ret_ty_body = zir.bodySlice(extra_index, extra.data.ret_body_len);
37503795 extra_index += ret_ty_body.len;
37513796 },
37523797 }
37533798
3754 const body = zir.extra[extra_index..][0..extra.data.body_len];
3799 const body = zir.bodySlice(extra_index, extra.data.body_len);
37553800 extra_index += body.len;
37563801
37573802 break :blk .{
......@@ -3762,7 +3807,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
37623807 };
37633808 },
37643809 .func_fancy => blk: {
3765 const inst_data = datas[fn_inst].pl_node;
3810 const inst_data = datas[@intFromEnum(fn_inst)].pl_node;
37663811 const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
37673812
37683813 var extra_index: usize = extra.end;
......@@ -3793,7 +3838,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
37933838 if (extra.data.bits.has_ret_ty_body) {
37943839 const body_len = zir.extra[extra_index];
37953840 extra_index += 1;
3796 ret_ty_body = zir.extra[extra_index..][0..body_len];
3841 ret_ty_body = zir.bodySlice(extra_index, body_len);
37973842 extra_index += ret_ty_body.len;
37983843 } else if (extra.data.bits.has_ret_ty_ref) {
37993844 ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
......@@ -3802,7 +3847,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
38023847
38033848 extra_index += @intFromBool(extra.data.bits.has_any_noalias);
38043849
3805 const body = zir.extra[extra_index..][0..extra.data.body_len];
3850 const body = zir.bodySlice(extra_index, extra.data.body_len);
38063851 extra_index += body.len;
38073852 break :blk .{
38083853 .param_block = extra.data.param_block,
......@@ -3813,14 +3858,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
38133858 },
38143859 else => unreachable,
38153860 };
3816 assert(tags[info.param_block] == .block or
3817 tags[info.param_block] == .block_comptime or
3818 tags[info.param_block] == .block_inline);
3819 const param_block = zir.extraData(Inst.Block, datas[info.param_block].pl_node.payload_index);
3820 const param_body = zir.extra[param_block.end..][0..param_block.data.body_len];
3861 switch (tags[@intFromEnum(info.param_block)]) {
3862 .block, .block_comptime, .block_inline => {}, // OK
3863 else => unreachable, // assertion failure
3864 }
3865 const param_block = zir.extraData(Inst.Block, datas[@intFromEnum(info.param_block)].pl_node.payload_index);
3866 const param_body = zir.bodySlice(param_block.end, param_block.data.body_len);
38213867 var total_params_len: u32 = 0;
38223868 for (param_body) |inst| {
3823 switch (tags[inst]) {
3869 switch (tags[@intFromEnum(inst)]) {
38243870 .param, .param_comptime, .param_anytype, .param_anytype_comptime => {
38253871 total_params_len += 1;
38263872 },
......@@ -3836,24 +3882,3 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
38363882 .total_params_len = total_params_len,
38373883 };
38383884}
3839
3840pub const ref_start_index: u32 = InternPool.static_len;
3841
3842pub fn indexToRef(inst: Inst.Index) Inst.Ref {
3843 return @enumFromInt(ref_start_index + inst);
3844}
3845
3846pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
3847 assert(inst != .none);
3848 const ref_int = @intFromEnum(inst);
3849 if (ref_int >= ref_start_index) {
3850 return ref_int - ref_start_index;
3851 } else {
3852 return null;
3853 }
3854}
3855
3856pub fn refToIndexAllowNone(inst: Inst.Ref) ?Inst.Index {
3857 if (inst == .none) return null;
3858 return refToIndex(inst);
3859}
src/print_zir.zig+109-107
......@@ -32,7 +32,7 @@ pub fn renderAsTextToFile(
3232 var raw_stream = std.io.bufferedWriter(fs_file.writer());
3333 const stream = raw_stream.writer();
3434
35 const main_struct_inst = Zir.main_struct_inst;
35 const main_struct_inst: Zir.Inst.Index = .main_struct_inst;
3636 try stream.print("%{d} ", .{main_struct_inst});
3737 try writer.writeInstToStream(stream, main_struct_inst);
3838 try stream.writeAll("\n");
......@@ -41,10 +41,9 @@ pub fn renderAsTextToFile(
4141 try stream.writeAll("Imports:\n");
4242
4343 const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index);
44 var import_i: u32 = 0;
4544 var extra_index = extra.end;
4645
47 while (import_i < extra.data.imports_len) : (import_i += 1) {
46 for (0..extra.data.imports_len) |_| {
4847 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
4948 extra_index = item.end;
5049
......@@ -197,8 +196,8 @@ const Writer = struct {
197196 inst: Zir.Inst.Index,
198197 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
199198 const tags = self.code.instructions.items(.tag);
200 const tag = tags[inst];
201 try stream.print("= {s}(", .{@tagName(tags[inst])});
199 const tag = tags[@intFromEnum(inst)];
200 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});
202201 switch (tag) {
203202 .as,
204203 .store,
......@@ -525,7 +524,7 @@ const Writer = struct {
525524 }
526525
527526 fn writeExtended(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
528 const extended = self.code.instructions.items(.data)[inst].extended;
527 const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;
529528 try stream.print("{s}(", .{@tagName(extended.opcode)});
530529 switch (extended.opcode) {
531530 .this,
......@@ -622,7 +621,7 @@ const Writer = struct {
622621 }
623622
624623 fn writeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
625 const inst_data = self.code.instructions.items(.data)[inst].bin;
624 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
626625 try self.writeInstRef(stream, inst_data.lhs);
627626 try stream.writeAll(", ");
628627 try self.writeInstRef(stream, inst_data.rhs);
......@@ -630,7 +629,7 @@ const Writer = struct {
630629 }
631630
632631 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
633 const inst_data = self.code.instructions.items(.data)[inst].bin;
632 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
634633 try self.writeInstRef(stream, inst_data.lhs);
635634 try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});
636635 }
......@@ -640,7 +639,7 @@ const Writer = struct {
640639 stream: anytype,
641640 inst: Zir.Inst.Index,
642641 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
643 const inst_data = self.code.instructions.items(.data)[inst].un_node;
642 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
644643 try self.writeInstRef(stream, inst_data.operand);
645644 try stream.writeAll(") ");
646645 try self.writeSrc(stream, inst_data.src());
......@@ -651,7 +650,7 @@ const Writer = struct {
651650 stream: anytype,
652651 inst: Zir.Inst.Index,
653652 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
654 const inst_data = self.code.instructions.items(.data)[inst].un_tok;
653 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
655654 try self.writeInstRef(stream, inst_data.operand);
656655 try stream.writeAll(") ");
657656 try self.writeSrc(stream, inst_data.src());
......@@ -662,7 +661,7 @@ const Writer = struct {
662661 stream: anytype,
663662 inst: Zir.Inst.Index,
664663 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
665 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
664 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
666665 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
667666 try self.writeInstRef(stream, extra.operand);
668667 try stream.print(", {d}) (destructure=", .{extra.expect_len});
......@@ -676,7 +675,7 @@ const Writer = struct {
676675 stream: anytype,
677676 inst: Zir.Inst.Index,
678677 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
679 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
678 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
680679 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
681680 try self.writeInstRef(stream, extra.ty);
682681 try stream.print(", {d}) ", .{extra.init_count});
......@@ -688,7 +687,7 @@ const Writer = struct {
688687 stream: anytype,
689688 inst: Zir.Inst.Index,
690689 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
691 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
690 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
692691 const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
693692 try self.writeInstRef(stream, extra.len);
694693 try stream.writeAll(", ");
......@@ -704,7 +703,7 @@ const Writer = struct {
704703 stream: anytype,
705704 inst: Zir.Inst.Index,
706705 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
707 const inst_data = self.code.instructions.items(.data)[inst].ptr_type;
706 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
708707 const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else "";
709708 const str_const = if (!inst_data.flags.is_mutable) "const, " else "";
710709 const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else "";
......@@ -745,12 +744,12 @@ const Writer = struct {
745744 }
746745
747746 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
748 const inst_data = self.code.instructions.items(.data)[inst].int;
747 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;
749748 try stream.print("{d})", .{inst_data});
750749 }
751750
752751 fn writeIntBig(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
753 const inst_data = self.code.instructions.items(.data)[inst].str;
752 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
754753 const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);
755754 const limb_bytes = self.code.string_bytes[inst_data.start..][0..byte_count];
756755 // limb_bytes is not aligned properly; we must allocate and copy the bytes
......@@ -769,12 +768,12 @@ const Writer = struct {
769768 }
770769
771770 fn writeFloat(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
772 const number = self.code.instructions.items(.data)[inst].float;
771 const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;
773772 try stream.print("{d})", .{number});
774773 }
775774
776775 fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
777 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
776 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
778777 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
779778 const src = inst_data.src();
780779 const number = extra.get();
......@@ -788,13 +787,13 @@ const Writer = struct {
788787 stream: anytype,
789788 inst: Zir.Inst.Index,
790789 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
791 const inst_data = self.code.instructions.items(.data)[inst].str;
790 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
792791 const str = inst_data.get(self.code);
793792 try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)});
794793 }
795794
796795 fn writeSliceStart(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
797 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
796 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
798797 const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
799798 try self.writeInstRef(stream, extra.lhs);
800799 try stream.writeAll(", ");
......@@ -804,7 +803,7 @@ const Writer = struct {
804803 }
805804
806805 fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
807 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
806 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
808807 const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
809808 try self.writeInstRef(stream, extra.lhs);
810809 try stream.writeAll(", ");
......@@ -816,7 +815,7 @@ const Writer = struct {
816815 }
817816
818817 fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
819 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
818 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
820819 const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
821820 try self.writeInstRef(stream, extra.lhs);
822821 try stream.writeAll(", ");
......@@ -830,7 +829,7 @@ const Writer = struct {
830829 }
831830
832831 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
833 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
832 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
834833 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
835834 try self.writeInstRef(stream, extra.lhs);
836835 try stream.writeAll(", ");
......@@ -846,7 +845,7 @@ const Writer = struct {
846845 }
847846
848847 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
849 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
848 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
850849 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
851850 try self.writeInstRef(stream, extra.union_type);
852851 try stream.writeAll(", ");
......@@ -858,7 +857,7 @@ const Writer = struct {
858857 }
859858
860859 fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
861 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
860 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
862861 const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
863862 try self.writeInstRef(stream, extra.elem_type);
864863 try stream.writeAll(", ");
......@@ -885,7 +884,7 @@ const Writer = struct {
885884 }
886885
887886 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
888 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
887 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
889888 const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
890889 try self.writeInstRef(stream, extra.mulend1);
891890 try stream.writeAll(", ");
......@@ -897,7 +896,7 @@ const Writer = struct {
897896 }
898897
899898 fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
900 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
899 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
901900 const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
902901
903902 try self.writeFlag(stream, "nodiscard ", extra.flags.ensure_result_used);
......@@ -913,7 +912,7 @@ const Writer = struct {
913912 }
914913
915914 fn writeFieldParentPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
916 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
915 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
917916 const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data;
918917 try self.writeInstRef(stream, extra.parent_type);
919918 try stream.writeAll(", ");
......@@ -938,9 +937,9 @@ const Writer = struct {
938937 }
939938
940939 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
941 const inst_data = self.code.instructions.items(.data)[inst].pl_tok;
940 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
942941 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
943 const body = self.code.extra[extra.end..][0..extra.data.body_len];
942 const body = self.code.bodySlice(extra.end, extra.data.body_len);
944943 try stream.print("\"{}\", ", .{
945944 std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)),
946945 });
......@@ -956,7 +955,7 @@ const Writer = struct {
956955 }
957956
958957 fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
959 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
958 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
960959 const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
961960 try self.writeInstRef(stream, extra.lhs);
962961 try stream.writeAll(", ");
......@@ -966,7 +965,7 @@ const Writer = struct {
966965 }
967966
968967 fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
969 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
968 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
970969 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
971970 const args = self.code.refSlice(extra.end, extra.data.operands_len);
972971 try stream.writeAll("{");
......@@ -979,13 +978,13 @@ const Writer = struct {
979978 }
980979
981980 fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
982 const inst_data = self.code.instructions.items(.data)[inst].elem_val_imm;
981 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
983982 try self.writeInstRef(stream, inst_data.operand);
984983 try stream.print(", {d})", .{inst_data.idx});
985984 }
986985
987986 fn writeArrayInitElemPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
988 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
987 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
989988 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
990989
991990 try self.writeInstRef(stream, extra.ptr);
......@@ -994,7 +993,7 @@ const Writer = struct {
994993 }
995994
996995 fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
997 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
996 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
998997 const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
999998 const decl_name = self.code.nullTerminatedString(extra.decl_name);
1000999
......@@ -1006,7 +1005,7 @@ const Writer = struct {
10061005 }
10071006
10081007 fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1009 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1008 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10101009 const extra = self.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
10111010
10121011 try self.writeInstRef(stream, extra.operand);
......@@ -1017,7 +1016,7 @@ const Writer = struct {
10171016 }
10181017
10191018 fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1020 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1019 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10211020 const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;
10221021
10231022 try self.writeInstRef(stream, extra.ptr_ty);
......@@ -1027,7 +1026,7 @@ const Writer = struct {
10271026 }
10281027
10291028 fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1030 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1029 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10311030 const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
10321031 var field_i: u32 = 0;
10331032 var extra_index = extra.end;
......@@ -1095,7 +1094,7 @@ const Writer = struct {
10951094 }
10961095
10971096 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1098 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1097 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10991098 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
11001099
11011100 try self.writeInstRef(stream, extra.elem_type);
......@@ -1108,7 +1107,7 @@ const Writer = struct {
11081107 }
11091108
11101109 fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1111 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1110 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11121111 const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
11131112
11141113 try self.writeInstRef(stream, extra.ptr);
......@@ -1121,7 +1120,7 @@ const Writer = struct {
11211120 }
11221121
11231122 fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1124 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1123 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11251124 const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
11261125
11271126 try self.writeInstRef(stream, extra.ptr);
......@@ -1136,7 +1135,7 @@ const Writer = struct {
11361135 }
11371136
11381137 fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1139 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1138 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11401139 const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
11411140 var field_i: u32 = 0;
11421141 var extra_index = extra.end;
......@@ -1157,7 +1156,7 @@ const Writer = struct {
11571156 }
11581157
11591158 fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1160 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1159 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11611160 const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
11621161 try self.writeInstRef(stream, extra.container_type);
11631162 const field_name = self.code.nullTerminatedString(extra.name_start);
......@@ -1166,7 +1165,7 @@ const Writer = struct {
11661165 }
11671166
11681167 fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1169 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1168 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11701169 const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
11711170 try self.writeInstRef(stream, extra.container_type);
11721171 try stream.writeAll(", ");
......@@ -1193,7 +1192,7 @@ const Writer = struct {
11931192 stream: anytype,
11941193 inst: Zir.Inst.Index,
11951194 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
1196 const inst_data = self.code.instructions.items(.data)[inst].inst_node;
1195 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
11971196 try self.writeInstIndex(stream, inst_data.inst);
11981197 try stream.writeAll(") ");
11991198 try self.writeSrc(stream, inst_data.src());
......@@ -1297,7 +1296,7 @@ const Writer = struct {
12971296 inst: Zir.Inst.Index,
12981297 comptime kind: enum { direct, field },
12991298 ) !void {
1300 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1299 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13011300 const ExtraType = switch (kind) {
13021301 .direct => Zir.Inst.Call,
13031302 .field => Zir.Inst.FieldCall,
......@@ -1331,7 +1330,7 @@ const Writer = struct {
13311330 const arg_end = self.code.extra[extra.end + i];
13321331 defer arg_start = arg_end;
13331332 const arg_body = body[arg_start..arg_end];
1334 try self.writeBracedBody(stream, arg_body);
1333 try self.writeBracedBody(stream, @ptrCast(arg_body));
13351334
13361335 try stream.writeAll(",\n");
13371336 }
......@@ -1345,24 +1344,24 @@ const Writer = struct {
13451344 }
13461345
13471346 fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1348 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1347 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13491348 try self.writePlNodeBlockWithoutSrc(stream, inst);
13501349 try self.writeSrc(stream, inst_data.src());
13511350 }
13521351
13531352 fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1354 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1353 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13551354 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1356 const body = self.code.extra[extra.end..][0..extra.data.body_len];
1355 const body = self.code.bodySlice(extra.end, extra.data.body_len);
13571356 try self.writeBracedBody(stream, body);
13581357 try stream.writeAll(") ");
13591358 }
13601359
13611360 fn writeCondBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1362 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1361 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13631362 const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1364 const then_body = self.code.extra[extra.end..][0..extra.data.then_body_len];
1365 const else_body = self.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1363 const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);
1364 const else_body = self.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len);
13661365 try self.writeInstRef(stream, extra.data.condition);
13671366 try stream.writeAll(", ");
13681367 try self.writeBracedBody(stream, then_body);
......@@ -1373,9 +1372,9 @@ const Writer = struct {
13731372 }
13741373
13751374 fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1376 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1375 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13771376 const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1378 const body = self.code.extra[extra.end..][0..extra.data.body_len];
1377 const body = self.code.bodySlice(extra.end, extra.data.body_len);
13791378 try self.writeInstRef(stream, extra.data.operand);
13801379 try stream.writeAll(", ");
13811380 try self.writeBracedBody(stream, body);
......@@ -1421,7 +1420,7 @@ const Writer = struct {
14211420 extra_index += 1;
14221421 try self.writeInstRef(stream, backing_int_ref);
14231422 } else {
1424 const body = self.code.extra[extra_index..][0..backing_int_body_len];
1423 const body = self.code.bodySlice(extra_index, backing_int_body_len);
14251424 extra_index += backing_int_body_len;
14261425 self.indent += 2;
14271426 try self.writeBracedDecl(stream, body);
......@@ -1535,7 +1534,7 @@ const Writer = struct {
15351534 }
15361535
15371536 if (field.type_len > 0) {
1538 const body = self.code.extra[extra_index..][0..field.type_len];
1537 const body = self.code.bodySlice(extra_index, field.type_len);
15391538 extra_index += body.len;
15401539 self.indent += 2;
15411540 try self.writeBracedDecl(stream, body);
......@@ -1543,7 +1542,7 @@ const Writer = struct {
15431542 }
15441543
15451544 if (field.align_len > 0) {
1546 const body = self.code.extra[extra_index..][0..field.align_len];
1545 const body = self.code.bodySlice(extra_index, field.align_len);
15471546 extra_index += body.len;
15481547 self.indent += 2;
15491548 try stream.writeAll(" align(");
......@@ -1553,7 +1552,7 @@ const Writer = struct {
15531552 }
15541553
15551554 if (field.init_len > 0) {
1556 const body = self.code.extra[extra_index..][0..field.init_len];
1555 const body = self.code.bodySlice(extra_index, field.init_len);
15571556 extra_index += body.len;
15581557 self.indent += 2;
15591558 try stream.writeAll(" = ");
......@@ -1639,7 +1638,7 @@ const Writer = struct {
16391638 }
16401639 try stream.writeAll(", ");
16411640
1642 const body = self.code.extra[extra_index..][0..body_len];
1641 const body = self.code.bodySlice(extra_index, body_len);
16431642 extra_index += body.len;
16441643
16451644 const prev_parent_decl_node = self.parent_decl_node;
......@@ -1742,7 +1741,7 @@ const Writer = struct {
17421741 extra_index += 1;
17431742 const decl_name_index = self.code.extra[extra_index];
17441743 extra_index += 1;
1745 const decl_index = self.code.extra[extra_index];
1744 const decl_index: Zir.Inst.Index = @enumFromInt(self.code.extra[extra_index]);
17461745 extra_index += 1;
17471746 const doc_comment_index = self.code.extra[extra_index];
17481747 extra_index += 1;
......@@ -1764,7 +1763,7 @@ const Writer = struct {
17641763 };
17651764
17661765 const pub_str = if (is_pub) "pub " else "";
1767 const hash_bytes = @as([16]u8, @bitCast(hash_u32s.*));
1766 const hash_bytes: [16]u8 = @bitCast(hash_u32s.*);
17681767 if (decl_name_index == 0) {
17691768 try stream.writeByteNTimes(' ', self.indent);
17701769 const name = if (is_exported) "usingnamespace" else "comptime";
......@@ -1810,12 +1809,12 @@ const Writer = struct {
18101809 }
18111810
18121811 if (self.recurse_decls) {
1813 const tag = self.code.instructions.items(.tag)[decl_index];
1812 const tag = self.code.instructions.items(.tag)[@intFromEnum(decl_index)];
18141813 try stream.print(" line({d}) hash({}): %{d} = {s}(", .{
18151814 line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index, @tagName(tag),
18161815 });
18171816
1818 const decl_block_inst_data = self.code.instructions.items(.data)[decl_index].pl_node;
1817 const decl_block_inst_data = self.code.instructions.items(.data)[@intFromEnum(decl_index)].pl_node;
18191818 const sub_decl_node_off = decl_block_inst_data.src_node;
18201819 self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off);
18211820 try self.writePlNodeBlockWithoutSrc(stream, decl_index);
......@@ -1888,7 +1887,7 @@ const Writer = struct {
18881887 try stream.writeAll(", ");
18891888 }
18901889
1891 const body = self.code.extra[extra_index..][0..body_len];
1890 const body = self.code.bodySlice(extra_index, body_len);
18921891 extra_index += body.len;
18931892
18941893 const prev_parent_decl_node = self.parent_decl_node;
......@@ -1988,7 +1987,7 @@ const Writer = struct {
19881987 inst: Zir.Inst.Index,
19891988 name_strategy: Zir.Inst.NameStrategy,
19901989 ) !void {
1991 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
1990 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19921991 const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
19931992
19941993 try stream.print("{s}, ", .{@tagName(name_strategy)});
......@@ -2015,7 +2014,7 @@ const Writer = struct {
20152014 }
20162015
20172016 fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2018 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2017 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20192018 const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
20202019
20212020 var extra_index: usize = extra.end;
......@@ -2029,7 +2028,7 @@ const Writer = struct {
20292028 const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: {
20302029 const tag_capture_inst = self.code.extra[extra_index];
20312030 extra_index += 1;
2032 break :blk tag_capture_inst;
2031 break :blk @enumFromInt(tag_capture_inst);
20332032 } else undefined;
20342033
20352034 try self.writeInstRef(stream, extra.data.operand);
......@@ -2057,7 +2056,7 @@ const Writer = struct {
20572056 };
20582057 const inline_text = if (info.is_inline) "inline " else "";
20592058 extra_index += 1;
2060 const body = self.code.extra[extra_index..][0..info.body_len];
2059 const body = self.code.bodySlice(extra_index, info.body_len);
20612060 extra_index += body.len;
20622061
20632062 try stream.writeAll(",\n");
......@@ -2074,7 +2073,7 @@ const Writer = struct {
20742073 extra_index += 1;
20752074 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index]));
20762075 extra_index += 1;
2077 const body = self.code.extra[extra_index..][0..info.body_len];
2076 const body = self.code.bodySlice(extra_index, info.body_len);
20782077 extra_index += info.body_len;
20792078
20802079 try stream.writeAll(",\n");
......@@ -2131,7 +2130,7 @@ const Writer = struct {
21312130 try self.writeInstRef(stream, item_last);
21322131 }
21332132
2134 const body = self.code.extra[extra_index..][0..info.body_len];
2133 const body = self.code.bodySlice(extra_index, info.body_len);
21352134 extra_index += info.body_len;
21362135 try stream.writeAll(" => ");
21372136 try self.writeBracedBody(stream, body);
......@@ -2145,7 +2144,7 @@ const Writer = struct {
21452144 }
21462145
21472146 fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2148 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2147 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
21492148 const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
21502149 const name = self.code.nullTerminatedString(extra.field_name_start);
21512150 try self.writeInstRef(stream, extra.lhs);
......@@ -2154,7 +2153,7 @@ const Writer = struct {
21542153 }
21552154
21562155 fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2157 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2156 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
21582157 const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
21592158 try self.writeInstRef(stream, extra.lhs);
21602159 try stream.writeAll(", ");
......@@ -2164,7 +2163,7 @@ const Writer = struct {
21642163 }
21652164
21662165 fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2167 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2166 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
21682167 const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
21692168 try self.writeInstRef(stream, extra.dest_type);
21702169 try stream.writeAll(", ");
......@@ -2178,7 +2177,7 @@ const Writer = struct {
21782177 stream: anytype,
21792178 inst: Zir.Inst.Index,
21802179 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2181 const src_node = self.code.instructions.items(.data)[inst].node;
2180 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
21822181 const src = LazySrcLoc.nodeOffset(src_node);
21832182 try stream.writeAll(") ");
21842183 try self.writeSrc(stream, src);
......@@ -2189,14 +2188,14 @@ const Writer = struct {
21892188 stream: anytype,
21902189 inst: Zir.Inst.Index,
21912190 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2192 const inst_data = self.code.instructions.items(.data)[inst].str_tok;
2191 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
21932192 const str = inst_data.get(self.code);
21942193 try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)});
21952194 try self.writeSrc(stream, inst_data.src());
21962195 }
21972196
21982197 fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2199 const inst_data = self.code.instructions.items(.data)[inst].str_op;
2198 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
22002199 const str = inst_data.getStr(self.code);
22012200 try self.writeInstRef(stream, inst_data.operand);
22022201 try stream.print(", \"{}\")", .{std.zig.fmtEscapes(str)});
......@@ -2208,7 +2207,7 @@ const Writer = struct {
22082207 inst: Zir.Inst.Index,
22092208 inferred_error_set: bool,
22102209 ) !void {
2211 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2210 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22122211 const src = inst_data.src();
22132212 const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index);
22142213
......@@ -2225,12 +2224,12 @@ const Writer = struct {
22252224 extra_index += 1;
22262225 },
22272226 else => {
2228 ret_ty_body = self.code.extra[extra_index..][0..extra.data.ret_body_len];
2227 ret_ty_body = self.code.bodySlice(extra_index, extra.data.ret_body_len);
22292228 extra_index += ret_ty_body.len;
22302229 },
22312230 }
22322231
2233 const body = self.code.extra[extra_index..][0..extra.data.body_len];
2232 const body = self.code.bodySlice(extra_index, extra.data.body_len);
22342233 extra_index += body.len;
22352234
22362235 var src_locs: Zir.Inst.Func.SrcLocs = undefined;
......@@ -2263,7 +2262,7 @@ const Writer = struct {
22632262 }
22642263
22652264 fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2266 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2265 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22672266 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
22682267 const src = inst_data.src();
22692268
......@@ -2289,7 +2288,7 @@ const Writer = struct {
22892288 if (extra.data.bits.has_align_body) {
22902289 const body_len = self.code.extra[extra_index];
22912290 extra_index += 1;
2292 align_body = self.code.extra[extra_index..][0..body_len];
2291 align_body = self.code.bodySlice(extra_index, body_len);
22932292 extra_index += align_body.len;
22942293 } else if (extra.data.bits.has_align_ref) {
22952294 align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -2298,7 +2297,7 @@ const Writer = struct {
22982297 if (extra.data.bits.has_addrspace_body) {
22992298 const body_len = self.code.extra[extra_index];
23002299 extra_index += 1;
2301 addrspace_body = self.code.extra[extra_index..][0..body_len];
2300 addrspace_body = self.code.bodySlice(extra_index, body_len);
23022301 extra_index += addrspace_body.len;
23032302 } else if (extra.data.bits.has_addrspace_ref) {
23042303 addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -2307,7 +2306,7 @@ const Writer = struct {
23072306 if (extra.data.bits.has_section_body) {
23082307 const body_len = self.code.extra[extra_index];
23092308 extra_index += 1;
2310 section_body = self.code.extra[extra_index..][0..body_len];
2309 section_body = self.code.bodySlice(extra_index, body_len);
23112310 extra_index += section_body.len;
23122311 } else if (extra.data.bits.has_section_ref) {
23132312 section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -2316,7 +2315,7 @@ const Writer = struct {
23162315 if (extra.data.bits.has_cc_body) {
23172316 const body_len = self.code.extra[extra_index];
23182317 extra_index += 1;
2319 cc_body = self.code.extra[extra_index..][0..body_len];
2318 cc_body = self.code.bodySlice(extra_index, body_len);
23202319 extra_index += cc_body.len;
23212320 } else if (extra.data.bits.has_cc_ref) {
23222321 cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -2325,7 +2324,7 @@ const Writer = struct {
23252324 if (extra.data.bits.has_ret_ty_body) {
23262325 const body_len = self.code.extra[extra_index];
23272326 extra_index += 1;
2328 ret_ty_body = self.code.extra[extra_index..][0..body_len];
2327 ret_ty_body = self.code.bodySlice(extra_index, body_len);
23292328 extra_index += ret_ty_body.len;
23302329 } else if (extra.data.bits.has_ret_ty_ref) {
23312330 ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -2338,7 +2337,7 @@ const Writer = struct {
23382337 break :blk x;
23392338 } else 0;
23402339
2341 const body = self.code.extra[extra_index..][0..extra.data.body_len];
2340 const body = self.code.bodySlice(extra_index, extra.data.body_len);
23422341 extra_index += body.len;
23432342
23442343 var src_locs: Zir.Inst.Func.SrcLocs = undefined;
......@@ -2423,7 +2422,7 @@ const Writer = struct {
24232422
24242423 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
24252424 const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
2426 const body = self.code.extra[extra.data.body_index..][0..extra.data.body_len];
2425 const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);
24272426 try self.writeBracedBody(stream, body);
24282427 try stream.writeAll(",[");
24292428 const args = self.code.refSlice(extra.end, extended.small);
......@@ -2435,16 +2434,16 @@ const Writer = struct {
24352434 }
24362435
24372436 fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2438 const inst_data = self.code.instructions.items(.data)[inst].bool_br;
2437 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bool_br;
24392438 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
2440 const body = self.code.extra[extra.end..][0..extra.data.body_len];
2439 const body = self.code.bodySlice(extra.end, extra.data.body_len);
24412440 try self.writeInstRef(stream, inst_data.lhs);
24422441 try stream.writeAll(", ");
24432442 try self.writeBracedBody(stream, body);
24442443 }
24452444
24462445 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2447 const int_type = self.code.instructions.items(.data)[inst].int_type;
2446 const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
24482447 const prefix: u8 = switch (int_type.signedness) {
24492448 .signed => 'i',
24502449 .unsigned => 'u',
......@@ -2454,14 +2453,14 @@ const Writer = struct {
24542453 }
24552454
24562455 fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2457 const inst_data = self.code.instructions.items(.data)[inst].save_err_ret_index;
2456 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24582457
24592458 try self.writeInstRef(stream, inst_data.operand);
24602459 try stream.writeAll(")");
24612460 }
24622461
24632462 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2464 const inst_data = self.code.instructions.items(.data)[inst].restore_err_ret_index;
2463 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
24652464
24662465 try self.writeInstRef(stream, inst_data.block);
24672466 try stream.writeAll(", ");
......@@ -2470,7 +2469,7 @@ const Writer = struct {
24702469 }
24712470
24722471 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2473 const inst_data = self.code.instructions.items(.data)[inst].@"break";
2472 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
24742473 const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
24752474
24762475 try self.writeInstIndex(stream, extra.block_inst);
......@@ -2480,7 +2479,7 @@ const Writer = struct {
24802479 }
24812480
24822481 fn writeArrayInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2483 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2482 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24842483
24852484 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
24862485 const args = self.code.refSlice(extra.end, extra.data.operands_len);
......@@ -2496,7 +2495,7 @@ const Writer = struct {
24962495 }
24972496
24982497 fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2499 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2498 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25002499
25012500 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
25022501 const args = self.code.refSlice(extra.end, extra.data.operands_len);
......@@ -2511,7 +2510,7 @@ const Writer = struct {
25112510 }
25122511
25132512 fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2514 const inst_data = self.code.instructions.items(.data)[inst].pl_node;
2513 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25152514
25162515 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
25172516 const args = self.code.refSlice(extra.end, extra.data.operands_len);
......@@ -2531,7 +2530,7 @@ const Writer = struct {
25312530 }
25322531
25332532 fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2534 const inst_data = self.code.instructions.items(.data)[inst].@"unreachable";
2533 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
25352534 try stream.writeAll(") ");
25362535 try self.writeSrc(stream, inst_data.src());
25372536 }
......@@ -2585,34 +2584,37 @@ const Writer = struct {
25852584 }
25862585
25872586 fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2588 const inst_data = self.code.instructions.items(.data)[inst].dbg_stmt;
2587 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
25892588 try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });
25902589 }
25912590
25922591 fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2593 const inst_data = self.code.instructions.items(.data)[inst].@"defer";
2594 const body = self.code.extra[inst_data.index..][0..inst_data.len];
2592 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
2593 const body = self.code.bodySlice(inst_data.index, inst_data.len);
25952594 try self.writeBracedBody(stream, body);
25962595 try stream.writeByte(')');
25972596 }
25982597
25992598 fn writeDeferErrCode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2600 const inst_data = self.code.instructions.items(.data)[inst].defer_err_code;
2599 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
26012600 const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
26022601
2603 try self.writeInstRef(stream, Zir.indexToRef(extra.remapped_err_code));
2602 try self.writeInstRef(stream, extra.remapped_err_code.toRef());
26042603 try stream.writeAll(" = ");
26052604 try self.writeInstRef(stream, inst_data.err_code);
26062605 try stream.writeAll(", ");
2607 const body = self.code.extra[extra.index..][0..extra.len];
2606 const body = self.code.bodySlice(extra.index, extra.len);
26082607 try self.writeBracedBody(stream, body);
26092608 try stream.writeByte(')');
26102609 }
26112610
26122611 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2613 const i = @intFromEnum(ref);
2614 if (i < InternPool.static_len) return stream.print("@{}", .{@as(InternPool.Index, @enumFromInt(i))});
2615 return self.writeInstIndex(stream, i - InternPool.static_len);
2612 if (ref.toIndex()) |i| {
2613 return self.writeInstIndex(stream, i);
2614 } else {
2615 const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));
2616 return stream.print("@{}", .{val});
2617 }
26162618 }
26172619
26182620 fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {