| author | |
| committer | |
| log | 62f45b802cab1337590d5c3397fca7b84d3a819b |
| tree | c0fef2d53bcd71009e6dc4f90a9aeb0f35386ca7 |
| parent | 49b9e1e69bda9080445ae10f9578262266082f91 |
This commit starts by making Zir.Inst.Index a nonexhaustive enum rather
than a u32 alias for type safety purposes, and the rest of the changes
are needed to get everything compiling again.7 files changed, 1011 insertions(+), 931 deletions(-)
src/AstGen.zig+182-175| ... | ... | @@ -13,8 +13,6 @@ const StringIndexContext = std.hash_map.StringIndexContext; |
| 13 | 13 | const isPrimitive = std.zig.primitives.isPrimitive; |
| 14 | 14 | |
| 15 | 15 | const Zir = @import("Zir.zig"); |
| 16 | const refToIndex = Zir.refToIndex; | |
| 17 | const indexToRef = Zir.indexToRef; | |
| 18 | 16 | const trace = @import("tracy.zig").trace; |
| 19 | 17 | const BuiltinFn = @import("BuiltinFn.zig"); |
| 20 | 18 | const AstRlAnnotate = @import("AstRlAnnotate.zig"); |
| ... | ... | @@ -86,13 +84,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 86 | 84 | inline for (fields) |field| { |
| 87 | 85 | astgen.extra.items[i] = switch (field.type) { |
| 88 | 86 | 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 | ||
| 90 | 92 | i32, |
| 91 | 93 | Zir.Inst.Call.Flags, |
| 92 | 94 | Zir.Inst.BuiltinCall.Flags, |
| 93 | 95 | Zir.Inst.SwitchBlock.Bits, |
| 94 | 96 | Zir.Inst.FuncFancy.Bits, |
| 95 | 97 | => @bitCast(@field(extra, field.name)), |
| 98 | ||
| 96 | 99 | else => @compileError("bad field type"), |
| 97 | 100 | }; |
| 98 | 101 | i += 1; |
| ... | ... | @@ -166,7 +169,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 166 | 169 | .Auto, |
| 167 | 170 | 0, |
| 168 | 171 | )) |struct_decl_ref| { |
| 169 | assert(refToIndex(struct_decl_ref).? == 0); | |
| 172 | assert(struct_decl_ref.toIndex().? == .main_struct_inst); | |
| 170 | 173 | } else |err| switch (err) { |
| 171 | 174 | error.OutOfMemory => return error.OutOfMemory, |
| 172 | 175 | error.AnalysisFail => {}, // Handled via compile_errors below. |
| ... | ... | @@ -1200,7 +1203,7 @@ fn suspendExpr( |
| 1200 | 1203 | } |
| 1201 | 1204 | try suspend_scope.setBlockBody(suspend_inst); |
| 1202 | 1205 | |
| 1203 | return indexToRef(suspend_inst); | |
| 1206 | return suspend_inst.toRef(); | |
| 1204 | 1207 | } |
| 1205 | 1208 | |
| 1206 | 1209 | fn awaitExpr( |
| ... | ... | @@ -1316,7 +1319,7 @@ fn fnProtoExpr( |
| 1316 | 1319 | var param_gz = block_scope.makeSubBlock(scope); |
| 1317 | 1320 | defer param_gz.unstack(); |
| 1318 | 1321 | 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); | |
| 1320 | 1323 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 1321 | 1324 | const main_tokens = tree.nodes.items(.main_token); |
| 1322 | 1325 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| ... | ... | @@ -1386,7 +1389,7 @@ fn fnProtoExpr( |
| 1386 | 1389 | try block_scope.setBlockBody(block_inst); |
| 1387 | 1390 | try gz.instructions.append(astgen.gpa, block_inst); |
| 1388 | 1391 | |
| 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); | |
| 1390 | 1393 | } |
| 1391 | 1394 | |
| 1392 | 1395 | fn arrayInitExpr( |
| ... | ... | @@ -1625,7 +1628,7 @@ fn arrayInitExprPtr( |
| 1625 | 1628 | .ptr = array_ptr_inst, |
| 1626 | 1629 | .index = @intCast(i), |
| 1627 | 1630 | }); |
| 1628 | astgen.extra.items[extra_index] = refToIndex(elem_ptr_inst).?; | |
| 1631 | astgen.extra.items[extra_index] = @intFromEnum(elem_ptr_inst.toIndex().?); | |
| 1629 | 1632 | extra_index += 1; |
| 1630 | 1633 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = elem_ptr_inst } } }, elem_init); |
| 1631 | 1634 | } |
| ... | ... | @@ -1825,7 +1828,7 @@ fn structInitExprTyped( |
| 1825 | 1828 | .name_start = str_index, |
| 1826 | 1829 | }); |
| 1827 | 1830 | setExtra(astgen, extra_index, Zir.Inst.StructInit.Item{ |
| 1828 | .field_type = refToIndex(field_ty_inst).?, | |
| 1831 | .field_type = field_ty_inst.toIndex().?, | |
| 1829 | 1832 | .init = try expr(gz, scope, .{ .rl = .{ .coerced_ty = field_ty_inst } }, field_init), |
| 1830 | 1833 | }); |
| 1831 | 1834 | extra_index += field_size; |
| ... | ... | @@ -1860,7 +1863,7 @@ fn structInitExprPtr( |
| 1860 | 1863 | .lhs = struct_ptr_inst, |
| 1861 | 1864 | .field_name_start = str_index, |
| 1862 | 1865 | }); |
| 1863 | astgen.extra.items[extra_index] = refToIndex(field_ptr).?; | |
| 1866 | astgen.extra.items[extra_index] = @intFromEnum(field_ptr.toIndex().?); | |
| 1864 | 1867 | extra_index += 1; |
| 1865 | 1868 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = field_ptr } } }, field_init); |
| 1866 | 1869 | } |
| ... | ... | @@ -1962,7 +1965,7 @@ fn comptimeExpr( |
| 1962 | 1965 | try block_scope.setBlockBody(block_inst); |
| 1963 | 1966 | try gz.instructions.append(gz.astgen.gpa, block_inst); |
| 1964 | 1967 | |
| 1965 | return rvalue(gz, ri, indexToRef(block_inst), node); | |
| 1968 | return rvalue(gz, ri, block_inst.toRef(), node); | |
| 1966 | 1969 | } |
| 1967 | 1970 | |
| 1968 | 1971 | /// 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 |
| 2048 | 2051 | break :blk label.block_inst; |
| 2049 | 2052 | } |
| 2050 | 2053 | } |
| 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; | |
| 2053 | 2056 | } |
| 2054 | 2057 | // If not the target, start over with the parent |
| 2055 | 2058 | scope = block_gz.parent; |
| ... | ... | @@ -2135,11 +2138,10 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) |
| 2135 | 2138 | ), |
| 2136 | 2139 | }); |
| 2137 | 2140 | } |
| 2138 | const continue_block = gen_zir.continue_block; | |
| 2139 | if (continue_block == 0) { | |
| 2141 | const continue_block = gen_zir.continue_block.unwrap() orelse { | |
| 2140 | 2142 | scope = gen_zir.parent; |
| 2141 | 2143 | continue; |
| 2142 | } | |
| 2144 | }; | |
| 2143 | 2145 | if (break_label != 0) blk: { |
| 2144 | 2146 | if (gen_zir.label) |*label| { |
| 2145 | 2147 | if (try astgen.tokenIdentEql(label.token, break_label)) { |
| ... | ... | @@ -2157,7 +2159,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) |
| 2157 | 2159 | else |
| 2158 | 2160 | .@"break"; |
| 2159 | 2161 | 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); | |
| 2161 | 2163 | } |
| 2162 | 2164 | |
| 2163 | 2165 | // As our last action before the continue, "pop" the error trace if needed |
| ... | ... | @@ -2333,9 +2335,9 @@ fn labeledBlockExpr( |
| 2333 | 2335 | |
| 2334 | 2336 | try block_scope.setBlockBody(block_inst); |
| 2335 | 2337 | if (need_result_rvalue) { |
| 2336 | return rvalue(gz, ri, indexToRef(block_inst), block_node); | |
| 2338 | return rvalue(gz, ri, block_inst.toRef(), block_node); | |
| 2337 | 2339 | } else { |
| 2338 | return indexToRef(block_inst); | |
| 2340 | return block_inst.toRef(); | |
| 2339 | 2341 | } |
| 2340 | 2342 | } |
| 2341 | 2343 | |
| ... | ... | @@ -2438,15 +2440,15 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2438 | 2440 | |
| 2439 | 2441 | fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: Ast.Node.Index) InnerError!Ast.Node.Index { |
| 2440 | 2442 | 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: { | |
| 2442 | 2444 | // Note that this array becomes invalid after appending more items to it |
| 2443 | 2445 | // in the above while loop. |
| 2444 | 2446 | const zir_tags = gz.astgen.instructions.items(.tag); |
| 2445 | switch (zir_tags[inst]) { | |
| 2447 | switch (zir_tags[@intFromEnum(inst)]) { | |
| 2446 | 2448 | // For some instructions, modify the zir data |
| 2447 | 2449 | // so we can avoid a separate ensure_result_used instruction. |
| 2448 | 2450 | .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; | |
| 2450 | 2452 | comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") == |
| 2451 | 2453 | std.meta.fieldIndex(Zir.Inst.FieldCall, "flags")); |
| 2452 | 2454 | 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 |
| 2456 | 2458 | break :b true; |
| 2457 | 2459 | }, |
| 2458 | 2460 | .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; | |
| 2460 | 2462 | const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[ |
| 2461 | 2463 | break_extra + std.meta.fieldIndex(Zir.Inst.BuiltinCall, "flags").? |
| 2462 | 2464 | ]); |
| ... | ... | @@ -2670,7 +2672,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2670 | 2672 | .array_init_elem_ptr, |
| 2671 | 2673 | => break :b false, |
| 2672 | 2674 | |
| 2673 | .extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) { | |
| 2675 | .extended => switch (gz.astgen.instructions.items(.data)[@intFromEnum(inst)].extended.opcode) { | |
| 2674 | 2676 | .breakpoint, |
| 2675 | 2677 | .fence, |
| 2676 | 2678 | .set_float_mode, |
| ... | ... | @@ -2783,7 +2785,7 @@ fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct { |
| 2783 | 2785 | |
| 2784 | 2786 | have_err = true; |
| 2785 | 2787 | |
| 2786 | const have_err_payload = defer_scope.remapped_err_code != 0; | |
| 2788 | const have_err_payload = defer_scope.remapped_err_code != .none; | |
| 2787 | 2789 | need_err_code = need_err_code or have_err_payload; |
| 2788 | 2790 | }, |
| 2789 | 2791 | .namespace, .enum_namespace => unreachable, |
| ... | ... | @@ -2831,18 +2833,16 @@ fn genDefers( |
| 2831 | 2833 | try gz.addDefer(defer_scope.index, defer_scope.len); |
| 2832 | 2834 | }, |
| 2833 | 2835 | .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| { | |
| 2837 | 2837 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 2838 | 2838 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 2839 | 2839 | |
| 2840 | 2840 | 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, | |
| 2842 | 2842 | .index = defer_scope.index, |
| 2843 | 2843 | .len = defer_scope.len, |
| 2844 | 2844 | }); |
| 2845 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 2845 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 2846 | 2846 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 2847 | 2847 | .tag = .defer_err_code, |
| 2848 | 2848 | .data = .{ .defer_err_code = .{ |
| ... | ... | @@ -2851,6 +2851,8 @@ fn genDefers( |
| 2851 | 2851 | } }, |
| 2852 | 2852 | }); |
| 2853 | 2853 | gz.instructions.appendAssumeCapacity(new_index); |
| 2854 | } else { | |
| 2855 | try gz.addDefer(defer_scope.index, defer_scope.len); | |
| 2854 | 2856 | } |
| 2855 | 2857 | }, |
| 2856 | 2858 | .normal_only => continue, |
| ... | ... | @@ -2916,12 +2918,13 @@ fn deferStmt( |
| 2916 | 2918 | |
| 2917 | 2919 | const payload_token = node_datas[node].lhs; |
| 2918 | 2920 | 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; | |
| 2920 | 2922 | const have_err_code = scope_tag == .defer_error and payload_token != 0; |
| 2921 | 2923 | const sub_scope = if (!have_err_code) &defer_gen.base else blk: { |
| 2922 | 2924 | try gz.addDbgBlockBegin(); |
| 2923 | 2925 | 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(); | |
| 2925 | 2928 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 2926 | 2929 | .tag = .extended, |
| 2927 | 2930 | .data = .{ .extended = .{ |
| ... | ... | @@ -2930,7 +2933,7 @@ fn deferStmt( |
| 2930 | 2933 | .operand = undefined, |
| 2931 | 2934 | } }, |
| 2932 | 2935 | }); |
| 2933 | const remapped_err_code_ref = Zir.indexToRef(remapped_err_code); | |
| 2936 | const remapped_err_code_ref = remapped_err_code.toRef(); | |
| 2934 | 2937 | local_val_scope = .{ |
| 2935 | 2938 | .parent = &defer_gen.base, |
| 2936 | 2939 | .gen_zir = gz, |
| ... | ... | @@ -2945,13 +2948,13 @@ fn deferStmt( |
| 2945 | 2948 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); |
| 2946 | 2949 | try checkUsed(gz, scope, sub_scope); |
| 2947 | 2950 | 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); | |
| 2949 | 2952 | |
| 2950 | 2953 | // We must handle ref_table for remapped_err_code manually. |
| 2951 | 2954 | const body = defer_gen.instructionsSlice(); |
| 2952 | 2955 | const body_len = blk: { |
| 2953 | 2956 | var refs: u32 = 0; |
| 2954 | if (have_err_code) { | |
| 2957 | if (opt_remapped_err_code.unwrap()) |remapped_err_code| { | |
| 2955 | 2958 | var cur_inst = remapped_err_code; |
| 2956 | 2959 | while (gz.astgen.ref_table.get(cur_inst)) |ref_inst| { |
| 2957 | 2960 | refs += 1; |
| ... | ... | @@ -2963,7 +2966,7 @@ fn deferStmt( |
| 2963 | 2966 | |
| 2964 | 2967 | const index: u32 = @intCast(gz.astgen.extra.items.len); |
| 2965 | 2968 | 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| { | |
| 2967 | 2970 | if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| { |
| 2968 | 2971 | gz.astgen.appendPossiblyRefdBodyInst(&gz.astgen.extra, kv.value); |
| 2969 | 2972 | } |
| ... | ... | @@ -2977,7 +2980,7 @@ fn deferStmt( |
| 2977 | 2980 | .parent = scope, |
| 2978 | 2981 | .index = index, |
| 2979 | 2982 | .len = body_len, |
| 2980 | .remapped_err_code = remapped_err_code, | |
| 2983 | .remapped_err_code = opt_remapped_err_code, | |
| 2981 | 2984 | }; |
| 2982 | 2985 | return &defer_scope.base; |
| 2983 | 2986 | } |
| ... | ... | @@ -3226,9 +3229,9 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void { |
| 3226 | 3229 | if (gz.instructions.items.len > 0) { |
| 3227 | 3230 | const last = gz.instructions.items[gz.instructions.items.len - 1]; |
| 3228 | 3231 | const zir_tags = astgen.instructions.items(.tag); |
| 3229 | if (zir_tags[last] == .dbg_stmt) { | |
| 3232 | if (zir_tags[@intFromEnum(last)] == .dbg_stmt) { | |
| 3230 | 3233 | const zir_datas = astgen.instructions.items(.data); |
| 3231 | zir_datas[last].dbg_stmt = .{ | |
| 3234 | zir_datas[@intFromEnum(last)].dbg_stmt = .{ | |
| 3232 | 3235 | .line = line, |
| 3233 | 3236 | .column = column, |
| 3234 | 3237 | }; |
| ... | ... | @@ -3721,8 +3724,8 @@ fn ptrType( |
| 3721 | 3724 | gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref)); |
| 3722 | 3725 | } |
| 3723 | 3726 | |
| 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(); | |
| 3726 | 3729 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ |
| 3727 | 3730 | .ptr_type = .{ |
| 3728 | 3731 | .flags = .{ |
| ... | ... | @@ -4049,7 +4052,7 @@ fn fnDecl( |
| 4049 | 4052 | var param_gz = decl_gz.makeSubBlock(scope); |
| 4050 | 4053 | defer param_gz.unstack(); |
| 4051 | 4054 | 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); | |
| 4053 | 4056 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 4054 | 4057 | |
| 4055 | 4058 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -4057,7 +4060,7 @@ fn fnDecl( |
| 4057 | 4060 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 4058 | 4061 | const param_inst = try decl_gz.addParam(&param_gz, tag, name_token, param_name, param.first_doc_comment); |
| 4059 | 4062 | assert(param_inst_expected == param_inst); |
| 4060 | break :param indexToRef(param_inst); | |
| 4063 | break :param param_inst.toRef(); | |
| 4061 | 4064 | }; |
| 4062 | 4065 | |
| 4063 | 4066 | if (param_name == 0 or is_extern) continue; |
| ... | ... | @@ -4102,7 +4105,7 @@ fn fnDecl( |
| 4102 | 4105 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4103 | 4106 | break :inst inst; |
| 4104 | 4107 | } |
| 4105 | _ = try align_gz.addBreak(.break_inline, 0, inst); | |
| 4108 | _ = try align_gz.addBreak(.break_inline, @enumFromInt(0), inst); | |
| 4106 | 4109 | break :inst inst; |
| 4107 | 4110 | }; |
| 4108 | 4111 | |
| ... | ... | @@ -4114,7 +4117,7 @@ fn fnDecl( |
| 4114 | 4117 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4115 | 4118 | break :inst inst; |
| 4116 | 4119 | } |
| 4117 | _ = try addrspace_gz.addBreak(.break_inline, 0, inst); | |
| 4120 | _ = try addrspace_gz.addBreak(.break_inline, @enumFromInt(0), inst); | |
| 4118 | 4121 | break :inst inst; |
| 4119 | 4122 | }; |
| 4120 | 4123 | |
| ... | ... | @@ -4126,7 +4129,7 @@ fn fnDecl( |
| 4126 | 4129 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4127 | 4130 | break :inst inst; |
| 4128 | 4131 | } |
| 4129 | _ = try section_gz.addBreak(.break_inline, 0, inst); | |
| 4132 | _ = try section_gz.addBreak(.break_inline, @enumFromInt(0), inst); | |
| 4130 | 4133 | break :inst inst; |
| 4131 | 4134 | }; |
| 4132 | 4135 | |
| ... | ... | @@ -4151,7 +4154,7 @@ fn fnDecl( |
| 4151 | 4154 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4152 | 4155 | break :blk inst; |
| 4153 | 4156 | } |
| 4154 | _ = try cc_gz.addBreak(.break_inline, 0, inst); | |
| 4157 | _ = try cc_gz.addBreak(.break_inline, @enumFromInt(0), inst); | |
| 4155 | 4158 | break :blk inst; |
| 4156 | 4159 | } else if (is_extern) { |
| 4157 | 4160 | // note: https://github.com/ziglang/zig/issues/5269 |
| ... | ... | @@ -4171,7 +4174,7 @@ fn fnDecl( |
| 4171 | 4174 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4172 | 4175 | break :inst inst; |
| 4173 | 4176 | } |
| 4174 | _ = try ret_gz.addBreak(.break_inline, 0, inst); | |
| 4177 | _ = try ret_gz.addBreak(.break_inline, @enumFromInt(0), inst); | |
| 4175 | 4178 | break :inst inst; |
| 4176 | 4179 | }; |
| 4177 | 4180 | |
| ... | ... | @@ -4271,7 +4274,7 @@ fn fnDecl( |
| 4271 | 4274 | wip_members.appendToDecl(line_delta); |
| 4272 | 4275 | } |
| 4273 | 4276 | wip_members.appendToDecl(fn_name_str_index); |
| 4274 | wip_members.appendToDecl(block_inst); | |
| 4277 | wip_members.appendToDecl(@intFromEnum(block_inst)); | |
| 4275 | 4278 | wip_members.appendToDecl(doc_comment_index); |
| 4276 | 4279 | } |
| 4277 | 4280 | |
| ... | ... | @@ -4421,7 +4424,7 @@ fn globalVarDecl( |
| 4421 | 4424 | wip_members.appendToDecl(line_delta); |
| 4422 | 4425 | } |
| 4423 | 4426 | wip_members.appendToDecl(name_str_index); |
| 4424 | wip_members.appendToDecl(block_inst); | |
| 4427 | wip_members.appendToDecl(@intFromEnum(block_inst)); | |
| 4425 | 4428 | wip_members.appendToDecl(doc_comment_index); // doc_comment wip |
| 4426 | 4429 | if (align_inst != .none) { |
| 4427 | 4430 | wip_members.appendToDecl(@intFromEnum(align_inst)); |
| ... | ... | @@ -4475,7 +4478,7 @@ fn comptimeDecl( |
| 4475 | 4478 | wip_members.appendToDecl(line_delta); |
| 4476 | 4479 | } |
| 4477 | 4480 | wip_members.appendToDecl(0); |
| 4478 | wip_members.appendToDecl(block_inst); | |
| 4481 | wip_members.appendToDecl(@intFromEnum(block_inst)); | |
| 4479 | 4482 | wip_members.appendToDecl(0); // no doc comments on comptime decls |
| 4480 | 4483 | } |
| 4481 | 4484 | |
| ... | ... | @@ -4526,7 +4529,7 @@ fn usingnamespaceDecl( |
| 4526 | 4529 | wip_members.appendToDecl(line_delta); |
| 4527 | 4530 | } |
| 4528 | 4531 | wip_members.appendToDecl(0); |
| 4529 | wip_members.appendToDecl(block_inst); | |
| 4532 | wip_members.appendToDecl(@intFromEnum(block_inst)); | |
| 4530 | 4533 | wip_members.appendToDecl(0); // no doc comments on usingnamespace decls |
| 4531 | 4534 | } |
| 4532 | 4535 | |
| ... | ... | @@ -4715,7 +4718,7 @@ fn testDecl( |
| 4715 | 4718 | wip_members.appendToDecl(2) // 2 here means that it is a decltest, look at doc comment for name |
| 4716 | 4719 | else |
| 4717 | 4720 | wip_members.appendToDecl(test_name); |
| 4718 | wip_members.appendToDecl(block_inst); | |
| 4721 | wip_members.appendToDecl(@intFromEnum(block_inst)); | |
| 4719 | 4722 | if (is_decltest) |
| 4720 | 4723 | wip_members.appendToDecl(test_name) // the doc comment on a decltest represents it's name |
| 4721 | 4724 | else |
| ... | ... | @@ -4747,7 +4750,7 @@ fn structDeclInner( |
| 4747 | 4750 | .any_default_inits = false, |
| 4748 | 4751 | .any_aligned_fields = false, |
| 4749 | 4752 | }); |
| 4750 | return indexToRef(decl_inst); | |
| 4753 | return decl_inst.toRef(); | |
| 4751 | 4754 | } |
| 4752 | 4755 | |
| 4753 | 4756 | const astgen = gz.astgen; |
| ... | ... | @@ -4993,7 +4996,7 @@ fn structDeclInner( |
| 4993 | 4996 | |
| 4994 | 4997 | block_scope.unstack(); |
| 4995 | 4998 | try gz.addNamespaceCaptures(&namespace); |
| 4996 | return indexToRef(decl_inst); | |
| 4999 | return decl_inst.toRef(); | |
| 4997 | 5000 | } |
| 4998 | 5001 | |
| 4999 | 5002 | fn unionDeclInner( |
| ... | ... | @@ -5154,7 +5157,7 @@ fn unionDeclInner( |
| 5154 | 5157 | |
| 5155 | 5158 | block_scope.unstack(); |
| 5156 | 5159 | try gz.addNamespaceCaptures(&namespace); |
| 5157 | return indexToRef(decl_inst); | |
| 5160 | return decl_inst.toRef(); | |
| 5158 | 5161 | } |
| 5159 | 5162 | |
| 5160 | 5163 | fn containerDecl( |
| ... | ... | @@ -5404,7 +5407,7 @@ fn containerDecl( |
| 5404 | 5407 | |
| 5405 | 5408 | block_scope.unstack(); |
| 5406 | 5409 | try gz.addNamespaceCaptures(&namespace); |
| 5407 | return rvalue(gz, ri, indexToRef(decl_inst), node); | |
| 5410 | return rvalue(gz, ri, decl_inst.toRef(), node); | |
| 5408 | 5411 | }, |
| 5409 | 5412 | .keyword_opaque => { |
| 5410 | 5413 | assert(container_decl.ast.arg == 0); |
| ... | ... | @@ -5455,7 +5458,7 @@ fn containerDecl( |
| 5455 | 5458 | |
| 5456 | 5459 | block_scope.unstack(); |
| 5457 | 5460 | try gz.addNamespaceCaptures(&namespace); |
| 5458 | return rvalue(gz, ri, indexToRef(decl_inst), node); | |
| 5461 | return rvalue(gz, ri, decl_inst.toRef(), node); | |
| 5459 | 5462 | }, |
| 5460 | 5463 | else => unreachable, |
| 5461 | 5464 | } |
| ... | ... | @@ -5642,7 +5645,7 @@ fn tryExpr( |
| 5642 | 5645 | _ = try else_scope.addUnNode(.ret_node, err_code, node); |
| 5643 | 5646 | |
| 5644 | 5647 | try else_scope.setTryBody(try_inst, operand); |
| 5645 | const result = indexToRef(try_inst); | |
| 5648 | const result = try_inst.toRef(); | |
| 5646 | 5649 | switch (ri.rl) { |
| 5647 | 5650 | .ref, .ref_coerced_ty => return result, |
| 5648 | 5651 | else => return rvalue(parent_gz, ri, result, node), |
| ... | ... | @@ -5755,9 +5758,9 @@ fn orelseCatchExpr( |
| 5755 | 5758 | try setCondBrPayload(condbr, cond, &then_scope, &else_scope); |
| 5756 | 5759 | |
| 5757 | 5760 | if (need_result_rvalue) { |
| 5758 | return rvalue(parent_gz, ri, indexToRef(block), node); | |
| 5761 | return rvalue(parent_gz, ri, block.toRef(), node); | |
| 5759 | 5762 | } else { |
| 5760 | return indexToRef(block); | |
| 5763 | return block.toRef(); | |
| 5761 | 5764 | } |
| 5762 | 5765 | } |
| 5763 | 5766 | |
| ... | ... | @@ -5916,7 +5919,7 @@ fn boolBinOp( |
| 5916 | 5919 | } |
| 5917 | 5920 | try rhs_scope.setBoolBrBody(bool_br); |
| 5918 | 5921 | |
| 5919 | const block_ref = indexToRef(bool_br); | |
| 5922 | const block_ref = bool_br.toRef(); | |
| 5920 | 5923 | return rvalue(gz, ri, block_ref, node); |
| 5921 | 5924 | } |
| 5922 | 5925 | |
| ... | ... | @@ -6116,9 +6119,9 @@ fn ifExpr( |
| 6116 | 6119 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); |
| 6117 | 6120 | |
| 6118 | 6121 | if (need_result_rvalue) { |
| 6119 | return rvalue(parent_gz, ri, indexToRef(block), node); | |
| 6122 | return rvalue(parent_gz, ri, block.toRef(), node); | |
| 6120 | 6123 | } else { |
| 6121 | return indexToRef(block); | |
| 6124 | return block.toRef(); | |
| 6122 | 6125 | } |
| 6123 | 6126 | } |
| 6124 | 6127 | |
| ... | ... | @@ -6142,7 +6145,7 @@ fn setCondBrPayload( |
| 6142 | 6145 | ); |
| 6143 | 6146 | |
| 6144 | 6147 | 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{ | |
| 6146 | 6149 | .condition = cond, |
| 6147 | 6150 | .then_body_len = then_body_len, |
| 6148 | 6151 | .else_body_len = else_body_len, |
| ... | ... | @@ -6245,7 +6248,7 @@ fn whileExpr( |
| 6245 | 6248 | |
| 6246 | 6249 | var dbg_var_name: ?u32 = null; |
| 6247 | 6250 | 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; | |
| 6249 | 6252 | var payload_val_scope: Scope.LocalVal = undefined; |
| 6250 | 6253 | const then_sub_scope = s: { |
| 6251 | 6254 | if (while_full.error_token != null) { |
| ... | ... | @@ -6255,7 +6258,8 @@ fn whileExpr( |
| 6255 | 6258 | else |
| 6256 | 6259 | .err_union_payload_unsafe; |
| 6257 | 6260 | // 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(); | |
| 6259 | 6263 | const ident_token = if (payload_is_ref) payload_token + 1 else payload_token; |
| 6260 | 6264 | const ident_bytes = tree.tokenSlice(ident_token); |
| 6261 | 6265 | if (mem.eql(u8, "_", ident_bytes)) |
| ... | ... | @@ -6267,12 +6271,12 @@ fn whileExpr( |
| 6267 | 6271 | .parent = &then_scope.base, |
| 6268 | 6272 | .gen_zir = &then_scope, |
| 6269 | 6273 | .name = ident_name, |
| 6270 | .inst = indexToRef(payload_inst), | |
| 6274 | .inst = payload_inst.toRef(), | |
| 6271 | 6275 | .token_src = payload_token, |
| 6272 | 6276 | .id_cat = .capture, |
| 6273 | 6277 | }; |
| 6274 | 6278 | dbg_var_name = ident_name; |
| 6275 | dbg_var_inst = indexToRef(payload_inst); | |
| 6279 | dbg_var_inst = payload_inst.toRef(); | |
| 6276 | 6280 | break :s &payload_val_scope.base; |
| 6277 | 6281 | } else { |
| 6278 | 6282 | _ = try then_scope.addUnNode(.ensure_err_union_payload_void, cond.inst, node); |
| ... | ... | @@ -6285,7 +6289,8 @@ fn whileExpr( |
| 6285 | 6289 | else |
| 6286 | 6290 | .optional_payload_unsafe; |
| 6287 | 6291 | // 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(); | |
| 6289 | 6294 | const ident_name = try astgen.identAsString(ident_token); |
| 6290 | 6295 | const ident_bytes = tree.tokenSlice(ident_token); |
| 6291 | 6296 | if (mem.eql(u8, "_", ident_bytes)) |
| ... | ... | @@ -6295,12 +6300,12 @@ fn whileExpr( |
| 6295 | 6300 | .parent = &then_scope.base, |
| 6296 | 6301 | .gen_zir = &then_scope, |
| 6297 | 6302 | .name = ident_name, |
| 6298 | .inst = indexToRef(payload_inst), | |
| 6303 | .inst = payload_inst.toRef(), | |
| 6299 | 6304 | .token_src = ident_token, |
| 6300 | 6305 | .id_cat = .capture, |
| 6301 | 6306 | }; |
| 6302 | 6307 | dbg_var_name = ident_name; |
| 6303 | dbg_var_inst = indexToRef(payload_inst); | |
| 6308 | dbg_var_inst = payload_inst.toRef(); | |
| 6304 | 6309 | break :s &payload_val_scope.base; |
| 6305 | 6310 | } else { |
| 6306 | 6311 | break :s &then_scope.base; |
| ... | ... | @@ -6316,8 +6321,8 @@ fn whileExpr( |
| 6316 | 6321 | _ = try loop_scope.addNode(repeat_tag, node); |
| 6317 | 6322 | |
| 6318 | 6323 | 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(); | |
| 6321 | 6326 | if (while_full.label_token) |label_token| { |
| 6322 | 6327 | loop_scope.label = .{ |
| 6323 | 6328 | .token = label_token, |
| ... | ... | @@ -6330,7 +6335,9 @@ fn whileExpr( |
| 6330 | 6335 | |
| 6331 | 6336 | try then_scope.addDbgBlockBegin(); |
| 6332 | 6337 | 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 | } | |
| 6334 | 6341 | if (dbg_var_name) |name| try then_scope.addDbgVar(.dbg_var_val, name, dbg_var_inst); |
| 6335 | 6342 | try then_scope.instructions.append(astgen.gpa, continue_block); |
| 6336 | 6343 | // This code could be improved to avoid emitting the continue expr when there |
| ... | ... | @@ -6386,8 +6393,8 @@ fn whileExpr( |
| 6386 | 6393 | }; |
| 6387 | 6394 | // Remove the continue block and break block so that `continue` and `break` |
| 6388 | 6395 | // 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; | |
| 6391 | 6398 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); |
| 6392 | 6399 | if (is_statement) { |
| 6393 | 6400 | _ = try addEnsureResult(&else_scope, else_result, else_node); |
| ... | ... | @@ -6412,9 +6419,9 @@ fn whileExpr( |
| 6412 | 6419 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); |
| 6413 | 6420 | |
| 6414 | 6421 | 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) | |
| 6416 | 6423 | else |
| 6417 | indexToRef(loop_block); | |
| 6424 | loop_block.toRef(); | |
| 6418 | 6425 | |
| 6419 | 6426 | if (is_statement) { |
| 6420 | 6427 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); |
| ... | ... | @@ -6577,8 +6584,8 @@ fn forExpr( |
| 6577 | 6584 | const cond_block = try loop_scope.makeBlockInst(block_tag, node); |
| 6578 | 6585 | try cond_scope.setBlockBody(cond_block); |
| 6579 | 6586 | |
| 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(); | |
| 6582 | 6589 | if (for_full.label_token) |label_token| { |
| 6583 | 6590 | loop_scope.label = .{ |
| 6584 | 6591 | .token = label_token, |
| ... | ... | @@ -6671,8 +6678,8 @@ fn forExpr( |
| 6671 | 6678 | const sub_scope = &else_scope.base; |
| 6672 | 6679 | // Remove the continue block and break block so that `continue` and `break` |
| 6673 | 6680 | // 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; | |
| 6676 | 6683 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); |
| 6677 | 6684 | if (is_statement) { |
| 6678 | 6685 | _ = try addEnsureResult(&else_scope, else_result, else_node); |
| ... | ... | @@ -6696,7 +6703,7 @@ fn forExpr( |
| 6696 | 6703 | // then_block and else_block unstacked now, can resurrect loop_scope to finally finish it |
| 6697 | 6704 | { |
| 6698 | 6705 | 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 }); | |
| 6700 | 6707 | |
| 6701 | 6708 | // Increment the index variable. |
| 6702 | 6709 | const index_plus_one = try loop_scope.addPlNode(.add_unsafe, node, Zir.Inst.Bin{ |
| ... | ... | @@ -6711,9 +6718,9 @@ fn forExpr( |
| 6711 | 6718 | } |
| 6712 | 6719 | |
| 6713 | 6720 | 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) | |
| 6715 | 6722 | else |
| 6716 | indexToRef(loop_block); | |
| 6723 | loop_block.toRef(); | |
| 6717 | 6724 | |
| 6718 | 6725 | if (is_statement) { |
| 6719 | 6726 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); |
| ... | ... | @@ -6912,7 +6919,7 @@ fn switchExpr( |
| 6912 | 6919 | |
| 6913 | 6920 | // If any prong has an inline tag capture, allocate a shared dummy instruction for it |
| 6914 | 6921 | 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); | |
| 6916 | 6923 | try astgen.instructions.append(astgen.gpa, .{ |
| 6917 | 6924 | .tag = .extended, |
| 6918 | 6925 | .data = .{ .extended = .{ |
| ... | ... | @@ -6967,12 +6974,12 @@ fn switchExpr( |
| 6967 | 6974 | .parent = &case_scope.base, |
| 6968 | 6975 | .gen_zir = &case_scope, |
| 6969 | 6976 | .name = capture_name, |
| 6970 | .inst = indexToRef(switch_block), | |
| 6977 | .inst = switch_block.toRef(), | |
| 6971 | 6978 | .token_src = payload_token, |
| 6972 | 6979 | .id_cat = .capture, |
| 6973 | 6980 | }; |
| 6974 | 6981 | dbg_var_name = capture_name; |
| 6975 | dbg_var_inst = indexToRef(switch_block); | |
| 6982 | dbg_var_inst = switch_block.toRef(); | |
| 6976 | 6983 | payload_sub_scope = &capture_val_scope.base; |
| 6977 | 6984 | } |
| 6978 | 6985 | |
| ... | ... | @@ -6996,12 +7003,12 @@ fn switchExpr( |
| 6996 | 7003 | .parent = payload_sub_scope, |
| 6997 | 7004 | .gen_zir = &case_scope, |
| 6998 | 7005 | .name = tag_name, |
| 6999 | .inst = indexToRef(tag_inst), | |
| 7006 | .inst = tag_inst.toRef(), | |
| 7000 | 7007 | .token_src = tag_token, |
| 7001 | 7008 | .id_cat = .@"switch tag capture", |
| 7002 | 7009 | }; |
| 7003 | 7010 | dbg_var_tag_name = tag_name; |
| 7004 | dbg_var_tag_inst = indexToRef(tag_inst); | |
| 7011 | dbg_var_tag_inst = tag_inst.toRef(); | |
| 7005 | 7012 | break :blk &tag_scope.base; |
| 7006 | 7013 | }; |
| 7007 | 7014 | |
| ... | ... | @@ -7136,11 +7143,11 @@ fn switchExpr( |
| 7136 | 7143 | } |
| 7137 | 7144 | |
| 7138 | 7145 | if (any_has_tag_capture) { |
| 7139 | astgen.extra.appendAssumeCapacity(tag_inst); | |
| 7146 | astgen.extra.appendAssumeCapacity(@intFromEnum(tag_inst)); | |
| 7140 | 7147 | } |
| 7141 | 7148 | |
| 7142 | 7149 | 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; | |
| 7144 | 7151 | |
| 7145 | 7152 | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { |
| 7146 | 7153 | var body_len_index = start_index; |
| ... | ... | @@ -7163,9 +7170,9 @@ fn switchExpr( |
| 7163 | 7170 | } |
| 7164 | 7171 | |
| 7165 | 7172 | 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); | |
| 7167 | 7174 | } else { |
| 7168 | return indexToRef(switch_block); | |
| 7175 | return switch_block.toRef(); | |
| 7169 | 7176 | } |
| 7170 | 7177 | } |
| 7171 | 7178 | |
| ... | ... | @@ -7524,13 +7531,13 @@ fn tunnelThroughClosure( |
| 7524 | 7531 | ) !Zir.Inst.Ref { |
| 7525 | 7532 | // For trivial values, we don't need a tunnel. |
| 7526 | 7533 | // Just return the ref. |
| 7527 | if (num_tunnels == 0 or refToIndex(value) == null) { | |
| 7534 | if (num_tunnels == 0 or value.toIndex() == null) { | |
| 7528 | 7535 | return value; |
| 7529 | 7536 | } |
| 7530 | 7537 | |
| 7531 | 7538 | // Otherwise we need a tunnel. Check if this namespace |
| 7532 | 7539 | // 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().?); | |
| 7534 | 7541 | if (!gop.found_existing) { |
| 7535 | 7542 | // Make a new capture for this value but don't add it to the declaring_gz yet |
| 7536 | 7543 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| ... | ... | @@ -7540,7 +7547,7 @@ fn tunnelThroughClosure( |
| 7540 | 7547 | .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token), |
| 7541 | 7548 | } }, |
| 7542 | 7549 | }); |
| 7543 | gop.value_ptr.* = @intCast(gz.astgen.instructions.len - 1); | |
| 7550 | gop.value_ptr.* = @enumFromInt(gz.astgen.instructions.len - 1); | |
| 7544 | 7551 | } |
| 7545 | 7552 | |
| 7546 | 7553 | // Add an instruction to get the value from the closure into |
| ... | ... | @@ -8032,7 +8039,7 @@ fn typeOf( |
| 8032 | 8039 | |
| 8033 | 8040 | // typeof_scope unstacked now, can add new instructions to gz |
| 8034 | 8041 | 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); | |
| 8036 | 8043 | } |
| 8037 | 8044 | const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; |
| 8038 | 8045 | const payload_index = try reserveExtra(astgen, payload_size + args.len); |
| ... | ... | @@ -8047,7 +8054,7 @@ fn typeOf( |
| 8047 | 8054 | const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node); |
| 8048 | 8055 | astgen.extra.items[args_index + i] = @intFromEnum(param_ref); |
| 8049 | 8056 | } |
| 8050 | _ = try typeof_scope.addBreak(.break_inline, refToIndex(typeof_inst).?, .void_value); | |
| 8057 | _ = try typeof_scope.addBreak(.break_inline, typeof_inst.toIndex().?, .void_value); | |
| 8051 | 8058 | |
| 8052 | 8059 | const body = typeof_scope.instructionsSlice(); |
| 8053 | 8060 | const body_len = astgen.countBodyLenAfterFixups(body); |
| ... | ... | @@ -8401,7 +8408,7 @@ fn builtinCall( |
| 8401 | 8408 | .node = gz.nodeIndexToRelative(node), |
| 8402 | 8409 | .operand = operand, |
| 8403 | 8410 | }); |
| 8404 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 8411 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 8405 | 8412 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 8406 | 8413 | .tag = .extended, |
| 8407 | 8414 | .data = .{ .extended = .{ |
| ... | ... | @@ -8411,7 +8418,7 @@ fn builtinCall( |
| 8411 | 8418 | } }, |
| 8412 | 8419 | }); |
| 8413 | 8420 | gz.instructions.appendAssumeCapacity(new_index); |
| 8414 | const result = indexToRef(new_index); | |
| 8421 | const result = new_index.toRef(); | |
| 8415 | 8422 | return rvalue(gz, ri, result, node); |
| 8416 | 8423 | }, |
| 8417 | 8424 | .panic => { |
| ... | ... | @@ -8993,7 +9000,7 @@ fn cImport( |
| 8993 | 9000 | // block_scope unstacked now, can add new instructions to gz |
| 8994 | 9001 | try gz.instructions.append(gpa, block_inst); |
| 8995 | 9002 | |
| 8996 | return indexToRef(block_inst); | |
| 9003 | return block_inst.toRef(); | |
| 8997 | 9004 | } |
| 8998 | 9005 | |
| 8999 | 9006 | fn overflowArithmetic( |
| ... | ... | @@ -9056,8 +9063,8 @@ fn callExpr( |
| 9056 | 9063 | } |
| 9057 | 9064 | assert(node != 0); |
| 9058 | 9065 | |
| 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(); | |
| 9061 | 9068 | try gz.astgen.instructions.append(astgen.gpa, undefined); |
| 9062 | 9069 | try gz.instructions.append(astgen.gpa, call_index); |
| 9063 | 9070 | |
| ... | ... | @@ -9104,7 +9111,7 @@ fn callExpr( |
| 9104 | 9111 | if (call.ast.params.len != 0) { |
| 9105 | 9112 | try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]); |
| 9106 | 9113 | } |
| 9107 | gz.astgen.instructions.set(call_index, .{ | |
| 9114 | gz.astgen.instructions.set(@intFromEnum(call_index), .{ | |
| 9108 | 9115 | .tag = .call, |
| 9109 | 9116 | .data = .{ .pl_node = .{ |
| 9110 | 9117 | .src_node = gz.nodeIndexToRelative(node), |
| ... | ... | @@ -9125,7 +9132,7 @@ fn callExpr( |
| 9125 | 9132 | if (call.ast.params.len != 0) { |
| 9126 | 9133 | try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]); |
| 9127 | 9134 | } |
| 9128 | gz.astgen.instructions.set(call_index, .{ | |
| 9135 | gz.astgen.instructions.set(@intFromEnum(call_index), .{ | |
| 9129 | 9136 | .tag = .field_call, |
| 9130 | 9137 | .data = .{ .pl_node = .{ |
| 9131 | 9138 | .src_node = gz.nodeIndexToRelative(node), |
| ... | ... | @@ -10062,10 +10069,10 @@ fn rvalueInner( |
| 10062 | 10069 | allow_coerce_pre_ref: bool, |
| 10063 | 10070 | ) InnerError!Zir.Inst.Ref { |
| 10064 | 10071 | const result = r: { |
| 10065 | if (refToIndex(raw_result)) |result_index| { | |
| 10072 | if (raw_result.toIndex()) |result_index| { | |
| 10066 | 10073 | 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)) { | |
| 10069 | 10076 | break :r Zir.Inst.Ref.void_value; |
| 10070 | 10077 | } |
| 10071 | 10078 | } |
| ... | ... | @@ -10094,16 +10101,16 @@ fn rvalueInner( |
| 10094 | 10101 | const astgen = gz.astgen; |
| 10095 | 10102 | const tree = astgen.tree; |
| 10096 | 10103 | const src_token = tree.firstToken(src_node); |
| 10097 | const result_index = refToIndex(coerced_result) orelse | |
| 10104 | const result_index = coerced_result.toIndex() orelse | |
| 10098 | 10105 | return gz.addUnTok(.ref, coerced_result, src_token); |
| 10099 | 10106 | 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)) | |
| 10101 | 10108 | return gz.addUnTok(.ref, coerced_result, src_token); |
| 10102 | 10109 | const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index); |
| 10103 | 10110 | if (!gop.found_existing) { |
| 10104 | 10111 | gop.value_ptr.* = try gz.makeUnTok(.ref, coerced_result, src_token); |
| 10105 | 10112 | } |
| 10106 | return indexToRef(gop.value_ptr.*); | |
| 10113 | return gop.value_ptr.*.toRef(); | |
| 10107 | 10114 | }, |
| 10108 | 10115 | .ty => |ty_inst| { |
| 10109 | 10116 | // Quickly eliminate some common, unnecessary type coercion. |
| ... | ... | @@ -10849,7 +10856,7 @@ const Scope = struct { |
| 10849 | 10856 | parent: *Scope, |
| 10850 | 10857 | index: u32, |
| 10851 | 10858 | len: u32, |
| 10852 | remapped_err_code: Zir.Inst.Index = 0, | |
| 10859 | remapped_err_code: Zir.Inst.OptionalIndex = .none, | |
| 10853 | 10860 | }; |
| 10854 | 10861 | |
| 10855 | 10862 | /// Represents a global scope that has any number of declarations in it. |
| ... | ... | @@ -10919,8 +10926,8 @@ const GenZir = struct { |
| 10919 | 10926 | /// if use is strictly nested. This saves prior size of list for unstacking. |
| 10920 | 10927 | instructions_top: usize, |
| 10921 | 10928 | 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, | |
| 10924 | 10931 | /// Only valid when setBreakResultInfo is called. |
| 10925 | 10932 | break_result_info: AstGen.ResultInfo = undefined, |
| 10926 | 10933 | |
| ... | ... | @@ -10995,14 +11002,14 @@ const GenZir = struct { |
| 10995 | 11002 | if (gz.isEmpty()) return false; |
| 10996 | 11003 | const tags = gz.astgen.instructions.items(.tag); |
| 10997 | 11004 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; |
| 10998 | return tags[last_inst].isNoReturn(); | |
| 11005 | return tags[@intFromEnum(last_inst)].isNoReturn(); | |
| 10999 | 11006 | } |
| 11000 | 11007 | |
| 11001 | 11008 | /// TODO all uses of this should be replaced with uses of `endsWithNoReturn`. |
| 11002 | 11009 | fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool { |
| 11003 | 11010 | 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(); | |
| 11006 | 11013 | } |
| 11007 | 11014 | return false; |
| 11008 | 11015 | } |
| ... | ... | @@ -11053,7 +11060,7 @@ const GenZir = struct { |
| 11053 | 11060 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, |
| 11054 | 11061 | ); |
| 11055 | 11062 | 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( | |
| 11057 | 11064 | Zir.Inst.Block{ .body_len = body_len }, |
| 11058 | 11065 | ); |
| 11059 | 11066 | astgen.appendBodyWithFixups(body); |
| ... | ... | @@ -11071,7 +11078,7 @@ const GenZir = struct { |
| 11071 | 11078 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, |
| 11072 | 11079 | ); |
| 11073 | 11080 | 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( | |
| 11075 | 11082 | Zir.Inst.Block{ .body_len = body_len }, |
| 11076 | 11083 | ); |
| 11077 | 11084 | astgen.appendBodyWithFixups(body); |
| ... | ... | @@ -11089,7 +11096,7 @@ const GenZir = struct { |
| 11089 | 11096 | @typeInfo(Zir.Inst.Try).Struct.fields.len + body_len, |
| 11090 | 11097 | ); |
| 11091 | 11098 | 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( | |
| 11093 | 11100 | Zir.Inst.Try{ |
| 11094 | 11101 | .operand = operand, |
| 11095 | 11102 | .body_len = body_len, |
| ... | ... | @@ -11139,7 +11146,7 @@ const GenZir = struct { |
| 11139 | 11146 | const astgen = gz.astgen; |
| 11140 | 11147 | const gpa = astgen.gpa; |
| 11141 | 11148 | 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); | |
| 11143 | 11150 | |
| 11144 | 11151 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11145 | 11152 | |
| ... | ... | @@ -11235,9 +11242,9 @@ const GenZir = struct { |
| 11235 | 11242 | if (align_body.len != 0) { |
| 11236 | 11243 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body)); |
| 11237 | 11244 | 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; | |
| 11239 | 11246 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11240 | new_index; | |
| 11247 | @intFromEnum(new_index); | |
| 11241 | 11248 | } else if (args.align_ref != .none) { |
| 11242 | 11249 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref)); |
| 11243 | 11250 | } |
| ... | ... | @@ -11245,9 +11252,9 @@ const GenZir = struct { |
| 11245 | 11252 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body)); |
| 11246 | 11253 | astgen.appendBodyWithFixups(addrspace_body); |
| 11247 | 11254 | 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; | |
| 11249 | 11256 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11250 | new_index; | |
| 11257 | @intFromEnum(new_index); | |
| 11251 | 11258 | } else if (args.addrspace_ref != .none) { |
| 11252 | 11259 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref)); |
| 11253 | 11260 | } |
| ... | ... | @@ -11255,27 +11262,27 @@ const GenZir = struct { |
| 11255 | 11262 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body)); |
| 11256 | 11263 | astgen.appendBodyWithFixups(section_body); |
| 11257 | 11264 | 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; | |
| 11259 | 11266 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11260 | new_index; | |
| 11267 | @intFromEnum(new_index); | |
| 11261 | 11268 | } else if (args.section_ref != .none) { |
| 11262 | 11269 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref)); |
| 11263 | 11270 | } |
| 11264 | 11271 | if (cc_body.len != 0) { |
| 11265 | 11272 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body)); |
| 11266 | 11273 | 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; | |
| 11268 | 11275 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11269 | new_index; | |
| 11276 | @intFromEnum(new_index); | |
| 11270 | 11277 | } else if (args.cc_ref != .none) { |
| 11271 | 11278 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref)); |
| 11272 | 11279 | } |
| 11273 | 11280 | if (ret_body.len != 0) { |
| 11274 | 11281 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body)); |
| 11275 | 11282 | 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; | |
| 11277 | 11284 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11278 | new_index; | |
| 11285 | @intFromEnum(new_index); | |
| 11279 | 11286 | } else if (ret_ref != .none) { |
| 11280 | 11287 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11281 | 11288 | } |
| ... | ... | @@ -11307,7 +11314,7 @@ const GenZir = struct { |
| 11307 | 11314 | } }, |
| 11308 | 11315 | }); |
| 11309 | 11316 | gz.instructions.appendAssumeCapacity(new_index); |
| 11310 | return indexToRef(new_index); | |
| 11317 | return new_index.toRef(); | |
| 11311 | 11318 | } else { |
| 11312 | 11319 | try astgen.extra.ensureUnusedCapacity( |
| 11313 | 11320 | gpa, |
| ... | ... | @@ -11330,9 +11337,9 @@ const GenZir = struct { |
| 11330 | 11337 | if (ret_body.len != 0) { |
| 11331 | 11338 | astgen.appendBodyWithFixups(ret_body); |
| 11332 | 11339 | |
| 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; | |
| 11334 | 11341 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11335 | new_index; | |
| 11342 | @intFromEnum(new_index); | |
| 11336 | 11343 | } else if (ret_ref != .none) { |
| 11337 | 11344 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11338 | 11345 | } |
| ... | ... | @@ -11358,7 +11365,7 @@ const GenZir = struct { |
| 11358 | 11365 | } }, |
| 11359 | 11366 | }); |
| 11360 | 11367 | gz.instructions.appendAssumeCapacity(new_index); |
| 11361 | return indexToRef(new_index); | |
| 11368 | return new_index.toRef(); | |
| 11362 | 11369 | } |
| 11363 | 11370 | } |
| 11364 | 11371 | |
| ... | ... | @@ -11402,7 +11409,7 @@ const GenZir = struct { |
| 11402 | 11409 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.init)); |
| 11403 | 11410 | } |
| 11404 | 11411 | |
| 11405 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | |
| 11412 | const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); | |
| 11406 | 11413 | astgen.instructions.appendAssumeCapacity(.{ |
| 11407 | 11414 | .tag = .extended, |
| 11408 | 11415 | .data = .{ .extended = .{ |
| ... | ... | @@ -11418,7 +11425,7 @@ const GenZir = struct { |
| 11418 | 11425 | } }, |
| 11419 | 11426 | }); |
| 11420 | 11427 | gz.instructions.appendAssumeCapacity(new_index); |
| 11421 | return indexToRef(new_index); | |
| 11428 | return new_index.toRef(); | |
| 11422 | 11429 | } |
| 11423 | 11430 | |
| 11424 | 11431 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| ... | ... | @@ -11433,7 +11440,7 @@ const GenZir = struct { |
| 11433 | 11440 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11434 | 11441 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11435 | 11442 | |
| 11436 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 11443 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 11437 | 11444 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11438 | 11445 | .tag = tag, |
| 11439 | 11446 | .data = .{ .bool_br = .{ |
| ... | ... | @@ -11459,7 +11466,7 @@ const GenZir = struct { |
| 11459 | 11466 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11460 | 11467 | try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len); |
| 11461 | 11468 | |
| 11462 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | |
| 11469 | const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); | |
| 11463 | 11470 | astgen.instructions.appendAssumeCapacity(.{ |
| 11464 | 11471 | .tag = .int_big, |
| 11465 | 11472 | .data = .{ .str = .{ |
| ... | ... | @@ -11469,7 +11476,7 @@ const GenZir = struct { |
| 11469 | 11476 | }); |
| 11470 | 11477 | gz.instructions.appendAssumeCapacity(new_index); |
| 11471 | 11478 | astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs)); |
| 11472 | return indexToRef(new_index); | |
| 11479 | return new_index.toRef(); | |
| 11473 | 11480 | } |
| 11474 | 11481 | |
| 11475 | 11482 | fn addFloat(gz: *GenZir, number: f64) !Zir.Inst.Ref { |
| ... | ... | @@ -11504,7 +11511,7 @@ const GenZir = struct { |
| 11504 | 11511 | src_node: Ast.Node.Index, |
| 11505 | 11512 | ) !Zir.Inst.Index { |
| 11506 | 11513 | 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); | |
| 11508 | 11515 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 11509 | 11516 | .tag = tag, |
| 11510 | 11517 | .data = .{ .un_node = .{ |
| ... | ... | @@ -11527,7 +11534,7 @@ const GenZir = struct { |
| 11527 | 11534 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11528 | 11535 | |
| 11529 | 11536 | 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); | |
| 11531 | 11538 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11532 | 11539 | .tag = tag, |
| 11533 | 11540 | .data = .{ .pl_node = .{ |
| ... | ... | @@ -11536,7 +11543,7 @@ const GenZir = struct { |
| 11536 | 11543 | } }, |
| 11537 | 11544 | }); |
| 11538 | 11545 | gz.instructions.appendAssumeCapacity(new_index); |
| 11539 | return indexToRef(new_index); | |
| 11546 | return new_index.toRef(); | |
| 11540 | 11547 | } |
| 11541 | 11548 | |
| 11542 | 11549 | fn addPlNodePayloadIndex( |
| ... | ... | @@ -11584,7 +11591,7 @@ const GenZir = struct { |
| 11584 | 11591 | gz.astgen.appendBodyWithFixups(param_body); |
| 11585 | 11592 | param_gz.unstack(); |
| 11586 | 11593 | |
| 11587 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 11594 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 11588 | 11595 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11589 | 11596 | .tag = tag, |
| 11590 | 11597 | .data = .{ .pl_tok = .{ |
| ... | ... | @@ -11612,7 +11619,7 @@ const GenZir = struct { |
| 11612 | 11619 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11613 | 11620 | |
| 11614 | 11621 | 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); | |
| 11616 | 11623 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11617 | 11624 | .tag = .extended, |
| 11618 | 11625 | .data = .{ .extended = .{ |
| ... | ... | @@ -11622,7 +11629,7 @@ const GenZir = struct { |
| 11622 | 11629 | } }, |
| 11623 | 11630 | }); |
| 11624 | 11631 | gz.instructions.appendAssumeCapacity(new_index); |
| 11625 | return indexToRef(new_index); | |
| 11632 | return new_index.toRef(); | |
| 11626 | 11633 | } |
| 11627 | 11634 | |
| 11628 | 11635 | fn addExtendedMultiOp( |
| ... | ... | @@ -11644,7 +11651,7 @@ const GenZir = struct { |
| 11644 | 11651 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{ |
| 11645 | 11652 | .src_node = gz.nodeIndexToRelative(node), |
| 11646 | 11653 | }); |
| 11647 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | |
| 11654 | const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); | |
| 11648 | 11655 | astgen.instructions.appendAssumeCapacity(.{ |
| 11649 | 11656 | .tag = .extended, |
| 11650 | 11657 | .data = .{ .extended = .{ |
| ... | ... | @@ -11655,7 +11662,7 @@ const GenZir = struct { |
| 11655 | 11662 | }); |
| 11656 | 11663 | gz.instructions.appendAssumeCapacity(new_index); |
| 11657 | 11664 | astgen.appendRefsAssumeCapacity(operands); |
| 11658 | return indexToRef(new_index); | |
| 11665 | return new_index.toRef(); | |
| 11659 | 11666 | } |
| 11660 | 11667 | |
| 11661 | 11668 | fn addExtendedMultiOpPayloadIndex( |
| ... | ... | @@ -11669,7 +11676,7 @@ const GenZir = struct { |
| 11669 | 11676 | |
| 11670 | 11677 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11671 | 11678 | 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); | |
| 11673 | 11680 | astgen.instructions.appendAssumeCapacity(.{ |
| 11674 | 11681 | .tag = .extended, |
| 11675 | 11682 | .data = .{ .extended = .{ |
| ... | ... | @@ -11679,7 +11686,7 @@ const GenZir = struct { |
| 11679 | 11686 | } }, |
| 11680 | 11687 | }); |
| 11681 | 11688 | gz.instructions.appendAssumeCapacity(new_index); |
| 11682 | return indexToRef(new_index); | |
| 11689 | return new_index.toRef(); | |
| 11683 | 11690 | } |
| 11684 | 11691 | |
| 11685 | 11692 | fn addUnTok( |
| ... | ... | @@ -11707,7 +11714,7 @@ const GenZir = struct { |
| 11707 | 11714 | abs_tok_index: Ast.TokenIndex, |
| 11708 | 11715 | ) !Zir.Inst.Index { |
| 11709 | 11716 | 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); | |
| 11711 | 11718 | assert(operand != .none); |
| 11712 | 11719 | try astgen.instructions.append(astgen.gpa, .{ |
| 11713 | 11720 | .tag = tag, |
| ... | ... | @@ -11771,7 +11778,7 @@ const GenZir = struct { |
| 11771 | 11778 | .data = .{ .restore_err_ret_index = .{ |
| 11772 | 11779 | .block = switch (bt) { |
| 11773 | 11780 | .ret => .none, |
| 11774 | .block => |b| Zir.indexToRef(b), | |
| 11781 | .block => |b| b.toRef(), | |
| 11775 | 11782 | }, |
| 11776 | 11783 | .operand = if (cond == .if_non_error) cond.if_non_error else .none, |
| 11777 | 11784 | } }, |
| ... | ... | @@ -11837,7 +11844,7 @@ const GenZir = struct { |
| 11837 | 11844 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11838 | 11845 | try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).Struct.fields.len); |
| 11839 | 11846 | |
| 11840 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 11847 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 11841 | 11848 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11842 | 11849 | .tag = tag, |
| 11843 | 11850 | .data = .{ .@"break" = .{ |
| ... | ... | @@ -11978,7 +11985,7 @@ const GenZir = struct { |
| 11978 | 11985 | const is_comptime: u4 = @intFromBool(args.is_comptime); |
| 11979 | 11986 | const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3); |
| 11980 | 11987 | |
| 11981 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | |
| 11988 | const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); | |
| 11982 | 11989 | astgen.instructions.appendAssumeCapacity(.{ |
| 11983 | 11990 | .tag = .extended, |
| 11984 | 11991 | .data = .{ .extended = .{ |
| ... | ... | @@ -11988,7 +11995,7 @@ const GenZir = struct { |
| 11988 | 11995 | } }, |
| 11989 | 11996 | }); |
| 11990 | 11997 | gz.instructions.appendAssumeCapacity(new_index); |
| 11991 | return indexToRef(new_index); | |
| 11998 | return new_index.toRef(); | |
| 11992 | 11999 | } |
| 11993 | 12000 | |
| 11994 | 12001 | fn addAsm( |
| ... | ... | @@ -12037,7 +12044,7 @@ const GenZir = struct { |
| 12037 | 12044 | @as(u16, @intCast(args.clobbers.len << 10)) | |
| 12038 | 12045 | (@as(u16, @intFromBool(args.is_volatile)) << 15); |
| 12039 | 12046 | |
| 12040 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | |
| 12047 | const new_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); | |
| 12041 | 12048 | astgen.instructions.appendAssumeCapacity(.{ |
| 12042 | 12049 | .tag = .extended, |
| 12043 | 12050 | .data = .{ .extended = .{ |
| ... | ... | @@ -12047,14 +12054,14 @@ const GenZir = struct { |
| 12047 | 12054 | } }, |
| 12048 | 12055 | }); |
| 12049 | 12056 | gz.instructions.appendAssumeCapacity(new_index); |
| 12050 | return indexToRef(new_index); | |
| 12057 | return new_index.toRef(); | |
| 12051 | 12058 | } |
| 12052 | 12059 | |
| 12053 | 12060 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| 12054 | 12061 | /// Does *not* append the block instruction to the scope. |
| 12055 | 12062 | /// Leaves the `payload_index` field undefined. |
| 12056 | 12063 | 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); | |
| 12058 | 12065 | const gpa = gz.astgen.gpa; |
| 12059 | 12066 | try gz.astgen.instructions.append(gpa, .{ |
| 12060 | 12067 | .tag = tag, |
| ... | ... | @@ -12071,7 +12078,7 @@ const GenZir = struct { |
| 12071 | 12078 | fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { |
| 12072 | 12079 | const gpa = gz.astgen.gpa; |
| 12073 | 12080 | 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); | |
| 12075 | 12082 | try gz.astgen.instructions.append(gpa, .{ |
| 12076 | 12083 | .tag = tag, |
| 12077 | 12084 | .data = .{ .pl_node = .{ |
| ... | ... | @@ -12119,7 +12126,7 @@ const GenZir = struct { |
| 12119 | 12126 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.backing_int_ref)); |
| 12120 | 12127 | } |
| 12121 | 12128 | } |
| 12122 | astgen.instructions.set(inst, .{ | |
| 12129 | astgen.instructions.set(@intFromEnum(inst), .{ | |
| 12123 | 12130 | .tag = .extended, |
| 12124 | 12131 | .data = .{ .extended = .{ |
| 12125 | 12132 | .opcode = .struct_decl, |
| ... | ... | @@ -12174,7 +12181,7 @@ const GenZir = struct { |
| 12174 | 12181 | if (args.decls_len != 0) { |
| 12175 | 12182 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12176 | 12183 | } |
| 12177 | astgen.instructions.set(inst, .{ | |
| 12184 | astgen.instructions.set(@intFromEnum(inst), .{ | |
| 12178 | 12185 | .tag = .extended, |
| 12179 | 12186 | .data = .{ .extended = .{ |
| 12180 | 12187 | .opcode = .union_decl, |
| ... | ... | @@ -12224,7 +12231,7 @@ const GenZir = struct { |
| 12224 | 12231 | if (args.decls_len != 0) { |
| 12225 | 12232 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12226 | 12233 | } |
| 12227 | astgen.instructions.set(inst, .{ | |
| 12234 | astgen.instructions.set(@intFromEnum(inst), .{ | |
| 12228 | 12235 | .tag = .extended, |
| 12229 | 12236 | .data = .{ .extended = .{ |
| 12230 | 12237 | .opcode = .enum_decl, |
| ... | ... | @@ -12259,7 +12266,7 @@ const GenZir = struct { |
| 12259 | 12266 | if (args.decls_len != 0) { |
| 12260 | 12267 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12261 | 12268 | } |
| 12262 | astgen.instructions.set(inst, .{ | |
| 12269 | astgen.instructions.set(@intFromEnum(inst), .{ | |
| 12263 | 12270 | .tag = .extended, |
| 12264 | 12271 | .data = .{ .extended = .{ |
| 12265 | 12272 | .opcode = .opaque_decl, |
| ... | ... | @@ -12274,7 +12281,7 @@ const GenZir = struct { |
| 12274 | 12281 | } |
| 12275 | 12282 | |
| 12276 | 12283 | fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref { |
| 12277 | return indexToRef(try gz.addAsIndex(inst)); | |
| 12284 | return (try gz.addAsIndex(inst)).toRef(); | |
| 12278 | 12285 | } |
| 12279 | 12286 | |
| 12280 | 12287 | fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index { |
| ... | ... | @@ -12282,7 +12289,7 @@ const GenZir = struct { |
| 12282 | 12289 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12283 | 12290 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12284 | 12291 | |
| 12285 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 12292 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 12286 | 12293 | gz.astgen.instructions.appendAssumeCapacity(inst); |
| 12287 | 12294 | gz.instructions.appendAssumeCapacity(new_index); |
| 12288 | 12295 | return new_index; |
| ... | ... | @@ -12293,7 +12300,7 @@ const GenZir = struct { |
| 12293 | 12300 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12294 | 12301 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12295 | 12302 | |
| 12296 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 12303 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 12297 | 12304 | gz.astgen.instructions.len += 1; |
| 12298 | 12305 | gz.instructions.appendAssumeCapacity(new_index); |
| 12299 | 12306 | return new_index; |
| ... | ... | @@ -12340,12 +12347,12 @@ const GenZir = struct { |
| 12340 | 12347 | const tags = gz.astgen.instructions.items(.tag); |
| 12341 | 12348 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; |
| 12342 | 12349 | // 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) { | |
| 12344 | 12351 | _ = gz.instructions.pop(); |
| 12345 | 12352 | return; |
| 12346 | 12353 | } |
| 12347 | 12354 | |
| 12348 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); | |
| 12355 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | |
| 12349 | 12356 | try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined }); |
| 12350 | 12357 | try gz.instructions.append(gpa, new_index); |
| 12351 | 12358 | } |
| ... | ... | @@ -12622,9 +12629,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast. |
| 12622 | 12629 | } |
| 12623 | 12630 | |
| 12624 | 12631 | fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { |
| 12625 | const inst = refToIndex(ref) orelse return false; | |
| 12632 | const inst = ref.toIndex() orelse return false; | |
| 12626 | 12633 | const zir_tags = astgen.instructions.items(.tag); |
| 12627 | return switch (zir_tags[inst]) { | |
| 12634 | return switch (zir_tags[@intFromEnum(inst)]) { | |
| 12628 | 12635 | .alloc_inferred, |
| 12629 | 12636 | .alloc_inferred_mut, |
| 12630 | 12637 | .alloc_inferred_comptime, |
| ... | ... | @@ -12633,8 +12640,8 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { |
| 12633 | 12640 | |
| 12634 | 12641 | .extended => { |
| 12635 | 12642 | 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); | |
| 12638 | 12645 | return !small.has_type; |
| 12639 | 12646 | }, |
| 12640 | 12647 | |
| ... | ... | @@ -12663,7 +12670,7 @@ fn appendPossiblyRefdBodyInst( |
| 12663 | 12670 | list: *std.ArrayListUnmanaged(u32), |
| 12664 | 12671 | body_inst: Zir.Inst.Index, |
| 12665 | 12672 | ) void { |
| 12666 | list.appendAssumeCapacity(body_inst); | |
| 12673 | list.appendAssumeCapacity(@intFromEnum(body_inst)); | |
| 12667 | 12674 | const kv = astgen.ref_table.fetchRemove(body_inst) orelse return; |
| 12668 | 12675 | const ref_inst = kv.value; |
| 12669 | 12676 | 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 { |
| 333 | 333 | file, |
| 334 | 334 | &root_scope, |
| 335 | 335 | .{}, |
| 336 | Zir.main_struct_inst, | |
| 336 | .main_struct_inst, | |
| 337 | 337 | false, |
| 338 | 338 | null, |
| 339 | 339 | ); |
| ... | ... | @@ -464,14 +464,14 @@ const Scope = struct { |
| 464 | 464 | /// Another reason is that in some places we use the pointer to uniquely |
| 465 | 465 | /// refer to a decl, as we wait for it to be analyzed. This means that |
| 466 | 466 | /// 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 { | |
| 468 | 468 | var cur: ?*const Scope = &self; |
| 469 | 469 | return while (cur) |s| : (cur = s.parent) { |
| 470 | 470 | break s.map.get(string_table_idx) orelse continue; |
| 471 | 471 | } else { |
| 472 | printWithContext( | |
| 472 | printWithOptionalContext( | |
| 473 | 473 | file, |
| 474 | inst_index, | |
| 474 | inst, | |
| 475 | 475 | "Could not find `{s}`\n\n", |
| 476 | 476 | .{file.zir.nullTerminatedString(string_table_idx)}, |
| 477 | 477 | ); |
| ... | ... | @@ -937,7 +937,7 @@ const AutodocErrors = error{ |
| 937 | 937 | /// This type is used to keep track of dangerous instruction |
| 938 | 938 | /// numbers that we definitely don't want to recurse into. |
| 939 | 939 | const CallContext = struct { |
| 940 | inst: usize, | |
| 940 | inst: Zir.Inst.Index, | |
| 941 | 941 | prev: ?*const CallContext, |
| 942 | 942 | }; |
| 943 | 943 | |
| ... | ... | @@ -954,14 +954,14 @@ fn walkInstruction( |
| 954 | 954 | file: *File, |
| 955 | 955 | parent_scope: *Scope, |
| 956 | 956 | parent_src: SrcLocInfo, |
| 957 | inst_index: usize, | |
| 957 | inst: Zir.Inst.Index, | |
| 958 | 958 | need_type: bool, // true if the caller needs us to provide also a typeRef |
| 959 | 959 | call_ctx: ?*const CallContext, |
| 960 | 960 | ) AutodocErrors!DocData.WalkResult { |
| 961 | 961 | const tags = file.zir.instructions.items(.tag); |
| 962 | 962 | const data = file.zir.instructions.items(.data); |
| 963 | 963 | |
| 964 | if (self.repurposed_insts.contains(@intCast(inst_index))) { | |
| 964 | if (self.repurposed_insts.contains(inst)) { | |
| 965 | 965 | // TODO: better handling here |
| 966 | 966 | return .{ .expr = .{ .comptimeExpr = 0 } }; |
| 967 | 967 | } |
| ... | ... | @@ -969,18 +969,18 @@ fn walkInstruction( |
| 969 | 969 | // We assume that the topmost ast_node entry corresponds to our decl |
| 970 | 970 | const self_ast_node_index = self.ast_nodes.items.len - 1; |
| 971 | 971 | |
| 972 | switch (tags[inst_index]) { | |
| 972 | switch (tags[@intFromEnum(inst)]) { | |
| 973 | 973 | else => { |
| 974 | 974 | printWithContext( |
| 975 | 975 | file, |
| 976 | inst_index, | |
| 976 | inst, | |
| 977 | 977 | "TODO: implement `{s}` for walkInstruction\n\n", |
| 978 | .{@tagName(tags[inst_index])}, | |
| 978 | .{@tagName(tags[@intFromEnum(inst)])}, | |
| 979 | 979 | ); |
| 980 | return self.cteTodo(@tagName(tags[inst_index])); | |
| 980 | return self.cteTodo(@tagName(tags[@intFromEnum(inst)])); | |
| 981 | 981 | }, |
| 982 | 982 | .import => { |
| 983 | const str_tok = data[inst_index].str_tok; | |
| 983 | const str_tok = data[@intFromEnum(inst)].str_tok; | |
| 984 | 984 | var path = str_tok.get(file.zir); |
| 985 | 985 | |
| 986 | 986 | // importFile cannot error out since all files |
| ... | ... | @@ -1048,7 +1048,7 @@ fn walkInstruction( |
| 1048 | 1048 | new_file, |
| 1049 | 1049 | &root_scope, |
| 1050 | 1050 | .{}, |
| 1051 | Zir.main_struct_inst, | |
| 1051 | .main_struct_inst, | |
| 1052 | 1052 | false, |
| 1053 | 1053 | call_ctx, |
| 1054 | 1054 | ); |
| ... | ... | @@ -1080,7 +1080,7 @@ fn walkInstruction( |
| 1080 | 1080 | new_file.file, |
| 1081 | 1081 | &new_scope, |
| 1082 | 1082 | .{}, |
| 1083 | Zir.main_struct_inst, | |
| 1083 | .main_struct_inst, | |
| 1084 | 1084 | need_type, |
| 1085 | 1085 | call_ctx, |
| 1086 | 1086 | ); |
| ... | ... | @@ -1092,7 +1092,7 @@ fn walkInstruction( |
| 1092 | 1092 | }; |
| 1093 | 1093 | }, |
| 1094 | 1094 | .ret_node => { |
| 1095 | const un_node = data[inst_index].un_node; | |
| 1095 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1096 | 1096 | return self.walkRef( |
| 1097 | 1097 | file, |
| 1098 | 1098 | parent_scope, |
| ... | ... | @@ -1103,9 +1103,9 @@ fn walkInstruction( |
| 1103 | 1103 | ); |
| 1104 | 1104 | }, |
| 1105 | 1105 | .ret_load => { |
| 1106 | const un_node = data[inst_index].un_node; | |
| 1106 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1107 | 1107 | 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().?); | |
| 1109 | 1109 | // TODO: this instruction doesn't let us know trivially if there's |
| 1110 | 1110 | // branching involved or not. For now here's the strat: |
| 1111 | 1111 | // We search backwarts until `ret_ptr` for `store_node`, |
| ... | ... | @@ -1113,7 +1113,7 @@ fn walkInstruction( |
| 1113 | 1113 | // than one, then it means that there's branching involved. |
| 1114 | 1114 | // Maybe. |
| 1115 | 1115 | |
| 1116 | var i = inst_index - 1; | |
| 1116 | var i = @intFromEnum(inst) - 1; | |
| 1117 | 1117 | var result_ref: ?Ref = null; |
| 1118 | 1118 | while (i > res_ptr_inst) : (i -= 1) { |
| 1119 | 1119 | if (tags[i] == .store_node) { |
| ... | ... | @@ -1146,7 +1146,7 @@ fn walkInstruction( |
| 1146 | 1146 | }; |
| 1147 | 1147 | }, |
| 1148 | 1148 | .closure_get => { |
| 1149 | const inst_node = data[inst_index].inst_node; | |
| 1149 | const inst_node = data[@intFromEnum(inst)].inst_node; | |
| 1150 | 1150 | return try self.walkInstruction( |
| 1151 | 1151 | file, |
| 1152 | 1152 | parent_scope, |
| ... | ... | @@ -1157,7 +1157,7 @@ fn walkInstruction( |
| 1157 | 1157 | ); |
| 1158 | 1158 | }, |
| 1159 | 1159 | .closure_capture => { |
| 1160 | const un_tok = data[inst_index].un_tok; | |
| 1160 | const un_tok = data[@intFromEnum(inst)].un_tok; | |
| 1161 | 1161 | return try self.walkRef( |
| 1162 | 1162 | file, |
| 1163 | 1163 | parent_scope, |
| ... | ... | @@ -1168,7 +1168,7 @@ fn walkInstruction( |
| 1168 | 1168 | ); |
| 1169 | 1169 | }, |
| 1170 | 1170 | .str => { |
| 1171 | const str = data[inst_index].str.get(file.zir); | |
| 1171 | const str = data[@intFromEnum(inst)].str.get(file.zir); | |
| 1172 | 1172 | |
| 1173 | 1173 | const tRef: ?DocData.Expr = if (!need_type) null else blk: { |
| 1174 | 1174 | const arrTypeId = self.types.items.len; |
| ... | ... | @@ -1204,7 +1204,7 @@ fn walkInstruction( |
| 1204 | 1204 | }; |
| 1205 | 1205 | }, |
| 1206 | 1206 | .compile_error => { |
| 1207 | const un_node = data[inst_index].un_node; | |
| 1207 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1208 | 1208 | |
| 1209 | 1209 | var operand: DocData.WalkResult = try self.walkRef( |
| 1210 | 1210 | file, |
| ... | ... | @@ -1223,7 +1223,7 @@ fn walkInstruction( |
| 1223 | 1223 | }; |
| 1224 | 1224 | }, |
| 1225 | 1225 | .enum_literal => { |
| 1226 | const str_tok = data[inst_index].str_tok; | |
| 1226 | const str_tok = data[@intFromEnum(inst)].str_tok; | |
| 1227 | 1227 | const literal = file.zir.nullTerminatedString(str_tok.start); |
| 1228 | 1228 | const type_index = self.types.items.len; |
| 1229 | 1229 | try self.types.append(self.arena, .{ |
| ... | ... | @@ -1236,7 +1236,7 @@ fn walkInstruction( |
| 1236 | 1236 | }; |
| 1237 | 1237 | }, |
| 1238 | 1238 | .int => { |
| 1239 | const int = data[inst_index].int; | |
| 1239 | const int = data[@intFromEnum(inst)].int; | |
| 1240 | 1240 | return DocData.WalkResult{ |
| 1241 | 1241 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_int_type) }, |
| 1242 | 1242 | .expr = .{ .int = .{ .value = int } }, |
| ... | ... | @@ -1244,7 +1244,7 @@ fn walkInstruction( |
| 1244 | 1244 | }, |
| 1245 | 1245 | .int_big => { |
| 1246 | 1246 | // @check |
| 1247 | const str = data[inst_index].str; //.get(file.zir); | |
| 1247 | const str = data[@intFromEnum(inst)].str; //.get(file.zir); | |
| 1248 | 1248 | const byte_count = str.len * @sizeOf(std.math.big.Limb); |
| 1249 | 1249 | const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; |
| 1250 | 1250 | |
| ... | ... | @@ -1271,7 +1271,7 @@ fn walkInstruction( |
| 1271 | 1271 | }, |
| 1272 | 1272 | |
| 1273 | 1273 | .slice_start => { |
| 1274 | const pl_node = data[inst_index].pl_node; | |
| 1274 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1275 | 1275 | const extra = file.zir.extraData(Zir.Inst.SliceStart, pl_node.payload_index); |
| 1276 | 1276 | |
| 1277 | 1277 | const slice_index = self.exprs.items.len; |
| ... | ... | @@ -1311,7 +1311,7 @@ fn walkInstruction( |
| 1311 | 1311 | }; |
| 1312 | 1312 | }, |
| 1313 | 1313 | .slice_end => { |
| 1314 | const pl_node = data[inst_index].pl_node; | |
| 1314 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1315 | 1315 | const extra = file.zir.extraData(Zir.Inst.SliceEnd, pl_node.payload_index); |
| 1316 | 1316 | |
| 1317 | 1317 | const slice_index = self.exprs.items.len; |
| ... | ... | @@ -1361,7 +1361,7 @@ fn walkInstruction( |
| 1361 | 1361 | }; |
| 1362 | 1362 | }, |
| 1363 | 1363 | .slice_sentinel => { |
| 1364 | const pl_node = data[inst_index].pl_node; | |
| 1364 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1365 | 1365 | const extra = file.zir.extraData(Zir.Inst.SliceSentinel, pl_node.payload_index); |
| 1366 | 1366 | |
| 1367 | 1367 | const slice_index = self.exprs.items.len; |
| ... | ... | @@ -1426,7 +1426,7 @@ fn walkInstruction( |
| 1426 | 1426 | }; |
| 1427 | 1427 | }, |
| 1428 | 1428 | .slice_length => { |
| 1429 | const pl_node = data[inst_index].pl_node; | |
| 1429 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1430 | 1430 | const extra = file.zir.extraData(Zir.Inst.SliceLength, pl_node.payload_index); |
| 1431 | 1431 | |
| 1432 | 1432 | const slice_index = self.exprs.items.len; |
| ... | ... | @@ -1498,7 +1498,7 @@ fn walkInstruction( |
| 1498 | 1498 | }, |
| 1499 | 1499 | |
| 1500 | 1500 | .load => { |
| 1501 | const un_node = data[inst_index].un_node; | |
| 1501 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1502 | 1502 | const operand = try self.walkRef( |
| 1503 | 1503 | file, |
| 1504 | 1504 | parent_scope, |
| ... | ... | @@ -1529,7 +1529,7 @@ fn walkInstruction( |
| 1529 | 1529 | }; |
| 1530 | 1530 | }, |
| 1531 | 1531 | .ref => { |
| 1532 | const un_tok = data[inst_index].un_tok; | |
| 1532 | const un_tok = data[@intFromEnum(inst)].un_tok; | |
| 1533 | 1533 | const operand = try self.walkRef( |
| 1534 | 1534 | file, |
| 1535 | 1535 | parent_scope, |
| ... | ... | @@ -1565,7 +1565,7 @@ fn walkInstruction( |
| 1565 | 1565 | .array_cat, |
| 1566 | 1566 | .array_mul, |
| 1567 | 1567 | => { |
| 1568 | const pl_node = data[inst_index].pl_node; | |
| 1568 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1569 | 1569 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1570 | 1570 | |
| 1571 | 1571 | const binop_index = self.exprs.items.len; |
| ... | ... | @@ -1593,7 +1593,7 @@ fn walkInstruction( |
| 1593 | 1593 | const rhs_index = self.exprs.items.len; |
| 1594 | 1594 | try self.exprs.append(self.arena, rhs.expr); |
| 1595 | 1595 | self.exprs.items[binop_index] = .{ .binOp = .{ |
| 1596 | .name = @tagName(tags[inst_index]), | |
| 1596 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 1597 | 1597 | .lhs = lhs_index, |
| 1598 | 1598 | .rhs = rhs_index, |
| 1599 | 1599 | } }; |
| ... | ... | @@ -1611,7 +1611,7 @@ fn walkInstruction( |
| 1611 | 1611 | .cmp_lt, |
| 1612 | 1612 | .cmp_lte, |
| 1613 | 1613 | => { |
| 1614 | const pl_node = data[inst_index].pl_node; | |
| 1614 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1615 | 1615 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1616 | 1616 | |
| 1617 | 1617 | const binop_index = self.exprs.items.len; |
| ... | ... | @@ -1639,7 +1639,7 @@ fn walkInstruction( |
| 1639 | 1639 | const rhs_index = self.exprs.items.len; |
| 1640 | 1640 | try self.exprs.append(self.arena, rhs.expr); |
| 1641 | 1641 | self.exprs.items[binop_index] = .{ .binOp = .{ |
| 1642 | .name = @tagName(tags[inst_index]), | |
| 1642 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 1643 | 1643 | .lhs = lhs_index, |
| 1644 | 1644 | .rhs = rhs_index, |
| 1645 | 1645 | } }; |
| ... | ... | @@ -1684,7 +1684,7 @@ fn walkInstruction( |
| 1684 | 1684 | .byte_swap, |
| 1685 | 1685 | .bit_reverse, |
| 1686 | 1686 | => { |
| 1687 | const un_node = data[inst_index].un_node; | |
| 1687 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1688 | 1688 | const bin_index = self.exprs.items.len; |
| 1689 | 1689 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); |
| 1690 | 1690 | const param = try self.walkRef( |
| ... | ... | @@ -1701,7 +1701,7 @@ fn walkInstruction( |
| 1701 | 1701 | |
| 1702 | 1702 | self.exprs.items[bin_index] = .{ |
| 1703 | 1703 | .builtin = .{ |
| 1704 | .name = @tagName(tags[inst_index]), | |
| 1704 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 1705 | 1705 | .param = param_index, |
| 1706 | 1706 | }, |
| 1707 | 1707 | }; |
| ... | ... | @@ -1715,7 +1715,7 @@ fn walkInstruction( |
| 1715 | 1715 | .bool_not, |
| 1716 | 1716 | .negate_wrap, |
| 1717 | 1717 | => { |
| 1718 | const un_node = data[inst_index].un_node; | |
| 1718 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 1719 | 1719 | const un_index = self.exprs.items.len; |
| 1720 | 1720 | try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } }); |
| 1721 | 1721 | const param = try self.walkRef( |
| ... | ... | @@ -1732,7 +1732,7 @@ fn walkInstruction( |
| 1732 | 1732 | |
| 1733 | 1733 | self.exprs.items[un_index] = .{ |
| 1734 | 1734 | .unOp = .{ |
| 1735 | .name = @tagName(tags[inst_index]), | |
| 1735 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 1736 | 1736 | .param = param_index, |
| 1737 | 1737 | }, |
| 1738 | 1738 | }; |
| ... | ... | @@ -1743,7 +1743,7 @@ fn walkInstruction( |
| 1743 | 1743 | }; |
| 1744 | 1744 | }, |
| 1745 | 1745 | .bool_br_and, .bool_br_or => { |
| 1746 | const bool_br = data[inst_index].bool_br; | |
| 1746 | const bool_br = data[@intFromEnum(inst)].bool_br; | |
| 1747 | 1747 | |
| 1748 | 1748 | const bin_index = self.exprs.items.len; |
| 1749 | 1749 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); |
| ... | ... | @@ -1764,14 +1764,14 @@ fn walkInstruction( |
| 1764 | 1764 | file, |
| 1765 | 1765 | parent_scope, |
| 1766 | 1766 | 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]), | |
| 1768 | 1768 | false, |
| 1769 | 1769 | call_ctx, |
| 1770 | 1770 | ); |
| 1771 | 1771 | const rhs_index = self.exprs.items.len; |
| 1772 | 1772 | try self.exprs.append(self.arena, rhs.expr); |
| 1773 | 1773 | |
| 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 } }; | |
| 1775 | 1775 | |
| 1776 | 1776 | return DocData.WalkResult{ |
| 1777 | 1777 | .typeRef = .{ .type = @intFromEnum(Ref.bool_type) }, |
| ... | ... | @@ -1780,7 +1780,7 @@ fn walkInstruction( |
| 1780 | 1780 | }, |
| 1781 | 1781 | .truncate => { |
| 1782 | 1782 | // 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; | |
| 1784 | 1784 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1785 | 1785 | |
| 1786 | 1786 | var rhs: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -1807,7 +1807,7 @@ fn walkInstruction( |
| 1807 | 1807 | call_ctx, |
| 1808 | 1808 | ); |
| 1809 | 1809 | |
| 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 } }; | |
| 1811 | 1811 | |
| 1812 | 1812 | return DocData.WalkResult{ |
| 1813 | 1813 | .typeRef = lhs.expr, |
| ... | ... | @@ -1841,7 +1841,7 @@ fn walkInstruction( |
| 1841 | 1841 | .min, |
| 1842 | 1842 | .max, |
| 1843 | 1843 | => { |
| 1844 | const pl_node = data[inst_index].pl_node; | |
| 1844 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1845 | 1845 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1846 | 1846 | |
| 1847 | 1847 | const binop_index = self.exprs.items.len; |
| ... | ... | @@ -1868,7 +1868,7 @@ fn walkInstruction( |
| 1868 | 1868 | try self.exprs.append(self.arena, lhs.expr); |
| 1869 | 1869 | const rhs_index = self.exprs.items.len; |
| 1870 | 1870 | 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 } }; | |
| 1872 | 1872 | |
| 1873 | 1873 | return DocData.WalkResult{ |
| 1874 | 1874 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| ... | ... | @@ -1876,7 +1876,7 @@ fn walkInstruction( |
| 1876 | 1876 | }; |
| 1877 | 1877 | }, |
| 1878 | 1878 | .mul_add => { |
| 1879 | const pl_node = data[inst_index].pl_node; | |
| 1879 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1880 | 1880 | const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); |
| 1881 | 1881 | |
| 1882 | 1882 | var mul1: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -1927,7 +1927,7 @@ fn walkInstruction( |
| 1927 | 1927 | }; |
| 1928 | 1928 | }, |
| 1929 | 1929 | .union_init => { |
| 1930 | const pl_node = data[inst_index].pl_node; | |
| 1930 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1931 | 1931 | const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); |
| 1932 | 1932 | |
| 1933 | 1933 | var union_type: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -1974,7 +1974,7 @@ fn walkInstruction( |
| 1974 | 1974 | }; |
| 1975 | 1975 | }, |
| 1976 | 1976 | .builtin_call => { |
| 1977 | const pl_node = data[inst_index].pl_node; | |
| 1977 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 1978 | 1978 | const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); |
| 1979 | 1979 | |
| 1980 | 1980 | var modifier: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -2022,7 +2022,7 @@ fn walkInstruction( |
| 2022 | 2022 | }; |
| 2023 | 2023 | }, |
| 2024 | 2024 | .error_union_type => { |
| 2025 | const pl_node = data[inst_index].pl_node; | |
| 2025 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2026 | 2026 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2027 | 2027 | |
| 2028 | 2028 | var lhs: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -2054,7 +2054,7 @@ fn walkInstruction( |
| 2054 | 2054 | }; |
| 2055 | 2055 | }, |
| 2056 | 2056 | .merge_error_sets => { |
| 2057 | const pl_node = data[inst_index].pl_node; | |
| 2057 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2058 | 2058 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2059 | 2059 | |
| 2060 | 2060 | var lhs: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -2085,7 +2085,7 @@ fn walkInstruction( |
| 2085 | 2085 | }; |
| 2086 | 2086 | }, |
| 2087 | 2087 | // .elem_type => { |
| 2088 | // const un_node = data[inst_index].un_node; | |
| 2088 | // const un_node = data[@intFromEnum(inst)].un_node; | |
| 2089 | 2089 | |
| 2090 | 2090 | // var operand: DocData.WalkResult = try self.walkRef( |
| 2091 | 2091 | // file, |
| ... | ... | @@ -2097,7 +2097,7 @@ fn walkInstruction( |
| 2097 | 2097 | // return operand; |
| 2098 | 2098 | // }, |
| 2099 | 2099 | .ptr_type => { |
| 2100 | const ptr = data[inst_index].ptr_type; | |
| 2100 | const ptr = data[@intFromEnum(inst)].ptr_type; | |
| 2101 | 2101 | const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); |
| 2102 | 2102 | var extra_index = extra.end; |
| 2103 | 2103 | |
| ... | ... | @@ -2208,7 +2208,7 @@ fn walkInstruction( |
| 2208 | 2208 | }; |
| 2209 | 2209 | }, |
| 2210 | 2210 | .array_type => { |
| 2211 | const pl_node = data[inst_index].pl_node; | |
| 2211 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2212 | 2212 | |
| 2213 | 2213 | const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 2214 | 2214 | const len = try self.walkRef( |
| ... | ... | @@ -2242,7 +2242,7 @@ fn walkInstruction( |
| 2242 | 2242 | }; |
| 2243 | 2243 | }, |
| 2244 | 2244 | .array_type_sentinel => { |
| 2245 | const pl_node = data[inst_index].pl_node; | |
| 2245 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2246 | 2246 | const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index); |
| 2247 | 2247 | const len = try self.walkRef( |
| 2248 | 2248 | file, |
| ... | ... | @@ -2283,7 +2283,7 @@ fn walkInstruction( |
| 2283 | 2283 | }; |
| 2284 | 2284 | }, |
| 2285 | 2285 | .array_init => { |
| 2286 | const pl_node = data[inst_index].pl_node; | |
| 2286 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2287 | 2287 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2288 | 2288 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2289 | 2289 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| ... | ... | @@ -2318,7 +2318,7 @@ fn walkInstruction( |
| 2318 | 2318 | }; |
| 2319 | 2319 | }, |
| 2320 | 2320 | .array_init_anon => { |
| 2321 | const pl_node = data[inst_index].pl_node; | |
| 2321 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2322 | 2322 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2323 | 2323 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2324 | 2324 | const array_data = try self.arena.alloc(usize, operands.len); |
| ... | ... | @@ -2343,7 +2343,7 @@ fn walkInstruction( |
| 2343 | 2343 | }; |
| 2344 | 2344 | }, |
| 2345 | 2345 | .array_init_ref => { |
| 2346 | const pl_node = data[inst_index].pl_node; | |
| 2346 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2347 | 2347 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2348 | 2348 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2349 | 2349 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| ... | ... | @@ -2389,7 +2389,7 @@ fn walkInstruction( |
| 2389 | 2389 | }; |
| 2390 | 2390 | }, |
| 2391 | 2391 | .float => { |
| 2392 | const float = data[inst_index].float; | |
| 2392 | const float = data[@intFromEnum(inst)].float; | |
| 2393 | 2393 | return DocData.WalkResult{ |
| 2394 | 2394 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, |
| 2395 | 2395 | .expr = .{ .float = float }, |
| ... | ... | @@ -2397,7 +2397,7 @@ fn walkInstruction( |
| 2397 | 2397 | }, |
| 2398 | 2398 | // @check: In frontend I'm handling float128 with `.toFixed(2)` |
| 2399 | 2399 | .float128 => { |
| 2400 | const pl_node = data[inst_index].pl_node; | |
| 2400 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2401 | 2401 | const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index); |
| 2402 | 2402 | return DocData.WalkResult{ |
| 2403 | 2403 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, |
| ... | ... | @@ -2405,7 +2405,7 @@ fn walkInstruction( |
| 2405 | 2405 | }; |
| 2406 | 2406 | }, |
| 2407 | 2407 | .negate => { |
| 2408 | const un_node = data[inst_index].un_node; | |
| 2408 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2409 | 2409 | |
| 2410 | 2410 | var operand: DocData.WalkResult = try self.walkRef( |
| 2411 | 2411 | file, |
| ... | ... | @@ -2425,7 +2425,7 @@ fn walkInstruction( |
| 2425 | 2425 | try self.exprs.append(self.arena, operand.expr); |
| 2426 | 2426 | self.exprs.items[un_index] = .{ |
| 2427 | 2427 | .unOp = .{ |
| 2428 | .name = @tagName(tags[inst_index]), | |
| 2428 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 2429 | 2429 | .param = param_index, |
| 2430 | 2430 | }, |
| 2431 | 2431 | }; |
| ... | ... | @@ -2438,7 +2438,7 @@ fn walkInstruction( |
| 2438 | 2438 | return operand; |
| 2439 | 2439 | }, |
| 2440 | 2440 | .size_of => { |
| 2441 | const un_node = data[inst_index].un_node; | |
| 2441 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2442 | 2442 | |
| 2443 | 2443 | const operand = try self.walkRef( |
| 2444 | 2444 | file, |
| ... | ... | @@ -2457,7 +2457,7 @@ fn walkInstruction( |
| 2457 | 2457 | }, |
| 2458 | 2458 | .bit_size_of => { |
| 2459 | 2459 | // not working correctly with `align()` |
| 2460 | const un_node = data[inst_index].un_node; | |
| 2460 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2461 | 2461 | |
| 2462 | 2462 | const operand = try self.walkRef( |
| 2463 | 2463 | file, |
| ... | ... | @@ -2477,7 +2477,7 @@ fn walkInstruction( |
| 2477 | 2477 | }, |
| 2478 | 2478 | .int_from_enum => { |
| 2479 | 2479 | // not working correctly with `align()` |
| 2480 | const un_node = data[inst_index].un_node; | |
| 2480 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2481 | 2481 | const operand = try self.walkRef( |
| 2482 | 2482 | file, |
| 2483 | 2483 | parent_scope, |
| ... | ... | @@ -2492,7 +2492,7 @@ fn walkInstruction( |
| 2492 | 2492 | try self.exprs.append(self.arena, operand.expr); |
| 2493 | 2493 | self.exprs.items[builtin_index] = .{ |
| 2494 | 2494 | .builtin = .{ |
| 2495 | .name = @tagName(tags[inst_index]), | |
| 2495 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 2496 | 2496 | .param = operand_index, |
| 2497 | 2497 | }, |
| 2498 | 2498 | }; |
| ... | ... | @@ -2504,7 +2504,7 @@ fn walkInstruction( |
| 2504 | 2504 | }, |
| 2505 | 2505 | .switch_block => { |
| 2506 | 2506 | // WIP |
| 2507 | const pl_node = data[inst_index].pl_node; | |
| 2507 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2508 | 2508 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); |
| 2509 | 2509 | |
| 2510 | 2510 | const switch_cond = try self.walkRef( |
| ... | ... | @@ -2553,7 +2553,7 @@ fn walkInstruction( |
| 2553 | 2553 | }, |
| 2554 | 2554 | |
| 2555 | 2555 | .typeof => { |
| 2556 | const un_node = data[inst_index].un_node; | |
| 2556 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2557 | 2557 | |
| 2558 | 2558 | const operand = try self.walkRef( |
| 2559 | 2559 | file, |
| ... | ... | @@ -2572,7 +2572,7 @@ fn walkInstruction( |
| 2572 | 2572 | }; |
| 2573 | 2573 | }, |
| 2574 | 2574 | .typeof_builtin => { |
| 2575 | const pl_node = data[inst_index].pl_node; | |
| 2575 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2576 | 2576 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 2577 | 2577 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 2578 | 2578 | var operand: DocData.WalkResult = try self.walkRef( |
| ... | ... | @@ -2593,11 +2593,11 @@ fn walkInstruction( |
| 2593 | 2593 | }; |
| 2594 | 2594 | }, |
| 2595 | 2595 | .as_node, .as_shift_operand => { |
| 2596 | const pl_node = data[inst_index].pl_node; | |
| 2596 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2597 | 2597 | const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index); |
| 2598 | 2598 | |
| 2599 | 2599 | // 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| { | |
| 2601 | 2601 | var maybe_cc = call_ctx; |
| 2602 | 2602 | while (maybe_cc) |cc| : (maybe_cc = cc.prev) { |
| 2603 | 2603 | if (cc.inst == dti) { |
| ... | ... | @@ -2650,7 +2650,7 @@ fn walkInstruction( |
| 2650 | 2650 | }; |
| 2651 | 2651 | }, |
| 2652 | 2652 | .optional_type => { |
| 2653 | const un_node = data[inst_index].un_node; | |
| 2653 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2654 | 2654 | |
| 2655 | 2655 | const operand: DocData.WalkResult = try self.walkRef( |
| 2656 | 2656 | file, |
| ... | ... | @@ -2672,14 +2672,14 @@ fn walkInstruction( |
| 2672 | 2672 | }; |
| 2673 | 2673 | }, |
| 2674 | 2674 | .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()); | |
| 2677 | 2677 | return DocData.WalkResult{ |
| 2678 | 2678 | .expr = .{ .declRef = decl_status }, |
| 2679 | 2679 | }; |
| 2680 | 2680 | }, |
| 2681 | 2681 | .field_val, .field_ptr => { |
| 2682 | const pl_node = data[inst_index].pl_node; | |
| 2682 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2683 | 2683 | const extra = file.zir.extraData(Zir.Inst.Field, pl_node.payload_index); |
| 2684 | 2684 | |
| 2685 | 2685 | var path: std.ArrayListUnmanaged(DocData.Expr) = .{}; |
| ... | ... | @@ -2692,12 +2692,15 @@ fn walkInstruction( |
| 2692 | 2692 | const lhs_ref = blk: { |
| 2693 | 2693 | var lhs_extra = extra; |
| 2694 | 2694 | while (true) { |
| 2695 | const lhs = Zir.refToIndex(lhs_extra.data.lhs) orelse { | |
| 2695 | const lhs = @intFromEnum(lhs_extra.data.lhs.toIndex() orelse { | |
| 2696 | 2696 | break :blk lhs_extra.data.lhs; |
| 2697 | }; | |
| 2697 | }); | |
| 2698 | 2698 | |
| 2699 | 2699 | 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 | } | |
| 2701 | 2704 | |
| 2702 | 2705 | lhs_extra = file.zir.extraData( |
| 2703 | 2706 | Zir.Inst.Field, |
| ... | ... | @@ -2721,15 +2724,16 @@ fn walkInstruction( |
| 2721 | 2724 | // TODO: double check that we really don't need type info here |
| 2722 | 2725 | |
| 2723 | 2726 | 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 => { | |
| 2726 | 2729 | break :blk DocData.WalkResult{ |
| 2727 | 2730 | .expr = .{ |
| 2728 | 2731 | .comptimeExpr = 0, |
| 2729 | 2732 | }, |
| 2730 | 2733 | }; |
| 2731 | } | |
| 2732 | } | |
| 2734 | }, | |
| 2735 | else => {}, | |
| 2736 | }; | |
| 2733 | 2737 | |
| 2734 | 2738 | break :blk try self.walkRef( |
| 2735 | 2739 | file, |
| ... | ... | @@ -2758,11 +2762,11 @@ fn walkInstruction( |
| 2758 | 2762 | // - (2) Paths can sometimes never resolve fully. This means that |
| 2759 | 2763 | // any value that depends on that will have to become a |
| 2760 | 2764 | // comptimeExpr. |
| 2761 | try self.tryResolveRefPath(file, inst_index, path.items); | |
| 2765 | try self.tryResolveRefPath(file, inst, path.items); | |
| 2762 | 2766 | return DocData.WalkResult{ .expr = .{ .refPath = path.items } }; |
| 2763 | 2767 | }, |
| 2764 | 2768 | .int_type => { |
| 2765 | const int_type = data[inst_index].int_type; | |
| 2769 | const int_type = data[@intFromEnum(inst)].int_type; | |
| 2766 | 2770 | const sign = if (int_type.signedness == .unsigned) "u" else "i"; |
| 2767 | 2771 | const bits = int_type.bit_count; |
| 2768 | 2772 | const name = try std.fmt.allocPrint(self.arena, "{s}{}", .{ sign, bits }); |
| ... | ... | @@ -2781,7 +2785,7 @@ fn walkInstruction( |
| 2781 | 2785 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| 2782 | 2786 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2783 | 2787 | }; |
| 2784 | const pl_node = data[inst_index].pl_node; | |
| 2788 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2785 | 2789 | const block_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2786 | 2790 | try self.comptime_exprs.append(self.arena, .{ |
| 2787 | 2791 | .code = block_expr, |
| ... | ... | @@ -2793,12 +2797,12 @@ fn walkInstruction( |
| 2793 | 2797 | file, |
| 2794 | 2798 | parent_scope, |
| 2795 | 2799 | parent_src, |
| 2796 | getBlockInlineBreak(file.zir, inst_index) orelse { | |
| 2800 | getBlockInlineBreak(file.zir, inst) orelse { | |
| 2797 | 2801 | const res = DocData.WalkResult{ |
| 2798 | 2802 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| 2799 | 2803 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, |
| 2800 | 2804 | }; |
| 2801 | const pl_node = data[inst_index].pl_node; | |
| 2805 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2802 | 2806 | const block_inline_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2803 | 2807 | try self.comptime_exprs.append(self.arena, .{ |
| 2804 | 2808 | .code = block_inline_expr, |
| ... | ... | @@ -2810,7 +2814,7 @@ fn walkInstruction( |
| 2810 | 2814 | ); |
| 2811 | 2815 | }, |
| 2812 | 2816 | .break_inline => { |
| 2813 | const @"break" = data[inst_index].@"break"; | |
| 2817 | const @"break" = data[@intFromEnum(inst)].@"break"; | |
| 2814 | 2818 | return try self.walkRef( |
| 2815 | 2819 | file, |
| 2816 | 2820 | parent_scope, |
| ... | ... | @@ -2821,7 +2825,7 @@ fn walkInstruction( |
| 2821 | 2825 | ); |
| 2822 | 2826 | }, |
| 2823 | 2827 | .struct_init => { |
| 2824 | const pl_node = data[inst_index].pl_node; | |
| 2828 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2825 | 2829 | const extra = file.zir.extraData(Zir.Inst.StructInit, pl_node.payload_index); |
| 2826 | 2830 | const field_vals = try self.arena.alloc( |
| 2827 | 2831 | DocData.Expr.FieldVal, |
| ... | ... | @@ -2835,7 +2839,7 @@ fn walkInstruction( |
| 2835 | 2839 | defer idx = init_extra.end; |
| 2836 | 2840 | |
| 2837 | 2841 | 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); | |
| 2839 | 2843 | if (tags[field_inst_index] != .struct_init_field_type) unreachable; |
| 2840 | 2844 | const field_pl_node = data[field_inst_index].pl_node; |
| 2841 | 2845 | const field_extra = file.zir.extraData( |
| ... | ... | @@ -2881,7 +2885,7 @@ fn walkInstruction( |
| 2881 | 2885 | .struct_init_empty, |
| 2882 | 2886 | .struct_init_empty_result, |
| 2883 | 2887 | => { |
| 2884 | const un_node = data[inst_index].un_node; | |
| 2888 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2885 | 2889 | |
| 2886 | 2890 | var operand: DocData.WalkResult = try self.walkRef( |
| 2887 | 2891 | file, |
| ... | ... | @@ -2898,7 +2902,7 @@ fn walkInstruction( |
| 2898 | 2902 | }; |
| 2899 | 2903 | }, |
| 2900 | 2904 | .struct_init_empty_ref_result => { |
| 2901 | const un_node = data[inst_index].un_node; | |
| 2905 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 2902 | 2906 | |
| 2903 | 2907 | var operand: DocData.WalkResult = try self.walkRef( |
| 2904 | 2908 | file, |
| ... | ... | @@ -2918,7 +2922,7 @@ fn walkInstruction( |
| 2918 | 2922 | }; |
| 2919 | 2923 | }, |
| 2920 | 2924 | .struct_init_anon => { |
| 2921 | const pl_node = data[inst_index].pl_node; | |
| 2925 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2922 | 2926 | const extra = file.zir.extraData(Zir.Inst.StructInitAnon, pl_node.payload_index); |
| 2923 | 2927 | |
| 2924 | 2928 | const field_vals = try self.arena.alloc( |
| ... | ... | @@ -2947,7 +2951,7 @@ fn walkInstruction( |
| 2947 | 2951 | }; |
| 2948 | 2952 | }, |
| 2949 | 2953 | .error_set_decl => { |
| 2950 | const pl_node = data[inst_index].pl_node; | |
| 2954 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 2951 | 2955 | const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index); |
| 2952 | 2956 | const fields = try self.arena.alloc( |
| 2953 | 2957 | DocData.Type.Field, |
| ... | ... | @@ -2986,7 +2990,7 @@ fn walkInstruction( |
| 2986 | 2990 | // This switch case handles the case where an expression depends |
| 2987 | 2991 | // on an anytype field. E.g.: `fn foo(bar: anytype) @TypeOf(bar)`. |
| 2988 | 2992 | // 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; | |
| 2990 | 2994 | const name = str_tok.get(file.zir); |
| 2991 | 2995 | const cte_slot_index = self.comptime_exprs.items.len; |
| 2992 | 2996 | try self.comptime_exprs.append(self.arena, .{ |
| ... | ... | @@ -2996,7 +3000,7 @@ fn walkInstruction( |
| 2996 | 3000 | }, |
| 2997 | 3001 | .param, .param_comptime => { |
| 2998 | 3002 | // See .param_anytype for more information. |
| 2999 | const pl_tok = data[inst_index].pl_tok; | |
| 3003 | const pl_tok = data[@intFromEnum(inst)].pl_tok; | |
| 3000 | 3004 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 3001 | 3005 | const name = file.zir.nullTerminatedString(extra.data.name); |
| 3002 | 3006 | |
| ... | ... | @@ -3007,7 +3011,7 @@ fn walkInstruction( |
| 3007 | 3011 | return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } }; |
| 3008 | 3012 | }, |
| 3009 | 3013 | .call => { |
| 3010 | const pl_node = data[inst_index].pl_node; | |
| 3014 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 3011 | 3015 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); |
| 3012 | 3016 | |
| 3013 | 3017 | const callee = try self.walkRef( |
| ... | ... | @@ -3023,8 +3027,8 @@ fn walkInstruction( |
| 3023 | 3027 | var args = try self.arena.alloc(DocData.Expr, args_len); |
| 3024 | 3028 | const body = file.zir.extra[extra.end..]; |
| 3025 | 3029 | |
| 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); | |
| 3028 | 3032 | |
| 3029 | 3033 | var i: usize = 0; |
| 3030 | 3034 | while (i < args_len) : (i += 1) { |
| ... | ... | @@ -3042,7 +3046,7 @@ fn walkInstruction( |
| 3042 | 3046 | ref, |
| 3043 | 3047 | false, |
| 3044 | 3048 | &.{ |
| 3045 | .inst = inst_index, | |
| 3049 | .inst = inst, | |
| 3046 | 3050 | .prev = call_ctx, |
| 3047 | 3051 | }, |
| 3048 | 3052 | ); |
| ... | ... | @@ -3068,7 +3072,7 @@ fn walkInstruction( |
| 3068 | 3072 | else => blk: { |
| 3069 | 3073 | printWithContext( |
| 3070 | 3074 | file, |
| 3071 | inst_index, | |
| 3075 | inst, | |
| 3072 | 3076 | "unexpected callee type in walkInstruction.call: `{s}`\n", |
| 3073 | 3077 | .{@tagName(self.types.items[func_type_idx])}, |
| 3074 | 3078 | ); |
| ... | ... | @@ -3089,10 +3093,10 @@ fn walkInstruction( |
| 3089 | 3093 | file, |
| 3090 | 3094 | parent_scope, |
| 3091 | 3095 | parent_src, |
| 3092 | inst_index, | |
| 3096 | inst, | |
| 3093 | 3097 | self_ast_node_index, |
| 3094 | 3098 | type_slot_index, |
| 3095 | tags[inst_index] == .func_inferred, | |
| 3099 | tags[@intFromEnum(inst)] == .func_inferred, | |
| 3096 | 3100 | call_ctx, |
| 3097 | 3101 | ); |
| 3098 | 3102 | |
| ... | ... | @@ -3106,7 +3110,7 @@ fn walkInstruction( |
| 3106 | 3110 | file, |
| 3107 | 3111 | parent_scope, |
| 3108 | 3112 | parent_src, |
| 3109 | inst_index, | |
| 3113 | inst, | |
| 3110 | 3114 | self_ast_node_index, |
| 3111 | 3115 | type_slot_index, |
| 3112 | 3116 | call_ctx, |
| ... | ... | @@ -3115,7 +3119,7 @@ fn walkInstruction( |
| 3115 | 3119 | return result; |
| 3116 | 3120 | }, |
| 3117 | 3121 | .optional_payload_safe, .optional_payload_unsafe => { |
| 3118 | const un_node = data[inst_index].un_node; | |
| 3122 | const un_node = data[@intFromEnum(inst)].un_node; | |
| 3119 | 3123 | const operand = try self.walkRef( |
| 3120 | 3124 | file, |
| 3121 | 3125 | parent_scope, |
| ... | ... | @@ -3135,7 +3139,7 @@ fn walkInstruction( |
| 3135 | 3139 | switch (t) { |
| 3136 | 3140 | .Optional => |opt| typeRef = opt.child, |
| 3137 | 3141 | else => { |
| 3138 | printWithContext(file, inst_index, "Invalid type for optional_payload_*: {}\n", .{t}); | |
| 3142 | printWithContext(file, inst, "Invalid type for optional_payload_*: {}\n", .{t}); | |
| 3139 | 3143 | }, |
| 3140 | 3144 | } |
| 3141 | 3145 | }, |
| ... | ... | @@ -3149,7 +3153,7 @@ fn walkInstruction( |
| 3149 | 3153 | }; |
| 3150 | 3154 | }, |
| 3151 | 3155 | .elem_val_node => { |
| 3152 | const pl_node = data[inst_index].pl_node; | |
| 3156 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 3153 | 3157 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 3154 | 3158 | const lhs = try self.walkRef( |
| 3155 | 3159 | file, |
| ... | ... | @@ -3181,12 +3185,12 @@ fn walkInstruction( |
| 3181 | 3185 | }; |
| 3182 | 3186 | }, |
| 3183 | 3187 | .extended => { |
| 3184 | const extended = data[inst_index].extended; | |
| 3188 | const extended = data[@intFromEnum(inst)].extended; | |
| 3185 | 3189 | switch (extended.opcode) { |
| 3186 | 3190 | else => { |
| 3187 | 3191 | printWithContext( |
| 3188 | 3192 | file, |
| 3189 | inst_index, | |
| 3193 | inst, | |
| 3190 | 3194 | "TODO: implement `walkInstruction.extended` for {s}", |
| 3191 | 3195 | .{@tagName(extended.opcode)}, |
| 3192 | 3196 | ); |
| ... | ... | @@ -3265,7 +3269,7 @@ fn walkInstruction( |
| 3265 | 3269 | extra_index = try self.analyzeAllDecls( |
| 3266 | 3270 | file, |
| 3267 | 3271 | &scope, |
| 3268 | inst_index, | |
| 3272 | inst, | |
| 3269 | 3273 | src_info, |
| 3270 | 3274 | &decl_indexes, |
| 3271 | 3275 | &priv_decl_indexes, |
| ... | ... | @@ -3285,7 +3289,7 @@ fn walkInstruction( |
| 3285 | 3289 | for (paths.items) |resume_info| { |
| 3286 | 3290 | try self.tryResolveRefPath( |
| 3287 | 3291 | resume_info.file, |
| 3288 | inst_index, | |
| 3292 | inst, | |
| 3289 | 3293 | resume_info.ref_path, |
| 3290 | 3294 | ); |
| 3291 | 3295 | } |
| ... | ... | @@ -3393,7 +3397,7 @@ fn walkInstruction( |
| 3393 | 3397 | extra_index = try self.analyzeAllDecls( |
| 3394 | 3398 | file, |
| 3395 | 3399 | &scope, |
| 3396 | inst_index, | |
| 3400 | inst, | |
| 3397 | 3401 | src_info, |
| 3398 | 3402 | &decl_indexes, |
| 3399 | 3403 | &priv_decl_indexes, |
| ... | ... | @@ -3452,7 +3456,7 @@ fn walkInstruction( |
| 3452 | 3456 | for (paths.items) |resume_info| { |
| 3453 | 3457 | try self.tryResolveRefPath( |
| 3454 | 3458 | resume_info.file, |
| 3455 | inst_index, | |
| 3459 | inst, | |
| 3456 | 3460 | resume_info.ref_path, |
| 3457 | 3461 | ); |
| 3458 | 3462 | } |
| ... | ... | @@ -3524,7 +3528,7 @@ fn walkInstruction( |
| 3524 | 3528 | extra_index = try self.analyzeAllDecls( |
| 3525 | 3529 | file, |
| 3526 | 3530 | &scope, |
| 3527 | inst_index, | |
| 3531 | inst, | |
| 3528 | 3532 | src_info, |
| 3529 | 3533 | &decl_indexes, |
| 3530 | 3534 | &priv_decl_indexes, |
| ... | ... | @@ -3604,7 +3608,7 @@ fn walkInstruction( |
| 3604 | 3608 | for (paths.items) |resume_info| { |
| 3605 | 3609 | try self.tryResolveRefPath( |
| 3606 | 3610 | resume_info.file, |
| 3607 | inst_index, | |
| 3611 | inst, | |
| 3608 | 3612 | resume_info.ref_path, |
| 3609 | 3613 | ); |
| 3610 | 3614 | } |
| ... | ... | @@ -3668,9 +3672,9 @@ fn walkInstruction( |
| 3668 | 3672 | backing_int = backing_int_res.expr; |
| 3669 | 3673 | extra_index += 1; // backing_int_ref |
| 3670 | 3674 | } 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); | |
| 3672 | 3676 | 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; | |
| 3674 | 3678 | const backing_int_res = try self.walkRef( |
| 3675 | 3679 | file, |
| 3676 | 3680 | &scope, |
| ... | ... | @@ -3695,7 +3699,7 @@ fn walkInstruction( |
| 3695 | 3699 | extra_index = try self.analyzeAllDecls( |
| 3696 | 3700 | file, |
| 3697 | 3701 | &scope, |
| 3698 | inst_index, | |
| 3702 | inst, | |
| 3699 | 3703 | src_info, |
| 3700 | 3704 | &decl_indexes, |
| 3701 | 3705 | &priv_decl_indexes, |
| ... | ... | @@ -3739,7 +3743,7 @@ fn walkInstruction( |
| 3739 | 3743 | for (paths.items) |resume_info| { |
| 3740 | 3744 | try self.tryResolveRefPath( |
| 3741 | 3745 | resume_info.file, |
| 3742 | inst_index, | |
| 3746 | inst, | |
| 3743 | 3747 | resume_info.ref_path, |
| 3744 | 3748 | ); |
| 3745 | 3749 | } |
| ... | ... | @@ -3883,7 +3887,7 @@ fn walkInstruction( |
| 3883 | 3887 | |
| 3884 | 3888 | const cmpxchg_index = self.exprs.items.len; |
| 3885 | 3889 | try self.exprs.append(self.arena, .{ .cmpxchg = .{ |
| 3886 | .name = @tagName(tags[inst_index]), | |
| 3890 | .name = @tagName(tags[@intFromEnum(inst)]), | |
| 3887 | 3891 | .type = type_index, |
| 3888 | 3892 | .ptr = ptr_index, |
| 3889 | 3893 | .expected_value = expected_value_index, |
| ... | ... | @@ -3912,14 +3916,14 @@ fn analyzeAllDecls( |
| 3912 | 3916 | self: *Autodoc, |
| 3913 | 3917 | file: *File, |
| 3914 | 3918 | scope: *Scope, |
| 3915 | parent_inst_index: usize, | |
| 3919 | parent_inst: Zir.Inst.Index, | |
| 3916 | 3920 | parent_src: SrcLocInfo, |
| 3917 | 3921 | decl_indexes: *std.ArrayListUnmanaged(usize), |
| 3918 | 3922 | priv_decl_indexes: *std.ArrayListUnmanaged(usize), |
| 3919 | 3923 | call_ctx: ?*const CallContext, |
| 3920 | 3924 | ) AutodocErrors!usize { |
| 3921 | 3925 | 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); | |
| 3923 | 3927 | |
| 3924 | 3928 | // First loop to discover decl names |
| 3925 | 3929 | { |
| ... | ... | @@ -4038,7 +4042,7 @@ fn analyzeDecl( |
| 4038 | 4042 | const decl_name_index = file.zir.extra[extra_index]; |
| 4039 | 4043 | |
| 4040 | 4044 | 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]); | |
| 4042 | 4046 | |
| 4043 | 4047 | extra_index += 1; |
| 4044 | 4048 | const doc_comment_index = file.zir.extra[extra_index]; |
| ... | ... | @@ -4066,7 +4070,7 @@ fn analyzeDecl( |
| 4066 | 4070 | _ = addrspace_inst; |
| 4067 | 4071 | |
| 4068 | 4072 | // 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; | |
| 4070 | 4074 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 4071 | 4075 | |
| 4072 | 4076 | const name: []const u8 = switch (decl_name_index) { |
| ... | ... | @@ -4124,7 +4128,7 @@ fn analyzeDecl( |
| 4124 | 4128 | try priv_decl_indexes.append(self.arena, decls_slot_index); |
| 4125 | 4129 | } |
| 4126 | 4130 | |
| 4127 | const decl_status_ptr = scope.resolveDeclName(decl_name_index, file, 0); | |
| 4131 | const decl_status_ptr = scope.resolveDeclName(decl_name_index, file, .none); | |
| 4128 | 4132 | std.debug.assert(decl_status_ptr.* == .Pending); |
| 4129 | 4133 | decl_status_ptr.* = .{ .Analyzed = decls_slot_index }; |
| 4130 | 4134 | |
| ... | ... | @@ -4158,11 +4162,11 @@ fn analyzeUsingnamespaceDecl( |
| 4158 | 4162 | const data = file.zir.instructions.items(.data); |
| 4159 | 4163 | |
| 4160 | 4164 | 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]); | |
| 4162 | 4166 | const doc_comment_index = file.zir.extra[@intFromEnum(d.sub_index) + 7]; |
| 4163 | 4167 | |
| 4164 | 4168 | // 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; | |
| 4166 | 4170 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 4167 | 4171 | |
| 4168 | 4172 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| ... | ... | @@ -4244,7 +4248,7 @@ fn analyzeDecltest( |
| 4244 | 4248 | break :idx idx; |
| 4245 | 4249 | }; |
| 4246 | 4250 | |
| 4247 | const decl_status = scope.resolveDeclName(decl_name_index, file, 0); | |
| 4251 | const decl_status = scope.resolveDeclName(decl_name_index, file, .none); | |
| 4248 | 4252 | |
| 4249 | 4253 | switch (decl_status.*) { |
| 4250 | 4254 | .Analyzed => |idx| { |
| ... | ... | @@ -4277,7 +4281,7 @@ fn tryResolveRefPath( |
| 4277 | 4281 | self: *Autodoc, |
| 4278 | 4282 | /// File from which the decl path originates. |
| 4279 | 4283 | file: *File, |
| 4280 | inst_index: usize, // used only for panicWithContext | |
| 4284 | inst: Zir.Inst.Index, // used only for panicWithContext | |
| 4281 | 4285 | path: []DocData.Expr, |
| 4282 | 4286 | ) AutodocErrors!void { |
| 4283 | 4287 | var i: usize = 0; |
| ... | ... | @@ -4374,7 +4378,7 @@ fn tryResolveRefPath( |
| 4374 | 4378 | } else { |
| 4375 | 4379 | panicWithContext( |
| 4376 | 4380 | file, |
| 4377 | inst_index, | |
| 4381 | inst, | |
| 4378 | 4382 | "exhausted eval quota for `{}`in tryResolveRefPath\n", |
| 4379 | 4383 | .{resolved_parent}, |
| 4380 | 4384 | ); |
| ... | ... | @@ -4386,7 +4390,7 @@ fn tryResolveRefPath( |
| 4386 | 4390 | // in the switch above this one! |
| 4387 | 4391 | printWithContext( |
| 4388 | 4392 | file, |
| 4389 | inst_index, | |
| 4393 | inst, | |
| 4390 | 4394 | "TODO: handle `{s}`in tryResolveRefPath\nInfo: {}", |
| 4391 | 4395 | .{ @tagName(resolved_parent), resolved_parent }, |
| 4392 | 4396 | ); |
| ... | ... | @@ -4403,7 +4407,7 @@ fn tryResolveRefPath( |
| 4403 | 4407 | else => { |
| 4404 | 4408 | panicWithContext( |
| 4405 | 4409 | file, |
| 4406 | inst_index, | |
| 4410 | inst, | |
| 4407 | 4411 | "TODO: handle `{s}` in tryResolveDeclPath.type\nInfo: {}", |
| 4408 | 4412 | .{ @tagName(self.types.items[t_index]), resolved_parent }, |
| 4409 | 4413 | ); |
| ... | ... | @@ -4442,7 +4446,7 @@ fn tryResolveRefPath( |
| 4442 | 4446 | } else { |
| 4443 | 4447 | panicWithContext( |
| 4444 | 4448 | file, |
| 4445 | inst_index, | |
| 4449 | inst, | |
| 4446 | 4450 | "TODO: handle `{s}` in tryResolveDeclPath.type.Array\nInfo: {}", |
| 4447 | 4451 | .{ child_string, resolved_parent }, |
| 4448 | 4452 | ); |
| ... | ... | @@ -4500,7 +4504,7 @@ fn tryResolveRefPath( |
| 4500 | 4504 | // if we got here, our search failed |
| 4501 | 4505 | printWithContext( |
| 4502 | 4506 | file, |
| 4503 | inst_index, | |
| 4507 | inst, | |
| 4504 | 4508 | "failed to match `{s}` in enum", |
| 4505 | 4509 | .{child_string}, |
| 4506 | 4510 | ); |
| ... | ... | @@ -4557,7 +4561,7 @@ fn tryResolveRefPath( |
| 4557 | 4561 | // if we got here, our search failed |
| 4558 | 4562 | printWithContext( |
| 4559 | 4563 | file, |
| 4560 | inst_index, | |
| 4564 | inst, | |
| 4561 | 4565 | "failed to match `{s}` in union", |
| 4562 | 4566 | .{child_string}, |
| 4563 | 4567 | ); |
| ... | ... | @@ -4614,7 +4618,7 @@ fn tryResolveRefPath( |
| 4614 | 4618 | // if we got here, our search failed |
| 4615 | 4619 | // printWithContext( |
| 4616 | 4620 | // file, |
| 4617 | // inst_index, | |
| 4621 | // inst, | |
| 4618 | 4622 | // "failed to match `{s}` in struct", |
| 4619 | 4623 | // .{child_string}, |
| 4620 | 4624 | // ); |
| ... | ... | @@ -4659,7 +4663,7 @@ fn tryResolveRefPath( |
| 4659 | 4663 | // if we got here, our search failed |
| 4660 | 4664 | printWithContext( |
| 4661 | 4665 | file, |
| 4662 | inst_index, | |
| 4666 | inst, | |
| 4663 | 4667 | "failed to match `{s}` in opaque", |
| 4664 | 4668 | .{child_string}, |
| 4665 | 4669 | ); |
| ... | ... | @@ -4679,7 +4683,7 @@ fn tryResolveRefPath( |
| 4679 | 4683 | // if we got here, our search failed |
| 4680 | 4684 | printWithContext( |
| 4681 | 4685 | file, |
| 4682 | inst_index, | |
| 4686 | inst, | |
| 4683 | 4687 | "failed to match `{s}` in struct", |
| 4684 | 4688 | .{child_string}, |
| 4685 | 4689 | ); |
| ... | ... | @@ -4696,7 +4700,7 @@ fn tryResolveRefPath( |
| 4696 | 4700 | _ = self.pending_ref_paths.remove(&path[path.len - 1]); |
| 4697 | 4701 | |
| 4698 | 4702 | 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); | |
| 4700 | 4704 | } |
| 4701 | 4705 | // TODO: this is where we should free waiter_list, but its in the arena |
| 4702 | 4706 | // that said, we might want to store it elsewhere and reclaim memory asap |
| ... | ... | @@ -4805,14 +4809,14 @@ fn analyzeFancyFunction( |
| 4805 | 4809 | file: *File, |
| 4806 | 4810 | scope: *Scope, |
| 4807 | 4811 | parent_src: SrcLocInfo, |
| 4808 | inst_index: usize, | |
| 4812 | inst: Zir.Inst.Index, | |
| 4809 | 4813 | self_ast_node_index: usize, |
| 4810 | 4814 | type_slot_index: usize, |
| 4811 | 4815 | call_ctx: ?*const CallContext, |
| 4812 | 4816 | ) AutodocErrors!DocData.WalkResult { |
| 4813 | 4817 | const tags = file.zir.instructions.items(.tag); |
| 4814 | 4818 | 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); | |
| 4816 | 4820 | |
| 4817 | 4821 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 4818 | 4822 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( |
| ... | ... | @@ -4826,18 +4830,18 @@ fn analyzeFancyFunction( |
| 4826 | 4830 | |
| 4827 | 4831 | // TODO: handle scope rules for fn parameters |
| 4828 | 4832 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { |
| 4829 | switch (tags[param_index]) { | |
| 4833 | switch (tags[@intFromEnum(param_index)]) { | |
| 4830 | 4834 | else => { |
| 4831 | 4835 | panicWithContext( |
| 4832 | 4836 | file, |
| 4833 | 4837 | param_index, |
| 4834 | 4838 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 4835 | .{@tagName(tags[param_index])}, | |
| 4839 | .{@tagName(tags[@intFromEnum(param_index)])}, | |
| 4836 | 4840 | ); |
| 4837 | 4841 | }, |
| 4838 | 4842 | .param_anytype, .param_anytype_comptime => { |
| 4839 | 4843 | // 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; | |
| 4841 | 4845 | |
| 4842 | 4846 | const name = str_tok.get(file.zir); |
| 4843 | 4847 | |
| ... | ... | @@ -4845,7 +4849,7 @@ fn analyzeFancyFunction( |
| 4845 | 4849 | self.ast_nodes.appendAssumeCapacity(.{ |
| 4846 | 4850 | .name = name, |
| 4847 | 4851 | .docs = "", |
| 4848 | .@"comptime" = tags[param_index] == .param_anytype_comptime, | |
| 4852 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime, | |
| 4849 | 4853 | }); |
| 4850 | 4854 | |
| 4851 | 4855 | param_type_refs.appendAssumeCapacity( |
| ... | ... | @@ -4853,7 +4857,7 @@ fn analyzeFancyFunction( |
| 4853 | 4857 | ); |
| 4854 | 4858 | }, |
| 4855 | 4859 | .param, .param_comptime => { |
| 4856 | const pl_tok = data[param_index].pl_tok; | |
| 4860 | const pl_tok = data[@intFromEnum(param_index)].pl_tok; | |
| 4857 | 4861 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 4858 | 4862 | const doc_comment = if (extra.data.doc_comment != 0) |
| 4859 | 4863 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| ... | ... | @@ -4865,7 +4869,7 @@ fn analyzeFancyFunction( |
| 4865 | 4869 | try self.ast_nodes.append(self.arena, .{ |
| 4866 | 4870 | .name = name, |
| 4867 | 4871 | .docs = doc_comment, |
| 4868 | .@"comptime" = tags[param_index] == .param_comptime, | |
| 4872 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime, | |
| 4869 | 4873 | }); |
| 4870 | 4874 | |
| 4871 | 4875 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| ... | ... | @@ -4886,7 +4890,7 @@ fn analyzeFancyFunction( |
| 4886 | 4890 | |
| 4887 | 4891 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 4888 | 4892 | |
| 4889 | const pl_node = data[inst_index].pl_node; | |
| 4893 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 4890 | 4894 | const extra = file.zir.extraData(Zir.Inst.FuncFancy, pl_node.payload_index); |
| 4891 | 4895 | |
| 4892 | 4896 | var extra_index: usize = extra.end; |
| ... | ... | @@ -4971,7 +4975,7 @@ fn analyzeFancyFunction( |
| 4971 | 4975 | |
| 4972 | 4976 | var cc_index: ?usize = null; |
| 4973 | 4977 | 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]); | |
| 4975 | 4979 | const cc_expr = try self.walkRef( |
| 4976 | 4980 | file, |
| 4977 | 4981 | scope, |
| ... | ... | @@ -4988,11 +4992,11 @@ fn analyzeFancyFunction( |
| 4988 | 4992 | } else if (extra.data.bits.has_cc_body) { |
| 4989 | 4993 | const cc_body_len = file.zir.extra[extra_index]; |
| 4990 | 4994 | 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); | |
| 4992 | 4996 | |
| 4993 | 4997 | // We assume the body ends with a break_inline |
| 4994 | 4998 | 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; | |
| 4996 | 5000 | const cc_expr = try self.walkRef( |
| 4997 | 5001 | file, |
| 4998 | 5002 | scope, |
| ... | ... | @@ -5029,7 +5033,7 @@ fn analyzeFancyFunction( |
| 5029 | 5033 | }, |
| 5030 | 5034 | else => blk: { |
| 5031 | 5035 | 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; | |
| 5033 | 5037 | const wr = try self.walkRef( |
| 5034 | 5038 | file, |
| 5035 | 5039 | scope, |
| ... | ... | @@ -5096,7 +5100,7 @@ fn analyzeFunction( |
| 5096 | 5100 | file: *File, |
| 5097 | 5101 | scope: *Scope, |
| 5098 | 5102 | parent_src: SrcLocInfo, |
| 5099 | inst_index: usize, | |
| 5103 | inst: Zir.Inst.Index, | |
| 5100 | 5104 | self_ast_node_index: usize, |
| 5101 | 5105 | type_slot_index: usize, |
| 5102 | 5106 | ret_is_inferred_error_set: bool, |
| ... | ... | @@ -5104,7 +5108,7 @@ fn analyzeFunction( |
| 5104 | 5108 | ) AutodocErrors!DocData.WalkResult { |
| 5105 | 5109 | const tags = file.zir.instructions.items(.tag); |
| 5106 | 5110 | 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); | |
| 5108 | 5112 | |
| 5109 | 5113 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 5110 | 5114 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( |
| ... | ... | @@ -5118,18 +5122,18 @@ fn analyzeFunction( |
| 5118 | 5122 | |
| 5119 | 5123 | // TODO: handle scope rules for fn parameters |
| 5120 | 5124 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { |
| 5121 | switch (tags[param_index]) { | |
| 5125 | switch (tags[@intFromEnum(param_index)]) { | |
| 5122 | 5126 | else => { |
| 5123 | 5127 | panicWithContext( |
| 5124 | 5128 | file, |
| 5125 | 5129 | param_index, |
| 5126 | 5130 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 5127 | .{@tagName(tags[param_index])}, | |
| 5131 | .{@tagName(tags[@intFromEnum(param_index)])}, | |
| 5128 | 5132 | ); |
| 5129 | 5133 | }, |
| 5130 | 5134 | .param_anytype, .param_anytype_comptime => { |
| 5131 | 5135 | // 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; | |
| 5133 | 5137 | |
| 5134 | 5138 | const name = str_tok.get(file.zir); |
| 5135 | 5139 | |
| ... | ... | @@ -5137,7 +5141,7 @@ fn analyzeFunction( |
| 5137 | 5141 | self.ast_nodes.appendAssumeCapacity(.{ |
| 5138 | 5142 | .name = name, |
| 5139 | 5143 | .docs = "", |
| 5140 | .@"comptime" = tags[param_index] == .param_anytype_comptime, | |
| 5144 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime, | |
| 5141 | 5145 | }); |
| 5142 | 5146 | |
| 5143 | 5147 | param_type_refs.appendAssumeCapacity( |
| ... | ... | @@ -5145,7 +5149,7 @@ fn analyzeFunction( |
| 5145 | 5149 | ); |
| 5146 | 5150 | }, |
| 5147 | 5151 | .param, .param_comptime => { |
| 5148 | const pl_tok = data[param_index].pl_tok; | |
| 5152 | const pl_tok = data[@intFromEnum(param_index)].pl_tok; | |
| 5149 | 5153 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 5150 | 5154 | const doc_comment = if (extra.data.doc_comment != 0) |
| 5151 | 5155 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| ... | ... | @@ -5157,7 +5161,7 @@ fn analyzeFunction( |
| 5157 | 5161 | try self.ast_nodes.append(self.arena, .{ |
| 5158 | 5162 | .name = name, |
| 5159 | 5163 | .docs = doc_comment, |
| 5160 | .@"comptime" = tags[param_index] == .param_comptime, | |
| 5164 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime, | |
| 5161 | 5165 | }); |
| 5162 | 5166 | |
| 5163 | 5167 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| ... | ... | @@ -5195,7 +5199,7 @@ fn analyzeFunction( |
| 5195 | 5199 | }, |
| 5196 | 5200 | else => blk: { |
| 5197 | 5201 | 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; | |
| 5199 | 5203 | const wr = try self.walkRef( |
| 5200 | 5204 | file, |
| 5201 | 5205 | scope, |
| ... | ... | @@ -5266,7 +5270,7 @@ fn getGenericReturnType( |
| 5266 | 5270 | file: *File, |
| 5267 | 5271 | scope: *Scope, |
| 5268 | 5272 | parent_src: SrcLocInfo, // function decl line |
| 5269 | body_main_block: usize, | |
| 5273 | body_main_block: Zir.Inst.Index, | |
| 5270 | 5274 | call_ctx: ?*const CallContext, |
| 5271 | 5275 | ) !DocData.Expr { |
| 5272 | 5276 | const tags = file.zir.instructions.items(.tag); |
| ... | ... | @@ -5274,25 +5278,27 @@ fn getGenericReturnType( |
| 5274 | 5278 | |
| 5275 | 5279 | // We expect `body_main_block` to be the first instruction |
| 5276 | 5280 | // 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; | |
| 5278 | 5282 | 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 | } | |
| 5295 | 5300 | } |
| 5301 | return DocData.Expr{ .comptimeExpr = 0 }; | |
| 5296 | 5302 | } |
| 5297 | 5303 | |
| 5298 | 5304 | fn collectUnionFieldInfo( |
| ... | ... | @@ -5470,11 +5476,11 @@ fn collectStructFieldInfo( |
| 5470 | 5476 | } |
| 5471 | 5477 | |
| 5472 | 5478 | 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); | |
| 5474 | 5480 | extra_index += body.len; |
| 5475 | 5481 | |
| 5476 | 5482 | const break_inst = body[body.len - 1]; |
| 5477 | const operand = data[break_inst].@"break".operand; | |
| 5483 | const operand = data[@intFromEnum(break_inst)].@"break".operand; | |
| 5478 | 5484 | try self.ast_nodes.append(self.arena, .{ |
| 5479 | 5485 | .file = self.files.getIndex(file).?, |
| 5480 | 5486 | .line = parent_src.line, |
| ... | ... | @@ -5499,11 +5505,11 @@ fn collectStructFieldInfo( |
| 5499 | 5505 | break :def null; |
| 5500 | 5506 | } |
| 5501 | 5507 | |
| 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); | |
| 5503 | 5509 | extra_index += body.len; |
| 5504 | 5510 | |
| 5505 | 5511 | const break_inst = body[body.len - 1]; |
| 5506 | const operand = data[break_inst].@"break".operand; | |
| 5512 | const operand = data[@intFromEnum(break_inst)].@"break".operand; | |
| 5507 | 5513 | const walk_result = try self.walkRef( |
| 5508 | 5514 | file, |
| 5509 | 5515 | scope, |
| ... | ... | @@ -5559,7 +5565,7 @@ fn walkRef( |
| 5559 | 5565 | .typeRef = .{ .type = @intFromEnum(std.builtin.TypeId.Type) }, |
| 5560 | 5566 | .expr = .{ .type = @intFromEnum(ref) }, |
| 5561 | 5567 | }; |
| 5562 | } else if (Zir.refToIndex(ref)) |zir_index| { | |
| 5568 | } else if (ref.toIndex()) |zir_index| { | |
| 5563 | 5569 | return self.walkInstruction( |
| 5564 | 5570 | file, |
| 5565 | 5571 | parent_scope, |
| ... | ... | @@ -5571,9 +5577,9 @@ fn walkRef( |
| 5571 | 5577 | } else { |
| 5572 | 5578 | switch (ref) { |
| 5573 | 5579 | else => { |
| 5574 | panicWithContext( | |
| 5580 | panicWithOptionalContext( | |
| 5575 | 5581 | file, |
| 5576 | 0, | |
| 5582 | .none, | |
| 5577 | 5583 | "TODO: handle {s} in walkRef", |
| 5578 | 5584 | .{@tagName(ref)}, |
| 5579 | 5585 | ); |
| ... | ... | @@ -5664,10 +5670,10 @@ fn walkRef( |
| 5664 | 5670 | } |
| 5665 | 5671 | } |
| 5666 | 5672 | |
| 5667 | fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref { | |
| 5673 | fn getBlockInlineBreak(zir: Zir, inst: Zir.Inst.Index) ?Zir.Inst.Ref { | |
| 5668 | 5674 | const tags = zir.instructions.items(.tag); |
| 5669 | 5675 | const data = zir.instructions.items(.data); |
| 5670 | const pl_node = data[inst_index].pl_node; | |
| 5676 | const pl_node = data[@intFromEnum(inst)].pl_node; | |
| 5671 | 5677 | const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 5672 | 5678 | const break_index = zir.extra[extra.end..][extra.data.body_len - 1]; |
| 5673 | 5679 | if (tags[break_index] == .condbr_inline) return null; |
| ... | ... | @@ -5675,12 +5681,36 @@ fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref { |
| 5675 | 5681 | return data[break_index].@"break".operand; |
| 5676 | 5682 | } |
| 5677 | 5683 | |
| 5678 | fn printWithContext(file: *File, inst: usize, comptime fmt: []const u8, args: anytype) void { | |
| 5684 | fn 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 | ||
| 5693 | fn printWithOptionalContext(file: *File, inst: Zir.Inst.OptionalIndex, comptime fmt: []const u8, args: anytype) void { | |
| 5679 | 5694 | log.debug("Context [{s}] % {} \n " ++ fmt, .{ file.sub_file_path, inst } ++ args); |
| 5680 | 5695 | } |
| 5681 | 5696 | |
| 5682 | fn panicWithContext(file: *File, inst: usize, comptime fmt: []const u8, args: anytype) noreturn { | |
| 5683 | printWithContext(file, inst, fmt, args); | |
| 5697 | fn 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 | ||
| 5707 | fn 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); | |
| 5684 | 5714 | unreachable; |
| 5685 | 5715 | } |
| 5686 | 5716 |
src/InternPool.zig+14-5| ... | ... | @@ -580,7 +580,7 @@ pub const Key = union(enum) { |
| 580 | 580 | pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: Zir.Inst.Index) void { |
| 581 | 581 | assert(s.layout != .Packed); |
| 582 | 582 | 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); | |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool { |
| ... | ... | @@ -2481,7 +2481,14 @@ pub const static_keys = [_]Key{ |
| 2481 | 2481 | }; |
| 2482 | 2482 | |
| 2483 | 2483 | /// How many items in the InternPool are statically known. |
| 2484 | pub 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. | |
| 2487 | pub const static_len = 84; | |
| 2488 | comptime { | |
| 2489 | //@compileLog(static_keys.len); | |
| 2490 | assert(static_len == static_keys.len); | |
| 2491 | } | |
| 2485 | 2492 | |
| 2486 | 2493 | pub const Tag = enum(u8) { |
| 2487 | 2494 | /// An integer type. |
| ... | ... | @@ -3658,7 +3665,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3658 | 3665 | .extra_index = 0, |
| 3659 | 3666 | .namespace = .none, |
| 3660 | 3667 | .decl = .none, |
| 3661 | .zir_index = @as(u32, undefined), | |
| 3668 | .zir_index = undefined, | |
| 3662 | 3669 | .layout = .Auto, |
| 3663 | 3670 | .field_names = .{ .start = 0, .len = 0 }, |
| 3664 | 3671 | .field_types = .{ .start = 0, .len = 0 }, |
| ... | ... | @@ -3674,7 +3681,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3674 | 3681 | .extra_index = 0, |
| 3675 | 3682 | .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(), |
| 3676 | 3683 | .decl = .none, |
| 3677 | .zir_index = @as(u32, undefined), | |
| 3684 | .zir_index = undefined, | |
| 3678 | 3685 | .layout = .Auto, |
| 3679 | 3686 | .field_names = .{ .start = 0, .len = 0 }, |
| 3680 | 3687 | .field_types = .{ .start = 0, .len = 0 }, |
| ... | ... | @@ -6403,6 +6410,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 6403 | 6410 | NullTerminatedString, |
| 6404 | 6411 | OptionalNullTerminatedString, |
| 6405 | 6412 | Tag.TypePointer.VectorIndex, |
| 6413 | Zir.Inst.Index, | |
| 6406 | 6414 | => @intFromEnum(@field(extra, field.name)), |
| 6407 | 6415 | |
| 6408 | 6416 | u32, |
| ... | ... | @@ -6477,6 +6485,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct |
| 6477 | 6485 | NullTerminatedString, |
| 6478 | 6486 | OptionalNullTerminatedString, |
| 6479 | 6487 | Tag.TypePointer.VectorIndex, |
| 6488 | Zir.Inst.Index, | |
| 6480 | 6489 | => @enumFromInt(int32), |
| 6481 | 6490 | |
| 6482 | 6491 | u32, |
| ... | ... | @@ -8191,7 +8200,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { |
| 8191 | 8200 | }, |
| 8192 | 8201 | else => unreachable, |
| 8193 | 8202 | }; |
| 8194 | return ip.extra.items[extra_index]; | |
| 8203 | return @enumFromInt(ip.extra.items[extra_index]); | |
| 8195 | 8204 | } |
| 8196 | 8205 | |
| 8197 | 8206 | pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index { |
src/Module.zig+13-14| ... | ... | @@ -389,7 +389,7 @@ pub const Decl = struct { |
| 389 | 389 | /// Index to ZIR `extra` array to the entry in the parent's decl structure |
| 390 | 390 | /// (the part that says "for every decls_len"). The first item at this index is |
| 391 | 391 | /// 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`. | |
| 393 | 393 | zir_decl_index: Zir.OptionalExtraIndex, |
| 394 | 394 | |
| 395 | 395 | /// Represents the "shallow" analysis status. For example, for decls that are functions, |
| ... | ... | @@ -547,7 +547,7 @@ pub const Decl = struct { |
| 547 | 547 | pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index { |
| 548 | 548 | assert(decl.zir_decl_index != .none); |
| 549 | 549 | 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]); | |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref { |
| ... | ... | @@ -1205,9 +1205,8 @@ pub const File = struct { |
| 1205 | 1205 | if (imports_index == 0) return; |
| 1206 | 1206 | const extra = file.zir.extraData(Zir.Inst.Imports, imports_index); |
| 1207 | 1207 | |
| 1208 | var import_i: u32 = 0; | |
| 1209 | 1208 | var extra_index = extra.end; |
| 1210 | while (import_i < extra.data.imports_len) : (import_i += 1) { | |
| 1209 | for (0..extra.data.imports_len) |_| { | |
| 1211 | 1210 | const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index); |
| 1212 | 1211 | extra_index = item.end; |
| 1213 | 1212 | |
| ... | ... | @@ -3206,8 +3205,8 @@ pub fn mapOldZirToNew( |
| 3206 | 3205 | |
| 3207 | 3206 | // Main struct inst is always the same |
| 3208 | 3207 | 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, | |
| 3211 | 3210 | }); |
| 3212 | 3211 | |
| 3213 | 3212 | var old_decls = std.ArrayList(Zir.Inst.Index).init(gpa); |
| ... | ... | @@ -3622,11 +3621,10 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 3622 | 3621 | }; |
| 3623 | 3622 | defer sema.deinit(); |
| 3624 | 3623 | |
| 3625 | const main_struct_inst = Zir.main_struct_inst; | |
| 3626 | 3624 | const struct_ty = sema.getStructType( |
| 3627 | 3625 | new_decl_index, |
| 3628 | 3626 | new_namespace_index, |
| 3629 | main_struct_inst, | |
| 3627 | .main_struct_inst, | |
| 3630 | 3628 | ) catch |err| switch (err) { |
| 3631 | 3629 | error.OutOfMemory => return error.OutOfMemory, |
| 3632 | 3630 | }; |
| ... | ... | @@ -3754,11 +3752,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 3754 | 3752 | defer block_scope.instructions.deinit(gpa); |
| 3755 | 3753 | |
| 3756 | 3754 | 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; | |
| 3758 | 3756 | const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 3759 | 3757 | 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. | |
| 3762 | 3761 | sema.builtin_type_target_index = .none; |
| 3763 | 3762 | for (comptime_mutable_decls.items) |ct_decl_index| { |
| 3764 | 3763 | const ct_decl = mod.declPtr(ct_decl_index); |
| ... | ... | @@ -6471,13 +6470,13 @@ pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0] |
| 6471 | 6470 | const param_body = file.zir.getParamBody(func.zir_body_inst); |
| 6472 | 6471 | const param = param_body[index]; |
| 6473 | 6472 | |
| 6474 | return switch (tags[param]) { | |
| 6473 | return switch (tags[@intFromEnum(param)]) { | |
| 6475 | 6474 | .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); | |
| 6477 | 6476 | break :blk file.zir.nullTerminatedString(extra.data.name); |
| 6478 | 6477 | }, |
| 6479 | 6478 | .param_anytype, .param_anytype_comptime => blk: { |
| 6480 | const param_data = data[param].str_tok; | |
| 6479 | const param_data = data[@intFromEnum(param)].str_tok; | |
| 6481 | 6480 | break :blk param_data.get(file.zir); |
| 6482 | 6481 | }, |
| 6483 | 6482 | else => unreachable, |
src/Sema.zig+370-362| ... | ... | @@ -226,7 +226,7 @@ pub const InferredErrorSet = struct { |
| 226 | 226 | /// be called safely for any of the instructions passed in. |
| 227 | 227 | pub const InstMap = struct { |
| 228 | 228 | items: []Air.Inst.Ref = &[_]Air.Inst.Ref{}, |
| 229 | start: Zir.Inst.Index = 0, | |
| 229 | start: Zir.Inst.Index = @enumFromInt(0), | |
| 230 | 230 | |
| 231 | 231 | pub fn deinit(map: InstMap, allocator: mem.Allocator) void { |
| 232 | 232 | allocator.free(map.items); |
| ... | ... | @@ -234,7 +234,7 @@ pub const InstMap = struct { |
| 234 | 234 | |
| 235 | 235 | pub fn get(map: InstMap, key: Zir.Inst.Index) ?Air.Inst.Ref { |
| 236 | 236 | if (!map.contains(key)) return null; |
| 237 | return map.items[key - map.start]; | |
| 237 | return map.items[@intFromEnum(key) - @intFromEnum(map.start)]; | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | pub fn putAssumeCapacity( |
| ... | ... | @@ -242,7 +242,7 @@ pub const InstMap = struct { |
| 242 | 242 | key: Zir.Inst.Index, |
| 243 | 243 | ref: Air.Inst.Ref, |
| 244 | 244 | ) void { |
| 245 | map.items[key - map.start] = ref; | |
| 245 | map.items[@intFromEnum(key) - @intFromEnum(map.start)] = ref; | |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | pub fn putAssumeCapacityNoClobber( |
| ... | ... | @@ -263,7 +263,7 @@ pub const InstMap = struct { |
| 263 | 263 | map: *InstMap, |
| 264 | 264 | key: Zir.Inst.Index, |
| 265 | 265 | ) GetOrPutResult { |
| 266 | const index = key - map.start; | |
| 266 | const index = @intFromEnum(key) - @intFromEnum(map.start); | |
| 267 | 267 | return GetOrPutResult{ |
| 268 | 268 | .value_ptr = &map.items[index], |
| 269 | 269 | .found_existing = map.items[index] != .none, |
| ... | ... | @@ -272,12 +272,12 @@ pub const InstMap = struct { |
| 272 | 272 | |
| 273 | 273 | pub fn remove(map: InstMap, key: Zir.Inst.Index) bool { |
| 274 | 274 | if (!map.contains(key)) return false; |
| 275 | map.items[key - map.start] = .none; | |
| 275 | map.items[@intFromEnum(key) - @intFromEnum(map.start)] = .none; | |
| 276 | 276 | return true; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | 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; | |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | pub fn ensureSpaceForInstructions( |
| ... | ... | @@ -285,13 +285,12 @@ pub const InstMap = struct { |
| 285 | 285 | allocator: mem.Allocator, |
| 286 | 286 | insts: []const Zir.Inst.Index, |
| 287 | 287 | ) !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) | |
| 292 | 291 | return; |
| 293 | 292 | |
| 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; | |
| 295 | 294 | var better_capacity = map.items.len; |
| 296 | 295 | var better_start = old_start; |
| 297 | 296 | while (true) { |
| ... | ... | @@ -310,7 +309,7 @@ pub const InstMap = struct { |
| 310 | 309 | |
| 311 | 310 | allocator.free(map.items); |
| 312 | 311 | map.items = new_items; |
| 313 | map.start = @intCast(better_start); | |
| 312 | map.start = @enumFromInt(better_start); | |
| 314 | 313 | } |
| 315 | 314 | }; |
| 316 | 315 | |
| ... | ... | @@ -350,7 +349,7 @@ pub const Block = struct { |
| 350 | 349 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. |
| 351 | 350 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. |
| 352 | 351 | runtime_index: Value.RuntimeIndex = .zero, |
| 353 | inline_block: Zir.Inst.Index = 0, | |
| 352 | inline_block: Zir.Inst.OptionalIndex = .none, | |
| 354 | 353 | |
| 355 | 354 | comptime_reason: ?*const ComptimeReason = null, |
| 356 | 355 | // 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 |
| 897 | 896 | _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) { |
| 898 | 897 | error.ComptimeBreak => { |
| 899 | 898 | 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"; | |
| 901 | 900 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 902 | 901 | try sema.addRuntimeBreak(block, .{ |
| 903 | 902 | .block_inst = extra.block_inst, |
| ... | ... | @@ -938,7 +937,7 @@ pub fn analyzeBodyBreak( |
| 938 | 937 | if (block.instructions.items.len != 0 and |
| 939 | 938 | sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1]))) |
| 940 | 939 | 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"; | |
| 942 | 941 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 943 | 942 | return BreakData{ |
| 944 | 943 | .block_inst = extra.block_inst, |
| ... | ... | @@ -998,7 +997,7 @@ fn analyzeBodyInner( |
| 998 | 997 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ |
| 999 | 998 | mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst, |
| 1000 | 999 | }); |
| 1001 | const air_inst: Air.Inst.Ref = switch (tags[inst]) { | |
| 1000 | const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) { | |
| 1002 | 1001 | // zig fmt: off |
| 1003 | 1002 | .alloc => try sema.zirAlloc(block, inst), |
| 1004 | 1003 | .alloc_inferred => try sema.zirAllocInferred(block, inst, true), |
| ... | ... | @@ -1220,7 +1219,7 @@ fn analyzeBodyInner( |
| 1220 | 1219 | // zig fmt: on |
| 1221 | 1220 | |
| 1222 | 1221 | .extended => ext: { |
| 1223 | const extended = datas[inst].extended; | |
| 1222 | const extended = datas[@intFromEnum(inst)].extended; | |
| 1224 | 1223 | break :ext switch (extended.opcode) { |
| 1225 | 1224 | // zig fmt: off |
| 1226 | 1225 | .variable => try sema.zirVarExtended( block, extended), |
| ... | ... | @@ -1477,13 +1476,13 @@ fn analyzeBodyInner( |
| 1477 | 1476 | }, |
| 1478 | 1477 | .check_comptime_control_flow => { |
| 1479 | 1478 | 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; | |
| 1481 | 1480 | const src = inst_data.src(); |
| 1482 | const inline_block = Zir.refToIndex(inst_data.operand).?; | |
| 1481 | const inline_block = inst_data.operand.toIndex().?; | |
| 1483 | 1482 | |
| 1484 | 1483 | var check_block = block; |
| 1485 | 1484 | const target_runtime_index = while (true) { |
| 1486 | if (check_block.inline_block == inline_block) { | |
| 1485 | if (check_block.inline_block == inline_block.toOptional()) { | |
| 1487 | 1486 | break check_block.runtime_index; |
| 1488 | 1487 | } |
| 1489 | 1488 | check_block = check_block.parent.?; |
| ... | ... | @@ -1534,7 +1533,7 @@ fn analyzeBodyInner( |
| 1534 | 1533 | .repeat => { |
| 1535 | 1534 | if (block.is_comptime) { |
| 1536 | 1535 | // 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); | |
| 1538 | 1537 | try sema.emitBackwardBranch(block, src); |
| 1539 | 1538 | |
| 1540 | 1539 | // We need to construct new capture scopes for the next loop iteration so it |
| ... | ... | @@ -1549,7 +1548,7 @@ fn analyzeBodyInner( |
| 1549 | 1548 | }, |
| 1550 | 1549 | .repeat_inline => { |
| 1551 | 1550 | // 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); | |
| 1553 | 1552 | try sema.emitBackwardBranch(block, src); |
| 1554 | 1553 | |
| 1555 | 1554 | // We need to construct new capture scopes for the next loop iteration so it |
| ... | ... | @@ -1562,9 +1561,9 @@ fn analyzeBodyInner( |
| 1562 | 1561 | .loop => blk: { |
| 1563 | 1562 | if (!block.is_comptime) break :blk try sema.zirLoop(block, inst); |
| 1564 | 1563 | // 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; | |
| 1566 | 1565 | 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); | |
| 1568 | 1567 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1569 | 1568 | break always_noreturn; |
| 1570 | 1569 | if (inst == break_data.block_inst) { |
| ... | ... | @@ -1575,12 +1574,12 @@ fn analyzeBodyInner( |
| 1575 | 1574 | }, |
| 1576 | 1575 | .block, .block_comptime => blk: { |
| 1577 | 1576 | 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); | |
| 1579 | 1578 | } |
| 1580 | 1579 | // 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; | |
| 1582 | 1581 | 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); | |
| 1584 | 1583 | // If this block contains a function prototype, we need to reset the |
| 1585 | 1584 | // current list of parameters and restore it later. |
| 1586 | 1585 | // Note: this probably needs to be resolved in a more general manner. |
| ... | ... | @@ -1601,9 +1600,9 @@ fn analyzeBodyInner( |
| 1601 | 1600 | // through a runtime conditional branch, we must retroactively emit |
| 1602 | 1601 | // a block, so we remember the block index here just in case. |
| 1603 | 1602 | const block_index = block.instructions.items.len; |
| 1604 | const inst_data = datas[inst].pl_node; | |
| 1603 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 1605 | 1604 | 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); | |
| 1607 | 1606 | const gpa = sema.gpa; |
| 1608 | 1607 | |
| 1609 | 1608 | const opt_break_data = b: { |
| ... | ... | @@ -1614,8 +1613,11 @@ fn analyzeBodyInner( |
| 1614 | 1613 | // If this block contains a function prototype, we need to reset the |
| 1615 | 1614 | // current list of parameters and restore it later. |
| 1616 | 1615 | // 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(); | |
| 1619 | 1621 | |
| 1620 | 1622 | var label: Block.Label = .{ |
| 1621 | 1623 | .zir_block = inst, |
| ... | ... | @@ -1682,11 +1684,14 @@ fn analyzeBodyInner( |
| 1682 | 1684 | .condbr => blk: { |
| 1683 | 1685 | if (!block.is_comptime) break sema.zirCondbr(block, inst); |
| 1684 | 1686 | // 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; | |
| 1686 | 1688 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 1687 | 1689 | 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 | ); | |
| 1690 | 1695 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1691 | 1696 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1692 | 1697 | .block_comptime_reason = block.comptime_reason, |
| ... | ... | @@ -1703,11 +1708,14 @@ fn analyzeBodyInner( |
| 1703 | 1708 | } |
| 1704 | 1709 | }, |
| 1705 | 1710 | .condbr_inline => blk: { |
| 1706 | const inst_data = datas[inst].pl_node; | |
| 1711 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 1707 | 1712 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 1708 | 1713 | 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 | ); | |
| 1711 | 1719 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1712 | 1720 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1713 | 1721 | .block_comptime_reason = block.comptime_reason, |
| ... | ... | @@ -1727,11 +1735,11 @@ fn analyzeBodyInner( |
| 1727 | 1735 | }, |
| 1728 | 1736 | .@"try" => blk: { |
| 1729 | 1737 | 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; | |
| 1731 | 1739 | const src = inst_data.src(); |
| 1732 | 1740 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1733 | 1741 | 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); | |
| 1735 | 1743 | const err_union = try sema.resolveInst(extra.data.operand); |
| 1736 | 1744 | const err_union_ty = sema.typeOf(err_union); |
| 1737 | 1745 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| ... | ... | @@ -1758,11 +1766,11 @@ fn analyzeBodyInner( |
| 1758 | 1766 | }, |
| 1759 | 1767 | .try_ptr => blk: { |
| 1760 | 1768 | 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; | |
| 1762 | 1770 | const src = inst_data.src(); |
| 1763 | 1771 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1764 | 1772 | 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); | |
| 1766 | 1774 | const operand = try sema.resolveInst(extra.data.operand); |
| 1767 | 1775 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1768 | 1776 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| ... | ... | @@ -1783,8 +1791,8 @@ fn analyzeBodyInner( |
| 1783 | 1791 | } |
| 1784 | 1792 | }, |
| 1785 | 1793 | .@"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); | |
| 1788 | 1796 | const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) { |
| 1789 | 1797 | error.ComptimeBreak => sema.comptime_break_inst, |
| 1790 | 1798 | else => |e| return e, |
| ... | ... | @@ -1793,9 +1801,9 @@ fn analyzeBodyInner( |
| 1793 | 1801 | break :blk .void_value; |
| 1794 | 1802 | }, |
| 1795 | 1803 | .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; | |
| 1797 | 1805 | 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); | |
| 1799 | 1807 | const err_code = try sema.resolveInst(inst_data.err_code); |
| 1800 | 1808 | map.putAssumeCapacity(extra.remapped_err_code, err_code); |
| 1801 | 1809 | 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 { |
| 1846 | 1854 | |
| 1847 | 1855 | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1848 | 1856 | 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 | } | |
| 1850 | 1862 | // First section of indexes correspond to a set number of constant values. |
| 1851 | 1863 | // 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)); | |
| 1857 | 1865 | } |
| 1858 | 1866 | |
| 1859 | 1867 | fn resolveConstBool( |
| ... | ... | @@ -1968,30 +1976,30 @@ const GenericPoisonReason = union(enum) { |
| 1968 | 1976 | fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 1969 | 1977 | var cur = ref; |
| 1970 | 1978 | 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)]) { | |
| 1973 | 1981 | .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; | |
| 1975 | 1983 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 1976 | 1984 | cur = extra.ptr_ty; |
| 1977 | 1985 | }, |
| 1978 | 1986 | .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; | |
| 1980 | 1988 | cur = bin.lhs; |
| 1981 | 1989 | }, |
| 1982 | 1990 | .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; | |
| 1984 | 1992 | cur = un_node.operand; |
| 1985 | 1993 | }, |
| 1986 | 1994 | .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; | |
| 1988 | 1996 | const extra = sema.code.extraData(Zir.Inst.FieldType, pl_node.payload_index).data; |
| 1989 | 1997 | cur = extra.container_type; |
| 1990 | 1998 | }, |
| 1991 | 1999 | .elem_type => { |
| 1992 | 2000 | // There are two cases here: the pointer type may already have been |
| 1993 | 2001 | // 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; | |
| 1995 | 2003 | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { |
| 1996 | 2004 | error.GenericPoison => unreachable, // this is a type, not a value |
| 1997 | 2005 | }; |
| ... | ... | @@ -2008,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 2008 | 2016 | // A function call can never return generic poison, so we must be |
| 2009 | 2017 | // evaluating an `anytype` function parameter. |
| 2010 | 2018 | // 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; | |
| 2012 | 2020 | return .{ .anytype_param = pl_node.src() }; |
| 2013 | 2021 | }, |
| 2014 | 2022 | else => return .unknown, |
| ... | ... | @@ -2651,7 +2659,7 @@ pub fn getStructType( |
| 2651 | 2659 | const mod = sema.mod; |
| 2652 | 2660 | const gpa = sema.gpa; |
| 2653 | 2661 | 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; | |
| 2655 | 2663 | assert(extended.opcode == .struct_decl); |
| 2656 | 2664 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2657 | 2665 | |
| ... | ... | @@ -2801,7 +2809,7 @@ fn createAnonymousDeclTypeNamed( |
| 2801 | 2809 | try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)}); |
| 2802 | 2810 | |
| 2803 | 2811 | 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)]) { | |
| 2805 | 2813 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { |
| 2806 | 2814 | const arg = sema.inst_map.get(zir_inst).?; |
| 2807 | 2815 | // If this is being called in a generic function then analyzeCall will |
| ... | ... | @@ -2827,11 +2835,10 @@ fn createAnonymousDeclTypeNamed( |
| 2827 | 2835 | return new_decl_index; |
| 2828 | 2836 | }, |
| 2829 | 2837 | .dbg_var => { |
| 2830 | const ref = Zir.indexToRef(inst.?); | |
| 2838 | const ref = inst.?.toRef(); | |
| 2831 | 2839 | const zir_tags = sema.code.instructions.items(.tag); |
| 2832 | 2840 | 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]) { | |
| 2835 | 2842 | .dbg_var_ptr, .dbg_var_val => { |
| 2836 | 2843 | if (zir_data[i].str_op.operand != ref) continue; |
| 2837 | 2844 | |
| ... | ... | @@ -2917,7 +2924,7 @@ fn zirEnumDecl( |
| 2917 | 2924 | |
| 2918 | 2925 | extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); |
| 2919 | 2926 | |
| 2920 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 2927 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 2921 | 2928 | extra_index += body.len; |
| 2922 | 2929 | |
| 2923 | 2930 | const bit_bags_count = std.math.divCeil(usize, fields_len, 32) catch unreachable; |
| ... | ... | @@ -3296,7 +3303,7 @@ fn zirErrorSetDecl( |
| 3296 | 3303 | |
| 3297 | 3304 | const mod = sema.mod; |
| 3298 | 3305 | 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; | |
| 3300 | 3307 | const src = inst_data.src(); |
| 3301 | 3308 | const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); |
| 3302 | 3309 | |
| ... | ... | @@ -3359,7 +3366,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 3359 | 3366 | const tracy = trace(@src()); |
| 3360 | 3367 | defer tracy.end(); |
| 3361 | 3368 | |
| 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; | |
| 3363 | 3370 | const operand = try sema.resolveInst(inst_data.operand); |
| 3364 | 3371 | return sema.analyzeRef(block, inst_data.src(), operand); |
| 3365 | 3372 | } |
| ... | ... | @@ -3368,7 +3375,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 3368 | 3375 | const tracy = trace(@src()); |
| 3369 | 3376 | defer tracy.end(); |
| 3370 | 3377 | |
| 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; | |
| 3372 | 3379 | const operand = try sema.resolveInst(inst_data.operand); |
| 3373 | 3380 | const src = inst_data.src(); |
| 3374 | 3381 | |
| ... | ... | @@ -3411,7 +3418,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3411 | 3418 | defer tracy.end(); |
| 3412 | 3419 | |
| 3413 | 3420 | 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; | |
| 3415 | 3422 | const operand = try sema.resolveInst(inst_data.operand); |
| 3416 | 3423 | const src = inst_data.src(); |
| 3417 | 3424 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -3434,7 +3441,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3434 | 3441 | defer tracy.end(); |
| 3435 | 3442 | |
| 3436 | 3443 | 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; | |
| 3438 | 3445 | const src = inst_data.src(); |
| 3439 | 3446 | const operand = try sema.resolveInst(inst_data.operand); |
| 3440 | 3447 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -3459,7 +3466,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 3459 | 3466 | const tracy = trace(@src()); |
| 3460 | 3467 | defer tracy.end(); |
| 3461 | 3468 | |
| 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; | |
| 3463 | 3470 | const src = inst_data.src(); |
| 3464 | 3471 | const object = try sema.resolveInst(inst_data.operand); |
| 3465 | 3472 | |
| ... | ... | @@ -3578,7 +3585,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3578 | 3585 | const tracy = trace(@src()); |
| 3579 | 3586 | defer tracy.end(); |
| 3580 | 3587 | |
| 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; | |
| 3582 | 3589 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3583 | 3590 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3584 | 3591 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | ... | @@ -3586,7 +3593,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3586 | 3593 | |
| 3587 | 3594 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3588 | 3595 | 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; | |
| 3590 | 3597 | const alloc = try sema.resolveInst(inst_data.operand); |
| 3591 | 3598 | const alloc_ty = sema.typeOf(alloc); |
| 3592 | 3599 | const ptr_info = alloc_ty.ptrInfo(mod); |
| ... | ... | @@ -3883,7 +3890,7 @@ fn zirAllocInferredComptime( |
| 3883 | 3890 | is_const: bool, |
| 3884 | 3891 | ) CompileError!Air.Inst.Ref { |
| 3885 | 3892 | 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; | |
| 3887 | 3894 | const src = LazySrcLoc.nodeOffset(src_node); |
| 3888 | 3895 | sema.src = src; |
| 3889 | 3896 | |
| ... | ... | @@ -3902,7 +3909,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3902 | 3909 | const tracy = trace(@src()); |
| 3903 | 3910 | defer tracy.end(); |
| 3904 | 3911 | |
| 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; | |
| 3906 | 3913 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3907 | 3914 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3908 | 3915 | if (block.is_comptime) { |
| ... | ... | @@ -3925,7 +3932,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 3925 | 3932 | const tracy = trace(@src()); |
| 3926 | 3933 | defer tracy.end(); |
| 3927 | 3934 | |
| 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; | |
| 3929 | 3936 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3930 | 3937 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3931 | 3938 | if (block.is_comptime) { |
| ... | ... | @@ -3951,7 +3958,7 @@ fn zirAllocInferred( |
| 3951 | 3958 | defer tracy.end(); |
| 3952 | 3959 | |
| 3953 | 3960 | 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; | |
| 3955 | 3962 | const src = LazySrcLoc.nodeOffset(src_node); |
| 3956 | 3963 | sema.src = src; |
| 3957 | 3964 | |
| ... | ... | @@ -3986,7 +3993,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3986 | 3993 | |
| 3987 | 3994 | const mod = sema.mod; |
| 3988 | 3995 | 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; | |
| 3990 | 3997 | const src = inst_data.src(); |
| 3991 | 3998 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3992 | 3999 | const ptr = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -4027,7 +4034,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4027 | 4034 | } }); |
| 4028 | 4035 | |
| 4029 | 4036 | // 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)); | |
| 4031 | 4038 | }, |
| 4032 | 4039 | .inferred_alloc => { |
| 4033 | 4040 | 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 |
| 4061 | 4068 | } }); |
| 4062 | 4069 | |
| 4063 | 4070 | // 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)); | |
| 4065 | 4072 | |
| 4066 | 4073 | // Unless the block is comptime, `alloc_inferred` always produces |
| 4067 | 4074 | // 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. |
| 4125 | 4132 | const mod = sema.mod; |
| 4126 | 4133 | const gpa = sema.gpa; |
| 4127 | 4134 | 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; | |
| 4129 | 4136 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 4130 | 4137 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| 4131 | 4138 | const src = inst_data.src(); |
| ... | ... | @@ -4264,14 +4271,14 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL |
| 4264 | 4271 | } |
| 4265 | 4272 | |
| 4266 | 4273 | fn 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; | |
| 4268 | 4275 | const ptr = try sema.resolveInst(un_node.operand); |
| 4269 | 4276 | return sema.optEuBasePtrInit(block, ptr, un_node.src()); |
| 4270 | 4277 | } |
| 4271 | 4278 | |
| 4272 | 4279 | fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4273 | 4280 | 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; | |
| 4275 | 4282 | const src = pl_node.src(); |
| 4276 | 4283 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4277 | 4284 | const uncoerced_val = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -4322,7 +4329,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4322 | 4329 | |
| 4323 | 4330 | fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4324 | 4331 | 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; | |
| 4326 | 4333 | const src = un_tok.src(); |
| 4327 | 4334 | // In case of GenericPoison, we don't actually have a type, so this will be |
| 4328 | 4335 | // treated as an untyped address-of operator. |
| ... | ... | @@ -4353,7 +4360,7 @@ fn zirValidateArrayInitRefTy( |
| 4353 | 4360 | inst: Zir.Inst.Index, |
| 4354 | 4361 | ) CompileError!Air.Inst.Ref { |
| 4355 | 4362 | 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; | |
| 4357 | 4364 | const src = pl_node.src(); |
| 4358 | 4365 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 4359 | 4366 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { |
| ... | ... | @@ -4389,7 +4396,7 @@ fn zirValidateArrayInitTy( |
| 4389 | 4396 | is_result_ty: bool, |
| 4390 | 4397 | ) CompileError!void { |
| 4391 | 4398 | 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; | |
| 4393 | 4400 | const src = inst_data.src(); |
| 4394 | 4401 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; |
| 4395 | 4402 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| ... | ... | @@ -4452,7 +4459,7 @@ fn zirValidateStructInitTy( |
| 4452 | 4459 | is_result_ty: bool, |
| 4453 | 4460 | ) CompileError!void { |
| 4454 | 4461 | 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; | |
| 4456 | 4463 | const src = inst_data.src(); |
| 4457 | 4464 | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 4458 | 4465 | // It's okay for the type to be unknown: this will result in an anonymous struct init. |
| ... | ... | @@ -4477,11 +4484,11 @@ fn zirValidatePtrStructInit( |
| 4477 | 4484 | defer tracy.end(); |
| 4478 | 4485 | |
| 4479 | 4486 | 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; | |
| 4481 | 4488 | const init_src = validate_inst.src(); |
| 4482 | 4489 | 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; | |
| 4485 | 4492 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4486 | 4493 | const object_ptr = try sema.resolveInst(field_ptr_extra.lhs); |
| 4487 | 4494 | const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod); |
| ... | ... | @@ -4525,7 +4532,7 @@ fn validateUnionInit( |
| 4525 | 4532 | errdefer msg.destroy(gpa); |
| 4526 | 4533 | |
| 4527 | 4534 | 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; | |
| 4529 | 4536 | const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node }; |
| 4530 | 4537 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); |
| 4531 | 4538 | } |
| ... | ... | @@ -4543,7 +4550,7 @@ fn validateUnionInit( |
| 4543 | 4550 | } |
| 4544 | 4551 | |
| 4545 | 4552 | 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; | |
| 4547 | 4554 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4548 | 4555 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4549 | 4556 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start)); |
| ... | ... | @@ -4662,14 +4669,14 @@ fn validateStructInit( |
| 4662 | 4669 | defer gpa.free(field_indices); |
| 4663 | 4670 | |
| 4664 | 4671 | // 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)); | |
| 4666 | 4673 | defer gpa.free(found_fields); |
| 4667 | @memset(found_fields, 0); | |
| 4674 | @memset(found_fields, .none); | |
| 4668 | 4675 | |
| 4669 | 4676 | var struct_ptr_zir_ref: Zir.Inst.Ref = undefined; |
| 4670 | 4677 | |
| 4671 | 4678 | 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; | |
| 4673 | 4680 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4674 | 4681 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4675 | 4682 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| ... | ... | @@ -4681,9 +4688,8 @@ fn validateStructInit( |
| 4681 | 4688 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) |
| 4682 | 4689 | else |
| 4683 | 4690 | 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; | |
| 4687 | 4693 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_ptr_data.src_node }; |
| 4688 | 4694 | const msg = msg: { |
| 4689 | 4695 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| ... | ... | @@ -4693,7 +4699,7 @@ fn validateStructInit( |
| 4693 | 4699 | }; |
| 4694 | 4700 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4695 | 4701 | } |
| 4696 | found_fields[field_index.*] = field_ptr; | |
| 4702 | found_fields[field_index.*] = field_ptr.toOptional(); | |
| 4697 | 4703 | } |
| 4698 | 4704 | |
| 4699 | 4705 | var root_msg: ?*Module.ErrorMsg = null; |
| ... | ... | @@ -4709,7 +4715,7 @@ fn validateStructInit( |
| 4709 | 4715 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. |
| 4710 | 4716 | for (found_fields, 0..) |field_ptr, i_usize| { |
| 4711 | 4717 | const i: u32 = @intCast(i_usize); |
| 4712 | if (field_ptr != 0) continue; | |
| 4718 | if (field_ptr != .none) continue; | |
| 4713 | 4719 | |
| 4714 | 4720 | const default_val = struct_ty.structFieldDefaultValue(i, mod); |
| 4715 | 4721 | if (default_val.toIntern() == .unreachable_value) { |
| ... | ... | @@ -4770,9 +4776,9 @@ fn validateStructInit( |
| 4770 | 4776 | // ends up being comptime-known. |
| 4771 | 4777 | const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod)); |
| 4772 | 4778 | |
| 4773 | field: for (found_fields, 0..) |field_ptr, i_usize| { | |
| 4779 | field: for (found_fields, 0..) |opt_field_ptr, i_usize| { | |
| 4774 | 4780 | const i: u32 = @intCast(i_usize); |
| 4775 | if (field_ptr != 0) { | |
| 4781 | if (opt_field_ptr.unwrap()) |field_ptr| { | |
| 4776 | 4782 | // Determine whether the value stored to this pointer is comptime-known. |
| 4777 | 4783 | const field_ty = struct_ty.structFieldType(i, mod); |
| 4778 | 4784 | if (try sema.typeHasOnePossibleValue(field_ty)) |opv| { |
| ... | ... | @@ -4831,7 +4837,7 @@ fn validateStructInit( |
| 4831 | 4837 | if (try sema.resolveValue(bin_op.rhs)) |val| { |
| 4832 | 4838 | field_values[i] = val.toIntern(); |
| 4833 | 4839 | } 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; | |
| 4835 | 4841 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| 4836 | 4842 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 4837 | 4843 | }); |
| ... | ... | @@ -4931,7 +4937,7 @@ fn validateStructInit( |
| 4931 | 4937 | |
| 4932 | 4938 | // Our task is to insert `store` instructions for all the default field values. |
| 4933 | 4939 | for (found_fields, 0..) |field_ptr, i| { |
| 4934 | if (field_ptr != 0) continue; | |
| 4940 | if (field_ptr != .none) continue; | |
| 4935 | 4941 | |
| 4936 | 4942 | const field_src = init_src; // TODO better source location |
| 4937 | 4943 | const default_field_ptr = if (struct_ty.isTuple(mod)) |
| ... | ... | @@ -4950,11 +4956,11 @@ fn zirValidatePtrArrayInit( |
| 4950 | 4956 | inst: Zir.Inst.Index, |
| 4951 | 4957 | ) CompileError!void { |
| 4952 | 4958 | 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; | |
| 4954 | 4960 | const init_src = validate_inst.src(); |
| 4955 | 4961 | 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; | |
| 4958 | 4964 | const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data; |
| 4959 | 4965 | const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr); |
| 4960 | 4966 | const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod); |
| ... | ... | @@ -5147,7 +5153,7 @@ fn zirValidatePtrArrayInit( |
| 5147 | 5153 | |
| 5148 | 5154 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5149 | 5155 | 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; | |
| 5151 | 5157 | const src = inst_data.src(); |
| 5152 | 5158 | const operand = try sema.resolveInst(inst_data.operand); |
| 5153 | 5159 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -5190,7 +5196,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5190 | 5196 | |
| 5191 | 5197 | fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5192 | 5198 | 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; | |
| 5194 | 5200 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 5195 | 5201 | const src = inst_data.src(); |
| 5196 | 5202 | const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node); |
| ... | ... | @@ -5328,7 +5334,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 5328 | 5334 | defer tracy.end(); |
| 5329 | 5335 | |
| 5330 | 5336 | 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; | |
| 5332 | 5338 | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 5333 | 5339 | const operand = try sema.resolveInst(bin_inst.rhs); |
| 5334 | 5340 | const ptr_inst = Air.refToIndex(ptr).?; |
| ... | ... | @@ -5387,7 +5393,7 @@ fn storeToInferredAllocComptime( |
| 5387 | 5393 | } |
| 5388 | 5394 | |
| 5389 | 5395 | fn 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; | |
| 5391 | 5397 | const src = inst_data.src(); |
| 5392 | 5398 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ |
| 5393 | 5399 | .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 |
| 5399 | 5405 | const tracy = trace(@src()); |
| 5400 | 5406 | defer tracy.end(); |
| 5401 | 5407 | |
| 5402 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 5408 | const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; | |
| 5403 | 5409 | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 5404 | 5410 | const value = try sema.resolveInst(bin_inst.rhs); |
| 5405 | 5411 | return sema.storePtr(block, sema.src, ptr, value); |
| ... | ... | @@ -5412,14 +5418,14 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5412 | 5418 | const mod = sema.mod; |
| 5413 | 5419 | const zir_tags = sema.code.instructions.items(.tag); |
| 5414 | 5420 | 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; | |
| 5416 | 5422 | const src = inst_data.src(); |
| 5417 | 5423 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5418 | 5424 | const ptr = try sema.resolveInst(extra.lhs); |
| 5419 | 5425 | const operand = try sema.resolveInst(extra.rhs); |
| 5420 | 5426 | |
| 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 | |
| 5423 | 5429 | else |
| 5424 | 5430 | false; |
| 5425 | 5431 | |
| ... | ... | @@ -5445,7 +5451,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5445 | 5451 | } |
| 5446 | 5452 | |
| 5447 | 5453 | fn 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); | |
| 5449 | 5455 | return sema.addStrLitNoAlias(bytes); |
| 5450 | 5456 | } |
| 5451 | 5457 | |
| ... | ... | @@ -5497,7 +5503,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 5497 | 5503 | const tracy = trace(@src()); |
| 5498 | 5504 | defer tracy.end(); |
| 5499 | 5505 | |
| 5500 | const int = sema.code.instructions.items(.data)[inst].int; | |
| 5506 | const int = sema.code.instructions.items(.data)[@intFromEnum(inst)].int; | |
| 5501 | 5507 | return sema.mod.intRef(Type.comptime_int, int); |
| 5502 | 5508 | } |
| 5503 | 5509 | |
| ... | ... | @@ -5507,7 +5513,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 5507 | 5513 | defer tracy.end(); |
| 5508 | 5514 | |
| 5509 | 5515 | 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; | |
| 5511 | 5517 | const byte_count = int.len * @sizeOf(std.math.big.Limb); |
| 5512 | 5518 | const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count]; |
| 5513 | 5519 | |
| ... | ... | @@ -5525,7 +5531,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 5525 | 5531 | |
| 5526 | 5532 | fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5527 | 5533 | _ = block; |
| 5528 | const number = sema.code.instructions.items(.data)[inst].float; | |
| 5534 | const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float; | |
| 5529 | 5535 | return Air.internedToRef((try sema.mod.floatValue( |
| 5530 | 5536 | Type.comptime_float, |
| 5531 | 5537 | number, |
| ... | ... | @@ -5534,7 +5540,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 5534 | 5540 | |
| 5535 | 5541 | fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5536 | 5542 | _ = 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; | |
| 5538 | 5544 | const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 5539 | 5545 | const number = extra.get(); |
| 5540 | 5546 | 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 |
| 5544 | 5550 | const tracy = trace(@src()); |
| 5545 | 5551 | defer tracy.end(); |
| 5546 | 5552 | |
| 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; | |
| 5548 | 5554 | const src = inst_data.src(); |
| 5549 | 5555 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5550 | 5556 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| ... | ... | @@ -5594,7 +5600,7 @@ fn zirCompileLog( |
| 5594 | 5600 | } |
| 5595 | 5601 | |
| 5596 | 5602 | fn 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; | |
| 5598 | 5604 | const src = inst_data.src(); |
| 5599 | 5605 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 5600 | 5606 | |
| ... | ... | @@ -5606,7 +5612,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I |
| 5606 | 5612 | } |
| 5607 | 5613 | |
| 5608 | 5614 | fn 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; | |
| 5610 | 5616 | const src = LazySrcLoc.nodeOffset(src_node); |
| 5611 | 5617 | sema.src = src; |
| 5612 | 5618 | _ = try block.addNoOp(.trap); |
| ... | ... | @@ -5618,10 +5624,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5618 | 5624 | defer tracy.end(); |
| 5619 | 5625 | |
| 5620 | 5626 | 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; | |
| 5622 | 5628 | const src = inst_data.src(); |
| 5623 | 5629 | 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); | |
| 5625 | 5631 | const gpa = sema.gpa; |
| 5626 | 5632 | |
| 5627 | 5633 | // 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 |
| 5690 | 5696 | const mod = sema.mod; |
| 5691 | 5697 | const comp = mod.comp; |
| 5692 | 5698 | 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; | |
| 5694 | 5700 | const src = pl_node.src(); |
| 5695 | 5701 | 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); | |
| 5697 | 5703 | |
| 5698 | 5704 | // we check this here to avoid undefined symbols |
| 5699 | 5705 | if (!@import("build_options").have_llvm) |
| ... | ... | @@ -5768,7 +5774,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5768 | 5774 | } |
| 5769 | 5775 | |
| 5770 | 5776 | fn 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; | |
| 5772 | 5778 | const src = inst_data.src(); |
| 5773 | 5779 | return sema.failWithUseOfAsync(parent_block, src); |
| 5774 | 5780 | } |
| ... | ... | @@ -5777,10 +5783,10 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 5777 | 5783 | const tracy = trace(@src()); |
| 5778 | 5784 | defer tracy.end(); |
| 5779 | 5785 | |
| 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; | |
| 5781 | 5787 | const src = pl_node.src(); |
| 5782 | 5788 | 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); | |
| 5784 | 5790 | const gpa = sema.gpa; |
| 5785 | 5791 | |
| 5786 | 5792 | // Reserve space for a Block instruction so that generated Break instructions can |
| ... | ... | @@ -5852,7 +5858,7 @@ fn resolveBlockBody( |
| 5852 | 5858 | try parent_block.instructions.appendSlice(sema.gpa, child_block.instructions.items); |
| 5853 | 5859 | |
| 5854 | 5860 | 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"; | |
| 5856 | 5862 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 5857 | 5863 | if (extra.block_inst == body_inst) { |
| 5858 | 5864 | return try sema.resolveInst(break_data.operand); |
| ... | ... | @@ -5991,7 +5997,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5991 | 5997 | defer tracy.end(); |
| 5992 | 5998 | |
| 5993 | 5999 | 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; | |
| 5995 | 6001 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 5996 | 6002 | const src = inst_data.src(); |
| 5997 | 6003 | 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 |
| 6027 | 6033 | defer tracy.end(); |
| 6028 | 6034 | |
| 6029 | 6035 | 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; | |
| 6031 | 6037 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 6032 | 6038 | const src = inst_data.src(); |
| 6033 | 6039 | 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 |
| 6198 | 6204 | } |
| 6199 | 6205 | |
| 6200 | 6206 | fn 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; | |
| 6202 | 6208 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6203 | 6209 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| 6204 | 6210 | .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 |
| 6228 | 6234 | const tracy = trace(@src()); |
| 6229 | 6235 | defer tracy.end(); |
| 6230 | 6236 | |
| 6231 | const inst_data = sema.code.instructions.items(.data)[inst].@"break"; | |
| 6237 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break"; | |
| 6232 | 6238 | const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 6233 | 6239 | const operand = try sema.resolveInst(inst_data.operand); |
| 6234 | 6240 | const zir_block = extra.block_inst; |
| ... | ... | @@ -6264,7 +6270,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 6264 | 6270 | // instructions. |
| 6265 | 6271 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return; |
| 6266 | 6272 | |
| 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; | |
| 6268 | 6274 | |
| 6269 | 6275 | if (block.instructions.items.len != 0) { |
| 6270 | 6276 | const idx = block.instructions.items[block.instructions.items.len - 1]; |
| ... | ... | @@ -6313,7 +6319,7 @@ fn zirDbgVar( |
| 6313 | 6319 | ) CompileError!void { |
| 6314 | 6320 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return; |
| 6315 | 6321 | |
| 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; | |
| 6317 | 6323 | const operand = try sema.resolveInst(str_op.operand); |
| 6318 | 6324 | const name = str_op.getStr(sema.code); |
| 6319 | 6325 | try sema.addDbgVar(block, operand, air_tag, name); |
| ... | ... | @@ -6358,7 +6364,7 @@ fn addDbgVar( |
| 6358 | 6364 | |
| 6359 | 6365 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6360 | 6366 | 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; | |
| 6362 | 6368 | const src = inst_data.src(); |
| 6363 | 6369 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6364 | 6370 | 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 |
| 6368 | 6374 | |
| 6369 | 6375 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6370 | 6376 | 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; | |
| 6372 | 6378 | const src = inst_data.src(); |
| 6373 | 6379 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6374 | 6380 | const decl = try sema.lookupIdentifier(block, src, decl_name); |
| ... | ... | @@ -6637,7 +6643,7 @@ fn zirCall( |
| 6637 | 6643 | defer tracy.end(); |
| 6638 | 6644 | |
| 6639 | 6645 | 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; | |
| 6641 | 6647 | const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; |
| 6642 | 6648 | const call_src = inst_data.src(); |
| 6643 | 6649 | const ExtraType = switch (kind) { |
| ... | ... | @@ -6685,12 +6691,12 @@ fn zirCall( |
| 6685 | 6691 | .call_inst = inst, |
| 6686 | 6692 | .call_node_offset = inst_data.src_node, |
| 6687 | 6693 | .num_args = args_len, |
| 6688 | .args_body = sema.code.extra[extra.end..], | |
| 6694 | .args_body = @ptrCast(sema.code.extra[extra.end..]), | |
| 6689 | 6695 | .any_arg_is_error = &input_is_error, |
| 6690 | 6696 | } }; |
| 6691 | 6697 | |
| 6692 | 6698 | // 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); | |
| 6694 | 6700 | const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call); |
| 6695 | 6701 | |
| 6696 | 6702 | if (sema.owner_func_index == .none or |
| ... | ... | @@ -6961,11 +6967,11 @@ const CallArgsInfo = union(enum) { |
| 6961 | 6967 | |
| 6962 | 6968 | const arg_body = if (real_arg_idx == 0) blk: { |
| 6963 | 6969 | const start = zir_call.num_args; |
| 6964 | const end = zir_call.args_body[0]; | |
| 6970 | const end = @intFromEnum(zir_call.args_body[0]); | |
| 6965 | 6971 | break :blk zir_call.args_body[start..end]; |
| 6966 | 6972 | } 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]); | |
| 6969 | 6975 | break :blk zir_call.args_body[start..end]; |
| 6970 | 6976 | }; |
| 6971 | 6977 | |
| ... | ... | @@ -7447,9 +7453,9 @@ fn analyzeCall( |
| 7447 | 7453 | try sema.emitDbgInline(block, prev_fn_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin); |
| 7448 | 7454 | |
| 7449 | 7455 | 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)]) { | |
| 7451 | 7457 | .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; | |
| 7453 | 7459 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 7454 | 7460 | const param_name = sema.code.nullTerminatedString(extra.data.name); |
| 7455 | 7461 | const inst = sema.inst_map.get(param).?; |
| ... | ... | @@ -7457,7 +7463,7 @@ fn analyzeCall( |
| 7457 | 7463 | try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name); |
| 7458 | 7464 | }, |
| 7459 | 7465 | .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; | |
| 7461 | 7467 | const param_name = inst_data.get(sema.code); |
| 7462 | 7468 | const inst = sema.inst_map.get(param).?; |
| 7463 | 7469 | |
| ... | ... | @@ -7640,18 +7646,18 @@ fn analyzeInlineCallArg( |
| 7640 | 7646 | const mod = ics.sema.mod; |
| 7641 | 7647 | const ip = &mod.intern_pool; |
| 7642 | 7648 | const zir_tags = ics.callee().code.instructions.items(.tag); |
| 7643 | switch (zir_tags[inst]) { | |
| 7649 | switch (zir_tags[@intFromEnum(inst)]) { | |
| 7644 | 7650 | .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true, |
| 7645 | 7651 | else => {}, |
| 7646 | 7652 | } |
| 7647 | switch (zir_tags[inst]) { | |
| 7653 | switch (zir_tags[@intFromEnum(inst)]) { | |
| 7648 | 7654 | .param, .param_comptime => { |
| 7649 | 7655 | // Evaluate the parameter type expression now that previous ones have |
| 7650 | 7656 | // 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; | |
| 7652 | 7658 | const param_src = pl_tok.src(); |
| 7653 | 7659 | 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); | |
| 7655 | 7661 | const param_ty = param_ty: { |
| 7656 | 7662 | const raw_param_ty = func_ty_info.param_types.get(ip)[arg_i.*]; |
| 7657 | 7663 | if (raw_param_ty != .generic_poison_type) break :param_ty raw_param_ty; |
| ... | ... | @@ -7670,7 +7676,7 @@ fn analyzeInlineCallArg( |
| 7670 | 7676 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", |
| 7671 | 7677 | .block_comptime_reason = param_block.comptime_reason, |
| 7672 | 7678 | }); |
| 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) { | |
| 7674 | 7680 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ |
| 7675 | 7681 | .needed_comptime_reason = "parameter is comptime", |
| 7676 | 7682 | }); |
| ... | ... | @@ -7736,7 +7742,7 @@ fn analyzeInlineCallArg( |
| 7736 | 7742 | should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod); |
| 7737 | 7743 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); |
| 7738 | 7744 | } else { |
| 7739 | if (zir_tags[inst] == .param_anytype_comptime) { | |
| 7745 | if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) { | |
| 7740 | 7746 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ |
| 7741 | 7747 | .needed_comptime_reason = "parameter is comptime", |
| 7742 | 7748 | }); |
| ... | ... | @@ -7864,7 +7870,7 @@ fn instantiateGenericCall( |
| 7864 | 7870 | try child_sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body); |
| 7865 | 7871 | |
| 7866 | 7872 | 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)]; | |
| 7868 | 7874 | |
| 7869 | 7875 | const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) { |
| 7870 | 7876 | else => |ty| ty.toType(), // parameter is not generic, so type is already resolved |
| ... | ... | @@ -7879,9 +7885,9 @@ fn instantiateGenericCall( |
| 7879 | 7885 | .param, .param_comptime => { |
| 7880 | 7886 | // We now know every prior parameter, so can resolve this |
| 7881 | 7887 | // 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; | |
| 7883 | 7889 | 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); | |
| 7885 | 7891 | |
| 7886 | 7892 | // Make sure any nested instructions don't clobber our work. |
| 7887 | 7893 | const prev_params = child_block.params; |
| ... | ... | @@ -7937,8 +7943,8 @@ fn instantiateGenericCall( |
| 7937 | 7943 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); |
| 7938 | 7944 | errdefer msg.destroy(sema.gpa); |
| 7939 | 7945 | 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(), | |
| 7942 | 7948 | else => unreachable, |
| 7943 | 7949 | }; |
| 7944 | 7950 | try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); |
| ... | ... | @@ -7952,8 +7958,8 @@ fn instantiateGenericCall( |
| 7952 | 7958 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); |
| 7953 | 7959 | errdefer msg.destroy(sema.gpa); |
| 7954 | 7960 | 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(), | |
| 7957 | 7963 | else => unreachable, |
| 7958 | 7964 | }; |
| 7959 | 7965 | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); |
| ... | ... | @@ -7975,9 +7981,9 @@ fn instantiateGenericCall( |
| 7975 | 7981 | } }, |
| 7976 | 7982 | })); |
| 7977 | 7983 | 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), | |
| 7979 | 7985 | .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; | |
| 7981 | 7987 | const extra = fn_zir.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 7982 | 7988 | break :name @enumFromInt(extra.data.name); |
| 7983 | 7989 | }, |
| ... | ... | @@ -8094,7 +8100,7 @@ fn emitDbgInline( |
| 8094 | 8100 | |
| 8095 | 8101 | fn zirIntType(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8096 | 8102 | 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; | |
| 8098 | 8104 | const ty = try mod.intType(int_type.signedness, int_type.bit_count); |
| 8099 | 8105 | return Air.internedToRef(ty.toIntern()); |
| 8100 | 8106 | } |
| ... | ... | @@ -8104,7 +8110,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8104 | 8110 | defer tracy.end(); |
| 8105 | 8111 | |
| 8106 | 8112 | 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; | |
| 8108 | 8114 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 8109 | 8115 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8110 | 8116 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| ... | ... | @@ -8119,7 +8125,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8119 | 8125 | |
| 8120 | 8126 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8121 | 8127 | 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; | |
| 8123 | 8129 | const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) { |
| 8124 | 8130 | // Since this is a ZIR instruction that returns a type, encountering |
| 8125 | 8131 | // 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 |
| 8142 | 8148 | |
| 8143 | 8149 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8144 | 8150 | 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; | |
| 8146 | 8152 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { |
| 8147 | 8153 | error.GenericPoison => return .generic_poison_type, |
| 8148 | 8154 | else => |e| return e, |
| ... | ... | @@ -8160,7 +8166,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8160 | 8166 | |
| 8161 | 8167 | fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8162 | 8168 | 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; | |
| 8164 | 8170 | const src = un_node.src(); |
| 8165 | 8171 | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { |
| 8166 | 8172 | error.GenericPoison => return .generic_poison_type, |
| ... | ... | @@ -8176,7 +8182,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8176 | 8182 | |
| 8177 | 8183 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8178 | 8184 | 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; | |
| 8180 | 8186 | const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { |
| 8181 | 8187 | // Since this is a ZIR instruction that returns a type, encountering |
| 8182 | 8188 | // 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 |
| 8193 | 8199 | |
| 8194 | 8200 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8195 | 8201 | 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; | |
| 8197 | 8203 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8198 | 8204 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 8199 | 8205 | 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 |
| 8213 | 8219 | const tracy = trace(@src()); |
| 8214 | 8220 | defer tracy.end(); |
| 8215 | 8221 | |
| 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; | |
| 8217 | 8223 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8218 | 8224 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8219 | 8225 | 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 |
| 8234 | 8240 | const tracy = trace(@src()); |
| 8235 | 8241 | defer tracy.end(); |
| 8236 | 8242 | |
| 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; | |
| 8238 | 8244 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 8239 | 8245 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8240 | 8246 | 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 |
| 8271 | 8277 | const tracy = trace(@src()); |
| 8272 | 8278 | defer tracy.end(); |
| 8273 | 8279 | |
| 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; | |
| 8275 | 8281 | if (true) { |
| 8276 | 8282 | return sema.failWithUseOfAsync(block, inst_data.src()); |
| 8277 | 8283 | } |
| ... | ... | @@ -8288,7 +8294,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8288 | 8294 | defer tracy.end(); |
| 8289 | 8295 | |
| 8290 | 8296 | 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; | |
| 8292 | 8298 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8293 | 8299 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 8294 | 8300 | 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 |
| 8321 | 8327 | fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8322 | 8328 | _ = block; |
| 8323 | 8329 | 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; | |
| 8325 | 8331 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 8326 | 8332 | _ = try mod.getErrorValue(name); |
| 8327 | 8333 | // 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 |
| 8420 | 8426 | |
| 8421 | 8427 | const mod = sema.mod; |
| 8422 | 8428 | 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; | |
| 8424 | 8430 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8425 | 8431 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 8426 | 8432 | 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 |
| 8475 | 8481 | defer tracy.end(); |
| 8476 | 8482 | |
| 8477 | 8483 | 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; | |
| 8479 | 8485 | const name = inst_data.get(sema.code); |
| 8480 | 8486 | return Air.internedToRef((try mod.intern(.{ |
| 8481 | 8487 | .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 |
| 8484 | 8490 | |
| 8485 | 8491 | fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8486 | 8492 | 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; | |
| 8488 | 8494 | const src = inst_data.src(); |
| 8489 | 8495 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8490 | 8496 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -8529,7 +8535,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8529 | 8535 | |
| 8530 | 8536 | fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8531 | 8537 | 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; | |
| 8533 | 8539 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8534 | 8540 | const src = inst_data.src(); |
| 8535 | 8541 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -8610,7 +8616,7 @@ fn zirOptionalPayloadPtr( |
| 8610 | 8616 | const tracy = trace(@src()); |
| 8611 | 8617 | defer tracy.end(); |
| 8612 | 8618 | |
| 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; | |
| 8614 | 8620 | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 8615 | 8621 | const src = inst_data.src(); |
| 8616 | 8622 | |
| ... | ... | @@ -8695,7 +8701,7 @@ fn zirOptionalPayload( |
| 8695 | 8701 | defer tracy.end(); |
| 8696 | 8702 | |
| 8697 | 8703 | 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; | |
| 8699 | 8705 | const src = inst_data.src(); |
| 8700 | 8706 | const operand = try sema.resolveInst(inst_data.operand); |
| 8701 | 8707 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -8747,7 +8753,7 @@ fn zirErrUnionPayload( |
| 8747 | 8753 | defer tracy.end(); |
| 8748 | 8754 | |
| 8749 | 8755 | 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; | |
| 8751 | 8757 | const src = inst_data.src(); |
| 8752 | 8758 | const operand = try sema.resolveInst(inst_data.operand); |
| 8753 | 8759 | const operand_src = src; |
| ... | ... | @@ -8799,7 +8805,7 @@ fn zirErrUnionPayloadPtr( |
| 8799 | 8805 | const tracy = trace(@src()); |
| 8800 | 8806 | defer tracy.end(); |
| 8801 | 8807 | |
| 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; | |
| 8803 | 8809 | const operand = try sema.resolveInst(inst_data.operand); |
| 8804 | 8810 | const src = inst_data.src(); |
| 8805 | 8811 | |
| ... | ... | @@ -8883,7 +8889,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8883 | 8889 | const tracy = trace(@src()); |
| 8884 | 8890 | defer tracy.end(); |
| 8885 | 8891 | |
| 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; | |
| 8887 | 8893 | const src = inst_data.src(); |
| 8888 | 8894 | const operand = try sema.resolveInst(inst_data.operand); |
| 8889 | 8895 | return sema.analyzeErrUnionCode(block, src, operand); |
| ... | ... | @@ -8917,7 +8923,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8917 | 8923 | defer tracy.end(); |
| 8918 | 8924 | |
| 8919 | 8925 | 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; | |
| 8921 | 8927 | const src = inst_data.src(); |
| 8922 | 8928 | const operand = try sema.resolveInst(inst_data.operand); |
| 8923 | 8929 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -8949,7 +8955,7 @@ fn zirFunc( |
| 8949 | 8955 | inferred_error_set: bool, |
| 8950 | 8956 | ) CompileError!Air.Inst.Ref { |
| 8951 | 8957 | 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; | |
| 8953 | 8959 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 8954 | 8960 | const target = sema.mod.getTarget(); |
| 8955 | 8961 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; |
| ... | ... | @@ -8971,7 +8977,7 @@ fn zirFunc( |
| 8971 | 8977 | } |
| 8972 | 8978 | }, |
| 8973 | 8979 | 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); | |
| 8975 | 8981 | extra_index += ret_ty_body.len; |
| 8976 | 8982 | |
| 8977 | 8983 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ |
| ... | ... | @@ -9591,9 +9597,9 @@ fn finishFunc( |
| 9591 | 9597 | param_body[0..block.params.len], |
| 9592 | 9598 | ) |is_comptime, name_nts, param_index| { |
| 9593 | 9599 | 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(), | |
| 9597 | 9603 | else => unreachable, |
| 9598 | 9604 | }; |
| 9599 | 9605 | const name = sema.code.nullTerminatedString2(name_nts); |
| ... | ... | @@ -9667,11 +9673,11 @@ fn zirParam( |
| 9667 | 9673 | inst: Zir.Inst.Index, |
| 9668 | 9674 | comptime_syntax: bool, |
| 9669 | 9675 | ) 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; | |
| 9671 | 9677 | const src = inst_data.src(); |
| 9672 | 9678 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 9673 | 9679 | 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); | |
| 9675 | 9681 | |
| 9676 | 9682 | const param_ty = param_ty: { |
| 9677 | 9683 | const err = err: { |
| ... | ... | @@ -9760,7 +9766,7 @@ fn zirParamAnytype( |
| 9760 | 9766 | inst: Zir.Inst.Index, |
| 9761 | 9767 | comptime_syntax: bool, |
| 9762 | 9768 | ) 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; | |
| 9764 | 9770 | const param_name: Zir.NullTerminatedString = @enumFromInt(inst_data.start); |
| 9765 | 9771 | |
| 9766 | 9772 | // 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 |
| 9777 | 9783 | const tracy = trace(@src()); |
| 9778 | 9784 | defer tracy.end(); |
| 9779 | 9785 | |
| 9780 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 9786 | const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; | |
| 9781 | 9787 | return sema.analyzeAs(block, sema.src, bin_inst.lhs, bin_inst.rhs, false); |
| 9782 | 9788 | } |
| 9783 | 9789 | |
| ... | ... | @@ -9785,7 +9791,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 9785 | 9791 | const tracy = trace(@src()); |
| 9786 | 9792 | defer tracy.end(); |
| 9787 | 9793 | |
| 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; | |
| 9789 | 9795 | const src = inst_data.src(); |
| 9790 | 9796 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 9791 | 9797 | sema.src = src; |
| ... | ... | @@ -9796,7 +9802,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 9796 | 9802 | const tracy = trace(@src()); |
| 9797 | 9803 | defer tracy.end(); |
| 9798 | 9804 | |
| 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; | |
| 9800 | 9806 | const src = inst_data.src(); |
| 9801 | 9807 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 9802 | 9808 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); |
| ... | ... | @@ -9828,8 +9834,8 @@ fn analyzeAs( |
| 9828 | 9834 | if (dest_ty_tag == .NoReturn) { |
| 9829 | 9835 | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 9830 | 9836 | } |
| 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 | |
| 9833 | 9839 | else |
| 9834 | 9840 | false; |
| 9835 | 9841 | 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! |
| 9843 | 9849 | defer tracy.end(); |
| 9844 | 9850 | |
| 9845 | 9851 | 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; | |
| 9847 | 9853 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9848 | 9854 | const operand = try sema.resolveInst(inst_data.operand); |
| 9849 | 9855 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -9909,7 +9915,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9909 | 9915 | defer tracy.end(); |
| 9910 | 9916 | |
| 9911 | 9917 | 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; | |
| 9913 | 9919 | const src = inst_data.src(); |
| 9914 | 9920 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9915 | 9921 | 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 |
| 9923 | 9929 | defer tracy.end(); |
| 9924 | 9930 | |
| 9925 | 9931 | 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; | |
| 9927 | 9933 | const src = inst_data.src(); |
| 9928 | 9934 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9929 | 9935 | 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 |
| 9937 | 9943 | defer tracy.end(); |
| 9938 | 9944 | |
| 9939 | 9945 | 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; | |
| 9941 | 9947 | const src = inst_data.src(); |
| 9942 | 9948 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9943 | 9949 | 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 |
| 9958 | 9964 | const tracy = trace(@src()); |
| 9959 | 9965 | defer tracy.end(); |
| 9960 | 9966 | |
| 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; | |
| 9962 | 9968 | const src = inst_data.src(); |
| 9963 | 9969 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9964 | 9970 | 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 |
| 9973 | 9979 | const tracy = trace(@src()); |
| 9974 | 9980 | defer tracy.end(); |
| 9975 | 9981 | |
| 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; | |
| 9977 | 9983 | const src = inst_data.src(); |
| 9978 | 9984 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9979 | 9985 | 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 |
| 9988 | 9994 | const tracy = trace(@src()); |
| 9989 | 9995 | defer tracy.end(); |
| 9990 | 9996 | |
| 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; | |
| 9992 | 9998 | const src = inst_data.src(); |
| 9993 | 9999 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9994 | 10000 | 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 |
| 10149 | 10155 | defer tracy.end(); |
| 10150 | 10156 | |
| 10151 | 10157 | 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; | |
| 10153 | 10159 | const src = inst_data.src(); |
| 10154 | 10160 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 10155 | 10161 | 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 |
| 10292 | 10298 | defer tracy.end(); |
| 10293 | 10299 | |
| 10294 | 10300 | 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; | |
| 10296 | 10302 | const src = inst_data.src(); |
| 10297 | 10303 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 10298 | 10304 | 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 |
| 10371 | 10377 | const tracy = trace(@src()); |
| 10372 | 10378 | defer tracy.end(); |
| 10373 | 10379 | |
| 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; | |
| 10375 | 10381 | const src = inst_data.src(); |
| 10376 | 10382 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10377 | 10383 | const array = try sema.resolveInst(extra.lhs); |
| ... | ... | @@ -10383,7 +10389,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10383 | 10389 | const tracy = trace(@src()); |
| 10384 | 10390 | defer tracy.end(); |
| 10385 | 10391 | |
| 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; | |
| 10387 | 10393 | const src = inst_data.src(); |
| 10388 | 10394 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 10389 | 10395 | 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! |
| 10397 | 10403 | defer tracy.end(); |
| 10398 | 10404 | |
| 10399 | 10405 | 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; | |
| 10401 | 10407 | const array = try sema.resolveInst(inst_data.operand); |
| 10402 | 10408 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); |
| 10403 | 10409 | 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 |
| 10408 | 10414 | defer tracy.end(); |
| 10409 | 10415 | |
| 10410 | 10416 | 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; | |
| 10412 | 10418 | const src = inst_data.src(); |
| 10413 | 10419 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10414 | 10420 | const array_ptr = try sema.resolveInst(extra.lhs); |
| ... | ... | @@ -10435,7 +10441,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10435 | 10441 | const tracy = trace(@src()); |
| 10436 | 10442 | defer tracy.end(); |
| 10437 | 10443 | |
| 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; | |
| 10439 | 10445 | const src = inst_data.src(); |
| 10440 | 10446 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 10441 | 10447 | 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 |
| 10449 | 10455 | defer tracy.end(); |
| 10450 | 10456 | |
| 10451 | 10457 | 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; | |
| 10453 | 10459 | const src = inst_data.src(); |
| 10454 | 10460 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 10455 | 10461 | const array_ptr = try sema.resolveInst(extra.ptr); |
| ... | ... | @@ -10468,7 +10474,7 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10468 | 10474 | const tracy = trace(@src()); |
| 10469 | 10475 | defer tracy.end(); |
| 10470 | 10476 | |
| 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; | |
| 10472 | 10478 | const src = inst_data.src(); |
| 10473 | 10479 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 10474 | 10480 | const array_ptr = try sema.resolveInst(extra.lhs); |
| ... | ... | @@ -10484,7 +10490,7 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10484 | 10490 | const tracy = trace(@src()); |
| 10485 | 10491 | defer tracy.end(); |
| 10486 | 10492 | |
| 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; | |
| 10488 | 10494 | const src = inst_data.src(); |
| 10489 | 10495 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 10490 | 10496 | const array_ptr = try sema.resolveInst(extra.lhs); |
| ... | ... | @@ -10501,7 +10507,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10501 | 10507 | const tracy = trace(@src()); |
| 10502 | 10508 | defer tracy.end(); |
| 10503 | 10509 | |
| 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; | |
| 10505 | 10511 | const src = inst_data.src(); |
| 10506 | 10512 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; |
| 10507 | 10513 | 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 |
| 10520 | 10526 | const tracy = trace(@src()); |
| 10521 | 10527 | defer tracy.end(); |
| 10522 | 10528 | |
| 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; | |
| 10524 | 10530 | const src = inst_data.src(); |
| 10525 | 10531 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 10526 | 10532 | const array_ptr = try sema.resolveInst(extra.lhs); |
| ... | ... | @@ -10581,7 +10587,7 @@ const SwitchProngAnalysis = struct { |
| 10581 | 10587 | merges: *Block.Merges, |
| 10582 | 10588 | ) CompileError!Air.Inst.Ref { |
| 10583 | 10589 | 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(); | |
| 10585 | 10591 | |
| 10586 | 10592 | if (has_tag_capture) { |
| 10587 | 10593 | const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); |
| ... | ... | @@ -10684,7 +10690,7 @@ const SwitchProngAnalysis = struct { |
| 10684 | 10690 | const operand_ty = sema.typeOf(spa.operand); |
| 10685 | 10691 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 10686 | 10692 | 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; | |
| 10688 | 10694 | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { |
| 10689 | 10695 | .scalar_capture => |i| .{ .scalar_tag_capture = i }, |
| 10690 | 10696 | .multi_capture => |i| .{ .multi_tag_capture = i }, |
| ... | ... | @@ -10720,7 +10726,7 @@ const SwitchProngAnalysis = struct { |
| 10720 | 10726 | const ip = &mod.intern_pool; |
| 10721 | 10727 | |
| 10722 | 10728 | 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; | |
| 10724 | 10730 | |
| 10725 | 10731 | const operand_ty = sema.typeOf(spa.operand); |
| 10726 | 10732 | 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 |
| 11146 | 11152 | const mod = sema.mod; |
| 11147 | 11153 | const gpa = sema.gpa; |
| 11148 | 11154 | 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; | |
| 11150 | 11156 | const src = inst_data.src(); |
| 11151 | 11157 | const src_node_offset = inst_data.src_node; |
| 11152 | 11158 | 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 |
| 11167 | 11173 | |
| 11168 | 11174 | // AstGen guarantees that the instruction immediately preceding |
| 11169 | 11175 | // 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); | |
| 11171 | 11177 | |
| 11172 | 11178 | var header_extra_index: usize = extra.end; |
| 11173 | 11179 | |
| ... | ... | @@ -11179,7 +11185,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11179 | 11185 | } else 0; |
| 11180 | 11186 | |
| 11181 | 11187 | 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]); | |
| 11183 | 11189 | header_extra_index += 1; |
| 11184 | 11190 | // SwitchProngAnalysis wants inst_map to have space for the tag capture. |
| 11185 | 11191 | // 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 |
| 11212 | 11218 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]); |
| 11213 | 11219 | const extra_body_start = header_extra_index + 1; |
| 11214 | 11220 | 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), | |
| 11216 | 11222 | .end = extra_body_start + info.body_len, |
| 11217 | 11223 | .capture = info.capture, |
| 11218 | 11224 | .is_inline = info.is_inline, |
| ... | ... | @@ -11482,7 +11488,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11482 | 11488 | // else => |e| return e, |
| 11483 | 11489 | // even if all the possible errors were already handled. |
| 11484 | 11490 | 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)]) { | |
| 11486 | 11492 | .dbg_block_begin, |
| 11487 | 11493 | .dbg_block_end, |
| 11488 | 11494 | .dbg_stmt, |
| ... | ... | @@ -11826,7 +11832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11826 | 11832 | extra_index += 1; |
| 11827 | 11833 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11828 | 11834 | 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); | |
| 11830 | 11836 | extra_index += info.body_len; |
| 11831 | 11837 | |
| 11832 | 11838 | const item = case_vals.items[scalar_i]; |
| ... | ... | @@ -11857,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11857 | 11863 | extra_index += 1; |
| 11858 | 11864 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11859 | 11865 | 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); | |
| 11861 | 11867 | |
| 11862 | 11868 | const items = case_vals.items[case_val_idx..][0..items_len]; |
| 11863 | 11869 | case_val_idx += items_len; |
| ... | ... | @@ -11986,7 +11992,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11986 | 11992 | extra_index += 1; |
| 11987 | 11993 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11988 | 11994 | 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); | |
| 11990 | 11996 | extra_index += info.body_len; |
| 11991 | 11997 | |
| 11992 | 11998 | case_block.instructions.shrinkRetainingCapacity(0); |
| ... | ... | @@ -12053,7 +12059,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12053 | 12059 | // Generate all possible cases as scalar prongs. |
| 12054 | 12060 | if (info.is_inline) { |
| 12055 | 12061 | 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); | |
| 12057 | 12063 | var emit_bb = false; |
| 12058 | 12064 | |
| 12059 | 12065 | var range_i: u32 = 0; |
| ... | ... | @@ -12184,7 +12190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12184 | 12190 | else |
| 12185 | 12191 | true; |
| 12186 | 12192 | |
| 12187 | const body = sema.code.extra[extra_index..][0..info.body_len]; | |
| 12193 | const body = sema.code.bodySlice(extra_index, info.body_len); | |
| 12188 | 12194 | extra_index += info.body_len; |
| 12189 | 12195 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12190 | 12196 | // nothing to do here |
| ... | ... | @@ -12268,7 +12274,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12268 | 12274 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12269 | 12275 | case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope); |
| 12270 | 12276 | |
| 12271 | const body = sema.code.extra[extra_index..][0..info.body_len]; | |
| 12277 | const body = sema.code.bodySlice(extra_index, info.body_len); | |
| 12272 | 12278 | extra_index += info.body_len; |
| 12273 | 12279 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12274 | 12280 | // nothing to do here |
| ... | ... | @@ -12493,8 +12499,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12493 | 12499 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12494 | 12500 | case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope); |
| 12495 | 12501 | |
| 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)) | |
| 12498 | 12506 | { |
| 12499 | 12507 | try sema.zirDbgStmt(&case_block, cond_dbg_node_index); |
| 12500 | 12508 | 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 |
| 12879 | 12887 | |
| 12880 | 12888 | const tags = sema.code.instructions.items(.tag); |
| 12881 | 12889 | for (body) |inst| { |
| 12882 | switch (tags[inst]) { | |
| 12890 | switch (tags[@intFromEnum(inst)]) { | |
| 12883 | 12891 | .@"unreachable" => if (!block.wantSafety()) return false, |
| 12884 | 12892 | .save_err_ret_index, |
| 12885 | 12893 | .dbg_block_begin, |
| ... | ... | @@ -12895,7 +12903,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12895 | 12903 | } |
| 12896 | 12904 | |
| 12897 | 12905 | for (body) |inst| { |
| 12898 | const air_inst = switch (tags[inst]) { | |
| 12906 | const air_inst = switch (tags[@intFromEnum(inst)]) { | |
| 12899 | 12907 | .dbg_block_begin, |
| 12900 | 12908 | .dbg_block_end, |
| 12901 | 12909 | => continue, |
| ... | ... | @@ -12923,7 +12931,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12923 | 12931 | return true; |
| 12924 | 12932 | }, |
| 12925 | 12933 | .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; | |
| 12927 | 12935 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 12928 | 12936 | |
| 12929 | 12937 | const panic_fn = try sema.getBuiltin("panic"); |
| ... | ... | @@ -12943,10 +12951,10 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12943 | 12951 | |
| 12944 | 12952 | fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void { |
| 12945 | 12953 | 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; | |
| 12948 | 12956 | |
| 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; | |
| 12950 | 12958 | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 12951 | 12959 | const operand_ty = sema.typeOf(err_operand); |
| 12952 | 12960 | if (operand_ty.zigTypeTag(mod) == .ErrorSet) { |
| ... | ... | @@ -12963,7 +12971,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind |
| 12963 | 12971 | fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !void { |
| 12964 | 12972 | const tags = sema.code.instructions.items(.tag); |
| 12965 | 12973 | const inst = for (body) |inst| { |
| 12966 | switch (tags[inst]) { | |
| 12974 | switch (tags[@intFromEnum(inst)]) { | |
| 12967 | 12975 | .dbg_block_begin, |
| 12968 | 12976 | .dbg_block_end, |
| 12969 | 12977 | .dbg_stmt, |
| ... | ... | @@ -12973,7 +12981,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 12973 | 12981 | else => return, |
| 12974 | 12982 | } |
| 12975 | 12983 | } 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"; | |
| 12977 | 12985 | const src = inst_data.src(); |
| 12978 | 12986 | |
| 12979 | 12987 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| ... | ... | @@ -12985,7 +12993,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 12985 | 12993 | |
| 12986 | 12994 | fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 12987 | 12995 | 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; | |
| 12989 | 12997 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 12990 | 12998 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12991 | 12999 | 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 |
| 13036 | 13044 | |
| 13037 | 13045 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13038 | 13046 | 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; | |
| 13040 | 13048 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13041 | 13049 | const src = inst_data.src(); |
| 13042 | 13050 | 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. |
| 13064 | 13072 | defer tracy.end(); |
| 13065 | 13073 | |
| 13066 | 13074 | 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; | |
| 13068 | 13076 | const operand_src = inst_data.src(); |
| 13069 | 13077 | const operand = inst_data.get(sema.code); |
| 13070 | 13078 | |
| ... | ... | @@ -13093,7 +13101,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13093 | 13101 | defer tracy.end(); |
| 13094 | 13102 | |
| 13095 | 13103 | 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; | |
| 13097 | 13105 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 13098 | 13106 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 13099 | 13107 | .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 |
| 13120 | 13128 | |
| 13121 | 13129 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13122 | 13130 | 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; | |
| 13124 | 13132 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 13125 | 13133 | _ = try mod.getErrorValue(name); |
| 13126 | 13134 | const error_set_type = try mod.singleErrorSetType(name); |
| ... | ... | @@ -13140,7 +13148,7 @@ fn zirShl( |
| 13140 | 13148 | defer tracy.end(); |
| 13141 | 13149 | |
| 13142 | 13150 | 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; | |
| 13144 | 13152 | const src = inst_data.src(); |
| 13145 | 13153 | sema.src = src; |
| 13146 | 13154 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | ... | @@ -13323,7 +13331,7 @@ fn zirShr( |
| 13323 | 13331 | defer tracy.end(); |
| 13324 | 13332 | |
| 13325 | 13333 | 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; | |
| 13327 | 13335 | const src = inst_data.src(); |
| 13328 | 13336 | sema.src = src; |
| 13329 | 13337 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | ... | @@ -13459,7 +13467,7 @@ fn zirBitwise( |
| 13459 | 13467 | defer tracy.end(); |
| 13460 | 13468 | |
| 13461 | 13469 | 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; | |
| 13463 | 13471 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 13464 | 13472 | sema.src = src; |
| 13465 | 13473 | 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. |
| 13514 | 13522 | defer tracy.end(); |
| 13515 | 13523 | |
| 13516 | 13524 | 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; | |
| 13518 | 13526 | const src = inst_data.src(); |
| 13519 | 13527 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 13520 | 13528 | |
| ... | ... | @@ -13648,7 +13656,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13648 | 13656 | defer tracy.end(); |
| 13649 | 13657 | |
| 13650 | 13658 | 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; | |
| 13652 | 13660 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13653 | 13661 | const lhs = try sema.resolveInst(extra.lhs); |
| 13654 | 13662 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -13977,7 +13985,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13977 | 13985 | defer tracy.end(); |
| 13978 | 13986 | |
| 13979 | 13987 | 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; | |
| 13981 | 13989 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13982 | 13990 | const lhs = try sema.resolveInst(extra.lhs); |
| 13983 | 13991 | const lhs_ty = sema.typeOf(lhs); |
| ... | ... | @@ -14116,7 +14124,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14116 | 14124 | |
| 14117 | 14125 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14118 | 14126 | 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; | |
| 14120 | 14128 | const src = inst_data.src(); |
| 14121 | 14129 | const lhs_src = src; |
| 14122 | 14130 | 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. |
| 14148 | 14156 | |
| 14149 | 14157 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14150 | 14158 | 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; | |
| 14152 | 14160 | const src = inst_data.src(); |
| 14153 | 14161 | const lhs_src = src; |
| 14154 | 14162 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| ... | ... | @@ -14176,7 +14184,7 @@ fn zirArithmetic( |
| 14176 | 14184 | const tracy = trace(@src()); |
| 14177 | 14185 | defer tracy.end(); |
| 14178 | 14186 | |
| 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; | |
| 14180 | 14188 | sema.src = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14181 | 14189 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14182 | 14190 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| ... | ... | @@ -14189,7 +14197,7 @@ fn zirArithmetic( |
| 14189 | 14197 | |
| 14190 | 14198 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14191 | 14199 | 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; | |
| 14193 | 14201 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14194 | 14202 | sema.src = src; |
| 14195 | 14203 | 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 |
| 14355 | 14363 | |
| 14356 | 14364 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14357 | 14365 | 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; | |
| 14359 | 14367 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14360 | 14368 | sema.src = src; |
| 14361 | 14369 | 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 |
| 14521 | 14529 | |
| 14522 | 14530 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14523 | 14531 | 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; | |
| 14525 | 14533 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14526 | 14534 | sema.src = src; |
| 14527 | 14535 | 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 |
| 14632 | 14640 | |
| 14633 | 14641 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14634 | 14642 | 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; | |
| 14636 | 14644 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14637 | 14645 | sema.src = src; |
| 14638 | 14646 | 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 |
| 14874 | 14882 | |
| 14875 | 14883 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14876 | 14884 | 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; | |
| 14878 | 14886 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14879 | 14887 | sema.src = src; |
| 14880 | 14888 | 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 |
| 15059 | 15067 | |
| 15060 | 15068 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15061 | 15069 | 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; | |
| 15063 | 15071 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 15064 | 15072 | sema.src = src; |
| 15065 | 15073 | 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 |
| 15155 | 15163 | |
| 15156 | 15164 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15157 | 15165 | 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; | |
| 15159 | 15167 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 15160 | 15168 | sema.src = src; |
| 15161 | 15169 | 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 |
| 16071 | 16079 | const tracy = trace(@src()); |
| 16072 | 16080 | defer tracy.end(); |
| 16073 | 16081 | |
| 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; | |
| 16075 | 16083 | const src = inst_data.src(); |
| 16076 | 16084 | const ptr_src = src; // TODO better source location |
| 16077 | 16085 | const ptr = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -16251,7 +16259,7 @@ fn zirCmpEq( |
| 16251 | 16259 | defer tracy.end(); |
| 16252 | 16260 | |
| 16253 | 16261 | 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; | |
| 16255 | 16263 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16256 | 16264 | const src: LazySrcLoc = inst_data.src(); |
| 16257 | 16265 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | ... | @@ -16367,7 +16375,7 @@ fn zirCmp( |
| 16367 | 16375 | const tracy = trace(@src()); |
| 16368 | 16376 | defer tracy.end(); |
| 16369 | 16377 | |
| 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; | |
| 16371 | 16379 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16372 | 16380 | const src: LazySrcLoc = inst_data.src(); |
| 16373 | 16381 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | ... | @@ -16512,7 +16520,7 @@ fn runtimeBoolCmp( |
| 16512 | 16520 | |
| 16513 | 16521 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16514 | 16522 | 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; | |
| 16516 | 16524 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 16517 | 16525 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 16518 | 16526 | switch (ty.zigTypeTag(mod)) { |
| ... | ... | @@ -16555,7 +16563,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16555 | 16563 | |
| 16556 | 16564 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16557 | 16565 | 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; | |
| 16559 | 16567 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 16560 | 16568 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 16561 | 16569 | switch (operand_ty.zigTypeTag(mod)) { |
| ... | ... | @@ -16607,7 +16615,7 @@ fn zirThis( |
| 16607 | 16615 | fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 16608 | 16616 | const mod = sema.mod; |
| 16609 | 16617 | 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; | |
| 16611 | 16619 | // Closures are not necessarily constant values. For example, the |
| 16612 | 16620 | // code might do something like this: |
| 16613 | 16621 | // 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 |
| 16629 | 16637 | fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16630 | 16638 | const mod = sema.mod; |
| 16631 | 16639 | //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; | |
| 16633 | 16641 | var scope: CaptureScope.Index = mod.declPtr(block.src_decl).src_scope; |
| 16634 | 16642 | assert(scope != .none); |
| 16635 | 16643 | // 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 |
| 16818 | 16826 | const mod = sema.mod; |
| 16819 | 16827 | const gpa = sema.gpa; |
| 16820 | 16828 | 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; | |
| 16822 | 16830 | const src = inst_data.src(); |
| 16823 | 16831 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 16824 | 16832 | const type_info_ty = try sema.getBuiltinType("Type"); |
| ... | ... | @@ -17923,16 +17931,16 @@ fn typeInfoNamespaceDecls( |
| 17923 | 17931 | fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17924 | 17932 | _ = block; |
| 17925 | 17933 | 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; | |
| 17927 | 17935 | const operand = try sema.resolveInst(inst_data.operand); |
| 17928 | 17936 | const operand_ty = sema.typeOf(operand); |
| 17929 | 17937 | return Air.internedToRef(operand_ty.toIntern()); |
| 17930 | 17938 | } |
| 17931 | 17939 | |
| 17932 | 17940 | fn 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; | |
| 17934 | 17942 | 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); | |
| 17936 | 17944 | |
| 17937 | 17945 | var child_block: Block = .{ |
| 17938 | 17946 | .parent = block, |
| ... | ... | @@ -17956,7 +17964,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17956 | 17964 | } |
| 17957 | 17965 | |
| 17958 | 17966 | fn 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; | |
| 17960 | 17968 | const src = inst_data.src(); |
| 17961 | 17969 | const operand = try sema.resolveInst(inst_data.operand); |
| 17962 | 17970 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -18010,7 +18018,7 @@ fn zirTypeofPeer( |
| 18010 | 18018 | |
| 18011 | 18019 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); |
| 18012 | 18020 | 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); | |
| 18014 | 18022 | |
| 18015 | 18023 | var child_block: Block = .{ |
| 18016 | 18024 | .parent = block, |
| ... | ... | @@ -18048,7 +18056,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18048 | 18056 | defer tracy.end(); |
| 18049 | 18057 | |
| 18050 | 18058 | 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; | |
| 18052 | 18060 | const src = inst_data.src(); |
| 18053 | 18061 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 18054 | 18062 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -18074,11 +18082,11 @@ fn zirBoolBr( |
| 18074 | 18082 | |
| 18075 | 18083 | const mod = sema.mod; |
| 18076 | 18084 | const datas = sema.code.instructions.items(.data); |
| 18077 | const inst_data = datas[inst].bool_br; | |
| 18085 | const inst_data = datas[@intFromEnum(inst)].bool_br; | |
| 18078 | 18086 | const lhs = try sema.resolveInst(inst_data.lhs); |
| 18079 | 18087 | const lhs_src = sema.src; |
| 18080 | 18088 | 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); | |
| 18082 | 18090 | const gpa = sema.gpa; |
| 18083 | 18091 | |
| 18084 | 18092 | if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { |
| ... | ... | @@ -18193,7 +18201,7 @@ fn zirIsNonNull( |
| 18193 | 18201 | const tracy = trace(@src()); |
| 18194 | 18202 | defer tracy.end(); |
| 18195 | 18203 | |
| 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; | |
| 18197 | 18205 | const src = inst_data.src(); |
| 18198 | 18206 | const operand = try sema.resolveInst(inst_data.operand); |
| 18199 | 18207 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| ... | ... | @@ -18209,7 +18217,7 @@ fn zirIsNonNullPtr( |
| 18209 | 18217 | defer tracy.end(); |
| 18210 | 18218 | |
| 18211 | 18219 | 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; | |
| 18213 | 18221 | const src = inst_data.src(); |
| 18214 | 18222 | const ptr = try sema.resolveInst(inst_data.operand); |
| 18215 | 18223 | 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 |
| 18234 | 18242 | const tracy = trace(@src()); |
| 18235 | 18243 | defer tracy.end(); |
| 18236 | 18244 | |
| 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; | |
| 18238 | 18246 | const src = inst_data.src(); |
| 18239 | 18247 | const operand = try sema.resolveInst(inst_data.operand); |
| 18240 | 18248 | try sema.checkErrorType(block, src, sema.typeOf(operand)); |
| ... | ... | @@ -18246,7 +18254,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 18246 | 18254 | defer tracy.end(); |
| 18247 | 18255 | |
| 18248 | 18256 | 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; | |
| 18250 | 18258 | const src = inst_data.src(); |
| 18251 | 18259 | const ptr = try sema.resolveInst(inst_data.operand); |
| 18252 | 18260 | 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 |
| 18258 | 18266 | const tracy = trace(@src()); |
| 18259 | 18267 | defer tracy.end(); |
| 18260 | 18268 | |
| 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; | |
| 18262 | 18270 | const src = inst_data.src(); |
| 18263 | 18271 | const operand = try sema.resolveInst(inst_data.operand); |
| 18264 | 18272 | return sema.analyzeIsNonErr(block, src, operand); |
| ... | ... | @@ -18273,12 +18281,12 @@ fn zirCondbr( |
| 18273 | 18281 | defer tracy.end(); |
| 18274 | 18282 | |
| 18275 | 18283 | 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; | |
| 18277 | 18285 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 18278 | 18286 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 18279 | 18287 | |
| 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); | |
| 18282 | 18290 | |
| 18283 | 18291 | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 18284 | 18292 | const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src); |
| ... | ... | @@ -18307,10 +18315,10 @@ fn zirCondbr( |
| 18307 | 18315 | defer gpa.free(true_instructions); |
| 18308 | 18316 | |
| 18309 | 18317 | 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; | |
| 18312 | 18320 | |
| 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; | |
| 18314 | 18322 | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 18315 | 18323 | const operand_ty = sema.typeOf(err_operand); |
| 18316 | 18324 | assert(operand_ty.zigTypeTag(mod) == .ErrorUnion); |
| ... | ... | @@ -18341,11 +18349,11 @@ fn zirCondbr( |
| 18341 | 18349 | } |
| 18342 | 18350 | |
| 18343 | 18351 | fn 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; | |
| 18345 | 18353 | const src = inst_data.src(); |
| 18346 | 18354 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 18347 | 18355 | 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); | |
| 18349 | 18357 | const err_union = try sema.resolveInst(extra.data.operand); |
| 18350 | 18358 | const err_union_ty = sema.typeOf(err_union); |
| 18351 | 18359 | const mod = sema.mod; |
| ... | ... | @@ -18387,11 +18395,11 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18387 | 18395 | } |
| 18388 | 18396 | |
| 18389 | 18397 | fn 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; | |
| 18391 | 18399 | const src = inst_data.src(); |
| 18392 | 18400 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 18393 | 18401 | 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); | |
| 18395 | 18403 | const operand = try sema.resolveInst(extra.data.operand); |
| 18396 | 18404 | const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src); |
| 18397 | 18405 | const err_union_ty = sema.typeOf(err_union); |
| ... | ... | @@ -18503,7 +18511,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18503 | 18511 | } |
| 18504 | 18512 | |
| 18505 | 18513 | fn 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"; | |
| 18507 | 18515 | const src = inst_data.src(); |
| 18508 | 18516 | |
| 18509 | 18517 | if (block.is_comptime) { |
| ... | ... | @@ -18528,7 +18536,7 @@ fn zirRetErrValue( |
| 18528 | 18536 | inst: Zir.Inst.Index, |
| 18529 | 18537 | ) CompileError!Zir.Inst.Index { |
| 18530 | 18538 | 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; | |
| 18532 | 18540 | const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 18533 | 18541 | _ = try mod.getErrorValue(err_name); |
| 18534 | 18542 | const src = inst_data.src(); |
| ... | ... | @@ -18550,7 +18558,7 @@ fn zirRetImplicit( |
| 18550 | 18558 | defer tracy.end(); |
| 18551 | 18559 | |
| 18552 | 18560 | 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; | |
| 18554 | 18562 | const r_brace_src = inst_data.src(); |
| 18555 | 18563 | if (block.inlining == null and sema.func_is_naked) { |
| 18556 | 18564 | assert(!block.is_comptime); |
| ... | ... | @@ -18595,7 +18603,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 18595 | 18603 | const tracy = trace(@src()); |
| 18596 | 18604 | defer tracy.end(); |
| 18597 | 18605 | |
| 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; | |
| 18599 | 18607 | const operand = try sema.resolveInst(inst_data.operand); |
| 18600 | 18608 | const src = inst_data.src(); |
| 18601 | 18609 | |
| ... | ... | @@ -18606,7 +18614,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 18606 | 18614 | const tracy = trace(@src()); |
| 18607 | 18615 | defer tracy.end(); |
| 18608 | 18616 | |
| 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; | |
| 18610 | 18618 | const src = inst_data.src(); |
| 18611 | 18619 | const ret_ptr = try sema.resolveInst(inst_data.operand); |
| 18612 | 18620 | |
| ... | ... | @@ -18693,7 +18701,7 @@ fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool { |
| 18693 | 18701 | |
| 18694 | 18702 | fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 18695 | 18703 | 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; | |
| 18697 | 18705 | |
| 18698 | 18706 | if (!mod.backendSupportsFeature(.error_return_trace)) return; |
| 18699 | 18707 | 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 |
| 18712 | 18720 | } |
| 18713 | 18721 | |
| 18714 | 18722 | fn 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; | |
| 18716 | 18724 | const src = sema.src; // TODO |
| 18717 | 18725 | |
| 18718 | 18726 | // This is only relevant at runtime. |
| ... | ... | @@ -18728,7 +18736,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) |
| 18728 | 18736 | const tracy = trace(@src()); |
| 18729 | 18737 | defer tracy.end(); |
| 18730 | 18738 | |
| 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: { | |
| 18732 | 18740 | var block = start_block; |
| 18733 | 18741 | while (true) { |
| 18734 | 18742 | if (block.label) |label| { |
| ... | ... | @@ -18858,7 +18866,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18858 | 18866 | defer tracy.end(); |
| 18859 | 18867 | |
| 18860 | 18868 | 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; | |
| 18862 | 18870 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 18863 | 18871 | const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node }; |
| 18864 | 18872 | 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 |
| 18998 | 19006 | const tracy = trace(@src()); |
| 18999 | 19007 | defer tracy.end(); |
| 19000 | 19008 | |
| 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; | |
| 19002 | 19010 | const src = inst_data.src(); |
| 19003 | 19011 | const obj_ty = try sema.resolveType(block, src, inst_data.operand); |
| 19004 | 19012 | const mod = sema.mod; |
| ... | ... | @@ -19017,7 +19025,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 19017 | 19025 | defer tracy.end(); |
| 19018 | 19026 | |
| 19019 | 19027 | 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; | |
| 19021 | 19029 | const src = inst_data.src(); |
| 19022 | 19030 | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 19023 | 19031 | // 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 |
| 19092 | 19100 | } |
| 19093 | 19101 | |
| 19094 | 19102 | fn 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; | |
| 19096 | 19104 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19097 | 19105 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 19098 | 19106 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| ... | ... | @@ -19154,14 +19162,14 @@ fn zirStructInit( |
| 19154 | 19162 | ) CompileError!Air.Inst.Ref { |
| 19155 | 19163 | const gpa = sema.gpa; |
| 19156 | 19164 | 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; | |
| 19158 | 19166 | const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 19159 | 19167 | const src = inst_data.src(); |
| 19160 | 19168 | |
| 19161 | 19169 | const mod = sema.mod; |
| 19162 | 19170 | const ip = &mod.intern_pool; |
| 19163 | 19171 | 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; | |
| 19165 | 19173 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; |
| 19166 | 19174 | const result_ty = sema.resolveType(block, src, first_field_type_extra.container_type) catch |err| switch (err) { |
| 19167 | 19175 | error.GenericPoison => { |
| ... | ... | @@ -19194,7 +19202,7 @@ fn zirStructInit( |
| 19194 | 19202 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index); |
| 19195 | 19203 | extra_index = item.end; |
| 19196 | 19204 | |
| 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; | |
| 19198 | 19206 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 19199 | 19207 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 19200 | 19208 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| ... | ... | @@ -19204,7 +19212,7 @@ fn zirStructInit( |
| 19204 | 19212 | try sema.structFieldIndex(block, resolved_ty, field_name, field_src); |
| 19205 | 19213 | if (field_inits[field_index] != .none) { |
| 19206 | 19214 | 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; | |
| 19208 | 19216 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_type_data.src_node }; |
| 19209 | 19217 | const msg = msg: { |
| 19210 | 19218 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| ... | ... | @@ -19239,7 +19247,7 @@ fn zirStructInit( |
| 19239 | 19247 | |
| 19240 | 19248 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| 19241 | 19249 | |
| 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; | |
| 19243 | 19251 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 19244 | 19252 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 19245 | 19253 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| ... | ... | @@ -19481,7 +19489,7 @@ fn zirStructInitAnon( |
| 19481 | 19489 | block: *Block, |
| 19482 | 19490 | inst: Zir.Inst.Index, |
| 19483 | 19491 | ) 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; | |
| 19485 | 19493 | const src = inst_data.src(); |
| 19486 | 19494 | const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 19487 | 19495 | return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); |
| ... | ... | @@ -19528,7 +19536,7 @@ fn structInitAnon( |
| 19528 | 19536 | .anon_init => sema.code.nullTerminatedString(item.data.field_name), |
| 19529 | 19537 | .typed_init => name: { |
| 19530 | 19538 | // `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; | |
| 19532 | 19540 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index); |
| 19533 | 19541 | break :name sema.code.nullTerminatedString(field_type_extra.data.name_start); |
| 19534 | 19542 | }, |
| ... | ... | @@ -19650,7 +19658,7 @@ fn zirArrayInit( |
| 19650 | 19658 | ) CompileError!Air.Inst.Ref { |
| 19651 | 19659 | const mod = sema.mod; |
| 19652 | 19660 | 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; | |
| 19654 | 19662 | const src = inst_data.src(); |
| 19655 | 19663 | |
| 19656 | 19664 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| ... | ... | @@ -19813,7 +19821,7 @@ fn zirArrayInitAnon( |
| 19813 | 19821 | block: *Block, |
| 19814 | 19822 | inst: Zir.Inst.Index, |
| 19815 | 19823 | ) 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; | |
| 19817 | 19825 | const src = inst_data.src(); |
| 19818 | 19826 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 19819 | 19827 | 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 |
| 19911 | 19919 | } |
| 19912 | 19920 | |
| 19913 | 19921 | fn 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; | |
| 19915 | 19923 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 19916 | 19924 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19917 | 19925 | 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 |
| 19925 | 19933 | fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19926 | 19934 | const mod = sema.mod; |
| 19927 | 19935 | 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; | |
| 19929 | 19937 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 19930 | 19938 | const ty_src = inst_data.src(); |
| 19931 | 19939 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| ... | ... | @@ -20034,7 +20042,7 @@ fn zirFrame( |
| 20034 | 20042 | |
| 20035 | 20043 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20036 | 20044 | 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; | |
| 20038 | 20046 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20039 | 20047 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 20040 | 20048 | if (ty.isNoReturn(mod)) { |
| ... | ... | @@ -20049,7 +20057,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20049 | 20057 | |
| 20050 | 20058 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20051 | 20059 | 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; | |
| 20053 | 20061 | const src = inst_data.src(); |
| 20054 | 20062 | const operand = try sema.resolveInst(inst_data.operand); |
| 20055 | 20063 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -20098,7 +20106,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 20098 | 20106 | } |
| 20099 | 20107 | |
| 20100 | 20108 | fn 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; | |
| 20102 | 20110 | const operand = try sema.resolveInst(inst_data.operand); |
| 20103 | 20111 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20104 | 20112 | |
| ... | ... | @@ -20118,7 +20126,7 @@ fn zirAbs( |
| 20118 | 20126 | inst: Zir.Inst.Index, |
| 20119 | 20127 | ) CompileError!Air.Inst.Ref { |
| 20120 | 20128 | 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; | |
| 20122 | 20130 | const operand = try sema.resolveInst(inst_data.operand); |
| 20123 | 20131 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20124 | 20132 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -20186,7 +20194,7 @@ fn zirUnaryMath( |
| 20186 | 20194 | defer tracy.end(); |
| 20187 | 20195 | |
| 20188 | 20196 | 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; | |
| 20190 | 20198 | const operand = try sema.resolveInst(inst_data.operand); |
| 20191 | 20199 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20192 | 20200 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -20209,7 +20217,7 @@ fn zirUnaryMath( |
| 20209 | 20217 | } |
| 20210 | 20218 | |
| 20211 | 20219 | fn 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; | |
| 20213 | 20221 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20214 | 20222 | const src = inst_data.src(); |
| 20215 | 20223 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -21385,7 +21393,7 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 21385 | 21393 | |
| 21386 | 21394 | fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21387 | 21395 | 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; | |
| 21389 | 21397 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21390 | 21398 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 21391 | 21399 | |
| ... | ... | @@ -21395,20 +21403,20 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21395 | 21403 | } |
| 21396 | 21404 | |
| 21397 | 21405 | fn 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; | |
| 21399 | 21407 | const src = inst_data.src(); |
| 21400 | 21408 | return sema.failWithUseOfAsync(block, src); |
| 21401 | 21409 | } |
| 21402 | 21410 | |
| 21403 | 21411 | fn 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; | |
| 21405 | 21413 | const src = inst_data.src(); |
| 21406 | 21414 | return sema.failWithUseOfAsync(block, src); |
| 21407 | 21415 | } |
| 21408 | 21416 | |
| 21409 | 21417 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21410 | 21418 | 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; | |
| 21412 | 21420 | const src = inst_data.src(); |
| 21413 | 21421 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21414 | 21422 | 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 |
| 21490 | 21498 | |
| 21491 | 21499 | fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21492 | 21500 | 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; | |
| 21494 | 21502 | const src = inst_data.src(); |
| 21495 | 21503 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21496 | 21504 | 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 |
| 21532 | 21540 | |
| 21533 | 21541 | fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21534 | 21542 | 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; | |
| 21536 | 21544 | const src = inst_data.src(); |
| 21537 | 21545 | |
| 21538 | 21546 | 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 |
| 21807 | 21815 | } |
| 21808 | 21816 | |
| 21809 | 21817 | fn 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; | |
| 21811 | 21819 | const src = inst_data.src(); |
| 21812 | 21820 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21813 | 21821 | 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 |
| 22237 | 22245 | |
| 22238 | 22246 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22239 | 22247 | 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; | |
| 22241 | 22249 | const src = inst_data.src(); |
| 22242 | 22250 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22243 | 22251 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| ... | ... | @@ -22326,7 +22334,7 @@ fn zirBitCount( |
| 22326 | 22334 | comptime comptimeOp: fn (val: Value, ty: Type, mod: *Module) u64, |
| 22327 | 22335 | ) CompileError!Air.Inst.Ref { |
| 22328 | 22336 | 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; | |
| 22330 | 22338 | const src = inst_data.src(); |
| 22331 | 22339 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22332 | 22340 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -22380,7 +22388,7 @@ fn zirBitCount( |
| 22380 | 22388 | |
| 22381 | 22389 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22382 | 22390 | 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; | |
| 22384 | 22392 | const src = inst_data.src(); |
| 22385 | 22393 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22386 | 22394 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -22436,7 +22444,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22436 | 22444 | } |
| 22437 | 22445 | |
| 22438 | 22446 | fn 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; | |
| 22440 | 22448 | const src = inst_data.src(); |
| 22441 | 22449 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22442 | 22450 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | ... | @@ -22495,7 +22503,7 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22495 | 22503 | } |
| 22496 | 22504 | |
| 22497 | 22505 | fn 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; | |
| 22499 | 22507 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 22500 | 22508 | sema.src = src; |
| 22501 | 22509 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | ... | @@ -23182,7 +23190,7 @@ fn zirCmpxchg( |
| 23182 | 23190 | |
| 23183 | 23191 | fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23184 | 23192 | 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; | |
| 23186 | 23194 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23187 | 23195 | const src = inst_data.src(); |
| 23188 | 23196 | 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 |
| 23203 | 23211 | } |
| 23204 | 23212 | |
| 23205 | 23213 | fn 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; | |
| 23207 | 23215 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23208 | 23216 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23209 | 23217 | 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. |
| 23275 | 23283 | |
| 23276 | 23284 | fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23277 | 23285 | 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; | |
| 23279 | 23287 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 23280 | 23288 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23281 | 23289 | 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 |
| 23552 | 23560 | } |
| 23553 | 23561 | |
| 23554 | 23562 | fn 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; | |
| 23556 | 23564 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 23557 | 23565 | // zig fmt: off |
| 23558 | 23566 | 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! |
| 23600 | 23608 | |
| 23601 | 23609 | fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23602 | 23610 | 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; | |
| 23604 | 23612 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 23605 | 23613 | const src = inst_data.src(); |
| 23606 | 23614 | // zig fmt: off |
| ... | ... | @@ -23685,7 +23693,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23685 | 23693 | } |
| 23686 | 23694 | |
| 23687 | 23695 | fn 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; | |
| 23689 | 23697 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 23690 | 23698 | const src = inst_data.src(); |
| 23691 | 23699 | // zig fmt: off |
| ... | ... | @@ -23721,7 +23729,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23721 | 23729 | } |
| 23722 | 23730 | |
| 23723 | 23731 | fn 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; | |
| 23725 | 23733 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 23726 | 23734 | const src = inst_data.src(); |
| 23727 | 23735 | |
| ... | ... | @@ -23789,7 +23797,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23789 | 23797 | defer tracy.end(); |
| 23790 | 23798 | |
| 23791 | 23799 | 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; | |
| 23793 | 23801 | const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23794 | 23802 | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 23795 | 23803 | 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 |
| 23880 | 23888 | } |
| 23881 | 23889 | |
| 23882 | 23890 | fn 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; | |
| 23884 | 23892 | const extra = sema.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; |
| 23885 | 23893 | const src = inst_data.src(); |
| 23886 | 23894 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | ... | @@ -24002,7 +24010,7 @@ fn zirMinMax( |
| 24002 | 24010 | inst: Zir.Inst.Index, |
| 24003 | 24011 | comptime air_tag: Air.Inst.Tag, |
| 24004 | 24012 | ) 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; | |
| 24006 | 24014 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24007 | 24015 | const src = inst_data.src(); |
| 24008 | 24016 | 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 |
| 24301 | 24309 | } |
| 24302 | 24310 | |
| 24303 | 24311 | fn 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; | |
| 24305 | 24313 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24306 | 24314 | const src = inst_data.src(); |
| 24307 | 24315 | 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 |
| 24521 | 24529 | const mod = sema.mod; |
| 24522 | 24530 | const gpa = sema.gpa; |
| 24523 | 24531 | 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; | |
| 24525 | 24533 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24526 | 24534 | const src = inst_data.src(); |
| 24527 | 24535 | 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 |
| 24607 | 24615 | } |
| 24608 | 24616 | |
| 24609 | 24617 | fn 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; | |
| 24611 | 24619 | const src = inst_data.src(); |
| 24612 | 24620 | return sema.failWithUseOfAsync(block, src); |
| 24613 | 24621 | } |
| ... | ... | @@ -24617,7 +24625,7 @@ fn zirAwait( |
| 24617 | 24625 | block: *Block, |
| 24618 | 24626 | inst: Zir.Inst.Index, |
| 24619 | 24627 | ) 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; | |
| 24621 | 24629 | const src = inst_data.src(); |
| 24622 | 24630 | |
| 24623 | 24631 | return sema.failWithUseOfAsync(block, src); |
| ... | ... | @@ -24702,7 +24710,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24702 | 24710 | defer tracy.end(); |
| 24703 | 24711 | |
| 24704 | 24712 | 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; | |
| 24706 | 24714 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 24707 | 24715 | const target = mod.getTarget(); |
| 24708 | 24716 | |
| ... | ... | @@ -24731,7 +24739,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24731 | 24739 | const @"align": ?Alignment = if (extra.data.bits.has_align_body) blk: { |
| 24732 | 24740 | const body_len = sema.code.extra[extra_index]; |
| 24733 | 24741 | extra_index += 1; |
| 24734 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 24742 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 24735 | 24743 | extra_index += body.len; |
| 24736 | 24744 | |
| 24737 | 24745 | 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 |
| 24762 | 24770 | const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: { |
| 24763 | 24771 | const body_len = sema.code.extra[extra_index]; |
| 24764 | 24772 | extra_index += 1; |
| 24765 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 24773 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 24766 | 24774 | extra_index += body.len; |
| 24767 | 24775 | |
| 24768 | 24776 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| ... | ... | @@ -24790,7 +24798,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24790 | 24798 | const section: Section = if (extra.data.bits.has_section_body) blk: { |
| 24791 | 24799 | const body_len = sema.code.extra[extra_index]; |
| 24792 | 24800 | extra_index += 1; |
| 24793 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 24801 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 24794 | 24802 | extra_index += body.len; |
| 24795 | 24803 | |
| 24796 | 24804 | const ty = Type.slice_const_u8; |
| ... | ... | @@ -24818,7 +24826,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24818 | 24826 | const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: { |
| 24819 | 24827 | const body_len = sema.code.extra[extra_index]; |
| 24820 | 24828 | extra_index += 1; |
| 24821 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 24829 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 24822 | 24830 | extra_index += body.len; |
| 24823 | 24831 | |
| 24824 | 24832 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| ... | ... | @@ -24849,7 +24857,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24849 | 24857 | const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: { |
| 24850 | 24858 | const body_len = sema.code.extra[extra_index]; |
| 24851 | 24859 | extra_index += 1; |
| 24852 | const body = sema.code.extra[extra_index..][0..body_len]; | |
| 24860 | const body = sema.code.bodySlice(extra_index, body_len); | |
| 24853 | 24861 | extra_index += body.len; |
| 24854 | 24862 | |
| 24855 | 24863 | 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 |
| 34821 | 34829 | break :blk accumulator; |
| 34822 | 34830 | }; |
| 34823 | 34831 | |
| 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; | |
| 34825 | 34833 | assert(extended.opcode == .struct_decl); |
| 34826 | 34834 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 34827 | 34835 | |
| ... | ... | @@ -34840,7 +34848,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp |
| 34840 | 34848 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 34841 | 34849 | break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref); |
| 34842 | 34850 | } else { |
| 34843 | const body = zir.extra[extra_index..][0..backing_int_body_len]; | |
| 34851 | const body = zir.bodySlice(extra_index, backing_int_body_len); | |
| 34844 | 34852 | const ty_ref = try sema.resolveBody(&block, body, struct_type.zir_index); |
| 34845 | 34853 | break :blk try sema.analyzeAsType(&block, backing_int_src, ty_ref); |
| 34846 | 34854 | } |
| ... | ... | @@ -35409,7 +35417,7 @@ fn semaStructFields( |
| 35409 | 35417 | const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace; |
| 35410 | 35418 | const zir = mod.namespacePtr(namespace_index).file_scope.zir; |
| 35411 | 35419 | 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; | |
| 35413 | 35421 | assert(extended.opcode == .struct_decl); |
| 35414 | 35422 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 35415 | 35423 | var extra_index: usize = extended.operand; |
| ... | ... | @@ -35590,7 +35598,7 @@ fn semaStructFields( |
| 35590 | 35598 | }; |
| 35591 | 35599 | } |
| 35592 | 35600 | 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); | |
| 35594 | 35602 | extra_index += body.len; |
| 35595 | 35603 | const ty_ref = try sema.resolveBody(&block_scope, body, zir_index); |
| 35596 | 35604 | break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) { |
| ... | ... | @@ -35676,7 +35684,7 @@ fn semaStructFields( |
| 35676 | 35684 | } |
| 35677 | 35685 | |
| 35678 | 35686 | 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); | |
| 35680 | 35688 | extra_index += body.len; |
| 35681 | 35689 | const align_ref = try sema.resolveBody(&block_scope, body, zir_index); |
| 35682 | 35690 | const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { |
| ... | ... | @@ -35706,7 +35714,7 @@ fn semaStructFields( |
| 35706 | 35714 | extra_index += zir_field.type_body_len; |
| 35707 | 35715 | extra_index += zir_field.align_body_len; |
| 35708 | 35716 | 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); | |
| 35710 | 35718 | extra_index += body.len; |
| 35711 | 35719 | const init = try sema.resolveBody(&block_scope, body, zir_index); |
| 35712 | 35720 | 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 |
| 35748 | 35756 | const ip = &mod.intern_pool; |
| 35749 | 35757 | const decl_index = union_type.decl; |
| 35750 | 35758 | 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; | |
| 35752 | 35760 | assert(extended.opcode == .union_decl); |
| 35753 | 35761 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 35754 | 35762 | var extra_index: usize = extended.operand; |
| ... | ... | @@ -35785,7 +35793,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35785 | 35793 | while (decls_it.next()) |_| {} |
| 35786 | 35794 | extra_index = decls_it.extra_index; |
| 35787 | 35795 | |
| 35788 | const body = zir.extra[extra_index..][0..body_len]; | |
| 35796 | const body = zir.bodySlice(extra_index, body_len); | |
| 35789 | 35797 | extra_index += body.len; |
| 35790 | 35798 | |
| 35791 | 35799 | 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) { |
| 93 | 93 | inline for (fields) |field| { |
| 94 | 94 | @field(result, field.name) = switch (field.type) { |
| 95 | 95 | u32 => code.extra[i], |
| 96 | Inst.Ref => @enumFromInt(code.extra[i]), | |
| 96 | ||
| 97 | Inst.Ref, | |
| 98 | Inst.Index, | |
| 99 | => @enumFromInt(code.extra[i]), | |
| 100 | ||
| 97 | 101 | i32, |
| 98 | 102 | Inst.Call.Flags, |
| 99 | 103 | Inst.BuiltinCall.Flags, |
| 100 | 104 | Inst.SwitchBlock.Bits, |
| 101 | 105 | Inst.FuncFancy.Bits, |
| 102 | 106 | => @bitCast(code.extra[i]), |
| 107 | ||
| 103 | 108 | else => @compileError("bad field type"), |
| 104 | 109 | }; |
| 105 | 110 | i += 1; |
| ... | ... | @@ -134,6 +139,10 @@ pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref { |
| 134 | 139 | return @ptrCast(code.extra[start..][0..len]); |
| 135 | 140 | } |
| 136 | 141 | |
| 142 | pub fn bodySlice(zir: Zir, start: usize, len: usize) []Inst.Index { | |
| 143 | return @ptrCast(zir.extra[start..][0..len]); | |
| 144 | } | |
| 145 | ||
| 137 | 146 | pub fn hasCompileErrors(code: Zir) bool { |
| 138 | 147 | return code.extra[@intFromEnum(ExtraIndex.compile_errors)] != 0; |
| 139 | 148 | } |
| ... | ... | @@ -145,10 +154,6 @@ pub fn deinit(code: *Zir, gpa: Allocator) void { |
| 145 | 154 | code.* = undefined; |
| 146 | 155 | } |
| 147 | 156 | |
| 148 | /// ZIR is structured so that the outermost "main" struct of any file | |
| 149 | /// is always at index 0. | |
| 150 | pub const main_struct_inst: Inst.Index = 0; | |
| 151 | ||
| 152 | 157 | /// These are untyped instructions generated from an Abstract Syntax Tree. |
| 153 | 158 | /// The data here is immutable because it is possible to have multiple |
| 154 | 159 | /// analyses on the same ZIR happening at the same time. |
| ... | ... | @@ -2093,7 +2098,34 @@ pub const Inst = struct { |
| 2093 | 2098 | }; |
| 2094 | 2099 | |
| 2095 | 2100 | /// 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 | }; | |
| 2097 | 2129 | |
| 2098 | 2130 | /// A reference to ZIR instruction, or to an InternPool index, or neither. |
| 2099 | 2131 | /// |
| ... | ... | @@ -2196,6 +2228,21 @@ pub const Inst = struct { |
| 2196 | 2228 | /// value and may instead be used as a sentinel to indicate null. |
| 2197 | 2229 | none = @intFromEnum(InternPool.Index.none), |
| 2198 | 2230 | _, |
| 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 | } | |
| 2199 | 2246 | }; |
| 2200 | 2247 | |
| 2201 | 2248 | /// All instructions have an 8-byte payload, which is contained within |
| ... | ... | @@ -3286,7 +3333,7 @@ pub const Inst = struct { |
| 3286 | 3333 | |
| 3287 | 3334 | /// Trailing: for each `imports_len` there is an Item |
| 3288 | 3335 | pub const Imports = struct { |
| 3289 | imports_len: Inst.Index, | |
| 3336 | imports_len: u32, | |
| 3290 | 3337 | |
| 3291 | 3338 | pub const Item = struct { |
| 3292 | 3339 | /// null terminated string index |
| ... | ... | @@ -3371,16 +3418,16 @@ pub const DeclIterator = struct { |
| 3371 | 3418 | } |
| 3372 | 3419 | }; |
| 3373 | 3420 | |
| 3374 | pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator { | |
| 3421 | pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | |
| 3375 | 3422 | const tags = zir.instructions.items(.tag); |
| 3376 | 3423 | const datas = zir.instructions.items(.data); |
| 3377 | switch (tags[decl_inst]) { | |
| 3424 | switch (tags[@intFromEnum(decl_inst)]) { | |
| 3378 | 3425 | // Functions are allowed and yield no iterations. |
| 3379 | 3426 | // There is one case matching this in the extended instruction set below. |
| 3380 | 3427 | .func, .func_inferred, .func_fancy => return declIteratorInner(zir, 0, 0), |
| 3381 | 3428 | |
| 3382 | 3429 | .extended => { |
| 3383 | const extended = datas[decl_inst].extended; | |
| 3430 | const extended = datas[@intFromEnum(decl_inst)].extended; | |
| 3384 | 3431 | switch (extended.opcode) { |
| 3385 | 3432 | .struct_decl => { |
| 3386 | 3433 | const small: Inst.StructDecl.Small = @bitCast(extended.small); |
| ... | ... | @@ -3469,7 +3516,7 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera |
| 3469 | 3516 | /// The iterator would have to allocate memory anyway to iterate. So here we populate |
| 3470 | 3517 | /// an ArrayList as the result. |
| 3471 | 3518 | pub 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]); | |
| 3473 | 3520 | list.clearRetainingCapacity(); |
| 3474 | 3521 | |
| 3475 | 3522 | return zir.findDeclsInner(list, block_inst); |
| ... | ... | @@ -3483,32 +3530,32 @@ fn findDeclsInner( |
| 3483 | 3530 | const tags = zir.instructions.items(.tag); |
| 3484 | 3531 | const datas = zir.instructions.items(.data); |
| 3485 | 3532 | |
| 3486 | switch (tags[inst]) { | |
| 3533 | switch (tags[@intFromEnum(inst)]) { | |
| 3487 | 3534 | // Functions instructions are interesting and have a body. |
| 3488 | 3535 | .func, |
| 3489 | 3536 | .func_inferred, |
| 3490 | 3537 | => { |
| 3491 | 3538 | try list.append(inst); |
| 3492 | 3539 | |
| 3493 | const inst_data = datas[inst].pl_node; | |
| 3540 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 3494 | 3541 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3495 | 3542 | var extra_index: usize = extra.end; |
| 3496 | 3543 | switch (extra.data.ret_body_len) { |
| 3497 | 3544 | 0 => {}, |
| 3498 | 3545 | 1 => extra_index += 1, |
| 3499 | 3546 | 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); | |
| 3501 | 3548 | extra_index += body.len; |
| 3502 | 3549 | try zir.findDeclsBody(list, body); |
| 3503 | 3550 | }, |
| 3504 | 3551 | } |
| 3505 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3552 | const body = zir.bodySlice(extra_index, extra.data.body_len); | |
| 3506 | 3553 | return zir.findDeclsBody(list, body); |
| 3507 | 3554 | }, |
| 3508 | 3555 | .func_fancy => { |
| 3509 | 3556 | try list.append(inst); |
| 3510 | 3557 | |
| 3511 | const inst_data = datas[inst].pl_node; | |
| 3558 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 3512 | 3559 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); |
| 3513 | 3560 | var extra_index: usize = extra.end; |
| 3514 | 3561 | extra_index += @intFromBool(extra.data.bits.has_lib_name); |
| ... | ... | @@ -3516,7 +3563,7 @@ fn findDeclsInner( |
| 3516 | 3563 | if (extra.data.bits.has_align_body) { |
| 3517 | 3564 | const body_len = zir.extra[extra_index]; |
| 3518 | 3565 | extra_index += 1; |
| 3519 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3566 | const body = zir.bodySlice(extra_index, body_len); | |
| 3520 | 3567 | try zir.findDeclsBody(list, body); |
| 3521 | 3568 | extra_index += body.len; |
| 3522 | 3569 | } else if (extra.data.bits.has_align_ref) { |
| ... | ... | @@ -3526,7 +3573,7 @@ fn findDeclsInner( |
| 3526 | 3573 | if (extra.data.bits.has_addrspace_body) { |
| 3527 | 3574 | const body_len = zir.extra[extra_index]; |
| 3528 | 3575 | extra_index += 1; |
| 3529 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3576 | const body = zir.bodySlice(extra_index, body_len); | |
| 3530 | 3577 | try zir.findDeclsBody(list, body); |
| 3531 | 3578 | extra_index += body.len; |
| 3532 | 3579 | } else if (extra.data.bits.has_addrspace_ref) { |
| ... | ... | @@ -3536,7 +3583,7 @@ fn findDeclsInner( |
| 3536 | 3583 | if (extra.data.bits.has_section_body) { |
| 3537 | 3584 | const body_len = zir.extra[extra_index]; |
| 3538 | 3585 | extra_index += 1; |
| 3539 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3586 | const body = zir.bodySlice(extra_index, body_len); | |
| 3540 | 3587 | try zir.findDeclsBody(list, body); |
| 3541 | 3588 | extra_index += body.len; |
| 3542 | 3589 | } else if (extra.data.bits.has_section_ref) { |
| ... | ... | @@ -3546,7 +3593,7 @@ fn findDeclsInner( |
| 3546 | 3593 | if (extra.data.bits.has_cc_body) { |
| 3547 | 3594 | const body_len = zir.extra[extra_index]; |
| 3548 | 3595 | extra_index += 1; |
| 3549 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3596 | const body = zir.bodySlice(extra_index, body_len); | |
| 3550 | 3597 | try zir.findDeclsBody(list, body); |
| 3551 | 3598 | extra_index += body.len; |
| 3552 | 3599 | } else if (extra.data.bits.has_cc_ref) { |
| ... | ... | @@ -3556,7 +3603,7 @@ fn findDeclsInner( |
| 3556 | 3603 | if (extra.data.bits.has_ret_ty_body) { |
| 3557 | 3604 | const body_len = zir.extra[extra_index]; |
| 3558 | 3605 | extra_index += 1; |
| 3559 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3606 | const body = zir.bodySlice(extra_index, body_len); | |
| 3560 | 3607 | try zir.findDeclsBody(list, body); |
| 3561 | 3608 | extra_index += body.len; |
| 3562 | 3609 | } else if (extra.data.bits.has_ret_ty_ref) { |
| ... | ... | @@ -3565,11 +3612,11 @@ fn findDeclsInner( |
| 3565 | 3612 | |
| 3566 | 3613 | extra_index += @intFromBool(extra.data.bits.has_any_noalias); |
| 3567 | 3614 | |
| 3568 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3615 | const body = zir.bodySlice(extra_index, extra.data.body_len); | |
| 3569 | 3616 | return zir.findDeclsBody(list, body); |
| 3570 | 3617 | }, |
| 3571 | 3618 | .extended => { |
| 3572 | const extended = datas[inst].extended; | |
| 3619 | const extended = datas[@intFromEnum(inst)].extended; | |
| 3573 | 3620 | switch (extended.opcode) { |
| 3574 | 3621 | |
| 3575 | 3622 | // Decl instructions are interesting but have no body. |
| ... | ... | @@ -3587,23 +3634,23 @@ fn findDeclsInner( |
| 3587 | 3634 | // Block instructions, recurse over the bodies. |
| 3588 | 3635 | |
| 3589 | 3636 | .block, .block_comptime, .block_inline => { |
| 3590 | const inst_data = datas[inst].pl_node; | |
| 3637 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 3591 | 3638 | 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); | |
| 3593 | 3640 | return zir.findDeclsBody(list, body); |
| 3594 | 3641 | }, |
| 3595 | 3642 | .condbr, .condbr_inline => { |
| 3596 | const inst_data = datas[inst].pl_node; | |
| 3643 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 3597 | 3644 | 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); | |
| 3600 | 3647 | try zir.findDeclsBody(list, then_body); |
| 3601 | 3648 | try zir.findDeclsBody(list, else_body); |
| 3602 | 3649 | }, |
| 3603 | 3650 | .@"try", .try_ptr => { |
| 3604 | const inst_data = datas[inst].pl_node; | |
| 3651 | const inst_data = datas[@intFromEnum(inst)].pl_node; | |
| 3605 | 3652 | 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); | |
| 3607 | 3654 | try zir.findDeclsBody(list, body); |
| 3608 | 3655 | }, |
| 3609 | 3656 | .switch_block => return findDeclsSwitch(zir, list, inst), |
| ... | ... | @@ -3619,7 +3666,7 @@ fn findDeclsSwitch( |
| 3619 | 3666 | list: *std.ArrayList(Inst.Index), |
| 3620 | 3667 | inst: Inst.Index, |
| 3621 | 3668 | ) 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; | |
| 3623 | 3670 | const extra = zir.extraData(Inst.SwitchBlock, inst_data.payload_index); |
| 3624 | 3671 | |
| 3625 | 3672 | var extra_index: usize = extra.end; |
| ... | ... | @@ -3634,7 +3681,7 @@ fn findDeclsSwitch( |
| 3634 | 3681 | if (special_prong != .none) { |
| 3635 | 3682 | const body_len: u31 = @truncate(zir.extra[extra_index]); |
| 3636 | 3683 | extra_index += 1; |
| 3637 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3684 | const body = zir.bodySlice(extra_index, body_len); | |
| 3638 | 3685 | extra_index += body.len; |
| 3639 | 3686 | |
| 3640 | 3687 | try zir.findDeclsBody(list, body); |
| ... | ... | @@ -3642,20 +3689,18 @@ fn findDeclsSwitch( |
| 3642 | 3689 | |
| 3643 | 3690 | { |
| 3644 | 3691 | 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) |_| { | |
| 3647 | 3693 | extra_index += 1; |
| 3648 | 3694 | const body_len: u31 = @truncate(zir.extra[extra_index]); |
| 3649 | 3695 | extra_index += 1; |
| 3650 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3696 | const body = zir.bodySlice(extra_index, body_len); | |
| 3651 | 3697 | extra_index += body_len; |
| 3652 | 3698 | |
| 3653 | 3699 | try zir.findDeclsBody(list, body); |
| 3654 | 3700 | } |
| 3655 | 3701 | } |
| 3656 | 3702 | { |
| 3657 | var multi_i: usize = 0; | |
| 3658 | while (multi_i < multi_cases_len) : (multi_i += 1) { | |
| 3703 | for (0..multi_cases_len) |_| { | |
| 3659 | 3704 | const items_len = zir.extra[extra_index]; |
| 3660 | 3705 | extra_index += 1; |
| 3661 | 3706 | const ranges_len = zir.extra[extra_index]; |
| ... | ... | @@ -3672,7 +3717,7 @@ fn findDeclsSwitch( |
| 3672 | 3717 | extra_index += 1; |
| 3673 | 3718 | } |
| 3674 | 3719 | |
| 3675 | const body = zir.extra[extra_index..][0..body_len]; | |
| 3720 | const body = zir.bodySlice(extra_index, body_len); | |
| 3676 | 3721 | extra_index += body_len; |
| 3677 | 3722 | |
| 3678 | 3723 | try zir.findDeclsBody(list, body); |
| ... | ... | @@ -3699,12 +3744,12 @@ pub const FnInfo = struct { |
| 3699 | 3744 | total_params_len: u32, |
| 3700 | 3745 | }; |
| 3701 | 3746 | |
| 3702 | pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 { | |
| 3747 | pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const Zir.Inst.Index { | |
| 3703 | 3748 | const tags = zir.instructions.items(.tag); |
| 3704 | 3749 | 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; | |
| 3706 | 3751 | |
| 3707 | const param_block_index = switch (tags[fn_inst]) { | |
| 3752 | const param_block_index = switch (tags[@intFromEnum(fn_inst)]) { | |
| 3708 | 3753 | .func, .func_inferred => blk: { |
| 3709 | 3754 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3710 | 3755 | break :blk extra.data.param_block; |
| ... | ... | @@ -3716,8 +3761,8 @@ pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 { |
| 3716 | 3761 | else => unreachable, |
| 3717 | 3762 | }; |
| 3718 | 3763 | |
| 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); | |
| 3721 | 3766 | } |
| 3722 | 3767 | |
| 3723 | 3768 | pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| ... | ... | @@ -3728,9 +3773,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3728 | 3773 | body: []const Inst.Index, |
| 3729 | 3774 | ret_ty_ref: Inst.Ref, |
| 3730 | 3775 | ret_ty_body: []const Inst.Index, |
| 3731 | } = switch (tags[fn_inst]) { | |
| 3776 | } = switch (tags[@intFromEnum(fn_inst)]) { | |
| 3732 | 3777 | .func, .func_inferred => blk: { |
| 3733 | const inst_data = datas[fn_inst].pl_node; | |
| 3778 | const inst_data = datas[@intFromEnum(fn_inst)].pl_node; | |
| 3734 | 3779 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3735 | 3780 | |
| 3736 | 3781 | var extra_index: usize = extra.end; |
| ... | ... | @@ -3746,12 +3791,12 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3746 | 3791 | extra_index += 1; |
| 3747 | 3792 | }, |
| 3748 | 3793 | 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); | |
| 3750 | 3795 | extra_index += ret_ty_body.len; |
| 3751 | 3796 | }, |
| 3752 | 3797 | } |
| 3753 | 3798 | |
| 3754 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3799 | const body = zir.bodySlice(extra_index, extra.data.body_len); | |
| 3755 | 3800 | extra_index += body.len; |
| 3756 | 3801 | |
| 3757 | 3802 | break :blk .{ |
| ... | ... | @@ -3762,7 +3807,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3762 | 3807 | }; |
| 3763 | 3808 | }, |
| 3764 | 3809 | .func_fancy => blk: { |
| 3765 | const inst_data = datas[fn_inst].pl_node; | |
| 3810 | const inst_data = datas[@intFromEnum(fn_inst)].pl_node; | |
| 3766 | 3811 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); |
| 3767 | 3812 | |
| 3768 | 3813 | var extra_index: usize = extra.end; |
| ... | ... | @@ -3793,7 +3838,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3793 | 3838 | if (extra.data.bits.has_ret_ty_body) { |
| 3794 | 3839 | const body_len = zir.extra[extra_index]; |
| 3795 | 3840 | extra_index += 1; |
| 3796 | ret_ty_body = zir.extra[extra_index..][0..body_len]; | |
| 3841 | ret_ty_body = zir.bodySlice(extra_index, body_len); | |
| 3797 | 3842 | extra_index += ret_ty_body.len; |
| 3798 | 3843 | } else if (extra.data.bits.has_ret_ty_ref) { |
| 3799 | 3844 | ret_ty_ref = @enumFromInt(zir.extra[extra_index]); |
| ... | ... | @@ -3802,7 +3847,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3802 | 3847 | |
| 3803 | 3848 | extra_index += @intFromBool(extra.data.bits.has_any_noalias); |
| 3804 | 3849 | |
| 3805 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3850 | const body = zir.bodySlice(extra_index, extra.data.body_len); | |
| 3806 | 3851 | extra_index += body.len; |
| 3807 | 3852 | break :blk .{ |
| 3808 | 3853 | .param_block = extra.data.param_block, |
| ... | ... | @@ -3813,14 +3858,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3813 | 3858 | }, |
| 3814 | 3859 | else => unreachable, |
| 3815 | 3860 | }; |
| 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); | |
| 3821 | 3867 | var total_params_len: u32 = 0; |
| 3822 | 3868 | for (param_body) |inst| { |
| 3823 | switch (tags[inst]) { | |
| 3869 | switch (tags[@intFromEnum(inst)]) { | |
| 3824 | 3870 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { |
| 3825 | 3871 | total_params_len += 1; |
| 3826 | 3872 | }, |
| ... | ... | @@ -3836,24 +3882,3 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3836 | 3882 | .total_params_len = total_params_len, |
| 3837 | 3883 | }; |
| 3838 | 3884 | } |
| 3839 | ||
| 3840 | pub const ref_start_index: u32 = InternPool.static_len; | |
| 3841 | ||
| 3842 | pub fn indexToRef(inst: Inst.Index) Inst.Ref { | |
| 3843 | return @enumFromInt(ref_start_index + inst); | |
| 3844 | } | |
| 3845 | ||
| 3846 | pub 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 | ||
| 3856 | pub 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( |
| 32 | 32 | var raw_stream = std.io.bufferedWriter(fs_file.writer()); |
| 33 | 33 | const stream = raw_stream.writer(); |
| 34 | 34 | |
| 35 | const main_struct_inst = Zir.main_struct_inst; | |
| 35 | const main_struct_inst: Zir.Inst.Index = .main_struct_inst; | |
| 36 | 36 | try stream.print("%{d} ", .{main_struct_inst}); |
| 37 | 37 | try writer.writeInstToStream(stream, main_struct_inst); |
| 38 | 38 | try stream.writeAll("\n"); |
| ... | ... | @@ -41,10 +41,9 @@ pub fn renderAsTextToFile( |
| 41 | 41 | try stream.writeAll("Imports:\n"); |
| 42 | 42 | |
| 43 | 43 | const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index); |
| 44 | var import_i: u32 = 0; | |
| 45 | 44 | var extra_index = extra.end; |
| 46 | 45 | |
| 47 | while (import_i < extra.data.imports_len) : (import_i += 1) { | |
| 46 | for (0..extra.data.imports_len) |_| { | |
| 48 | 47 | const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index); |
| 49 | 48 | extra_index = item.end; |
| 50 | 49 | |
| ... | ... | @@ -197,8 +196,8 @@ const Writer = struct { |
| 197 | 196 | inst: Zir.Inst.Index, |
| 198 | 197 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { |
| 199 | 198 | 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)])}); | |
| 202 | 201 | switch (tag) { |
| 203 | 202 | .as, |
| 204 | 203 | .store, |
| ... | ... | @@ -525,7 +524,7 @@ const Writer = struct { |
| 525 | 524 | } |
| 526 | 525 | |
| 527 | 526 | 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; | |
| 529 | 528 | try stream.print("{s}(", .{@tagName(extended.opcode)}); |
| 530 | 529 | switch (extended.opcode) { |
| 531 | 530 | .this, |
| ... | ... | @@ -622,7 +621,7 @@ const Writer = struct { |
| 622 | 621 | } |
| 623 | 622 | |
| 624 | 623 | 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; | |
| 626 | 625 | try self.writeInstRef(stream, inst_data.lhs); |
| 627 | 626 | try stream.writeAll(", "); |
| 628 | 627 | try self.writeInstRef(stream, inst_data.rhs); |
| ... | ... | @@ -630,7 +629,7 @@ const Writer = struct { |
| 630 | 629 | } |
| 631 | 630 | |
| 632 | 631 | 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; | |
| 634 | 633 | try self.writeInstRef(stream, inst_data.lhs); |
| 635 | 634 | try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)}); |
| 636 | 635 | } |
| ... | ... | @@ -640,7 +639,7 @@ const Writer = struct { |
| 640 | 639 | stream: anytype, |
| 641 | 640 | inst: Zir.Inst.Index, |
| 642 | 641 | ) (@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; | |
| 644 | 643 | try self.writeInstRef(stream, inst_data.operand); |
| 645 | 644 | try stream.writeAll(") "); |
| 646 | 645 | try self.writeSrc(stream, inst_data.src()); |
| ... | ... | @@ -651,7 +650,7 @@ const Writer = struct { |
| 651 | 650 | stream: anytype, |
| 652 | 651 | inst: Zir.Inst.Index, |
| 653 | 652 | ) (@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; | |
| 655 | 654 | try self.writeInstRef(stream, inst_data.operand); |
| 656 | 655 | try stream.writeAll(") "); |
| 657 | 656 | try self.writeSrc(stream, inst_data.src()); |
| ... | ... | @@ -662,7 +661,7 @@ const Writer = struct { |
| 662 | 661 | stream: anytype, |
| 663 | 662 | inst: Zir.Inst.Index, |
| 664 | 663 | ) (@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; | |
| 666 | 665 | const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 667 | 666 | try self.writeInstRef(stream, extra.operand); |
| 668 | 667 | try stream.print(", {d}) (destructure=", .{extra.expect_len}); |
| ... | ... | @@ -676,7 +675,7 @@ const Writer = struct { |
| 676 | 675 | stream: anytype, |
| 677 | 676 | inst: Zir.Inst.Index, |
| 678 | 677 | ) (@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; | |
| 680 | 679 | const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 681 | 680 | try self.writeInstRef(stream, extra.ty); |
| 682 | 681 | try stream.print(", {d}) ", .{extra.init_count}); |
| ... | ... | @@ -688,7 +687,7 @@ const Writer = struct { |
| 688 | 687 | stream: anytype, |
| 689 | 688 | inst: Zir.Inst.Index, |
| 690 | 689 | ) (@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; | |
| 692 | 691 | const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 693 | 692 | try self.writeInstRef(stream, extra.len); |
| 694 | 693 | try stream.writeAll(", "); |
| ... | ... | @@ -704,7 +703,7 @@ const Writer = struct { |
| 704 | 703 | stream: anytype, |
| 705 | 704 | inst: Zir.Inst.Index, |
| 706 | 705 | ) (@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; | |
| 708 | 707 | const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else ""; |
| 709 | 708 | const str_const = if (!inst_data.flags.is_mutable) "const, " else ""; |
| 710 | 709 | const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else ""; |
| ... | ... | @@ -745,12 +744,12 @@ const Writer = struct { |
| 745 | 744 | } |
| 746 | 745 | |
| 747 | 746 | 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; | |
| 749 | 748 | try stream.print("{d})", .{inst_data}); |
| 750 | 749 | } |
| 751 | 750 | |
| 752 | 751 | 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; | |
| 754 | 753 | const byte_count = inst_data.len * @sizeOf(std.math.big.Limb); |
| 755 | 754 | const limb_bytes = self.code.string_bytes[inst_data.start..][0..byte_count]; |
| 756 | 755 | // limb_bytes is not aligned properly; we must allocate and copy the bytes |
| ... | ... | @@ -769,12 +768,12 @@ const Writer = struct { |
| 769 | 768 | } |
| 770 | 769 | |
| 771 | 770 | 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; | |
| 773 | 772 | try stream.print("{d})", .{number}); |
| 774 | 773 | } |
| 775 | 774 | |
| 776 | 775 | 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; | |
| 778 | 777 | const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 779 | 778 | const src = inst_data.src(); |
| 780 | 779 | const number = extra.get(); |
| ... | ... | @@ -788,13 +787,13 @@ const Writer = struct { |
| 788 | 787 | stream: anytype, |
| 789 | 788 | inst: Zir.Inst.Index, |
| 790 | 789 | ) (@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; | |
| 792 | 791 | const str = inst_data.get(self.code); |
| 793 | 792 | try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)}); |
| 794 | 793 | } |
| 795 | 794 | |
| 796 | 795 | 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; | |
| 798 | 797 | const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 799 | 798 | try self.writeInstRef(stream, extra.lhs); |
| 800 | 799 | try stream.writeAll(", "); |
| ... | ... | @@ -804,7 +803,7 @@ const Writer = struct { |
| 804 | 803 | } |
| 805 | 804 | |
| 806 | 805 | 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; | |
| 808 | 807 | const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 809 | 808 | try self.writeInstRef(stream, extra.lhs); |
| 810 | 809 | try stream.writeAll(", "); |
| ... | ... | @@ -816,7 +815,7 @@ const Writer = struct { |
| 816 | 815 | } |
| 817 | 816 | |
| 818 | 817 | 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; | |
| 820 | 819 | const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 821 | 820 | try self.writeInstRef(stream, extra.lhs); |
| 822 | 821 | try stream.writeAll(", "); |
| ... | ... | @@ -830,7 +829,7 @@ const Writer = struct { |
| 830 | 829 | } |
| 831 | 830 | |
| 832 | 831 | 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; | |
| 834 | 833 | const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 835 | 834 | try self.writeInstRef(stream, extra.lhs); |
| 836 | 835 | try stream.writeAll(", "); |
| ... | ... | @@ -846,7 +845,7 @@ const Writer = struct { |
| 846 | 845 | } |
| 847 | 846 | |
| 848 | 847 | 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; | |
| 850 | 849 | const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 851 | 850 | try self.writeInstRef(stream, extra.union_type); |
| 852 | 851 | try stream.writeAll(", "); |
| ... | ... | @@ -858,7 +857,7 @@ const Writer = struct { |
| 858 | 857 | } |
| 859 | 858 | |
| 860 | 859 | 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; | |
| 862 | 861 | const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 863 | 862 | try self.writeInstRef(stream, extra.elem_type); |
| 864 | 863 | try stream.writeAll(", "); |
| ... | ... | @@ -885,7 +884,7 @@ const Writer = struct { |
| 885 | 884 | } |
| 886 | 885 | |
| 887 | 886 | 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; | |
| 889 | 888 | const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 890 | 889 | try self.writeInstRef(stream, extra.mulend1); |
| 891 | 890 | try stream.writeAll(", "); |
| ... | ... | @@ -897,7 +896,7 @@ const Writer = struct { |
| 897 | 896 | } |
| 898 | 897 | |
| 899 | 898 | 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; | |
| 901 | 900 | const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 902 | 901 | |
| 903 | 902 | try self.writeFlag(stream, "nodiscard ", extra.flags.ensure_result_used); |
| ... | ... | @@ -913,7 +912,7 @@ const Writer = struct { |
| 913 | 912 | } |
| 914 | 913 | |
| 915 | 914 | 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; | |
| 917 | 916 | const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; |
| 918 | 917 | try self.writeInstRef(stream, extra.parent_type); |
| 919 | 918 | try stream.writeAll(", "); |
| ... | ... | @@ -938,9 +937,9 @@ const Writer = struct { |
| 938 | 937 | } |
| 939 | 938 | |
| 940 | 939 | 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; | |
| 942 | 941 | 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); | |
| 944 | 943 | try stream.print("\"{}\", ", .{ |
| 945 | 944 | std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)), |
| 946 | 945 | }); |
| ... | ... | @@ -956,7 +955,7 @@ const Writer = struct { |
| 956 | 955 | } |
| 957 | 956 | |
| 958 | 957 | 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; | |
| 960 | 959 | const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 961 | 960 | try self.writeInstRef(stream, extra.lhs); |
| 962 | 961 | try stream.writeAll(", "); |
| ... | ... | @@ -966,7 +965,7 @@ const Writer = struct { |
| 966 | 965 | } |
| 967 | 966 | |
| 968 | 967 | 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; | |
| 970 | 969 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 971 | 970 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| 972 | 971 | try stream.writeAll("{"); |
| ... | ... | @@ -979,13 +978,13 @@ const Writer = struct { |
| 979 | 978 | } |
| 980 | 979 | |
| 981 | 980 | 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; | |
| 983 | 982 | try self.writeInstRef(stream, inst_data.operand); |
| 984 | 983 | try stream.print(", {d})", .{inst_data.idx}); |
| 985 | 984 | } |
| 986 | 985 | |
| 987 | 986 | 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; | |
| 989 | 988 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 990 | 989 | |
| 991 | 990 | try self.writeInstRef(stream, extra.ptr); |
| ... | ... | @@ -994,7 +993,7 @@ const Writer = struct { |
| 994 | 993 | } |
| 995 | 994 | |
| 996 | 995 | 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; | |
| 998 | 997 | const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 999 | 998 | const decl_name = self.code.nullTerminatedString(extra.decl_name); |
| 1000 | 999 | |
| ... | ... | @@ -1006,7 +1005,7 @@ const Writer = struct { |
| 1006 | 1005 | } |
| 1007 | 1006 | |
| 1008 | 1007 | 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; | |
| 1010 | 1009 | const extra = self.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 1011 | 1010 | |
| 1012 | 1011 | try self.writeInstRef(stream, extra.operand); |
| ... | ... | @@ -1017,7 +1016,7 @@ const Writer = struct { |
| 1017 | 1016 | } |
| 1018 | 1017 | |
| 1019 | 1018 | 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; | |
| 1021 | 1020 | const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data; |
| 1022 | 1021 | |
| 1023 | 1022 | try self.writeInstRef(stream, extra.ptr_ty); |
| ... | ... | @@ -1027,7 +1026,7 @@ const Writer = struct { |
| 1027 | 1026 | } |
| 1028 | 1027 | |
| 1029 | 1028 | 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; | |
| 1031 | 1030 | const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 1032 | 1031 | var field_i: u32 = 0; |
| 1033 | 1032 | var extra_index = extra.end; |
| ... | ... | @@ -1095,7 +1094,7 @@ const Writer = struct { |
| 1095 | 1094 | } |
| 1096 | 1095 | |
| 1097 | 1096 | 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; | |
| 1099 | 1098 | const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 1100 | 1099 | |
| 1101 | 1100 | try self.writeInstRef(stream, extra.elem_type); |
| ... | ... | @@ -1108,7 +1107,7 @@ const Writer = struct { |
| 1108 | 1107 | } |
| 1109 | 1108 | |
| 1110 | 1109 | 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; | |
| 1112 | 1111 | const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 1113 | 1112 | |
| 1114 | 1113 | try self.writeInstRef(stream, extra.ptr); |
| ... | ... | @@ -1121,7 +1120,7 @@ const Writer = struct { |
| 1121 | 1120 | } |
| 1122 | 1121 | |
| 1123 | 1122 | 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; | |
| 1125 | 1124 | const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 1126 | 1125 | |
| 1127 | 1126 | try self.writeInstRef(stream, extra.ptr); |
| ... | ... | @@ -1136,7 +1135,7 @@ const Writer = struct { |
| 1136 | 1135 | } |
| 1137 | 1136 | |
| 1138 | 1137 | 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; | |
| 1140 | 1139 | const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 1141 | 1140 | var field_i: u32 = 0; |
| 1142 | 1141 | var extra_index = extra.end; |
| ... | ... | @@ -1157,7 +1156,7 @@ const Writer = struct { |
| 1157 | 1156 | } |
| 1158 | 1157 | |
| 1159 | 1158 | 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; | |
| 1161 | 1160 | const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 1162 | 1161 | try self.writeInstRef(stream, extra.container_type); |
| 1163 | 1162 | const field_name = self.code.nullTerminatedString(extra.name_start); |
| ... | ... | @@ -1166,7 +1165,7 @@ const Writer = struct { |
| 1166 | 1165 | } |
| 1167 | 1166 | |
| 1168 | 1167 | 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; | |
| 1170 | 1169 | const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 1171 | 1170 | try self.writeInstRef(stream, extra.container_type); |
| 1172 | 1171 | try stream.writeAll(", "); |
| ... | ... | @@ -1193,7 +1192,7 @@ const Writer = struct { |
| 1193 | 1192 | stream: anytype, |
| 1194 | 1193 | inst: Zir.Inst.Index, |
| 1195 | 1194 | ) (@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; | |
| 1197 | 1196 | try self.writeInstIndex(stream, inst_data.inst); |
| 1198 | 1197 | try stream.writeAll(") "); |
| 1199 | 1198 | try self.writeSrc(stream, inst_data.src()); |
| ... | ... | @@ -1297,7 +1296,7 @@ const Writer = struct { |
| 1297 | 1296 | inst: Zir.Inst.Index, |
| 1298 | 1297 | comptime kind: enum { direct, field }, |
| 1299 | 1298 | ) !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; | |
| 1301 | 1300 | const ExtraType = switch (kind) { |
| 1302 | 1301 | .direct => Zir.Inst.Call, |
| 1303 | 1302 | .field => Zir.Inst.FieldCall, |
| ... | ... | @@ -1331,7 +1330,7 @@ const Writer = struct { |
| 1331 | 1330 | const arg_end = self.code.extra[extra.end + i]; |
| 1332 | 1331 | defer arg_start = arg_end; |
| 1333 | 1332 | const arg_body = body[arg_start..arg_end]; |
| 1334 | try self.writeBracedBody(stream, arg_body); | |
| 1333 | try self.writeBracedBody(stream, @ptrCast(arg_body)); | |
| 1335 | 1334 | |
| 1336 | 1335 | try stream.writeAll(",\n"); |
| 1337 | 1336 | } |
| ... | ... | @@ -1345,24 +1344,24 @@ const Writer = struct { |
| 1345 | 1344 | } |
| 1346 | 1345 | |
| 1347 | 1346 | 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; | |
| 1349 | 1348 | try self.writePlNodeBlockWithoutSrc(stream, inst); |
| 1350 | 1349 | try self.writeSrc(stream, inst_data.src()); |
| 1351 | 1350 | } |
| 1352 | 1351 | |
| 1353 | 1352 | 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; | |
| 1355 | 1354 | 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); | |
| 1357 | 1356 | try self.writeBracedBody(stream, body); |
| 1358 | 1357 | try stream.writeAll(") "); |
| 1359 | 1358 | } |
| 1360 | 1359 | |
| 1361 | 1360 | 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; | |
| 1363 | 1362 | 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); | |
| 1366 | 1365 | try self.writeInstRef(stream, extra.data.condition); |
| 1367 | 1366 | try stream.writeAll(", "); |
| 1368 | 1367 | try self.writeBracedBody(stream, then_body); |
| ... | ... | @@ -1373,9 +1372,9 @@ const Writer = struct { |
| 1373 | 1372 | } |
| 1374 | 1373 | |
| 1375 | 1374 | 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; | |
| 1377 | 1376 | 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); | |
| 1379 | 1378 | try self.writeInstRef(stream, extra.data.operand); |
| 1380 | 1379 | try stream.writeAll(", "); |
| 1381 | 1380 | try self.writeBracedBody(stream, body); |
| ... | ... | @@ -1421,7 +1420,7 @@ const Writer = struct { |
| 1421 | 1420 | extra_index += 1; |
| 1422 | 1421 | try self.writeInstRef(stream, backing_int_ref); |
| 1423 | 1422 | } 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); | |
| 1425 | 1424 | extra_index += backing_int_body_len; |
| 1426 | 1425 | self.indent += 2; |
| 1427 | 1426 | try self.writeBracedDecl(stream, body); |
| ... | ... | @@ -1535,7 +1534,7 @@ const Writer = struct { |
| 1535 | 1534 | } |
| 1536 | 1535 | |
| 1537 | 1536 | 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); | |
| 1539 | 1538 | extra_index += body.len; |
| 1540 | 1539 | self.indent += 2; |
| 1541 | 1540 | try self.writeBracedDecl(stream, body); |
| ... | ... | @@ -1543,7 +1542,7 @@ const Writer = struct { |
| 1543 | 1542 | } |
| 1544 | 1543 | |
| 1545 | 1544 | 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); | |
| 1547 | 1546 | extra_index += body.len; |
| 1548 | 1547 | self.indent += 2; |
| 1549 | 1548 | try stream.writeAll(" align("); |
| ... | ... | @@ -1553,7 +1552,7 @@ const Writer = struct { |
| 1553 | 1552 | } |
| 1554 | 1553 | |
| 1555 | 1554 | 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); | |
| 1557 | 1556 | extra_index += body.len; |
| 1558 | 1557 | self.indent += 2; |
| 1559 | 1558 | try stream.writeAll(" = "); |
| ... | ... | @@ -1639,7 +1638,7 @@ const Writer = struct { |
| 1639 | 1638 | } |
| 1640 | 1639 | try stream.writeAll(", "); |
| 1641 | 1640 | |
| 1642 | const body = self.code.extra[extra_index..][0..body_len]; | |
| 1641 | const body = self.code.bodySlice(extra_index, body_len); | |
| 1643 | 1642 | extra_index += body.len; |
| 1644 | 1643 | |
| 1645 | 1644 | const prev_parent_decl_node = self.parent_decl_node; |
| ... | ... | @@ -1742,7 +1741,7 @@ const Writer = struct { |
| 1742 | 1741 | extra_index += 1; |
| 1743 | 1742 | const decl_name_index = self.code.extra[extra_index]; |
| 1744 | 1743 | 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]); | |
| 1746 | 1745 | extra_index += 1; |
| 1747 | 1746 | const doc_comment_index = self.code.extra[extra_index]; |
| 1748 | 1747 | extra_index += 1; |
| ... | ... | @@ -1764,7 +1763,7 @@ const Writer = struct { |
| 1764 | 1763 | }; |
| 1765 | 1764 | |
| 1766 | 1765 | 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.*); | |
| 1768 | 1767 | if (decl_name_index == 0) { |
| 1769 | 1768 | try stream.writeByteNTimes(' ', self.indent); |
| 1770 | 1769 | const name = if (is_exported) "usingnamespace" else "comptime"; |
| ... | ... | @@ -1810,12 +1809,12 @@ const Writer = struct { |
| 1810 | 1809 | } |
| 1811 | 1810 | |
| 1812 | 1811 | 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)]; | |
| 1814 | 1813 | try stream.print(" line({d}) hash({}): %{d} = {s}(", .{ |
| 1815 | 1814 | line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index, @tagName(tag), |
| 1816 | 1815 | }); |
| 1817 | 1816 | |
| 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; | |
| 1819 | 1818 | const sub_decl_node_off = decl_block_inst_data.src_node; |
| 1820 | 1819 | self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off); |
| 1821 | 1820 | try self.writePlNodeBlockWithoutSrc(stream, decl_index); |
| ... | ... | @@ -1888,7 +1887,7 @@ const Writer = struct { |
| 1888 | 1887 | try stream.writeAll(", "); |
| 1889 | 1888 | } |
| 1890 | 1889 | |
| 1891 | const body = self.code.extra[extra_index..][0..body_len]; | |
| 1890 | const body = self.code.bodySlice(extra_index, body_len); | |
| 1892 | 1891 | extra_index += body.len; |
| 1893 | 1892 | |
| 1894 | 1893 | const prev_parent_decl_node = self.parent_decl_node; |
| ... | ... | @@ -1988,7 +1987,7 @@ const Writer = struct { |
| 1988 | 1987 | inst: Zir.Inst.Index, |
| 1989 | 1988 | name_strategy: Zir.Inst.NameStrategy, |
| 1990 | 1989 | ) !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; | |
| 1992 | 1991 | const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); |
| 1993 | 1992 | |
| 1994 | 1993 | try stream.print("{s}, ", .{@tagName(name_strategy)}); |
| ... | ... | @@ -2015,7 +2014,7 @@ const Writer = struct { |
| 2015 | 2014 | } |
| 2016 | 2015 | |
| 2017 | 2016 | 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; | |
| 2019 | 2018 | const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 2020 | 2019 | |
| 2021 | 2020 | var extra_index: usize = extra.end; |
| ... | ... | @@ -2029,7 +2028,7 @@ const Writer = struct { |
| 2029 | 2028 | const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: { |
| 2030 | 2029 | const tag_capture_inst = self.code.extra[extra_index]; |
| 2031 | 2030 | extra_index += 1; |
| 2032 | break :blk tag_capture_inst; | |
| 2031 | break :blk @enumFromInt(tag_capture_inst); | |
| 2033 | 2032 | } else undefined; |
| 2034 | 2033 | |
| 2035 | 2034 | try self.writeInstRef(stream, extra.data.operand); |
| ... | ... | @@ -2057,7 +2056,7 @@ const Writer = struct { |
| 2057 | 2056 | }; |
| 2058 | 2057 | const inline_text = if (info.is_inline) "inline " else ""; |
| 2059 | 2058 | 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); | |
| 2061 | 2060 | extra_index += body.len; |
| 2062 | 2061 | |
| 2063 | 2062 | try stream.writeAll(",\n"); |
| ... | ... | @@ -2074,7 +2073,7 @@ const Writer = struct { |
| 2074 | 2073 | extra_index += 1; |
| 2075 | 2074 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index])); |
| 2076 | 2075 | 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); | |
| 2078 | 2077 | extra_index += info.body_len; |
| 2079 | 2078 | |
| 2080 | 2079 | try stream.writeAll(",\n"); |
| ... | ... | @@ -2131,7 +2130,7 @@ const Writer = struct { |
| 2131 | 2130 | try self.writeInstRef(stream, item_last); |
| 2132 | 2131 | } |
| 2133 | 2132 | |
| 2134 | const body = self.code.extra[extra_index..][0..info.body_len]; | |
| 2133 | const body = self.code.bodySlice(extra_index, info.body_len); | |
| 2135 | 2134 | extra_index += info.body_len; |
| 2136 | 2135 | try stream.writeAll(" => "); |
| 2137 | 2136 | try self.writeBracedBody(stream, body); |
| ... | ... | @@ -2145,7 +2144,7 @@ const Writer = struct { |
| 2145 | 2144 | } |
| 2146 | 2145 | |
| 2147 | 2146 | 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; | |
| 2149 | 2148 | const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 2150 | 2149 | const name = self.code.nullTerminatedString(extra.field_name_start); |
| 2151 | 2150 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -2154,7 +2153,7 @@ const Writer = struct { |
| 2154 | 2153 | } |
| 2155 | 2154 | |
| 2156 | 2155 | 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; | |
| 2158 | 2157 | const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 2159 | 2158 | try self.writeInstRef(stream, extra.lhs); |
| 2160 | 2159 | try stream.writeAll(", "); |
| ... | ... | @@ -2164,7 +2163,7 @@ const Writer = struct { |
| 2164 | 2163 | } |
| 2165 | 2164 | |
| 2166 | 2165 | 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; | |
| 2168 | 2167 | const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 2169 | 2168 | try self.writeInstRef(stream, extra.dest_type); |
| 2170 | 2169 | try stream.writeAll(", "); |
| ... | ... | @@ -2178,7 +2177,7 @@ const Writer = struct { |
| 2178 | 2177 | stream: anytype, |
| 2179 | 2178 | inst: Zir.Inst.Index, |
| 2180 | 2179 | ) (@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; | |
| 2182 | 2181 | const src = LazySrcLoc.nodeOffset(src_node); |
| 2183 | 2182 | try stream.writeAll(") "); |
| 2184 | 2183 | try self.writeSrc(stream, src); |
| ... | ... | @@ -2189,14 +2188,14 @@ const Writer = struct { |
| 2189 | 2188 | stream: anytype, |
| 2190 | 2189 | inst: Zir.Inst.Index, |
| 2191 | 2190 | ) (@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; | |
| 2193 | 2192 | const str = inst_data.get(self.code); |
| 2194 | 2193 | try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)}); |
| 2195 | 2194 | try self.writeSrc(stream, inst_data.src()); |
| 2196 | 2195 | } |
| 2197 | 2196 | |
| 2198 | 2197 | 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; | |
| 2200 | 2199 | const str = inst_data.getStr(self.code); |
| 2201 | 2200 | try self.writeInstRef(stream, inst_data.operand); |
| 2202 | 2201 | try stream.print(", \"{}\")", .{std.zig.fmtEscapes(str)}); |
| ... | ... | @@ -2208,7 +2207,7 @@ const Writer = struct { |
| 2208 | 2207 | inst: Zir.Inst.Index, |
| 2209 | 2208 | inferred_error_set: bool, |
| 2210 | 2209 | ) !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; | |
| 2212 | 2211 | const src = inst_data.src(); |
| 2213 | 2212 | const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 2214 | 2213 | |
| ... | ... | @@ -2225,12 +2224,12 @@ const Writer = struct { |
| 2225 | 2224 | extra_index += 1; |
| 2226 | 2225 | }, |
| 2227 | 2226 | 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); | |
| 2229 | 2228 | extra_index += ret_ty_body.len; |
| 2230 | 2229 | }, |
| 2231 | 2230 | } |
| 2232 | 2231 | |
| 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); | |
| 2234 | 2233 | extra_index += body.len; |
| 2235 | 2234 | |
| 2236 | 2235 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; |
| ... | ... | @@ -2263,7 +2262,7 @@ const Writer = struct { |
| 2263 | 2262 | } |
| 2264 | 2263 | |
| 2265 | 2264 | 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; | |
| 2267 | 2266 | const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 2268 | 2267 | const src = inst_data.src(); |
| 2269 | 2268 | |
| ... | ... | @@ -2289,7 +2288,7 @@ const Writer = struct { |
| 2289 | 2288 | if (extra.data.bits.has_align_body) { |
| 2290 | 2289 | const body_len = self.code.extra[extra_index]; |
| 2291 | 2290 | extra_index += 1; |
| 2292 | align_body = self.code.extra[extra_index..][0..body_len]; | |
| 2291 | align_body = self.code.bodySlice(extra_index, body_len); | |
| 2293 | 2292 | extra_index += align_body.len; |
| 2294 | 2293 | } else if (extra.data.bits.has_align_ref) { |
| 2295 | 2294 | align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | ... | @@ -2298,7 +2297,7 @@ const Writer = struct { |
| 2298 | 2297 | if (extra.data.bits.has_addrspace_body) { |
| 2299 | 2298 | const body_len = self.code.extra[extra_index]; |
| 2300 | 2299 | extra_index += 1; |
| 2301 | addrspace_body = self.code.extra[extra_index..][0..body_len]; | |
| 2300 | addrspace_body = self.code.bodySlice(extra_index, body_len); | |
| 2302 | 2301 | extra_index += addrspace_body.len; |
| 2303 | 2302 | } else if (extra.data.bits.has_addrspace_ref) { |
| 2304 | 2303 | addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | ... | @@ -2307,7 +2306,7 @@ const Writer = struct { |
| 2307 | 2306 | if (extra.data.bits.has_section_body) { |
| 2308 | 2307 | const body_len = self.code.extra[extra_index]; |
| 2309 | 2308 | extra_index += 1; |
| 2310 | section_body = self.code.extra[extra_index..][0..body_len]; | |
| 2309 | section_body = self.code.bodySlice(extra_index, body_len); | |
| 2311 | 2310 | extra_index += section_body.len; |
| 2312 | 2311 | } else if (extra.data.bits.has_section_ref) { |
| 2313 | 2312 | section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | ... | @@ -2316,7 +2315,7 @@ const Writer = struct { |
| 2316 | 2315 | if (extra.data.bits.has_cc_body) { |
| 2317 | 2316 | const body_len = self.code.extra[extra_index]; |
| 2318 | 2317 | extra_index += 1; |
| 2319 | cc_body = self.code.extra[extra_index..][0..body_len]; | |
| 2318 | cc_body = self.code.bodySlice(extra_index, body_len); | |
| 2320 | 2319 | extra_index += cc_body.len; |
| 2321 | 2320 | } else if (extra.data.bits.has_cc_ref) { |
| 2322 | 2321 | cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | ... | @@ -2325,7 +2324,7 @@ const Writer = struct { |
| 2325 | 2324 | if (extra.data.bits.has_ret_ty_body) { |
| 2326 | 2325 | const body_len = self.code.extra[extra_index]; |
| 2327 | 2326 | 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); | |
| 2329 | 2328 | extra_index += ret_ty_body.len; |
| 2330 | 2329 | } else if (extra.data.bits.has_ret_ty_ref) { |
| 2331 | 2330 | ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | ... | @@ -2338,7 +2337,7 @@ const Writer = struct { |
| 2338 | 2337 | break :blk x; |
| 2339 | 2338 | } else 0; |
| 2340 | 2339 | |
| 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); | |
| 2342 | 2341 | extra_index += body.len; |
| 2343 | 2342 | |
| 2344 | 2343 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; |
| ... | ... | @@ -2423,7 +2422,7 @@ const Writer = struct { |
| 2423 | 2422 | |
| 2424 | 2423 | fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| 2425 | 2424 | 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); | |
| 2427 | 2426 | try self.writeBracedBody(stream, body); |
| 2428 | 2427 | try stream.writeAll(",["); |
| 2429 | 2428 | const args = self.code.refSlice(extra.end, extended.small); |
| ... | ... | @@ -2435,16 +2434,16 @@ const Writer = struct { |
| 2435 | 2434 | } |
| 2436 | 2435 | |
| 2437 | 2436 | 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; | |
| 2439 | 2438 | 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); | |
| 2441 | 2440 | try self.writeInstRef(stream, inst_data.lhs); |
| 2442 | 2441 | try stream.writeAll(", "); |
| 2443 | 2442 | try self.writeBracedBody(stream, body); |
| 2444 | 2443 | } |
| 2445 | 2444 | |
| 2446 | 2445 | 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; | |
| 2448 | 2447 | const prefix: u8 = switch (int_type.signedness) { |
| 2449 | 2448 | .signed => 'i', |
| 2450 | 2449 | .unsigned => 'u', |
| ... | ... | @@ -2454,14 +2453,14 @@ const Writer = struct { |
| 2454 | 2453 | } |
| 2455 | 2454 | |
| 2456 | 2455 | 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; | |
| 2458 | 2457 | |
| 2459 | 2458 | try self.writeInstRef(stream, inst_data.operand); |
| 2460 | 2459 | try stream.writeAll(")"); |
| 2461 | 2460 | } |
| 2462 | 2461 | |
| 2463 | 2462 | 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; | |
| 2465 | 2464 | |
| 2466 | 2465 | try self.writeInstRef(stream, inst_data.block); |
| 2467 | 2466 | try stream.writeAll(", "); |
| ... | ... | @@ -2470,7 +2469,7 @@ const Writer = struct { |
| 2470 | 2469 | } |
| 2471 | 2470 | |
| 2472 | 2471 | 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"; | |
| 2474 | 2473 | const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 2475 | 2474 | |
| 2476 | 2475 | try self.writeInstIndex(stream, extra.block_inst); |
| ... | ... | @@ -2480,7 +2479,7 @@ const Writer = struct { |
| 2480 | 2479 | } |
| 2481 | 2480 | |
| 2482 | 2481 | 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; | |
| 2484 | 2483 | |
| 2485 | 2484 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2486 | 2485 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | ... | @@ -2496,7 +2495,7 @@ const Writer = struct { |
| 2496 | 2495 | } |
| 2497 | 2496 | |
| 2498 | 2497 | 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; | |
| 2500 | 2499 | |
| 2501 | 2500 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2502 | 2501 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | ... | @@ -2511,7 +2510,7 @@ const Writer = struct { |
| 2511 | 2510 | } |
| 2512 | 2511 | |
| 2513 | 2512 | 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; | |
| 2515 | 2514 | |
| 2516 | 2515 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2517 | 2516 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | ... | @@ -2531,7 +2530,7 @@ const Writer = struct { |
| 2531 | 2530 | } |
| 2532 | 2531 | |
| 2533 | 2532 | 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"; | |
| 2535 | 2534 | try stream.writeAll(") "); |
| 2536 | 2535 | try self.writeSrc(stream, inst_data.src()); |
| 2537 | 2536 | } |
| ... | ... | @@ -2585,34 +2584,37 @@ const Writer = struct { |
| 2585 | 2584 | } |
| 2586 | 2585 | |
| 2587 | 2586 | 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; | |
| 2589 | 2588 | try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 }); |
| 2590 | 2589 | } |
| 2591 | 2590 | |
| 2592 | 2591 | 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); | |
| 2595 | 2594 | try self.writeBracedBody(stream, body); |
| 2596 | 2595 | try stream.writeByte(')'); |
| 2597 | 2596 | } |
| 2598 | 2597 | |
| 2599 | 2598 | 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; | |
| 2601 | 2600 | const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; |
| 2602 | 2601 | |
| 2603 | try self.writeInstRef(stream, Zir.indexToRef(extra.remapped_err_code)); | |
| 2602 | try self.writeInstRef(stream, extra.remapped_err_code.toRef()); | |
| 2604 | 2603 | try stream.writeAll(" = "); |
| 2605 | 2604 | try self.writeInstRef(stream, inst_data.err_code); |
| 2606 | 2605 | try stream.writeAll(", "); |
| 2607 | const body = self.code.extra[extra.index..][0..extra.len]; | |
| 2606 | const body = self.code.bodySlice(extra.index, extra.len); | |
| 2608 | 2607 | try self.writeBracedBody(stream, body); |
| 2609 | 2608 | try stream.writeByte(')'); |
| 2610 | 2609 | } |
| 2611 | 2610 | |
| 2612 | 2611 | 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 | } | |
| 2616 | 2618 | } |
| 2617 | 2619 | |
| 2618 | 2620 | fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |