| author | |
| committer | |
| log | e69fd4d696b7e24c66a50adb3bf3fe011ee1a626 |
| tree | c0fef2d53bcd71009e6dc4f90a9aeb0f35386ca7 |
| parent | 256ab68a97cb6a84278c78d93917ab5e8ae53209 |
| parent | 62f45b802cab1337590d5c3397fca7b84d3a819b |
| signature |
make Zir.Inst.Index typed8 files changed, 1033 insertions(+), 941 deletions(-)
lib/std/mem.zig+22-10| ... | @@ -3527,21 +3527,33 @@ test "max" { | ... | @@ -3527,21 +3527,33 @@ test "max" { |
| 3527 | /// Finds the smallest and largest number in a slice. O(n). | 3527 | /// Finds the smallest and largest number in a slice. O(n). |
| 3528 | /// Returns an anonymous struct with the fields `min` and `max`. | 3528 | /// Returns an anonymous struct with the fields `min` and `max`. |
| 3529 | /// `slice` must not be empty. | 3529 | /// `slice` must not be empty. |
| 3530 | pub fn minMax(comptime T: type, slice: []const T) struct { min: T, max: T } { | 3530 | pub fn minMax(comptime T: type, slice: []const T) struct { T, T } { |
| 3531 | assert(slice.len > 0); | 3531 | assert(slice.len > 0); |
| 3532 | var minVal = slice[0]; | 3532 | var running_minimum = slice[0]; |
| 3533 | var maxVal = slice[0]; | 3533 | var running_maximum = slice[0]; |
| 3534 | for (slice[1..]) |item| { | 3534 | for (slice[1..]) |item| { |
| 3535 | minVal = @min(minVal, item); | 3535 | running_minimum = @min(running_minimum, item); |
| 3536 | maxVal = @max(maxVal, item); | 3536 | running_maximum = @max(running_maximum, item); |
| 3537 | } | 3537 | } |
| 3538 | return .{ .min = minVal, .max = maxVal }; | 3538 | return .{ running_minimum, running_maximum }; |
| 3539 | } | 3539 | } |
| 3540 | 3540 | ||
| 3541 | test "minMax" { | 3541 | test minMax { |
| 3542 | try testing.expectEqual(minMax(u8, "abcdefg"), .{ .min = 'a', .max = 'g' }); | 3542 | { |
| 3543 | try testing.expectEqual(minMax(u8, "bcdefga"), .{ .min = 'a', .max = 'g' }); | 3543 | const actual_min, const actual_max = minMax(u8, "abcdefg"); |
| 3544 | try testing.expectEqual(minMax(u8, "a"), .{ .min = 'a', .max = 'a' }); | 3544 | try testing.expectEqual(@as(u8, 'a'), actual_min); |
| 3545 | try testing.expectEqual(@as(u8, 'g'), actual_max); | ||
| 3546 | } | ||
| 3547 | { | ||
| 3548 | const actual_min, const actual_max = minMax(u8, "bcdefga"); | ||
| 3549 | try testing.expectEqual(@as(u8, 'a'), actual_min); | ||
| 3550 | try testing.expectEqual(@as(u8, 'g'), actual_max); | ||
| 3551 | } | ||
| 3552 | { | ||
| 3553 | const actual_min, const actual_max = minMax(u8, "a"); | ||
| 3554 | try testing.expectEqual(@as(u8, 'a'), actual_min); | ||
| 3555 | try testing.expectEqual(@as(u8, 'a'), actual_max); | ||
| 3556 | } | ||
| 3545 | } | 3557 | } |
| 3546 | 3558 | ||
| 3547 | /// Returns the index of the smallest number in a slice. O(n). | 3559 | /// Returns the index of the smallest number in a slice. O(n). |
src/AstGen.zig+182-175| ... | @@ -13,8 +13,6 @@ const StringIndexContext = std.hash_map.StringIndexContext; | ... | @@ -13,8 +13,6 @@ const StringIndexContext = std.hash_map.StringIndexContext; |
| 13 | const isPrimitive = std.zig.primitives.isPrimitive; | 13 | const isPrimitive = std.zig.primitives.isPrimitive; |
| 14 | 14 | ||
| 15 | const Zir = @import("Zir.zig"); | 15 | const Zir = @import("Zir.zig"); |
| 16 | const refToIndex = Zir.refToIndex; | ||
| 17 | const indexToRef = Zir.indexToRef; | ||
| 18 | const trace = @import("tracy.zig").trace; | 16 | const trace = @import("tracy.zig").trace; |
| 19 | const BuiltinFn = @import("BuiltinFn.zig"); | 17 | const BuiltinFn = @import("BuiltinFn.zig"); |
| 20 | const AstRlAnnotate = @import("AstRlAnnotate.zig"); | 18 | const AstRlAnnotate = @import("AstRlAnnotate.zig"); |
| ... | @@ -86,13 +84,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { | ... | @@ -86,13 +84,18 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 86 | inline for (fields) |field| { | 84 | inline for (fields) |field| { |
| 87 | astgen.extra.items[i] = switch (field.type) { | 85 | astgen.extra.items[i] = switch (field.type) { |
| 88 | u32 => @field(extra, field.name), | 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 | i32, | 92 | i32, |
| 91 | Zir.Inst.Call.Flags, | 93 | Zir.Inst.Call.Flags, |
| 92 | Zir.Inst.BuiltinCall.Flags, | 94 | Zir.Inst.BuiltinCall.Flags, |
| 93 | Zir.Inst.SwitchBlock.Bits, | 95 | Zir.Inst.SwitchBlock.Bits, |
| 94 | Zir.Inst.FuncFancy.Bits, | 96 | Zir.Inst.FuncFancy.Bits, |
| 95 | => @bitCast(@field(extra, field.name)), | 97 | => @bitCast(@field(extra, field.name)), |
| 98 | |||
| 96 | else => @compileError("bad field type"), | 99 | else => @compileError("bad field type"), |
| 97 | }; | 100 | }; |
| 98 | i += 1; | 101 | i += 1; |
| ... | @@ -166,7 +169,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { | ... | @@ -166,7 +169,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 166 | .Auto, | 169 | .Auto, |
| 167 | 0, | 170 | 0, |
| 168 | )) |struct_decl_ref| { | 171 | )) |struct_decl_ref| { |
| 169 | assert(refToIndex(struct_decl_ref).? == 0); | 172 | assert(struct_decl_ref.toIndex().? == .main_struct_inst); |
| 170 | } else |err| switch (err) { | 173 | } else |err| switch (err) { |
| 171 | error.OutOfMemory => return error.OutOfMemory, | 174 | error.OutOfMemory => return error.OutOfMemory, |
| 172 | error.AnalysisFail => {}, // Handled via compile_errors below. | 175 | error.AnalysisFail => {}, // Handled via compile_errors below. |
| ... | @@ -1200,7 +1203,7 @@ fn suspendExpr( | ... | @@ -1200,7 +1203,7 @@ fn suspendExpr( |
| 1200 | } | 1203 | } |
| 1201 | try suspend_scope.setBlockBody(suspend_inst); | 1204 | try suspend_scope.setBlockBody(suspend_inst); |
| 1202 | 1205 | ||
| 1203 | return indexToRef(suspend_inst); | 1206 | return suspend_inst.toRef(); |
| 1204 | } | 1207 | } |
| 1205 | 1208 | ||
| 1206 | fn awaitExpr( | 1209 | fn awaitExpr( |
| ... | @@ -1316,7 +1319,7 @@ fn fnProtoExpr( | ... | @@ -1316,7 +1319,7 @@ fn fnProtoExpr( |
| 1316 | var param_gz = block_scope.makeSubBlock(scope); | 1319 | var param_gz = block_scope.makeSubBlock(scope); |
| 1317 | defer param_gz.unstack(); | 1320 | defer param_gz.unstack(); |
| 1318 | const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node); | 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 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); | 1323 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 1321 | const main_tokens = tree.nodes.items(.main_token); | 1324 | const main_tokens = tree.nodes.items(.main_token); |
| 1322 | const name_token = param.name_token orelse main_tokens[param_type_node]; | 1325 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| ... | @@ -1386,7 +1389,7 @@ fn fnProtoExpr( | ... | @@ -1386,7 +1389,7 @@ fn fnProtoExpr( |
| 1386 | try block_scope.setBlockBody(block_inst); | 1389 | try block_scope.setBlockBody(block_inst); |
| 1387 | try gz.instructions.append(astgen.gpa, block_inst); | 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 | fn arrayInitExpr( | 1395 | fn arrayInitExpr( |
| ... | @@ -1625,7 +1628,7 @@ fn arrayInitExprPtr( | ... | @@ -1625,7 +1628,7 @@ fn arrayInitExprPtr( |
| 1625 | .ptr = array_ptr_inst, | 1628 | .ptr = array_ptr_inst, |
| 1626 | .index = @intCast(i), | 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 | extra_index += 1; | 1632 | extra_index += 1; |
| 1630 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = elem_ptr_inst } } }, elem_init); | 1633 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = elem_ptr_inst } } }, elem_init); |
| 1631 | } | 1634 | } |
| ... | @@ -1825,7 +1828,7 @@ fn structInitExprTyped( | ... | @@ -1825,7 +1828,7 @@ fn structInitExprTyped( |
| 1825 | .name_start = str_index, | 1828 | .name_start = str_index, |
| 1826 | }); | 1829 | }); |
| 1827 | setExtra(astgen, extra_index, Zir.Inst.StructInit.Item{ | 1830 | setExtra(astgen, extra_index, Zir.Inst.StructInit.Item{ |
| 1828 | .field_type = refToIndex(field_ty_inst).?, | 1831 | .field_type = field_ty_inst.toIndex().?, |
| 1829 | .init = try expr(gz, scope, .{ .rl = .{ .coerced_ty = field_ty_inst } }, field_init), | 1832 | .init = try expr(gz, scope, .{ .rl = .{ .coerced_ty = field_ty_inst } }, field_init), |
| 1830 | }); | 1833 | }); |
| 1831 | extra_index += field_size; | 1834 | extra_index += field_size; |
| ... | @@ -1860,7 +1863,7 @@ fn structInitExprPtr( | ... | @@ -1860,7 +1863,7 @@ fn structInitExprPtr( |
| 1860 | .lhs = struct_ptr_inst, | 1863 | .lhs = struct_ptr_inst, |
| 1861 | .field_name_start = str_index, | 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 | extra_index += 1; | 1867 | extra_index += 1; |
| 1865 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = field_ptr } } }, field_init); | 1868 | _ = try expr(gz, scope, .{ .rl = .{ .ptr = .{ .inst = field_ptr } } }, field_init); |
| 1866 | } | 1869 | } |
| ... | @@ -1962,7 +1965,7 @@ fn comptimeExpr( | ... | @@ -1962,7 +1965,7 @@ fn comptimeExpr( |
| 1962 | try block_scope.setBlockBody(block_inst); | 1965 | try block_scope.setBlockBody(block_inst); |
| 1963 | try gz.instructions.append(gz.astgen.gpa, block_inst); | 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 | /// This one is for an actual `comptime` syntax, and will emit a compile error if | 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,8 +2051,8 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn |
| 2048 | break :blk label.block_inst; | 2051 | break :blk label.block_inst; |
| 2049 | } | 2052 | } |
| 2050 | } | 2053 | } |
| 2051 | } else if (block_gz.break_block != 0) { | 2054 | } else if (block_gz.break_block.unwrap()) |i| { |
| 2052 | break :blk block_gz.break_block; | 2055 | break :blk i; |
| 2053 | } | 2056 | } |
| 2054 | // If not the target, start over with the parent | 2057 | // If not the target, start over with the parent |
| 2055 | scope = block_gz.parent; | 2058 | scope = block_gz.parent; |
| ... | @@ -2135,11 +2138,10 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) | ... | @@ -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; | 2141 | const continue_block = gen_zir.continue_block.unwrap() orelse { |
| 2139 | if (continue_block == 0) { | ||
| 2140 | scope = gen_zir.parent; | 2142 | scope = gen_zir.parent; |
| 2141 | continue; | 2143 | continue; |
| 2142 | } | 2144 | }; |
| 2143 | if (break_label != 0) blk: { | 2145 | if (break_label != 0) blk: { |
| 2144 | if (gen_zir.label) |*label| { | 2146 | if (gen_zir.label) |*label| { |
| 2145 | if (try astgen.tokenIdentEql(label.token, break_label)) { | 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,7 +2159,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) |
| 2157 | else | 2159 | else |
| 2158 | .@"break"; | 2160 | .@"break"; |
| 2159 | if (break_tag == .break_inline) { | 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 | // As our last action before the continue, "pop" the error trace if needed | 2165 | // As our last action before the continue, "pop" the error trace if needed |
| ... | @@ -2333,9 +2335,9 @@ fn labeledBlockExpr( | ... | @@ -2333,9 +2335,9 @@ fn labeledBlockExpr( |
| 2333 | 2335 | ||
| 2334 | try block_scope.setBlockBody(block_inst); | 2336 | try block_scope.setBlockBody(block_inst); |
| 2335 | if (need_result_rvalue) { | 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 | } else { | 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,15 +2440,15 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2438 | 2440 | ||
| 2439 | fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: Ast.Node.Index) InnerError!Ast.Node.Index { | 2441 | fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: Ast.Node.Index) InnerError!Ast.Node.Index { |
| 2440 | var noreturn_src_node: Ast.Node.Index = 0; | 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 | // Note that this array becomes invalid after appending more items to it | 2444 | // Note that this array becomes invalid after appending more items to it |
| 2443 | // in the above while loop. | 2445 | // in the above while loop. |
| 2444 | const zir_tags = gz.astgen.instructions.items(.tag); | 2446 | const zir_tags = gz.astgen.instructions.items(.tag); |
| 2445 | switch (zir_tags[inst]) { | 2447 | switch (zir_tags[@intFromEnum(inst)]) { |
| 2446 | // For some instructions, modify the zir data | 2448 | // For some instructions, modify the zir data |
| 2447 | // so we can avoid a separate ensure_result_used instruction. | 2449 | // so we can avoid a separate ensure_result_used instruction. |
| 2448 | .call, .field_call => { | 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 | comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") == | 2452 | comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") == |
| 2451 | std.meta.fieldIndex(Zir.Inst.FieldCall, "flags")); | 2453 | std.meta.fieldIndex(Zir.Inst.FieldCall, "flags")); |
| 2452 | const flags: *Zir.Inst.Call.Flags = @ptrCast(&gz.astgen.extra.items[ | 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,7 +2458,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2456 | break :b true; | 2458 | break :b true; |
| 2457 | }, | 2459 | }, |
| 2458 | .builtin_call => { | 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 | const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[ | 2462 | const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[ |
| 2461 | break_extra + std.meta.fieldIndex(Zir.Inst.BuiltinCall, "flags").? | 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,7 +2672,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2670 | .array_init_elem_ptr, | 2672 | .array_init_elem_ptr, |
| 2671 | => break :b false, | 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 | .breakpoint, | 2676 | .breakpoint, |
| 2675 | .fence, | 2677 | .fence, |
| 2676 | .set_float_mode, | 2678 | .set_float_mode, |
| ... | @@ -2783,7 +2785,7 @@ fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct { | ... | @@ -2783,7 +2785,7 @@ fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct { |
| 2783 | 2785 | ||
| 2784 | have_err = true; | 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 | need_err_code = need_err_code or have_err_payload; | 2789 | need_err_code = need_err_code or have_err_payload; |
| 2788 | }, | 2790 | }, |
| 2789 | .namespace, .enum_namespace => unreachable, | 2791 | .namespace, .enum_namespace => unreachable, |
| ... | @@ -2831,18 +2833,16 @@ fn genDefers( | ... | @@ -2831,18 +2833,16 @@ fn genDefers( |
| 2831 | try gz.addDefer(defer_scope.index, defer_scope.len); | 2833 | try gz.addDefer(defer_scope.index, defer_scope.len); |
| 2832 | }, | 2834 | }, |
| 2833 | .both => |err_code| { | 2835 | .both => |err_code| { |
| 2834 | if (defer_scope.remapped_err_code == 0) { | 2836 | if (defer_scope.remapped_err_code.unwrap()) |remapped_err_code| { |
| 2835 | try gz.addDefer(defer_scope.index, defer_scope.len); | ||
| 2836 | } else { | ||
| 2837 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 2837 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 2838 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 2838 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 2839 | 2839 | ||
| 2840 | const payload_index = try gz.astgen.addExtra(Zir.Inst.DeferErrCode{ | 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 | .index = defer_scope.index, | 2842 | .index = defer_scope.index, |
| 2843 | .len = defer_scope.len, | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 2846 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 2847 | .tag = .defer_err_code, | 2847 | .tag = .defer_err_code, |
| 2848 | .data = .{ .defer_err_code = .{ | 2848 | .data = .{ .defer_err_code = .{ |
| ... | @@ -2851,6 +2851,8 @@ fn genDefers( | ... | @@ -2851,6 +2851,8 @@ fn genDefers( |
| 2851 | } }, | 2851 | } }, |
| 2852 | }); | 2852 | }); |
| 2853 | gz.instructions.appendAssumeCapacity(new_index); | 2853 | gz.instructions.appendAssumeCapacity(new_index); |
| 2854 | } else { | ||
| 2855 | try gz.addDefer(defer_scope.index, defer_scope.len); | ||
| 2854 | } | 2856 | } |
| 2855 | }, | 2857 | }, |
| 2856 | .normal_only => continue, | 2858 | .normal_only => continue, |
| ... | @@ -2916,12 +2918,13 @@ fn deferStmt( | ... | @@ -2916,12 +2918,13 @@ fn deferStmt( |
| 2916 | 2918 | ||
| 2917 | const payload_token = node_datas[node].lhs; | 2919 | const payload_token = node_datas[node].lhs; |
| 2918 | var local_val_scope: Scope.LocalVal = undefined; | 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 | const have_err_code = scope_tag == .defer_error and payload_token != 0; | 2922 | const have_err_code = scope_tag == .defer_error and payload_token != 0; |
| 2921 | const sub_scope = if (!have_err_code) &defer_gen.base else blk: { | 2923 | const sub_scope = if (!have_err_code) &defer_gen.base else blk: { |
| 2922 | try gz.addDbgBlockBegin(); | 2924 | try gz.addDbgBlockBegin(); |
| 2923 | const ident_name = try gz.astgen.identAsString(payload_token); | 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 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ | 2928 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 2926 | .tag = .extended, | 2929 | .tag = .extended, |
| 2927 | .data = .{ .extended = .{ | 2930 | .data = .{ .extended = .{ |
| ... | @@ -2930,7 +2933,7 @@ fn deferStmt( | ... | @@ -2930,7 +2933,7 @@ fn deferStmt( |
| 2930 | .operand = undefined, | 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 | local_val_scope = .{ | 2937 | local_val_scope = .{ |
| 2935 | .parent = &defer_gen.base, | 2938 | .parent = &defer_gen.base, |
| 2936 | .gen_zir = gz, | 2939 | .gen_zir = gz, |
| ... | @@ -2945,13 +2948,13 @@ fn deferStmt( | ... | @@ -2945,13 +2948,13 @@ fn deferStmt( |
| 2945 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); | 2948 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); |
| 2946 | try checkUsed(gz, scope, sub_scope); | 2949 | try checkUsed(gz, scope, sub_scope); |
| 2947 | if (have_err_code) try gz.addDbgBlockEnd(); | 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 | // We must handle ref_table for remapped_err_code manually. | 2953 | // We must handle ref_table for remapped_err_code manually. |
| 2951 | const body = defer_gen.instructionsSlice(); | 2954 | const body = defer_gen.instructionsSlice(); |
| 2952 | const body_len = blk: { | 2955 | const body_len = blk: { |
| 2953 | var refs: u32 = 0; | 2956 | var refs: u32 = 0; |
| 2954 | if (have_err_code) { | 2957 | if (opt_remapped_err_code.unwrap()) |remapped_err_code| { |
| 2955 | var cur_inst = remapped_err_code; | 2958 | var cur_inst = remapped_err_code; |
| 2956 | while (gz.astgen.ref_table.get(cur_inst)) |ref_inst| { | 2959 | while (gz.astgen.ref_table.get(cur_inst)) |ref_inst| { |
| 2957 | refs += 1; | 2960 | refs += 1; |
| ... | @@ -2963,7 +2966,7 @@ fn deferStmt( | ... | @@ -2963,7 +2966,7 @@ fn deferStmt( |
| 2963 | 2966 | ||
| 2964 | const index: u32 = @intCast(gz.astgen.extra.items.len); | 2967 | const index: u32 = @intCast(gz.astgen.extra.items.len); |
| 2965 | try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len); | 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 | if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| { | 2970 | if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| { |
| 2968 | gz.astgen.appendPossiblyRefdBodyInst(&gz.astgen.extra, kv.value); | 2971 | gz.astgen.appendPossiblyRefdBodyInst(&gz.astgen.extra, kv.value); |
| 2969 | } | 2972 | } |
| ... | @@ -2977,7 +2980,7 @@ fn deferStmt( | ... | @@ -2977,7 +2980,7 @@ fn deferStmt( |
| 2977 | .parent = scope, | 2980 | .parent = scope, |
| 2978 | .index = index, | 2981 | .index = index, |
| 2979 | .len = body_len, | 2982 | .len = body_len, |
| 2980 | .remapped_err_code = remapped_err_code, | 2983 | .remapped_err_code = opt_remapped_err_code, |
| 2981 | }; | 2984 | }; |
| 2982 | return &defer_scope.base; | 2985 | return &defer_scope.base; |
| 2983 | } | 2986 | } |
| ... | @@ -3226,9 +3229,9 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void { | ... | @@ -3226,9 +3229,9 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void { |
| 3226 | if (gz.instructions.items.len > 0) { | 3229 | if (gz.instructions.items.len > 0) { |
| 3227 | const last = gz.instructions.items[gz.instructions.items.len - 1]; | 3230 | const last = gz.instructions.items[gz.instructions.items.len - 1]; |
| 3228 | const zir_tags = astgen.instructions.items(.tag); | 3231 | const zir_tags = astgen.instructions.items(.tag); |
| 3229 | if (zir_tags[last] == .dbg_stmt) { | 3232 | if (zir_tags[@intFromEnum(last)] == .dbg_stmt) { |
| 3230 | const zir_datas = astgen.instructions.items(.data); | 3233 | const zir_datas = astgen.instructions.items(.data); |
| 3231 | zir_datas[last].dbg_stmt = .{ | 3234 | zir_datas[@intFromEnum(last)].dbg_stmt = .{ |
| 3232 | .line = line, | 3235 | .line = line, |
| 3233 | .column = column, | 3236 | .column = column, |
| 3234 | }; | 3237 | }; |
| ... | @@ -3721,8 +3724,8 @@ fn ptrType( | ... | @@ -3721,8 +3724,8 @@ fn ptrType( |
| 3721 | gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref)); | 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); | 3727 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); |
| 3725 | const result = indexToRef(new_index); | 3728 | const result = new_index.toRef(); |
| 3726 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ | 3729 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ |
| 3727 | .ptr_type = .{ | 3730 | .ptr_type = .{ |
| 3728 | .flags = .{ | 3731 | .flags = .{ |
| ... | @@ -4049,7 +4052,7 @@ fn fnDecl( | ... | @@ -4049,7 +4052,7 @@ fn fnDecl( |
| 4049 | var param_gz = decl_gz.makeSubBlock(scope); | 4052 | var param_gz = decl_gz.makeSubBlock(scope); |
| 4050 | defer param_gz.unstack(); | 4053 | defer param_gz.unstack(); |
| 4051 | const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node); | 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 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); | 4056 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 4054 | 4057 | ||
| 4055 | const main_tokens = tree.nodes.items(.main_token); | 4058 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -4057,7 +4060,7 @@ fn fnDecl( | ... | @@ -4057,7 +4060,7 @@ fn fnDecl( |
| 4057 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; | 4060 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 4058 | const param_inst = try decl_gz.addParam(&param_gz, tag, name_token, param_name, param.first_doc_comment); | 4061 | const param_inst = try decl_gz.addParam(&param_gz, tag, name_token, param_name, param.first_doc_comment); |
| 4059 | assert(param_inst_expected == param_inst); | 4062 | assert(param_inst_expected == param_inst); |
| 4060 | break :param indexToRef(param_inst); | 4063 | break :param param_inst.toRef(); |
| 4061 | }; | 4064 | }; |
| 4062 | 4065 | ||
| 4063 | if (param_name == 0 or is_extern) continue; | 4066 | if (param_name == 0 or is_extern) continue; |
| ... | @@ -4102,7 +4105,7 @@ fn fnDecl( | ... | @@ -4102,7 +4105,7 @@ fn fnDecl( |
| 4102 | // In this case we will send a len=0 body which can be encoded more efficiently. | 4105 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4103 | break :inst inst; | 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 | break :inst inst; | 4109 | break :inst inst; |
| 4107 | }; | 4110 | }; |
| 4108 | 4111 | ||
| ... | @@ -4114,7 +4117,7 @@ fn fnDecl( | ... | @@ -4114,7 +4117,7 @@ fn fnDecl( |
| 4114 | // In this case we will send a len=0 body which can be encoded more efficiently. | 4117 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4115 | break :inst inst; | 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 | break :inst inst; | 4121 | break :inst inst; |
| 4119 | }; | 4122 | }; |
| 4120 | 4123 | ||
| ... | @@ -4126,7 +4129,7 @@ fn fnDecl( | ... | @@ -4126,7 +4129,7 @@ fn fnDecl( |
| 4126 | // In this case we will send a len=0 body which can be encoded more efficiently. | 4129 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4127 | break :inst inst; | 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 | break :inst inst; | 4133 | break :inst inst; |
| 4131 | }; | 4134 | }; |
| 4132 | 4135 | ||
| ... | @@ -4151,7 +4154,7 @@ fn fnDecl( | ... | @@ -4151,7 +4154,7 @@ fn fnDecl( |
| 4151 | // In this case we will send a len=0 body which can be encoded more efficiently. | 4154 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4152 | break :blk inst; | 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 | break :blk inst; | 4158 | break :blk inst; |
| 4156 | } else if (is_extern) { | 4159 | } else if (is_extern) { |
| 4157 | // note: https://github.com/ziglang/zig/issues/5269 | 4160 | // note: https://github.com/ziglang/zig/issues/5269 |
| ... | @@ -4171,7 +4174,7 @@ fn fnDecl( | ... | @@ -4171,7 +4174,7 @@ fn fnDecl( |
| 4171 | // In this case we will send a len=0 body which can be encoded more efficiently. | 4174 | // In this case we will send a len=0 body which can be encoded more efficiently. |
| 4172 | break :inst inst; | 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 | break :inst inst; | 4178 | break :inst inst; |
| 4176 | }; | 4179 | }; |
| 4177 | 4180 | ||
| ... | @@ -4271,7 +4274,7 @@ fn fnDecl( | ... | @@ -4271,7 +4274,7 @@ fn fnDecl( |
| 4271 | wip_members.appendToDecl(line_delta); | 4274 | wip_members.appendToDecl(line_delta); |
| 4272 | } | 4275 | } |
| 4273 | wip_members.appendToDecl(fn_name_str_index); | 4276 | wip_members.appendToDecl(fn_name_str_index); |
| 4274 | wip_members.appendToDecl(block_inst); | 4277 | wip_members.appendToDecl(@intFromEnum(block_inst)); |
| 4275 | wip_members.appendToDecl(doc_comment_index); | 4278 | wip_members.appendToDecl(doc_comment_index); |
| 4276 | } | 4279 | } |
| 4277 | 4280 | ||
| ... | @@ -4421,7 +4424,7 @@ fn globalVarDecl( | ... | @@ -4421,7 +4424,7 @@ fn globalVarDecl( |
| 4421 | wip_members.appendToDecl(line_delta); | 4424 | wip_members.appendToDecl(line_delta); |
| 4422 | } | 4425 | } |
| 4423 | wip_members.appendToDecl(name_str_index); | 4426 | wip_members.appendToDecl(name_str_index); |
| 4424 | wip_members.appendToDecl(block_inst); | 4427 | wip_members.appendToDecl(@intFromEnum(block_inst)); |
| 4425 | wip_members.appendToDecl(doc_comment_index); // doc_comment wip | 4428 | wip_members.appendToDecl(doc_comment_index); // doc_comment wip |
| 4426 | if (align_inst != .none) { | 4429 | if (align_inst != .none) { |
| 4427 | wip_members.appendToDecl(@intFromEnum(align_inst)); | 4430 | wip_members.appendToDecl(@intFromEnum(align_inst)); |
| ... | @@ -4475,7 +4478,7 @@ fn comptimeDecl( | ... | @@ -4475,7 +4478,7 @@ fn comptimeDecl( |
| 4475 | wip_members.appendToDecl(line_delta); | 4478 | wip_members.appendToDecl(line_delta); |
| 4476 | } | 4479 | } |
| 4477 | wip_members.appendToDecl(0); | 4480 | wip_members.appendToDecl(0); |
| 4478 | wip_members.appendToDecl(block_inst); | 4481 | wip_members.appendToDecl(@intFromEnum(block_inst)); |
| 4479 | wip_members.appendToDecl(0); // no doc comments on comptime decls | 4482 | wip_members.appendToDecl(0); // no doc comments on comptime decls |
| 4480 | } | 4483 | } |
| 4481 | 4484 | ||
| ... | @@ -4526,7 +4529,7 @@ fn usingnamespaceDecl( | ... | @@ -4526,7 +4529,7 @@ fn usingnamespaceDecl( |
| 4526 | wip_members.appendToDecl(line_delta); | 4529 | wip_members.appendToDecl(line_delta); |
| 4527 | } | 4530 | } |
| 4528 | wip_members.appendToDecl(0); | 4531 | wip_members.appendToDecl(0); |
| 4529 | wip_members.appendToDecl(block_inst); | 4532 | wip_members.appendToDecl(@intFromEnum(block_inst)); |
| 4530 | wip_members.appendToDecl(0); // no doc comments on usingnamespace decls | 4533 | wip_members.appendToDecl(0); // no doc comments on usingnamespace decls |
| 4531 | } | 4534 | } |
| 4532 | 4535 | ||
| ... | @@ -4715,7 +4718,7 @@ fn testDecl( | ... | @@ -4715,7 +4718,7 @@ fn testDecl( |
| 4715 | wip_members.appendToDecl(2) // 2 here means that it is a decltest, look at doc comment for name | 4718 | wip_members.appendToDecl(2) // 2 here means that it is a decltest, look at doc comment for name |
| 4716 | else | 4719 | else |
| 4717 | wip_members.appendToDecl(test_name); | 4720 | wip_members.appendToDecl(test_name); |
| 4718 | wip_members.appendToDecl(block_inst); | 4721 | wip_members.appendToDecl(@intFromEnum(block_inst)); |
| 4719 | if (is_decltest) | 4722 | if (is_decltest) |
| 4720 | wip_members.appendToDecl(test_name) // the doc comment on a decltest represents it's name | 4723 | wip_members.appendToDecl(test_name) // the doc comment on a decltest represents it's name |
| 4721 | else | 4724 | else |
| ... | @@ -4747,7 +4750,7 @@ fn structDeclInner( | ... | @@ -4747,7 +4750,7 @@ fn structDeclInner( |
| 4747 | .any_default_inits = false, | 4750 | .any_default_inits = false, |
| 4748 | .any_aligned_fields = false, | 4751 | .any_aligned_fields = false, |
| 4749 | }); | 4752 | }); |
| 4750 | return indexToRef(decl_inst); | 4753 | return decl_inst.toRef(); |
| 4751 | } | 4754 | } |
| 4752 | 4755 | ||
| 4753 | const astgen = gz.astgen; | 4756 | const astgen = gz.astgen; |
| ... | @@ -4993,7 +4996,7 @@ fn structDeclInner( | ... | @@ -4993,7 +4996,7 @@ fn structDeclInner( |
| 4993 | 4996 | ||
| 4994 | block_scope.unstack(); | 4997 | block_scope.unstack(); |
| 4995 | try gz.addNamespaceCaptures(&namespace); | 4998 | try gz.addNamespaceCaptures(&namespace); |
| 4996 | return indexToRef(decl_inst); | 4999 | return decl_inst.toRef(); |
| 4997 | } | 5000 | } |
| 4998 | 5001 | ||
| 4999 | fn unionDeclInner( | 5002 | fn unionDeclInner( |
| ... | @@ -5154,7 +5157,7 @@ fn unionDeclInner( | ... | @@ -5154,7 +5157,7 @@ fn unionDeclInner( |
| 5154 | 5157 | ||
| 5155 | block_scope.unstack(); | 5158 | block_scope.unstack(); |
| 5156 | try gz.addNamespaceCaptures(&namespace); | 5159 | try gz.addNamespaceCaptures(&namespace); |
| 5157 | return indexToRef(decl_inst); | 5160 | return decl_inst.toRef(); |
| 5158 | } | 5161 | } |
| 5159 | 5162 | ||
| 5160 | fn containerDecl( | 5163 | fn containerDecl( |
| ... | @@ -5404,7 +5407,7 @@ fn containerDecl( | ... | @@ -5404,7 +5407,7 @@ fn containerDecl( |
| 5404 | 5407 | ||
| 5405 | block_scope.unstack(); | 5408 | block_scope.unstack(); |
| 5406 | try gz.addNamespaceCaptures(&namespace); | 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 | .keyword_opaque => { | 5412 | .keyword_opaque => { |
| 5410 | assert(container_decl.ast.arg == 0); | 5413 | assert(container_decl.ast.arg == 0); |
| ... | @@ -5455,7 +5458,7 @@ fn containerDecl( | ... | @@ -5455,7 +5458,7 @@ fn containerDecl( |
| 5455 | 5458 | ||
| 5456 | block_scope.unstack(); | 5459 | block_scope.unstack(); |
| 5457 | try gz.addNamespaceCaptures(&namespace); | 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 | else => unreachable, | 5463 | else => unreachable, |
| 5461 | } | 5464 | } |
| ... | @@ -5642,7 +5645,7 @@ fn tryExpr( | ... | @@ -5642,7 +5645,7 @@ fn tryExpr( |
| 5642 | _ = try else_scope.addUnNode(.ret_node, err_code, node); | 5645 | _ = try else_scope.addUnNode(.ret_node, err_code, node); |
| 5643 | 5646 | ||
| 5644 | try else_scope.setTryBody(try_inst, operand); | 5647 | try else_scope.setTryBody(try_inst, operand); |
| 5645 | const result = indexToRef(try_inst); | 5648 | const result = try_inst.toRef(); |
| 5646 | switch (ri.rl) { | 5649 | switch (ri.rl) { |
| 5647 | .ref, .ref_coerced_ty => return result, | 5650 | .ref, .ref_coerced_ty => return result, |
| 5648 | else => return rvalue(parent_gz, ri, result, node), | 5651 | else => return rvalue(parent_gz, ri, result, node), |
| ... | @@ -5755,9 +5758,9 @@ fn orelseCatchExpr( | ... | @@ -5755,9 +5758,9 @@ fn orelseCatchExpr( |
| 5755 | try setCondBrPayload(condbr, cond, &then_scope, &else_scope); | 5758 | try setCondBrPayload(condbr, cond, &then_scope, &else_scope); |
| 5756 | 5759 | ||
| 5757 | if (need_result_rvalue) { | 5760 | if (need_result_rvalue) { |
| 5758 | return rvalue(parent_gz, ri, indexToRef(block), node); | 5761 | return rvalue(parent_gz, ri, block.toRef(), node); |
| 5759 | } else { | 5762 | } else { |
| 5760 | return indexToRef(block); | 5763 | return block.toRef(); |
| 5761 | } | 5764 | } |
| 5762 | } | 5765 | } |
| 5763 | 5766 | ||
| ... | @@ -5916,7 +5919,7 @@ fn boolBinOp( | ... | @@ -5916,7 +5919,7 @@ fn boolBinOp( |
| 5916 | } | 5919 | } |
| 5917 | try rhs_scope.setBoolBrBody(bool_br); | 5920 | try rhs_scope.setBoolBrBody(bool_br); |
| 5918 | 5921 | ||
| 5919 | const block_ref = indexToRef(bool_br); | 5922 | const block_ref = bool_br.toRef(); |
| 5920 | return rvalue(gz, ri, block_ref, node); | 5923 | return rvalue(gz, ri, block_ref, node); |
| 5921 | } | 5924 | } |
| 5922 | 5925 | ||
| ... | @@ -6116,9 +6119,9 @@ fn ifExpr( | ... | @@ -6116,9 +6119,9 @@ fn ifExpr( |
| 6116 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); | 6119 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); |
| 6117 | 6120 | ||
| 6118 | if (need_result_rvalue) { | 6121 | if (need_result_rvalue) { |
| 6119 | return rvalue(parent_gz, ri, indexToRef(block), node); | 6122 | return rvalue(parent_gz, ri, block.toRef(), node); |
| 6120 | } else { | 6123 | } else { |
| 6121 | return indexToRef(block); | 6124 | return block.toRef(); |
| 6122 | } | 6125 | } |
| 6123 | } | 6126 | } |
| 6124 | 6127 | ||
| ... | @@ -6142,7 +6145,7 @@ fn setCondBrPayload( | ... | @@ -6142,7 +6145,7 @@ fn setCondBrPayload( |
| 6142 | ); | 6145 | ); |
| 6143 | 6146 | ||
| 6144 | const zir_datas = astgen.instructions.items(.data); | 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 | .condition = cond, | 6149 | .condition = cond, |
| 6147 | .then_body_len = then_body_len, | 6150 | .then_body_len = then_body_len, |
| 6148 | .else_body_len = else_body_len, | 6151 | .else_body_len = else_body_len, |
| ... | @@ -6245,7 +6248,7 @@ fn whileExpr( | ... | @@ -6245,7 +6248,7 @@ fn whileExpr( |
| 6245 | 6248 | ||
| 6246 | var dbg_var_name: ?u32 = null; | 6249 | var dbg_var_name: ?u32 = null; |
| 6247 | var dbg_var_inst: Zir.Inst.Ref = undefined; | 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 | var payload_val_scope: Scope.LocalVal = undefined; | 6252 | var payload_val_scope: Scope.LocalVal = undefined; |
| 6250 | const then_sub_scope = s: { | 6253 | const then_sub_scope = s: { |
| 6251 | if (while_full.error_token != null) { | 6254 | if (while_full.error_token != null) { |
| ... | @@ -6255,7 +6258,8 @@ fn whileExpr( | ... | @@ -6255,7 +6258,8 @@ fn whileExpr( |
| 6255 | else | 6258 | else |
| 6256 | .err_union_payload_unsafe; | 6259 | .err_union_payload_unsafe; |
| 6257 | // will add this instruction to then_scope.instructions below | 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 | const ident_token = if (payload_is_ref) payload_token + 1 else payload_token; | 6263 | const ident_token = if (payload_is_ref) payload_token + 1 else payload_token; |
| 6260 | const ident_bytes = tree.tokenSlice(ident_token); | 6264 | const ident_bytes = tree.tokenSlice(ident_token); |
| 6261 | if (mem.eql(u8, "_", ident_bytes)) | 6265 | if (mem.eql(u8, "_", ident_bytes)) |
| ... | @@ -6267,12 +6271,12 @@ fn whileExpr( | ... | @@ -6267,12 +6271,12 @@ fn whileExpr( |
| 6267 | .parent = &then_scope.base, | 6271 | .parent = &then_scope.base, |
| 6268 | .gen_zir = &then_scope, | 6272 | .gen_zir = &then_scope, |
| 6269 | .name = ident_name, | 6273 | .name = ident_name, |
| 6270 | .inst = indexToRef(payload_inst), | 6274 | .inst = payload_inst.toRef(), |
| 6271 | .token_src = payload_token, | 6275 | .token_src = payload_token, |
| 6272 | .id_cat = .capture, | 6276 | .id_cat = .capture, |
| 6273 | }; | 6277 | }; |
| 6274 | dbg_var_name = ident_name; | 6278 | dbg_var_name = ident_name; |
| 6275 | dbg_var_inst = indexToRef(payload_inst); | 6279 | dbg_var_inst = payload_inst.toRef(); |
| 6276 | break :s &payload_val_scope.base; | 6280 | break :s &payload_val_scope.base; |
| 6277 | } else { | 6281 | } else { |
| 6278 | _ = try then_scope.addUnNode(.ensure_err_union_payload_void, cond.inst, node); | 6282 | _ = try then_scope.addUnNode(.ensure_err_union_payload_void, cond.inst, node); |
| ... | @@ -6285,7 +6289,8 @@ fn whileExpr( | ... | @@ -6285,7 +6289,8 @@ fn whileExpr( |
| 6285 | else | 6289 | else |
| 6286 | .optional_payload_unsafe; | 6290 | .optional_payload_unsafe; |
| 6287 | // will add this instruction to then_scope.instructions below | 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 | const ident_name = try astgen.identAsString(ident_token); | 6294 | const ident_name = try astgen.identAsString(ident_token); |
| 6290 | const ident_bytes = tree.tokenSlice(ident_token); | 6295 | const ident_bytes = tree.tokenSlice(ident_token); |
| 6291 | if (mem.eql(u8, "_", ident_bytes)) | 6296 | if (mem.eql(u8, "_", ident_bytes)) |
| ... | @@ -6295,12 +6300,12 @@ fn whileExpr( | ... | @@ -6295,12 +6300,12 @@ fn whileExpr( |
| 6295 | .parent = &then_scope.base, | 6300 | .parent = &then_scope.base, |
| 6296 | .gen_zir = &then_scope, | 6301 | .gen_zir = &then_scope, |
| 6297 | .name = ident_name, | 6302 | .name = ident_name, |
| 6298 | .inst = indexToRef(payload_inst), | 6303 | .inst = payload_inst.toRef(), |
| 6299 | .token_src = ident_token, | 6304 | .token_src = ident_token, |
| 6300 | .id_cat = .capture, | 6305 | .id_cat = .capture, |
| 6301 | }; | 6306 | }; |
| 6302 | dbg_var_name = ident_name; | 6307 | dbg_var_name = ident_name; |
| 6303 | dbg_var_inst = indexToRef(payload_inst); | 6308 | dbg_var_inst = payload_inst.toRef(); |
| 6304 | break :s &payload_val_scope.base; | 6309 | break :s &payload_val_scope.base; |
| 6305 | } else { | 6310 | } else { |
| 6306 | break :s &then_scope.base; | 6311 | break :s &then_scope.base; |
| ... | @@ -6316,8 +6321,8 @@ fn whileExpr( | ... | @@ -6316,8 +6321,8 @@ fn whileExpr( |
| 6316 | _ = try loop_scope.addNode(repeat_tag, node); | 6321 | _ = try loop_scope.addNode(repeat_tag, node); |
| 6317 | 6322 | ||
| 6318 | try loop_scope.setBlockBody(loop_block); | 6323 | try loop_scope.setBlockBody(loop_block); |
| 6319 | loop_scope.break_block = loop_block; | 6324 | loop_scope.break_block = loop_block.toOptional(); |
| 6320 | loop_scope.continue_block = continue_block; | 6325 | loop_scope.continue_block = continue_block.toOptional(); |
| 6321 | if (while_full.label_token) |label_token| { | 6326 | if (while_full.label_token) |label_token| { |
| 6322 | loop_scope.label = .{ | 6327 | loop_scope.label = .{ |
| 6323 | .token = label_token, | 6328 | .token = label_token, |
| ... | @@ -6330,7 +6335,9 @@ fn whileExpr( | ... | @@ -6330,7 +6335,9 @@ fn whileExpr( |
| 6330 | 6335 | ||
| 6331 | try then_scope.addDbgBlockBegin(); | 6336 | try then_scope.addDbgBlockBegin(); |
| 6332 | const then_node = while_full.ast.then_expr; | 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 | if (dbg_var_name) |name| try then_scope.addDbgVar(.dbg_var_val, name, dbg_var_inst); | 6341 | if (dbg_var_name) |name| try then_scope.addDbgVar(.dbg_var_val, name, dbg_var_inst); |
| 6335 | try then_scope.instructions.append(astgen.gpa, continue_block); | 6342 | try then_scope.instructions.append(astgen.gpa, continue_block); |
| 6336 | // This code could be improved to avoid emitting the continue expr when there | 6343 | // This code could be improved to avoid emitting the continue expr when there |
| ... | @@ -6386,8 +6393,8 @@ fn whileExpr( | ... | @@ -6386,8 +6393,8 @@ fn whileExpr( |
| 6386 | }; | 6393 | }; |
| 6387 | // Remove the continue block and break block so that `continue` and `break` | 6394 | // Remove the continue block and break block so that `continue` and `break` |
| 6388 | // control flow apply to outer loops; not this one. | 6395 | // control flow apply to outer loops; not this one. |
| 6389 | loop_scope.continue_block = 0; | 6396 | loop_scope.continue_block = .none; |
| 6390 | loop_scope.break_block = 0; | 6397 | loop_scope.break_block = .none; |
| 6391 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); | 6398 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); |
| 6392 | if (is_statement) { | 6399 | if (is_statement) { |
| 6393 | _ = try addEnsureResult(&else_scope, else_result, else_node); | 6400 | _ = try addEnsureResult(&else_scope, else_result, else_node); |
| ... | @@ -6412,9 +6419,9 @@ fn whileExpr( | ... | @@ -6412,9 +6419,9 @@ fn whileExpr( |
| 6412 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); | 6419 | try setCondBrPayload(condbr, cond.bool_bit, &then_scope, &else_scope); |
| 6413 | 6420 | ||
| 6414 | const result = if (need_result_rvalue) | 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 | else | 6423 | else |
| 6417 | indexToRef(loop_block); | 6424 | loop_block.toRef(); |
| 6418 | 6425 | ||
| 6419 | if (is_statement) { | 6426 | if (is_statement) { |
| 6420 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); | 6427 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); |
| ... | @@ -6577,8 +6584,8 @@ fn forExpr( | ... | @@ -6577,8 +6584,8 @@ fn forExpr( |
| 6577 | const cond_block = try loop_scope.makeBlockInst(block_tag, node); | 6584 | const cond_block = try loop_scope.makeBlockInst(block_tag, node); |
| 6578 | try cond_scope.setBlockBody(cond_block); | 6585 | try cond_scope.setBlockBody(cond_block); |
| 6579 | 6586 | ||
| 6580 | loop_scope.break_block = loop_block; | 6587 | loop_scope.break_block = loop_block.toOptional(); |
| 6581 | loop_scope.continue_block = cond_block; | 6588 | loop_scope.continue_block = cond_block.toOptional(); |
| 6582 | if (for_full.label_token) |label_token| { | 6589 | if (for_full.label_token) |label_token| { |
| 6583 | loop_scope.label = .{ | 6590 | loop_scope.label = .{ |
| 6584 | .token = label_token, | 6591 | .token = label_token, |
| ... | @@ -6671,8 +6678,8 @@ fn forExpr( | ... | @@ -6671,8 +6678,8 @@ fn forExpr( |
| 6671 | const sub_scope = &else_scope.base; | 6678 | const sub_scope = &else_scope.base; |
| 6672 | // Remove the continue block and break block so that `continue` and `break` | 6679 | // Remove the continue block and break block so that `continue` and `break` |
| 6673 | // control flow apply to outer loops; not this one. | 6680 | // control flow apply to outer loops; not this one. |
| 6674 | loop_scope.continue_block = 0; | 6681 | loop_scope.continue_block = .none; |
| 6675 | loop_scope.break_block = 0; | 6682 | loop_scope.break_block = .none; |
| 6676 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); | 6683 | const else_result = try expr(&else_scope, sub_scope, loop_scope.break_result_info, else_node); |
| 6677 | if (is_statement) { | 6684 | if (is_statement) { |
| 6678 | _ = try addEnsureResult(&else_scope, else_result, else_node); | 6685 | _ = try addEnsureResult(&else_scope, else_result, else_node); |
| ... | @@ -6696,7 +6703,7 @@ fn forExpr( | ... | @@ -6696,7 +6703,7 @@ fn forExpr( |
| 6696 | // then_block and else_block unstacked now, can resurrect loop_scope to finally finish it | 6703 | // then_block and else_block unstacked now, can resurrect loop_scope to finally finish it |
| 6697 | { | 6704 | { |
| 6698 | loop_scope.instructions_top = loop_scope.instructions.items.len; | 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 | // Increment the index variable. | 6708 | // Increment the index variable. |
| 6702 | const index_plus_one = try loop_scope.addPlNode(.add_unsafe, node, Zir.Inst.Bin{ | 6709 | const index_plus_one = try loop_scope.addPlNode(.add_unsafe, node, Zir.Inst.Bin{ |
| ... | @@ -6711,9 +6718,9 @@ fn forExpr( | ... | @@ -6711,9 +6718,9 @@ fn forExpr( |
| 6711 | } | 6718 | } |
| 6712 | 6719 | ||
| 6713 | const result = if (need_result_rvalue) | 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 | else | 6722 | else |
| 6716 | indexToRef(loop_block); | 6723 | loop_block.toRef(); |
| 6717 | 6724 | ||
| 6718 | if (is_statement) { | 6725 | if (is_statement) { |
| 6719 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); | 6726 | _ = try parent_gz.addUnNode(.ensure_result_used, result, node); |
| ... | @@ -6912,7 +6919,7 @@ fn switchExpr( | ... | @@ -6912,7 +6919,7 @@ fn switchExpr( |
| 6912 | 6919 | ||
| 6913 | // If any prong has an inline tag capture, allocate a shared dummy instruction for it | 6920 | // If any prong has an inline tag capture, allocate a shared dummy instruction for it |
| 6914 | const tag_inst = if (any_has_tag_capture) tag_inst: { | 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 | try astgen.instructions.append(astgen.gpa, .{ | 6923 | try astgen.instructions.append(astgen.gpa, .{ |
| 6917 | .tag = .extended, | 6924 | .tag = .extended, |
| 6918 | .data = .{ .extended = .{ | 6925 | .data = .{ .extended = .{ |
| ... | @@ -6967,12 +6974,12 @@ fn switchExpr( | ... | @@ -6967,12 +6974,12 @@ fn switchExpr( |
| 6967 | .parent = &case_scope.base, | 6974 | .parent = &case_scope.base, |
| 6968 | .gen_zir = &case_scope, | 6975 | .gen_zir = &case_scope, |
| 6969 | .name = capture_name, | 6976 | .name = capture_name, |
| 6970 | .inst = indexToRef(switch_block), | 6977 | .inst = switch_block.toRef(), |
| 6971 | .token_src = payload_token, | 6978 | .token_src = payload_token, |
| 6972 | .id_cat = .capture, | 6979 | .id_cat = .capture, |
| 6973 | }; | 6980 | }; |
| 6974 | dbg_var_name = capture_name; | 6981 | dbg_var_name = capture_name; |
| 6975 | dbg_var_inst = indexToRef(switch_block); | 6982 | dbg_var_inst = switch_block.toRef(); |
| 6976 | payload_sub_scope = &capture_val_scope.base; | 6983 | payload_sub_scope = &capture_val_scope.base; |
| 6977 | } | 6984 | } |
| 6978 | 6985 | ||
| ... | @@ -6996,12 +7003,12 @@ fn switchExpr( | ... | @@ -6996,12 +7003,12 @@ fn switchExpr( |
| 6996 | .parent = payload_sub_scope, | 7003 | .parent = payload_sub_scope, |
| 6997 | .gen_zir = &case_scope, | 7004 | .gen_zir = &case_scope, |
| 6998 | .name = tag_name, | 7005 | .name = tag_name, |
| 6999 | .inst = indexToRef(tag_inst), | 7006 | .inst = tag_inst.toRef(), |
| 7000 | .token_src = tag_token, | 7007 | .token_src = tag_token, |
| 7001 | .id_cat = .@"switch tag capture", | 7008 | .id_cat = .@"switch tag capture", |
| 7002 | }; | 7009 | }; |
| 7003 | dbg_var_tag_name = tag_name; | 7010 | dbg_var_tag_name = tag_name; |
| 7004 | dbg_var_tag_inst = indexToRef(tag_inst); | 7011 | dbg_var_tag_inst = tag_inst.toRef(); |
| 7005 | break :blk &tag_scope.base; | 7012 | break :blk &tag_scope.base; |
| 7006 | }; | 7013 | }; |
| 7007 | 7014 | ||
| ... | @@ -7136,11 +7143,11 @@ fn switchExpr( | ... | @@ -7136,11 +7143,11 @@ fn switchExpr( |
| 7136 | } | 7143 | } |
| 7137 | 7144 | ||
| 7138 | if (any_has_tag_capture) { | 7145 | if (any_has_tag_capture) { |
| 7139 | astgen.extra.appendAssumeCapacity(tag_inst); | 7146 | astgen.extra.appendAssumeCapacity(@intFromEnum(tag_inst)); |
| 7140 | } | 7147 | } |
| 7141 | 7148 | ||
| 7142 | const zir_datas = astgen.instructions.items(.data); | 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 | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { | 7152 | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { |
| 7146 | var body_len_index = start_index; | 7153 | var body_len_index = start_index; |
| ... | @@ -7163,9 +7170,9 @@ fn switchExpr( | ... | @@ -7163,9 +7170,9 @@ fn switchExpr( |
| 7163 | } | 7170 | } |
| 7164 | 7171 | ||
| 7165 | if (need_result_rvalue) { | 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 | } else { | 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,13 +7531,13 @@ fn tunnelThroughClosure( |
| 7524 | ) !Zir.Inst.Ref { | 7531 | ) !Zir.Inst.Ref { |
| 7525 | // For trivial values, we don't need a tunnel. | 7532 | // For trivial values, we don't need a tunnel. |
| 7526 | // Just return the ref. | 7533 | // Just return the ref. |
| 7527 | if (num_tunnels == 0 or refToIndex(value) == null) { | 7534 | if (num_tunnels == 0 or value.toIndex() == null) { |
| 7528 | return value; | 7535 | return value; |
| 7529 | } | 7536 | } |
| 7530 | 7537 | ||
| 7531 | // Otherwise we need a tunnel. Check if this namespace | 7538 | // Otherwise we need a tunnel. Check if this namespace |
| 7532 | // already has one for this value. | 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 | if (!gop.found_existing) { | 7541 | if (!gop.found_existing) { |
| 7535 | // Make a new capture for this value but don't add it to the declaring_gz yet | 7542 | // Make a new capture for this value but don't add it to the declaring_gz yet |
| 7536 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ | 7543 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| ... | @@ -7540,7 +7547,7 @@ fn tunnelThroughClosure( | ... | @@ -7540,7 +7547,7 @@ fn tunnelThroughClosure( |
| 7540 | .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token), | 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 | // Add an instruction to get the value from the closure into | 7553 | // Add an instruction to get the value from the closure into |
| ... | @@ -8032,7 +8039,7 @@ fn typeOf( | ... | @@ -8032,7 +8039,7 @@ fn typeOf( |
| 8032 | 8039 | ||
| 8033 | // typeof_scope unstacked now, can add new instructions to gz | 8040 | // typeof_scope unstacked now, can add new instructions to gz |
| 8034 | try gz.instructions.append(gpa, typeof_inst); | 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 | const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; | 8044 | const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len; |
| 8038 | const payload_index = try reserveExtra(astgen, payload_size + args.len); | 8045 | const payload_index = try reserveExtra(astgen, payload_size + args.len); |
| ... | @@ -8047,7 +8054,7 @@ fn typeOf( | ... | @@ -8047,7 +8054,7 @@ fn typeOf( |
| 8047 | const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node); | 8054 | const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node); |
| 8048 | astgen.extra.items[args_index + i] = @intFromEnum(param_ref); | 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 | const body = typeof_scope.instructionsSlice(); | 8059 | const body = typeof_scope.instructionsSlice(); |
| 8053 | const body_len = astgen.countBodyLenAfterFixups(body); | 8060 | const body_len = astgen.countBodyLenAfterFixups(body); |
| ... | @@ -8401,7 +8408,7 @@ fn builtinCall( | ... | @@ -8401,7 +8408,7 @@ fn builtinCall( |
| 8401 | .node = gz.nodeIndexToRelative(node), | 8408 | .node = gz.nodeIndexToRelative(node), |
| 8402 | .operand = operand, | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 8412 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 8406 | .tag = .extended, | 8413 | .tag = .extended, |
| 8407 | .data = .{ .extended = .{ | 8414 | .data = .{ .extended = .{ |
| ... | @@ -8411,7 +8418,7 @@ fn builtinCall( | ... | @@ -8411,7 +8418,7 @@ fn builtinCall( |
| 8411 | } }, | 8418 | } }, |
| 8412 | }); | 8419 | }); |
| 8413 | gz.instructions.appendAssumeCapacity(new_index); | 8420 | gz.instructions.appendAssumeCapacity(new_index); |
| 8414 | const result = indexToRef(new_index); | 8421 | const result = new_index.toRef(); |
| 8415 | return rvalue(gz, ri, result, node); | 8422 | return rvalue(gz, ri, result, node); |
| 8416 | }, | 8423 | }, |
| 8417 | .panic => { | 8424 | .panic => { |
| ... | @@ -8993,7 +9000,7 @@ fn cImport( | ... | @@ -8993,7 +9000,7 @@ fn cImport( |
| 8993 | // block_scope unstacked now, can add new instructions to gz | 9000 | // block_scope unstacked now, can add new instructions to gz |
| 8994 | try gz.instructions.append(gpa, block_inst); | 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 | fn overflowArithmetic( | 9006 | fn overflowArithmetic( |
| ... | @@ -9056,8 +9063,8 @@ fn callExpr( | ... | @@ -9056,8 +9063,8 @@ fn callExpr( |
| 9056 | } | 9063 | } |
| 9057 | assert(node != 0); | 9064 | assert(node != 0); |
| 9058 | 9065 | ||
| 9059 | const call_index: Zir.Inst.Index = @intCast(astgen.instructions.len); | 9066 | const call_index: Zir.Inst.Index = @enumFromInt(astgen.instructions.len); |
| 9060 | const call_inst = Zir.indexToRef(call_index); | 9067 | const call_inst = call_index.toRef(); |
| 9061 | try gz.astgen.instructions.append(astgen.gpa, undefined); | 9068 | try gz.astgen.instructions.append(astgen.gpa, undefined); |
| 9062 | try gz.instructions.append(astgen.gpa, call_index); | 9069 | try gz.instructions.append(astgen.gpa, call_index); |
| 9063 | 9070 | ||
| ... | @@ -9104,7 +9111,7 @@ fn callExpr( | ... | @@ -9104,7 +9111,7 @@ fn callExpr( |
| 9104 | if (call.ast.params.len != 0) { | 9111 | if (call.ast.params.len != 0) { |
| 9105 | try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]); | 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 | .tag = .call, | 9115 | .tag = .call, |
| 9109 | .data = .{ .pl_node = .{ | 9116 | .data = .{ .pl_node = .{ |
| 9110 | .src_node = gz.nodeIndexToRelative(node), | 9117 | .src_node = gz.nodeIndexToRelative(node), |
| ... | @@ -9125,7 +9132,7 @@ fn callExpr( | ... | @@ -9125,7 +9132,7 @@ fn callExpr( |
| 9125 | if (call.ast.params.len != 0) { | 9132 | if (call.ast.params.len != 0) { |
| 9126 | try astgen.extra.appendSlice(astgen.gpa, astgen.scratch.items[scratch_top..]); | 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 | .tag = .field_call, | 9136 | .tag = .field_call, |
| 9130 | .data = .{ .pl_node = .{ | 9137 | .data = .{ .pl_node = .{ |
| 9131 | .src_node = gz.nodeIndexToRelative(node), | 9138 | .src_node = gz.nodeIndexToRelative(node), |
| ... | @@ -10062,10 +10069,10 @@ fn rvalueInner( | ... | @@ -10062,10 +10069,10 @@ fn rvalueInner( |
| 10062 | allow_coerce_pre_ref: bool, | 10069 | allow_coerce_pre_ref: bool, |
| 10063 | ) InnerError!Zir.Inst.Ref { | 10070 | ) InnerError!Zir.Inst.Ref { |
| 10064 | const result = r: { | 10071 | const result = r: { |
| 10065 | if (refToIndex(raw_result)) |result_index| { | 10072 | if (raw_result.toIndex()) |result_index| { |
| 10066 | const zir_tags = gz.astgen.instructions.items(.tag); | 10073 | const zir_tags = gz.astgen.instructions.items(.tag); |
| 10067 | const data = gz.astgen.instructions.items(.data)[result_index]; | 10074 | const data = gz.astgen.instructions.items(.data)[@intFromEnum(result_index)]; |
| 10068 | if (zir_tags[result_index].isAlwaysVoid(data)) { | 10075 | if (zir_tags[@intFromEnum(result_index)].isAlwaysVoid(data)) { |
| 10069 | break :r Zir.Inst.Ref.void_value; | 10076 | break :r Zir.Inst.Ref.void_value; |
| 10070 | } | 10077 | } |
| 10071 | } | 10078 | } |
| ... | @@ -10094,16 +10101,16 @@ fn rvalueInner( | ... | @@ -10094,16 +10101,16 @@ fn rvalueInner( |
| 10094 | const astgen = gz.astgen; | 10101 | const astgen = gz.astgen; |
| 10095 | const tree = astgen.tree; | 10102 | const tree = astgen.tree; |
| 10096 | const src_token = tree.firstToken(src_node); | 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 | return gz.addUnTok(.ref, coerced_result, src_token); | 10105 | return gz.addUnTok(.ref, coerced_result, src_token); |
| 10099 | const zir_tags = gz.astgen.instructions.items(.tag); | 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 | return gz.addUnTok(.ref, coerced_result, src_token); | 10108 | return gz.addUnTok(.ref, coerced_result, src_token); |
| 10102 | const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index); | 10109 | const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index); |
| 10103 | if (!gop.found_existing) { | 10110 | if (!gop.found_existing) { |
| 10104 | gop.value_ptr.* = try gz.makeUnTok(.ref, coerced_result, src_token); | 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 | .ty => |ty_inst| { | 10115 | .ty => |ty_inst| { |
| 10109 | // Quickly eliminate some common, unnecessary type coercion. | 10116 | // Quickly eliminate some common, unnecessary type coercion. |
| ... | @@ -10849,7 +10856,7 @@ const Scope = struct { | ... | @@ -10849,7 +10856,7 @@ const Scope = struct { |
| 10849 | parent: *Scope, | 10856 | parent: *Scope, |
| 10850 | index: u32, | 10857 | index: u32, |
| 10851 | len: u32, | 10858 | len: u32, |
| 10852 | remapped_err_code: Zir.Inst.Index = 0, | 10859 | remapped_err_code: Zir.Inst.OptionalIndex = .none, |
| 10853 | }; | 10860 | }; |
| 10854 | 10861 | ||
| 10855 | /// Represents a global scope that has any number of declarations in it. | 10862 | /// Represents a global scope that has any number of declarations in it. |
| ... | @@ -10919,8 +10926,8 @@ const GenZir = struct { | ... | @@ -10919,8 +10926,8 @@ const GenZir = struct { |
| 10919 | /// if use is strictly nested. This saves prior size of list for unstacking. | 10926 | /// if use is strictly nested. This saves prior size of list for unstacking. |
| 10920 | instructions_top: usize, | 10927 | instructions_top: usize, |
| 10921 | label: ?Label = null, | 10928 | label: ?Label = null, |
| 10922 | break_block: Zir.Inst.Index = 0, | 10929 | break_block: Zir.Inst.OptionalIndex = .none, |
| 10923 | continue_block: Zir.Inst.Index = 0, | 10930 | continue_block: Zir.Inst.OptionalIndex = .none, |
| 10924 | /// Only valid when setBreakResultInfo is called. | 10931 | /// Only valid when setBreakResultInfo is called. |
| 10925 | break_result_info: AstGen.ResultInfo = undefined, | 10932 | break_result_info: AstGen.ResultInfo = undefined, |
| 10926 | 10933 | ||
| ... | @@ -10995,14 +11002,14 @@ const GenZir = struct { | ... | @@ -10995,14 +11002,14 @@ const GenZir = struct { |
| 10995 | if (gz.isEmpty()) return false; | 11002 | if (gz.isEmpty()) return false; |
| 10996 | const tags = gz.astgen.instructions.items(.tag); | 11003 | const tags = gz.astgen.instructions.items(.tag); |
| 10997 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; | 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 | /// TODO all uses of this should be replaced with uses of `endsWithNoReturn`. | 11008 | /// TODO all uses of this should be replaced with uses of `endsWithNoReturn`. |
| 11002 | fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool { | 11009 | fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool { |
| 11003 | if (inst_ref == .unreachable_value) return true; | 11010 | if (inst_ref == .unreachable_value) return true; |
| 11004 | if (refToIndex(inst_ref)) |inst_index| { | 11011 | if (inst_ref.toIndex()) |inst_index| { |
| 11005 | return gz.astgen.instructions.items(.tag)[inst_index].isNoReturn(); | 11012 | return gz.astgen.instructions.items(.tag)[@intFromEnum(inst_index)].isNoReturn(); |
| 11006 | } | 11013 | } |
| 11007 | return false; | 11014 | return false; |
| 11008 | } | 11015 | } |
| ... | @@ -11053,7 +11060,7 @@ const GenZir = struct { | ... | @@ -11053,7 +11060,7 @@ const GenZir = struct { |
| 11053 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, | 11060 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, |
| 11054 | ); | 11061 | ); |
| 11055 | const zir_datas = astgen.instructions.items(.data); | 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 | Zir.Inst.Block{ .body_len = body_len }, | 11064 | Zir.Inst.Block{ .body_len = body_len }, |
| 11058 | ); | 11065 | ); |
| 11059 | astgen.appendBodyWithFixups(body); | 11066 | astgen.appendBodyWithFixups(body); |
| ... | @@ -11071,7 +11078,7 @@ const GenZir = struct { | ... | @@ -11071,7 +11078,7 @@ const GenZir = struct { |
| 11071 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, | 11078 | @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len, |
| 11072 | ); | 11079 | ); |
| 11073 | const zir_datas = astgen.instructions.items(.data); | 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 | Zir.Inst.Block{ .body_len = body_len }, | 11082 | Zir.Inst.Block{ .body_len = body_len }, |
| 11076 | ); | 11083 | ); |
| 11077 | astgen.appendBodyWithFixups(body); | 11084 | astgen.appendBodyWithFixups(body); |
| ... | @@ -11089,7 +11096,7 @@ const GenZir = struct { | ... | @@ -11089,7 +11096,7 @@ const GenZir = struct { |
| 11089 | @typeInfo(Zir.Inst.Try).Struct.fields.len + body_len, | 11096 | @typeInfo(Zir.Inst.Try).Struct.fields.len + body_len, |
| 11090 | ); | 11097 | ); |
| 11091 | const zir_datas = astgen.instructions.items(.data); | 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 | Zir.Inst.Try{ | 11100 | Zir.Inst.Try{ |
| 11094 | .operand = operand, | 11101 | .operand = operand, |
| 11095 | .body_len = body_len, | 11102 | .body_len = body_len, |
| ... | @@ -11139,7 +11146,7 @@ const GenZir = struct { | ... | @@ -11139,7 +11146,7 @@ const GenZir = struct { |
| 11139 | const astgen = gz.astgen; | 11146 | const astgen = gz.astgen; |
| 11140 | const gpa = astgen.gpa; | 11147 | const gpa = astgen.gpa; |
| 11141 | const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref; | 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 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); | 11151 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11145 | 11152 | ||
| ... | @@ -11235,9 +11242,9 @@ const GenZir = struct { | ... | @@ -11235,9 +11242,9 @@ const GenZir = struct { |
| 11235 | if (align_body.len != 0) { | 11242 | if (align_body.len != 0) { |
| 11236 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body)); | 11243 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body)); |
| 11237 | astgen.appendBodyWithFixups(align_body); | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11246 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11240 | new_index; | 11247 | @intFromEnum(new_index); |
| 11241 | } else if (args.align_ref != .none) { | 11248 | } else if (args.align_ref != .none) { |
| 11242 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref)); | 11249 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref)); |
| 11243 | } | 11250 | } |
| ... | @@ -11245,9 +11252,9 @@ const GenZir = struct { | ... | @@ -11245,9 +11252,9 @@ const GenZir = struct { |
| 11245 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body)); | 11252 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body)); |
| 11246 | astgen.appendBodyWithFixups(addrspace_body); | 11253 | astgen.appendBodyWithFixups(addrspace_body); |
| 11247 | const break_extra = | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11256 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11250 | new_index; | 11257 | @intFromEnum(new_index); |
| 11251 | } else if (args.addrspace_ref != .none) { | 11258 | } else if (args.addrspace_ref != .none) { |
| 11252 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref)); | 11259 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref)); |
| 11253 | } | 11260 | } |
| ... | @@ -11255,27 +11262,27 @@ const GenZir = struct { | ... | @@ -11255,27 +11262,27 @@ const GenZir = struct { |
| 11255 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body)); | 11262 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body)); |
| 11256 | astgen.appendBodyWithFixups(section_body); | 11263 | astgen.appendBodyWithFixups(section_body); |
| 11257 | const break_extra = | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11266 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11260 | new_index; | 11267 | @intFromEnum(new_index); |
| 11261 | } else if (args.section_ref != .none) { | 11268 | } else if (args.section_ref != .none) { |
| 11262 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref)); | 11269 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref)); |
| 11263 | } | 11270 | } |
| 11264 | if (cc_body.len != 0) { | 11271 | if (cc_body.len != 0) { |
| 11265 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body)); | 11272 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body)); |
| 11266 | astgen.appendBodyWithFixups(cc_body); | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11275 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11269 | new_index; | 11276 | @intFromEnum(new_index); |
| 11270 | } else if (args.cc_ref != .none) { | 11277 | } else if (args.cc_ref != .none) { |
| 11271 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref)); | 11278 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref)); |
| 11272 | } | 11279 | } |
| 11273 | if (ret_body.len != 0) { | 11280 | if (ret_body.len != 0) { |
| 11274 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body)); | 11281 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body)); |
| 11275 | astgen.appendBodyWithFixups(ret_body); | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11284 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11278 | new_index; | 11285 | @intFromEnum(new_index); |
| 11279 | } else if (ret_ref != .none) { | 11286 | } else if (ret_ref != .none) { |
| 11280 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); | 11287 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11281 | } | 11288 | } |
| ... | @@ -11307,7 +11314,7 @@ const GenZir = struct { | ... | @@ -11307,7 +11314,7 @@ const GenZir = struct { |
| 11307 | } }, | 11314 | } }, |
| 11308 | }); | 11315 | }); |
| 11309 | gz.instructions.appendAssumeCapacity(new_index); | 11316 | gz.instructions.appendAssumeCapacity(new_index); |
| 11310 | return indexToRef(new_index); | 11317 | return new_index.toRef(); |
| 11311 | } else { | 11318 | } else { |
| 11312 | try astgen.extra.ensureUnusedCapacity( | 11319 | try astgen.extra.ensureUnusedCapacity( |
| 11313 | gpa, | 11320 | gpa, |
| ... | @@ -11330,9 +11337,9 @@ const GenZir = struct { | ... | @@ -11330,9 +11337,9 @@ const GenZir = struct { |
| 11330 | if (ret_body.len != 0) { | 11337 | if (ret_body.len != 0) { |
| 11331 | astgen.appendBodyWithFixups(ret_body); | 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 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = | 11341 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11335 | new_index; | 11342 | @intFromEnum(new_index); |
| 11336 | } else if (ret_ref != .none) { | 11343 | } else if (ret_ref != .none) { |
| 11337 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); | 11344 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11338 | } | 11345 | } |
| ... | @@ -11358,7 +11365,7 @@ const GenZir = struct { | ... | @@ -11358,7 +11365,7 @@ const GenZir = struct { |
| 11358 | } }, | 11365 | } }, |
| 11359 | }); | 11366 | }); |
| 11360 | gz.instructions.appendAssumeCapacity(new_index); | 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,7 +11409,7 @@ const GenZir = struct { |
| 11402 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.init)); | 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 | astgen.instructions.appendAssumeCapacity(.{ | 11413 | astgen.instructions.appendAssumeCapacity(.{ |
| 11407 | .tag = .extended, | 11414 | .tag = .extended, |
| 11408 | .data = .{ .extended = .{ | 11415 | .data = .{ .extended = .{ |
| ... | @@ -11418,7 +11425,7 @@ const GenZir = struct { | ... | @@ -11418,7 +11425,7 @@ const GenZir = struct { |
| 11418 | } }, | 11425 | } }, |
| 11419 | }); | 11426 | }); |
| 11420 | gz.instructions.appendAssumeCapacity(new_index); | 11427 | gz.instructions.appendAssumeCapacity(new_index); |
| 11421 | return indexToRef(new_index); | 11428 | return new_index.toRef(); |
| 11422 | } | 11429 | } |
| 11423 | 11430 | ||
| 11424 | /// Note that this returns a `Zir.Inst.Index` not a ref. | 11431 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| ... | @@ -11433,7 +11440,7 @@ const GenZir = struct { | ... | @@ -11433,7 +11440,7 @@ const GenZir = struct { |
| 11433 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 11440 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11434 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 11444 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11438 | .tag = tag, | 11445 | .tag = tag, |
| 11439 | .data = .{ .bool_br = .{ | 11446 | .data = .{ .bool_br = .{ |
| ... | @@ -11459,7 +11466,7 @@ const GenZir = struct { | ... | @@ -11459,7 +11466,7 @@ const GenZir = struct { |
| 11459 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); | 11466 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11460 | try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len); | 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 | astgen.instructions.appendAssumeCapacity(.{ | 11470 | astgen.instructions.appendAssumeCapacity(.{ |
| 11464 | .tag = .int_big, | 11471 | .tag = .int_big, |
| 11465 | .data = .{ .str = .{ | 11472 | .data = .{ .str = .{ |
| ... | @@ -11469,7 +11476,7 @@ const GenZir = struct { | ... | @@ -11469,7 +11476,7 @@ const GenZir = struct { |
| 11469 | }); | 11476 | }); |
| 11470 | gz.instructions.appendAssumeCapacity(new_index); | 11477 | gz.instructions.appendAssumeCapacity(new_index); |
| 11471 | astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs)); | 11478 | astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs)); |
| 11472 | return indexToRef(new_index); | 11479 | return new_index.toRef(); |
| 11473 | } | 11480 | } |
| 11474 | 11481 | ||
| 11475 | fn addFloat(gz: *GenZir, number: f64) !Zir.Inst.Ref { | 11482 | fn addFloat(gz: *GenZir, number: f64) !Zir.Inst.Ref { |
| ... | @@ -11504,7 +11511,7 @@ const GenZir = struct { | ... | @@ -11504,7 +11511,7 @@ const GenZir = struct { |
| 11504 | src_node: Ast.Node.Index, | 11511 | src_node: Ast.Node.Index, |
| 11505 | ) !Zir.Inst.Index { | 11512 | ) !Zir.Inst.Index { |
| 11506 | assert(operand != .none); | 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 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ | 11515 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 11509 | .tag = tag, | 11516 | .tag = tag, |
| 11510 | .data = .{ .un_node = .{ | 11517 | .data = .{ .un_node = .{ |
| ... | @@ -11527,7 +11534,7 @@ const GenZir = struct { | ... | @@ -11527,7 +11534,7 @@ const GenZir = struct { |
| 11527 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 11534 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11528 | 11535 | ||
| 11529 | const payload_index = try gz.astgen.addExtra(extra); | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 11538 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11532 | .tag = tag, | 11539 | .tag = tag, |
| 11533 | .data = .{ .pl_node = .{ | 11540 | .data = .{ .pl_node = .{ |
| ... | @@ -11536,7 +11543,7 @@ const GenZir = struct { | ... | @@ -11536,7 +11543,7 @@ const GenZir = struct { |
| 11536 | } }, | 11543 | } }, |
| 11537 | }); | 11544 | }); |
| 11538 | gz.instructions.appendAssumeCapacity(new_index); | 11545 | gz.instructions.appendAssumeCapacity(new_index); |
| 11539 | return indexToRef(new_index); | 11546 | return new_index.toRef(); |
| 11540 | } | 11547 | } |
| 11541 | 11548 | ||
| 11542 | fn addPlNodePayloadIndex( | 11549 | fn addPlNodePayloadIndex( |
| ... | @@ -11584,7 +11591,7 @@ const GenZir = struct { | ... | @@ -11584,7 +11591,7 @@ const GenZir = struct { |
| 11584 | gz.astgen.appendBodyWithFixups(param_body); | 11591 | gz.astgen.appendBodyWithFixups(param_body); |
| 11585 | param_gz.unstack(); | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 11595 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11589 | .tag = tag, | 11596 | .tag = tag, |
| 11590 | .data = .{ .pl_tok = .{ | 11597 | .data = .{ .pl_tok = .{ |
| ... | @@ -11612,7 +11619,7 @@ const GenZir = struct { | ... | @@ -11612,7 +11619,7 @@ const GenZir = struct { |
| 11612 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 11619 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11613 | 11620 | ||
| 11614 | const payload_index = try gz.astgen.addExtra(extra); | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 11623 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11617 | .tag = .extended, | 11624 | .tag = .extended, |
| 11618 | .data = .{ .extended = .{ | 11625 | .data = .{ .extended = .{ |
| ... | @@ -11622,7 +11629,7 @@ const GenZir = struct { | ... | @@ -11622,7 +11629,7 @@ const GenZir = struct { |
| 11622 | } }, | 11629 | } }, |
| 11623 | }); | 11630 | }); |
| 11624 | gz.instructions.appendAssumeCapacity(new_index); | 11631 | gz.instructions.appendAssumeCapacity(new_index); |
| 11625 | return indexToRef(new_index); | 11632 | return new_index.toRef(); |
| 11626 | } | 11633 | } |
| 11627 | 11634 | ||
| 11628 | fn addExtendedMultiOp( | 11635 | fn addExtendedMultiOp( |
| ... | @@ -11644,7 +11651,7 @@ const GenZir = struct { | ... | @@ -11644,7 +11651,7 @@ const GenZir = struct { |
| 11644 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{ | 11651 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{ |
| 11645 | .src_node = gz.nodeIndexToRelative(node), | 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 | astgen.instructions.appendAssumeCapacity(.{ | 11655 | astgen.instructions.appendAssumeCapacity(.{ |
| 11649 | .tag = .extended, | 11656 | .tag = .extended, |
| 11650 | .data = .{ .extended = .{ | 11657 | .data = .{ .extended = .{ |
| ... | @@ -11655,7 +11662,7 @@ const GenZir = struct { | ... | @@ -11655,7 +11662,7 @@ const GenZir = struct { |
| 11655 | }); | 11662 | }); |
| 11656 | gz.instructions.appendAssumeCapacity(new_index); | 11663 | gz.instructions.appendAssumeCapacity(new_index); |
| 11657 | astgen.appendRefsAssumeCapacity(operands); | 11664 | astgen.appendRefsAssumeCapacity(operands); |
| 11658 | return indexToRef(new_index); | 11665 | return new_index.toRef(); |
| 11659 | } | 11666 | } |
| 11660 | 11667 | ||
| 11661 | fn addExtendedMultiOpPayloadIndex( | 11668 | fn addExtendedMultiOpPayloadIndex( |
| ... | @@ -11669,7 +11676,7 @@ const GenZir = struct { | ... | @@ -11669,7 +11676,7 @@ const GenZir = struct { |
| 11669 | 11676 | ||
| 11670 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 11677 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11671 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); | 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 | astgen.instructions.appendAssumeCapacity(.{ | 11680 | astgen.instructions.appendAssumeCapacity(.{ |
| 11674 | .tag = .extended, | 11681 | .tag = .extended, |
| 11675 | .data = .{ .extended = .{ | 11682 | .data = .{ .extended = .{ |
| ... | @@ -11679,7 +11686,7 @@ const GenZir = struct { | ... | @@ -11679,7 +11686,7 @@ const GenZir = struct { |
| 11679 | } }, | 11686 | } }, |
| 11680 | }); | 11687 | }); |
| 11681 | gz.instructions.appendAssumeCapacity(new_index); | 11688 | gz.instructions.appendAssumeCapacity(new_index); |
| 11682 | return indexToRef(new_index); | 11689 | return new_index.toRef(); |
| 11683 | } | 11690 | } |
| 11684 | 11691 | ||
| 11685 | fn addUnTok( | 11692 | fn addUnTok( |
| ... | @@ -11707,7 +11714,7 @@ const GenZir = struct { | ... | @@ -11707,7 +11714,7 @@ const GenZir = struct { |
| 11707 | abs_tok_index: Ast.TokenIndex, | 11714 | abs_tok_index: Ast.TokenIndex, |
| 11708 | ) !Zir.Inst.Index { | 11715 | ) !Zir.Inst.Index { |
| 11709 | const astgen = gz.astgen; | 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 | assert(operand != .none); | 11718 | assert(operand != .none); |
| 11712 | try astgen.instructions.append(astgen.gpa, .{ | 11719 | try astgen.instructions.append(astgen.gpa, .{ |
| 11713 | .tag = tag, | 11720 | .tag = tag, |
| ... | @@ -11771,7 +11778,7 @@ const GenZir = struct { | ... | @@ -11771,7 +11778,7 @@ const GenZir = struct { |
| 11771 | .data = .{ .restore_err_ret_index = .{ | 11778 | .data = .{ .restore_err_ret_index = .{ |
| 11772 | .block = switch (bt) { | 11779 | .block = switch (bt) { |
| 11773 | .ret => .none, | 11780 | .ret => .none, |
| 11774 | .block => |b| Zir.indexToRef(b), | 11781 | .block => |b| b.toRef(), |
| 11775 | }, | 11782 | }, |
| 11776 | .operand = if (cond == .if_non_error) cond.if_non_error else .none, | 11783 | .operand = if (cond == .if_non_error) cond.if_non_error else .none, |
| 11777 | } }, | 11784 | } }, |
| ... | @@ -11837,7 +11844,7 @@ const GenZir = struct { | ... | @@ -11837,7 +11844,7 @@ const GenZir = struct { |
| 11837 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 11844 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11838 | try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).Struct.fields.len); | 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 | gz.astgen.instructions.appendAssumeCapacity(.{ | 11848 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11842 | .tag = tag, | 11849 | .tag = tag, |
| 11843 | .data = .{ .@"break" = .{ | 11850 | .data = .{ .@"break" = .{ |
| ... | @@ -11978,7 +11985,7 @@ const GenZir = struct { | ... | @@ -11978,7 +11985,7 @@ const GenZir = struct { |
| 11978 | const is_comptime: u4 = @intFromBool(args.is_comptime); | 11985 | const is_comptime: u4 = @intFromBool(args.is_comptime); |
| 11979 | const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3); | 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 | astgen.instructions.appendAssumeCapacity(.{ | 11989 | astgen.instructions.appendAssumeCapacity(.{ |
| 11983 | .tag = .extended, | 11990 | .tag = .extended, |
| 11984 | .data = .{ .extended = .{ | 11991 | .data = .{ .extended = .{ |
| ... | @@ -11988,7 +11995,7 @@ const GenZir = struct { | ... | @@ -11988,7 +11995,7 @@ const GenZir = struct { |
| 11988 | } }, | 11995 | } }, |
| 11989 | }); | 11996 | }); |
| 11990 | gz.instructions.appendAssumeCapacity(new_index); | 11997 | gz.instructions.appendAssumeCapacity(new_index); |
| 11991 | return indexToRef(new_index); | 11998 | return new_index.toRef(); |
| 11992 | } | 11999 | } |
| 11993 | 12000 | ||
| 11994 | fn addAsm( | 12001 | fn addAsm( |
| ... | @@ -12037,7 +12044,7 @@ const GenZir = struct { | ... | @@ -12037,7 +12044,7 @@ const GenZir = struct { |
| 12037 | @as(u16, @intCast(args.clobbers.len << 10)) | | 12044 | @as(u16, @intCast(args.clobbers.len << 10)) | |
| 12038 | (@as(u16, @intFromBool(args.is_volatile)) << 15); | 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 | astgen.instructions.appendAssumeCapacity(.{ | 12048 | astgen.instructions.appendAssumeCapacity(.{ |
| 12042 | .tag = .extended, | 12049 | .tag = .extended, |
| 12043 | .data = .{ .extended = .{ | 12050 | .data = .{ .extended = .{ |
| ... | @@ -12047,14 +12054,14 @@ const GenZir = struct { | ... | @@ -12047,14 +12054,14 @@ const GenZir = struct { |
| 12047 | } }, | 12054 | } }, |
| 12048 | }); | 12055 | }); |
| 12049 | gz.instructions.appendAssumeCapacity(new_index); | 12056 | gz.instructions.appendAssumeCapacity(new_index); |
| 12050 | return indexToRef(new_index); | 12057 | return new_index.toRef(); |
| 12051 | } | 12058 | } |
| 12052 | 12059 | ||
| 12053 | /// Note that this returns a `Zir.Inst.Index` not a ref. | 12060 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| 12054 | /// Does *not* append the block instruction to the scope. | 12061 | /// Does *not* append the block instruction to the scope. |
| 12055 | /// Leaves the `payload_index` field undefined. | 12062 | /// Leaves the `payload_index` field undefined. |
| 12056 | fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { | 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 | const gpa = gz.astgen.gpa; | 12065 | const gpa = gz.astgen.gpa; |
| 12059 | try gz.astgen.instructions.append(gpa, .{ | 12066 | try gz.astgen.instructions.append(gpa, .{ |
| 12060 | .tag = tag, | 12067 | .tag = tag, |
| ... | @@ -12071,7 +12078,7 @@ const GenZir = struct { | ... | @@ -12071,7 +12078,7 @@ const GenZir = struct { |
| 12071 | fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { | 12078 | fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { |
| 12072 | const gpa = gz.astgen.gpa; | 12079 | const gpa = gz.astgen.gpa; |
| 12073 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 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 | try gz.astgen.instructions.append(gpa, .{ | 12082 | try gz.astgen.instructions.append(gpa, .{ |
| 12076 | .tag = tag, | 12083 | .tag = tag, |
| 12077 | .data = .{ .pl_node = .{ | 12084 | .data = .{ .pl_node = .{ |
| ... | @@ -12119,7 +12126,7 @@ const GenZir = struct { | ... | @@ -12119,7 +12126,7 @@ const GenZir = struct { |
| 12119 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.backing_int_ref)); | 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 | .tag = .extended, | 12130 | .tag = .extended, |
| 12124 | .data = .{ .extended = .{ | 12131 | .data = .{ .extended = .{ |
| 12125 | .opcode = .struct_decl, | 12132 | .opcode = .struct_decl, |
| ... | @@ -12174,7 +12181,7 @@ const GenZir = struct { | ... | @@ -12174,7 +12181,7 @@ const GenZir = struct { |
| 12174 | if (args.decls_len != 0) { | 12181 | if (args.decls_len != 0) { |
| 12175 | astgen.extra.appendAssumeCapacity(args.decls_len); | 12182 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12176 | } | 12183 | } |
| 12177 | astgen.instructions.set(inst, .{ | 12184 | astgen.instructions.set(@intFromEnum(inst), .{ |
| 12178 | .tag = .extended, | 12185 | .tag = .extended, |
| 12179 | .data = .{ .extended = .{ | 12186 | .data = .{ .extended = .{ |
| 12180 | .opcode = .union_decl, | 12187 | .opcode = .union_decl, |
| ... | @@ -12224,7 +12231,7 @@ const GenZir = struct { | ... | @@ -12224,7 +12231,7 @@ const GenZir = struct { |
| 12224 | if (args.decls_len != 0) { | 12231 | if (args.decls_len != 0) { |
| 12225 | astgen.extra.appendAssumeCapacity(args.decls_len); | 12232 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12226 | } | 12233 | } |
| 12227 | astgen.instructions.set(inst, .{ | 12234 | astgen.instructions.set(@intFromEnum(inst), .{ |
| 12228 | .tag = .extended, | 12235 | .tag = .extended, |
| 12229 | .data = .{ .extended = .{ | 12236 | .data = .{ .extended = .{ |
| 12230 | .opcode = .enum_decl, | 12237 | .opcode = .enum_decl, |
| ... | @@ -12259,7 +12266,7 @@ const GenZir = struct { | ... | @@ -12259,7 +12266,7 @@ const GenZir = struct { |
| 12259 | if (args.decls_len != 0) { | 12266 | if (args.decls_len != 0) { |
| 12260 | astgen.extra.appendAssumeCapacity(args.decls_len); | 12267 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| 12261 | } | 12268 | } |
| 12262 | astgen.instructions.set(inst, .{ | 12269 | astgen.instructions.set(@intFromEnum(inst), .{ |
| 12263 | .tag = .extended, | 12270 | .tag = .extended, |
| 12264 | .data = .{ .extended = .{ | 12271 | .data = .{ .extended = .{ |
| 12265 | .opcode = .opaque_decl, | 12272 | .opcode = .opaque_decl, |
| ... | @@ -12274,7 +12281,7 @@ const GenZir = struct { | ... | @@ -12274,7 +12281,7 @@ const GenZir = struct { |
| 12274 | } | 12281 | } |
| 12275 | 12282 | ||
| 12276 | fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref { | 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 | fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index { | 12287 | fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index { |
| ... | @@ -12282,7 +12289,7 @@ const GenZir = struct { | ... | @@ -12282,7 +12289,7 @@ const GenZir = struct { |
| 12282 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 12289 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12283 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 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 | gz.astgen.instructions.appendAssumeCapacity(inst); | 12293 | gz.astgen.instructions.appendAssumeCapacity(inst); |
| 12287 | gz.instructions.appendAssumeCapacity(new_index); | 12294 | gz.instructions.appendAssumeCapacity(new_index); |
| 12288 | return new_index; | 12295 | return new_index; |
| ... | @@ -12293,7 +12300,7 @@ const GenZir = struct { | ... | @@ -12293,7 +12300,7 @@ const GenZir = struct { |
| 12293 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | 12300 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12294 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | 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 | gz.astgen.instructions.len += 1; | 12304 | gz.astgen.instructions.len += 1; |
| 12298 | gz.instructions.appendAssumeCapacity(new_index); | 12305 | gz.instructions.appendAssumeCapacity(new_index); |
| 12299 | return new_index; | 12306 | return new_index; |
| ... | @@ -12340,12 +12347,12 @@ const GenZir = struct { | ... | @@ -12340,12 +12347,12 @@ const GenZir = struct { |
| 12340 | const tags = gz.astgen.instructions.items(.tag); | 12347 | const tags = gz.astgen.instructions.items(.tag); |
| 12341 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; | 12348 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; |
| 12342 | // remove dbg_block_begin immediately followed by dbg_block_end | 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 | _ = gz.instructions.pop(); | 12351 | _ = gz.instructions.pop(); |
| 12345 | return; | 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 | try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined }); | 12356 | try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined }); |
| 12350 | try gz.instructions.append(gpa, new_index); | 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,9 +12629,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast. |
| 12622 | } | 12629 | } |
| 12623 | 12630 | ||
| 12624 | fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { | 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 | const zir_tags = astgen.instructions.items(.tag); | 12633 | const zir_tags = astgen.instructions.items(.tag); |
| 12627 | return switch (zir_tags[inst]) { | 12634 | return switch (zir_tags[@intFromEnum(inst)]) { |
| 12628 | .alloc_inferred, | 12635 | .alloc_inferred, |
| 12629 | .alloc_inferred_mut, | 12636 | .alloc_inferred_mut, |
| 12630 | .alloc_inferred_comptime, | 12637 | .alloc_inferred_comptime, |
| ... | @@ -12633,8 +12640,8 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { | ... | @@ -12633,8 +12640,8 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { |
| 12633 | 12640 | ||
| 12634 | .extended => { | 12641 | .extended => { |
| 12635 | const zir_data = astgen.instructions.items(.data); | 12642 | const zir_data = astgen.instructions.items(.data); |
| 12636 | if (zir_data[inst].extended.opcode != .alloc) return false; | 12643 | if (zir_data[@intFromEnum(inst)].extended.opcode != .alloc) return false; |
| 12637 | const small: Zir.Inst.AllocExtended.Small = @bitCast(zir_data[inst].extended.small); | 12644 | const small: Zir.Inst.AllocExtended.Small = @bitCast(zir_data[@intFromEnum(inst)].extended.small); |
| 12638 | return !small.has_type; | 12645 | return !small.has_type; |
| 12639 | }, | 12646 | }, |
| 12640 | 12647 | ||
| ... | @@ -12663,7 +12670,7 @@ fn appendPossiblyRefdBodyInst( | ... | @@ -12663,7 +12670,7 @@ fn appendPossiblyRefdBodyInst( |
| 12663 | list: *std.ArrayListUnmanaged(u32), | 12670 | list: *std.ArrayListUnmanaged(u32), |
| 12664 | body_inst: Zir.Inst.Index, | 12671 | body_inst: Zir.Inst.Index, |
| 12665 | ) void { | 12672 | ) void { |
| 12666 | list.appendAssumeCapacity(body_inst); | 12673 | list.appendAssumeCapacity(@intFromEnum(body_inst)); |
| 12667 | const kv = astgen.ref_table.fetchRemove(body_inst) orelse return; | 12674 | const kv = astgen.ref_table.fetchRemove(body_inst) orelse return; |
| 12668 | const ref_inst = kv.value; | 12675 | const ref_inst = kv.value; |
| 12669 | return appendPossiblyRefdBodyInst(astgen, list, ref_inst); | 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,7 +333,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void { |
| 333 | file, | 333 | file, |
| 334 | &root_scope, | 334 | &root_scope, |
| 335 | .{}, | 335 | .{}, |
| 336 | Zir.main_struct_inst, | 336 | .main_struct_inst, |
| 337 | false, | 337 | false, |
| 338 | null, | 338 | null, |
| 339 | ); | 339 | ); |
| ... | @@ -464,14 +464,14 @@ const Scope = struct { | ... | @@ -464,14 +464,14 @@ const Scope = struct { |
| 464 | /// Another reason is that in some places we use the pointer to uniquely | 464 | /// Another reason is that in some places we use the pointer to uniquely |
| 465 | /// refer to a decl, as we wait for it to be analyzed. This means that | 465 | /// refer to a decl, as we wait for it to be analyzed. This means that |
| 466 | /// those pointers must stay stable. | 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 | var cur: ?*const Scope = &self; | 468 | var cur: ?*const Scope = &self; |
| 469 | return while (cur) |s| : (cur = s.parent) { | 469 | return while (cur) |s| : (cur = s.parent) { |
| 470 | break s.map.get(string_table_idx) orelse continue; | 470 | break s.map.get(string_table_idx) orelse continue; |
| 471 | } else { | 471 | } else { |
| 472 | printWithContext( | 472 | printWithOptionalContext( |
| 473 | file, | 473 | file, |
| 474 | inst_index, | 474 | inst, |
| 475 | "Could not find `{s}`\n\n", | 475 | "Could not find `{s}`\n\n", |
| 476 | .{file.zir.nullTerminatedString(string_table_idx)}, | 476 | .{file.zir.nullTerminatedString(string_table_idx)}, |
| 477 | ); | 477 | ); |
| ... | @@ -937,7 +937,7 @@ const AutodocErrors = error{ | ... | @@ -937,7 +937,7 @@ const AutodocErrors = error{ |
| 937 | /// This type is used to keep track of dangerous instruction | 937 | /// This type is used to keep track of dangerous instruction |
| 938 | /// numbers that we definitely don't want to recurse into. | 938 | /// numbers that we definitely don't want to recurse into. |
| 939 | const CallContext = struct { | 939 | const CallContext = struct { |
| 940 | inst: usize, | 940 | inst: Zir.Inst.Index, |
| 941 | prev: ?*const CallContext, | 941 | prev: ?*const CallContext, |
| 942 | }; | 942 | }; |
| 943 | 943 | ||
| ... | @@ -954,14 +954,14 @@ fn walkInstruction( | ... | @@ -954,14 +954,14 @@ fn walkInstruction( |
| 954 | file: *File, | 954 | file: *File, |
| 955 | parent_scope: *Scope, | 955 | parent_scope: *Scope, |
| 956 | parent_src: SrcLocInfo, | 956 | parent_src: SrcLocInfo, |
| 957 | inst_index: usize, | 957 | inst: Zir.Inst.Index, |
| 958 | need_type: bool, // true if the caller needs us to provide also a typeRef | 958 | need_type: bool, // true if the caller needs us to provide also a typeRef |
| 959 | call_ctx: ?*const CallContext, | 959 | call_ctx: ?*const CallContext, |
| 960 | ) AutodocErrors!DocData.WalkResult { | 960 | ) AutodocErrors!DocData.WalkResult { |
| 961 | const tags = file.zir.instructions.items(.tag); | 961 | const tags = file.zir.instructions.items(.tag); |
| 962 | const data = file.zir.instructions.items(.data); | 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 | // TODO: better handling here | 965 | // TODO: better handling here |
| 966 | return .{ .expr = .{ .comptimeExpr = 0 } }; | 966 | return .{ .expr = .{ .comptimeExpr = 0 } }; |
| 967 | } | 967 | } |
| ... | @@ -969,18 +969,18 @@ fn walkInstruction( | ... | @@ -969,18 +969,18 @@ fn walkInstruction( |
| 969 | // We assume that the topmost ast_node entry corresponds to our decl | 969 | // We assume that the topmost ast_node entry corresponds to our decl |
| 970 | const self_ast_node_index = self.ast_nodes.items.len - 1; | 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 | else => { | 973 | else => { |
| 974 | printWithContext( | 974 | printWithContext( |
| 975 | file, | 975 | file, |
| 976 | inst_index, | 976 | inst, |
| 977 | "TODO: implement `{s}` for walkInstruction\n\n", | 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 | .import => { | 982 | .import => { |
| 983 | const str_tok = data[inst_index].str_tok; | 983 | const str_tok = data[@intFromEnum(inst)].str_tok; |
| 984 | var path = str_tok.get(file.zir); | 984 | var path = str_tok.get(file.zir); |
| 985 | 985 | ||
| 986 | // importFile cannot error out since all files | 986 | // importFile cannot error out since all files |
| ... | @@ -1048,7 +1048,7 @@ fn walkInstruction( | ... | @@ -1048,7 +1048,7 @@ fn walkInstruction( |
| 1048 | new_file, | 1048 | new_file, |
| 1049 | &root_scope, | 1049 | &root_scope, |
| 1050 | .{}, | 1050 | .{}, |
| 1051 | Zir.main_struct_inst, | 1051 | .main_struct_inst, |
| 1052 | false, | 1052 | false, |
| 1053 | call_ctx, | 1053 | call_ctx, |
| 1054 | ); | 1054 | ); |
| ... | @@ -1080,7 +1080,7 @@ fn walkInstruction( | ... | @@ -1080,7 +1080,7 @@ fn walkInstruction( |
| 1080 | new_file.file, | 1080 | new_file.file, |
| 1081 | &new_scope, | 1081 | &new_scope, |
| 1082 | .{}, | 1082 | .{}, |
| 1083 | Zir.main_struct_inst, | 1083 | .main_struct_inst, |
| 1084 | need_type, | 1084 | need_type, |
| 1085 | call_ctx, | 1085 | call_ctx, |
| 1086 | ); | 1086 | ); |
| ... | @@ -1092,7 +1092,7 @@ fn walkInstruction( | ... | @@ -1092,7 +1092,7 @@ fn walkInstruction( |
| 1092 | }; | 1092 | }; |
| 1093 | }, | 1093 | }, |
| 1094 | .ret_node => { | 1094 | .ret_node => { |
| 1095 | const un_node = data[inst_index].un_node; | 1095 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1096 | return self.walkRef( | 1096 | return self.walkRef( |
| 1097 | file, | 1097 | file, |
| 1098 | parent_scope, | 1098 | parent_scope, |
| ... | @@ -1103,9 +1103,9 @@ fn walkInstruction( | ... | @@ -1103,9 +1103,9 @@ fn walkInstruction( |
| 1103 | ); | 1103 | ); |
| 1104 | }, | 1104 | }, |
| 1105 | .ret_load => { | 1105 | .ret_load => { |
| 1106 | const un_node = data[inst_index].un_node; | 1106 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1107 | const res_ptr_ref = un_node.operand; | 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 | // TODO: this instruction doesn't let us know trivially if there's | 1109 | // TODO: this instruction doesn't let us know trivially if there's |
| 1110 | // branching involved or not. For now here's the strat: | 1110 | // branching involved or not. For now here's the strat: |
| 1111 | // We search backwarts until `ret_ptr` for `store_node`, | 1111 | // We search backwarts until `ret_ptr` for `store_node`, |
| ... | @@ -1113,7 +1113,7 @@ fn walkInstruction( | ... | @@ -1113,7 +1113,7 @@ fn walkInstruction( |
| 1113 | // than one, then it means that there's branching involved. | 1113 | // than one, then it means that there's branching involved. |
| 1114 | // Maybe. | 1114 | // Maybe. |
| 1115 | 1115 | ||
| 1116 | var i = inst_index - 1; | 1116 | var i = @intFromEnum(inst) - 1; |
| 1117 | var result_ref: ?Ref = null; | 1117 | var result_ref: ?Ref = null; |
| 1118 | while (i > res_ptr_inst) : (i -= 1) { | 1118 | while (i > res_ptr_inst) : (i -= 1) { |
| 1119 | if (tags[i] == .store_node) { | 1119 | if (tags[i] == .store_node) { |
| ... | @@ -1146,7 +1146,7 @@ fn walkInstruction( | ... | @@ -1146,7 +1146,7 @@ fn walkInstruction( |
| 1146 | }; | 1146 | }; |
| 1147 | }, | 1147 | }, |
| 1148 | .closure_get => { | 1148 | .closure_get => { |
| 1149 | const inst_node = data[inst_index].inst_node; | 1149 | const inst_node = data[@intFromEnum(inst)].inst_node; |
| 1150 | return try self.walkInstruction( | 1150 | return try self.walkInstruction( |
| 1151 | file, | 1151 | file, |
| 1152 | parent_scope, | 1152 | parent_scope, |
| ... | @@ -1157,7 +1157,7 @@ fn walkInstruction( | ... | @@ -1157,7 +1157,7 @@ fn walkInstruction( |
| 1157 | ); | 1157 | ); |
| 1158 | }, | 1158 | }, |
| 1159 | .closure_capture => { | 1159 | .closure_capture => { |
| 1160 | const un_tok = data[inst_index].un_tok; | 1160 | const un_tok = data[@intFromEnum(inst)].un_tok; |
| 1161 | return try self.walkRef( | 1161 | return try self.walkRef( |
| 1162 | file, | 1162 | file, |
| 1163 | parent_scope, | 1163 | parent_scope, |
| ... | @@ -1168,7 +1168,7 @@ fn walkInstruction( | ... | @@ -1168,7 +1168,7 @@ fn walkInstruction( |
| 1168 | ); | 1168 | ); |
| 1169 | }, | 1169 | }, |
| 1170 | .str => { | 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 | const tRef: ?DocData.Expr = if (!need_type) null else blk: { | 1173 | const tRef: ?DocData.Expr = if (!need_type) null else blk: { |
| 1174 | const arrTypeId = self.types.items.len; | 1174 | const arrTypeId = self.types.items.len; |
| ... | @@ -1204,7 +1204,7 @@ fn walkInstruction( | ... | @@ -1204,7 +1204,7 @@ fn walkInstruction( |
| 1204 | }; | 1204 | }; |
| 1205 | }, | 1205 | }, |
| 1206 | .compile_error => { | 1206 | .compile_error => { |
| 1207 | const un_node = data[inst_index].un_node; | 1207 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1208 | 1208 | ||
| 1209 | var operand: DocData.WalkResult = try self.walkRef( | 1209 | var operand: DocData.WalkResult = try self.walkRef( |
| 1210 | file, | 1210 | file, |
| ... | @@ -1223,7 +1223,7 @@ fn walkInstruction( | ... | @@ -1223,7 +1223,7 @@ fn walkInstruction( |
| 1223 | }; | 1223 | }; |
| 1224 | }, | 1224 | }, |
| 1225 | .enum_literal => { | 1225 | .enum_literal => { |
| 1226 | const str_tok = data[inst_index].str_tok; | 1226 | const str_tok = data[@intFromEnum(inst)].str_tok; |
| 1227 | const literal = file.zir.nullTerminatedString(str_tok.start); | 1227 | const literal = file.zir.nullTerminatedString(str_tok.start); |
| 1228 | const type_index = self.types.items.len; | 1228 | const type_index = self.types.items.len; |
| 1229 | try self.types.append(self.arena, .{ | 1229 | try self.types.append(self.arena, .{ |
| ... | @@ -1236,7 +1236,7 @@ fn walkInstruction( | ... | @@ -1236,7 +1236,7 @@ fn walkInstruction( |
| 1236 | }; | 1236 | }; |
| 1237 | }, | 1237 | }, |
| 1238 | .int => { | 1238 | .int => { |
| 1239 | const int = data[inst_index].int; | 1239 | const int = data[@intFromEnum(inst)].int; |
| 1240 | return DocData.WalkResult{ | 1240 | return DocData.WalkResult{ |
| 1241 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_int_type) }, | 1241 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_int_type) }, |
| 1242 | .expr = .{ .int = .{ .value = int } }, | 1242 | .expr = .{ .int = .{ .value = int } }, |
| ... | @@ -1244,7 +1244,7 @@ fn walkInstruction( | ... | @@ -1244,7 +1244,7 @@ fn walkInstruction( |
| 1244 | }, | 1244 | }, |
| 1245 | .int_big => { | 1245 | .int_big => { |
| 1246 | // @check | 1246 | // @check |
| 1247 | const str = data[inst_index].str; //.get(file.zir); | 1247 | const str = data[@intFromEnum(inst)].str; //.get(file.zir); |
| 1248 | const byte_count = str.len * @sizeOf(std.math.big.Limb); | 1248 | const byte_count = str.len * @sizeOf(std.math.big.Limb); |
| 1249 | const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; | 1249 | const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count]; |
| 1250 | 1250 | ||
| ... | @@ -1271,7 +1271,7 @@ fn walkInstruction( | ... | @@ -1271,7 +1271,7 @@ fn walkInstruction( |
| 1271 | }, | 1271 | }, |
| 1272 | 1272 | ||
| 1273 | .slice_start => { | 1273 | .slice_start => { |
| 1274 | const pl_node = data[inst_index].pl_node; | 1274 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1275 | const extra = file.zir.extraData(Zir.Inst.SliceStart, pl_node.payload_index); | 1275 | const extra = file.zir.extraData(Zir.Inst.SliceStart, pl_node.payload_index); |
| 1276 | 1276 | ||
| 1277 | const slice_index = self.exprs.items.len; | 1277 | const slice_index = self.exprs.items.len; |
| ... | @@ -1311,7 +1311,7 @@ fn walkInstruction( | ... | @@ -1311,7 +1311,7 @@ fn walkInstruction( |
| 1311 | }; | 1311 | }; |
| 1312 | }, | 1312 | }, |
| 1313 | .slice_end => { | 1313 | .slice_end => { |
| 1314 | const pl_node = data[inst_index].pl_node; | 1314 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1315 | const extra = file.zir.extraData(Zir.Inst.SliceEnd, pl_node.payload_index); | 1315 | const extra = file.zir.extraData(Zir.Inst.SliceEnd, pl_node.payload_index); |
| 1316 | 1316 | ||
| 1317 | const slice_index = self.exprs.items.len; | 1317 | const slice_index = self.exprs.items.len; |
| ... | @@ -1361,7 +1361,7 @@ fn walkInstruction( | ... | @@ -1361,7 +1361,7 @@ fn walkInstruction( |
| 1361 | }; | 1361 | }; |
| 1362 | }, | 1362 | }, |
| 1363 | .slice_sentinel => { | 1363 | .slice_sentinel => { |
| 1364 | const pl_node = data[inst_index].pl_node; | 1364 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1365 | const extra = file.zir.extraData(Zir.Inst.SliceSentinel, pl_node.payload_index); | 1365 | const extra = file.zir.extraData(Zir.Inst.SliceSentinel, pl_node.payload_index); |
| 1366 | 1366 | ||
| 1367 | const slice_index = self.exprs.items.len; | 1367 | const slice_index = self.exprs.items.len; |
| ... | @@ -1426,7 +1426,7 @@ fn walkInstruction( | ... | @@ -1426,7 +1426,7 @@ fn walkInstruction( |
| 1426 | }; | 1426 | }; |
| 1427 | }, | 1427 | }, |
| 1428 | .slice_length => { | 1428 | .slice_length => { |
| 1429 | const pl_node = data[inst_index].pl_node; | 1429 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1430 | const extra = file.zir.extraData(Zir.Inst.SliceLength, pl_node.payload_index); | 1430 | const extra = file.zir.extraData(Zir.Inst.SliceLength, pl_node.payload_index); |
| 1431 | 1431 | ||
| 1432 | const slice_index = self.exprs.items.len; | 1432 | const slice_index = self.exprs.items.len; |
| ... | @@ -1498,7 +1498,7 @@ fn walkInstruction( | ... | @@ -1498,7 +1498,7 @@ fn walkInstruction( |
| 1498 | }, | 1498 | }, |
| 1499 | 1499 | ||
| 1500 | .load => { | 1500 | .load => { |
| 1501 | const un_node = data[inst_index].un_node; | 1501 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1502 | const operand = try self.walkRef( | 1502 | const operand = try self.walkRef( |
| 1503 | file, | 1503 | file, |
| 1504 | parent_scope, | 1504 | parent_scope, |
| ... | @@ -1529,7 +1529,7 @@ fn walkInstruction( | ... | @@ -1529,7 +1529,7 @@ fn walkInstruction( |
| 1529 | }; | 1529 | }; |
| 1530 | }, | 1530 | }, |
| 1531 | .ref => { | 1531 | .ref => { |
| 1532 | const un_tok = data[inst_index].un_tok; | 1532 | const un_tok = data[@intFromEnum(inst)].un_tok; |
| 1533 | const operand = try self.walkRef( | 1533 | const operand = try self.walkRef( |
| 1534 | file, | 1534 | file, |
| 1535 | parent_scope, | 1535 | parent_scope, |
| ... | @@ -1565,7 +1565,7 @@ fn walkInstruction( | ... | @@ -1565,7 +1565,7 @@ fn walkInstruction( |
| 1565 | .array_cat, | 1565 | .array_cat, |
| 1566 | .array_mul, | 1566 | .array_mul, |
| 1567 | => { | 1567 | => { |
| 1568 | const pl_node = data[inst_index].pl_node; | 1568 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1569 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 1569 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1570 | 1570 | ||
| 1571 | const binop_index = self.exprs.items.len; | 1571 | const binop_index = self.exprs.items.len; |
| ... | @@ -1593,7 +1593,7 @@ fn walkInstruction( | ... | @@ -1593,7 +1593,7 @@ fn walkInstruction( |
| 1593 | const rhs_index = self.exprs.items.len; | 1593 | const rhs_index = self.exprs.items.len; |
| 1594 | try self.exprs.append(self.arena, rhs.expr); | 1594 | try self.exprs.append(self.arena, rhs.expr); |
| 1595 | self.exprs.items[binop_index] = .{ .binOp = .{ | 1595 | self.exprs.items[binop_index] = .{ .binOp = .{ |
| 1596 | .name = @tagName(tags[inst_index]), | 1596 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 1597 | .lhs = lhs_index, | 1597 | .lhs = lhs_index, |
| 1598 | .rhs = rhs_index, | 1598 | .rhs = rhs_index, |
| 1599 | } }; | 1599 | } }; |
| ... | @@ -1611,7 +1611,7 @@ fn walkInstruction( | ... | @@ -1611,7 +1611,7 @@ fn walkInstruction( |
| 1611 | .cmp_lt, | 1611 | .cmp_lt, |
| 1612 | .cmp_lte, | 1612 | .cmp_lte, |
| 1613 | => { | 1613 | => { |
| 1614 | const pl_node = data[inst_index].pl_node; | 1614 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1615 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 1615 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1616 | 1616 | ||
| 1617 | const binop_index = self.exprs.items.len; | 1617 | const binop_index = self.exprs.items.len; |
| ... | @@ -1639,7 +1639,7 @@ fn walkInstruction( | ... | @@ -1639,7 +1639,7 @@ fn walkInstruction( |
| 1639 | const rhs_index = self.exprs.items.len; | 1639 | const rhs_index = self.exprs.items.len; |
| 1640 | try self.exprs.append(self.arena, rhs.expr); | 1640 | try self.exprs.append(self.arena, rhs.expr); |
| 1641 | self.exprs.items[binop_index] = .{ .binOp = .{ | 1641 | self.exprs.items[binop_index] = .{ .binOp = .{ |
| 1642 | .name = @tagName(tags[inst_index]), | 1642 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 1643 | .lhs = lhs_index, | 1643 | .lhs = lhs_index, |
| 1644 | .rhs = rhs_index, | 1644 | .rhs = rhs_index, |
| 1645 | } }; | 1645 | } }; |
| ... | @@ -1684,7 +1684,7 @@ fn walkInstruction( | ... | @@ -1684,7 +1684,7 @@ fn walkInstruction( |
| 1684 | .byte_swap, | 1684 | .byte_swap, |
| 1685 | .bit_reverse, | 1685 | .bit_reverse, |
| 1686 | => { | 1686 | => { |
| 1687 | const un_node = data[inst_index].un_node; | 1687 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1688 | const bin_index = self.exprs.items.len; | 1688 | const bin_index = self.exprs.items.len; |
| 1689 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); | 1689 | try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } }); |
| 1690 | const param = try self.walkRef( | 1690 | const param = try self.walkRef( |
| ... | @@ -1701,7 +1701,7 @@ fn walkInstruction( | ... | @@ -1701,7 +1701,7 @@ fn walkInstruction( |
| 1701 | 1701 | ||
| 1702 | self.exprs.items[bin_index] = .{ | 1702 | self.exprs.items[bin_index] = .{ |
| 1703 | .builtin = .{ | 1703 | .builtin = .{ |
| 1704 | .name = @tagName(tags[inst_index]), | 1704 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 1705 | .param = param_index, | 1705 | .param = param_index, |
| 1706 | }, | 1706 | }, |
| 1707 | }; | 1707 | }; |
| ... | @@ -1715,7 +1715,7 @@ fn walkInstruction( | ... | @@ -1715,7 +1715,7 @@ fn walkInstruction( |
| 1715 | .bool_not, | 1715 | .bool_not, |
| 1716 | .negate_wrap, | 1716 | .negate_wrap, |
| 1717 | => { | 1717 | => { |
| 1718 | const un_node = data[inst_index].un_node; | 1718 | const un_node = data[@intFromEnum(inst)].un_node; |
| 1719 | const un_index = self.exprs.items.len; | 1719 | const un_index = self.exprs.items.len; |
| 1720 | try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } }); | 1720 | try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } }); |
| 1721 | const param = try self.walkRef( | 1721 | const param = try self.walkRef( |
| ... | @@ -1732,7 +1732,7 @@ fn walkInstruction( | ... | @@ -1732,7 +1732,7 @@ fn walkInstruction( |
| 1732 | 1732 | ||
| 1733 | self.exprs.items[un_index] = .{ | 1733 | self.exprs.items[un_index] = .{ |
| 1734 | .unOp = .{ | 1734 | .unOp = .{ |
| 1735 | .name = @tagName(tags[inst_index]), | 1735 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 1736 | .param = param_index, | 1736 | .param = param_index, |
| 1737 | }, | 1737 | }, |
| 1738 | }; | 1738 | }; |
| ... | @@ -1743,7 +1743,7 @@ fn walkInstruction( | ... | @@ -1743,7 +1743,7 @@ fn walkInstruction( |
| 1743 | }; | 1743 | }; |
| 1744 | }, | 1744 | }, |
| 1745 | .bool_br_and, .bool_br_or => { | 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 | const bin_index = self.exprs.items.len; | 1748 | const bin_index = self.exprs.items.len; |
| 1749 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); | 1749 | try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } }); |
| ... | @@ -1764,14 +1764,14 @@ fn walkInstruction( | ... | @@ -1764,14 +1764,14 @@ fn walkInstruction( |
| 1764 | file, | 1764 | file, |
| 1765 | parent_scope, | 1765 | parent_scope, |
| 1766 | parent_src, | 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 | false, | 1768 | false, |
| 1769 | call_ctx, | 1769 | call_ctx, |
| 1770 | ); | 1770 | ); |
| 1771 | const rhs_index = self.exprs.items.len; | 1771 | const rhs_index = self.exprs.items.len; |
| 1772 | try self.exprs.append(self.arena, rhs.expr); | 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 | return DocData.WalkResult{ | 1776 | return DocData.WalkResult{ |
| 1777 | .typeRef = .{ .type = @intFromEnum(Ref.bool_type) }, | 1777 | .typeRef = .{ .type = @intFromEnum(Ref.bool_type) }, |
| ... | @@ -1780,7 +1780,7 @@ fn walkInstruction( | ... | @@ -1780,7 +1780,7 @@ fn walkInstruction( |
| 1780 | }, | 1780 | }, |
| 1781 | .truncate => { | 1781 | .truncate => { |
| 1782 | // in the ZIR this node is a builtin `bin` but we want send it as a `un` builtin | 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 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 1784 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1785 | 1785 | ||
| 1786 | var rhs: DocData.WalkResult = try self.walkRef( | 1786 | var rhs: DocData.WalkResult = try self.walkRef( |
| ... | @@ -1807,7 +1807,7 @@ fn walkInstruction( | ... | @@ -1807,7 +1807,7 @@ fn walkInstruction( |
| 1807 | call_ctx, | 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 | return DocData.WalkResult{ | 1812 | return DocData.WalkResult{ |
| 1813 | .typeRef = lhs.expr, | 1813 | .typeRef = lhs.expr, |
| ... | @@ -1841,7 +1841,7 @@ fn walkInstruction( | ... | @@ -1841,7 +1841,7 @@ fn walkInstruction( |
| 1841 | .min, | 1841 | .min, |
| 1842 | .max, | 1842 | .max, |
| 1843 | => { | 1843 | => { |
| 1844 | const pl_node = data[inst_index].pl_node; | 1844 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1845 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 1845 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 1846 | 1846 | ||
| 1847 | const binop_index = self.exprs.items.len; | 1847 | const binop_index = self.exprs.items.len; |
| ... | @@ -1868,7 +1868,7 @@ fn walkInstruction( | ... | @@ -1868,7 +1868,7 @@ fn walkInstruction( |
| 1868 | try self.exprs.append(self.arena, lhs.expr); | 1868 | try self.exprs.append(self.arena, lhs.expr); |
| 1869 | const rhs_index = self.exprs.items.len; | 1869 | const rhs_index = self.exprs.items.len; |
| 1870 | try self.exprs.append(self.arena, rhs.expr); | 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 | return DocData.WalkResult{ | 1873 | return DocData.WalkResult{ |
| 1874 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, | 1874 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| ... | @@ -1876,7 +1876,7 @@ fn walkInstruction( | ... | @@ -1876,7 +1876,7 @@ fn walkInstruction( |
| 1876 | }; | 1876 | }; |
| 1877 | }, | 1877 | }, |
| 1878 | .mul_add => { | 1878 | .mul_add => { |
| 1879 | const pl_node = data[inst_index].pl_node; | 1879 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1880 | const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); | 1880 | const extra = file.zir.extraData(Zir.Inst.MulAdd, pl_node.payload_index); |
| 1881 | 1881 | ||
| 1882 | var mul1: DocData.WalkResult = try self.walkRef( | 1882 | var mul1: DocData.WalkResult = try self.walkRef( |
| ... | @@ -1927,7 +1927,7 @@ fn walkInstruction( | ... | @@ -1927,7 +1927,7 @@ fn walkInstruction( |
| 1927 | }; | 1927 | }; |
| 1928 | }, | 1928 | }, |
| 1929 | .union_init => { | 1929 | .union_init => { |
| 1930 | const pl_node = data[inst_index].pl_node; | 1930 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1931 | const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); | 1931 | const extra = file.zir.extraData(Zir.Inst.UnionInit, pl_node.payload_index); |
| 1932 | 1932 | ||
| 1933 | var union_type: DocData.WalkResult = try self.walkRef( | 1933 | var union_type: DocData.WalkResult = try self.walkRef( |
| ... | @@ -1974,7 +1974,7 @@ fn walkInstruction( | ... | @@ -1974,7 +1974,7 @@ fn walkInstruction( |
| 1974 | }; | 1974 | }; |
| 1975 | }, | 1975 | }, |
| 1976 | .builtin_call => { | 1976 | .builtin_call => { |
| 1977 | const pl_node = data[inst_index].pl_node; | 1977 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 1978 | const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); | 1978 | const extra = file.zir.extraData(Zir.Inst.BuiltinCall, pl_node.payload_index); |
| 1979 | 1979 | ||
| 1980 | var modifier: DocData.WalkResult = try self.walkRef( | 1980 | var modifier: DocData.WalkResult = try self.walkRef( |
| ... | @@ -2022,7 +2022,7 @@ fn walkInstruction( | ... | @@ -2022,7 +2022,7 @@ fn walkInstruction( |
| 2022 | }; | 2022 | }; |
| 2023 | }, | 2023 | }, |
| 2024 | .error_union_type => { | 2024 | .error_union_type => { |
| 2025 | const pl_node = data[inst_index].pl_node; | 2025 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2026 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 2026 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2027 | 2027 | ||
| 2028 | var lhs: DocData.WalkResult = try self.walkRef( | 2028 | var lhs: DocData.WalkResult = try self.walkRef( |
| ... | @@ -2054,7 +2054,7 @@ fn walkInstruction( | ... | @@ -2054,7 +2054,7 @@ fn walkInstruction( |
| 2054 | }; | 2054 | }; |
| 2055 | }, | 2055 | }, |
| 2056 | .merge_error_sets => { | 2056 | .merge_error_sets => { |
| 2057 | const pl_node = data[inst_index].pl_node; | 2057 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2058 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 2058 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 2059 | 2059 | ||
| 2060 | var lhs: DocData.WalkResult = try self.walkRef( | 2060 | var lhs: DocData.WalkResult = try self.walkRef( |
| ... | @@ -2085,7 +2085,7 @@ fn walkInstruction( | ... | @@ -2085,7 +2085,7 @@ fn walkInstruction( |
| 2085 | }; | 2085 | }; |
| 2086 | }, | 2086 | }, |
| 2087 | // .elem_type => { | 2087 | // .elem_type => { |
| 2088 | // const un_node = data[inst_index].un_node; | 2088 | // const un_node = data[@intFromEnum(inst)].un_node; |
| 2089 | 2089 | ||
| 2090 | // var operand: DocData.WalkResult = try self.walkRef( | 2090 | // var operand: DocData.WalkResult = try self.walkRef( |
| 2091 | // file, | 2091 | // file, |
| ... | @@ -2097,7 +2097,7 @@ fn walkInstruction( | ... | @@ -2097,7 +2097,7 @@ fn walkInstruction( |
| 2097 | // return operand; | 2097 | // return operand; |
| 2098 | // }, | 2098 | // }, |
| 2099 | .ptr_type => { | 2099 | .ptr_type => { |
| 2100 | const ptr = data[inst_index].ptr_type; | 2100 | const ptr = data[@intFromEnum(inst)].ptr_type; |
| 2101 | const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); | 2101 | const extra = file.zir.extraData(Zir.Inst.PtrType, ptr.payload_index); |
| 2102 | var extra_index = extra.end; | 2102 | var extra_index = extra.end; |
| 2103 | 2103 | ||
| ... | @@ -2208,7 +2208,7 @@ fn walkInstruction( | ... | @@ -2208,7 +2208,7 @@ fn walkInstruction( |
| 2208 | }; | 2208 | }; |
| 2209 | }, | 2209 | }, |
| 2210 | .array_type => { | 2210 | .array_type => { |
| 2211 | const pl_node = data[inst_index].pl_node; | 2211 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2212 | 2212 | ||
| 2213 | const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data; | 2213 | const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 2214 | const len = try self.walkRef( | 2214 | const len = try self.walkRef( |
| ... | @@ -2242,7 +2242,7 @@ fn walkInstruction( | ... | @@ -2242,7 +2242,7 @@ fn walkInstruction( |
| 2242 | }; | 2242 | }; |
| 2243 | }, | 2243 | }, |
| 2244 | .array_type_sentinel => { | 2244 | .array_type_sentinel => { |
| 2245 | const pl_node = data[inst_index].pl_node; | 2245 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2246 | const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index); | 2246 | const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index); |
| 2247 | const len = try self.walkRef( | 2247 | const len = try self.walkRef( |
| 2248 | file, | 2248 | file, |
| ... | @@ -2283,7 +2283,7 @@ fn walkInstruction( | ... | @@ -2283,7 +2283,7 @@ fn walkInstruction( |
| 2283 | }; | 2283 | }; |
| 2284 | }, | 2284 | }, |
| 2285 | .array_init => { | 2285 | .array_init => { |
| 2286 | const pl_node = data[inst_index].pl_node; | 2286 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2287 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); | 2287 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2288 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); | 2288 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2289 | const array_data = try self.arena.alloc(usize, operands.len - 1); | 2289 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| ... | @@ -2318,7 +2318,7 @@ fn walkInstruction( | ... | @@ -2318,7 +2318,7 @@ fn walkInstruction( |
| 2318 | }; | 2318 | }; |
| 2319 | }, | 2319 | }, |
| 2320 | .array_init_anon => { | 2320 | .array_init_anon => { |
| 2321 | const pl_node = data[inst_index].pl_node; | 2321 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2322 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); | 2322 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2323 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); | 2323 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2324 | const array_data = try self.arena.alloc(usize, operands.len); | 2324 | const array_data = try self.arena.alloc(usize, operands.len); |
| ... | @@ -2343,7 +2343,7 @@ fn walkInstruction( | ... | @@ -2343,7 +2343,7 @@ fn walkInstruction( |
| 2343 | }; | 2343 | }; |
| 2344 | }, | 2344 | }, |
| 2345 | .array_init_ref => { | 2345 | .array_init_ref => { |
| 2346 | const pl_node = data[inst_index].pl_node; | 2346 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2347 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); | 2347 | const extra = file.zir.extraData(Zir.Inst.MultiOp, pl_node.payload_index); |
| 2348 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); | 2348 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 2349 | const array_data = try self.arena.alloc(usize, operands.len - 1); | 2349 | const array_data = try self.arena.alloc(usize, operands.len - 1); |
| ... | @@ -2389,7 +2389,7 @@ fn walkInstruction( | ... | @@ -2389,7 +2389,7 @@ fn walkInstruction( |
| 2389 | }; | 2389 | }; |
| 2390 | }, | 2390 | }, |
| 2391 | .float => { | 2391 | .float => { |
| 2392 | const float = data[inst_index].float; | 2392 | const float = data[@intFromEnum(inst)].float; |
| 2393 | return DocData.WalkResult{ | 2393 | return DocData.WalkResult{ |
| 2394 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, | 2394 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, |
| 2395 | .expr = .{ .float = float }, | 2395 | .expr = .{ .float = float }, |
| ... | @@ -2397,7 +2397,7 @@ fn walkInstruction( | ... | @@ -2397,7 +2397,7 @@ fn walkInstruction( |
| 2397 | }, | 2397 | }, |
| 2398 | // @check: In frontend I'm handling float128 with `.toFixed(2)` | 2398 | // @check: In frontend I'm handling float128 with `.toFixed(2)` |
| 2399 | .float128 => { | 2399 | .float128 => { |
| 2400 | const pl_node = data[inst_index].pl_node; | 2400 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2401 | const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index); | 2401 | const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index); |
| 2402 | return DocData.WalkResult{ | 2402 | return DocData.WalkResult{ |
| 2403 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, | 2403 | .typeRef = .{ .type = @intFromEnum(Ref.comptime_float_type) }, |
| ... | @@ -2405,7 +2405,7 @@ fn walkInstruction( | ... | @@ -2405,7 +2405,7 @@ fn walkInstruction( |
| 2405 | }; | 2405 | }; |
| 2406 | }, | 2406 | }, |
| 2407 | .negate => { | 2407 | .negate => { |
| 2408 | const un_node = data[inst_index].un_node; | 2408 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2409 | 2409 | ||
| 2410 | var operand: DocData.WalkResult = try self.walkRef( | 2410 | var operand: DocData.WalkResult = try self.walkRef( |
| 2411 | file, | 2411 | file, |
| ... | @@ -2425,7 +2425,7 @@ fn walkInstruction( | ... | @@ -2425,7 +2425,7 @@ fn walkInstruction( |
| 2425 | try self.exprs.append(self.arena, operand.expr); | 2425 | try self.exprs.append(self.arena, operand.expr); |
| 2426 | self.exprs.items[un_index] = .{ | 2426 | self.exprs.items[un_index] = .{ |
| 2427 | .unOp = .{ | 2427 | .unOp = .{ |
| 2428 | .name = @tagName(tags[inst_index]), | 2428 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 2429 | .param = param_index, | 2429 | .param = param_index, |
| 2430 | }, | 2430 | }, |
| 2431 | }; | 2431 | }; |
| ... | @@ -2438,7 +2438,7 @@ fn walkInstruction( | ... | @@ -2438,7 +2438,7 @@ fn walkInstruction( |
| 2438 | return operand; | 2438 | return operand; |
| 2439 | }, | 2439 | }, |
| 2440 | .size_of => { | 2440 | .size_of => { |
| 2441 | const un_node = data[inst_index].un_node; | 2441 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2442 | 2442 | ||
| 2443 | const operand = try self.walkRef( | 2443 | const operand = try self.walkRef( |
| 2444 | file, | 2444 | file, |
| ... | @@ -2457,7 +2457,7 @@ fn walkInstruction( | ... | @@ -2457,7 +2457,7 @@ fn walkInstruction( |
| 2457 | }, | 2457 | }, |
| 2458 | .bit_size_of => { | 2458 | .bit_size_of => { |
| 2459 | // not working correctly with `align()` | 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 | const operand = try self.walkRef( | 2462 | const operand = try self.walkRef( |
| 2463 | file, | 2463 | file, |
| ... | @@ -2477,7 +2477,7 @@ fn walkInstruction( | ... | @@ -2477,7 +2477,7 @@ fn walkInstruction( |
| 2477 | }, | 2477 | }, |
| 2478 | .int_from_enum => { | 2478 | .int_from_enum => { |
| 2479 | // not working correctly with `align()` | 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 | const operand = try self.walkRef( | 2481 | const operand = try self.walkRef( |
| 2482 | file, | 2482 | file, |
| 2483 | parent_scope, | 2483 | parent_scope, |
| ... | @@ -2492,7 +2492,7 @@ fn walkInstruction( | ... | @@ -2492,7 +2492,7 @@ fn walkInstruction( |
| 2492 | try self.exprs.append(self.arena, operand.expr); | 2492 | try self.exprs.append(self.arena, operand.expr); |
| 2493 | self.exprs.items[builtin_index] = .{ | 2493 | self.exprs.items[builtin_index] = .{ |
| 2494 | .builtin = .{ | 2494 | .builtin = .{ |
| 2495 | .name = @tagName(tags[inst_index]), | 2495 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 2496 | .param = operand_index, | 2496 | .param = operand_index, |
| 2497 | }, | 2497 | }, |
| 2498 | }; | 2498 | }; |
| ... | @@ -2504,7 +2504,7 @@ fn walkInstruction( | ... | @@ -2504,7 +2504,7 @@ fn walkInstruction( |
| 2504 | }, | 2504 | }, |
| 2505 | .switch_block => { | 2505 | .switch_block => { |
| 2506 | // WIP | 2506 | // WIP |
| 2507 | const pl_node = data[inst_index].pl_node; | 2507 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2508 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); | 2508 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); |
| 2509 | 2509 | ||
| 2510 | const switch_cond = try self.walkRef( | 2510 | const switch_cond = try self.walkRef( |
| ... | @@ -2553,7 +2553,7 @@ fn walkInstruction( | ... | @@ -2553,7 +2553,7 @@ fn walkInstruction( |
| 2553 | }, | 2553 | }, |
| 2554 | 2554 | ||
| 2555 | .typeof => { | 2555 | .typeof => { |
| 2556 | const un_node = data[inst_index].un_node; | 2556 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2557 | 2557 | ||
| 2558 | const operand = try self.walkRef( | 2558 | const operand = try self.walkRef( |
| 2559 | file, | 2559 | file, |
| ... | @@ -2572,7 +2572,7 @@ fn walkInstruction( | ... | @@ -2572,7 +2572,7 @@ fn walkInstruction( |
| 2572 | }; | 2572 | }; |
| 2573 | }, | 2573 | }, |
| 2574 | .typeof_builtin => { | 2574 | .typeof_builtin => { |
| 2575 | const pl_node = data[inst_index].pl_node; | 2575 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2576 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); | 2576 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 2577 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; | 2577 | const body = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| 2578 | var operand: DocData.WalkResult = try self.walkRef( | 2578 | var operand: DocData.WalkResult = try self.walkRef( |
| ... | @@ -2593,11 +2593,11 @@ fn walkInstruction( | ... | @@ -2593,11 +2593,11 @@ fn walkInstruction( |
| 2593 | }; | 2593 | }; |
| 2594 | }, | 2594 | }, |
| 2595 | .as_node, .as_shift_operand => { | 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 | const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index); | 2597 | const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index); |
| 2598 | 2598 | ||
| 2599 | // Skip the as_node if the destination type is a call instruction | 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 | var maybe_cc = call_ctx; | 2601 | var maybe_cc = call_ctx; |
| 2602 | while (maybe_cc) |cc| : (maybe_cc = cc.prev) { | 2602 | while (maybe_cc) |cc| : (maybe_cc = cc.prev) { |
| 2603 | if (cc.inst == dti) { | 2603 | if (cc.inst == dti) { |
| ... | @@ -2650,7 +2650,7 @@ fn walkInstruction( | ... | @@ -2650,7 +2650,7 @@ fn walkInstruction( |
| 2650 | }; | 2650 | }; |
| 2651 | }, | 2651 | }, |
| 2652 | .optional_type => { | 2652 | .optional_type => { |
| 2653 | const un_node = data[inst_index].un_node; | 2653 | const un_node = data[@intFromEnum(inst)].un_node; |
| 2654 | 2654 | ||
| 2655 | const operand: DocData.WalkResult = try self.walkRef( | 2655 | const operand: DocData.WalkResult = try self.walkRef( |
| 2656 | file, | 2656 | file, |
| ... | @@ -2672,14 +2672,14 @@ fn walkInstruction( | ... | @@ -2672,14 +2672,14 @@ fn walkInstruction( |
| 2672 | }; | 2672 | }; |
| 2673 | }, | 2673 | }, |
| 2674 | .decl_val, .decl_ref => { | 2674 | .decl_val, .decl_ref => { |
| 2675 | const str_tok = data[inst_index].str_tok; | 2675 | const str_tok = data[@intFromEnum(inst)].str_tok; |
| 2676 | const decl_status = parent_scope.resolveDeclName(str_tok.start, file, inst_index); | 2676 | const decl_status = parent_scope.resolveDeclName(str_tok.start, file, inst.toOptional()); |
| 2677 | return DocData.WalkResult{ | 2677 | return DocData.WalkResult{ |
| 2678 | .expr = .{ .declRef = decl_status }, | 2678 | .expr = .{ .declRef = decl_status }, |
| 2679 | }; | 2679 | }; |
| 2680 | }, | 2680 | }, |
| 2681 | .field_val, .field_ptr => { | 2681 | .field_val, .field_ptr => { |
| 2682 | const pl_node = data[inst_index].pl_node; | 2682 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2683 | const extra = file.zir.extraData(Zir.Inst.Field, pl_node.payload_index); | 2683 | const extra = file.zir.extraData(Zir.Inst.Field, pl_node.payload_index); |
| 2684 | 2684 | ||
| 2685 | var path: std.ArrayListUnmanaged(DocData.Expr) = .{}; | 2685 | var path: std.ArrayListUnmanaged(DocData.Expr) = .{}; |
| ... | @@ -2692,12 +2692,15 @@ fn walkInstruction( | ... | @@ -2692,12 +2692,15 @@ fn walkInstruction( |
| 2692 | const lhs_ref = blk: { | 2692 | const lhs_ref = blk: { |
| 2693 | var lhs_extra = extra; | 2693 | var lhs_extra = extra; |
| 2694 | while (true) { | 2694 | while (true) { |
| 2695 | const lhs = Zir.refToIndex(lhs_extra.data.lhs) orelse { | 2695 | const lhs = @intFromEnum(lhs_extra.data.lhs.toIndex() orelse { |
| 2696 | break :blk lhs_extra.data.lhs; | 2696 | break :blk lhs_extra.data.lhs; |
| 2697 | }; | 2697 | }); |
| 2698 | 2698 | ||
| 2699 | if (tags[lhs] != .field_val and | 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 | lhs_extra = file.zir.extraData( | 2705 | lhs_extra = file.zir.extraData( |
| 2703 | Zir.Inst.Field, | 2706 | Zir.Inst.Field, |
| ... | @@ -2721,15 +2724,16 @@ fn walkInstruction( | ... | @@ -2721,15 +2724,16 @@ fn walkInstruction( |
| 2721 | // TODO: double check that we really don't need type info here | 2724 | // TODO: double check that we really don't need type info here |
| 2722 | 2725 | ||
| 2723 | const wr = blk: { | 2726 | const wr = blk: { |
| 2724 | if (Zir.refToIndex(lhs_ref)) |lhs_inst| { | 2727 | if (lhs_ref.toIndex()) |lhs_inst| switch (tags[@intFromEnum(lhs_inst)]) { |
| 2725 | if (tags[lhs_inst] == .call or tags[lhs_inst] == .field_call) { | 2728 | .call, .field_call => { |
| 2726 | break :blk DocData.WalkResult{ | 2729 | break :blk DocData.WalkResult{ |
| 2727 | .expr = .{ | 2730 | .expr = .{ |
| 2728 | .comptimeExpr = 0, | 2731 | .comptimeExpr = 0, |
| 2729 | }, | 2732 | }, |
| 2730 | }; | 2733 | }; |
| 2731 | } | 2734 | }, |
| 2732 | } | 2735 | else => {}, |
| 2736 | }; | ||
| 2733 | 2737 | ||
| 2734 | break :blk try self.walkRef( | 2738 | break :blk try self.walkRef( |
| 2735 | file, | 2739 | file, |
| ... | @@ -2758,11 +2762,11 @@ fn walkInstruction( | ... | @@ -2758,11 +2762,11 @@ fn walkInstruction( |
| 2758 | // - (2) Paths can sometimes never resolve fully. This means that | 2762 | // - (2) Paths can sometimes never resolve fully. This means that |
| 2759 | // any value that depends on that will have to become a | 2763 | // any value that depends on that will have to become a |
| 2760 | // comptimeExpr. | 2764 | // comptimeExpr. |
| 2761 | try self.tryResolveRefPath(file, inst_index, path.items); | 2765 | try self.tryResolveRefPath(file, inst, path.items); |
| 2762 | return DocData.WalkResult{ .expr = .{ .refPath = path.items } }; | 2766 | return DocData.WalkResult{ .expr = .{ .refPath = path.items } }; |
| 2763 | }, | 2767 | }, |
| 2764 | .int_type => { | 2768 | .int_type => { |
| 2765 | const int_type = data[inst_index].int_type; | 2769 | const int_type = data[@intFromEnum(inst)].int_type; |
| 2766 | const sign = if (int_type.signedness == .unsigned) "u" else "i"; | 2770 | const sign = if (int_type.signedness == .unsigned) "u" else "i"; |
| 2767 | const bits = int_type.bit_count; | 2771 | const bits = int_type.bit_count; |
| 2768 | const name = try std.fmt.allocPrint(self.arena, "{s}{}", .{ sign, bits }); | 2772 | const name = try std.fmt.allocPrint(self.arena, "{s}{}", .{ sign, bits }); |
| ... | @@ -2781,7 +2785,7 @@ fn walkInstruction( | ... | @@ -2781,7 +2785,7 @@ fn walkInstruction( |
| 2781 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, | 2785 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| 2782 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, | 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 | const block_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); | 2789 | const block_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2786 | try self.comptime_exprs.append(self.arena, .{ | 2790 | try self.comptime_exprs.append(self.arena, .{ |
| 2787 | .code = block_expr, | 2791 | .code = block_expr, |
| ... | @@ -2793,12 +2797,12 @@ fn walkInstruction( | ... | @@ -2793,12 +2797,12 @@ fn walkInstruction( |
| 2793 | file, | 2797 | file, |
| 2794 | parent_scope, | 2798 | parent_scope, |
| 2795 | parent_src, | 2799 | parent_src, |
| 2796 | getBlockInlineBreak(file.zir, inst_index) orelse { | 2800 | getBlockInlineBreak(file.zir, inst) orelse { |
| 2797 | const res = DocData.WalkResult{ | 2801 | const res = DocData.WalkResult{ |
| 2798 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, | 2802 | .typeRef = .{ .type = @intFromEnum(Ref.type_type) }, |
| 2799 | .expr = .{ .comptimeExpr = self.comptime_exprs.items.len }, | 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 | const block_inline_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); | 2806 | const block_inline_expr = try self.getBlockSource(file, parent_src, pl_node.src_node); |
| 2803 | try self.comptime_exprs.append(self.arena, .{ | 2807 | try self.comptime_exprs.append(self.arena, .{ |
| 2804 | .code = block_inline_expr, | 2808 | .code = block_inline_expr, |
| ... | @@ -2810,7 +2814,7 @@ fn walkInstruction( | ... | @@ -2810,7 +2814,7 @@ fn walkInstruction( |
| 2810 | ); | 2814 | ); |
| 2811 | }, | 2815 | }, |
| 2812 | .break_inline => { | 2816 | .break_inline => { |
| 2813 | const @"break" = data[inst_index].@"break"; | 2817 | const @"break" = data[@intFromEnum(inst)].@"break"; |
| 2814 | return try self.walkRef( | 2818 | return try self.walkRef( |
| 2815 | file, | 2819 | file, |
| 2816 | parent_scope, | 2820 | parent_scope, |
| ... | @@ -2821,7 +2825,7 @@ fn walkInstruction( | ... | @@ -2821,7 +2825,7 @@ fn walkInstruction( |
| 2821 | ); | 2825 | ); |
| 2822 | }, | 2826 | }, |
| 2823 | .struct_init => { | 2827 | .struct_init => { |
| 2824 | const pl_node = data[inst_index].pl_node; | 2828 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2825 | const extra = file.zir.extraData(Zir.Inst.StructInit, pl_node.payload_index); | 2829 | const extra = file.zir.extraData(Zir.Inst.StructInit, pl_node.payload_index); |
| 2826 | const field_vals = try self.arena.alloc( | 2830 | const field_vals = try self.arena.alloc( |
| 2827 | DocData.Expr.FieldVal, | 2831 | DocData.Expr.FieldVal, |
| ... | @@ -2835,7 +2839,7 @@ fn walkInstruction( | ... | @@ -2835,7 +2839,7 @@ fn walkInstruction( |
| 2835 | defer idx = init_extra.end; | 2839 | defer idx = init_extra.end; |
| 2836 | 2840 | ||
| 2837 | const field_name = blk: { | 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 | if (tags[field_inst_index] != .struct_init_field_type) unreachable; | 2843 | if (tags[field_inst_index] != .struct_init_field_type) unreachable; |
| 2840 | const field_pl_node = data[field_inst_index].pl_node; | 2844 | const field_pl_node = data[field_inst_index].pl_node; |
| 2841 | const field_extra = file.zir.extraData( | 2845 | const field_extra = file.zir.extraData( |
| ... | @@ -2881,7 +2885,7 @@ fn walkInstruction( | ... | @@ -2881,7 +2885,7 @@ fn walkInstruction( |
| 2881 | .struct_init_empty, | 2885 | .struct_init_empty, |
| 2882 | .struct_init_empty_result, | 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 | var operand: DocData.WalkResult = try self.walkRef( | 2890 | var operand: DocData.WalkResult = try self.walkRef( |
| 2887 | file, | 2891 | file, |
| ... | @@ -2898,7 +2902,7 @@ fn walkInstruction( | ... | @@ -2898,7 +2902,7 @@ fn walkInstruction( |
| 2898 | }; | 2902 | }; |
| 2899 | }, | 2903 | }, |
| 2900 | .struct_init_empty_ref_result => { | 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 | var operand: DocData.WalkResult = try self.walkRef( | 2907 | var operand: DocData.WalkResult = try self.walkRef( |
| 2904 | file, | 2908 | file, |
| ... | @@ -2918,7 +2922,7 @@ fn walkInstruction( | ... | @@ -2918,7 +2922,7 @@ fn walkInstruction( |
| 2918 | }; | 2922 | }; |
| 2919 | }, | 2923 | }, |
| 2920 | .struct_init_anon => { | 2924 | .struct_init_anon => { |
| 2921 | const pl_node = data[inst_index].pl_node; | 2925 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2922 | const extra = file.zir.extraData(Zir.Inst.StructInitAnon, pl_node.payload_index); | 2926 | const extra = file.zir.extraData(Zir.Inst.StructInitAnon, pl_node.payload_index); |
| 2923 | 2927 | ||
| 2924 | const field_vals = try self.arena.alloc( | 2928 | const field_vals = try self.arena.alloc( |
| ... | @@ -2947,7 +2951,7 @@ fn walkInstruction( | ... | @@ -2947,7 +2951,7 @@ fn walkInstruction( |
| 2947 | }; | 2951 | }; |
| 2948 | }, | 2952 | }, |
| 2949 | .error_set_decl => { | 2953 | .error_set_decl => { |
| 2950 | const pl_node = data[inst_index].pl_node; | 2954 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 2951 | const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index); | 2955 | const extra = file.zir.extraData(Zir.Inst.ErrorSetDecl, pl_node.payload_index); |
| 2952 | const fields = try self.arena.alloc( | 2956 | const fields = try self.arena.alloc( |
| 2953 | DocData.Type.Field, | 2957 | DocData.Type.Field, |
| ... | @@ -2986,7 +2990,7 @@ fn walkInstruction( | ... | @@ -2986,7 +2990,7 @@ fn walkInstruction( |
| 2986 | // This switch case handles the case where an expression depends | 2990 | // This switch case handles the case where an expression depends |
| 2987 | // on an anytype field. E.g.: `fn foo(bar: anytype) @TypeOf(bar)`. | 2991 | // on an anytype field. E.g.: `fn foo(bar: anytype) @TypeOf(bar)`. |
| 2988 | // This means that we're looking at a generic expression. | 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 | const name = str_tok.get(file.zir); | 2994 | const name = str_tok.get(file.zir); |
| 2991 | const cte_slot_index = self.comptime_exprs.items.len; | 2995 | const cte_slot_index = self.comptime_exprs.items.len; |
| 2992 | try self.comptime_exprs.append(self.arena, .{ | 2996 | try self.comptime_exprs.append(self.arena, .{ |
| ... | @@ -2996,7 +3000,7 @@ fn walkInstruction( | ... | @@ -2996,7 +3000,7 @@ fn walkInstruction( |
| 2996 | }, | 3000 | }, |
| 2997 | .param, .param_comptime => { | 3001 | .param, .param_comptime => { |
| 2998 | // See .param_anytype for more information. | 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 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); | 3004 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 3001 | const name = file.zir.nullTerminatedString(extra.data.name); | 3005 | const name = file.zir.nullTerminatedString(extra.data.name); |
| 3002 | 3006 | ||
| ... | @@ -3007,7 +3011,7 @@ fn walkInstruction( | ... | @@ -3007,7 +3011,7 @@ fn walkInstruction( |
| 3007 | return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } }; | 3011 | return DocData.WalkResult{ .expr = .{ .comptimeExpr = cte_slot_index } }; |
| 3008 | }, | 3012 | }, |
| 3009 | .call => { | 3013 | .call => { |
| 3010 | const pl_node = data[inst_index].pl_node; | 3014 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 3011 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); | 3015 | const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index); |
| 3012 | 3016 | ||
| 3013 | const callee = try self.walkRef( | 3017 | const callee = try self.walkRef( |
| ... | @@ -3023,8 +3027,8 @@ fn walkInstruction( | ... | @@ -3023,8 +3027,8 @@ fn walkInstruction( |
| 3023 | var args = try self.arena.alloc(DocData.Expr, args_len); | 3027 | var args = try self.arena.alloc(DocData.Expr, args_len); |
| 3024 | const body = file.zir.extra[extra.end..]; | 3028 | const body = file.zir.extra[extra.end..]; |
| 3025 | 3029 | ||
| 3026 | try self.repurposed_insts.put(self.arena, @intCast(inst_index), {}); | 3030 | try self.repurposed_insts.put(self.arena, inst, {}); |
| 3027 | defer _ = self.repurposed_insts.remove(@intCast(inst_index)); | 3031 | defer _ = self.repurposed_insts.remove(inst); |
| 3028 | 3032 | ||
| 3029 | var i: usize = 0; | 3033 | var i: usize = 0; |
| 3030 | while (i < args_len) : (i += 1) { | 3034 | while (i < args_len) : (i += 1) { |
| ... | @@ -3042,7 +3046,7 @@ fn walkInstruction( | ... | @@ -3042,7 +3046,7 @@ fn walkInstruction( |
| 3042 | ref, | 3046 | ref, |
| 3043 | false, | 3047 | false, |
| 3044 | &.{ | 3048 | &.{ |
| 3045 | .inst = inst_index, | 3049 | .inst = inst, |
| 3046 | .prev = call_ctx, | 3050 | .prev = call_ctx, |
| 3047 | }, | 3051 | }, |
| 3048 | ); | 3052 | ); |
| ... | @@ -3068,7 +3072,7 @@ fn walkInstruction( | ... | @@ -3068,7 +3072,7 @@ fn walkInstruction( |
| 3068 | else => blk: { | 3072 | else => blk: { |
| 3069 | printWithContext( | 3073 | printWithContext( |
| 3070 | file, | 3074 | file, |
| 3071 | inst_index, | 3075 | inst, |
| 3072 | "unexpected callee type in walkInstruction.call: `{s}`\n", | 3076 | "unexpected callee type in walkInstruction.call: `{s}`\n", |
| 3073 | .{@tagName(self.types.items[func_type_idx])}, | 3077 | .{@tagName(self.types.items[func_type_idx])}, |
| 3074 | ); | 3078 | ); |
| ... | @@ -3089,10 +3093,10 @@ fn walkInstruction( | ... | @@ -3089,10 +3093,10 @@ fn walkInstruction( |
| 3089 | file, | 3093 | file, |
| 3090 | parent_scope, | 3094 | parent_scope, |
| 3091 | parent_src, | 3095 | parent_src, |
| 3092 | inst_index, | 3096 | inst, |
| 3093 | self_ast_node_index, | 3097 | self_ast_node_index, |
| 3094 | type_slot_index, | 3098 | type_slot_index, |
| 3095 | tags[inst_index] == .func_inferred, | 3099 | tags[@intFromEnum(inst)] == .func_inferred, |
| 3096 | call_ctx, | 3100 | call_ctx, |
| 3097 | ); | 3101 | ); |
| 3098 | 3102 | ||
| ... | @@ -3106,7 +3110,7 @@ fn walkInstruction( | ... | @@ -3106,7 +3110,7 @@ fn walkInstruction( |
| 3106 | file, | 3110 | file, |
| 3107 | parent_scope, | 3111 | parent_scope, |
| 3108 | parent_src, | 3112 | parent_src, |
| 3109 | inst_index, | 3113 | inst, |
| 3110 | self_ast_node_index, | 3114 | self_ast_node_index, |
| 3111 | type_slot_index, | 3115 | type_slot_index, |
| 3112 | call_ctx, | 3116 | call_ctx, |
| ... | @@ -3115,7 +3119,7 @@ fn walkInstruction( | ... | @@ -3115,7 +3119,7 @@ fn walkInstruction( |
| 3115 | return result; | 3119 | return result; |
| 3116 | }, | 3120 | }, |
| 3117 | .optional_payload_safe, .optional_payload_unsafe => { | 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 | const operand = try self.walkRef( | 3123 | const operand = try self.walkRef( |
| 3120 | file, | 3124 | file, |
| 3121 | parent_scope, | 3125 | parent_scope, |
| ... | @@ -3135,7 +3139,7 @@ fn walkInstruction( | ... | @@ -3135,7 +3139,7 @@ fn walkInstruction( |
| 3135 | switch (t) { | 3139 | switch (t) { |
| 3136 | .Optional => |opt| typeRef = opt.child, | 3140 | .Optional => |opt| typeRef = opt.child, |
| 3137 | else => { | 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,7 +3153,7 @@ fn walkInstruction( |
| 3149 | }; | 3153 | }; |
| 3150 | }, | 3154 | }, |
| 3151 | .elem_val_node => { | 3155 | .elem_val_node => { |
| 3152 | const pl_node = data[inst_index].pl_node; | 3156 | const pl_node = data[@intFromEnum(inst)].pl_node; |
| 3153 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); | 3157 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| 3154 | const lhs = try self.walkRef( | 3158 | const lhs = try self.walkRef( |
| 3155 | file, | 3159 | file, |
| ... | @@ -3181,12 +3185,12 @@ fn walkInstruction( | ... | @@ -3181,12 +3185,12 @@ fn walkInstruction( |
| 3181 | }; | 3185 | }; |
| 3182 | }, | 3186 | }, |
| 3183 | .extended => { | 3187 | .extended => { |
| 3184 | const extended = data[inst_index].extended; | 3188 | const extended = data[@intFromEnum(inst)].extended; |
| 3185 | switch (extended.opcode) { | 3189 | switch (extended.opcode) { |
| 3186 | else => { | 3190 | else => { |
| 3187 | printWithContext( | 3191 | printWithContext( |
| 3188 | file, | 3192 | file, |
| 3189 | inst_index, | 3193 | inst, |
| 3190 | "TODO: implement `walkInstruction.extended` for {s}", | 3194 | "TODO: implement `walkInstruction.extended` for {s}", |
| 3191 | .{@tagName(extended.opcode)}, | 3195 | .{@tagName(extended.opcode)}, |
| 3192 | ); | 3196 | ); |
| ... | @@ -3265,7 +3269,7 @@ fn walkInstruction( | ... | @@ -3265,7 +3269,7 @@ fn walkInstruction( |
| 3265 | extra_index = try self.analyzeAllDecls( | 3269 | extra_index = try self.analyzeAllDecls( |
| 3266 | file, | 3270 | file, |
| 3267 | &scope, | 3271 | &scope, |
| 3268 | inst_index, | 3272 | inst, |
| 3269 | src_info, | 3273 | src_info, |
| 3270 | &decl_indexes, | 3274 | &decl_indexes, |
| 3271 | &priv_decl_indexes, | 3275 | &priv_decl_indexes, |
| ... | @@ -3285,7 +3289,7 @@ fn walkInstruction( | ... | @@ -3285,7 +3289,7 @@ fn walkInstruction( |
| 3285 | for (paths.items) |resume_info| { | 3289 | for (paths.items) |resume_info| { |
| 3286 | try self.tryResolveRefPath( | 3290 | try self.tryResolveRefPath( |
| 3287 | resume_info.file, | 3291 | resume_info.file, |
| 3288 | inst_index, | 3292 | inst, |
| 3289 | resume_info.ref_path, | 3293 | resume_info.ref_path, |
| 3290 | ); | 3294 | ); |
| 3291 | } | 3295 | } |
| ... | @@ -3393,7 +3397,7 @@ fn walkInstruction( | ... | @@ -3393,7 +3397,7 @@ fn walkInstruction( |
| 3393 | extra_index = try self.analyzeAllDecls( | 3397 | extra_index = try self.analyzeAllDecls( |
| 3394 | file, | 3398 | file, |
| 3395 | &scope, | 3399 | &scope, |
| 3396 | inst_index, | 3400 | inst, |
| 3397 | src_info, | 3401 | src_info, |
| 3398 | &decl_indexes, | 3402 | &decl_indexes, |
| 3399 | &priv_decl_indexes, | 3403 | &priv_decl_indexes, |
| ... | @@ -3452,7 +3456,7 @@ fn walkInstruction( | ... | @@ -3452,7 +3456,7 @@ fn walkInstruction( |
| 3452 | for (paths.items) |resume_info| { | 3456 | for (paths.items) |resume_info| { |
| 3453 | try self.tryResolveRefPath( | 3457 | try self.tryResolveRefPath( |
| 3454 | resume_info.file, | 3458 | resume_info.file, |
| 3455 | inst_index, | 3459 | inst, |
| 3456 | resume_info.ref_path, | 3460 | resume_info.ref_path, |
| 3457 | ); | 3461 | ); |
| 3458 | } | 3462 | } |
| ... | @@ -3524,7 +3528,7 @@ fn walkInstruction( | ... | @@ -3524,7 +3528,7 @@ fn walkInstruction( |
| 3524 | extra_index = try self.analyzeAllDecls( | 3528 | extra_index = try self.analyzeAllDecls( |
| 3525 | file, | 3529 | file, |
| 3526 | &scope, | 3530 | &scope, |
| 3527 | inst_index, | 3531 | inst, |
| 3528 | src_info, | 3532 | src_info, |
| 3529 | &decl_indexes, | 3533 | &decl_indexes, |
| 3530 | &priv_decl_indexes, | 3534 | &priv_decl_indexes, |
| ... | @@ -3604,7 +3608,7 @@ fn walkInstruction( | ... | @@ -3604,7 +3608,7 @@ fn walkInstruction( |
| 3604 | for (paths.items) |resume_info| { | 3608 | for (paths.items) |resume_info| { |
| 3605 | try self.tryResolveRefPath( | 3609 | try self.tryResolveRefPath( |
| 3606 | resume_info.file, | 3610 | resume_info.file, |
| 3607 | inst_index, | 3611 | inst, |
| 3608 | resume_info.ref_path, | 3612 | resume_info.ref_path, |
| 3609 | ); | 3613 | ); |
| 3610 | } | 3614 | } |
| ... | @@ -3668,9 +3672,9 @@ fn walkInstruction( | ... | @@ -3668,9 +3672,9 @@ fn walkInstruction( |
| 3668 | backing_int = backing_int_res.expr; | 3672 | backing_int = backing_int_res.expr; |
| 3669 | extra_index += 1; // backing_int_ref | 3673 | extra_index += 1; // backing_int_ref |
| 3670 | } else { | 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 | const break_inst = backing_int_body[backing_int_body.len - 1]; | 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 | const backing_int_res = try self.walkRef( | 3678 | const backing_int_res = try self.walkRef( |
| 3675 | file, | 3679 | file, |
| 3676 | &scope, | 3680 | &scope, |
| ... | @@ -3695,7 +3699,7 @@ fn walkInstruction( | ... | @@ -3695,7 +3699,7 @@ fn walkInstruction( |
| 3695 | extra_index = try self.analyzeAllDecls( | 3699 | extra_index = try self.analyzeAllDecls( |
| 3696 | file, | 3700 | file, |
| 3697 | &scope, | 3701 | &scope, |
| 3698 | inst_index, | 3702 | inst, |
| 3699 | src_info, | 3703 | src_info, |
| 3700 | &decl_indexes, | 3704 | &decl_indexes, |
| 3701 | &priv_decl_indexes, | 3705 | &priv_decl_indexes, |
| ... | @@ -3739,7 +3743,7 @@ fn walkInstruction( | ... | @@ -3739,7 +3743,7 @@ fn walkInstruction( |
| 3739 | for (paths.items) |resume_info| { | 3743 | for (paths.items) |resume_info| { |
| 3740 | try self.tryResolveRefPath( | 3744 | try self.tryResolveRefPath( |
| 3741 | resume_info.file, | 3745 | resume_info.file, |
| 3742 | inst_index, | 3746 | inst, |
| 3743 | resume_info.ref_path, | 3747 | resume_info.ref_path, |
| 3744 | ); | 3748 | ); |
| 3745 | } | 3749 | } |
| ... | @@ -3883,7 +3887,7 @@ fn walkInstruction( | ... | @@ -3883,7 +3887,7 @@ fn walkInstruction( |
| 3883 | 3887 | ||
| 3884 | const cmpxchg_index = self.exprs.items.len; | 3888 | const cmpxchg_index = self.exprs.items.len; |
| 3885 | try self.exprs.append(self.arena, .{ .cmpxchg = .{ | 3889 | try self.exprs.append(self.arena, .{ .cmpxchg = .{ |
| 3886 | .name = @tagName(tags[inst_index]), | 3890 | .name = @tagName(tags[@intFromEnum(inst)]), |
| 3887 | .type = type_index, | 3891 | .type = type_index, |
| 3888 | .ptr = ptr_index, | 3892 | .ptr = ptr_index, |
| 3889 | .expected_value = expected_value_index, | 3893 | .expected_value = expected_value_index, |
| ... | @@ -3912,14 +3916,14 @@ fn analyzeAllDecls( | ... | @@ -3912,14 +3916,14 @@ fn analyzeAllDecls( |
| 3912 | self: *Autodoc, | 3916 | self: *Autodoc, |
| 3913 | file: *File, | 3917 | file: *File, |
| 3914 | scope: *Scope, | 3918 | scope: *Scope, |
| 3915 | parent_inst_index: usize, | 3919 | parent_inst: Zir.Inst.Index, |
| 3916 | parent_src: SrcLocInfo, | 3920 | parent_src: SrcLocInfo, |
| 3917 | decl_indexes: *std.ArrayListUnmanaged(usize), | 3921 | decl_indexes: *std.ArrayListUnmanaged(usize), |
| 3918 | priv_decl_indexes: *std.ArrayListUnmanaged(usize), | 3922 | priv_decl_indexes: *std.ArrayListUnmanaged(usize), |
| 3919 | call_ctx: ?*const CallContext, | 3923 | call_ctx: ?*const CallContext, |
| 3920 | ) AutodocErrors!usize { | 3924 | ) AutodocErrors!usize { |
| 3921 | const first_decl_indexes_slot = decl_indexes.items.len; | 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 | // First loop to discover decl names | 3928 | // First loop to discover decl names |
| 3925 | { | 3929 | { |
| ... | @@ -4038,7 +4042,7 @@ fn analyzeDecl( | ... | @@ -4038,7 +4042,7 @@ fn analyzeDecl( |
| 4038 | const decl_name_index = file.zir.extra[extra_index]; | 4042 | const decl_name_index = file.zir.extra[extra_index]; |
| 4039 | 4043 | ||
| 4040 | extra_index += 1; | 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 | extra_index += 1; | 4047 | extra_index += 1; |
| 4044 | const doc_comment_index = file.zir.extra[extra_index]; | 4048 | const doc_comment_index = file.zir.extra[extra_index]; |
| ... | @@ -4066,7 +4070,7 @@ fn analyzeDecl( | ... | @@ -4066,7 +4070,7 @@ fn analyzeDecl( |
| 4066 | _ = addrspace_inst; | 4070 | _ = addrspace_inst; |
| 4067 | 4071 | ||
| 4068 | // This is known to work because decl values are always block_inlines | 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 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); | 4074 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 4071 | 4075 | ||
| 4072 | const name: []const u8 = switch (decl_name_index) { | 4076 | const name: []const u8 = switch (decl_name_index) { |
| ... | @@ -4124,7 +4128,7 @@ fn analyzeDecl( | ... | @@ -4124,7 +4128,7 @@ fn analyzeDecl( |
| 4124 | try priv_decl_indexes.append(self.arena, decls_slot_index); | 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 | std.debug.assert(decl_status_ptr.* == .Pending); | 4132 | std.debug.assert(decl_status_ptr.* == .Pending); |
| 4129 | decl_status_ptr.* = .{ .Analyzed = decls_slot_index }; | 4133 | decl_status_ptr.* = .{ .Analyzed = decls_slot_index }; |
| 4130 | 4134 | ||
| ... | @@ -4158,11 +4162,11 @@ fn analyzeUsingnamespaceDecl( | ... | @@ -4158,11 +4162,11 @@ fn analyzeUsingnamespaceDecl( |
| 4158 | const data = file.zir.instructions.items(.data); | 4162 | const data = file.zir.instructions.items(.data); |
| 4159 | 4163 | ||
| 4160 | const is_pub = @as(u1, @truncate(d.flags)) != 0; | 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 | const doc_comment_index = file.zir.extra[@intFromEnum(d.sub_index) + 7]; | 4166 | const doc_comment_index = file.zir.extra[@intFromEnum(d.sub_index) + 7]; |
| 4163 | 4167 | ||
| 4164 | // This is known to work because decl values are always block_inlines | 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 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); | 4170 | const decl_src = try self.srcLocInfo(file, value_pl_node.src_node, parent_src); |
| 4167 | 4171 | ||
| 4168 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) | 4172 | const doc_comment: ?[]const u8 = if (doc_comment_index != 0) |
| ... | @@ -4244,7 +4248,7 @@ fn analyzeDecltest( | ... | @@ -4244,7 +4248,7 @@ fn analyzeDecltest( |
| 4244 | break :idx idx; | 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 | switch (decl_status.*) { | 4253 | switch (decl_status.*) { |
| 4250 | .Analyzed => |idx| { | 4254 | .Analyzed => |idx| { |
| ... | @@ -4277,7 +4281,7 @@ fn tryResolveRefPath( | ... | @@ -4277,7 +4281,7 @@ fn tryResolveRefPath( |
| 4277 | self: *Autodoc, | 4281 | self: *Autodoc, |
| 4278 | /// File from which the decl path originates. | 4282 | /// File from which the decl path originates. |
| 4279 | file: *File, | 4283 | file: *File, |
| 4280 | inst_index: usize, // used only for panicWithContext | 4284 | inst: Zir.Inst.Index, // used only for panicWithContext |
| 4281 | path: []DocData.Expr, | 4285 | path: []DocData.Expr, |
| 4282 | ) AutodocErrors!void { | 4286 | ) AutodocErrors!void { |
| 4283 | var i: usize = 0; | 4287 | var i: usize = 0; |
| ... | @@ -4374,7 +4378,7 @@ fn tryResolveRefPath( | ... | @@ -4374,7 +4378,7 @@ fn tryResolveRefPath( |
| 4374 | } else { | 4378 | } else { |
| 4375 | panicWithContext( | 4379 | panicWithContext( |
| 4376 | file, | 4380 | file, |
| 4377 | inst_index, | 4381 | inst, |
| 4378 | "exhausted eval quota for `{}`in tryResolveRefPath\n", | 4382 | "exhausted eval quota for `{}`in tryResolveRefPath\n", |
| 4379 | .{resolved_parent}, | 4383 | .{resolved_parent}, |
| 4380 | ); | 4384 | ); |
| ... | @@ -4386,7 +4390,7 @@ fn tryResolveRefPath( | ... | @@ -4386,7 +4390,7 @@ fn tryResolveRefPath( |
| 4386 | // in the switch above this one! | 4390 | // in the switch above this one! |
| 4387 | printWithContext( | 4391 | printWithContext( |
| 4388 | file, | 4392 | file, |
| 4389 | inst_index, | 4393 | inst, |
| 4390 | "TODO: handle `{s}`in tryResolveRefPath\nInfo: {}", | 4394 | "TODO: handle `{s}`in tryResolveRefPath\nInfo: {}", |
| 4391 | .{ @tagName(resolved_parent), resolved_parent }, | 4395 | .{ @tagName(resolved_parent), resolved_parent }, |
| 4392 | ); | 4396 | ); |
| ... | @@ -4403,7 +4407,7 @@ fn tryResolveRefPath( | ... | @@ -4403,7 +4407,7 @@ fn tryResolveRefPath( |
| 4403 | else => { | 4407 | else => { |
| 4404 | panicWithContext( | 4408 | panicWithContext( |
| 4405 | file, | 4409 | file, |
| 4406 | inst_index, | 4410 | inst, |
| 4407 | "TODO: handle `{s}` in tryResolveDeclPath.type\nInfo: {}", | 4411 | "TODO: handle `{s}` in tryResolveDeclPath.type\nInfo: {}", |
| 4408 | .{ @tagName(self.types.items[t_index]), resolved_parent }, | 4412 | .{ @tagName(self.types.items[t_index]), resolved_parent }, |
| 4409 | ); | 4413 | ); |
| ... | @@ -4442,7 +4446,7 @@ fn tryResolveRefPath( | ... | @@ -4442,7 +4446,7 @@ fn tryResolveRefPath( |
| 4442 | } else { | 4446 | } else { |
| 4443 | panicWithContext( | 4447 | panicWithContext( |
| 4444 | file, | 4448 | file, |
| 4445 | inst_index, | 4449 | inst, |
| 4446 | "TODO: handle `{s}` in tryResolveDeclPath.type.Array\nInfo: {}", | 4450 | "TODO: handle `{s}` in tryResolveDeclPath.type.Array\nInfo: {}", |
| 4447 | .{ child_string, resolved_parent }, | 4451 | .{ child_string, resolved_parent }, |
| 4448 | ); | 4452 | ); |
| ... | @@ -4500,7 +4504,7 @@ fn tryResolveRefPath( | ... | @@ -4500,7 +4504,7 @@ fn tryResolveRefPath( |
| 4500 | // if we got here, our search failed | 4504 | // if we got here, our search failed |
| 4501 | printWithContext( | 4505 | printWithContext( |
| 4502 | file, | 4506 | file, |
| 4503 | inst_index, | 4507 | inst, |
| 4504 | "failed to match `{s}` in enum", | 4508 | "failed to match `{s}` in enum", |
| 4505 | .{child_string}, | 4509 | .{child_string}, |
| 4506 | ); | 4510 | ); |
| ... | @@ -4557,7 +4561,7 @@ fn tryResolveRefPath( | ... | @@ -4557,7 +4561,7 @@ fn tryResolveRefPath( |
| 4557 | // if we got here, our search failed | 4561 | // if we got here, our search failed |
| 4558 | printWithContext( | 4562 | printWithContext( |
| 4559 | file, | 4563 | file, |
| 4560 | inst_index, | 4564 | inst, |
| 4561 | "failed to match `{s}` in union", | 4565 | "failed to match `{s}` in union", |
| 4562 | .{child_string}, | 4566 | .{child_string}, |
| 4563 | ); | 4567 | ); |
| ... | @@ -4614,7 +4618,7 @@ fn tryResolveRefPath( | ... | @@ -4614,7 +4618,7 @@ fn tryResolveRefPath( |
| 4614 | // if we got here, our search failed | 4618 | // if we got here, our search failed |
| 4615 | // printWithContext( | 4619 | // printWithContext( |
| 4616 | // file, | 4620 | // file, |
| 4617 | // inst_index, | 4621 | // inst, |
| 4618 | // "failed to match `{s}` in struct", | 4622 | // "failed to match `{s}` in struct", |
| 4619 | // .{child_string}, | 4623 | // .{child_string}, |
| 4620 | // ); | 4624 | // ); |
| ... | @@ -4659,7 +4663,7 @@ fn tryResolveRefPath( | ... | @@ -4659,7 +4663,7 @@ fn tryResolveRefPath( |
| 4659 | // if we got here, our search failed | 4663 | // if we got here, our search failed |
| 4660 | printWithContext( | 4664 | printWithContext( |
| 4661 | file, | 4665 | file, |
| 4662 | inst_index, | 4666 | inst, |
| 4663 | "failed to match `{s}` in opaque", | 4667 | "failed to match `{s}` in opaque", |
| 4664 | .{child_string}, | 4668 | .{child_string}, |
| 4665 | ); | 4669 | ); |
| ... | @@ -4679,7 +4683,7 @@ fn tryResolveRefPath( | ... | @@ -4679,7 +4683,7 @@ fn tryResolveRefPath( |
| 4679 | // if we got here, our search failed | 4683 | // if we got here, our search failed |
| 4680 | printWithContext( | 4684 | printWithContext( |
| 4681 | file, | 4685 | file, |
| 4682 | inst_index, | 4686 | inst, |
| 4683 | "failed to match `{s}` in struct", | 4687 | "failed to match `{s}` in struct", |
| 4684 | .{child_string}, | 4688 | .{child_string}, |
| 4685 | ); | 4689 | ); |
| ... | @@ -4696,7 +4700,7 @@ fn tryResolveRefPath( | ... | @@ -4696,7 +4700,7 @@ fn tryResolveRefPath( |
| 4696 | _ = self.pending_ref_paths.remove(&path[path.len - 1]); | 4700 | _ = self.pending_ref_paths.remove(&path[path.len - 1]); |
| 4697 | 4701 | ||
| 4698 | for (waiter_list.items) |resume_info| { | 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 | // TODO: this is where we should free waiter_list, but its in the arena | 4705 | // TODO: this is where we should free waiter_list, but its in the arena |
| 4702 | // that said, we might want to store it elsewhere and reclaim memory asap | 4706 | // that said, we might want to store it elsewhere and reclaim memory asap |
| ... | @@ -4805,14 +4809,14 @@ fn analyzeFancyFunction( | ... | @@ -4805,14 +4809,14 @@ fn analyzeFancyFunction( |
| 4805 | file: *File, | 4809 | file: *File, |
| 4806 | scope: *Scope, | 4810 | scope: *Scope, |
| 4807 | parent_src: SrcLocInfo, | 4811 | parent_src: SrcLocInfo, |
| 4808 | inst_index: usize, | 4812 | inst: Zir.Inst.Index, |
| 4809 | self_ast_node_index: usize, | 4813 | self_ast_node_index: usize, |
| 4810 | type_slot_index: usize, | 4814 | type_slot_index: usize, |
| 4811 | call_ctx: ?*const CallContext, | 4815 | call_ctx: ?*const CallContext, |
| 4812 | ) AutodocErrors!DocData.WalkResult { | 4816 | ) AutodocErrors!DocData.WalkResult { |
| 4813 | const tags = file.zir.instructions.items(.tag); | 4817 | const tags = file.zir.instructions.items(.tag); |
| 4814 | const data = file.zir.instructions.items(.data); | 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 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); | 4821 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 4818 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( | 4822 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( |
| ... | @@ -4826,18 +4830,18 @@ fn analyzeFancyFunction( | ... | @@ -4826,18 +4830,18 @@ fn analyzeFancyFunction( |
| 4826 | 4830 | ||
| 4827 | // TODO: handle scope rules for fn parameters | 4831 | // TODO: handle scope rules for fn parameters |
| 4828 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { | 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 | else => { | 4834 | else => { |
| 4831 | panicWithContext( | 4835 | panicWithContext( |
| 4832 | file, | 4836 | file, |
| 4833 | param_index, | 4837 | param_index, |
| 4834 | "TODO: handle `{s}` in walkInstruction.func\n", | 4838 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 4835 | .{@tagName(tags[param_index])}, | 4839 | .{@tagName(tags[@intFromEnum(param_index)])}, |
| 4836 | ); | 4840 | ); |
| 4837 | }, | 4841 | }, |
| 4838 | .param_anytype, .param_anytype_comptime => { | 4842 | .param_anytype, .param_anytype_comptime => { |
| 4839 | // TODO: where are the doc comments? | 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 | const name = str_tok.get(file.zir); | 4846 | const name = str_tok.get(file.zir); |
| 4843 | 4847 | ||
| ... | @@ -4845,7 +4849,7 @@ fn analyzeFancyFunction( | ... | @@ -4845,7 +4849,7 @@ fn analyzeFancyFunction( |
| 4845 | self.ast_nodes.appendAssumeCapacity(.{ | 4849 | self.ast_nodes.appendAssumeCapacity(.{ |
| 4846 | .name = name, | 4850 | .name = name, |
| 4847 | .docs = "", | 4851 | .docs = "", |
| 4848 | .@"comptime" = tags[param_index] == .param_anytype_comptime, | 4852 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime, |
| 4849 | }); | 4853 | }); |
| 4850 | 4854 | ||
| 4851 | param_type_refs.appendAssumeCapacity( | 4855 | param_type_refs.appendAssumeCapacity( |
| ... | @@ -4853,7 +4857,7 @@ fn analyzeFancyFunction( | ... | @@ -4853,7 +4857,7 @@ fn analyzeFancyFunction( |
| 4853 | ); | 4857 | ); |
| 4854 | }, | 4858 | }, |
| 4855 | .param, .param_comptime => { | 4859 | .param, .param_comptime => { |
| 4856 | const pl_tok = data[param_index].pl_tok; | 4860 | const pl_tok = data[@intFromEnum(param_index)].pl_tok; |
| 4857 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); | 4861 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 4858 | const doc_comment = if (extra.data.doc_comment != 0) | 4862 | const doc_comment = if (extra.data.doc_comment != 0) |
| 4859 | file.zir.nullTerminatedString(extra.data.doc_comment) | 4863 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| ... | @@ -4865,7 +4869,7 @@ fn analyzeFancyFunction( | ... | @@ -4865,7 +4869,7 @@ fn analyzeFancyFunction( |
| 4865 | try self.ast_nodes.append(self.arena, .{ | 4869 | try self.ast_nodes.append(self.arena, .{ |
| 4866 | .name = name, | 4870 | .name = name, |
| 4867 | .docs = doc_comment, | 4871 | .docs = doc_comment, |
| 4868 | .@"comptime" = tags[param_index] == .param_comptime, | 4872 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime, |
| 4869 | }); | 4873 | }); |
| 4870 | 4874 | ||
| 4871 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; | 4875 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| ... | @@ -4886,7 +4890,7 @@ fn analyzeFancyFunction( | ... | @@ -4886,7 +4890,7 @@ fn analyzeFancyFunction( |
| 4886 | 4890 | ||
| 4887 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; | 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 | const extra = file.zir.extraData(Zir.Inst.FuncFancy, pl_node.payload_index); | 4894 | const extra = file.zir.extraData(Zir.Inst.FuncFancy, pl_node.payload_index); |
| 4891 | 4895 | ||
| 4892 | var extra_index: usize = extra.end; | 4896 | var extra_index: usize = extra.end; |
| ... | @@ -4971,7 +4975,7 @@ fn analyzeFancyFunction( | ... | @@ -4971,7 +4975,7 @@ fn analyzeFancyFunction( |
| 4971 | 4975 | ||
| 4972 | var cc_index: ?usize = null; | 4976 | var cc_index: ?usize = null; |
| 4973 | if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) { | 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 | const cc_expr = try self.walkRef( | 4979 | const cc_expr = try self.walkRef( |
| 4976 | file, | 4980 | file, |
| 4977 | scope, | 4981 | scope, |
| ... | @@ -4988,11 +4992,11 @@ fn analyzeFancyFunction( | ... | @@ -4988,11 +4992,11 @@ fn analyzeFancyFunction( |
| 4988 | } else if (extra.data.bits.has_cc_body) { | 4992 | } else if (extra.data.bits.has_cc_body) { |
| 4989 | const cc_body_len = file.zir.extra[extra_index]; | 4993 | const cc_body_len = file.zir.extra[extra_index]; |
| 4990 | extra_index += 1; | 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 | // We assume the body ends with a break_inline | 4997 | // We assume the body ends with a break_inline |
| 4994 | const break_index = cc_body[cc_body.len - 1]; | 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 | const cc_expr = try self.walkRef( | 5000 | const cc_expr = try self.walkRef( |
| 4997 | file, | 5001 | file, |
| 4998 | scope, | 5002 | scope, |
| ... | @@ -5029,7 +5033,7 @@ fn analyzeFancyFunction( | ... | @@ -5029,7 +5033,7 @@ fn analyzeFancyFunction( |
| 5029 | }, | 5033 | }, |
| 5030 | else => blk: { | 5034 | else => blk: { |
| 5031 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; | 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 | const wr = try self.walkRef( | 5037 | const wr = try self.walkRef( |
| 5034 | file, | 5038 | file, |
| 5035 | scope, | 5039 | scope, |
| ... | @@ -5096,7 +5100,7 @@ fn analyzeFunction( | ... | @@ -5096,7 +5100,7 @@ fn analyzeFunction( |
| 5096 | file: *File, | 5100 | file: *File, |
| 5097 | scope: *Scope, | 5101 | scope: *Scope, |
| 5098 | parent_src: SrcLocInfo, | 5102 | parent_src: SrcLocInfo, |
| 5099 | inst_index: usize, | 5103 | inst: Zir.Inst.Index, |
| 5100 | self_ast_node_index: usize, | 5104 | self_ast_node_index: usize, |
| 5101 | type_slot_index: usize, | 5105 | type_slot_index: usize, |
| 5102 | ret_is_inferred_error_set: bool, | 5106 | ret_is_inferred_error_set: bool, |
| ... | @@ -5104,7 +5108,7 @@ fn analyzeFunction( | ... | @@ -5104,7 +5108,7 @@ fn analyzeFunction( |
| 5104 | ) AutodocErrors!DocData.WalkResult { | 5108 | ) AutodocErrors!DocData.WalkResult { |
| 5105 | const tags = file.zir.instructions.items(.tag); | 5109 | const tags = file.zir.instructions.items(.tag); |
| 5106 | const data = file.zir.instructions.items(.data); | 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 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); | 5113 | try self.ast_nodes.ensureUnusedCapacity(self.arena, fn_info.total_params_len); |
| 5110 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( | 5114 | var param_type_refs = try std.ArrayListUnmanaged(DocData.Expr).initCapacity( |
| ... | @@ -5118,18 +5122,18 @@ fn analyzeFunction( | ... | @@ -5118,18 +5122,18 @@ fn analyzeFunction( |
| 5118 | 5122 | ||
| 5119 | // TODO: handle scope rules for fn parameters | 5123 | // TODO: handle scope rules for fn parameters |
| 5120 | for (fn_info.param_body[0..fn_info.total_params_len]) |param_index| { | 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 | else => { | 5126 | else => { |
| 5123 | panicWithContext( | 5127 | panicWithContext( |
| 5124 | file, | 5128 | file, |
| 5125 | param_index, | 5129 | param_index, |
| 5126 | "TODO: handle `{s}` in walkInstruction.func\n", | 5130 | "TODO: handle `{s}` in walkInstruction.func\n", |
| 5127 | .{@tagName(tags[param_index])}, | 5131 | .{@tagName(tags[@intFromEnum(param_index)])}, |
| 5128 | ); | 5132 | ); |
| 5129 | }, | 5133 | }, |
| 5130 | .param_anytype, .param_anytype_comptime => { | 5134 | .param_anytype, .param_anytype_comptime => { |
| 5131 | // TODO: where are the doc comments? | 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 | const name = str_tok.get(file.zir); | 5138 | const name = str_tok.get(file.zir); |
| 5135 | 5139 | ||
| ... | @@ -5137,7 +5141,7 @@ fn analyzeFunction( | ... | @@ -5137,7 +5141,7 @@ fn analyzeFunction( |
| 5137 | self.ast_nodes.appendAssumeCapacity(.{ | 5141 | self.ast_nodes.appendAssumeCapacity(.{ |
| 5138 | .name = name, | 5142 | .name = name, |
| 5139 | .docs = "", | 5143 | .docs = "", |
| 5140 | .@"comptime" = tags[param_index] == .param_anytype_comptime, | 5144 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_anytype_comptime, |
| 5141 | }); | 5145 | }); |
| 5142 | 5146 | ||
| 5143 | param_type_refs.appendAssumeCapacity( | 5147 | param_type_refs.appendAssumeCapacity( |
| ... | @@ -5145,7 +5149,7 @@ fn analyzeFunction( | ... | @@ -5145,7 +5149,7 @@ fn analyzeFunction( |
| 5145 | ); | 5149 | ); |
| 5146 | }, | 5150 | }, |
| 5147 | .param, .param_comptime => { | 5151 | .param, .param_comptime => { |
| 5148 | const pl_tok = data[param_index].pl_tok; | 5152 | const pl_tok = data[@intFromEnum(param_index)].pl_tok; |
| 5149 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); | 5153 | const extra = file.zir.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 5150 | const doc_comment = if (extra.data.doc_comment != 0) | 5154 | const doc_comment = if (extra.data.doc_comment != 0) |
| 5151 | file.zir.nullTerminatedString(extra.data.doc_comment) | 5155 | file.zir.nullTerminatedString(extra.data.doc_comment) |
| ... | @@ -5157,7 +5161,7 @@ fn analyzeFunction( | ... | @@ -5157,7 +5161,7 @@ fn analyzeFunction( |
| 5157 | try self.ast_nodes.append(self.arena, .{ | 5161 | try self.ast_nodes.append(self.arena, .{ |
| 5158 | .name = name, | 5162 | .name = name, |
| 5159 | .docs = doc_comment, | 5163 | .docs = doc_comment, |
| 5160 | .@"comptime" = tags[param_index] == .param_comptime, | 5164 | .@"comptime" = tags[@intFromEnum(param_index)] == .param_comptime, |
| 5161 | }); | 5165 | }); |
| 5162 | 5166 | ||
| 5163 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; | 5167 | const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1]; |
| ... | @@ -5195,7 +5199,7 @@ fn analyzeFunction( | ... | @@ -5195,7 +5199,7 @@ fn analyzeFunction( |
| 5195 | }, | 5199 | }, |
| 5196 | else => blk: { | 5200 | else => blk: { |
| 5197 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; | 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 | const wr = try self.walkRef( | 5203 | const wr = try self.walkRef( |
| 5200 | file, | 5204 | file, |
| 5201 | scope, | 5205 | scope, |
| ... | @@ -5266,7 +5270,7 @@ fn getGenericReturnType( | ... | @@ -5266,7 +5270,7 @@ fn getGenericReturnType( |
| 5266 | file: *File, | 5270 | file: *File, |
| 5267 | scope: *Scope, | 5271 | scope: *Scope, |
| 5268 | parent_src: SrcLocInfo, // function decl line | 5272 | parent_src: SrcLocInfo, // function decl line |
| 5269 | body_main_block: usize, | 5273 | body_main_block: Zir.Inst.Index, |
| 5270 | call_ctx: ?*const CallContext, | 5274 | call_ctx: ?*const CallContext, |
| 5271 | ) !DocData.Expr { | 5275 | ) !DocData.Expr { |
| 5272 | const tags = file.zir.instructions.items(.tag); | 5276 | const tags = file.zir.instructions.items(.tag); |
| ... | @@ -5274,25 +5278,27 @@ fn getGenericReturnType( | ... | @@ -5274,25 +5278,27 @@ fn getGenericReturnType( |
| 5274 | 5278 | ||
| 5275 | // We expect `body_main_block` to be the first instruction | 5279 | // We expect `body_main_block` to be the first instruction |
| 5276 | // inside the function body, and for it to be a block instruction. | 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 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); | 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]; | 5283 | const body = file.zir.bodySlice(extra.end, extra.data.body_len); |
| 5280 | switch (tags[maybe_ret_node]) { | 5284 | if (body.len >= 4) { |
| 5281 | .ret_node, .ret_load => { | 5285 | const maybe_ret_inst = body[body.len - 4]; |
| 5282 | const wr = try self.walkInstruction( | 5286 | switch (tags[@intFromEnum(maybe_ret_inst)]) { |
| 5283 | file, | 5287 | .ret_node, .ret_load => { |
| 5284 | scope, | 5288 | const wr = try self.walkInstruction( |
| 5285 | parent_src, | 5289 | file, |
| 5286 | maybe_ret_node, | 5290 | scope, |
| 5287 | false, | 5291 | parent_src, |
| 5288 | call_ctx, | 5292 | maybe_ret_inst, |
| 5289 | ); | 5293 | false, |
| 5290 | return wr.expr; | 5294 | call_ctx, |
| 5291 | }, | 5295 | ); |
| 5292 | else => { | 5296 | return wr.expr; |
| 5293 | return DocData.Expr{ .comptimeExpr = 0 }; | 5297 | }, |
| 5294 | }, | 5298 | else => {}, |
| 5299 | } | ||
| 5295 | } | 5300 | } |
| 5301 | return DocData.Expr{ .comptimeExpr = 0 }; | ||
| 5296 | } | 5302 | } |
| 5297 | 5303 | ||
| 5298 | fn collectUnionFieldInfo( | 5304 | fn collectUnionFieldInfo( |
| ... | @@ -5470,11 +5476,11 @@ fn collectStructFieldInfo( | ... | @@ -5470,11 +5476,11 @@ fn collectStructFieldInfo( |
| 5470 | } | 5476 | } |
| 5471 | 5477 | ||
| 5472 | std.debug.assert(field.type_body_len != 0); | 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 | extra_index += body.len; | 5480 | extra_index += body.len; |
| 5475 | 5481 | ||
| 5476 | const break_inst = body[body.len - 1]; | 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 | try self.ast_nodes.append(self.arena, .{ | 5484 | try self.ast_nodes.append(self.arena, .{ |
| 5479 | .file = self.files.getIndex(file).?, | 5485 | .file = self.files.getIndex(file).?, |
| 5480 | .line = parent_src.line, | 5486 | .line = parent_src.line, |
| ... | @@ -5499,11 +5505,11 @@ fn collectStructFieldInfo( | ... | @@ -5499,11 +5505,11 @@ fn collectStructFieldInfo( |
| 5499 | break :def null; | 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 | extra_index += body.len; | 5509 | extra_index += body.len; |
| 5504 | 5510 | ||
| 5505 | const break_inst = body[body.len - 1]; | 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 | const walk_result = try self.walkRef( | 5513 | const walk_result = try self.walkRef( |
| 5508 | file, | 5514 | file, |
| 5509 | scope, | 5515 | scope, |
| ... | @@ -5559,7 +5565,7 @@ fn walkRef( | ... | @@ -5559,7 +5565,7 @@ fn walkRef( |
| 5559 | .typeRef = .{ .type = @intFromEnum(std.builtin.TypeId.Type) }, | 5565 | .typeRef = .{ .type = @intFromEnum(std.builtin.TypeId.Type) }, |
| 5560 | .expr = .{ .type = @intFromEnum(ref) }, | 5566 | .expr = .{ .type = @intFromEnum(ref) }, |
| 5561 | }; | 5567 | }; |
| 5562 | } else if (Zir.refToIndex(ref)) |zir_index| { | 5568 | } else if (ref.toIndex()) |zir_index| { |
| 5563 | return self.walkInstruction( | 5569 | return self.walkInstruction( |
| 5564 | file, | 5570 | file, |
| 5565 | parent_scope, | 5571 | parent_scope, |
| ... | @@ -5571,9 +5577,9 @@ fn walkRef( | ... | @@ -5571,9 +5577,9 @@ fn walkRef( |
| 5571 | } else { | 5577 | } else { |
| 5572 | switch (ref) { | 5578 | switch (ref) { |
| 5573 | else => { | 5579 | else => { |
| 5574 | panicWithContext( | 5580 | panicWithOptionalContext( |
| 5575 | file, | 5581 | file, |
| 5576 | 0, | 5582 | .none, |
| 5577 | "TODO: handle {s} in walkRef", | 5583 | "TODO: handle {s} in walkRef", |
| 5578 | .{@tagName(ref)}, | 5584 | .{@tagName(ref)}, |
| 5579 | ); | 5585 | ); |
| ... | @@ -5664,10 +5670,10 @@ fn walkRef( | ... | @@ -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 | const tags = zir.instructions.items(.tag); | 5674 | const tags = zir.instructions.items(.tag); |
| 5669 | const data = zir.instructions.items(.data); | 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 | const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index); | 5677 | const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 5672 | const break_index = zir.extra[extra.end..][extra.data.body_len - 1]; | 5678 | const break_index = zir.extra[extra.end..][extra.data.body_len - 1]; |
| 5673 | if (tags[break_index] == .condbr_inline) return null; | 5679 | if (tags[break_index] == .condbr_inline) return null; |
| ... | @@ -5675,12 +5681,36 @@ fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref { | ... | @@ -5675,12 +5681,36 @@ fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref { |
| 5675 | return data[break_index].@"break".operand; | 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 | log.debug("Context [{s}] % {} \n " ++ fmt, .{ file.sub_file_path, inst } ++ args); | 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 { | 5697 | fn panicWithContext( |
| 5683 | printWithContext(file, inst, fmt, args); | 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 | unreachable; | 5714 | unreachable; |
| 5685 | } | 5715 | } |
| 5686 | 5716 |
src/InternPool.zig+14-5| ... | @@ -580,7 +580,7 @@ pub const Key = union(enum) { | ... | @@ -580,7 +580,7 @@ pub const Key = union(enum) { |
| 580 | pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: Zir.Inst.Index) void { | 580 | pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: Zir.Inst.Index) void { |
| 581 | assert(s.layout != .Packed); | 581 | assert(s.layout != .Packed); |
| 582 | const field_index = std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?; | 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 | pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool { | 586 | pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool { |
| ... | @@ -2481,7 +2481,14 @@ pub const static_keys = [_]Key{ | ... | @@ -2481,7 +2481,14 @@ pub const static_keys = [_]Key{ |
| 2481 | }; | 2481 | }; |
| 2482 | 2482 | ||
| 2483 | /// How many items in the InternPool are statically known. | 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 | pub const Tag = enum(u8) { | 2493 | pub const Tag = enum(u8) { |
| 2487 | /// An integer type. | 2494 | /// An integer type. |
| ... | @@ -3658,7 +3665,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -3658,7 +3665,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3658 | .extra_index = 0, | 3665 | .extra_index = 0, |
| 3659 | .namespace = .none, | 3666 | .namespace = .none, |
| 3660 | .decl = .none, | 3667 | .decl = .none, |
| 3661 | .zir_index = @as(u32, undefined), | 3668 | .zir_index = undefined, |
| 3662 | .layout = .Auto, | 3669 | .layout = .Auto, |
| 3663 | .field_names = .{ .start = 0, .len = 0 }, | 3670 | .field_names = .{ .start = 0, .len = 0 }, |
| 3664 | .field_types = .{ .start = 0, .len = 0 }, | 3671 | .field_types = .{ .start = 0, .len = 0 }, |
| ... | @@ -3674,7 +3681,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -3674,7 +3681,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3674 | .extra_index = 0, | 3681 | .extra_index = 0, |
| 3675 | .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(), | 3682 | .namespace = @as(Module.Namespace.Index, @enumFromInt(data)).toOptional(), |
| 3676 | .decl = .none, | 3683 | .decl = .none, |
| 3677 | .zir_index = @as(u32, undefined), | 3684 | .zir_index = undefined, |
| 3678 | .layout = .Auto, | 3685 | .layout = .Auto, |
| 3679 | .field_names = .{ .start = 0, .len = 0 }, | 3686 | .field_names = .{ .start = 0, .len = 0 }, |
| 3680 | .field_types = .{ .start = 0, .len = 0 }, | 3687 | .field_types = .{ .start = 0, .len = 0 }, |
| ... | @@ -6403,6 +6410,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { | ... | @@ -6403,6 +6410,7 @@ fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 6403 | NullTerminatedString, | 6410 | NullTerminatedString, |
| 6404 | OptionalNullTerminatedString, | 6411 | OptionalNullTerminatedString, |
| 6405 | Tag.TypePointer.VectorIndex, | 6412 | Tag.TypePointer.VectorIndex, |
| 6413 | Zir.Inst.Index, | ||
| 6406 | => @intFromEnum(@field(extra, field.name)), | 6414 | => @intFromEnum(@field(extra, field.name)), |
| 6407 | 6415 | ||
| 6408 | u32, | 6416 | u32, |
| ... | @@ -6477,6 +6485,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct | ... | @@ -6477,6 +6485,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct |
| 6477 | NullTerminatedString, | 6485 | NullTerminatedString, |
| 6478 | OptionalNullTerminatedString, | 6486 | OptionalNullTerminatedString, |
| 6479 | Tag.TypePointer.VectorIndex, | 6487 | Tag.TypePointer.VectorIndex, |
| 6488 | Zir.Inst.Index, | ||
| 6480 | => @enumFromInt(int32), | 6489 | => @enumFromInt(int32), |
| 6481 | 6490 | ||
| 6482 | u32, | 6491 | u32, |
| ... | @@ -8191,7 +8200,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { | ... | @@ -8191,7 +8200,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { |
| 8191 | }, | 8200 | }, |
| 8192 | else => unreachable, | 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 | pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index { | 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,7 +389,7 @@ pub const Decl = struct { |
| 389 | /// Index to ZIR `extra` array to the entry in the parent's decl structure | 389 | /// Index to ZIR `extra` array to the entry in the parent's decl structure |
| 390 | /// (the part that says "for every decls_len"). The first item at this index is | 390 | /// (the part that says "for every decls_len"). The first item at this index is |
| 391 | /// the contents hash, followed by line, name, etc. | 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 | zir_decl_index: Zir.OptionalExtraIndex, | 393 | zir_decl_index: Zir.OptionalExtraIndex, |
| 394 | 394 | ||
| 395 | /// Represents the "shallow" analysis status. For example, for decls that are functions, | 395 | /// Represents the "shallow" analysis status. For example, for decls that are functions, |
| ... | @@ -547,7 +547,7 @@ pub const Decl = struct { | ... | @@ -547,7 +547,7 @@ pub const Decl = struct { |
| 547 | pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index { | 547 | pub fn zirBlockIndex(decl: *const Decl, mod: *Module) Zir.Inst.Index { |
| 548 | assert(decl.zir_decl_index != .none); | 548 | assert(decl.zir_decl_index != .none); |
| 549 | const zir = decl.getFileScope(mod).zir; | 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 | pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref { | 553 | pub fn zirAlignRef(decl: Decl, mod: *Module) Zir.Inst.Ref { |
| ... | @@ -1205,9 +1205,8 @@ pub const File = struct { | ... | @@ -1205,9 +1205,8 @@ pub const File = struct { |
| 1205 | if (imports_index == 0) return; | 1205 | if (imports_index == 0) return; |
| 1206 | const extra = file.zir.extraData(Zir.Inst.Imports, imports_index); | 1206 | const extra = file.zir.extraData(Zir.Inst.Imports, imports_index); |
| 1207 | 1207 | ||
| 1208 | var import_i: u32 = 0; | ||
| 1209 | var extra_index = extra.end; | 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 | const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index); | 1210 | const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index); |
| 1212 | extra_index = item.end; | 1211 | extra_index = item.end; |
| 1213 | 1212 | ||
| ... | @@ -3206,8 +3205,8 @@ pub fn mapOldZirToNew( | ... | @@ -3206,8 +3205,8 @@ pub fn mapOldZirToNew( |
| 3206 | 3205 | ||
| 3207 | // Main struct inst is always the same | 3206 | // Main struct inst is always the same |
| 3208 | try match_stack.append(gpa, .{ | 3207 | try match_stack.append(gpa, .{ |
| 3209 | .old_inst = Zir.main_struct_inst, | 3208 | .old_inst = .main_struct_inst, |
| 3210 | .new_inst = Zir.main_struct_inst, | 3209 | .new_inst = .main_struct_inst, |
| 3211 | }); | 3210 | }); |
| 3212 | 3211 | ||
| 3213 | var old_decls = std.ArrayList(Zir.Inst.Index).init(gpa); | 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,11 +3621,10 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 3622 | }; | 3621 | }; |
| 3623 | defer sema.deinit(); | 3622 | defer sema.deinit(); |
| 3624 | 3623 | ||
| 3625 | const main_struct_inst = Zir.main_struct_inst; | ||
| 3626 | const struct_ty = sema.getStructType( | 3624 | const struct_ty = sema.getStructType( |
| 3627 | new_decl_index, | 3625 | new_decl_index, |
| 3628 | new_namespace_index, | 3626 | new_namespace_index, |
| 3629 | main_struct_inst, | 3627 | .main_struct_inst, |
| 3630 | ) catch |err| switch (err) { | 3628 | ) catch |err| switch (err) { |
| 3631 | error.OutOfMemory => return error.OutOfMemory, | 3629 | error.OutOfMemory => return error.OutOfMemory, |
| 3632 | }; | 3630 | }; |
| ... | @@ -3754,11 +3752,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -3754,11 +3752,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 3754 | defer block_scope.instructions.deinit(gpa); | 3752 | defer block_scope.instructions.deinit(gpa); |
| 3755 | 3753 | ||
| 3756 | const zir_block_index = decl.zirBlockIndex(mod); | 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 | const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index); | 3756 | const extra = zir.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 3759 | const body = zir.extra[extra.end..][0..extra.data.body_len]; | 3757 | const body = zir.extra[extra.end..][0..extra.data.body_len]; |
| 3760 | const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand; | 3758 | const result_ref = (try sema.analyzeBodyBreak(&block_scope, @ptrCast(body))).?.operand; |
| 3761 | // We'll do some other bits with the Sema. Clear the type target index just in case they analyze any type. | 3759 | // We'll do some other bits with the Sema. Clear the type target index just |
| 3760 | // in case they analyze any type. | ||
| 3762 | sema.builtin_type_target_index = .none; | 3761 | sema.builtin_type_target_index = .none; |
| 3763 | for (comptime_mutable_decls.items) |ct_decl_index| { | 3762 | for (comptime_mutable_decls.items) |ct_decl_index| { |
| 3764 | const ct_decl = mod.declPtr(ct_decl_index); | 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,13 +6470,13 @@ pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0] |
| 6471 | const param_body = file.zir.getParamBody(func.zir_body_inst); | 6470 | const param_body = file.zir.getParamBody(func.zir_body_inst); |
| 6472 | const param = param_body[index]; | 6471 | const param = param_body[index]; |
| 6473 | 6472 | ||
| 6474 | return switch (tags[param]) { | 6473 | return switch (tags[@intFromEnum(param)]) { |
| 6475 | .param, .param_comptime => blk: { | 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 | break :blk file.zir.nullTerminatedString(extra.data.name); | 6476 | break :blk file.zir.nullTerminatedString(extra.data.name); |
| 6478 | }, | 6477 | }, |
| 6479 | .param_anytype, .param_anytype_comptime => blk: { | 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 | break :blk param_data.get(file.zir); | 6480 | break :blk param_data.get(file.zir); |
| 6482 | }, | 6481 | }, |
| 6483 | else => unreachable, | 6482 | else => unreachable, |
src/Sema.zig+370-362| ... | @@ -226,7 +226,7 @@ pub const InferredErrorSet = struct { | ... | @@ -226,7 +226,7 @@ pub const InferredErrorSet = struct { |
| 226 | /// be called safely for any of the instructions passed in. | 226 | /// be called safely for any of the instructions passed in. |
| 227 | pub const InstMap = struct { | 227 | pub const InstMap = struct { |
| 228 | items: []Air.Inst.Ref = &[_]Air.Inst.Ref{}, | 228 | items: []Air.Inst.Ref = &[_]Air.Inst.Ref{}, |
| 229 | start: Zir.Inst.Index = 0, | 229 | start: Zir.Inst.Index = @enumFromInt(0), |
| 230 | 230 | ||
| 231 | pub fn deinit(map: InstMap, allocator: mem.Allocator) void { | 231 | pub fn deinit(map: InstMap, allocator: mem.Allocator) void { |
| 232 | allocator.free(map.items); | 232 | allocator.free(map.items); |
| ... | @@ -234,7 +234,7 @@ pub const InstMap = struct { | ... | @@ -234,7 +234,7 @@ pub const InstMap = struct { |
| 234 | 234 | ||
| 235 | pub fn get(map: InstMap, key: Zir.Inst.Index) ?Air.Inst.Ref { | 235 | pub fn get(map: InstMap, key: Zir.Inst.Index) ?Air.Inst.Ref { |
| 236 | if (!map.contains(key)) return null; | 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 | pub fn putAssumeCapacity( | 240 | pub fn putAssumeCapacity( |
| ... | @@ -242,7 +242,7 @@ pub const InstMap = struct { | ... | @@ -242,7 +242,7 @@ pub const InstMap = struct { |
| 242 | key: Zir.Inst.Index, | 242 | key: Zir.Inst.Index, |
| 243 | ref: Air.Inst.Ref, | 243 | ref: Air.Inst.Ref, |
| 244 | ) void { | 244 | ) void { |
| 245 | map.items[key - map.start] = ref; | 245 | map.items[@intFromEnum(key) - @intFromEnum(map.start)] = ref; |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | pub fn putAssumeCapacityNoClobber( | 248 | pub fn putAssumeCapacityNoClobber( |
| ... | @@ -263,7 +263,7 @@ pub const InstMap = struct { | ... | @@ -263,7 +263,7 @@ pub const InstMap = struct { |
| 263 | map: *InstMap, | 263 | map: *InstMap, |
| 264 | key: Zir.Inst.Index, | 264 | key: Zir.Inst.Index, |
| 265 | ) GetOrPutResult { | 265 | ) GetOrPutResult { |
| 266 | const index = key - map.start; | 266 | const index = @intFromEnum(key) - @intFromEnum(map.start); |
| 267 | return GetOrPutResult{ | 267 | return GetOrPutResult{ |
| 268 | .value_ptr = &map.items[index], | 268 | .value_ptr = &map.items[index], |
| 269 | .found_existing = map.items[index] != .none, | 269 | .found_existing = map.items[index] != .none, |
| ... | @@ -272,12 +272,12 @@ pub const InstMap = struct { | ... | @@ -272,12 +272,12 @@ pub const InstMap = struct { |
| 272 | 272 | ||
| 273 | pub fn remove(map: InstMap, key: Zir.Inst.Index) bool { | 273 | pub fn remove(map: InstMap, key: Zir.Inst.Index) bool { |
| 274 | if (!map.contains(key)) return false; | 274 | if (!map.contains(key)) return false; |
| 275 | map.items[key - map.start] = .none; | 275 | map.items[@intFromEnum(key) - @intFromEnum(map.start)] = .none; |
| 276 | return true; | 276 | return true; |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | pub fn contains(map: InstMap, key: Zir.Inst.Index) bool { | 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 | pub fn ensureSpaceForInstructions( | 283 | pub fn ensureSpaceForInstructions( |
| ... | @@ -285,13 +285,12 @@ pub const InstMap = struct { | ... | @@ -285,13 +285,12 @@ pub const InstMap = struct { |
| 285 | allocator: mem.Allocator, | 285 | allocator: mem.Allocator, |
| 286 | insts: []const Zir.Inst.Index, | 286 | insts: []const Zir.Inst.Index, |
| 287 | ) !void { | 287 | ) !void { |
| 288 | const min_max = mem.minMax(Zir.Inst.Index, insts); | 288 | const start, const end = mem.minMax(u32, @ptrCast(insts)); |
| 289 | const start = min_max.min; | 289 | const map_start = @intFromEnum(map.start); |
| 290 | const end = min_max.max; | 290 | if (map_start <= start and end < map.items.len + map_start) |
| 291 | if (map.start <= start and end < map.items.len + map.start) | ||
| 292 | return; | 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 | var better_capacity = map.items.len; | 294 | var better_capacity = map.items.len; |
| 296 | var better_start = old_start; | 295 | var better_start = old_start; |
| 297 | while (true) { | 296 | while (true) { |
| ... | @@ -310,7 +309,7 @@ pub const InstMap = struct { | ... | @@ -310,7 +309,7 @@ pub const InstMap = struct { |
| 310 | 309 | ||
| 311 | allocator.free(map.items); | 310 | allocator.free(map.items); |
| 312 | map.items = new_items; | 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,7 +349,7 @@ pub const Block = struct { |
| 350 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. | 349 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. |
| 351 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. | 350 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. |
| 352 | runtime_index: Value.RuntimeIndex = .zero, | 351 | runtime_index: Value.RuntimeIndex = .zero, |
| 353 | inline_block: Zir.Inst.Index = 0, | 352 | inline_block: Zir.Inst.OptionalIndex = .none, |
| 354 | 353 | ||
| 355 | comptime_reason: ?*const ComptimeReason = null, | 354 | comptime_reason: ?*const ComptimeReason = null, |
| 356 | // TODO is_comptime and comptime_reason should probably be merged together. | 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,7 +896,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In |
| 897 | _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) { | 896 | _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) { |
| 898 | error.ComptimeBreak => { | 897 | error.ComptimeBreak => { |
| 899 | const zir_datas = sema.code.instructions.items(.data); | 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 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; | 900 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 902 | try sema.addRuntimeBreak(block, .{ | 901 | try sema.addRuntimeBreak(block, .{ |
| 903 | .block_inst = extra.block_inst, | 902 | .block_inst = extra.block_inst, |
| ... | @@ -938,7 +937,7 @@ pub fn analyzeBodyBreak( | ... | @@ -938,7 +937,7 @@ pub fn analyzeBodyBreak( |
| 938 | if (block.instructions.items.len != 0 and | 937 | if (block.instructions.items.len != 0 and |
| 939 | sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1]))) | 938 | sema.isNoReturn(Air.indexToRef(block.instructions.items[block.instructions.items.len - 1]))) |
| 940 | return null; | 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 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; | 941 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 943 | return BreakData{ | 942 | return BreakData{ |
| 944 | .block_inst = extra.block_inst, | 943 | .block_inst = extra.block_inst, |
| ... | @@ -998,7 +997,7 @@ fn analyzeBodyInner( | ... | @@ -998,7 +997,7 @@ fn analyzeBodyInner( |
| 998 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ | 997 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ |
| 999 | mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst, | 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 | // zig fmt: off | 1001 | // zig fmt: off |
| 1003 | .alloc => try sema.zirAlloc(block, inst), | 1002 | .alloc => try sema.zirAlloc(block, inst), |
| 1004 | .alloc_inferred => try sema.zirAllocInferred(block, inst, true), | 1003 | .alloc_inferred => try sema.zirAllocInferred(block, inst, true), |
| ... | @@ -1220,7 +1219,7 @@ fn analyzeBodyInner( | ... | @@ -1220,7 +1219,7 @@ fn analyzeBodyInner( |
| 1220 | // zig fmt: on | 1219 | // zig fmt: on |
| 1221 | 1220 | ||
| 1222 | .extended => ext: { | 1221 | .extended => ext: { |
| 1223 | const extended = datas[inst].extended; | 1222 | const extended = datas[@intFromEnum(inst)].extended; |
| 1224 | break :ext switch (extended.opcode) { | 1223 | break :ext switch (extended.opcode) { |
| 1225 | // zig fmt: off | 1224 | // zig fmt: off |
| 1226 | .variable => try sema.zirVarExtended( block, extended), | 1225 | .variable => try sema.zirVarExtended( block, extended), |
| ... | @@ -1477,13 +1476,13 @@ fn analyzeBodyInner( | ... | @@ -1477,13 +1476,13 @@ fn analyzeBodyInner( |
| 1477 | }, | 1476 | }, |
| 1478 | .check_comptime_control_flow => { | 1477 | .check_comptime_control_flow => { |
| 1479 | if (!block.is_comptime) { | 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 | const src = inst_data.src(); | 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 | var check_block = block; | 1483 | var check_block = block; |
| 1485 | const target_runtime_index = while (true) { | 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 | break check_block.runtime_index; | 1486 | break check_block.runtime_index; |
| 1488 | } | 1487 | } |
| 1489 | check_block = check_block.parent.?; | 1488 | check_block = check_block.parent.?; |
| ... | @@ -1534,7 +1533,7 @@ fn analyzeBodyInner( | ... | @@ -1534,7 +1533,7 @@ fn analyzeBodyInner( |
| 1534 | .repeat => { | 1533 | .repeat => { |
| 1535 | if (block.is_comptime) { | 1534 | if (block.is_comptime) { |
| 1536 | // Send comptime control flow back to the beginning of this block. | 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 | try sema.emitBackwardBranch(block, src); | 1537 | try sema.emitBackwardBranch(block, src); |
| 1539 | 1538 | ||
| 1540 | // We need to construct new capture scopes for the next loop iteration so it | 1539 | // We need to construct new capture scopes for the next loop iteration so it |
| ... | @@ -1549,7 +1548,7 @@ fn analyzeBodyInner( | ... | @@ -1549,7 +1548,7 @@ fn analyzeBodyInner( |
| 1549 | }, | 1548 | }, |
| 1550 | .repeat_inline => { | 1549 | .repeat_inline => { |
| 1551 | // Send comptime control flow back to the beginning of this block. | 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 | try sema.emitBackwardBranch(block, src); | 1552 | try sema.emitBackwardBranch(block, src); |
| 1554 | 1553 | ||
| 1555 | // We need to construct new capture scopes for the next loop iteration so it | 1554 | // We need to construct new capture scopes for the next loop iteration so it |
| ... | @@ -1562,9 +1561,9 @@ fn analyzeBodyInner( | ... | @@ -1562,9 +1561,9 @@ fn analyzeBodyInner( |
| 1562 | .loop => blk: { | 1561 | .loop => blk: { |
| 1563 | if (!block.is_comptime) break :blk try sema.zirLoop(block, inst); | 1562 | if (!block.is_comptime) break :blk try sema.zirLoop(block, inst); |
| 1564 | // Same as `block_inline`. TODO https://github.com/ziglang/zig/issues/8220 | 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 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse | 1567 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1569 | break always_noreturn; | 1568 | break always_noreturn; |
| 1570 | if (inst == break_data.block_inst) { | 1569 | if (inst == break_data.block_inst) { |
| ... | @@ -1575,12 +1574,12 @@ fn analyzeBodyInner( | ... | @@ -1575,12 +1574,12 @@ fn analyzeBodyInner( |
| 1575 | }, | 1574 | }, |
| 1576 | .block, .block_comptime => blk: { | 1575 | .block, .block_comptime => blk: { |
| 1577 | if (!block.is_comptime) { | 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 | // Same as `block_inline`. TODO https://github.com/ziglang/zig/issues/8220 | 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 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | // If this block contains a function prototype, we need to reset the | 1583 | // If this block contains a function prototype, we need to reset the |
| 1585 | // current list of parameters and restore it later. | 1584 | // current list of parameters and restore it later. |
| 1586 | // Note: this probably needs to be resolved in a more general manner. | 1585 | // Note: this probably needs to be resolved in a more general manner. |
| ... | @@ -1601,9 +1600,9 @@ fn analyzeBodyInner( | ... | @@ -1601,9 +1600,9 @@ fn analyzeBodyInner( |
| 1601 | // through a runtime conditional branch, we must retroactively emit | 1600 | // through a runtime conditional branch, we must retroactively emit |
| 1602 | // a block, so we remember the block index here just in case. | 1601 | // a block, so we remember the block index here just in case. |
| 1603 | const block_index = block.instructions.items.len; | 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 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | const gpa = sema.gpa; | 1606 | const gpa = sema.gpa; |
| 1608 | 1607 | ||
| 1609 | const opt_break_data = b: { | 1608 | const opt_break_data = b: { |
| ... | @@ -1614,8 +1613,11 @@ fn analyzeBodyInner( | ... | @@ -1614,8 +1613,11 @@ fn analyzeBodyInner( |
| 1614 | // If this block contains a function prototype, we need to reset the | 1613 | // If this block contains a function prototype, we need to reset the |
| 1615 | // current list of parameters and restore it later. | 1614 | // current list of parameters and restore it later. |
| 1616 | // Note: this probably needs to be resolved in a more general manner. | 1615 | // Note: this probably needs to be resolved in a more general manner. |
| 1617 | child_block.inline_block = | 1616 | const tag_index = @intFromEnum(inline_body[inline_body.len - 1]); |
| 1618 | if (tags[inline_body[inline_body.len - 1]] == .repeat_inline) inline_body[0] else inst; | 1617 | child_block.inline_block = (if (tags[tag_index] == .repeat_inline) |
| 1618 | inline_body[0] | ||
| 1619 | else | ||
| 1620 | inst).toOptional(); | ||
| 1619 | 1621 | ||
| 1620 | var label: Block.Label = .{ | 1622 | var label: Block.Label = .{ |
| 1621 | .zir_block = inst, | 1623 | .zir_block = inst, |
| ... | @@ -1682,11 +1684,14 @@ fn analyzeBodyInner( | ... | @@ -1682,11 +1684,14 @@ fn analyzeBodyInner( |
| 1682 | .condbr => blk: { | 1684 | .condbr => blk: { |
| 1683 | if (!block.is_comptime) break sema.zirCondbr(block, inst); | 1685 | if (!block.is_comptime) break sema.zirCondbr(block, inst); |
| 1684 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 | 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 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1688 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 1687 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 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]; | 1690 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1689 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1691 | const else_body = sema.code.bodySlice( |
| 1692 | extra.end + then_body.len, | ||
| 1693 | extra.data.else_body_len, | ||
| 1694 | ); | ||
| 1690 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ | 1695 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1691 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", | 1696 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1692 | .block_comptime_reason = block.comptime_reason, | 1697 | .block_comptime_reason = block.comptime_reason, |
| ... | @@ -1703,11 +1708,14 @@ fn analyzeBodyInner( | ... | @@ -1703,11 +1708,14 @@ fn analyzeBodyInner( |
| 1703 | } | 1708 | } |
| 1704 | }, | 1709 | }, |
| 1705 | .condbr_inline => blk: { | 1710 | .condbr_inline => blk: { |
| 1706 | const inst_data = datas[inst].pl_node; | 1711 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 1707 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1712 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 1708 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 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]; | 1714 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1710 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1715 | const else_body = sema.code.bodySlice( |
| 1716 | extra.end + then_body.len, | ||
| 1717 | extra.data.else_body_len, | ||
| 1718 | ); | ||
| 1711 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ | 1719 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1712 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", | 1720 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1713 | .block_comptime_reason = block.comptime_reason, | 1721 | .block_comptime_reason = block.comptime_reason, |
| ... | @@ -1727,11 +1735,11 @@ fn analyzeBodyInner( | ... | @@ -1727,11 +1735,11 @@ fn analyzeBodyInner( |
| 1727 | }, | 1735 | }, |
| 1728 | .@"try" => blk: { | 1736 | .@"try" => blk: { |
| 1729 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 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 | const src = inst_data.src(); | 1739 | const src = inst_data.src(); |
| 1732 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1740 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1733 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 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 | const err_union = try sema.resolveInst(extra.data.operand); | 1743 | const err_union = try sema.resolveInst(extra.data.operand); |
| 1736 | const err_union_ty = sema.typeOf(err_union); | 1744 | const err_union_ty = sema.typeOf(err_union); |
| 1737 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { | 1745 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| ... | @@ -1758,11 +1766,11 @@ fn analyzeBodyInner( | ... | @@ -1758,11 +1766,11 @@ fn analyzeBodyInner( |
| 1758 | }, | 1766 | }, |
| 1759 | .try_ptr => blk: { | 1767 | .try_ptr => blk: { |
| 1760 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); | 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 | const src = inst_data.src(); | 1770 | const src = inst_data.src(); |
| 1763 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1771 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 1764 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 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 | const operand = try sema.resolveInst(extra.data.operand); | 1774 | const operand = try sema.resolveInst(extra.data.operand); |
| 1767 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); | 1775 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1768 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1776 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| ... | @@ -1783,8 +1791,8 @@ fn analyzeBodyInner( | ... | @@ -1783,8 +1791,8 @@ fn analyzeBodyInner( |
| 1783 | } | 1791 | } |
| 1784 | }, | 1792 | }, |
| 1785 | .@"defer" => blk: { | 1793 | .@"defer" => blk: { |
| 1786 | const inst_data = sema.code.instructions.items(.data)[inst].@"defer"; | 1794 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"defer"; |
| 1787 | const defer_body = sema.code.extra[inst_data.index..][0..inst_data.len]; | 1795 | const defer_body = sema.code.bodySlice(inst_data.index, inst_data.len); |
| 1788 | const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) { | 1796 | const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) { |
| 1789 | error.ComptimeBreak => sema.comptime_break_inst, | 1797 | error.ComptimeBreak => sema.comptime_break_inst, |
| 1790 | else => |e| return e, | 1798 | else => |e| return e, |
| ... | @@ -1793,9 +1801,9 @@ fn analyzeBodyInner( | ... | @@ -1793,9 +1801,9 @@ fn analyzeBodyInner( |
| 1793 | break :blk .void_value; | 1801 | break :blk .void_value; |
| 1794 | }, | 1802 | }, |
| 1795 | .defer_err_code => blk: { | 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 | const extra = sema.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; | 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 | const err_code = try sema.resolveInst(inst_data.err_code); | 1807 | const err_code = try sema.resolveInst(inst_data.err_code); |
| 1800 | map.putAssumeCapacity(extra.remapped_err_code, err_code); | 1808 | map.putAssumeCapacity(extra.remapped_err_code, err_code); |
| 1801 | const break_inst = sema.analyzeBodyInner(block, defer_body) catch |err| switch (err) { | 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,14 +1854,14 @@ pub fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1846 | 1854 | ||
| 1847 | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { | 1855 | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1848 | assert(zir_ref != .none); | 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 | // First section of indexes correspond to a set number of constant values. | 1862 | // First section of indexes correspond to a set number of constant values. |
| 1851 | // We intentionally map the same indexes to the same values between ZIR and AIR. | 1863 | // We intentionally map the same indexes to the same values between ZIR and AIR. |
| 1852 | if (i < InternPool.static_len) return @enumFromInt(i); | 1864 | return @enumFromInt(@intFromEnum(zir_ref)); |
| 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; | ||
| 1857 | } | 1865 | } |
| 1858 | 1866 | ||
| 1859 | fn resolveConstBool( | 1867 | fn resolveConstBool( |
| ... | @@ -1968,30 +1976,30 @@ const GenericPoisonReason = union(enum) { | ... | @@ -1968,30 +1976,30 @@ const GenericPoisonReason = union(enum) { |
| 1968 | fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { | 1976 | fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 1969 | var cur = ref; | 1977 | var cur = ref; |
| 1970 | while (true) { | 1978 | while (true) { |
| 1971 | const inst = Zir.refToIndex(cur) orelse return .unknown; | 1979 | const inst = cur.toIndex() orelse return .unknown; |
| 1972 | switch (sema.code.instructions.items(.tag)[inst]) { | 1980 | switch (sema.code.instructions.items(.tag)[@intFromEnum(inst)]) { |
| 1973 | .validate_array_init_ref_ty => { | 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 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; | 1983 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 1976 | cur = extra.ptr_ty; | 1984 | cur = extra.ptr_ty; |
| 1977 | }, | 1985 | }, |
| 1978 | .array_init_elem_type => { | 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 | cur = bin.lhs; | 1988 | cur = bin.lhs; |
| 1981 | }, | 1989 | }, |
| 1982 | .indexable_ptr_elem_type, .vector_elem_type => { | 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 | cur = un_node.operand; | 1992 | cur = un_node.operand; |
| 1985 | }, | 1993 | }, |
| 1986 | .struct_init_field_type => { | 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 | const extra = sema.code.extraData(Zir.Inst.FieldType, pl_node.payload_index).data; | 1996 | const extra = sema.code.extraData(Zir.Inst.FieldType, pl_node.payload_index).data; |
| 1989 | cur = extra.container_type; | 1997 | cur = extra.container_type; |
| 1990 | }, | 1998 | }, |
| 1991 | .elem_type => { | 1999 | .elem_type => { |
| 1992 | // There are two cases here: the pointer type may already have been | 2000 | // There are two cases here: the pointer type may already have been |
| 1993 | // generic poison, or it may have been an anyopaque pointer. | 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 | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { | 2003 | const operand_ref = sema.resolveInst(un_node.operand) catch |err| switch (err) { |
| 1996 | error.GenericPoison => unreachable, // this is a type, not a value | 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,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 2008 | // A function call can never return generic poison, so we must be | 2016 | // A function call can never return generic poison, so we must be |
| 2009 | // evaluating an `anytype` function parameter. | 2017 | // evaluating an `anytype` function parameter. |
| 2010 | // TODO: better source location - function decl rather than call | 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 | return .{ .anytype_param = pl_node.src() }; | 2020 | return .{ .anytype_param = pl_node.src() }; |
| 2013 | }, | 2021 | }, |
| 2014 | else => return .unknown, | 2022 | else => return .unknown, |
| ... | @@ -2651,7 +2659,7 @@ pub fn getStructType( | ... | @@ -2651,7 +2659,7 @@ pub fn getStructType( |
| 2651 | const mod = sema.mod; | 2659 | const mod = sema.mod; |
| 2652 | const gpa = sema.gpa; | 2660 | const gpa = sema.gpa; |
| 2653 | const ip = &mod.intern_pool; | 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 | assert(extended.opcode == .struct_decl); | 2663 | assert(extended.opcode == .struct_decl); |
| 2656 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2664 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2657 | 2665 | ||
| ... | @@ -2801,7 +2809,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2801,7 +2809,7 @@ fn createAnonymousDeclTypeNamed( |
| 2801 | try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)}); | 2809 | try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)}); |
| 2802 | 2810 | ||
| 2803 | var arg_i: usize = 0; | 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 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { | 2813 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { |
| 2806 | const arg = sema.inst_map.get(zir_inst).?; | 2814 | const arg = sema.inst_map.get(zir_inst).?; |
| 2807 | // If this is being called in a generic function then analyzeCall will | 2815 | // If this is being called in a generic function then analyzeCall will |
| ... | @@ -2827,11 +2835,10 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2827,11 +2835,10 @@ fn createAnonymousDeclTypeNamed( |
| 2827 | return new_decl_index; | 2835 | return new_decl_index; |
| 2828 | }, | 2836 | }, |
| 2829 | .dbg_var => { | 2837 | .dbg_var => { |
| 2830 | const ref = Zir.indexToRef(inst.?); | 2838 | const ref = inst.?.toRef(); |
| 2831 | const zir_tags = sema.code.instructions.items(.tag); | 2839 | const zir_tags = sema.code.instructions.items(.tag); |
| 2832 | const zir_data = sema.code.instructions.items(.data); | 2840 | const zir_data = sema.code.instructions.items(.data); |
| 2833 | var i = inst.?; | 2841 | for (@intFromEnum(inst.?)..zir_tags.len) |i| switch (zir_tags[i]) { |
| 2834 | while (i < zir_tags.len) : (i += 1) switch (zir_tags[i]) { | ||
| 2835 | .dbg_var_ptr, .dbg_var_val => { | 2842 | .dbg_var_ptr, .dbg_var_val => { |
| 2836 | if (zir_data[i].str_op.operand != ref) continue; | 2843 | if (zir_data[i].str_op.operand != ref) continue; |
| 2837 | 2844 | ||
| ... | @@ -2917,7 +2924,7 @@ fn zirEnumDecl( | ... | @@ -2917,7 +2924,7 @@ fn zirEnumDecl( |
| 2917 | 2924 | ||
| 2918 | extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl); | 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 | extra_index += body.len; | 2928 | extra_index += body.len; |
| 2922 | 2929 | ||
| 2923 | const bit_bags_count = std.math.divCeil(usize, fields_len, 32) catch unreachable; | 2930 | const bit_bags_count = std.math.divCeil(usize, fields_len, 32) catch unreachable; |
| ... | @@ -3296,7 +3303,7 @@ fn zirErrorSetDecl( | ... | @@ -3296,7 +3303,7 @@ fn zirErrorSetDecl( |
| 3296 | 3303 | ||
| 3297 | const mod = sema.mod; | 3304 | const mod = sema.mod; |
| 3298 | const gpa = sema.gpa; | 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 | const src = inst_data.src(); | 3307 | const src = inst_data.src(); |
| 3301 | const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); | 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,7 +3366,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 3359 | const tracy = trace(@src()); | 3366 | const tracy = trace(@src()); |
| 3360 | defer tracy.end(); | 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 | const operand = try sema.resolveInst(inst_data.operand); | 3370 | const operand = try sema.resolveInst(inst_data.operand); |
| 3364 | return sema.analyzeRef(block, inst_data.src(), operand); | 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,7 +3375,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 3368 | const tracy = trace(@src()); | 3375 | const tracy = trace(@src()); |
| 3369 | defer tracy.end(); | 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 | const operand = try sema.resolveInst(inst_data.operand); | 3379 | const operand = try sema.resolveInst(inst_data.operand); |
| 3373 | const src = inst_data.src(); | 3380 | const src = inst_data.src(); |
| 3374 | 3381 | ||
| ... | @@ -3411,7 +3418,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3411,7 +3418,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3411 | defer tracy.end(); | 3418 | defer tracy.end(); |
| 3412 | 3419 | ||
| 3413 | const mod = sema.mod; | 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 | const operand = try sema.resolveInst(inst_data.operand); | 3422 | const operand = try sema.resolveInst(inst_data.operand); |
| 3416 | const src = inst_data.src(); | 3423 | const src = inst_data.src(); |
| 3417 | const operand_ty = sema.typeOf(operand); | 3424 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -3434,7 +3441,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index | ... | @@ -3434,7 +3441,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3434 | defer tracy.end(); | 3441 | defer tracy.end(); |
| 3435 | 3442 | ||
| 3436 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 3445 | const src = inst_data.src(); |
| 3439 | const operand = try sema.resolveInst(inst_data.operand); | 3446 | const operand = try sema.resolveInst(inst_data.operand); |
| 3440 | const operand_ty = sema.typeOf(operand); | 3447 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -3459,7 +3466,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3459,7 +3466,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 3459 | const tracy = trace(@src()); | 3466 | const tracy = trace(@src()); |
| 3460 | defer tracy.end(); | 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 | const src = inst_data.src(); | 3470 | const src = inst_data.src(); |
| 3464 | const object = try sema.resolveInst(inst_data.operand); | 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,7 +3585,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3578 | const tracy = trace(@src()); | 3585 | const tracy = trace(@src()); |
| 3579 | defer tracy.end(); | 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 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3589 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3583 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3590 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3584 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 3591 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | @@ -3586,7 +3593,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -3586,7 +3593,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3586 | 3593 | ||
| 3587 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 3594 | fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3588 | const mod = sema.mod; | 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 | const alloc = try sema.resolveInst(inst_data.operand); | 3597 | const alloc = try sema.resolveInst(inst_data.operand); |
| 3591 | const alloc_ty = sema.typeOf(alloc); | 3598 | const alloc_ty = sema.typeOf(alloc); |
| 3592 | const ptr_info = alloc_ty.ptrInfo(mod); | 3599 | const ptr_info = alloc_ty.ptrInfo(mod); |
| ... | @@ -3883,7 +3890,7 @@ fn zirAllocInferredComptime( | ... | @@ -3883,7 +3890,7 @@ fn zirAllocInferredComptime( |
| 3883 | is_const: bool, | 3890 | is_const: bool, |
| 3884 | ) CompileError!Air.Inst.Ref { | 3891 | ) CompileError!Air.Inst.Ref { |
| 3885 | const gpa = sema.gpa; | 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 | const src = LazySrcLoc.nodeOffset(src_node); | 3894 | const src = LazySrcLoc.nodeOffset(src_node); |
| 3888 | sema.src = src; | 3895 | sema.src = src; |
| 3889 | 3896 | ||
| ... | @@ -3902,7 +3909,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -3902,7 +3909,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3902 | const tracy = trace(@src()); | 3909 | const tracy = trace(@src()); |
| 3903 | defer tracy.end(); | 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 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3913 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3907 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3914 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3908 | if (block.is_comptime) { | 3915 | if (block.is_comptime) { |
| ... | @@ -3925,7 +3932,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -3925,7 +3932,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 3925 | const tracy = trace(@src()); | 3932 | const tracy = trace(@src()); |
| 3926 | defer tracy.end(); | 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 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3936 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3930 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3937 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3931 | if (block.is_comptime) { | 3938 | if (block.is_comptime) { |
| ... | @@ -3951,7 +3958,7 @@ fn zirAllocInferred( | ... | @@ -3951,7 +3958,7 @@ fn zirAllocInferred( |
| 3951 | defer tracy.end(); | 3958 | defer tracy.end(); |
| 3952 | 3959 | ||
| 3953 | const gpa = sema.gpa; | 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 | const src = LazySrcLoc.nodeOffset(src_node); | 3962 | const src = LazySrcLoc.nodeOffset(src_node); |
| 3956 | sema.src = src; | 3963 | sema.src = src; |
| 3957 | 3964 | ||
| ... | @@ -3986,7 +3993,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3986,7 +3993,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3986 | 3993 | ||
| 3987 | const mod = sema.mod; | 3994 | const mod = sema.mod; |
| 3988 | const gpa = sema.gpa; | 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 | const src = inst_data.src(); | 3997 | const src = inst_data.src(); |
| 3991 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3998 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 3992 | const ptr = try sema.resolveInst(inst_data.operand); | 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,7 +4034,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4027 | } }); | 4034 | } }); |
| 4028 | 4035 | ||
| 4029 | // Remap the ZIR operand to the resolved pointer value | 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 | .inferred_alloc => { | 4039 | .inferred_alloc => { |
| 4033 | const ia1 = sema.air_instructions.items(.data)[ptr_inst].inferred_alloc; | 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,7 +4068,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4061 | } }); | 4068 | } }); |
| 4062 | 4069 | ||
| 4063 | // Remap the ZIR oeprand to the resolved pointer value | 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 | // Unless the block is comptime, `alloc_inferred` always produces | 4073 | // Unless the block is comptime, `alloc_inferred` always produces |
| 4067 | // a runtime constant. The final inferred type needs to be | 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,7 +4132,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4125 | const mod = sema.mod; | 4132 | const mod = sema.mod; |
| 4126 | const gpa = sema.gpa; | 4133 | const gpa = sema.gpa; |
| 4127 | const ip = &mod.intern_pool; | 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 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 4136 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 4130 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); | 4137 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| 4131 | const src = inst_data.src(); | 4138 | const src = inst_data.src(); |
| ... | @@ -4264,14 +4271,14 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL | ... | @@ -4264,14 +4271,14 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL |
| 4264 | } | 4271 | } |
| 4265 | 4272 | ||
| 4266 | fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const ptr = try sema.resolveInst(un_node.operand); | 4275 | const ptr = try sema.resolveInst(un_node.operand); |
| 4269 | return sema.optEuBasePtrInit(block, ptr, un_node.src()); | 4276 | return sema.optEuBasePtrInit(block, ptr, un_node.src()); |
| 4270 | } | 4277 | } |
| 4271 | 4278 | ||
| 4272 | fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4279 | fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4273 | const mod = sema.mod; | 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 | const src = pl_node.src(); | 4282 | const src = pl_node.src(); |
| 4276 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; | 4283 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4277 | const uncoerced_val = try sema.resolveInst(extra.rhs); | 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,7 +4329,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4322 | 4329 | ||
| 4323 | fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4330 | fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4324 | const mod = sema.mod; | 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 | const src = un_tok.src(); | 4333 | const src = un_tok.src(); |
| 4327 | // In case of GenericPoison, we don't actually have a type, so this will be | 4334 | // In case of GenericPoison, we don't actually have a type, so this will be |
| 4328 | // treated as an untyped address-of operator. | 4335 | // treated as an untyped address-of operator. |
| ... | @@ -4353,7 +4360,7 @@ fn zirValidateArrayInitRefTy( | ... | @@ -4353,7 +4360,7 @@ fn zirValidateArrayInitRefTy( |
| 4353 | inst: Zir.Inst.Index, | 4360 | inst: Zir.Inst.Index, |
| 4354 | ) CompileError!Air.Inst.Ref { | 4361 | ) CompileError!Air.Inst.Ref { |
| 4355 | const mod = sema.mod; | 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 | const src = pl_node.src(); | 4364 | const src = pl_node.src(); |
| 4358 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; | 4365 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 4359 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { | 4366 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { |
| ... | @@ -4389,7 +4396,7 @@ fn zirValidateArrayInitTy( | ... | @@ -4389,7 +4396,7 @@ fn zirValidateArrayInitTy( |
| 4389 | is_result_ty: bool, | 4396 | is_result_ty: bool, |
| 4390 | ) CompileError!void { | 4397 | ) CompileError!void { |
| 4391 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 4400 | const src = inst_data.src(); |
| 4394 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; | 4401 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; |
| 4395 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; | 4402 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| ... | @@ -4452,7 +4459,7 @@ fn zirValidateStructInitTy( | ... | @@ -4452,7 +4459,7 @@ fn zirValidateStructInitTy( |
| 4452 | is_result_ty: bool, | 4459 | is_result_ty: bool, |
| 4453 | ) CompileError!void { | 4460 | ) CompileError!void { |
| 4454 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 4463 | const src = inst_data.src(); |
| 4457 | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { | 4464 | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 4458 | // It's okay for the type to be unknown: this will result in an anonymous struct init. | 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,11 +4484,11 @@ fn zirValidatePtrStructInit( |
| 4477 | defer tracy.end(); | 4484 | defer tracy.end(); |
| 4478 | 4485 | ||
| 4479 | const mod = sema.mod; | 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 | const init_src = validate_inst.src(); | 4488 | const init_src = validate_inst.src(); |
| 4482 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); | 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]; | 4490 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 4484 | const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node; | 4491 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| 4485 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4492 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4486 | const object_ptr = try sema.resolveInst(field_ptr_extra.lhs); | 4493 | const object_ptr = try sema.resolveInst(field_ptr_extra.lhs); |
| 4487 | const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod); | 4494 | const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod); |
| ... | @@ -4525,7 +4532,7 @@ fn validateUnionInit( | ... | @@ -4525,7 +4532,7 @@ fn validateUnionInit( |
| 4525 | errdefer msg.destroy(gpa); | 4532 | errdefer msg.destroy(gpa); |
| 4526 | 4533 | ||
| 4527 | for (instrs[1..]) |inst| { | 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 | const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node }; | 4536 | const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node }; |
| 4530 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); | 4537 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); |
| 4531 | } | 4538 | } |
| ... | @@ -4543,7 +4550,7 @@ fn validateUnionInit( | ... | @@ -4543,7 +4550,7 @@ fn validateUnionInit( |
| 4543 | } | 4550 | } |
| 4544 | 4551 | ||
| 4545 | const field_ptr = instrs[0]; | 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 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4554 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4548 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4555 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4549 | const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start)); | 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,14 +4669,14 @@ fn validateStructInit( |
| 4662 | defer gpa.free(field_indices); | 4669 | defer gpa.free(field_indices); |
| 4663 | 4670 | ||
| 4664 | // Maps field index to field_ptr index of where it was already initialized. | 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 | defer gpa.free(found_fields); | 4673 | defer gpa.free(found_fields); |
| 4667 | @memset(found_fields, 0); | 4674 | @memset(found_fields, .none); |
| 4668 | 4675 | ||
| 4669 | var struct_ptr_zir_ref: Zir.Inst.Ref = undefined; | 4676 | var struct_ptr_zir_ref: Zir.Inst.Ref = undefined; |
| 4670 | 4677 | ||
| 4671 | for (instrs, field_indices) |field_ptr, *field_index| { | 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 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4680 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; |
| 4674 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4681 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4675 | struct_ptr_zir_ref = field_ptr_extra.lhs; | 4682 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| ... | @@ -4681,9 +4688,8 @@ fn validateStructInit( | ... | @@ -4681,9 +4688,8 @@ fn validateStructInit( |
| 4681 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) | 4688 | try sema.tupleFieldIndex(block, struct_ty, field_name, field_src) |
| 4682 | else | 4689 | else |
| 4683 | try sema.structFieldIndex(block, struct_ty, field_name, field_src); | 4690 | try sema.structFieldIndex(block, struct_ty, field_name, field_src); |
| 4684 | if (found_fields[field_index.*] != 0) { | 4691 | if (found_fields[field_index.*].unwrap()) |other_field_ptr| { |
| 4685 | const other_field_ptr = found_fields[field_index.*]; | 4692 | const other_field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(other_field_ptr)].pl_node; |
| 4686 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; | ||
| 4687 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_ptr_data.src_node }; | 4693 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_ptr_data.src_node }; |
| 4688 | const msg = msg: { | 4694 | const msg = msg: { |
| 4689 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); | 4695 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| ... | @@ -4693,7 +4699,7 @@ fn validateStructInit( | ... | @@ -4693,7 +4699,7 @@ fn validateStructInit( |
| 4693 | }; | 4699 | }; |
| 4694 | return sema.failWithOwnedErrorMsg(block, msg); | 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 | var root_msg: ?*Module.ErrorMsg = null; | 4705 | var root_msg: ?*Module.ErrorMsg = null; |
| ... | @@ -4709,7 +4715,7 @@ fn validateStructInit( | ... | @@ -4709,7 +4715,7 @@ fn validateStructInit( |
| 4709 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. | 4715 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. |
| 4710 | for (found_fields, 0..) |field_ptr, i_usize| { | 4716 | for (found_fields, 0..) |field_ptr, i_usize| { |
| 4711 | const i: u32 = @intCast(i_usize); | 4717 | const i: u32 = @intCast(i_usize); |
| 4712 | if (field_ptr != 0) continue; | 4718 | if (field_ptr != .none) continue; |
| 4713 | 4719 | ||
| 4714 | const default_val = struct_ty.structFieldDefaultValue(i, mod); | 4720 | const default_val = struct_ty.structFieldDefaultValue(i, mod); |
| 4715 | if (default_val.toIntern() == .unreachable_value) { | 4721 | if (default_val.toIntern() == .unreachable_value) { |
| ... | @@ -4770,9 +4776,9 @@ fn validateStructInit( | ... | @@ -4770,9 +4776,9 @@ fn validateStructInit( |
| 4770 | // ends up being comptime-known. | 4776 | // ends up being comptime-known. |
| 4771 | const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod)); | 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 | const i: u32 = @intCast(i_usize); | 4780 | const i: u32 = @intCast(i_usize); |
| 4775 | if (field_ptr != 0) { | 4781 | if (opt_field_ptr.unwrap()) |field_ptr| { |
| 4776 | // Determine whether the value stored to this pointer is comptime-known. | 4782 | // Determine whether the value stored to this pointer is comptime-known. |
| 4777 | const field_ty = struct_ty.structFieldType(i, mod); | 4783 | const field_ty = struct_ty.structFieldType(i, mod); |
| 4778 | if (try sema.typeHasOnePossibleValue(field_ty)) |opv| { | 4784 | if (try sema.typeHasOnePossibleValue(field_ty)) |opv| { |
| ... | @@ -4831,7 +4837,7 @@ fn validateStructInit( | ... | @@ -4831,7 +4837,7 @@ fn validateStructInit( |
| 4831 | if (try sema.resolveValue(bin_op.rhs)) |val| { | 4837 | if (try sema.resolveValue(bin_op.rhs)) |val| { |
| 4832 | field_values[i] = val.toIntern(); | 4838 | field_values[i] = val.toIntern(); |
| 4833 | } else if (require_comptime) { | 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 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ | 4841 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| 4836 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 4842 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 4837 | }); | 4843 | }); |
| ... | @@ -4931,7 +4937,7 @@ fn validateStructInit( | ... | @@ -4931,7 +4937,7 @@ fn validateStructInit( |
| 4931 | 4937 | ||
| 4932 | // Our task is to insert `store` instructions for all the default field values. | 4938 | // Our task is to insert `store` instructions for all the default field values. |
| 4933 | for (found_fields, 0..) |field_ptr, i| { | 4939 | for (found_fields, 0..) |field_ptr, i| { |
| 4934 | if (field_ptr != 0) continue; | 4940 | if (field_ptr != .none) continue; |
| 4935 | 4941 | ||
| 4936 | const field_src = init_src; // TODO better source location | 4942 | const field_src = init_src; // TODO better source location |
| 4937 | const default_field_ptr = if (struct_ty.isTuple(mod)) | 4943 | const default_field_ptr = if (struct_ty.isTuple(mod)) |
| ... | @@ -4950,11 +4956,11 @@ fn zirValidatePtrArrayInit( | ... | @@ -4950,11 +4956,11 @@ fn zirValidatePtrArrayInit( |
| 4950 | inst: Zir.Inst.Index, | 4956 | inst: Zir.Inst.Index, |
| 4951 | ) CompileError!void { | 4957 | ) CompileError!void { |
| 4952 | const mod = sema.mod; | 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 | const init_src = validate_inst.src(); | 4960 | const init_src = validate_inst.src(); |
| 4955 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); | 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]; | 4962 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 4957 | const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node; | 4963 | const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| 4958 | const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data; | 4964 | const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data; |
| 4959 | const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr); | 4965 | const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr); |
| 4960 | const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod); | 4966 | const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod); |
| ... | @@ -5147,7 +5153,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5147,7 +5153,7 @@ fn zirValidatePtrArrayInit( |
| 5147 | 5153 | ||
| 5148 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5154 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5149 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 5157 | const src = inst_data.src(); |
| 5152 | const operand = try sema.resolveInst(inst_data.operand); | 5158 | const operand = try sema.resolveInst(inst_data.operand); |
| 5153 | const operand_ty = sema.typeOf(operand); | 5159 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -5190,7 +5196,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -5190,7 +5196,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5190 | 5196 | ||
| 5191 | fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5197 | fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5192 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; | 5200 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 5195 | const src = inst_data.src(); | 5201 | const src = inst_data.src(); |
| 5196 | const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node); | 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,7 +5334,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 5328 | defer tracy.end(); | 5334 | defer tracy.end(); |
| 5329 | 5335 | ||
| 5330 | const src: LazySrcLoc = sema.src; | 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 | const ptr = try sema.resolveInst(bin_inst.lhs); | 5338 | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 5333 | const operand = try sema.resolveInst(bin_inst.rhs); | 5339 | const operand = try sema.resolveInst(bin_inst.rhs); |
| 5334 | const ptr_inst = Air.refToIndex(ptr).?; | 5340 | const ptr_inst = Air.refToIndex(ptr).?; |
| ... | @@ -5387,7 +5393,7 @@ fn storeToInferredAllocComptime( | ... | @@ -5387,7 +5393,7 @@ fn storeToInferredAllocComptime( |
| 5387 | } | 5393 | } |
| 5388 | 5394 | ||
| 5389 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 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 | const src = inst_data.src(); | 5397 | const src = inst_data.src(); |
| 5392 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ | 5398 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ |
| 5393 | .needed_comptime_reason = "eval branch quota must be comptime-known", | 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,7 +5405,7 @@ fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5399 | const tracy = trace(@src()); | 5405 | const tracy = trace(@src()); |
| 5400 | defer tracy.end(); | 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 | const ptr = try sema.resolveInst(bin_inst.lhs); | 5409 | const ptr = try sema.resolveInst(bin_inst.lhs); |
| 5404 | const value = try sema.resolveInst(bin_inst.rhs); | 5410 | const value = try sema.resolveInst(bin_inst.rhs); |
| 5405 | return sema.storePtr(block, sema.src, ptr, value); | 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,14 +5418,14 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5412 | const mod = sema.mod; | 5418 | const mod = sema.mod; |
| 5413 | const zir_tags = sema.code.instructions.items(.tag); | 5419 | const zir_tags = sema.code.instructions.items(.tag); |
| 5414 | const zir_datas = sema.code.instructions.items(.data); | 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 | const src = inst_data.src(); | 5422 | const src = inst_data.src(); |
| 5417 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 5423 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5418 | const ptr = try sema.resolveInst(extra.lhs); | 5424 | const ptr = try sema.resolveInst(extra.lhs); |
| 5419 | const operand = try sema.resolveInst(extra.rhs); | 5425 | const operand = try sema.resolveInst(extra.rhs); |
| 5420 | 5426 | ||
| 5421 | const is_ret = if (Zir.refToIndex(extra.lhs)) |ptr_index| | 5427 | const is_ret = if (extra.lhs.toIndex()) |ptr_index| |
| 5422 | zir_tags[ptr_index] == .ret_ptr | 5428 | zir_tags[@intFromEnum(ptr_index)] == .ret_ptr |
| 5423 | else | 5429 | else |
| 5424 | false; | 5430 | false; |
| 5425 | 5431 | ||
| ... | @@ -5445,7 +5451,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v | ... | @@ -5445,7 +5451,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5445 | } | 5451 | } |
| 5446 | 5452 | ||
| 5447 | fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | return sema.addStrLitNoAlias(bytes); | 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,7 +5503,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 5497 | const tracy = trace(@src()); | 5503 | const tracy = trace(@src()); |
| 5498 | defer tracy.end(); | 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 | return sema.mod.intRef(Type.comptime_int, int); | 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,7 +5513,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 5507 | defer tracy.end(); | 5513 | defer tracy.end(); |
| 5508 | 5514 | ||
| 5509 | const mod = sema.mod; | 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 | const byte_count = int.len * @sizeOf(std.math.big.Limb); | 5517 | const byte_count = int.len * @sizeOf(std.math.big.Limb); |
| 5512 | const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count]; | 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,7 +5531,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 5525 | 5531 | ||
| 5526 | fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 5532 | fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5527 | _ = block; | 5533 | _ = block; |
| 5528 | const number = sema.code.instructions.items(.data)[inst].float; | 5534 | const number = sema.code.instructions.items(.data)[@intFromEnum(inst)].float; |
| 5529 | return Air.internedToRef((try sema.mod.floatValue( | 5535 | return Air.internedToRef((try sema.mod.floatValue( |
| 5530 | Type.comptime_float, | 5536 | Type.comptime_float, |
| 5531 | number, | 5537 | number, |
| ... | @@ -5534,7 +5540,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -5534,7 +5540,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 5534 | 5540 | ||
| 5535 | fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 5541 | fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5536 | _ = block; | 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 | const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; | 5544 | const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 5539 | const number = extra.get(); | 5545 | const number = extra.get(); |
| 5540 | return Air.internedToRef((try sema.mod.floatValue(Type.comptime_float, number)).toIntern()); | 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,7 +5550,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5544 | const tracy = trace(@src()); | 5550 | const tracy = trace(@src()); |
| 5545 | defer tracy.end(); | 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 | const src = inst_data.src(); | 5554 | const src = inst_data.src(); |
| 5549 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5555 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5550 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 5556 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| ... | @@ -5594,7 +5600,7 @@ fn zirCompileLog( | ... | @@ -5594,7 +5600,7 @@ fn zirCompileLog( |
| 5594 | } | 5600 | } |
| 5595 | 5601 | ||
| 5596 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { | 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 | const src = inst_data.src(); | 5604 | const src = inst_data.src(); |
| 5599 | const msg_inst = try sema.resolveInst(inst_data.operand); | 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,7 +5612,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I |
| 5606 | } | 5612 | } |
| 5607 | 5613 | ||
| 5608 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { | 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 | const src = LazySrcLoc.nodeOffset(src_node); | 5616 | const src = LazySrcLoc.nodeOffset(src_node); |
| 5611 | sema.src = src; | 5617 | sema.src = src; |
| 5612 | _ = try block.addNoOp(.trap); | 5618 | _ = try block.addNoOp(.trap); |
| ... | @@ -5618,10 +5624,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5618,10 +5624,10 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5618 | defer tracy.end(); | 5624 | defer tracy.end(); |
| 5619 | 5625 | ||
| 5620 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 5628 | const src = inst_data.src(); |
| 5623 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | const gpa = sema.gpa; | 5631 | const gpa = sema.gpa; |
| 5626 | 5632 | ||
| 5627 | // AIR expects a block outside the loop block too. | 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,10 +5696,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5690 | const mod = sema.mod; | 5696 | const mod = sema.mod; |
| 5691 | const comp = mod.comp; | 5697 | const comp = mod.comp; |
| 5692 | const gpa = sema.gpa; | 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 | const src = pl_node.src(); | 5700 | const src = pl_node.src(); |
| 5695 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); | 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 | // we check this here to avoid undefined symbols | 5704 | // we check this here to avoid undefined symbols |
| 5699 | if (!@import("build_options").have_llvm) | 5705 | if (!@import("build_options").have_llvm) |
| ... | @@ -5768,7 +5774,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5768,7 +5774,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5768 | } | 5774 | } |
| 5769 | 5775 | ||
| 5770 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 5778 | const src = inst_data.src(); |
| 5773 | return sema.failWithUseOfAsync(parent_block, src); | 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,10 +5783,10 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 5777 | const tracy = trace(@src()); | 5783 | const tracy = trace(@src()); |
| 5778 | defer tracy.end(); | 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 | const src = pl_node.src(); | 5787 | const src = pl_node.src(); |
| 5782 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); | 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 | const gpa = sema.gpa; | 5790 | const gpa = sema.gpa; |
| 5785 | 5791 | ||
| 5786 | // Reserve space for a Block instruction so that generated Break instructions can | 5792 | // Reserve space for a Block instruction so that generated Break instructions can |
| ... | @@ -5852,7 +5858,7 @@ fn resolveBlockBody( | ... | @@ -5852,7 +5858,7 @@ fn resolveBlockBody( |
| 5852 | try parent_block.instructions.appendSlice(sema.gpa, child_block.instructions.items); | 5858 | try parent_block.instructions.appendSlice(sema.gpa, child_block.instructions.items); |
| 5853 | 5859 | ||
| 5854 | const break_inst = sema.comptime_break_inst; | 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 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; | 5862 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 5857 | if (extra.block_inst == body_inst) { | 5863 | if (extra.block_inst == body_inst) { |
| 5858 | return try sema.resolveInst(break_data.operand); | 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,7 +5997,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5991 | defer tracy.end(); | 5997 | defer tracy.end(); |
| 5992 | 5998 | ||
| 5993 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | 6001 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 5996 | const src = inst_data.src(); | 6002 | const src = inst_data.src(); |
| 5997 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +6033,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6027 | defer tracy.end(); | 6033 | defer tracy.end(); |
| 6028 | 6034 | ||
| 6029 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; | 6037 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 6032 | const src = inst_data.src(); | 6038 | const src = inst_data.src(); |
| 6033 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +6204,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 6198 | } | 6204 | } |
| 6199 | 6205 | ||
| 6200 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6208 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6203 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ | 6209 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| 6204 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", | 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,7 +6234,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError |
| 6228 | const tracy = trace(@src()); | 6234 | const tracy = trace(@src()); |
| 6229 | defer tracy.end(); | 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 | const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; | 6238 | const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 6233 | const operand = try sema.resolveInst(inst_data.operand); | 6239 | const operand = try sema.resolveInst(inst_data.operand); |
| 6234 | const zir_block = extra.block_inst; | 6240 | const zir_block = extra.block_inst; |
| ... | @@ -6264,7 +6270,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -6264,7 +6270,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 6264 | // instructions. | 6270 | // instructions. |
| 6265 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return; | 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 | if (block.instructions.items.len != 0) { | 6275 | if (block.instructions.items.len != 0) { |
| 6270 | const idx = block.instructions.items[block.instructions.items.len - 1]; | 6276 | const idx = block.instructions.items[block.instructions.items.len - 1]; |
| ... | @@ -6313,7 +6319,7 @@ fn zirDbgVar( | ... | @@ -6313,7 +6319,7 @@ fn zirDbgVar( |
| 6313 | ) CompileError!void { | 6319 | ) CompileError!void { |
| 6314 | if (block.is_comptime or sema.mod.comp.bin_file.options.strip) return; | 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 | const operand = try sema.resolveInst(str_op.operand); | 6323 | const operand = try sema.resolveInst(str_op.operand); |
| 6318 | const name = str_op.getStr(sema.code); | 6324 | const name = str_op.getStr(sema.code); |
| 6319 | try sema.addDbgVar(block, operand, air_tag, name); | 6325 | try sema.addDbgVar(block, operand, air_tag, name); |
| ... | @@ -6358,7 +6364,7 @@ fn addDbgVar( | ... | @@ -6358,7 +6364,7 @@ fn addDbgVar( |
| 6358 | 6364 | ||
| 6359 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6365 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6360 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 6368 | const src = inst_data.src(); |
| 6363 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 6369 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6364 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); | 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,7 +6374,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6368 | 6374 | ||
| 6369 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6375 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6370 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 6378 | const src = inst_data.src(); |
| 6373 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 6379 | const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 6374 | const decl = try sema.lookupIdentifier(block, src, decl_name); | 6380 | const decl = try sema.lookupIdentifier(block, src, decl_name); |
| ... | @@ -6637,7 +6643,7 @@ fn zirCall( | ... | @@ -6637,7 +6643,7 @@ fn zirCall( |
| 6637 | defer tracy.end(); | 6643 | defer tracy.end(); |
| 6638 | 6644 | ||
| 6639 | const mod = sema.mod; | 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 | const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; | 6647 | const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; |
| 6642 | const call_src = inst_data.src(); | 6648 | const call_src = inst_data.src(); |
| 6643 | const ExtraType = switch (kind) { | 6649 | const ExtraType = switch (kind) { |
| ... | @@ -6685,12 +6691,12 @@ fn zirCall( | ... | @@ -6685,12 +6691,12 @@ fn zirCall( |
| 6685 | .call_inst = inst, | 6691 | .call_inst = inst, |
| 6686 | .call_node_offset = inst_data.src_node, | 6692 | .call_node_offset = inst_data.src_node, |
| 6687 | .num_args = args_len, | 6693 | .num_args = args_len, |
| 6688 | .args_body = sema.code.extra[extra.end..], | 6694 | .args_body = @ptrCast(sema.code.extra[extra.end..]), |
| 6689 | .any_arg_is_error = &input_is_error, | 6695 | .any_arg_is_error = &input_is_error, |
| 6690 | } }; | 6696 | } }; |
| 6691 | 6697 | ||
| 6692 | // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction. | 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 | const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call); | 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 | if (sema.owner_func_index == .none or | 6702 | if (sema.owner_func_index == .none or |
| ... | @@ -6961,11 +6967,11 @@ const CallArgsInfo = union(enum) { | ... | @@ -6961,11 +6967,11 @@ const CallArgsInfo = union(enum) { |
| 6961 | 6967 | ||
| 6962 | const arg_body = if (real_arg_idx == 0) blk: { | 6968 | const arg_body = if (real_arg_idx == 0) blk: { |
| 6963 | const start = zir_call.num_args; | 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 | break :blk zir_call.args_body[start..end]; | 6971 | break :blk zir_call.args_body[start..end]; |
| 6966 | } else blk: { | 6972 | } else blk: { |
| 6967 | const start = zir_call.args_body[real_arg_idx - 1]; | 6973 | const start = @intFromEnum(zir_call.args_body[real_arg_idx - 1]); |
| 6968 | const end = zir_call.args_body[real_arg_idx]; | 6974 | const end = @intFromEnum(zir_call.args_body[real_arg_idx]); |
| 6969 | break :blk zir_call.args_body[start..end]; | 6975 | break :blk zir_call.args_body[start..end]; |
| 6970 | }; | 6976 | }; |
| 6971 | 6977 | ||
| ... | @@ -7447,9 +7453,9 @@ fn analyzeCall( | ... | @@ -7447,9 +7453,9 @@ fn analyzeCall( |
| 7447 | try sema.emitDbgInline(block, prev_fn_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin); | 7453 | try sema.emitDbgInline(block, prev_fn_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin); |
| 7448 | 7454 | ||
| 7449 | const zir_tags = sema.code.instructions.items(.tag); | 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 | .param, .param_comptime => { | 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 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); | 7459 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 7454 | const param_name = sema.code.nullTerminatedString(extra.data.name); | 7460 | const param_name = sema.code.nullTerminatedString(extra.data.name); |
| 7455 | const inst = sema.inst_map.get(param).?; | 7461 | const inst = sema.inst_map.get(param).?; |
| ... | @@ -7457,7 +7463,7 @@ fn analyzeCall( | ... | @@ -7457,7 +7463,7 @@ fn analyzeCall( |
| 7457 | try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name); | 7463 | try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name); |
| 7458 | }, | 7464 | }, |
| 7459 | .param_anytype, .param_anytype_comptime => { | 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 | const param_name = inst_data.get(sema.code); | 7467 | const param_name = inst_data.get(sema.code); |
| 7462 | const inst = sema.inst_map.get(param).?; | 7468 | const inst = sema.inst_map.get(param).?; |
| 7463 | 7469 | ||
| ... | @@ -7640,18 +7646,18 @@ fn analyzeInlineCallArg( | ... | @@ -7640,18 +7646,18 @@ fn analyzeInlineCallArg( |
| 7640 | const mod = ics.sema.mod; | 7646 | const mod = ics.sema.mod; |
| 7641 | const ip = &mod.intern_pool; | 7647 | const ip = &mod.intern_pool; |
| 7642 | const zir_tags = ics.callee().code.instructions.items(.tag); | 7648 | const zir_tags = ics.callee().code.instructions.items(.tag); |
| 7643 | switch (zir_tags[inst]) { | 7649 | switch (zir_tags[@intFromEnum(inst)]) { |
| 7644 | .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true, | 7650 | .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true, |
| 7645 | else => {}, | 7651 | else => {}, |
| 7646 | } | 7652 | } |
| 7647 | switch (zir_tags[inst]) { | 7653 | switch (zir_tags[@intFromEnum(inst)]) { |
| 7648 | .param, .param_comptime => { | 7654 | .param, .param_comptime => { |
| 7649 | // Evaluate the parameter type expression now that previous ones have | 7655 | // Evaluate the parameter type expression now that previous ones have |
| 7650 | // been mapped, and coerce the corresponding argument to it. | 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 | const param_src = pl_tok.src(); | 7658 | const param_src = pl_tok.src(); |
| 7653 | const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index); | 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 | const param_ty = param_ty: { | 7661 | const param_ty = param_ty: { |
| 7656 | const raw_param_ty = func_ty_info.param_types.get(ip)[arg_i.*]; | 7662 | const raw_param_ty = func_ty_info.param_types.get(ip)[arg_i.*]; |
| 7657 | if (raw_param_ty != .generic_poison_type) break :param_ty raw_param_ty; | 7663 | if (raw_param_ty != .generic_poison_type) break :param_ty raw_param_ty; |
| ... | @@ -7670,7 +7676,7 @@ fn analyzeInlineCallArg( | ... | @@ -7670,7 +7676,7 @@ fn analyzeInlineCallArg( |
| 7670 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", | 7676 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", |
| 7671 | .block_comptime_reason = param_block.comptime_reason, | 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 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ | 7680 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ |
| 7675 | .needed_comptime_reason = "parameter is comptime", | 7681 | .needed_comptime_reason = "parameter is comptime", |
| 7676 | }); | 7682 | }); |
| ... | @@ -7736,7 +7742,7 @@ fn analyzeInlineCallArg( | ... | @@ -7736,7 +7742,7 @@ fn analyzeInlineCallArg( |
| 7736 | should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod); | 7742 | should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod); |
| 7737 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); | 7743 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); |
| 7738 | } else { | 7744 | } else { |
| 7739 | if (zir_tags[inst] == .param_anytype_comptime) { | 7745 | if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) { |
| 7740 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ | 7746 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ |
| 7741 | .needed_comptime_reason = "parameter is comptime", | 7747 | .needed_comptime_reason = "parameter is comptime", |
| 7742 | }); | 7748 | }); |
| ... | @@ -7864,7 +7870,7 @@ fn instantiateGenericCall( | ... | @@ -7864,7 +7870,7 @@ fn instantiateGenericCall( |
| 7864 | try child_sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body); | 7870 | try child_sema.inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body); |
| 7865 | 7871 | ||
| 7866 | for (fn_info.param_body[0..args_info.count()], 0..) |param_inst, arg_index| { | 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 | const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) { | 7875 | const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) { |
| 7870 | else => |ty| ty.toType(), // parameter is not generic, so type is already resolved | 7876 | else => |ty| ty.toType(), // parameter is not generic, so type is already resolved |
| ... | @@ -7879,9 +7885,9 @@ fn instantiateGenericCall( | ... | @@ -7879,9 +7885,9 @@ fn instantiateGenericCall( |
| 7879 | .param, .param_comptime => { | 7885 | .param, .param_comptime => { |
| 7880 | // We now know every prior parameter, so can resolve this | 7886 | // We now know every prior parameter, so can resolve this |
| 7881 | // parameter's type. The child sema has these types. | 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 | const param_extra = fn_zir.extraData(Zir.Inst.Param, param_data.payload_index); | 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 | // Make sure any nested instructions don't clobber our work. | 7892 | // Make sure any nested instructions don't clobber our work. |
| 7887 | const prev_params = child_block.params; | 7893 | const prev_params = child_block.params; |
| ... | @@ -7937,8 +7943,8 @@ fn instantiateGenericCall( | ... | @@ -7937,8 +7943,8 @@ fn instantiateGenericCall( |
| 7937 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); | 7943 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); |
| 7938 | errdefer msg.destroy(sema.gpa); | 7944 | errdefer msg.destroy(sema.gpa); |
| 7939 | const param_src = switch (param_tag) { | 7945 | const param_src = switch (param_tag) { |
| 7940 | .param_comptime => fn_zir.instructions.items(.data)[param_inst].pl_tok.src(), | 7946 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), |
| 7941 | .param_anytype_comptime => fn_zir.instructions.items(.data)[param_inst].str_tok.src(), | 7947 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), |
| 7942 | else => unreachable, | 7948 | else => unreachable, |
| 7943 | }; | 7949 | }; |
| 7944 | try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); | 7950 | try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); |
| ... | @@ -7952,8 +7958,8 @@ fn instantiateGenericCall( | ... | @@ -7952,8 +7958,8 @@ fn instantiateGenericCall( |
| 7952 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); | 7958 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); |
| 7953 | errdefer msg.destroy(sema.gpa); | 7959 | errdefer msg.destroy(sema.gpa); |
| 7954 | const param_src = switch (param_tag) { | 7960 | const param_src = switch (param_tag) { |
| 7955 | .param => fn_zir.instructions.items(.data)[param_inst].pl_tok.src(), | 7961 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), |
| 7956 | .param_anytype => fn_zir.instructions.items(.data)[param_inst].str_tok.src(), | 7962 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), |
| 7957 | else => unreachable, | 7963 | else => unreachable, |
| 7958 | }; | 7964 | }; |
| 7959 | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); | 7965 | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); |
| ... | @@ -7975,9 +7981,9 @@ fn instantiateGenericCall( | ... | @@ -7975,9 +7981,9 @@ fn instantiateGenericCall( |
| 7975 | } }, | 7981 | } }, |
| 7976 | })); | 7982 | })); |
| 7977 | const param_name: Zir.NullTerminatedString = switch (param_tag) { | 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 | .param => name: { | 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 | const extra = fn_zir.extraData(Zir.Inst.Param, inst_data.payload_index); | 7987 | const extra = fn_zir.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 7982 | break :name @enumFromInt(extra.data.name); | 7988 | break :name @enumFromInt(extra.data.name); |
| 7983 | }, | 7989 | }, |
| ... | @@ -8094,7 +8100,7 @@ fn emitDbgInline( | ... | @@ -8094,7 +8100,7 @@ fn emitDbgInline( |
| 8094 | 8100 | ||
| 8095 | fn zirIntType(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8101 | fn zirIntType(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8096 | const mod = sema.mod; | 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 | const ty = try mod.intType(int_type.signedness, int_type.bit_count); | 8104 | const ty = try mod.intType(int_type.signedness, int_type.bit_count); |
| 8099 | return Air.internedToRef(ty.toIntern()); | 8105 | return Air.internedToRef(ty.toIntern()); |
| 8100 | } | 8106 | } |
| ... | @@ -8104,7 +8110,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8104,7 +8110,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8104 | defer tracy.end(); | 8110 | defer tracy.end(); |
| 8105 | 8111 | ||
| 8106 | const mod = sema.mod; | 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 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 8114 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 8109 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); | 8115 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8110 | if (child_type.zigTypeTag(mod) == .Opaque) { | 8116 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| ... | @@ -8119,7 +8125,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8119,7 +8125,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8119 | 8125 | ||
| 8120 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8126 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8121 | const mod = sema.mod; | 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 | const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) { | 8129 | const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) { |
| 8124 | // Since this is a ZIR instruction that returns a type, encountering | 8130 | // Since this is a ZIR instruction that returns a type, encountering |
| 8125 | // generic poison should not result in a failed compilation, but the | 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,7 +8148,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8142 | 8148 | ||
| 8143 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8149 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8144 | const mod = sema.mod; | 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 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8152 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { |
| 8147 | error.GenericPoison => return .generic_poison_type, | 8153 | error.GenericPoison => return .generic_poison_type, |
| 8148 | else => |e| return e, | 8154 | else => |e| return e, |
| ... | @@ -8160,7 +8166,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -8160,7 +8166,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8160 | 8166 | ||
| 8161 | fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8167 | fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8162 | const mod = sema.mod; | 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 | const src = un_node.src(); | 8170 | const src = un_node.src(); |
| 8165 | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { | 8171 | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { |
| 8166 | error.GenericPoison => return .generic_poison_type, | 8172 | error.GenericPoison => return .generic_poison_type, |
| ... | @@ -8176,7 +8182,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -8176,7 +8182,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8176 | 8182 | ||
| 8177 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8183 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8178 | const mod = sema.mod; | 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 | const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8186 | const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { |
| 8181 | // Since this is a ZIR instruction that returns a type, encountering | 8187 | // Since this is a ZIR instruction that returns a type, encountering |
| 8182 | // generic poison should not result in a failed compilation, but the | 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,7 +8199,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8193 | 8199 | ||
| 8194 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8200 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8195 | const mod = sema.mod; | 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 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8203 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8198 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 8204 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 8199 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +8219,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8213 | const tracy = trace(@src()); | 8219 | const tracy = trace(@src()); |
| 8214 | defer tracy.end(); | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8223 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8218 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8224 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8219 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 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,7 +8240,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8234 | const tracy = trace(@src()); | 8240 | const tracy = trace(@src()); |
| 8235 | defer tracy.end(); | 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 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; | 8244 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 8239 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8245 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8240 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; | 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,7 +8277,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8271 | const tracy = trace(@src()); | 8277 | const tracy = trace(@src()); |
| 8272 | defer tracy.end(); | 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 | if (true) { | 8281 | if (true) { |
| 8276 | return sema.failWithUseOfAsync(block, inst_data.src()); | 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,7 +8294,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8288 | defer tracy.end(); | 8294 | defer tracy.end(); |
| 8289 | 8295 | ||
| 8290 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8298 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8293 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 8299 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 8294 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 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,7 +8327,7 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p |
| 8321 | fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8327 | fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8322 | _ = block; | 8328 | _ = block; |
| 8323 | const mod = sema.mod; | 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 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 8331 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 8326 | _ = try mod.getErrorValue(name); | 8332 | _ = try mod.getErrorValue(name); |
| 8327 | // Create an error set type with only this error value, and return the value. | 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,7 +8426,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8420 | 8426 | ||
| 8421 | const mod = sema.mod; | 8427 | const mod = sema.mod; |
| 8422 | const ip = &mod.intern_pool; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8430 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8425 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 8431 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 8426 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +8481,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8475 | defer tracy.end(); | 8481 | defer tracy.end(); |
| 8476 | 8482 | ||
| 8477 | const mod = sema.mod; | 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 | const name = inst_data.get(sema.code); | 8485 | const name = inst_data.get(sema.code); |
| 8480 | return Air.internedToRef((try mod.intern(.{ | 8486 | return Air.internedToRef((try mod.intern(.{ |
| 8481 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name), | 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,7 +8490,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8484 | 8490 | ||
| 8485 | fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8491 | fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8486 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 8494 | const src = inst_data.src(); |
| 8489 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8495 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8490 | const operand = try sema.resolveInst(inst_data.operand); | 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,7 +8535,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8529 | 8535 | ||
| 8530 | fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8536 | fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8531 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8539 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8534 | const src = inst_data.src(); | 8540 | const src = inst_data.src(); |
| 8535 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8541 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | @@ -8610,7 +8616,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -8610,7 +8616,7 @@ fn zirOptionalPayloadPtr( |
| 8610 | const tracy = trace(@src()); | 8616 | const tracy = trace(@src()); |
| 8611 | defer tracy.end(); | 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 | const optional_ptr = try sema.resolveInst(inst_data.operand); | 8620 | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 8615 | const src = inst_data.src(); | 8621 | const src = inst_data.src(); |
| 8616 | 8622 | ||
| ... | @@ -8695,7 +8701,7 @@ fn zirOptionalPayload( | ... | @@ -8695,7 +8701,7 @@ fn zirOptionalPayload( |
| 8695 | defer tracy.end(); | 8701 | defer tracy.end(); |
| 8696 | 8702 | ||
| 8697 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 8705 | const src = inst_data.src(); |
| 8700 | const operand = try sema.resolveInst(inst_data.operand); | 8706 | const operand = try sema.resolveInst(inst_data.operand); |
| 8701 | const operand_ty = sema.typeOf(operand); | 8707 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -8747,7 +8753,7 @@ fn zirErrUnionPayload( | ... | @@ -8747,7 +8753,7 @@ fn zirErrUnionPayload( |
| 8747 | defer tracy.end(); | 8753 | defer tracy.end(); |
| 8748 | 8754 | ||
| 8749 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 8757 | const src = inst_data.src(); |
| 8752 | const operand = try sema.resolveInst(inst_data.operand); | 8758 | const operand = try sema.resolveInst(inst_data.operand); |
| 8753 | const operand_src = src; | 8759 | const operand_src = src; |
| ... | @@ -8799,7 +8805,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -8799,7 +8805,7 @@ fn zirErrUnionPayloadPtr( |
| 8799 | const tracy = trace(@src()); | 8805 | const tracy = trace(@src()); |
| 8800 | defer tracy.end(); | 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 | const operand = try sema.resolveInst(inst_data.operand); | 8809 | const operand = try sema.resolveInst(inst_data.operand); |
| 8804 | const src = inst_data.src(); | 8810 | const src = inst_data.src(); |
| 8805 | 8811 | ||
| ... | @@ -8883,7 +8889,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8883,7 +8889,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8883 | const tracy = trace(@src()); | 8889 | const tracy = trace(@src()); |
| 8884 | defer tracy.end(); | 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 | const src = inst_data.src(); | 8893 | const src = inst_data.src(); |
| 8888 | const operand = try sema.resolveInst(inst_data.operand); | 8894 | const operand = try sema.resolveInst(inst_data.operand); |
| 8889 | return sema.analyzeErrUnionCode(block, src, operand); | 8895 | return sema.analyzeErrUnionCode(block, src, operand); |
| ... | @@ -8917,7 +8923,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8917,7 +8923,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8917 | defer tracy.end(); | 8923 | defer tracy.end(); |
| 8918 | 8924 | ||
| 8919 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 8927 | const src = inst_data.src(); |
| 8922 | const operand = try sema.resolveInst(inst_data.operand); | 8928 | const operand = try sema.resolveInst(inst_data.operand); |
| 8923 | const operand_ty = sema.typeOf(operand); | 8929 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -8949,7 +8955,7 @@ fn zirFunc( | ... | @@ -8949,7 +8955,7 @@ fn zirFunc( |
| 8949 | inferred_error_set: bool, | 8955 | inferred_error_set: bool, |
| 8950 | ) CompileError!Air.Inst.Ref { | 8956 | ) CompileError!Air.Inst.Ref { |
| 8951 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); | 8959 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 8954 | const target = sema.mod.getTarget(); | 8960 | const target = sema.mod.getTarget(); |
| 8955 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; | 8961 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; |
| ... | @@ -8971,7 +8977,7 @@ fn zirFunc( | ... | @@ -8971,7 +8977,7 @@ fn zirFunc( |
| 8971 | } | 8977 | } |
| 8972 | }, | 8978 | }, |
| 8973 | else => blk: { | 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 | extra_index += ret_ty_body.len; | 8981 | extra_index += ret_ty_body.len; |
| 8976 | 8982 | ||
| 8977 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ | 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,9 +9597,9 @@ fn finishFunc( |
| 9591 | param_body[0..block.params.len], | 9597 | param_body[0..block.params.len], |
| 9592 | ) |is_comptime, name_nts, param_index| { | 9598 | ) |is_comptime, name_nts, param_index| { |
| 9593 | if (!is_comptime) { | 9599 | if (!is_comptime) { |
| 9594 | const param_src = switch (tags[param_index]) { | 9600 | const param_src = switch (tags[@intFromEnum(param_index)]) { |
| 9595 | .param => data[param_index].pl_tok.src(), | 9601 | .param => data[@intFromEnum(param_index)].pl_tok.src(), |
| 9596 | .param_anytype => data[param_index].str_tok.src(), | 9602 | .param_anytype => data[@intFromEnum(param_index)].str_tok.src(), |
| 9597 | else => unreachable, | 9603 | else => unreachable, |
| 9598 | }; | 9604 | }; |
| 9599 | const name = sema.code.nullTerminatedString2(name_nts); | 9605 | const name = sema.code.nullTerminatedString2(name_nts); |
| ... | @@ -9667,11 +9673,11 @@ fn zirParam( | ... | @@ -9667,11 +9673,11 @@ fn zirParam( |
| 9667 | inst: Zir.Inst.Index, | 9673 | inst: Zir.Inst.Index, |
| 9668 | comptime_syntax: bool, | 9674 | comptime_syntax: bool, |
| 9669 | ) CompileError!void { | 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 | const src = inst_data.src(); | 9677 | const src = inst_data.src(); |
| 9672 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); | 9678 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 9673 | const param_name: Zir.NullTerminatedString = @enumFromInt(extra.data.name); | 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 | const param_ty = param_ty: { | 9682 | const param_ty = param_ty: { |
| 9677 | const err = err: { | 9683 | const err = err: { |
| ... | @@ -9760,7 +9766,7 @@ fn zirParamAnytype( | ... | @@ -9760,7 +9766,7 @@ fn zirParamAnytype( |
| 9760 | inst: Zir.Inst.Index, | 9766 | inst: Zir.Inst.Index, |
| 9761 | comptime_syntax: bool, | 9767 | comptime_syntax: bool, |
| 9762 | ) CompileError!void { | 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 | const param_name: Zir.NullTerminatedString = @enumFromInt(inst_data.start); | 9770 | const param_name: Zir.NullTerminatedString = @enumFromInt(inst_data.start); |
| 9765 | 9771 | ||
| 9766 | // We are evaluating a generic function without any comptime args provided. | 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,7 +9783,7 @@ fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst |
| 9777 | const tracy = trace(@src()); | 9783 | const tracy = trace(@src()); |
| 9778 | defer tracy.end(); | 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 | return sema.analyzeAs(block, sema.src, bin_inst.lhs, bin_inst.rhs, false); | 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,7 +9791,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 9785 | const tracy = trace(@src()); | 9791 | const tracy = trace(@src()); |
| 9786 | defer tracy.end(); | 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 | const src = inst_data.src(); | 9795 | const src = inst_data.src(); |
| 9790 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 9796 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 9791 | sema.src = src; | 9797 | sema.src = src; |
| ... | @@ -9796,7 +9802,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -9796,7 +9802,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 9796 | const tracy = trace(@src()); | 9802 | const tracy = trace(@src()); |
| 9797 | defer tracy.end(); | 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 | const src = inst_data.src(); | 9806 | const src = inst_data.src(); |
| 9801 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 9807 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 9802 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); | 9808 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); |
| ... | @@ -9828,8 +9834,8 @@ fn analyzeAs( | ... | @@ -9828,8 +9834,8 @@ fn analyzeAs( |
| 9828 | if (dest_ty_tag == .NoReturn) { | 9834 | if (dest_ty_tag == .NoReturn) { |
| 9829 | return sema.fail(block, src, "cannot cast to noreturn", .{}); | 9835 | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 9830 | } | 9836 | } |
| 9831 | const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| | 9837 | const is_ret = if (zir_dest_type.toIndex()) |ptr_index| |
| 9832 | sema.code.instructions.items(.tag)[ptr_index] == .ret_type | 9838 | sema.code.instructions.items(.tag)[@intFromEnum(ptr_index)] == .ret_type |
| 9833 | else | 9839 | else |
| 9834 | false; | 9840 | false; |
| 9835 | 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) { | 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,7 +9849,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9843 | defer tracy.end(); | 9849 | defer tracy.end(); |
| 9844 | 9850 | ||
| 9845 | const mod = sema.mod; | 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 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9853 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9848 | const operand = try sema.resolveInst(inst_data.operand); | 9854 | const operand = try sema.resolveInst(inst_data.operand); |
| 9849 | const operand_ty = sema.typeOf(operand); | 9855 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -9909,7 +9915,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -9909,7 +9915,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9909 | defer tracy.end(); | 9915 | defer tracy.end(); |
| 9910 | 9916 | ||
| 9911 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 9919 | const src = inst_data.src(); |
| 9914 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 9920 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9915 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 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,7 +9929,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9923 | defer tracy.end(); | 9929 | defer tracy.end(); |
| 9924 | 9930 | ||
| 9925 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 9933 | const src = inst_data.src(); |
| 9928 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 9934 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9929 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 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,7 +9943,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 9937 | defer tracy.end(); | 9943 | defer tracy.end(); |
| 9938 | 9944 | ||
| 9939 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 9947 | const src = inst_data.src(); |
| 9942 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 9948 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| 9943 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 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,7 +9964,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9958 | const tracy = trace(@src()); | 9964 | const tracy = trace(@src()); |
| 9959 | defer tracy.end(); | 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 | const src = inst_data.src(); | 9968 | const src = inst_data.src(); |
| 9963 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9969 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9964 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 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,7 +9979,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9973 | const tracy = trace(@src()); | 9979 | const tracy = trace(@src()); |
| 9974 | defer tracy.end(); | 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 | const src = inst_data.src(); | 9983 | const src = inst_data.src(); |
| 9978 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9984 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9979 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 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,7 +9994,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9988 | const tracy = trace(@src()); | 9994 | const tracy = trace(@src()); |
| 9989 | defer tracy.end(); | 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 | const src = inst_data.src(); | 9998 | const src = inst_data.src(); |
| 9993 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9999 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9994 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +10155,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10149 | defer tracy.end(); | 10155 | defer tracy.end(); |
| 10150 | 10156 | ||
| 10151 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 10159 | const src = inst_data.src(); |
| 10154 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10160 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 10155 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +10298,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10292 | defer tracy.end(); | 10298 | defer tracy.end(); |
| 10293 | 10299 | ||
| 10294 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 10302 | const src = inst_data.src(); |
| 10297 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10303 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 10298 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +10377,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10371 | const tracy = trace(@src()); | 10377 | const tracy = trace(@src()); |
| 10372 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10381 | const src = inst_data.src(); |
| 10376 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10382 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10377 | const array = try sema.resolveInst(extra.lhs); | 10383 | const array = try sema.resolveInst(extra.lhs); |
| ... | @@ -10383,7 +10389,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10383,7 +10389,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10383 | const tracy = trace(@src()); | 10389 | const tracy = trace(@src()); |
| 10384 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10393 | const src = inst_data.src(); |
| 10388 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10394 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 10389 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +10403,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10397 | defer tracy.end(); | 10403 | defer tracy.end(); |
| 10398 | 10404 | ||
| 10399 | const mod = sema.mod; | 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 | const array = try sema.resolveInst(inst_data.operand); | 10407 | const array = try sema.resolveInst(inst_data.operand); |
| 10402 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); | 10408 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); |
| 10403 | return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false); | 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,7 +10414,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10408 | defer tracy.end(); | 10414 | defer tracy.end(); |
| 10409 | 10415 | ||
| 10410 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 10418 | const src = inst_data.src(); |
| 10413 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10419 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10414 | const array_ptr = try sema.resolveInst(extra.lhs); | 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,7 +10441,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10435 | const tracy = trace(@src()); | 10441 | const tracy = trace(@src()); |
| 10436 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10445 | const src = inst_data.src(); |
| 10440 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10446 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; |
| 10441 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +10455,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 10449 | defer tracy.end(); | 10455 | defer tracy.end(); |
| 10450 | 10456 | ||
| 10451 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 10459 | const src = inst_data.src(); |
| 10454 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; | 10460 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 10455 | const array_ptr = try sema.resolveInst(extra.ptr); | 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,7 +10474,7 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10468 | const tracy = trace(@src()); | 10474 | const tracy = trace(@src()); |
| 10469 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10478 | const src = inst_data.src(); |
| 10473 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; | 10479 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 10474 | const array_ptr = try sema.resolveInst(extra.lhs); | 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,7 +10490,7 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10484 | const tracy = trace(@src()); | 10490 | const tracy = trace(@src()); |
| 10485 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10494 | const src = inst_data.src(); |
| 10489 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; | 10495 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 10490 | const array_ptr = try sema.resolveInst(extra.lhs); | 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,7 +10507,7 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10501 | const tracy = trace(@src()); | 10507 | const tracy = trace(@src()); |
| 10502 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10511 | const src = inst_data.src(); |
| 10506 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; | 10512 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; |
| 10507 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; | 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,7 +10526,7 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10520 | const tracy = trace(@src()); | 10526 | const tracy = trace(@src()); |
| 10521 | defer tracy.end(); | 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 | const src = inst_data.src(); | 10530 | const src = inst_data.src(); |
| 10525 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; | 10531 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 10526 | const array_ptr = try sema.resolveInst(extra.lhs); | 10532 | const array_ptr = try sema.resolveInst(extra.lhs); |
| ... | @@ -10581,7 +10587,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10581,7 +10587,7 @@ const SwitchProngAnalysis = struct { |
| 10581 | merges: *Block.Merges, | 10587 | merges: *Block.Merges, |
| 10582 | ) CompileError!Air.Inst.Ref { | 10588 | ) CompileError!Air.Inst.Ref { |
| 10583 | const sema = spa.sema; | 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 | if (has_tag_capture) { | 10592 | if (has_tag_capture) { |
| 10587 | const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); | 10593 | const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); |
| ... | @@ -10684,7 +10690,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10684,7 +10690,7 @@ const SwitchProngAnalysis = struct { |
| 10684 | const operand_ty = sema.typeOf(spa.operand); | 10690 | const operand_ty = sema.typeOf(spa.operand); |
| 10685 | if (operand_ty.zigTypeTag(mod) != .Union) { | 10691 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 10686 | const zir_datas = sema.code.instructions.items(.data); | 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 | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { | 10694 | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { |
| 10689 | .scalar_capture => |i| .{ .scalar_tag_capture = i }, | 10695 | .scalar_capture => |i| .{ .scalar_tag_capture = i }, |
| 10690 | .multi_capture => |i| .{ .multi_tag_capture = i }, | 10696 | .multi_capture => |i| .{ .multi_tag_capture = i }, |
| ... | @@ -10720,7 +10726,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10720,7 +10726,7 @@ const SwitchProngAnalysis = struct { |
| 10720 | const ip = &mod.intern_pool; | 10726 | const ip = &mod.intern_pool; |
| 10721 | 10727 | ||
| 10722 | const zir_datas = sema.code.instructions.items(.data); | 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 | const operand_ty = sema.typeOf(spa.operand); | 10731 | const operand_ty = sema.typeOf(spa.operand); |
| 10726 | const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined; | 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,7 +11152,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11146 | const mod = sema.mod; | 11152 | const mod = sema.mod; |
| 11147 | const gpa = sema.gpa; | 11153 | const gpa = sema.gpa; |
| 11148 | const ip = &mod.intern_pool; | 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 | const src = inst_data.src(); | 11156 | const src = inst_data.src(); |
| 11151 | const src_node_offset = inst_data.src_node; | 11157 | const src_node_offset = inst_data.src_node; |
| 11152 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; | 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,7 +11173,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11167 | 11173 | ||
| 11168 | // AstGen guarantees that the instruction immediately preceding | 11174 | // AstGen guarantees that the instruction immediately preceding |
| 11169 | // switch_block(_ref) is a dbg_stmt | 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 | var header_extra_index: usize = extra.end; | 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,7 +11185,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11179 | } else 0; | 11185 | } else 0; |
| 11180 | 11186 | ||
| 11181 | const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: { | 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 | header_extra_index += 1; | 11189 | header_extra_index += 1; |
| 11184 | // SwitchProngAnalysis wants inst_map to have space for the tag capture. | 11190 | // SwitchProngAnalysis wants inst_map to have space for the tag capture. |
| 11185 | // Note that the normal capture is referred to via the switch block | 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,7 +11218,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11212 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]); | 11218 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]); |
| 11213 | const extra_body_start = header_extra_index + 1; | 11219 | const extra_body_start = header_extra_index + 1; |
| 11214 | break :blk .{ | 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 | .end = extra_body_start + info.body_len, | 11222 | .end = extra_body_start + info.body_len, |
| 11217 | .capture = info.capture, | 11223 | .capture = info.capture, |
| 11218 | .is_inline = info.is_inline, | 11224 | .is_inline = info.is_inline, |
| ... | @@ -11482,7 +11488,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11482,7 +11488,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11482 | // else => |e| return e, | 11488 | // else => |e| return e, |
| 11483 | // even if all the possible errors were already handled. | 11489 | // even if all the possible errors were already handled. |
| 11484 | const tags = sema.code.instructions.items(.tag); | 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 | .dbg_block_begin, | 11492 | .dbg_block_begin, |
| 11487 | .dbg_block_end, | 11493 | .dbg_block_end, |
| 11488 | .dbg_stmt, | 11494 | .dbg_stmt, |
| ... | @@ -11826,7 +11832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11826,7 +11832,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11826 | extra_index += 1; | 11832 | extra_index += 1; |
| 11827 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); | 11833 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11828 | extra_index += 1; | 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 | extra_index += info.body_len; | 11836 | extra_index += info.body_len; |
| 11831 | 11837 | ||
| 11832 | const item = case_vals.items[scalar_i]; | 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,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11857 | extra_index += 1; | 11863 | extra_index += 1; |
| 11858 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); | 11864 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11859 | extra_index += 1 + items_len; | 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 | const items = case_vals.items[case_val_idx..][0..items_len]; | 11868 | const items = case_vals.items[case_val_idx..][0..items_len]; |
| 11863 | case_val_idx += items_len; | 11869 | case_val_idx += items_len; |
| ... | @@ -11986,7 +11992,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11986,7 +11992,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11986 | extra_index += 1; | 11992 | extra_index += 1; |
| 11987 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); | 11993 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11988 | extra_index += 1; | 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 | extra_index += info.body_len; | 11996 | extra_index += info.body_len; |
| 11991 | 11997 | ||
| 11992 | case_block.instructions.shrinkRetainingCapacity(0); | 11998 | case_block.instructions.shrinkRetainingCapacity(0); |
| ... | @@ -12053,7 +12059,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12053,7 +12059,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12053 | // Generate all possible cases as scalar prongs. | 12059 | // Generate all possible cases as scalar prongs. |
| 12054 | if (info.is_inline) { | 12060 | if (info.is_inline) { |
| 12055 | const body_start = extra_index + 2 * ranges_len; | 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 | var emit_bb = false; | 12063 | var emit_bb = false; |
| 12058 | 12064 | ||
| 12059 | var range_i: u32 = 0; | 12065 | var range_i: u32 = 0; |
| ... | @@ -12184,7 +12190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12184,7 +12190,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12184 | else | 12190 | else |
| 12185 | true; | 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 | extra_index += info.body_len; | 12194 | extra_index += info.body_len; |
| 12189 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { | 12195 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12190 | // nothing to do here | 12196 | // nothing to do here |
| ... | @@ -12268,7 +12274,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12268,7 +12274,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12268 | case_block.instructions.shrinkRetainingCapacity(0); | 12274 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12269 | case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope); | 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 | extra_index += info.body_len; | 12278 | extra_index += info.body_len; |
| 12273 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { | 12279 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12274 | // nothing to do here | 12280 | // nothing to do here |
| ... | @@ -12493,8 +12499,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12493,8 +12499,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12493 | case_block.instructions.shrinkRetainingCapacity(0); | 12499 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12494 | case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope); | 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 | 12502 | if (mod.backendSupportsFeature(.is_named_enum_value) and |
| 12497 | operand_ty.zigTypeTag(mod) == .Enum and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) | 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 | try sema.zirDbgStmt(&case_block, cond_dbg_node_index); | 12507 | try sema.zirDbgStmt(&case_block, cond_dbg_node_index); |
| 12500 | const ok = try case_block.addUnOp(.is_named_enum_value, operand); | 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,7 +12887,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12879 | 12887 | ||
| 12880 | const tags = sema.code.instructions.items(.tag); | 12888 | const tags = sema.code.instructions.items(.tag); |
| 12881 | for (body) |inst| { | 12889 | for (body) |inst| { |
| 12882 | switch (tags[inst]) { | 12890 | switch (tags[@intFromEnum(inst)]) { |
| 12883 | .@"unreachable" => if (!block.wantSafety()) return false, | 12891 | .@"unreachable" => if (!block.wantSafety()) return false, |
| 12884 | .save_err_ret_index, | 12892 | .save_err_ret_index, |
| 12885 | .dbg_block_begin, | 12893 | .dbg_block_begin, |
| ... | @@ -12895,7 +12903,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op | ... | @@ -12895,7 +12903,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12895 | } | 12903 | } |
| 12896 | 12904 | ||
| 12897 | for (body) |inst| { | 12905 | for (body) |inst| { |
| 12898 | const air_inst = switch (tags[inst]) { | 12906 | const air_inst = switch (tags[@intFromEnum(inst)]) { |
| 12899 | .dbg_block_begin, | 12907 | .dbg_block_begin, |
| 12900 | .dbg_block_end, | 12908 | .dbg_block_end, |
| 12901 | => continue, | 12909 | => continue, |
| ... | @@ -12923,7 +12931,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op | ... | @@ -12923,7 +12931,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12923 | return true; | 12931 | return true; |
| 12924 | }, | 12932 | }, |
| 12925 | .panic => { | 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 | const msg_inst = try sema.resolveInst(inst_data.operand); | 12935 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 12928 | 12936 | ||
| 12929 | const panic_fn = try sema.getBuiltin("panic"); | 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,10 +12951,10 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 12943 | 12951 | ||
| 12944 | fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void { | 12952 | fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void { |
| 12945 | const mod = sema.mod; | 12953 | const mod = sema.mod; |
| 12946 | const index = Zir.refToIndex(cond) orelse return; | 12954 | const index = cond.toIndex() orelse return; |
| 12947 | if (sema.code.instructions.items(.tag)[index] != .is_non_err) 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 | const err_operand = try sema.resolveInst(err_inst_data.operand); | 12958 | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 12951 | const operand_ty = sema.typeOf(err_operand); | 12959 | const operand_ty = sema.typeOf(err_operand); |
| 12952 | if (operand_ty.zigTypeTag(mod) == .ErrorSet) { | 12960 | if (operand_ty.zigTypeTag(mod) == .ErrorSet) { |
| ... | @@ -12963,7 +12971,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind | ... | @@ -12963,7 +12971,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind |
| 12963 | fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !void { | 12971 | fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref) !void { |
| 12964 | const tags = sema.code.instructions.items(.tag); | 12972 | const tags = sema.code.instructions.items(.tag); |
| 12965 | const inst = for (body) |inst| { | 12973 | const inst = for (body) |inst| { |
| 12966 | switch (tags[inst]) { | 12974 | switch (tags[@intFromEnum(inst)]) { |
| 12967 | .dbg_block_begin, | 12975 | .dbg_block_begin, |
| 12968 | .dbg_block_end, | 12976 | .dbg_block_end, |
| 12969 | .dbg_stmt, | 12977 | .dbg_stmt, |
| ... | @@ -12973,7 +12981,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I | ... | @@ -12973,7 +12981,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 12973 | else => return, | 12981 | else => return, |
| 12974 | } | 12982 | } |
| 12975 | } else return; | 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 | const src = inst_data.src(); | 12985 | const src = inst_data.src(); |
| 12978 | 12986 | ||
| 12979 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 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,7 +12993,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 12985 | 12993 | ||
| 12986 | fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12994 | fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 12987 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 12997 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 12990 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12998 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12991 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +13044,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13036 | 13044 | ||
| 13037 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 13045 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13038 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13048 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13041 | const src = inst_data.src(); | 13049 | const src = inst_data.src(); |
| 13042 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +13072,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13064 | defer tracy.end(); | 13072 | defer tracy.end(); |
| 13065 | 13073 | ||
| 13066 | const mod = sema.mod; | 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 | const operand_src = inst_data.src(); | 13076 | const operand_src = inst_data.src(); |
| 13069 | const operand = inst_data.get(sema.code); | 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,7 +13101,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13093 | defer tracy.end(); | 13101 | defer tracy.end(); |
| 13094 | 13102 | ||
| 13095 | const mod = sema.mod; | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13105 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 13098 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 13106 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 13099 | .needed_comptime_reason = "file path name must be comptime-known", | 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,7 +13128,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13120 | 13128 | ||
| 13121 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 13129 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13122 | const mod = sema.mod; | 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 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 13132 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 13125 | _ = try mod.getErrorValue(name); | 13133 | _ = try mod.getErrorValue(name); |
| 13126 | const error_set_type = try mod.singleErrorSetType(name); | 13134 | const error_set_type = try mod.singleErrorSetType(name); |
| ... | @@ -13140,7 +13148,7 @@ fn zirShl( | ... | @@ -13140,7 +13148,7 @@ fn zirShl( |
| 13140 | defer tracy.end(); | 13148 | defer tracy.end(); |
| 13141 | 13149 | ||
| 13142 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 13152 | const src = inst_data.src(); |
| 13145 | sema.src = src; | 13153 | sema.src = src; |
| 13146 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 13154 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -13323,7 +13331,7 @@ fn zirShr( | ... | @@ -13323,7 +13331,7 @@ fn zirShr( |
| 13323 | defer tracy.end(); | 13331 | defer tracy.end(); |
| 13324 | 13332 | ||
| 13325 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 13335 | const src = inst_data.src(); |
| 13328 | sema.src = src; | 13336 | sema.src = src; |
| 13329 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 13337 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -13459,7 +13467,7 @@ fn zirBitwise( | ... | @@ -13459,7 +13467,7 @@ fn zirBitwise( |
| 13459 | defer tracy.end(); | 13467 | defer tracy.end(); |
| 13460 | 13468 | ||
| 13461 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 13471 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 13464 | sema.src = src; | 13472 | sema.src = src; |
| 13465 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +13522,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13514 | defer tracy.end(); | 13522 | defer tracy.end(); |
| 13515 | 13523 | ||
| 13516 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 13526 | const src = inst_data.src(); |
| 13519 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 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,7 +13656,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13648 | defer tracy.end(); | 13656 | defer tracy.end(); |
| 13649 | 13657 | ||
| 13650 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13660 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13653 | const lhs = try sema.resolveInst(extra.lhs); | 13661 | const lhs = try sema.resolveInst(extra.lhs); |
| 13654 | const rhs = try sema.resolveInst(extra.rhs); | 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,7 +13985,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13977 | defer tracy.end(); | 13985 | defer tracy.end(); |
| 13978 | 13986 | ||
| 13979 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13989 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13982 | const lhs = try sema.resolveInst(extra.lhs); | 13990 | const lhs = try sema.resolveInst(extra.lhs); |
| 13983 | const lhs_ty = sema.typeOf(lhs); | 13991 | const lhs_ty = sema.typeOf(lhs); |
| ... | @@ -14116,7 +14124,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14116,7 +14124,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14116 | 14124 | ||
| 14117 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14125 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14118 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 14128 | const src = inst_data.src(); |
| 14121 | const lhs_src = src; | 14129 | const lhs_src = src; |
| 14122 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 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,7 +14156,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14148 | 14156 | ||
| 14149 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14157 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14150 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 14160 | const src = inst_data.src(); |
| 14153 | const lhs_src = src; | 14161 | const lhs_src = src; |
| 14154 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 14162 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| ... | @@ -14176,7 +14184,7 @@ fn zirArithmetic( | ... | @@ -14176,7 +14184,7 @@ fn zirArithmetic( |
| 14176 | const tracy = trace(@src()); | 14184 | const tracy = trace(@src()); |
| 14177 | defer tracy.end(); | 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 | sema.src = .{ .node_offset_bin_op = inst_data.src_node }; | 14188 | sema.src = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14181 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14189 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14182 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14190 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| ... | @@ -14189,7 +14197,7 @@ fn zirArithmetic( | ... | @@ -14189,7 +14197,7 @@ fn zirArithmetic( |
| 14189 | 14197 | ||
| 14190 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14198 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14191 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14201 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14194 | sema.src = src; | 14202 | sema.src = src; |
| 14195 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +14363,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14355 | 14363 | ||
| 14356 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14364 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14357 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14367 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14360 | sema.src = src; | 14368 | sema.src = src; |
| 14361 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +14529,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14521 | 14529 | ||
| 14522 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14530 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14523 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14533 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14526 | sema.src = src; | 14534 | sema.src = src; |
| 14527 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +14640,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14632 | 14640 | ||
| 14633 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14641 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14634 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14644 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14637 | sema.src = src; | 14645 | sema.src = src; |
| 14638 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +14882,7 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst |
| 14874 | 14882 | ||
| 14875 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 14883 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14876 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14886 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 14879 | sema.src = src; | 14887 | sema.src = src; |
| 14880 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +15067,7 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr |
| 15059 | 15067 | ||
| 15060 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15068 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15061 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15071 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 15064 | sema.src = src; | 15072 | sema.src = src; |
| 15065 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +15163,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15155 | 15163 | ||
| 15156 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15164 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15157 | const mod = sema.mod; | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15167 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 15160 | sema.src = src; | 15168 | sema.src = src; |
| 15161 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 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,7 +16079,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In |
| 16071 | const tracy = trace(@src()); | 16079 | const tracy = trace(@src()); |
| 16072 | defer tracy.end(); | 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 | const src = inst_data.src(); | 16083 | const src = inst_data.src(); |
| 16076 | const ptr_src = src; // TODO better source location | 16084 | const ptr_src = src; // TODO better source location |
| 16077 | const ptr = try sema.resolveInst(inst_data.operand); | 16085 | const ptr = try sema.resolveInst(inst_data.operand); |
| ... | @@ -16251,7 +16259,7 @@ fn zirCmpEq( | ... | @@ -16251,7 +16259,7 @@ fn zirCmpEq( |
| 16251 | defer tracy.end(); | 16259 | defer tracy.end(); |
| 16252 | 16260 | ||
| 16253 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16263 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16256 | const src: LazySrcLoc = inst_data.src(); | 16264 | const src: LazySrcLoc = inst_data.src(); |
| 16257 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 16265 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -16367,7 +16375,7 @@ fn zirCmp( | ... | @@ -16367,7 +16375,7 @@ fn zirCmp( |
| 16367 | const tracy = trace(@src()); | 16375 | const tracy = trace(@src()); |
| 16368 | defer tracy.end(); | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16379 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16372 | const src: LazySrcLoc = inst_data.src(); | 16380 | const src: LazySrcLoc = inst_data.src(); |
| 16373 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 16381 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -16512,7 +16520,7 @@ fn runtimeBoolCmp( | ... | @@ -16512,7 +16520,7 @@ fn runtimeBoolCmp( |
| 16512 | 16520 | ||
| 16513 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16521 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16514 | const mod = sema.mod; | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 16524 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 16517 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 16525 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 16518 | switch (ty.zigTypeTag(mod)) { | 16526 | switch (ty.zigTypeTag(mod)) { |
| ... | @@ -16555,7 +16563,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -16555,7 +16563,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16555 | 16563 | ||
| 16556 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16564 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16557 | const mod = sema.mod; | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 16567 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 16560 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); | 16568 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 16561 | switch (operand_ty.zigTypeTag(mod)) { | 16569 | switch (operand_ty.zigTypeTag(mod)) { |
| ... | @@ -16607,7 +16615,7 @@ fn zirThis( | ... | @@ -16607,7 +16615,7 @@ fn zirThis( |
| 16607 | fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 16615 | fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 16608 | const mod = sema.mod; | 16616 | const mod = sema.mod; |
| 16609 | const gpa = sema.gpa; | 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 | // Closures are not necessarily constant values. For example, the | 16619 | // Closures are not necessarily constant values. For example, the |
| 16612 | // code might do something like this: | 16620 | // code might do something like this: |
| 16613 | // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; } | 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,7 +16637,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 16629 | fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16637 | fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16630 | const mod = sema.mod; | 16638 | const mod = sema.mod; |
| 16631 | //const ip = &mod.intern_pool; | 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 | var scope: CaptureScope.Index = mod.declPtr(block.src_decl).src_scope; | 16641 | var scope: CaptureScope.Index = mod.declPtr(block.src_decl).src_scope; |
| 16634 | assert(scope != .none); | 16642 | assert(scope != .none); |
| 16635 | // Note: The target closure must be in this scope list. | 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,7 +16826,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16818 | const mod = sema.mod; | 16826 | const mod = sema.mod; |
| 16819 | const gpa = sema.gpa; | 16827 | const gpa = sema.gpa; |
| 16820 | const ip = &mod.intern_pool; | 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 | const src = inst_data.src(); | 16830 | const src = inst_data.src(); |
| 16823 | const ty = try sema.resolveType(block, src, inst_data.operand); | 16831 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 16824 | const type_info_ty = try sema.getBuiltinType("Type"); | 16832 | const type_info_ty = try sema.getBuiltinType("Type"); |
| ... | @@ -17923,16 +17931,16 @@ fn typeInfoNamespaceDecls( | ... | @@ -17923,16 +17931,16 @@ fn typeInfoNamespaceDecls( |
| 17923 | fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17931 | fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17924 | _ = block; | 17932 | _ = block; |
| 17925 | const zir_datas = sema.code.instructions.items(.data); | 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 | const operand = try sema.resolveInst(inst_data.operand); | 17935 | const operand = try sema.resolveInst(inst_data.operand); |
| 17928 | const operand_ty = sema.typeOf(operand); | 17936 | const operand_ty = sema.typeOf(operand); |
| 17929 | return Air.internedToRef(operand_ty.toIntern()); | 17937 | return Air.internedToRef(operand_ty.toIntern()); |
| 17930 | } | 17938 | } |
| 17931 | 17939 | ||
| 17932 | fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); | 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 | var child_block: Block = .{ | 17945 | var child_block: Block = .{ |
| 17938 | .parent = block, | 17946 | .parent = block, |
| ... | @@ -17956,7 +17964,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -17956,7 +17964,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17956 | } | 17964 | } |
| 17957 | 17965 | ||
| 17958 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 17968 | const src = inst_data.src(); |
| 17961 | const operand = try sema.resolveInst(inst_data.operand); | 17969 | const operand = try sema.resolveInst(inst_data.operand); |
| 17962 | const operand_ty = sema.typeOf(operand); | 17970 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -18010,7 +18018,7 @@ fn zirTypeofPeer( | ... | @@ -18010,7 +18018,7 @@ fn zirTypeofPeer( |
| 18010 | 18018 | ||
| 18011 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); | 18019 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); |
| 18012 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 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 | var child_block: Block = .{ | 18023 | var child_block: Block = .{ |
| 18016 | .parent = block, | 18024 | .parent = block, |
| ... | @@ -18048,7 +18056,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18048,7 +18056,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18048 | defer tracy.end(); | 18056 | defer tracy.end(); |
| 18049 | 18057 | ||
| 18050 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 18060 | const src = inst_data.src(); |
| 18053 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 18061 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 18054 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 18062 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| ... | @@ -18074,11 +18082,11 @@ fn zirBoolBr( | ... | @@ -18074,11 +18082,11 @@ fn zirBoolBr( |
| 18074 | 18082 | ||
| 18075 | const mod = sema.mod; | 18083 | const mod = sema.mod; |
| 18076 | const datas = sema.code.instructions.items(.data); | 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 | const lhs = try sema.resolveInst(inst_data.lhs); | 18086 | const lhs = try sema.resolveInst(inst_data.lhs); |
| 18079 | const lhs_src = sema.src; | 18087 | const lhs_src = sema.src; |
| 18080 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | const gpa = sema.gpa; | 18090 | const gpa = sema.gpa; |
| 18083 | 18091 | ||
| 18084 | if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { | 18092 | if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { |
| ... | @@ -18193,7 +18201,7 @@ fn zirIsNonNull( | ... | @@ -18193,7 +18201,7 @@ fn zirIsNonNull( |
| 18193 | const tracy = trace(@src()); | 18201 | const tracy = trace(@src()); |
| 18194 | defer tracy.end(); | 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 | const src = inst_data.src(); | 18205 | const src = inst_data.src(); |
| 18198 | const operand = try sema.resolveInst(inst_data.operand); | 18206 | const operand = try sema.resolveInst(inst_data.operand); |
| 18199 | try sema.checkNullableType(block, src, sema.typeOf(operand)); | 18207 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| ... | @@ -18209,7 +18217,7 @@ fn zirIsNonNullPtr( | ... | @@ -18209,7 +18217,7 @@ fn zirIsNonNullPtr( |
| 18209 | defer tracy.end(); | 18217 | defer tracy.end(); |
| 18210 | 18218 | ||
| 18211 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 18221 | const src = inst_data.src(); |
| 18214 | const ptr = try sema.resolveInst(inst_data.operand); | 18222 | const ptr = try sema.resolveInst(inst_data.operand); |
| 18215 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod)); | 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,7 +18242,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18234 | const tracy = trace(@src()); | 18242 | const tracy = trace(@src()); |
| 18235 | defer tracy.end(); | 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 | const src = inst_data.src(); | 18246 | const src = inst_data.src(); |
| 18239 | const operand = try sema.resolveInst(inst_data.operand); | 18247 | const operand = try sema.resolveInst(inst_data.operand); |
| 18240 | try sema.checkErrorType(block, src, sema.typeOf(operand)); | 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,7 +18254,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 18246 | defer tracy.end(); | 18254 | defer tracy.end(); |
| 18247 | 18255 | ||
| 18248 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 18258 | const src = inst_data.src(); |
| 18251 | const ptr = try sema.resolveInst(inst_data.operand); | 18259 | const ptr = try sema.resolveInst(inst_data.operand); |
| 18252 | try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod)); | 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,7 +18266,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 18258 | const tracy = trace(@src()); | 18266 | const tracy = trace(@src()); |
| 18259 | defer tracy.end(); | 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 | const src = inst_data.src(); | 18270 | const src = inst_data.src(); |
| 18263 | const operand = try sema.resolveInst(inst_data.operand); | 18271 | const operand = try sema.resolveInst(inst_data.operand); |
| 18264 | return sema.analyzeIsNonErr(block, src, operand); | 18272 | return sema.analyzeIsNonErr(block, src, operand); |
| ... | @@ -18273,12 +18281,12 @@ fn zirCondbr( | ... | @@ -18273,12 +18281,12 @@ fn zirCondbr( |
| 18273 | defer tracy.end(); | 18281 | defer tracy.end(); |
| 18274 | 18282 | ||
| 18275 | const mod = sema.mod; | 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 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 18285 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; |
| 18278 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 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]; | 18288 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 18281 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 18289 | const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len); |
| 18282 | 18290 | ||
| 18283 | const uncasted_cond = try sema.resolveInst(extra.data.condition); | 18291 | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 18284 | const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src); | 18292 | const cond = try sema.coerce(parent_block, Type.bool, uncasted_cond, cond_src); |
| ... | @@ -18307,10 +18315,10 @@ fn zirCondbr( | ... | @@ -18307,10 +18315,10 @@ fn zirCondbr( |
| 18307 | defer gpa.free(true_instructions); | 18315 | defer gpa.free(true_instructions); |
| 18308 | 18316 | ||
| 18309 | const err_cond = blk: { | 18317 | const err_cond = blk: { |
| 18310 | const index = Zir.refToIndex(extra.data.condition) orelse break :blk null; | 18318 | const index = extra.data.condition.toIndex() orelse break :blk null; |
| 18311 | if (sema.code.instructions.items(.tag)[index] != .is_non_err) 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 | const err_operand = try sema.resolveInst(err_inst_data.operand); | 18322 | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 18315 | const operand_ty = sema.typeOf(err_operand); | 18323 | const operand_ty = sema.typeOf(err_operand); |
| 18316 | assert(operand_ty.zigTypeTag(mod) == .ErrorUnion); | 18324 | assert(operand_ty.zigTypeTag(mod) == .ErrorUnion); |
| ... | @@ -18341,11 +18349,11 @@ fn zirCondbr( | ... | @@ -18341,11 +18349,11 @@ fn zirCondbr( |
| 18341 | } | 18349 | } |
| 18342 | 18350 | ||
| 18343 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 18353 | const src = inst_data.src(); |
| 18346 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 18354 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 18347 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 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 | const err_union = try sema.resolveInst(extra.data.operand); | 18357 | const err_union = try sema.resolveInst(extra.data.operand); |
| 18350 | const err_union_ty = sema.typeOf(err_union); | 18358 | const err_union_ty = sema.typeOf(err_union); |
| 18351 | const mod = sema.mod; | 18359 | const mod = sema.mod; |
| ... | @@ -18387,11 +18395,11 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -18387,11 +18395,11 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18387 | } | 18395 | } |
| 18388 | 18396 | ||
| 18389 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 18399 | const src = inst_data.src(); |
| 18392 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 18400 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 18393 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 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 | const operand = try sema.resolveInst(extra.data.operand); | 18403 | const operand = try sema.resolveInst(extra.data.operand); |
| 18396 | const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src); | 18404 | const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src); |
| 18397 | const err_union_ty = sema.typeOf(err_union); | 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,7 +18511,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18503 | } | 18511 | } |
| 18504 | 18512 | ||
| 18505 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { | 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 | const src = inst_data.src(); | 18515 | const src = inst_data.src(); |
| 18508 | 18516 | ||
| 18509 | if (block.is_comptime) { | 18517 | if (block.is_comptime) { |
| ... | @@ -18528,7 +18536,7 @@ fn zirRetErrValue( | ... | @@ -18528,7 +18536,7 @@ fn zirRetErrValue( |
| 18528 | inst: Zir.Inst.Index, | 18536 | inst: Zir.Inst.Index, |
| 18529 | ) CompileError!Zir.Inst.Index { | 18537 | ) CompileError!Zir.Inst.Index { |
| 18530 | const mod = sema.mod; | 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 | const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 18540 | const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 18533 | _ = try mod.getErrorValue(err_name); | 18541 | _ = try mod.getErrorValue(err_name); |
| 18534 | const src = inst_data.src(); | 18542 | const src = inst_data.src(); |
| ... | @@ -18550,7 +18558,7 @@ fn zirRetImplicit( | ... | @@ -18550,7 +18558,7 @@ fn zirRetImplicit( |
| 18550 | defer tracy.end(); | 18558 | defer tracy.end(); |
| 18551 | 18559 | ||
| 18552 | const mod = sema.mod; | 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 | const r_brace_src = inst_data.src(); | 18562 | const r_brace_src = inst_data.src(); |
| 18555 | if (block.inlining == null and sema.func_is_naked) { | 18563 | if (block.inlining == null and sema.func_is_naked) { |
| 18556 | assert(!block.is_comptime); | 18564 | assert(!block.is_comptime); |
| ... | @@ -18595,7 +18603,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir | ... | @@ -18595,7 +18603,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 18595 | const tracy = trace(@src()); | 18603 | const tracy = trace(@src()); |
| 18596 | defer tracy.end(); | 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 | const operand = try sema.resolveInst(inst_data.operand); | 18607 | const operand = try sema.resolveInst(inst_data.operand); |
| 18600 | const src = inst_data.src(); | 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,7 +18614,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 18606 | const tracy = trace(@src()); | 18614 | const tracy = trace(@src()); |
| 18607 | defer tracy.end(); | 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 | const src = inst_data.src(); | 18618 | const src = inst_data.src(); |
| 18611 | const ret_ptr = try sema.resolveInst(inst_data.operand); | 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,7 +18701,7 @@ fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool { |
| 18693 | 18701 | ||
| 18694 | fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 18702 | fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 18695 | const mod = sema.mod; | 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 | if (!mod.backendSupportsFeature(.error_return_trace)) return; | 18706 | if (!mod.backendSupportsFeature(.error_return_trace)) return; |
| 18699 | if (!mod.comp.bin_file.options.error_return_tracing) return; | 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,7 +18720,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18712 | } | 18720 | } |
| 18713 | 18721 | ||
| 18714 | fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void { | 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 | const src = sema.src; // TODO | 18724 | const src = sema.src; // TODO |
| 18717 | 18725 | ||
| 18718 | // This is only relevant at runtime. | 18726 | // This is only relevant at runtime. |
| ... | @@ -18728,7 +18736,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) | ... | @@ -18728,7 +18736,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) |
| 18728 | const tracy = trace(@src()); | 18736 | const tracy = trace(@src()); |
| 18729 | defer tracy.end(); | 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 | var block = start_block; | 18740 | var block = start_block; |
| 18733 | while (true) { | 18741 | while (true) { |
| 18734 | if (block.label) |label| { | 18742 | if (block.label) |label| { |
| ... | @@ -18858,7 +18866,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18858,7 +18866,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18858 | defer tracy.end(); | 18866 | defer tracy.end(); |
| 18859 | 18867 | ||
| 18860 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); | 18870 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 18863 | const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node }; | 18871 | const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node }; |
| 18864 | const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node }; | 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,7 +19006,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18998 | const tracy = trace(@src()); | 19006 | const tracy = trace(@src()); |
| 18999 | defer tracy.end(); | 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 | const src = inst_data.src(); | 19010 | const src = inst_data.src(); |
| 19003 | const obj_ty = try sema.resolveType(block, src, inst_data.operand); | 19011 | const obj_ty = try sema.resolveType(block, src, inst_data.operand); |
| 19004 | const mod = sema.mod; | 19012 | const mod = sema.mod; |
| ... | @@ -19017,7 +19025,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is | ... | @@ -19017,7 +19025,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 19017 | defer tracy.end(); | 19025 | defer tracy.end(); |
| 19018 | 19026 | ||
| 19019 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 19029 | const src = inst_data.src(); |
| 19022 | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { | 19030 | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 19023 | // Generic poison means this is an untyped anonymous empty struct init | 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,7 +19100,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 19092 | } | 19100 | } |
| 19093 | 19101 | ||
| 19094 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 19104 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19097 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 19105 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 19098 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 19106 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| ... | @@ -19154,14 +19162,14 @@ fn zirStructInit( | ... | @@ -19154,14 +19162,14 @@ fn zirStructInit( |
| 19154 | ) CompileError!Air.Inst.Ref { | 19162 | ) CompileError!Air.Inst.Ref { |
| 19155 | const gpa = sema.gpa; | 19163 | const gpa = sema.gpa; |
| 19156 | const zir_datas = sema.code.instructions.items(.data); | 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 | const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); | 19166 | const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 19159 | const src = inst_data.src(); | 19167 | const src = inst_data.src(); |
| 19160 | 19168 | ||
| 19161 | const mod = sema.mod; | 19169 | const mod = sema.mod; |
| 19162 | const ip = &mod.intern_pool; | 19170 | const ip = &mod.intern_pool; |
| 19163 | const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data; | 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 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; | 19173 | const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data; |
| 19166 | const result_ty = sema.resolveType(block, src, first_field_type_extra.container_type) catch |err| switch (err) { | 19174 | const result_ty = sema.resolveType(block, src, first_field_type_extra.container_type) catch |err| switch (err) { |
| 19167 | error.GenericPoison => { | 19175 | error.GenericPoison => { |
| ... | @@ -19194,7 +19202,7 @@ fn zirStructInit( | ... | @@ -19194,7 +19202,7 @@ fn zirStructInit( |
| 19194 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index); | 19202 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index); |
| 19195 | extra_index = item.end; | 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 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 19206 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 19199 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 19207 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 19200 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); | 19208 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| ... | @@ -19204,7 +19212,7 @@ fn zirStructInit( | ... | @@ -19204,7 +19212,7 @@ fn zirStructInit( |
| 19204 | try sema.structFieldIndex(block, resolved_ty, field_name, field_src); | 19212 | try sema.structFieldIndex(block, resolved_ty, field_name, field_src); |
| 19205 | if (field_inits[field_index] != .none) { | 19213 | if (field_inits[field_index] != .none) { |
| 19206 | const other_field_type = found_fields[field_index]; | 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 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_type_data.src_node }; | 19216 | const other_field_src: LazySrcLoc = .{ .node_offset_initializer = other_field_type_data.src_node }; |
| 19209 | const msg = msg: { | 19217 | const msg = msg: { |
| 19210 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); | 19218 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| ... | @@ -19239,7 +19247,7 @@ fn zirStructInit( | ... | @@ -19239,7 +19247,7 @@ fn zirStructInit( |
| 19239 | 19247 | ||
| 19240 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); | 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 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 19251 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; |
| 19244 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 19252 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 19245 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); | 19253 | const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start)); |
| ... | @@ -19481,7 +19489,7 @@ fn zirStructInitAnon( | ... | @@ -19481,7 +19489,7 @@ fn zirStructInitAnon( |
| 19481 | block: *Block, | 19489 | block: *Block, |
| 19482 | inst: Zir.Inst.Index, | 19490 | inst: Zir.Inst.Index, |
| 19483 | ) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 19493 | const src = inst_data.src(); |
| 19486 | const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); | 19494 | const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 19487 | return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); | 19495 | return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); |
| ... | @@ -19528,7 +19536,7 @@ fn structInitAnon( | ... | @@ -19528,7 +19536,7 @@ fn structInitAnon( |
| 19528 | .anon_init => sema.code.nullTerminatedString(item.data.field_name), | 19536 | .anon_init => sema.code.nullTerminatedString(item.data.field_name), |
| 19529 | .typed_init => name: { | 19537 | .typed_init => name: { |
| 19530 | // `item.data.field_type` references a `field_type` instruction | 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 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index); | 19540 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index); |
| 19533 | break :name sema.code.nullTerminatedString(field_type_extra.data.name_start); | 19541 | break :name sema.code.nullTerminatedString(field_type_extra.data.name_start); |
| 19534 | }, | 19542 | }, |
| ... | @@ -19650,7 +19658,7 @@ fn zirArrayInit( | ... | @@ -19650,7 +19658,7 @@ fn zirArrayInit( |
| 19650 | ) CompileError!Air.Inst.Ref { | 19658 | ) CompileError!Air.Inst.Ref { |
| 19651 | const mod = sema.mod; | 19659 | const mod = sema.mod; |
| 19652 | const gpa = sema.gpa; | 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 | const src = inst_data.src(); | 19662 | const src = inst_data.src(); |
| 19655 | 19663 | ||
| 19656 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 19664 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| ... | @@ -19813,7 +19821,7 @@ fn zirArrayInitAnon( | ... | @@ -19813,7 +19821,7 @@ fn zirArrayInitAnon( |
| 19813 | block: *Block, | 19821 | block: *Block, |
| 19814 | inst: Zir.Inst.Index, | 19822 | inst: Zir.Inst.Index, |
| 19815 | ) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 19825 | const src = inst_data.src(); |
| 19818 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 19826 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 19819 | const operands = sema.code.refSlice(extra.end, extra.data.operands_len); | 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,7 +19919,7 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In |
| 19911 | } | 19919 | } |
| 19912 | 19920 | ||
| 19913 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; | 19923 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 19916 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 19924 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19917 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +19933,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 19925 | fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19933 | fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19926 | const mod = sema.mod; | 19934 | const mod = sema.mod; |
| 19927 | const ip = &mod.intern_pool; | 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 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 19937 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 19930 | const ty_src = inst_data.src(); | 19938 | const ty_src = inst_data.src(); |
| 19931 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 19939 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; |
| ... | @@ -20034,7 +20042,7 @@ fn zirFrame( | ... | @@ -20034,7 +20042,7 @@ fn zirFrame( |
| 20034 | 20042 | ||
| 20035 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20043 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20036 | const mod = sema.mod; | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20046 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20039 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 20047 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 20040 | if (ty.isNoReturn(mod)) { | 20048 | if (ty.isNoReturn(mod)) { |
| ... | @@ -20049,7 +20057,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20049,7 +20057,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20049 | 20057 | ||
| 20050 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20058 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20051 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 20061 | const src = inst_data.src(); |
| 20054 | const operand = try sema.resolveInst(inst_data.operand); | 20062 | const operand = try sema.resolveInst(inst_data.operand); |
| 20055 | const operand_ty = sema.typeOf(operand); | 20063 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -20098,7 +20106,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -20098,7 +20106,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 20098 | } | 20106 | } |
| 20099 | 20107 | ||
| 20100 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const operand = try sema.resolveInst(inst_data.operand); | 20110 | const operand = try sema.resolveInst(inst_data.operand); |
| 20103 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20111 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20104 | 20112 | ||
| ... | @@ -20118,7 +20126,7 @@ fn zirAbs( | ... | @@ -20118,7 +20126,7 @@ fn zirAbs( |
| 20118 | inst: Zir.Inst.Index, | 20126 | inst: Zir.Inst.Index, |
| 20119 | ) CompileError!Air.Inst.Ref { | 20127 | ) CompileError!Air.Inst.Ref { |
| 20120 | const mod = sema.mod; | 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 | const operand = try sema.resolveInst(inst_data.operand); | 20130 | const operand = try sema.resolveInst(inst_data.operand); |
| 20123 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20131 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20124 | const operand_ty = sema.typeOf(operand); | 20132 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -20186,7 +20194,7 @@ fn zirUnaryMath( | ... | @@ -20186,7 +20194,7 @@ fn zirUnaryMath( |
| 20186 | defer tracy.end(); | 20194 | defer tracy.end(); |
| 20187 | 20195 | ||
| 20188 | const mod = sema.mod; | 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 | const operand = try sema.resolveInst(inst_data.operand); | 20198 | const operand = try sema.resolveInst(inst_data.operand); |
| 20191 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20199 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20192 | const operand_ty = sema.typeOf(operand); | 20200 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -20209,7 +20217,7 @@ fn zirUnaryMath( | ... | @@ -20209,7 +20217,7 @@ fn zirUnaryMath( |
| 20209 | } | 20217 | } |
| 20210 | 20218 | ||
| 20211 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20221 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 20214 | const src = inst_data.src(); | 20222 | const src = inst_data.src(); |
| 20215 | const operand = try sema.resolveInst(inst_data.operand); | 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,7 +21393,7 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 21385 | 21393 | ||
| 21386 | fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21394 | fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21387 | const mod = sema.mod; | 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 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21397 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21390 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); | 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,20 +21403,20 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21395 | } | 21403 | } |
| 21396 | 21404 | ||
| 21397 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 21407 | const src = inst_data.src(); |
| 21400 | return sema.failWithUseOfAsync(block, src); | 21408 | return sema.failWithUseOfAsync(block, src); |
| 21401 | } | 21409 | } |
| 21402 | 21410 | ||
| 21403 | fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 21413 | const src = inst_data.src(); |
| 21406 | return sema.failWithUseOfAsync(block, src); | 21414 | return sema.failWithUseOfAsync(block, src); |
| 21407 | } | 21415 | } |
| 21408 | 21416 | ||
| 21409 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21417 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21410 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 21420 | const src = inst_data.src(); |
| 21413 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 21421 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21414 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +21498,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21490 | 21498 | ||
| 21491 | fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21499 | fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21492 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 21502 | const src = inst_data.src(); |
| 21495 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 21503 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21496 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +21540,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21532 | 21540 | ||
| 21533 | fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21541 | fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21534 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 21544 | const src = inst_data.src(); |
| 21537 | 21545 | ||
| 21538 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +21815,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 21807 | } | 21815 | } |
| 21808 | 21816 | ||
| 21809 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 21819 | const src = inst_data.src(); |
| 21812 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21820 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21813 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 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,7 +22245,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 22237 | 22245 | ||
| 22238 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22246 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22239 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 22249 | const src = inst_data.src(); |
| 22242 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22250 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22243 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22251 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| ... | @@ -22326,7 +22334,7 @@ fn zirBitCount( | ... | @@ -22326,7 +22334,7 @@ fn zirBitCount( |
| 22326 | comptime comptimeOp: fn (val: Value, ty: Type, mod: *Module) u64, | 22334 | comptime comptimeOp: fn (val: Value, ty: Type, mod: *Module) u64, |
| 22327 | ) CompileError!Air.Inst.Ref { | 22335 | ) CompileError!Air.Inst.Ref { |
| 22328 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 22338 | const src = inst_data.src(); |
| 22331 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22339 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22332 | const operand = try sema.resolveInst(inst_data.operand); | 22340 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | @@ -22380,7 +22388,7 @@ fn zirBitCount( | ... | @@ -22380,7 +22388,7 @@ fn zirBitCount( |
| 22380 | 22388 | ||
| 22381 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22389 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22382 | const mod = sema.mod; | 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 | const src = inst_data.src(); | 22392 | const src = inst_data.src(); |
| 22385 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22393 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22386 | const operand = try sema.resolveInst(inst_data.operand); | 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,7 +22444,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22436 | } | 22444 | } |
| 22437 | 22445 | ||
| 22438 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 22448 | const src = inst_data.src(); |
| 22441 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22449 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22442 | const operand = try sema.resolveInst(inst_data.operand); | 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,7 +22503,7 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22495 | } | 22503 | } |
| 22496 | 22504 | ||
| 22497 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { | 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 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 22507 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; |
| 22500 | sema.src = src; | 22508 | sema.src = src; |
| 22501 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 22509 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| ... | @@ -23182,7 +23190,7 @@ fn zirCmpxchg( | ... | @@ -23182,7 +23190,7 @@ fn zirCmpxchg( |
| 23182 | 23190 | ||
| 23183 | fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23191 | fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23184 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23194 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23187 | const src = inst_data.src(); | 23195 | const src = inst_data.src(); |
| 23188 | const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +23211,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 23203 | } | 23211 | } |
| 23204 | 23212 | ||
| 23205 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23215 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23208 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23216 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23209 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 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,7 +23283,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 23275 | 23283 | ||
| 23276 | fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23284 | fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23277 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; | 23287 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 23280 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23288 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23281 | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 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,7 +23560,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 23552 | } | 23560 | } |
| 23553 | 23561 | ||
| 23554 | fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; | 23564 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 23557 | // zig fmt: off | 23565 | // zig fmt: off |
| 23558 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +23608,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23600 | 23608 | ||
| 23601 | fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23609 | fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23602 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 23612 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 23605 | const src = inst_data.src(); | 23613 | const src = inst_data.src(); |
| 23606 | // zig fmt: off | 23614 | // zig fmt: off |
| ... | @@ -23685,7 +23693,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -23685,7 +23693,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23685 | } | 23693 | } |
| 23686 | 23694 | ||
| 23687 | fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 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 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; | 23697 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 23690 | const src = inst_data.src(); | 23698 | const src = inst_data.src(); |
| 23691 | // zig fmt: off | 23699 | // zig fmt: off |
| ... | @@ -23721,7 +23729,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23721,7 +23729,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23721 | } | 23729 | } |
| 23722 | 23730 | ||
| 23723 | fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; | 23733 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 23726 | const src = inst_data.src(); | 23734 | const src = inst_data.src(); |
| 23727 | 23735 | ||
| ... | @@ -23789,7 +23797,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23789,7 +23797,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23789 | defer tracy.end(); | 23797 | defer tracy.end(); |
| 23790 | 23798 | ||
| 23791 | const mod = sema.mod; | 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 | const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23801 | const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 23794 | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 23802 | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 23795 | const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 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,7 +23888,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23880 | } | 23888 | } |
| 23881 | 23889 | ||
| 23882 | fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; | 23892 | const extra = sema.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; |
| 23885 | const src = inst_data.src(); | 23893 | const src = inst_data.src(); |
| 23886 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23894 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| ... | @@ -24002,7 +24010,7 @@ fn zirMinMax( | ... | @@ -24002,7 +24010,7 @@ fn zirMinMax( |
| 24002 | inst: Zir.Inst.Index, | 24010 | inst: Zir.Inst.Index, |
| 24003 | comptime air_tag: Air.Inst.Tag, | 24011 | comptime air_tag: Air.Inst.Tag, |
| 24004 | ) CompileError!Air.Inst.Ref { | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24014 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24007 | const src = inst_data.src(); | 24015 | const src = inst_data.src(); |
| 24008 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +24309,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A |
| 24301 | } | 24309 | } |
| 24302 | 24310 | ||
| 24303 | fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24313 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24306 | const src = inst_data.src(); | 24314 | const src = inst_data.src(); |
| 24307 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +24529,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 24521 | const mod = sema.mod; | 24529 | const mod = sema.mod; |
| 24522 | const gpa = sema.gpa; | 24530 | const gpa = sema.gpa; |
| 24523 | const ip = &mod.intern_pool; | 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 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24533 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24526 | const src = inst_data.src(); | 24534 | const src = inst_data.src(); |
| 24527 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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,7 +24615,7 @@ fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.I |
| 24607 | } | 24615 | } |
| 24608 | 24616 | ||
| 24609 | fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 24619 | const src = inst_data.src(); |
| 24612 | return sema.failWithUseOfAsync(block, src); | 24620 | return sema.failWithUseOfAsync(block, src); |
| 24613 | } | 24621 | } |
| ... | @@ -24617,7 +24625,7 @@ fn zirAwait( | ... | @@ -24617,7 +24625,7 @@ fn zirAwait( |
| 24617 | block: *Block, | 24625 | block: *Block, |
| 24618 | inst: Zir.Inst.Index, | 24626 | inst: Zir.Inst.Index, |
| 24619 | ) CompileError!Air.Inst.Ref { | 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 | const src = inst_data.src(); | 24629 | const src = inst_data.src(); |
| 24622 | 24630 | ||
| 24623 | return sema.failWithUseOfAsync(block, src); | 24631 | return sema.failWithUseOfAsync(block, src); |
| ... | @@ -24702,7 +24710,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24702,7 +24710,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24702 | defer tracy.end(); | 24710 | defer tracy.end(); |
| 24703 | 24711 | ||
| 24704 | const mod = sema.mod; | 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 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); | 24714 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 24707 | const target = mod.getTarget(); | 24715 | const target = mod.getTarget(); |
| 24708 | 24716 | ||
| ... | @@ -24731,7 +24739,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24731,7 +24739,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24731 | const @"align": ?Alignment = if (extra.data.bits.has_align_body) blk: { | 24739 | const @"align": ?Alignment = if (extra.data.bits.has_align_body) blk: { |
| 24732 | const body_len = sema.code.extra[extra_index]; | 24740 | const body_len = sema.code.extra[extra_index]; |
| 24733 | extra_index += 1; | 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 | extra_index += body.len; | 24743 | extra_index += body.len; |
| 24736 | 24744 | ||
| 24737 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{ | 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,7 +24770,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24762 | const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: { | 24770 | const @"addrspace": ?std.builtin.AddressSpace = if (extra.data.bits.has_addrspace_body) blk: { |
| 24763 | const body_len = sema.code.extra[extra_index]; | 24771 | const body_len = sema.code.extra[extra_index]; |
| 24764 | extra_index += 1; | 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 | extra_index += body.len; | 24774 | extra_index += body.len; |
| 24767 | 24775 | ||
| 24768 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); | 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,7 +24798,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24790 | const section: Section = if (extra.data.bits.has_section_body) blk: { | 24798 | const section: Section = if (extra.data.bits.has_section_body) blk: { |
| 24791 | const body_len = sema.code.extra[extra_index]; | 24799 | const body_len = sema.code.extra[extra_index]; |
| 24792 | extra_index += 1; | 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 | extra_index += body.len; | 24802 | extra_index += body.len; |
| 24795 | 24803 | ||
| 24796 | const ty = Type.slice_const_u8; | 24804 | const ty = Type.slice_const_u8; |
| ... | @@ -24818,7 +24826,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24818,7 +24826,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24818 | const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: { | 24826 | const cc: ?std.builtin.CallingConvention = if (extra.data.bits.has_cc_body) blk: { |
| 24819 | const body_len = sema.code.extra[extra_index]; | 24827 | const body_len = sema.code.extra[extra_index]; |
| 24820 | extra_index += 1; | 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 | extra_index += body.len; | 24830 | extra_index += body.len; |
| 24823 | 24831 | ||
| 24824 | const cc_ty = try sema.getBuiltinType("CallingConvention"); | 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,7 +24857,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24849 | const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: { | 24857 | const ret_ty: Type = if (extra.data.bits.has_ret_ty_body) blk: { |
| 24850 | const body_len = sema.code.extra[extra_index]; | 24858 | const body_len = sema.code.extra[extra_index]; |
| 24851 | extra_index += 1; | 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 | extra_index += body.len; | 24861 | extra_index += body.len; |
| 24854 | 24862 | ||
| 24855 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ | 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,7 +34829,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp |
| 34821 | break :blk accumulator; | 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 | assert(extended.opcode == .struct_decl); | 34833 | assert(extended.opcode == .struct_decl); |
| 34826 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 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,7 +34848,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp |
| 34840 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 34848 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 34841 | break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref); | 34849 | break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref); |
| 34842 | } else { | 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 | const ty_ref = try sema.resolveBody(&block, body, struct_type.zir_index); | 34852 | const ty_ref = try sema.resolveBody(&block, body, struct_type.zir_index); |
| 34845 | break :blk try sema.analyzeAsType(&block, backing_int_src, ty_ref); | 34853 | break :blk try sema.analyzeAsType(&block, backing_int_src, ty_ref); |
| 34846 | } | 34854 | } |
| ... | @@ -35409,7 +35417,7 @@ fn semaStructFields( | ... | @@ -35409,7 +35417,7 @@ fn semaStructFields( |
| 35409 | const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace; | 35417 | const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace; |
| 35410 | const zir = mod.namespacePtr(namespace_index).file_scope.zir; | 35418 | const zir = mod.namespacePtr(namespace_index).file_scope.zir; |
| 35411 | const zir_index = struct_type.zir_index; | 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 | assert(extended.opcode == .struct_decl); | 35421 | assert(extended.opcode == .struct_decl); |
| 35414 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 35422 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 35415 | var extra_index: usize = extended.operand; | 35423 | var extra_index: usize = extended.operand; |
| ... | @@ -35590,7 +35598,7 @@ fn semaStructFields( | ... | @@ -35590,7 +35598,7 @@ fn semaStructFields( |
| 35590 | }; | 35598 | }; |
| 35591 | } | 35599 | } |
| 35592 | assert(zir_field.type_body_len != 0); | 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 | extra_index += body.len; | 35602 | extra_index += body.len; |
| 35595 | const ty_ref = try sema.resolveBody(&block_scope, body, zir_index); | 35603 | const ty_ref = try sema.resolveBody(&block_scope, body, zir_index); |
| 35596 | break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) { | 35604 | break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) { |
| ... | @@ -35676,7 +35684,7 @@ fn semaStructFields( | ... | @@ -35676,7 +35684,7 @@ fn semaStructFields( |
| 35676 | } | 35684 | } |
| 35677 | 35685 | ||
| 35678 | if (zir_field.align_body_len > 0) { | 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 | extra_index += body.len; | 35688 | extra_index += body.len; |
| 35681 | const align_ref = try sema.resolveBody(&block_scope, body, zir_index); | 35689 | const align_ref = try sema.resolveBody(&block_scope, body, zir_index); |
| 35682 | const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { | 35690 | const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { |
| ... | @@ -35706,7 +35714,7 @@ fn semaStructFields( | ... | @@ -35706,7 +35714,7 @@ fn semaStructFields( |
| 35706 | extra_index += zir_field.type_body_len; | 35714 | extra_index += zir_field.type_body_len; |
| 35707 | extra_index += zir_field.align_body_len; | 35715 | extra_index += zir_field.align_body_len; |
| 35708 | if (zir_field.init_body_len > 0) { | 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 | extra_index += body.len; | 35718 | extra_index += body.len; |
| 35711 | const init = try sema.resolveBody(&block_scope, body, zir_index); | 35719 | const init = try sema.resolveBody(&block_scope, body, zir_index); |
| 35712 | const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) { | 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,7 +35756,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35748 | const ip = &mod.intern_pool; | 35756 | const ip = &mod.intern_pool; |
| 35749 | const decl_index = union_type.decl; | 35757 | const decl_index = union_type.decl; |
| 35750 | const zir = mod.namespacePtr(union_type.namespace).file_scope.zir; | 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 | assert(extended.opcode == .union_decl); | 35760 | assert(extended.opcode == .union_decl); |
| 35753 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 35761 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 35754 | var extra_index: usize = extended.operand; | 35762 | var extra_index: usize = extended.operand; |
| ... | @@ -35785,7 +35793,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35785,7 +35793,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35785 | while (decls_it.next()) |_| {} | 35793 | while (decls_it.next()) |_| {} |
| 35786 | extra_index = decls_it.extra_index; | 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 | extra_index += body.len; | 35797 | extra_index += body.len; |
| 35790 | 35798 | ||
| 35791 | const decl = mod.declPtr(decl_index); | 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,13 +93,18 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) { |
| 93 | inline for (fields) |field| { | 93 | inline for (fields) |field| { |
| 94 | @field(result, field.name) = switch (field.type) { | 94 | @field(result, field.name) = switch (field.type) { |
| 95 | u32 => code.extra[i], | 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 | i32, | 101 | i32, |
| 98 | Inst.Call.Flags, | 102 | Inst.Call.Flags, |
| 99 | Inst.BuiltinCall.Flags, | 103 | Inst.BuiltinCall.Flags, |
| 100 | Inst.SwitchBlock.Bits, | 104 | Inst.SwitchBlock.Bits, |
| 101 | Inst.FuncFancy.Bits, | 105 | Inst.FuncFancy.Bits, |
| 102 | => @bitCast(code.extra[i]), | 106 | => @bitCast(code.extra[i]), |
| 107 | |||
| 103 | else => @compileError("bad field type"), | 108 | else => @compileError("bad field type"), |
| 104 | }; | 109 | }; |
| 105 | i += 1; | 110 | i += 1; |
| ... | @@ -134,6 +139,10 @@ pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref { | ... | @@ -134,6 +139,10 @@ pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref { |
| 134 | return @ptrCast(code.extra[start..][0..len]); | 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 | pub fn hasCompileErrors(code: Zir) bool { | 146 | pub fn hasCompileErrors(code: Zir) bool { |
| 138 | return code.extra[@intFromEnum(ExtraIndex.compile_errors)] != 0; | 147 | return code.extra[@intFromEnum(ExtraIndex.compile_errors)] != 0; |
| 139 | } | 148 | } |
| ... | @@ -145,10 +154,6 @@ pub fn deinit(code: *Zir, gpa: Allocator) void { | ... | @@ -145,10 +154,6 @@ pub fn deinit(code: *Zir, gpa: Allocator) void { |
| 145 | code.* = undefined; | 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 | /// These are untyped instructions generated from an Abstract Syntax Tree. | 157 | /// These are untyped instructions generated from an Abstract Syntax Tree. |
| 153 | /// The data here is immutable because it is possible to have multiple | 158 | /// The data here is immutable because it is possible to have multiple |
| 154 | /// analyses on the same ZIR happening at the same time. | 159 | /// analyses on the same ZIR happening at the same time. |
| ... | @@ -2093,7 +2098,34 @@ pub const Inst = struct { | ... | @@ -2093,7 +2098,34 @@ pub const Inst = struct { |
| 2093 | }; | 2098 | }; |
| 2094 | 2099 | ||
| 2095 | /// The position of a ZIR instruction within the `Zir` instructions array. | 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 | /// A reference to ZIR instruction, or to an InternPool index, or neither. | 2130 | /// A reference to ZIR instruction, or to an InternPool index, or neither. |
| 2099 | /// | 2131 | /// |
| ... | @@ -2196,6 +2228,21 @@ pub const Inst = struct { | ... | @@ -2196,6 +2228,21 @@ pub const Inst = struct { |
| 2196 | /// value and may instead be used as a sentinel to indicate null. | 2228 | /// value and may instead be used as a sentinel to indicate null. |
| 2197 | none = @intFromEnum(InternPool.Index.none), | 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 | /// All instructions have an 8-byte payload, which is contained within | 2248 | /// All instructions have an 8-byte payload, which is contained within |
| ... | @@ -3286,7 +3333,7 @@ pub const Inst = struct { | ... | @@ -3286,7 +3333,7 @@ pub const Inst = struct { |
| 3286 | 3333 | ||
| 3287 | /// Trailing: for each `imports_len` there is an Item | 3334 | /// Trailing: for each `imports_len` there is an Item |
| 3288 | pub const Imports = struct { | 3335 | pub const Imports = struct { |
| 3289 | imports_len: Inst.Index, | 3336 | imports_len: u32, |
| 3290 | 3337 | ||
| 3291 | pub const Item = struct { | 3338 | pub const Item = struct { |
| 3292 | /// null terminated string index | 3339 | /// null terminated string index |
| ... | @@ -3371,16 +3418,16 @@ pub const DeclIterator = struct { | ... | @@ -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 | const tags = zir.instructions.items(.tag); | 3422 | const tags = zir.instructions.items(.tag); |
| 3376 | const datas = zir.instructions.items(.data); | 3423 | const datas = zir.instructions.items(.data); |
| 3377 | switch (tags[decl_inst]) { | 3424 | switch (tags[@intFromEnum(decl_inst)]) { |
| 3378 | // Functions are allowed and yield no iterations. | 3425 | // Functions are allowed and yield no iterations. |
| 3379 | // There is one case matching this in the extended instruction set below. | 3426 | // There is one case matching this in the extended instruction set below. |
| 3380 | .func, .func_inferred, .func_fancy => return declIteratorInner(zir, 0, 0), | 3427 | .func, .func_inferred, .func_fancy => return declIteratorInner(zir, 0, 0), |
| 3381 | 3428 | ||
| 3382 | .extended => { | 3429 | .extended => { |
| 3383 | const extended = datas[decl_inst].extended; | 3430 | const extended = datas[@intFromEnum(decl_inst)].extended; |
| 3384 | switch (extended.opcode) { | 3431 | switch (extended.opcode) { |
| 3385 | .struct_decl => { | 3432 | .struct_decl => { |
| 3386 | const small: Inst.StructDecl.Small = @bitCast(extended.small); | 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,7 +3516,7 @@ pub fn declIteratorInner(zir: Zir, extra_index: usize, decls_len: u32) DeclItera |
| 3469 | /// The iterator would have to allocate memory anyway to iterate. So here we populate | 3516 | /// The iterator would have to allocate memory anyway to iterate. So here we populate |
| 3470 | /// an ArrayList as the result. | 3517 | /// an ArrayList as the result. |
| 3471 | pub fn findDecls(zir: Zir, list: *std.ArrayList(Inst.Index), decl_sub_index: ExtraIndex) !void { | 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 | list.clearRetainingCapacity(); | 3520 | list.clearRetainingCapacity(); |
| 3474 | 3521 | ||
| 3475 | return zir.findDeclsInner(list, block_inst); | 3522 | return zir.findDeclsInner(list, block_inst); |
| ... | @@ -3483,32 +3530,32 @@ fn findDeclsInner( | ... | @@ -3483,32 +3530,32 @@ fn findDeclsInner( |
| 3483 | const tags = zir.instructions.items(.tag); | 3530 | const tags = zir.instructions.items(.tag); |
| 3484 | const datas = zir.instructions.items(.data); | 3531 | const datas = zir.instructions.items(.data); |
| 3485 | 3532 | ||
| 3486 | switch (tags[inst]) { | 3533 | switch (tags[@intFromEnum(inst)]) { |
| 3487 | // Functions instructions are interesting and have a body. | 3534 | // Functions instructions are interesting and have a body. |
| 3488 | .func, | 3535 | .func, |
| 3489 | .func_inferred, | 3536 | .func_inferred, |
| 3490 | => { | 3537 | => { |
| 3491 | try list.append(inst); | 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 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); | 3541 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3495 | var extra_index: usize = extra.end; | 3542 | var extra_index: usize = extra.end; |
| 3496 | switch (extra.data.ret_body_len) { | 3543 | switch (extra.data.ret_body_len) { |
| 3497 | 0 => {}, | 3544 | 0 => {}, |
| 3498 | 1 => extra_index += 1, | 3545 | 1 => extra_index += 1, |
| 3499 | else => { | 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 | extra_index += body.len; | 3548 | extra_index += body.len; |
| 3502 | try zir.findDeclsBody(list, body); | 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 | return zir.findDeclsBody(list, body); | 3553 | return zir.findDeclsBody(list, body); |
| 3507 | }, | 3554 | }, |
| 3508 | .func_fancy => { | 3555 | .func_fancy => { |
| 3509 | try list.append(inst); | 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 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); | 3559 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); |
| 3513 | var extra_index: usize = extra.end; | 3560 | var extra_index: usize = extra.end; |
| 3514 | extra_index += @intFromBool(extra.data.bits.has_lib_name); | 3561 | extra_index += @intFromBool(extra.data.bits.has_lib_name); |
| ... | @@ -3516,7 +3563,7 @@ fn findDeclsInner( | ... | @@ -3516,7 +3563,7 @@ fn findDeclsInner( |
| 3516 | if (extra.data.bits.has_align_body) { | 3563 | if (extra.data.bits.has_align_body) { |
| 3517 | const body_len = zir.extra[extra_index]; | 3564 | const body_len = zir.extra[extra_index]; |
| 3518 | extra_index += 1; | 3565 | extra_index += 1; |
| 3519 | const body = zir.extra[extra_index..][0..body_len]; | 3566 | const body = zir.bodySlice(extra_index, body_len); |
| 3520 | try zir.findDeclsBody(list, body); | 3567 | try zir.findDeclsBody(list, body); |
| 3521 | extra_index += body.len; | 3568 | extra_index += body.len; |
| 3522 | } else if (extra.data.bits.has_align_ref) { | 3569 | } else if (extra.data.bits.has_align_ref) { |
| ... | @@ -3526,7 +3573,7 @@ fn findDeclsInner( | ... | @@ -3526,7 +3573,7 @@ fn findDeclsInner( |
| 3526 | if (extra.data.bits.has_addrspace_body) { | 3573 | if (extra.data.bits.has_addrspace_body) { |
| 3527 | const body_len = zir.extra[extra_index]; | 3574 | const body_len = zir.extra[extra_index]; |
| 3528 | extra_index += 1; | 3575 | extra_index += 1; |
| 3529 | const body = zir.extra[extra_index..][0..body_len]; | 3576 | const body = zir.bodySlice(extra_index, body_len); |
| 3530 | try zir.findDeclsBody(list, body); | 3577 | try zir.findDeclsBody(list, body); |
| 3531 | extra_index += body.len; | 3578 | extra_index += body.len; |
| 3532 | } else if (extra.data.bits.has_addrspace_ref) { | 3579 | } else if (extra.data.bits.has_addrspace_ref) { |
| ... | @@ -3536,7 +3583,7 @@ fn findDeclsInner( | ... | @@ -3536,7 +3583,7 @@ fn findDeclsInner( |
| 3536 | if (extra.data.bits.has_section_body) { | 3583 | if (extra.data.bits.has_section_body) { |
| 3537 | const body_len = zir.extra[extra_index]; | 3584 | const body_len = zir.extra[extra_index]; |
| 3538 | extra_index += 1; | 3585 | extra_index += 1; |
| 3539 | const body = zir.extra[extra_index..][0..body_len]; | 3586 | const body = zir.bodySlice(extra_index, body_len); |
| 3540 | try zir.findDeclsBody(list, body); | 3587 | try zir.findDeclsBody(list, body); |
| 3541 | extra_index += body.len; | 3588 | extra_index += body.len; |
| 3542 | } else if (extra.data.bits.has_section_ref) { | 3589 | } else if (extra.data.bits.has_section_ref) { |
| ... | @@ -3546,7 +3593,7 @@ fn findDeclsInner( | ... | @@ -3546,7 +3593,7 @@ fn findDeclsInner( |
| 3546 | if (extra.data.bits.has_cc_body) { | 3593 | if (extra.data.bits.has_cc_body) { |
| 3547 | const body_len = zir.extra[extra_index]; | 3594 | const body_len = zir.extra[extra_index]; |
| 3548 | extra_index += 1; | 3595 | extra_index += 1; |
| 3549 | const body = zir.extra[extra_index..][0..body_len]; | 3596 | const body = zir.bodySlice(extra_index, body_len); |
| 3550 | try zir.findDeclsBody(list, body); | 3597 | try zir.findDeclsBody(list, body); |
| 3551 | extra_index += body.len; | 3598 | extra_index += body.len; |
| 3552 | } else if (extra.data.bits.has_cc_ref) { | 3599 | } else if (extra.data.bits.has_cc_ref) { |
| ... | @@ -3556,7 +3603,7 @@ fn findDeclsInner( | ... | @@ -3556,7 +3603,7 @@ fn findDeclsInner( |
| 3556 | if (extra.data.bits.has_ret_ty_body) { | 3603 | if (extra.data.bits.has_ret_ty_body) { |
| 3557 | const body_len = zir.extra[extra_index]; | 3604 | const body_len = zir.extra[extra_index]; |
| 3558 | extra_index += 1; | 3605 | extra_index += 1; |
| 3559 | const body = zir.extra[extra_index..][0..body_len]; | 3606 | const body = zir.bodySlice(extra_index, body_len); |
| 3560 | try zir.findDeclsBody(list, body); | 3607 | try zir.findDeclsBody(list, body); |
| 3561 | extra_index += body.len; | 3608 | extra_index += body.len; |
| 3562 | } else if (extra.data.bits.has_ret_ty_ref) { | 3609 | } else if (extra.data.bits.has_ret_ty_ref) { |
| ... | @@ -3565,11 +3612,11 @@ fn findDeclsInner( | ... | @@ -3565,11 +3612,11 @@ fn findDeclsInner( |
| 3565 | 3612 | ||
| 3566 | extra_index += @intFromBool(extra.data.bits.has_any_noalias); | 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 | return zir.findDeclsBody(list, body); | 3616 | return zir.findDeclsBody(list, body); |
| 3570 | }, | 3617 | }, |
| 3571 | .extended => { | 3618 | .extended => { |
| 3572 | const extended = datas[inst].extended; | 3619 | const extended = datas[@intFromEnum(inst)].extended; |
| 3573 | switch (extended.opcode) { | 3620 | switch (extended.opcode) { |
| 3574 | 3621 | ||
| 3575 | // Decl instructions are interesting but have no body. | 3622 | // Decl instructions are interesting but have no body. |
| ... | @@ -3587,23 +3634,23 @@ fn findDeclsInner( | ... | @@ -3587,23 +3634,23 @@ fn findDeclsInner( |
| 3587 | // Block instructions, recurse over the bodies. | 3634 | // Block instructions, recurse over the bodies. |
| 3588 | 3635 | ||
| 3589 | .block, .block_comptime, .block_inline => { | 3636 | .block, .block_comptime, .block_inline => { |
| 3590 | const inst_data = datas[inst].pl_node; | 3637 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 3591 | const extra = zir.extraData(Inst.Block, inst_data.payload_index); | 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 | return zir.findDeclsBody(list, body); | 3640 | return zir.findDeclsBody(list, body); |
| 3594 | }, | 3641 | }, |
| 3595 | .condbr, .condbr_inline => { | 3642 | .condbr, .condbr_inline => { |
| 3596 | const inst_data = datas[inst].pl_node; | 3643 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 3597 | const extra = zir.extraData(Inst.CondBr, inst_data.payload_index); | 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]; | 3645 | const then_body = zir.bodySlice(extra.end, extra.data.then_body_len); |
| 3599 | const else_body = zir.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 3646 | const else_body = zir.bodySlice(extra.end + then_body.len, extra.data.else_body_len); |
| 3600 | try zir.findDeclsBody(list, then_body); | 3647 | try zir.findDeclsBody(list, then_body); |
| 3601 | try zir.findDeclsBody(list, else_body); | 3648 | try zir.findDeclsBody(list, else_body); |
| 3602 | }, | 3649 | }, |
| 3603 | .@"try", .try_ptr => { | 3650 | .@"try", .try_ptr => { |
| 3604 | const inst_data = datas[inst].pl_node; | 3651 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 3605 | const extra = zir.extraData(Inst.Try, inst_data.payload_index); | 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 | try zir.findDeclsBody(list, body); | 3654 | try zir.findDeclsBody(list, body); |
| 3608 | }, | 3655 | }, |
| 3609 | .switch_block => return findDeclsSwitch(zir, list, inst), | 3656 | .switch_block => return findDeclsSwitch(zir, list, inst), |
| ... | @@ -3619,7 +3666,7 @@ fn findDeclsSwitch( | ... | @@ -3619,7 +3666,7 @@ fn findDeclsSwitch( |
| 3619 | list: *std.ArrayList(Inst.Index), | 3666 | list: *std.ArrayList(Inst.Index), |
| 3620 | inst: Inst.Index, | 3667 | inst: Inst.Index, |
| 3621 | ) Allocator.Error!void { | 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 | const extra = zir.extraData(Inst.SwitchBlock, inst_data.payload_index); | 3670 | const extra = zir.extraData(Inst.SwitchBlock, inst_data.payload_index); |
| 3624 | 3671 | ||
| 3625 | var extra_index: usize = extra.end; | 3672 | var extra_index: usize = extra.end; |
| ... | @@ -3634,7 +3681,7 @@ fn findDeclsSwitch( | ... | @@ -3634,7 +3681,7 @@ fn findDeclsSwitch( |
| 3634 | if (special_prong != .none) { | 3681 | if (special_prong != .none) { |
| 3635 | const body_len: u31 = @truncate(zir.extra[extra_index]); | 3682 | const body_len: u31 = @truncate(zir.extra[extra_index]); |
| 3636 | extra_index += 1; | 3683 | extra_index += 1; |
| 3637 | const body = zir.extra[extra_index..][0..body_len]; | 3684 | const body = zir.bodySlice(extra_index, body_len); |
| 3638 | extra_index += body.len; | 3685 | extra_index += body.len; |
| 3639 | 3686 | ||
| 3640 | try zir.findDeclsBody(list, body); | 3687 | try zir.findDeclsBody(list, body); |
| ... | @@ -3642,20 +3689,18 @@ fn findDeclsSwitch( | ... | @@ -3642,20 +3689,18 @@ fn findDeclsSwitch( |
| 3642 | 3689 | ||
| 3643 | { | 3690 | { |
| 3644 | const scalar_cases_len = extra.data.bits.scalar_cases_len; | 3691 | const scalar_cases_len = extra.data.bits.scalar_cases_len; |
| 3645 | var scalar_i: usize = 0; | 3692 | for (0..scalar_cases_len) |_| { |
| 3646 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | ||
| 3647 | extra_index += 1; | 3693 | extra_index += 1; |
| 3648 | const body_len: u31 = @truncate(zir.extra[extra_index]); | 3694 | const body_len: u31 = @truncate(zir.extra[extra_index]); |
| 3649 | extra_index += 1; | 3695 | extra_index += 1; |
| 3650 | const body = zir.extra[extra_index..][0..body_len]; | 3696 | const body = zir.bodySlice(extra_index, body_len); |
| 3651 | extra_index += body_len; | 3697 | extra_index += body_len; |
| 3652 | 3698 | ||
| 3653 | try zir.findDeclsBody(list, body); | 3699 | try zir.findDeclsBody(list, body); |
| 3654 | } | 3700 | } |
| 3655 | } | 3701 | } |
| 3656 | { | 3702 | { |
| 3657 | var multi_i: usize = 0; | 3703 | for (0..multi_cases_len) |_| { |
| 3658 | while (multi_i < multi_cases_len) : (multi_i += 1) { | ||
| 3659 | const items_len = zir.extra[extra_index]; | 3704 | const items_len = zir.extra[extra_index]; |
| 3660 | extra_index += 1; | 3705 | extra_index += 1; |
| 3661 | const ranges_len = zir.extra[extra_index]; | 3706 | const ranges_len = zir.extra[extra_index]; |
| ... | @@ -3672,7 +3717,7 @@ fn findDeclsSwitch( | ... | @@ -3672,7 +3717,7 @@ fn findDeclsSwitch( |
| 3672 | extra_index += 1; | 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 | extra_index += body_len; | 3721 | extra_index += body_len; |
| 3677 | 3722 | ||
| 3678 | try zir.findDeclsBody(list, body); | 3723 | try zir.findDeclsBody(list, body); |
| ... | @@ -3699,12 +3744,12 @@ pub const FnInfo = struct { | ... | @@ -3699,12 +3744,12 @@ pub const FnInfo = struct { |
| 3699 | total_params_len: u32, | 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 | const tags = zir.instructions.items(.tag); | 3748 | const tags = zir.instructions.items(.tag); |
| 3704 | const datas = zir.instructions.items(.data); | 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 | .func, .func_inferred => blk: { | 3753 | .func, .func_inferred => blk: { |
| 3709 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); | 3754 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3710 | break :blk extra.data.param_block; | 3755 | break :blk extra.data.param_block; |
| ... | @@ -3716,8 +3761,8 @@ pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 { | ... | @@ -3716,8 +3761,8 @@ pub fn getParamBody(zir: Zir, fn_inst: Inst.Index) []const u32 { |
| 3716 | else => unreachable, | 3761 | else => unreachable, |
| 3717 | }; | 3762 | }; |
| 3718 | 3763 | ||
| 3719 | const param_block = zir.extraData(Inst.Block, datas[param_block_index].pl_node.payload_index); | 3764 | const param_block = zir.extraData(Inst.Block, datas[@intFromEnum(param_block_index)].pl_node.payload_index); |
| 3720 | return zir.extra[param_block.end..][0..param_block.data.body_len]; | 3765 | return zir.bodySlice(param_block.end, param_block.data.body_len); |
| 3721 | } | 3766 | } |
| 3722 | 3767 | ||
| 3723 | pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | 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,9 +3773,9 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3728 | body: []const Inst.Index, | 3773 | body: []const Inst.Index, |
| 3729 | ret_ty_ref: Inst.Ref, | 3774 | ret_ty_ref: Inst.Ref, |
| 3730 | ret_ty_body: []const Inst.Index, | 3775 | ret_ty_body: []const Inst.Index, |
| 3731 | } = switch (tags[fn_inst]) { | 3776 | } = switch (tags[@intFromEnum(fn_inst)]) { |
| 3732 | .func, .func_inferred => blk: { | 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 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); | 3779 | const extra = zir.extraData(Inst.Func, inst_data.payload_index); |
| 3735 | 3780 | ||
| 3736 | var extra_index: usize = extra.end; | 3781 | var extra_index: usize = extra.end; |
| ... | @@ -3746,12 +3791,12 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3746,12 +3791,12 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3746 | extra_index += 1; | 3791 | extra_index += 1; |
| 3747 | }, | 3792 | }, |
| 3748 | else => { | 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 | extra_index += ret_ty_body.len; | 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 | extra_index += body.len; | 3800 | extra_index += body.len; |
| 3756 | 3801 | ||
| 3757 | break :blk .{ | 3802 | break :blk .{ |
| ... | @@ -3762,7 +3807,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3762,7 +3807,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3762 | }; | 3807 | }; |
| 3763 | }, | 3808 | }, |
| 3764 | .func_fancy => blk: { | 3809 | .func_fancy => blk: { |
| 3765 | const inst_data = datas[fn_inst].pl_node; | 3810 | const inst_data = datas[@intFromEnum(fn_inst)].pl_node; |
| 3766 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); | 3811 | const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index); |
| 3767 | 3812 | ||
| 3768 | var extra_index: usize = extra.end; | 3813 | var extra_index: usize = extra.end; |
| ... | @@ -3793,7 +3838,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3793,7 +3838,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3793 | if (extra.data.bits.has_ret_ty_body) { | 3838 | if (extra.data.bits.has_ret_ty_body) { |
| 3794 | const body_len = zir.extra[extra_index]; | 3839 | const body_len = zir.extra[extra_index]; |
| 3795 | extra_index += 1; | 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 | extra_index += ret_ty_body.len; | 3842 | extra_index += ret_ty_body.len; |
| 3798 | } else if (extra.data.bits.has_ret_ty_ref) { | 3843 | } else if (extra.data.bits.has_ret_ty_ref) { |
| 3799 | ret_ty_ref = @enumFromInt(zir.extra[extra_index]); | 3844 | ret_ty_ref = @enumFromInt(zir.extra[extra_index]); |
| ... | @@ -3802,7 +3847,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3802,7 +3847,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3802 | 3847 | ||
| 3803 | extra_index += @intFromBool(extra.data.bits.has_any_noalias); | 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 | extra_index += body.len; | 3851 | extra_index += body.len; |
| 3807 | break :blk .{ | 3852 | break :blk .{ |
| 3808 | .param_block = extra.data.param_block, | 3853 | .param_block = extra.data.param_block, |
| ... | @@ -3813,14 +3858,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3813,14 +3858,15 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3813 | }, | 3858 | }, |
| 3814 | else => unreachable, | 3859 | else => unreachable, |
| 3815 | }; | 3860 | }; |
| 3816 | assert(tags[info.param_block] == .block or | 3861 | switch (tags[@intFromEnum(info.param_block)]) { |
| 3817 | tags[info.param_block] == .block_comptime or | 3862 | .block, .block_comptime, .block_inline => {}, // OK |
| 3818 | tags[info.param_block] == .block_inline); | 3863 | else => unreachable, // assertion failure |
| 3819 | const param_block = zir.extraData(Inst.Block, datas[info.param_block].pl_node.payload_index); | 3864 | } |
| 3820 | const param_body = zir.extra[param_block.end..][0..param_block.data.body_len]; | 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 | var total_params_len: u32 = 0; | 3867 | var total_params_len: u32 = 0; |
| 3822 | for (param_body) |inst| { | 3868 | for (param_body) |inst| { |
| 3823 | switch (tags[inst]) { | 3869 | switch (tags[@intFromEnum(inst)]) { |
| 3824 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { | 3870 | .param, .param_comptime, .param_anytype, .param_anytype_comptime => { |
| 3825 | total_params_len += 1; | 3871 | total_params_len += 1; |
| 3826 | }, | 3872 | }, |
| ... | @@ -3836,24 +3882,3 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { | ... | @@ -3836,24 +3882,3 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3836 | .total_params_len = total_params_len, | 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,7 +32,7 @@ pub fn renderAsTextToFile( |
| 32 | var raw_stream = std.io.bufferedWriter(fs_file.writer()); | 32 | var raw_stream = std.io.bufferedWriter(fs_file.writer()); |
| 33 | const stream = raw_stream.writer(); | 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 | try stream.print("%{d} ", .{main_struct_inst}); | 36 | try stream.print("%{d} ", .{main_struct_inst}); |
| 37 | try writer.writeInstToStream(stream, main_struct_inst); | 37 | try writer.writeInstToStream(stream, main_struct_inst); |
| 38 | try stream.writeAll("\n"); | 38 | try stream.writeAll("\n"); |
| ... | @@ -41,10 +41,9 @@ pub fn renderAsTextToFile( | ... | @@ -41,10 +41,9 @@ pub fn renderAsTextToFile( |
| 41 | try stream.writeAll("Imports:\n"); | 41 | try stream.writeAll("Imports:\n"); |
| 42 | 42 | ||
| 43 | const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index); | 43 | const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index); |
| 44 | var import_i: u32 = 0; | ||
| 45 | var extra_index = extra.end; | 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 | const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index); | 47 | const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index); |
| 49 | extra_index = item.end; | 48 | extra_index = item.end; |
| 50 | 49 | ||
| ... | @@ -197,8 +196,8 @@ const Writer = struct { | ... | @@ -197,8 +196,8 @@ const Writer = struct { |
| 197 | inst: Zir.Inst.Index, | 196 | inst: Zir.Inst.Index, |
| 198 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 197 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { |
| 199 | const tags = self.code.instructions.items(.tag); | 198 | const tags = self.code.instructions.items(.tag); |
| 200 | const tag = tags[inst]; | 199 | const tag = tags[@intFromEnum(inst)]; |
| 201 | try stream.print("= {s}(", .{@tagName(tags[inst])}); | 200 | try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])}); |
| 202 | switch (tag) { | 201 | switch (tag) { |
| 203 | .as, | 202 | .as, |
| 204 | .store, | 203 | .store, |
| ... | @@ -525,7 +524,7 @@ const Writer = struct { | ... | @@ -525,7 +524,7 @@ const Writer = struct { |
| 525 | } | 524 | } |
| 526 | 525 | ||
| 527 | fn writeExtended(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try stream.print("{s}(", .{@tagName(extended.opcode)}); | 528 | try stream.print("{s}(", .{@tagName(extended.opcode)}); |
| 530 | switch (extended.opcode) { | 529 | switch (extended.opcode) { |
| 531 | .this, | 530 | .this, |
| ... | @@ -622,7 +621,7 @@ const Writer = struct { | ... | @@ -622,7 +621,7 @@ const Writer = struct { |
| 622 | } | 621 | } |
| 623 | 622 | ||
| 624 | fn writeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writeInstRef(stream, inst_data.lhs); | 625 | try self.writeInstRef(stream, inst_data.lhs); |
| 627 | try stream.writeAll(", "); | 626 | try stream.writeAll(", "); |
| 628 | try self.writeInstRef(stream, inst_data.rhs); | 627 | try self.writeInstRef(stream, inst_data.rhs); |
| ... | @@ -630,7 +629,7 @@ const Writer = struct { | ... | @@ -630,7 +629,7 @@ const Writer = struct { |
| 630 | } | 629 | } |
| 631 | 630 | ||
| 632 | fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writeInstRef(stream, inst_data.lhs); | 633 | try self.writeInstRef(stream, inst_data.lhs); |
| 635 | try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)}); | 634 | try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)}); |
| 636 | } | 635 | } |
| ... | @@ -640,7 +639,7 @@ const Writer = struct { | ... | @@ -640,7 +639,7 @@ const Writer = struct { |
| 640 | stream: anytype, | 639 | stream: anytype, |
| 641 | inst: Zir.Inst.Index, | 640 | inst: Zir.Inst.Index, |
| 642 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | try self.writeInstRef(stream, inst_data.operand); | 643 | try self.writeInstRef(stream, inst_data.operand); |
| 645 | try stream.writeAll(") "); | 644 | try stream.writeAll(") "); |
| 646 | try self.writeSrc(stream, inst_data.src()); | 645 | try self.writeSrc(stream, inst_data.src()); |
| ... | @@ -651,7 +650,7 @@ const Writer = struct { | ... | @@ -651,7 +650,7 @@ const Writer = struct { |
| 651 | stream: anytype, | 650 | stream: anytype, |
| 652 | inst: Zir.Inst.Index, | 651 | inst: Zir.Inst.Index, |
| 653 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | try self.writeInstRef(stream, inst_data.operand); | 654 | try self.writeInstRef(stream, inst_data.operand); |
| 656 | try stream.writeAll(") "); | 655 | try stream.writeAll(") "); |
| 657 | try self.writeSrc(stream, inst_data.src()); | 656 | try self.writeSrc(stream, inst_data.src()); |
| ... | @@ -662,7 +661,7 @@ const Writer = struct { | ... | @@ -662,7 +661,7 @@ const Writer = struct { |
| 662 | stream: anytype, | 661 | stream: anytype, |
| 663 | inst: Zir.Inst.Index, | 662 | inst: Zir.Inst.Index, |
| 664 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; | 665 | const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 667 | try self.writeInstRef(stream, extra.operand); | 666 | try self.writeInstRef(stream, extra.operand); |
| 668 | try stream.print(", {d}) (destructure=", .{extra.expect_len}); | 667 | try stream.print(", {d}) (destructure=", .{extra.expect_len}); |
| ... | @@ -676,7 +675,7 @@ const Writer = struct { | ... | @@ -676,7 +675,7 @@ const Writer = struct { |
| 676 | stream: anytype, | 675 | stream: anytype, |
| 677 | inst: Zir.Inst.Index, | 676 | inst: Zir.Inst.Index, |
| 678 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; | 679 | const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 681 | try self.writeInstRef(stream, extra.ty); | 680 | try self.writeInstRef(stream, extra.ty); |
| 682 | try stream.print(", {d}) ", .{extra.init_count}); | 681 | try stream.print(", {d}) ", .{extra.init_count}); |
| ... | @@ -688,7 +687,7 @@ const Writer = struct { | ... | @@ -688,7 +687,7 @@ const Writer = struct { |
| 688 | stream: anytype, | 687 | stream: anytype, |
| 689 | inst: Zir.Inst.Index, | 688 | inst: Zir.Inst.Index, |
| 690 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; | 691 | const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 693 | try self.writeInstRef(stream, extra.len); | 692 | try self.writeInstRef(stream, extra.len); |
| 694 | try stream.writeAll(", "); | 693 | try stream.writeAll(", "); |
| ... | @@ -704,7 +703,7 @@ const Writer = struct { | ... | @@ -704,7 +703,7 @@ const Writer = struct { |
| 704 | stream: anytype, | 703 | stream: anytype, |
| 705 | inst: Zir.Inst.Index, | 704 | inst: Zir.Inst.Index, |
| 706 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else ""; | 707 | const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else ""; |
| 709 | const str_const = if (!inst_data.flags.is_mutable) "const, " else ""; | 708 | const str_const = if (!inst_data.flags.is_mutable) "const, " else ""; |
| 710 | const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else ""; | 709 | const str_volatile = if (inst_data.flags.is_volatile) "volatile, " else ""; |
| ... | @@ -745,12 +744,12 @@ const Writer = struct { | ... | @@ -745,12 +744,12 @@ const Writer = struct { |
| 745 | } | 744 | } |
| 746 | 745 | ||
| 747 | fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try stream.print("{d})", .{inst_data}); | 748 | try stream.print("{d})", .{inst_data}); |
| 750 | } | 749 | } |
| 751 | 750 | ||
| 752 | fn writeIntBig(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const byte_count = inst_data.len * @sizeOf(std.math.big.Limb); | 753 | const byte_count = inst_data.len * @sizeOf(std.math.big.Limb); |
| 755 | const limb_bytes = self.code.string_bytes[inst_data.start..][0..byte_count]; | 754 | const limb_bytes = self.code.string_bytes[inst_data.start..][0..byte_count]; |
| 756 | // limb_bytes is not aligned properly; we must allocate and copy the bytes | 755 | // limb_bytes is not aligned properly; we must allocate and copy the bytes |
| ... | @@ -769,12 +768,12 @@ const Writer = struct { | ... | @@ -769,12 +768,12 @@ const Writer = struct { |
| 769 | } | 768 | } |
| 770 | 769 | ||
| 771 | fn writeFloat(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try stream.print("{d})", .{number}); | 772 | try stream.print("{d})", .{number}); |
| 774 | } | 773 | } |
| 775 | 774 | ||
| 776 | fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; | 777 | const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 779 | const src = inst_data.src(); | 778 | const src = inst_data.src(); |
| 780 | const number = extra.get(); | 779 | const number = extra.get(); |
| ... | @@ -788,13 +787,13 @@ const Writer = struct { | ... | @@ -788,13 +787,13 @@ const Writer = struct { |
| 788 | stream: anytype, | 787 | stream: anytype, |
| 789 | inst: Zir.Inst.Index, | 788 | inst: Zir.Inst.Index, |
| 790 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const str = inst_data.get(self.code); | 791 | const str = inst_data.get(self.code); |
| 793 | try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)}); | 792 | try stream.print("\"{}\")", .{std.zig.fmtEscapes(str)}); |
| 794 | } | 793 | } |
| 795 | 794 | ||
| 796 | fn writeSliceStart(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; | 797 | const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 799 | try self.writeInstRef(stream, extra.lhs); | 798 | try self.writeInstRef(stream, extra.lhs); |
| 800 | try stream.writeAll(", "); | 799 | try stream.writeAll(", "); |
| ... | @@ -804,7 +803,7 @@ const Writer = struct { | ... | @@ -804,7 +803,7 @@ const Writer = struct { |
| 804 | } | 803 | } |
| 805 | 804 | ||
| 806 | fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; | 807 | const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 809 | try self.writeInstRef(stream, extra.lhs); | 808 | try self.writeInstRef(stream, extra.lhs); |
| 810 | try stream.writeAll(", "); | 809 | try stream.writeAll(", "); |
| ... | @@ -816,7 +815,7 @@ const Writer = struct { | ... | @@ -816,7 +815,7 @@ const Writer = struct { |
| 816 | } | 815 | } |
| 817 | 816 | ||
| 818 | fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; | 819 | const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 821 | try self.writeInstRef(stream, extra.lhs); | 820 | try self.writeInstRef(stream, extra.lhs); |
| 822 | try stream.writeAll(", "); | 821 | try stream.writeAll(", "); |
| ... | @@ -830,7 +829,7 @@ const Writer = struct { | ... | @@ -830,7 +829,7 @@ const Writer = struct { |
| 830 | } | 829 | } |
| 831 | 830 | ||
| 832 | fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; | 833 | const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 835 | try self.writeInstRef(stream, extra.lhs); | 834 | try self.writeInstRef(stream, extra.lhs); |
| 836 | try stream.writeAll(", "); | 835 | try stream.writeAll(", "); |
| ... | @@ -846,7 +845,7 @@ const Writer = struct { | ... | @@ -846,7 +845,7 @@ const Writer = struct { |
| 846 | } | 845 | } |
| 847 | 846 | ||
| 848 | fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; | 849 | const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 851 | try self.writeInstRef(stream, extra.union_type); | 850 | try self.writeInstRef(stream, extra.union_type); |
| 852 | try stream.writeAll(", "); | 851 | try stream.writeAll(", "); |
| ... | @@ -858,7 +857,7 @@ const Writer = struct { | ... | @@ -858,7 +857,7 @@ const Writer = struct { |
| 858 | } | 857 | } |
| 859 | 858 | ||
| 860 | fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; | 861 | const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 863 | try self.writeInstRef(stream, extra.elem_type); | 862 | try self.writeInstRef(stream, extra.elem_type); |
| 864 | try stream.writeAll(", "); | 863 | try stream.writeAll(", "); |
| ... | @@ -885,7 +884,7 @@ const Writer = struct { | ... | @@ -885,7 +884,7 @@ const Writer = struct { |
| 885 | } | 884 | } |
| 886 | 885 | ||
| 887 | fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; | 888 | const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 890 | try self.writeInstRef(stream, extra.mulend1); | 889 | try self.writeInstRef(stream, extra.mulend1); |
| 891 | try stream.writeAll(", "); | 890 | try stream.writeAll(", "); |
| ... | @@ -897,7 +896,7 @@ const Writer = struct { | ... | @@ -897,7 +896,7 @@ const Writer = struct { |
| 897 | } | 896 | } |
| 898 | 897 | ||
| 899 | fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; | 900 | const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 902 | 901 | ||
| 903 | try self.writeFlag(stream, "nodiscard ", extra.flags.ensure_result_used); | 902 | try self.writeFlag(stream, "nodiscard ", extra.flags.ensure_result_used); |
| ... | @@ -913,7 +912,7 @@ const Writer = struct { | ... | @@ -913,7 +912,7 @@ const Writer = struct { |
| 913 | } | 912 | } |
| 914 | 913 | ||
| 915 | fn writeFieldParentPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; | 916 | const extra = self.code.extraData(Zir.Inst.FieldParentPtr, inst_data.payload_index).data; |
| 918 | try self.writeInstRef(stream, extra.parent_type); | 917 | try self.writeInstRef(stream, extra.parent_type); |
| 919 | try stream.writeAll(", "); | 918 | try stream.writeAll(", "); |
| ... | @@ -938,9 +937,9 @@ const Writer = struct { | ... | @@ -938,9 +937,9 @@ const Writer = struct { |
| 938 | } | 937 | } |
| 939 | 938 | ||
| 940 | fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index); | 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 | try stream.print("\"{}\", ", .{ | 943 | try stream.print("\"{}\", ", .{ |
| 945 | std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)), | 944 | std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)), |
| 946 | }); | 945 | }); |
| ... | @@ -956,7 +955,7 @@ const Writer = struct { | ... | @@ -956,7 +955,7 @@ const Writer = struct { |
| 956 | } | 955 | } |
| 957 | 956 | ||
| 958 | fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 959 | const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 961 | try self.writeInstRef(stream, extra.lhs); | 960 | try self.writeInstRef(stream, extra.lhs); |
| 962 | try stream.writeAll(", "); | 961 | try stream.writeAll(", "); |
| ... | @@ -966,7 +965,7 @@ const Writer = struct { | ... | @@ -966,7 +965,7 @@ const Writer = struct { |
| 966 | } | 965 | } |
| 967 | 966 | ||
| 968 | fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 969 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 971 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | 970 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| 972 | try stream.writeAll("{"); | 971 | try stream.writeAll("{"); |
| ... | @@ -979,13 +978,13 @@ const Writer = struct { | ... | @@ -979,13 +978,13 @@ const Writer = struct { |
| 979 | } | 978 | } |
| 980 | 979 | ||
| 981 | fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writeInstRef(stream, inst_data.operand); | 982 | try self.writeInstRef(stream, inst_data.operand); |
| 984 | try stream.print(", {d})", .{inst_data.idx}); | 983 | try stream.print(", {d})", .{inst_data.idx}); |
| 985 | } | 984 | } |
| 986 | 985 | ||
| 987 | fn writeArrayInitElemPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; | 988 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 990 | 989 | ||
| 991 | try self.writeInstRef(stream, extra.ptr); | 990 | try self.writeInstRef(stream, extra.ptr); |
| ... | @@ -994,7 +993,7 @@ const Writer = struct { | ... | @@ -994,7 +993,7 @@ const Writer = struct { |
| 994 | } | 993 | } |
| 995 | 994 | ||
| 996 | fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | 997 | const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 999 | const decl_name = self.code.nullTerminatedString(extra.decl_name); | 998 | const decl_name = self.code.nullTerminatedString(extra.decl_name); |
| 1000 | 999 | ||
| ... | @@ -1006,7 +1005,7 @@ const Writer = struct { | ... | @@ -1006,7 +1005,7 @@ const Writer = struct { |
| 1006 | } | 1005 | } |
| 1007 | 1006 | ||
| 1008 | fn writePlNodeExportValue(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; | 1009 | const extra = self.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 1011 | 1010 | ||
| 1012 | try self.writeInstRef(stream, extra.operand); | 1011 | try self.writeInstRef(stream, extra.operand); |
| ... | @@ -1017,7 +1016,7 @@ const Writer = struct { | ... | @@ -1017,7 +1016,7 @@ const Writer = struct { |
| 1017 | } | 1016 | } |
| 1018 | 1017 | ||
| 1019 | fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data; | 1020 | const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data; |
| 1022 | 1021 | ||
| 1023 | try self.writeInstRef(stream, extra.ptr_ty); | 1022 | try self.writeInstRef(stream, extra.ptr_ty); |
| ... | @@ -1027,7 +1026,7 @@ const Writer = struct { | ... | @@ -1027,7 +1026,7 @@ const Writer = struct { |
| 1027 | } | 1026 | } |
| 1028 | 1027 | ||
| 1029 | fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); | 1030 | const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 1032 | var field_i: u32 = 0; | 1031 | var field_i: u32 = 0; |
| 1033 | var extra_index = extra.end; | 1032 | var extra_index = extra.end; |
| ... | @@ -1095,7 +1094,7 @@ const Writer = struct { | ... | @@ -1095,7 +1094,7 @@ const Writer = struct { |
| 1095 | } | 1094 | } |
| 1096 | 1095 | ||
| 1097 | fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; | 1098 | const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 1100 | 1099 | ||
| 1101 | try self.writeInstRef(stream, extra.elem_type); | 1100 | try self.writeInstRef(stream, extra.elem_type); |
| ... | @@ -1108,7 +1107,7 @@ const Writer = struct { | ... | @@ -1108,7 +1107,7 @@ const Writer = struct { |
| 1108 | } | 1107 | } |
| 1109 | 1108 | ||
| 1110 | fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; | 1111 | const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 1113 | 1112 | ||
| 1114 | try self.writeInstRef(stream, extra.ptr); | 1113 | try self.writeInstRef(stream, extra.ptr); |
| ... | @@ -1121,7 +1120,7 @@ const Writer = struct { | ... | @@ -1121,7 +1120,7 @@ const Writer = struct { |
| 1121 | } | 1120 | } |
| 1122 | 1121 | ||
| 1123 | fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 1124 | const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 1126 | 1125 | ||
| 1127 | try self.writeInstRef(stream, extra.ptr); | 1126 | try self.writeInstRef(stream, extra.ptr); |
| ... | @@ -1136,7 +1135,7 @@ const Writer = struct { | ... | @@ -1136,7 +1135,7 @@ const Writer = struct { |
| 1136 | } | 1135 | } |
| 1137 | 1136 | ||
| 1138 | fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); | 1139 | const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 1141 | var field_i: u32 = 0; | 1140 | var field_i: u32 = 0; |
| 1142 | var extra_index = extra.end; | 1141 | var extra_index = extra.end; |
| ... | @@ -1157,7 +1156,7 @@ const Writer = struct { | ... | @@ -1157,7 +1156,7 @@ const Writer = struct { |
| 1157 | } | 1156 | } |
| 1158 | 1157 | ||
| 1159 | fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 1160 | const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 1162 | try self.writeInstRef(stream, extra.container_type); | 1161 | try self.writeInstRef(stream, extra.container_type); |
| 1163 | const field_name = self.code.nullTerminatedString(extra.name_start); | 1162 | const field_name = self.code.nullTerminatedString(extra.name_start); |
| ... | @@ -1166,7 +1165,7 @@ const Writer = struct { | ... | @@ -1166,7 +1165,7 @@ const Writer = struct { |
| 1166 | } | 1165 | } |
| 1167 | 1166 | ||
| 1168 | fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; | 1169 | const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 1171 | try self.writeInstRef(stream, extra.container_type); | 1170 | try self.writeInstRef(stream, extra.container_type); |
| 1172 | try stream.writeAll(", "); | 1171 | try stream.writeAll(", "); |
| ... | @@ -1193,7 +1192,7 @@ const Writer = struct { | ... | @@ -1193,7 +1192,7 @@ const Writer = struct { |
| 1193 | stream: anytype, | 1192 | stream: anytype, |
| 1194 | inst: Zir.Inst.Index, | 1193 | inst: Zir.Inst.Index, |
| 1195 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | try self.writeInstIndex(stream, inst_data.inst); | 1196 | try self.writeInstIndex(stream, inst_data.inst); |
| 1198 | try stream.writeAll(") "); | 1197 | try stream.writeAll(") "); |
| 1199 | try self.writeSrc(stream, inst_data.src()); | 1198 | try self.writeSrc(stream, inst_data.src()); |
| ... | @@ -1297,7 +1296,7 @@ const Writer = struct { | ... | @@ -1297,7 +1296,7 @@ const Writer = struct { |
| 1297 | inst: Zir.Inst.Index, | 1296 | inst: Zir.Inst.Index, |
| 1298 | comptime kind: enum { direct, field }, | 1297 | comptime kind: enum { direct, field }, |
| 1299 | ) !void { | 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 | const ExtraType = switch (kind) { | 1300 | const ExtraType = switch (kind) { |
| 1302 | .direct => Zir.Inst.Call, | 1301 | .direct => Zir.Inst.Call, |
| 1303 | .field => Zir.Inst.FieldCall, | 1302 | .field => Zir.Inst.FieldCall, |
| ... | @@ -1331,7 +1330,7 @@ const Writer = struct { | ... | @@ -1331,7 +1330,7 @@ const Writer = struct { |
| 1331 | const arg_end = self.code.extra[extra.end + i]; | 1330 | const arg_end = self.code.extra[extra.end + i]; |
| 1332 | defer arg_start = arg_end; | 1331 | defer arg_start = arg_end; |
| 1333 | const arg_body = body[arg_start..arg_end]; | 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 | try stream.writeAll(",\n"); | 1335 | try stream.writeAll(",\n"); |
| 1337 | } | 1336 | } |
| ... | @@ -1345,24 +1344,24 @@ const Writer = struct { | ... | @@ -1345,24 +1344,24 @@ const Writer = struct { |
| 1345 | } | 1344 | } |
| 1346 | 1345 | ||
| 1347 | fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writePlNodeBlockWithoutSrc(stream, inst); | 1348 | try self.writePlNodeBlockWithoutSrc(stream, inst); |
| 1350 | try self.writeSrc(stream, inst_data.src()); | 1349 | try self.writeSrc(stream, inst_data.src()); |
| 1351 | } | 1350 | } |
| 1352 | 1351 | ||
| 1353 | fn writePlNodeBlockWithoutSrc(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | try self.writeBracedBody(stream, body); | 1356 | try self.writeBracedBody(stream, body); |
| 1358 | try stream.writeAll(") "); | 1357 | try stream.writeAll(") "); |
| 1359 | } | 1358 | } |
| 1360 | 1359 | ||
| 1361 | fn writeCondBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 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]; | 1363 | const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1365 | const else_body = self.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1364 | const else_body = self.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len); |
| 1366 | try self.writeInstRef(stream, extra.data.condition); | 1365 | try self.writeInstRef(stream, extra.data.condition); |
| 1367 | try stream.writeAll(", "); | 1366 | try stream.writeAll(", "); |
| 1368 | try self.writeBracedBody(stream, then_body); | 1367 | try self.writeBracedBody(stream, then_body); |
| ... | @@ -1373,9 +1372,9 @@ const Writer = struct { | ... | @@ -1373,9 +1372,9 @@ const Writer = struct { |
| 1373 | } | 1372 | } |
| 1374 | 1373 | ||
| 1375 | fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 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 | try self.writeInstRef(stream, extra.data.operand); | 1378 | try self.writeInstRef(stream, extra.data.operand); |
| 1380 | try stream.writeAll(", "); | 1379 | try stream.writeAll(", "); |
| 1381 | try self.writeBracedBody(stream, body); | 1380 | try self.writeBracedBody(stream, body); |
| ... | @@ -1421,7 +1420,7 @@ const Writer = struct { | ... | @@ -1421,7 +1420,7 @@ const Writer = struct { |
| 1421 | extra_index += 1; | 1420 | extra_index += 1; |
| 1422 | try self.writeInstRef(stream, backing_int_ref); | 1421 | try self.writeInstRef(stream, backing_int_ref); |
| 1423 | } else { | 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 | extra_index += backing_int_body_len; | 1424 | extra_index += backing_int_body_len; |
| 1426 | self.indent += 2; | 1425 | self.indent += 2; |
| 1427 | try self.writeBracedDecl(stream, body); | 1426 | try self.writeBracedDecl(stream, body); |
| ... | @@ -1535,7 +1534,7 @@ const Writer = struct { | ... | @@ -1535,7 +1534,7 @@ const Writer = struct { |
| 1535 | } | 1534 | } |
| 1536 | 1535 | ||
| 1537 | if (field.type_len > 0) { | 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 | extra_index += body.len; | 1538 | extra_index += body.len; |
| 1540 | self.indent += 2; | 1539 | self.indent += 2; |
| 1541 | try self.writeBracedDecl(stream, body); | 1540 | try self.writeBracedDecl(stream, body); |
| ... | @@ -1543,7 +1542,7 @@ const Writer = struct { | ... | @@ -1543,7 +1542,7 @@ const Writer = struct { |
| 1543 | } | 1542 | } |
| 1544 | 1543 | ||
| 1545 | if (field.align_len > 0) { | 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 | extra_index += body.len; | 1546 | extra_index += body.len; |
| 1548 | self.indent += 2; | 1547 | self.indent += 2; |
| 1549 | try stream.writeAll(" align("); | 1548 | try stream.writeAll(" align("); |
| ... | @@ -1553,7 +1552,7 @@ const Writer = struct { | ... | @@ -1553,7 +1552,7 @@ const Writer = struct { |
| 1553 | } | 1552 | } |
| 1554 | 1553 | ||
| 1555 | if (field.init_len > 0) { | 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 | extra_index += body.len; | 1556 | extra_index += body.len; |
| 1558 | self.indent += 2; | 1557 | self.indent += 2; |
| 1559 | try stream.writeAll(" = "); | 1558 | try stream.writeAll(" = "); |
| ... | @@ -1639,7 +1638,7 @@ const Writer = struct { | ... | @@ -1639,7 +1638,7 @@ const Writer = struct { |
| 1639 | } | 1638 | } |
| 1640 | try stream.writeAll(", "); | 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 | extra_index += body.len; | 1642 | extra_index += body.len; |
| 1644 | 1643 | ||
| 1645 | const prev_parent_decl_node = self.parent_decl_node; | 1644 | const prev_parent_decl_node = self.parent_decl_node; |
| ... | @@ -1742,7 +1741,7 @@ const Writer = struct { | ... | @@ -1742,7 +1741,7 @@ const Writer = struct { |
| 1742 | extra_index += 1; | 1741 | extra_index += 1; |
| 1743 | const decl_name_index = self.code.extra[extra_index]; | 1742 | const decl_name_index = self.code.extra[extra_index]; |
| 1744 | extra_index += 1; | 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 | extra_index += 1; | 1745 | extra_index += 1; |
| 1747 | const doc_comment_index = self.code.extra[extra_index]; | 1746 | const doc_comment_index = self.code.extra[extra_index]; |
| 1748 | extra_index += 1; | 1747 | extra_index += 1; |
| ... | @@ -1764,7 +1763,7 @@ const Writer = struct { | ... | @@ -1764,7 +1763,7 @@ const Writer = struct { |
| 1764 | }; | 1763 | }; |
| 1765 | 1764 | ||
| 1766 | const pub_str = if (is_pub) "pub " else ""; | 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 | if (decl_name_index == 0) { | 1767 | if (decl_name_index == 0) { |
| 1769 | try stream.writeByteNTimes(' ', self.indent); | 1768 | try stream.writeByteNTimes(' ', self.indent); |
| 1770 | const name = if (is_exported) "usingnamespace" else "comptime"; | 1769 | const name = if (is_exported) "usingnamespace" else "comptime"; |
| ... | @@ -1810,12 +1809,12 @@ const Writer = struct { | ... | @@ -1810,12 +1809,12 @@ const Writer = struct { |
| 1810 | } | 1809 | } |
| 1811 | 1810 | ||
| 1812 | if (self.recurse_decls) { | 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 | try stream.print(" line({d}) hash({}): %{d} = {s}(", .{ | 1813 | try stream.print(" line({d}) hash({}): %{d} = {s}(", .{ |
| 1815 | line, std.fmt.fmtSliceHexLower(&hash_bytes), decl_index, @tagName(tag), | 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 | const sub_decl_node_off = decl_block_inst_data.src_node; | 1818 | const sub_decl_node_off = decl_block_inst_data.src_node; |
| 1820 | self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off); | 1819 | self.parent_decl_node = self.relativeToNodeIndex(sub_decl_node_off); |
| 1821 | try self.writePlNodeBlockWithoutSrc(stream, decl_index); | 1820 | try self.writePlNodeBlockWithoutSrc(stream, decl_index); |
| ... | @@ -1888,7 +1887,7 @@ const Writer = struct { | ... | @@ -1888,7 +1887,7 @@ const Writer = struct { |
| 1888 | try stream.writeAll(", "); | 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 | extra_index += body.len; | 1891 | extra_index += body.len; |
| 1893 | 1892 | ||
| 1894 | const prev_parent_decl_node = self.parent_decl_node; | 1893 | const prev_parent_decl_node = self.parent_decl_node; |
| ... | @@ -1988,7 +1987,7 @@ const Writer = struct { | ... | @@ -1988,7 +1987,7 @@ const Writer = struct { |
| 1988 | inst: Zir.Inst.Index, | 1987 | inst: Zir.Inst.Index, |
| 1989 | name_strategy: Zir.Inst.NameStrategy, | 1988 | name_strategy: Zir.Inst.NameStrategy, |
| 1990 | ) !void { | 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 | const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); | 1991 | const extra = self.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index); |
| 1993 | 1992 | ||
| 1994 | try stream.print("{s}, ", .{@tagName(name_strategy)}); | 1993 | try stream.print("{s}, ", .{@tagName(name_strategy)}); |
| ... | @@ -2015,7 +2014,7 @@ const Writer = struct { | ... | @@ -2015,7 +2014,7 @@ const Writer = struct { |
| 2015 | } | 2014 | } |
| 2016 | 2015 | ||
| 2017 | fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); | 2018 | const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 2020 | 2019 | ||
| 2021 | var extra_index: usize = extra.end; | 2020 | var extra_index: usize = extra.end; |
| ... | @@ -2029,7 +2028,7 @@ const Writer = struct { | ... | @@ -2029,7 +2028,7 @@ const Writer = struct { |
| 2029 | const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: { | 2028 | const tag_capture_inst: Zir.Inst.Index = if (extra.data.bits.any_has_tag_capture) blk: { |
| 2030 | const tag_capture_inst = self.code.extra[extra_index]; | 2029 | const tag_capture_inst = self.code.extra[extra_index]; |
| 2031 | extra_index += 1; | 2030 | extra_index += 1; |
| 2032 | break :blk tag_capture_inst; | 2031 | break :blk @enumFromInt(tag_capture_inst); |
| 2033 | } else undefined; | 2032 | } else undefined; |
| 2034 | 2033 | ||
| 2035 | try self.writeInstRef(stream, extra.data.operand); | 2034 | try self.writeInstRef(stream, extra.data.operand); |
| ... | @@ -2057,7 +2056,7 @@ const Writer = struct { | ... | @@ -2057,7 +2056,7 @@ const Writer = struct { |
| 2057 | }; | 2056 | }; |
| 2058 | const inline_text = if (info.is_inline) "inline " else ""; | 2057 | const inline_text = if (info.is_inline) "inline " else ""; |
| 2059 | extra_index += 1; | 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 | extra_index += body.len; | 2060 | extra_index += body.len; |
| 2062 | 2061 | ||
| 2063 | try stream.writeAll(",\n"); | 2062 | try stream.writeAll(",\n"); |
| ... | @@ -2074,7 +2073,7 @@ const Writer = struct { | ... | @@ -2074,7 +2073,7 @@ const Writer = struct { |
| 2074 | extra_index += 1; | 2073 | extra_index += 1; |
| 2075 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index])); | 2074 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(self.code.extra[extra_index])); |
| 2076 | extra_index += 1; | 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 | extra_index += info.body_len; | 2077 | extra_index += info.body_len; |
| 2079 | 2078 | ||
| 2080 | try stream.writeAll(",\n"); | 2079 | try stream.writeAll(",\n"); |
| ... | @@ -2131,7 +2130,7 @@ const Writer = struct { | ... | @@ -2131,7 +2130,7 @@ const Writer = struct { |
| 2131 | try self.writeInstRef(stream, item_last); | 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 | extra_index += info.body_len; | 2134 | extra_index += info.body_len; |
| 2136 | try stream.writeAll(" => "); | 2135 | try stream.writeAll(" => "); |
| 2137 | try self.writeBracedBody(stream, body); | 2136 | try self.writeBracedBody(stream, body); |
| ... | @@ -2145,7 +2144,7 @@ const Writer = struct { | ... | @@ -2145,7 +2144,7 @@ const Writer = struct { |
| 2145 | } | 2144 | } |
| 2146 | 2145 | ||
| 2147 | fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 2148 | const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 2150 | const name = self.code.nullTerminatedString(extra.field_name_start); | 2149 | const name = self.code.nullTerminatedString(extra.field_name_start); |
| 2151 | try self.writeInstRef(stream, extra.lhs); | 2150 | try self.writeInstRef(stream, extra.lhs); |
| ... | @@ -2154,7 +2153,7 @@ const Writer = struct { | ... | @@ -2154,7 +2153,7 @@ const Writer = struct { |
| 2154 | } | 2153 | } |
| 2155 | 2154 | ||
| 2156 | fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 2157 | const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 2159 | try self.writeInstRef(stream, extra.lhs); | 2158 | try self.writeInstRef(stream, extra.lhs); |
| 2160 | try stream.writeAll(", "); | 2159 | try stream.writeAll(", "); |
| ... | @@ -2164,7 +2163,7 @@ const Writer = struct { | ... | @@ -2164,7 +2163,7 @@ const Writer = struct { |
| 2164 | } | 2163 | } |
| 2165 | 2164 | ||
| 2166 | fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 2167 | const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 2169 | try self.writeInstRef(stream, extra.dest_type); | 2168 | try self.writeInstRef(stream, extra.dest_type); |
| 2170 | try stream.writeAll(", "); | 2169 | try stream.writeAll(", "); |
| ... | @@ -2178,7 +2177,7 @@ const Writer = struct { | ... | @@ -2178,7 +2177,7 @@ const Writer = struct { |
| 2178 | stream: anytype, | 2177 | stream: anytype, |
| 2179 | inst: Zir.Inst.Index, | 2178 | inst: Zir.Inst.Index, |
| 2180 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const src = LazySrcLoc.nodeOffset(src_node); | 2181 | const src = LazySrcLoc.nodeOffset(src_node); |
| 2183 | try stream.writeAll(") "); | 2182 | try stream.writeAll(") "); |
| 2184 | try self.writeSrc(stream, src); | 2183 | try self.writeSrc(stream, src); |
| ... | @@ -2189,14 +2188,14 @@ const Writer = struct { | ... | @@ -2189,14 +2188,14 @@ const Writer = struct { |
| 2189 | stream: anytype, | 2188 | stream: anytype, |
| 2190 | inst: Zir.Inst.Index, | 2189 | inst: Zir.Inst.Index, |
| 2191 | ) (@TypeOf(stream).Error || error{OutOfMemory})!void { | 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 | const str = inst_data.get(self.code); | 2192 | const str = inst_data.get(self.code); |
| 2194 | try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)}); | 2193 | try stream.print("\"{}\") ", .{std.zig.fmtEscapes(str)}); |
| 2195 | try self.writeSrc(stream, inst_data.src()); | 2194 | try self.writeSrc(stream, inst_data.src()); |
| 2196 | } | 2195 | } |
| 2197 | 2196 | ||
| 2198 | fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const str = inst_data.getStr(self.code); | 2199 | const str = inst_data.getStr(self.code); |
| 2201 | try self.writeInstRef(stream, inst_data.operand); | 2200 | try self.writeInstRef(stream, inst_data.operand); |
| 2202 | try stream.print(", \"{}\")", .{std.zig.fmtEscapes(str)}); | 2201 | try stream.print(", \"{}\")", .{std.zig.fmtEscapes(str)}); |
| ... | @@ -2208,7 +2207,7 @@ const Writer = struct { | ... | @@ -2208,7 +2207,7 @@ const Writer = struct { |
| 2208 | inst: Zir.Inst.Index, | 2207 | inst: Zir.Inst.Index, |
| 2209 | inferred_error_set: bool, | 2208 | inferred_error_set: bool, |
| 2210 | ) !void { | 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 | const src = inst_data.src(); | 2211 | const src = inst_data.src(); |
| 2213 | const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index); | 2212 | const extra = self.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 2214 | 2213 | ||
| ... | @@ -2225,12 +2224,12 @@ const Writer = struct { | ... | @@ -2225,12 +2224,12 @@ const Writer = struct { |
| 2225 | extra_index += 1; | 2224 | extra_index += 1; |
| 2226 | }, | 2225 | }, |
| 2227 | else => { | 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 | extra_index += ret_ty_body.len; | 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 | extra_index += body.len; | 2233 | extra_index += body.len; |
| 2235 | 2234 | ||
| 2236 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; | 2235 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; |
| ... | @@ -2263,7 +2262,7 @@ const Writer = struct { | ... | @@ -2263,7 +2262,7 @@ const Writer = struct { |
| 2263 | } | 2262 | } |
| 2264 | 2263 | ||
| 2265 | fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); | 2266 | const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 2268 | const src = inst_data.src(); | 2267 | const src = inst_data.src(); |
| 2269 | 2268 | ||
| ... | @@ -2289,7 +2288,7 @@ const Writer = struct { | ... | @@ -2289,7 +2288,7 @@ const Writer = struct { |
| 2289 | if (extra.data.bits.has_align_body) { | 2288 | if (extra.data.bits.has_align_body) { |
| 2290 | const body_len = self.code.extra[extra_index]; | 2289 | const body_len = self.code.extra[extra_index]; |
| 2291 | extra_index += 1; | 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 | extra_index += align_body.len; | 2292 | extra_index += align_body.len; |
| 2294 | } else if (extra.data.bits.has_align_ref) { | 2293 | } else if (extra.data.bits.has_align_ref) { |
| 2295 | align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 2294 | align_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | @@ -2298,7 +2297,7 @@ const Writer = struct { | ... | @@ -2298,7 +2297,7 @@ const Writer = struct { |
| 2298 | if (extra.data.bits.has_addrspace_body) { | 2297 | if (extra.data.bits.has_addrspace_body) { |
| 2299 | const body_len = self.code.extra[extra_index]; | 2298 | const body_len = self.code.extra[extra_index]; |
| 2300 | extra_index += 1; | 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 | extra_index += addrspace_body.len; | 2301 | extra_index += addrspace_body.len; |
| 2303 | } else if (extra.data.bits.has_addrspace_ref) { | 2302 | } else if (extra.data.bits.has_addrspace_ref) { |
| 2304 | addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 2303 | addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | @@ -2307,7 +2306,7 @@ const Writer = struct { | ... | @@ -2307,7 +2306,7 @@ const Writer = struct { |
| 2307 | if (extra.data.bits.has_section_body) { | 2306 | if (extra.data.bits.has_section_body) { |
| 2308 | const body_len = self.code.extra[extra_index]; | 2307 | const body_len = self.code.extra[extra_index]; |
| 2309 | extra_index += 1; | 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 | extra_index += section_body.len; | 2310 | extra_index += section_body.len; |
| 2312 | } else if (extra.data.bits.has_section_ref) { | 2311 | } else if (extra.data.bits.has_section_ref) { |
| 2313 | section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 2312 | section_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | @@ -2316,7 +2315,7 @@ const Writer = struct { | ... | @@ -2316,7 +2315,7 @@ const Writer = struct { |
| 2316 | if (extra.data.bits.has_cc_body) { | 2315 | if (extra.data.bits.has_cc_body) { |
| 2317 | const body_len = self.code.extra[extra_index]; | 2316 | const body_len = self.code.extra[extra_index]; |
| 2318 | extra_index += 1; | 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 | extra_index += cc_body.len; | 2319 | extra_index += cc_body.len; |
| 2321 | } else if (extra.data.bits.has_cc_ref) { | 2320 | } else if (extra.data.bits.has_cc_ref) { |
| 2322 | cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 2321 | cc_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | @@ -2325,7 +2324,7 @@ const Writer = struct { | ... | @@ -2325,7 +2324,7 @@ const Writer = struct { |
| 2325 | if (extra.data.bits.has_ret_ty_body) { | 2324 | if (extra.data.bits.has_ret_ty_body) { |
| 2326 | const body_len = self.code.extra[extra_index]; | 2325 | const body_len = self.code.extra[extra_index]; |
| 2327 | extra_index += 1; | 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 | extra_index += ret_ty_body.len; | 2328 | extra_index += ret_ty_body.len; |
| 2330 | } else if (extra.data.bits.has_ret_ty_ref) { | 2329 | } else if (extra.data.bits.has_ret_ty_ref) { |
| 2331 | ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); | 2330 | ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index])); |
| ... | @@ -2338,7 +2337,7 @@ const Writer = struct { | ... | @@ -2338,7 +2337,7 @@ const Writer = struct { |
| 2338 | break :blk x; | 2337 | break :blk x; |
| 2339 | } else 0; | 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 | extra_index += body.len; | 2341 | extra_index += body.len; |
| 2343 | 2342 | ||
| 2344 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; | 2343 | var src_locs: Zir.Inst.Func.SrcLocs = undefined; |
| ... | @@ -2423,7 +2422,7 @@ const Writer = struct { | ... | @@ -2423,7 +2422,7 @@ const Writer = struct { |
| 2423 | 2422 | ||
| 2424 | fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 2423 | fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| 2425 | const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); | 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 | try self.writeBracedBody(stream, body); | 2426 | try self.writeBracedBody(stream, body); |
| 2428 | try stream.writeAll(",["); | 2427 | try stream.writeAll(",["); |
| 2429 | const args = self.code.refSlice(extra.end, extended.small); | 2428 | const args = self.code.refSlice(extra.end, extended.small); |
| ... | @@ -2435,16 +2434,16 @@ const Writer = struct { | ... | @@ -2435,16 +2434,16 @@ const Writer = struct { |
| 2435 | } | 2434 | } |
| 2436 | 2435 | ||
| 2437 | fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 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 | try self.writeInstRef(stream, inst_data.lhs); | 2440 | try self.writeInstRef(stream, inst_data.lhs); |
| 2442 | try stream.writeAll(", "); | 2441 | try stream.writeAll(", "); |
| 2443 | try self.writeBracedBody(stream, body); | 2442 | try self.writeBracedBody(stream, body); |
| 2444 | } | 2443 | } |
| 2445 | 2444 | ||
| 2446 | fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const prefix: u8 = switch (int_type.signedness) { | 2447 | const prefix: u8 = switch (int_type.signedness) { |
| 2449 | .signed => 'i', | 2448 | .signed => 'i', |
| 2450 | .unsigned => 'u', | 2449 | .unsigned => 'u', |
| ... | @@ -2454,14 +2453,14 @@ const Writer = struct { | ... | @@ -2454,14 +2453,14 @@ const Writer = struct { |
| 2454 | } | 2453 | } |
| 2455 | 2454 | ||
| 2456 | fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writeInstRef(stream, inst_data.operand); | 2458 | try self.writeInstRef(stream, inst_data.operand); |
| 2460 | try stream.writeAll(")"); | 2459 | try stream.writeAll(")"); |
| 2461 | } | 2460 | } |
| 2462 | 2461 | ||
| 2463 | fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try self.writeInstRef(stream, inst_data.block); | 2465 | try self.writeInstRef(stream, inst_data.block); |
| 2467 | try stream.writeAll(", "); | 2466 | try stream.writeAll(", "); |
| ... | @@ -2470,7 +2469,7 @@ const Writer = struct { | ... | @@ -2470,7 +2469,7 @@ const Writer = struct { |
| 2470 | } | 2469 | } |
| 2471 | 2470 | ||
| 2472 | fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; | 2473 | const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 2475 | 2474 | ||
| 2476 | try self.writeInstIndex(stream, extra.block_inst); | 2475 | try self.writeInstIndex(stream, extra.block_inst); |
| ... | @@ -2480,7 +2479,7 @@ const Writer = struct { | ... | @@ -2480,7 +2479,7 @@ const Writer = struct { |
| 2480 | } | 2479 | } |
| 2481 | 2480 | ||
| 2482 | fn writeArrayInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 2484 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2486 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | 2485 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | @@ -2496,7 +2495,7 @@ const Writer = struct { | ... | @@ -2496,7 +2495,7 @@ const Writer = struct { |
| 2496 | } | 2495 | } |
| 2497 | 2496 | ||
| 2498 | fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 2500 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2502 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | 2501 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | @@ -2511,7 +2510,7 @@ const Writer = struct { | ... | @@ -2511,7 +2510,7 @@ const Writer = struct { |
| 2511 | } | 2510 | } |
| 2512 | 2511 | ||
| 2513 | fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 2515 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 2517 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | 2516 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | @@ -2531,7 +2530,7 @@ const Writer = struct { | ... | @@ -2531,7 +2530,7 @@ const Writer = struct { |
| 2531 | } | 2530 | } |
| 2532 | 2531 | ||
| 2533 | fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try stream.writeAll(") "); | 2534 | try stream.writeAll(") "); |
| 2536 | try self.writeSrc(stream, inst_data.src()); | 2535 | try self.writeSrc(stream, inst_data.src()); |
| 2537 | } | 2536 | } |
| ... | @@ -2585,34 +2584,37 @@ const Writer = struct { | ... | @@ -2585,34 +2584,37 @@ const Writer = struct { |
| 2585 | } | 2584 | } |
| 2586 | 2585 | ||
| 2587 | fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 }); | 2588 | try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 }); |
| 2590 | } | 2589 | } |
| 2591 | 2590 | ||
| 2592 | fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 2591 | fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 2593 | const inst_data = self.code.instructions.items(.data)[inst].@"defer"; | 2592 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer"; |
| 2594 | const body = self.code.extra[inst_data.index..][0..inst_data.len]; | 2593 | const body = self.code.bodySlice(inst_data.index, inst_data.len); |
| 2595 | try self.writeBracedBody(stream, body); | 2594 | try self.writeBracedBody(stream, body); |
| 2596 | try stream.writeByte(')'); | 2595 | try stream.writeByte(')'); |
| 2597 | } | 2596 | } |
| 2598 | 2597 | ||
| 2599 | fn writeDeferErrCode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 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 | const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; | 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 | try stream.writeAll(" = "); | 2603 | try stream.writeAll(" = "); |
| 2605 | try self.writeInstRef(stream, inst_data.err_code); | 2604 | try self.writeInstRef(stream, inst_data.err_code); |
| 2606 | try stream.writeAll(", "); | 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 | try self.writeBracedBody(stream, body); | 2607 | try self.writeBracedBody(stream, body); |
| 2609 | try stream.writeByte(')'); | 2608 | try stream.writeByte(')'); |
| 2610 | } | 2609 | } |
| 2611 | 2610 | ||
| 2612 | fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void { | 2611 | fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void { |
| 2613 | const i = @intFromEnum(ref); | 2612 | if (ref.toIndex()) |i| { |
| 2614 | if (i < InternPool.static_len) return stream.print("@{}", .{@as(InternPool.Index, @enumFromInt(i))}); | 2613 | return self.writeInstIndex(stream, i); |
| 2615 | return self.writeInstIndex(stream, i - InternPool.static_len); | 2614 | } else { |
| 2615 | const val: InternPool.Index = @enumFromInt(@intFromEnum(ref)); | ||
| 2616 | return stream.print("@{}", .{val}); | ||
| 2617 | } | ||
| 2616 | } | 2618 | } |
| 2617 | 2619 | ||
| 2618 | fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 2620 | fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |