| ... | ... | @@ -70,10 +70,10 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 { |
| 70 | 70 | |
| 71 | 71 | fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 { |
| 72 | 72 | const fields = std.meta.fields(@TypeOf(extra)); |
| 73 | | const result = @as(u32, @intCast(astgen.extra.items.len)); |
| 73 | const extra_index: u32 = @intCast(astgen.extra.items.len); |
| 74 | 74 | astgen.extra.items.len += fields.len; |
| 75 | | setExtra(astgen, result, extra); |
| 76 | | return result; |
| 75 | setExtra(astgen, extra_index, extra); |
| 76 | return extra_index; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| ... | ... | @@ -83,11 +83,12 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 83 | 83 | astgen.extra.items[i] = switch (field.type) { |
| 84 | 84 | u32 => @field(extra, field.name), |
| 85 | 85 | Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)), |
| 86 | | i32 => @as(u32, @bitCast(@field(extra, field.name))), |
| 87 | | Zir.Inst.Call.Flags => @as(u32, @bitCast(@field(extra, field.name))), |
| 88 | | Zir.Inst.BuiltinCall.Flags => @as(u32, @bitCast(@field(extra, field.name))), |
| 89 | | Zir.Inst.SwitchBlock.Bits => @as(u32, @bitCast(@field(extra, field.name))), |
| 90 | | Zir.Inst.FuncFancy.Bits => @as(u32, @bitCast(@field(extra, field.name))), |
| 86 | i32, |
| 87 | Zir.Inst.Call.Flags, |
| 88 | Zir.Inst.BuiltinCall.Flags, |
| 89 | Zir.Inst.SwitchBlock.Bits, |
| 90 | Zir.Inst.FuncFancy.Bits, |
| 91 | => @bitCast(@field(extra, field.name)), |
| 91 | 92 | else => @compileError("bad field type"), |
| 92 | 93 | }; |
| 93 | 94 | i += 1; |
| ... | ... | @@ -95,19 +96,17 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | fn reserveExtra(astgen: *AstGen, size: usize) Allocator.Error!u32 { |
| 98 | | const result = @as(u32, @intCast(astgen.extra.items.len)); |
| 99 | | try astgen.extra.resize(astgen.gpa, result + size); |
| 100 | | return result; |
| 99 | const extra_index: u32 = @intCast(astgen.extra.items.len); |
| 100 | try astgen.extra.resize(astgen.gpa, extra_index + size); |
| 101 | return extra_index; |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void { |
| 104 | | const coerced = @as([]const u32, @ptrCast(refs)); |
| 105 | | return astgen.extra.appendSlice(astgen.gpa, coerced); |
| 105 | return astgen.extra.appendSlice(astgen.gpa, @ptrCast(refs)); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void { |
| 109 | | const coerced = @as([]const u32, @ptrCast(refs)); |
| 110 | | astgen.extra.appendSliceAssumeCapacity(coerced); |
| 109 | astgen.extra.appendSliceAssumeCapacity(@ptrCast(refs)); |
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| ... | ... | @@ -176,7 +175,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 176 | 175 | @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len); |
| 177 | 176 | |
| 178 | 177 | astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{ |
| 179 | | .items_len = @as(u32, @intCast(astgen.compile_errors.items.len)), |
| 178 | .items_len = @intCast(astgen.compile_errors.items.len), |
| 180 | 179 | }); |
| 181 | 180 | |
| 182 | 181 | for (astgen.compile_errors.items) |item| { |
| ... | ... | @@ -192,7 +191,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 192 | 191 | astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len); |
| 193 | 192 | |
| 194 | 193 | astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{ |
| 195 | | .imports_len = @as(u32, @intCast(astgen.imports.count())), |
| 194 | .imports_len = @intCast(astgen.imports.count()), |
| 196 | 195 | }); |
| 197 | 196 | |
| 198 | 197 | var it = astgen.imports.iterator(); |
| ... | ... | @@ -1334,7 +1333,7 @@ fn fnProtoExpr( |
| 1334 | 1333 | var param_gz = block_scope.makeSubBlock(scope); |
| 1335 | 1334 | defer param_gz.unstack(); |
| 1336 | 1335 | const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node); |
| 1337 | | const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1)); |
| 1336 | const param_inst_expected: u32 = @intCast(astgen.instructions.len + 1); |
| 1338 | 1337 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 1339 | 1338 | const main_tokens = tree.nodes.items(.main_token); |
| 1340 | 1339 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| ... | ... | @@ -1468,7 +1467,7 @@ fn arrayInitExpr( |
| 1468 | 1467 | const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr); |
| 1469 | 1468 | _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{ |
| 1470 | 1469 | .ty = array_type_inst, |
| 1471 | | .init_count = @as(u32, @intCast(array_init.ast.elements.len)), |
| 1470 | .init_count = @intCast(array_init.ast.elements.len), |
| 1472 | 1471 | }); |
| 1473 | 1472 | break :inst .{ |
| 1474 | 1473 | .array = array_type_inst, |
| ... | ... | @@ -1552,7 +1551,7 @@ fn arrayInitExprRlNone( |
| 1552 | 1551 | const astgen = gz.astgen; |
| 1553 | 1552 | |
| 1554 | 1553 | const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{ |
| 1555 | | .operands_len = @as(u32, @intCast(elements.len)), |
| 1554 | .operands_len = @intCast(elements.len), |
| 1556 | 1555 | }); |
| 1557 | 1556 | var extra_index = try reserveExtra(astgen, elements.len); |
| 1558 | 1557 | |
| ... | ... | @@ -1577,7 +1576,7 @@ fn arrayInitExprInner( |
| 1577 | 1576 | |
| 1578 | 1577 | const len = elements.len + @intFromBool(array_ty_inst != .none); |
| 1579 | 1578 | const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{ |
| 1580 | | .operands_len = @as(u32, @intCast(len)), |
| 1579 | .operands_len = @intCast(len), |
| 1581 | 1580 | }); |
| 1582 | 1581 | var extra_index = try reserveExtra(astgen, len); |
| 1583 | 1582 | if (array_ty_inst != .none) { |
| ... | ... | @@ -1593,7 +1592,7 @@ fn arrayInitExprInner( |
| 1593 | 1592 | .tag = .elem_type_index, |
| 1594 | 1593 | .data = .{ .bin = .{ |
| 1595 | 1594 | .lhs = array_ty_inst, |
| 1596 | | .rhs = @as(Zir.Inst.Ref, @enumFromInt(i)), |
| 1595 | .rhs = @enumFromInt(i), |
| 1597 | 1596 | } }, |
| 1598 | 1597 | }); |
| 1599 | 1598 | break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } }; |
| ... | ... | @@ -1638,14 +1637,14 @@ fn arrayInitExprRlPtrInner( |
| 1638 | 1637 | const astgen = gz.astgen; |
| 1639 | 1638 | |
| 1640 | 1639 | const payload_index = try addExtra(astgen, Zir.Inst.Block{ |
| 1641 | | .body_len = @as(u32, @intCast(elements.len)), |
| 1640 | .body_len = @intCast(elements.len), |
| 1642 | 1641 | }); |
| 1643 | 1642 | var extra_index = try reserveExtra(astgen, elements.len); |
| 1644 | 1643 | |
| 1645 | 1644 | for (elements, 0..) |elem_init, i| { |
| 1646 | 1645 | const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{ |
| 1647 | 1646 | .ptr = result_ptr, |
| 1648 | | .index = @as(u32, @intCast(i)), |
| 1647 | .index = @intCast(i), |
| 1649 | 1648 | }); |
| 1650 | 1649 | astgen.extra.items[extra_index] = refToIndex(elem_ptr).?; |
| 1651 | 1650 | extra_index += 1; |
| ... | ... | @@ -1797,7 +1796,7 @@ fn structInitExprRlNone( |
| 1797 | 1796 | const tree = astgen.tree; |
| 1798 | 1797 | |
| 1799 | 1798 | const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{ |
| 1800 | | .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)), |
| 1799 | .fields_len = @intCast(struct_init.ast.fields.len), |
| 1801 | 1800 | }); |
| 1802 | 1801 | const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len; |
| 1803 | 1802 | var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size); |
| ... | ... | @@ -1855,7 +1854,7 @@ fn structInitExprRlPtrInner( |
| 1855 | 1854 | const tree = astgen.tree; |
| 1856 | 1855 | |
| 1857 | 1856 | const payload_index = try addExtra(astgen, Zir.Inst.Block{ |
| 1858 | | .body_len = @as(u32, @intCast(struct_init.ast.fields.len)), |
| 1857 | .body_len = @intCast(struct_init.ast.fields.len), |
| 1859 | 1858 | }); |
| 1860 | 1859 | var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len); |
| 1861 | 1860 | |
| ... | ... | @@ -1887,7 +1886,7 @@ fn structInitExprRlTy( |
| 1887 | 1886 | const tree = astgen.tree; |
| 1888 | 1887 | |
| 1889 | 1888 | const payload_index = try addExtra(astgen, Zir.Inst.StructInit{ |
| 1890 | | .fields_len = @as(u32, @intCast(struct_init.ast.fields.len)), |
| 1889 | .fields_len = @intCast(struct_init.ast.fields.len), |
| 1891 | 1890 | }); |
| 1892 | 1891 | const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len; |
| 1893 | 1892 | var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size); |
| ... | ... | @@ -2126,7 +2125,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn |
| 2126 | 2125 | } |
| 2127 | 2126 | |
| 2128 | 2127 | const operand = try reachableExpr(parent_gz, parent_scope, block_gz.break_result_info, rhs, node); |
| 2129 | | const search_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 2128 | const search_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 2130 | 2129 | |
| 2131 | 2130 | try genDefers(parent_gz, scope, parent_scope, .normal_only); |
| 2132 | 2131 | |
| ... | ... | @@ -2373,8 +2372,8 @@ fn labeledBlockExpr( |
| 2373 | 2372 | try astgen.appendErrorTok(label_token, "unused block label", .{}); |
| 2374 | 2373 | } |
| 2375 | 2374 | |
| 2376 | | const zir_datas = gz.astgen.instructions.items(.data); |
| 2377 | | const zir_tags = gz.astgen.instructions.items(.tag); |
| 2375 | const zir_datas = astgen.instructions.items(.data); |
| 2376 | const zir_tags = astgen.instructions.items(.tag); |
| 2378 | 2377 | const strat = ri.rl.strategy(&block_scope); |
| 2379 | 2378 | switch (strat.tag) { |
| 2380 | 2379 | .break_void => { |
| ... | ... | @@ -2396,6 +2395,10 @@ fn labeledBlockExpr( |
| 2396 | 2395 | // it as the break operand. |
| 2397 | 2396 | // This corresponds to similar code in `setCondBrPayloadElideBlockStorePtr`. |
| 2398 | 2397 | if (block_scope.rl_ty_inst != .none) { |
| 2398 | try astgen.extra.ensureUnusedCapacity( |
| 2399 | astgen.gpa, |
| 2400 | @typeInfo(Zir.Inst.As).Struct.fields.len * block_scope.labeled_breaks.items.len, |
| 2401 | ); |
| 2399 | 2402 | for (block_scope.labeled_breaks.items) |br| { |
| 2400 | 2403 | // We expect the `store_to_block_ptr` to be created between 1-3 instructions |
| 2401 | 2404 | // prior to the break. |
| ... | ... | @@ -2404,12 +2407,28 @@ fn labeledBlockExpr( |
| 2404 | 2407 | if (zir_tags[search_index] == .store_to_block_ptr and |
| 2405 | 2408 | zir_datas[search_index].bin.lhs == block_scope.rl_ptr) |
| 2406 | 2409 | { |
| 2407 | | zir_tags[search_index] = .as; |
| 2408 | | zir_datas[search_index].bin = .{ |
| 2409 | | .lhs = block_scope.rl_ty_inst, |
| 2410 | | .rhs = zir_datas[br.br].@"break".operand, |
| 2411 | | }; |
| 2412 | | zir_datas[br.br].@"break".operand = indexToRef(search_index); |
| 2410 | const break_data = &zir_datas[br.br].@"break"; |
| 2411 | const break_src: i32 = @bitCast(astgen.extra.items[ |
| 2412 | break_data.payload_index + |
| 2413 | std.meta.fieldIndex(Zir.Inst.Break, "operand_src_node").? |
| 2414 | ]); |
| 2415 | if (break_src == Zir.Inst.Break.no_src_node) { |
| 2416 | zir_tags[search_index] = .as; |
| 2417 | zir_datas[search_index].bin = .{ |
| 2418 | .lhs = block_scope.rl_ty_inst, |
| 2419 | .rhs = break_data.operand, |
| 2420 | }; |
| 2421 | } else { |
| 2422 | zir_tags[search_index] = .as_node; |
| 2423 | zir_datas[search_index] = .{ .pl_node = .{ |
| 2424 | .src_node = break_src, |
| 2425 | .payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.As{ |
| 2426 | .dest_type = block_scope.rl_ty_inst, |
| 2427 | .operand = break_data.operand, |
| 2428 | }), |
| 2429 | } }; |
| 2430 | } |
| 2431 | break_data.operand = indexToRef(search_index); |
| 2413 | 2432 | break; |
| 2414 | 2433 | } |
| 2415 | 2434 | } else unreachable; |
| ... | ... | @@ -2530,19 +2549,21 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2530 | 2549 | // For some instructions, modify the zir data |
| 2531 | 2550 | // so we can avoid a separate ensure_result_used instruction. |
| 2532 | 2551 | .call, .field_call => { |
| 2533 | | const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index; |
| 2534 | | const slot = &gz.astgen.extra.items[extra_index]; |
| 2535 | | var flags = @as(Zir.Inst.Call.Flags, @bitCast(slot.*)); |
| 2552 | const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index; |
| 2553 | comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") == |
| 2554 | std.meta.fieldIndex(Zir.Inst.FieldCall, "flags")); |
| 2555 | const flags: *Zir.Inst.Call.Flags = @ptrCast(&gz.astgen.extra.items[ |
| 2556 | break_extra + std.meta.fieldIndex(Zir.Inst.Call, "flags").? |
| 2557 | ]); |
| 2536 | 2558 | flags.ensure_result_used = true; |
| 2537 | | slot.* = @as(u32, @bitCast(flags)); |
| 2538 | 2559 | break :b true; |
| 2539 | 2560 | }, |
| 2540 | 2561 | .builtin_call => { |
| 2541 | | const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index; |
| 2542 | | const slot = &gz.astgen.extra.items[extra_index]; |
| 2543 | | var flags = @as(Zir.Inst.BuiltinCall.Flags, @bitCast(slot.*)); |
| 2562 | const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index; |
| 2563 | const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[ |
| 2564 | break_extra + std.meta.fieldIndex(Zir.Inst.BuiltinCall, "flags").? |
| 2565 | ]); |
| 2544 | 2566 | flags.ensure_result_used = true; |
| 2545 | | slot.* = @as(u32, @bitCast(flags)); |
| 2546 | 2567 | break :b true; |
| 2547 | 2568 | }, |
| 2548 | 2569 | |
| ... | ... | @@ -2920,7 +2941,7 @@ fn genDefers( |
| 2920 | 2941 | .index = defer_scope.index, |
| 2921 | 2942 | .len = defer_scope.len, |
| 2922 | 2943 | }); |
| 2923 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 2944 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 2924 | 2945 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 2925 | 2946 | .tag = .defer_err_code, |
| 2926 | 2947 | .data = .{ .defer_err_code = .{ |
| ... | ... | @@ -2999,7 +3020,7 @@ fn deferStmt( |
| 2999 | 3020 | const sub_scope = if (!have_err_code) &defer_gen.base else blk: { |
| 3000 | 3021 | try gz.addDbgBlockBegin(); |
| 3001 | 3022 | const ident_name = try gz.astgen.identAsString(payload_token); |
| 3002 | | remapped_err_code = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 3023 | remapped_err_code = @intCast(gz.astgen.instructions.len); |
| 3003 | 3024 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 3004 | 3025 | .tag = .extended, |
| 3005 | 3026 | .data = .{ .extended = .{ |
| ... | ... | @@ -3039,7 +3060,7 @@ fn deferStmt( |
| 3039 | 3060 | break :blk gz.astgen.countBodyLenAfterFixups(body) + refs; |
| 3040 | 3061 | }; |
| 3041 | 3062 | |
| 3042 | | const index = @as(u32, @intCast(gz.astgen.extra.items.len)); |
| 3063 | const index: u32 = @intCast(gz.astgen.extra.items.len); |
| 3043 | 3064 | try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len); |
| 3044 | 3065 | if (have_err_code) { |
| 3045 | 3066 | if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| { |
| ... | ... | @@ -3580,7 +3601,7 @@ fn ptrType( |
| 3580 | 3601 | gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref)); |
| 3581 | 3602 | } |
| 3582 | 3603 | |
| 3583 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 3604 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 3584 | 3605 | const result = indexToRef(new_index); |
| 3585 | 3606 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ |
| 3586 | 3607 | .ptr_type = .{ |
| ... | ... | @@ -3671,7 +3692,7 @@ const WipMembers = struct { |
| 3671 | 3692 | const max_decl_size = 11; |
| 3672 | 3693 | |
| 3673 | 3694 | fn init(gpa: Allocator, payload: *ArrayListUnmanaged(u32), decl_count: u32, field_count: u32, comptime bits_per_field: u32, comptime max_field_size: u32) Allocator.Error!Self { |
| 3674 | | const payload_top = @as(u32, @intCast(payload.items.len)); |
| 3695 | const payload_top: u32 = @intCast(payload.items.len); |
| 3675 | 3696 | const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32; |
| 3676 | 3697 | const field_bits_start = decls_start + decl_count * max_decl_size; |
| 3677 | 3698 | const fields_start = field_bits_start + if (bits_per_field > 0) blk: { |
| ... | ... | @@ -3726,7 +3747,7 @@ const WipMembers = struct { |
| 3726 | 3747 | fn appendToDeclSlice(self: *Self, data: []const u32) void { |
| 3727 | 3748 | assert(self.decls_end + data.len <= self.field_bits_start); |
| 3728 | 3749 | @memcpy(self.payload.items[self.decls_end..][0..data.len], data); |
| 3729 | | self.decls_end += @as(u32, @intCast(data.len)); |
| 3750 | self.decls_end += @intCast(data.len); |
| 3730 | 3751 | } |
| 3731 | 3752 | |
| 3732 | 3753 | fn appendToField(self: *Self, data: u32) void { |
| ... | ... | @@ -3739,14 +3760,14 @@ const WipMembers = struct { |
| 3739 | 3760 | const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32); |
| 3740 | 3761 | if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) { |
| 3741 | 3762 | const index = self.payload_top + self.decl_index / decls_per_u32; |
| 3742 | | self.payload.items[index] >>= @as(u5, @intCast(empty_decl_slots * bits_per_decl)); |
| 3763 | self.payload.items[index] >>= @intCast(empty_decl_slots * bits_per_decl); |
| 3743 | 3764 | } |
| 3744 | 3765 | if (bits_per_field > 0) { |
| 3745 | 3766 | const fields_per_u32 = 32 / bits_per_field; |
| 3746 | 3767 | const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32); |
| 3747 | 3768 | if (self.field_index > 0 and empty_field_slots < fields_per_u32) { |
| 3748 | 3769 | const index = self.field_bits_start + self.field_index / fields_per_u32; |
| 3749 | | self.payload.items[index] >>= @as(u5, @intCast(empty_field_slots * bits_per_field)); |
| 3770 | self.payload.items[index] >>= @intCast(empty_field_slots * bits_per_field); |
| 3750 | 3771 | } |
| 3751 | 3772 | } |
| 3752 | 3773 | } |
| ... | ... | @@ -3908,7 +3929,7 @@ fn fnDecl( |
| 3908 | 3929 | var param_gz = decl_gz.makeSubBlock(scope); |
| 3909 | 3930 | defer param_gz.unstack(); |
| 3910 | 3931 | const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node); |
| 3911 | | const param_inst_expected = @as(u32, @intCast(astgen.instructions.len + 1)); |
| 3932 | const param_inst_expected: u32 = @intCast(astgen.instructions.len + 1); |
| 3912 | 3933 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 3913 | 3934 | |
| 3914 | 3935 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -4122,9 +4143,8 @@ fn fnDecl( |
| 4122 | 4143 | try decl_gz.setBlockBody(block_inst); |
| 4123 | 4144 | |
| 4124 | 4145 | { |
| 4125 | | const contents_hash = std.zig.hashSrc(tree.getNodeSource(decl_node)); |
| 4126 | | const casted = @as([4]u32, @bitCast(contents_hash)); |
| 4127 | | wip_members.appendToDeclSlice(&casted); |
| 4146 | const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(decl_node)); |
| 4147 | wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash)); |
| 4128 | 4148 | } |
| 4129 | 4149 | { |
| 4130 | 4150 | const line_delta = decl_gz.decl_line - gz.decl_line; |
| ... | ... | @@ -4273,9 +4293,8 @@ fn globalVarDecl( |
| 4273 | 4293 | try block_scope.setBlockBody(block_inst); |
| 4274 | 4294 | |
| 4275 | 4295 | { |
| 4276 | | const contents_hash = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4277 | | const casted = @as([4]u32, @bitCast(contents_hash)); |
| 4278 | | wip_members.appendToDeclSlice(&casted); |
| 4296 | const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4297 | wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash)); |
| 4279 | 4298 | } |
| 4280 | 4299 | { |
| 4281 | 4300 | const line_delta = block_scope.decl_line - gz.decl_line; |
| ... | ... | @@ -4328,9 +4347,8 @@ fn comptimeDecl( |
| 4328 | 4347 | try decl_block.setBlockBody(block_inst); |
| 4329 | 4348 | |
| 4330 | 4349 | { |
| 4331 | | const contents_hash = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4332 | | const casted = @as([4]u32, @bitCast(contents_hash)); |
| 4333 | | wip_members.appendToDeclSlice(&casted); |
| 4350 | const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4351 | wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash)); |
| 4334 | 4352 | } |
| 4335 | 4353 | { |
| 4336 | 4354 | const line_delta = decl_block.decl_line - gz.decl_line; |
| ... | ... | @@ -4380,9 +4398,8 @@ fn usingnamespaceDecl( |
| 4380 | 4398 | try decl_block.setBlockBody(block_inst); |
| 4381 | 4399 | |
| 4382 | 4400 | { |
| 4383 | | const contents_hash = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4384 | | const casted = @as([4]u32, @bitCast(contents_hash)); |
| 4385 | | wip_members.appendToDeclSlice(&casted); |
| 4401 | const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4402 | wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash)); |
| 4386 | 4403 | } |
| 4387 | 4404 | { |
| 4388 | 4405 | const line_delta = decl_block.decl_line - gz.decl_line; |
| ... | ... | @@ -4567,9 +4584,8 @@ fn testDecl( |
| 4567 | 4584 | try decl_block.setBlockBody(block_inst); |
| 4568 | 4585 | |
| 4569 | 4586 | { |
| 4570 | | const contents_hash = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4571 | | const casted = @as([4]u32, @bitCast(contents_hash)); |
| 4572 | | wip_members.appendToDeclSlice(&casted); |
| 4587 | const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node)); |
| 4588 | wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash)); |
| 4573 | 4589 | } |
| 4574 | 4590 | { |
| 4575 | 4591 | const line_delta = decl_block.decl_line - gz.decl_line; |
| ... | ... | @@ -4668,7 +4684,7 @@ fn structDeclInner( |
| 4668 | 4684 | }; |
| 4669 | 4685 | |
| 4670 | 4686 | const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members); |
| 4671 | | const field_count = @as(u32, @intCast(container_decl.ast.members.len - decl_count)); |
| 4687 | const field_count: u32 = @intCast(container_decl.ast.members.len - decl_count); |
| 4672 | 4688 | |
| 4673 | 4689 | const bits_per_field = 4; |
| 4674 | 4690 | const max_field_size = 5; |
| ... | ... | @@ -4781,7 +4797,7 @@ fn structDeclInner( |
| 4781 | 4797 | const old_scratch_len = astgen.scratch.items.len; |
| 4782 | 4798 | try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body)); |
| 4783 | 4799 | appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body); |
| 4784 | | wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len))); |
| 4800 | wip_members.appendToField(@intCast(astgen.scratch.items.len - old_scratch_len)); |
| 4785 | 4801 | block_scope.instructions.items.len = block_scope.instructions_top; |
| 4786 | 4802 | } else { |
| 4787 | 4803 | wip_members.appendToField(@intFromEnum(field_type)); |
| ... | ... | @@ -4799,7 +4815,7 @@ fn structDeclInner( |
| 4799 | 4815 | const old_scratch_len = astgen.scratch.items.len; |
| 4800 | 4816 | try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body)); |
| 4801 | 4817 | appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body); |
| 4802 | | wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len))); |
| 4818 | wip_members.appendToField(@intCast(astgen.scratch.items.len - old_scratch_len)); |
| 4803 | 4819 | block_scope.instructions.items.len = block_scope.instructions_top; |
| 4804 | 4820 | } |
| 4805 | 4821 | |
| ... | ... | @@ -4814,7 +4830,7 @@ fn structDeclInner( |
| 4814 | 4830 | const old_scratch_len = astgen.scratch.items.len; |
| 4815 | 4831 | try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body)); |
| 4816 | 4832 | appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body); |
| 4817 | | wip_members.appendToField(@as(u32, @intCast(astgen.scratch.items.len - old_scratch_len))); |
| 4833 | wip_members.appendToField(@intCast(astgen.scratch.items.len - old_scratch_len)); |
| 4818 | 4834 | block_scope.instructions.items.len = block_scope.instructions_top; |
| 4819 | 4835 | } else if (member.comptime_token) |comptime_token| { |
| 4820 | 4836 | return astgen.failTok(comptime_token, "comptime field without default initialization value", .{}); |
| ... | ... | @@ -4827,7 +4843,7 @@ fn structDeclInner( |
| 4827 | 4843 | .fields_len = field_count, |
| 4828 | 4844 | .decls_len = decl_count, |
| 4829 | 4845 | .backing_int_ref = backing_int_ref, |
| 4830 | | .backing_int_body_len = @as(u32, @intCast(backing_int_body_len)), |
| 4846 | .backing_int_body_len = @intCast(backing_int_body_len), |
| 4831 | 4847 | .known_non_opv = known_non_opv, |
| 4832 | 4848 | .known_comptime_only = known_comptime_only, |
| 4833 | 4849 | .is_tuple = is_tuple, |
| ... | ... | @@ -4887,7 +4903,7 @@ fn unionDeclInner( |
| 4887 | 4903 | defer block_scope.unstack(); |
| 4888 | 4904 | |
| 4889 | 4905 | const decl_count = try astgen.scanDecls(&namespace, members); |
| 4890 | | const field_count = @as(u32, @intCast(members.len - decl_count)); |
| 4906 | const field_count: u32 = @intCast(members.len - decl_count); |
| 4891 | 4907 | |
| 4892 | 4908 | if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) { |
| 4893 | 4909 | const layout_str = if (layout == .Extern) "extern" else "packed"; |
| ... | ... | @@ -5182,7 +5198,7 @@ fn containerDecl( |
| 5182 | 5198 | |
| 5183 | 5199 | const bits_per_field = 1; |
| 5184 | 5200 | const max_field_size = 3; |
| 5185 | | var wip_members = try WipMembers.init(gpa, &astgen.scratch, @as(u32, @intCast(counts.decls)), @as(u32, @intCast(counts.total_fields)), bits_per_field, max_field_size); |
| 5201 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size); |
| 5186 | 5202 | defer wip_members.deinit(); |
| 5187 | 5203 | |
| 5188 | 5204 | for (container_decl.ast.members) |member_node| { |
| ... | ... | @@ -5240,8 +5256,8 @@ fn containerDecl( |
| 5240 | 5256 | .nonexhaustive = nonexhaustive, |
| 5241 | 5257 | .tag_type = arg_inst, |
| 5242 | 5258 | .body_len = body_len, |
| 5243 | | .fields_len = @as(u32, @intCast(counts.total_fields)), |
| 5244 | | .decls_len = @as(u32, @intCast(counts.decls)), |
| 5259 | .fields_len = @intCast(counts.total_fields), |
| 5260 | .decls_len = @intCast(counts.decls), |
| 5245 | 5261 | }); |
| 5246 | 5262 | |
| 5247 | 5263 | wip_members.finishBits(bits_per_field); |
| ... | ... | @@ -5431,7 +5447,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi |
| 5431 | 5447 | } |
| 5432 | 5448 | |
| 5433 | 5449 | setExtra(astgen, payload_index, Zir.Inst.ErrorSetDecl{ |
| 5434 | | .fields_len = @as(u32, @intCast(fields_len)), |
| 5450 | .fields_len = @intCast(fields_len), |
| 5435 | 5451 | }); |
| 5436 | 5452 | const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index); |
| 5437 | 5453 | return rvalue(gz, ri, result, node); |
| ... | ... | @@ -5657,7 +5673,7 @@ fn finishThenElseBlock( |
| 5657 | 5673 | 0; |
| 5658 | 5674 | |
| 5659 | 5675 | if (strat.elide_store_to_block_ptr_instructions) { |
| 5660 | | try setCondBrPayloadElideBlockStorePtr(condbr, cond, then_scope, then_break, else_scope, else_break, block_scope.rl_ptr); |
| 5676 | try setCondBrPayloadElideBlockStorePtr(condbr, cond, then_scope, then_break, then_src_node, else_scope, else_break, else_src_node, block_scope.rl_ptr); |
| 5661 | 5677 | } else { |
| 5662 | 5678 | try setCondBrPayload(condbr, cond, then_scope, then_break, else_scope, else_break); |
| 5663 | 5679 | } |
| ... | ... | @@ -6082,8 +6098,10 @@ fn setCondBrPayloadElideBlockStorePtr( |
| 6082 | 6098 | cond: Zir.Inst.Ref, |
| 6083 | 6099 | then_scope: *GenZir, |
| 6084 | 6100 | then_break: Zir.Inst.Index, |
| 6101 | then_src_node: Ast.Node.Index, |
| 6085 | 6102 | else_scope: *GenZir, |
| 6086 | 6103 | else_break: Zir.Inst.Index, |
| 6104 | else_src_node: Ast.Node.Index, |
| 6087 | 6105 | block_ptr: Zir.Inst.Ref, |
| 6088 | 6106 | ) !void { |
| 6089 | 6107 | defer then_scope.unstack(); |
| ... | ... | @@ -6097,39 +6115,36 @@ fn setCondBrPayloadElideBlockStorePtr( |
| 6097 | 6115 | const else_body_len = astgen.countBodyLenAfterFixups(else_body) + @intFromBool(has_else_break); |
| 6098 | 6116 | try astgen.extra.ensureUnusedCapacity( |
| 6099 | 6117 | astgen.gpa, |
| 6100 | | @typeInfo(Zir.Inst.CondBr).Struct.fields.len + then_body_len + else_body_len, |
| 6118 | @typeInfo(Zir.Inst.CondBr).Struct.fields.len + then_body_len + else_body_len + |
| 6119 | @typeInfo(Zir.Inst.As).Struct.fields.len * 2, |
| 6101 | 6120 | ); |
| 6102 | 6121 | |
| 6103 | 6122 | const zir_tags = astgen.instructions.items(.tag); |
| 6104 | 6123 | const zir_datas = astgen.instructions.items(.data); |
| 6105 | 6124 | |
| 6106 | | const condbr_pl = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{ |
| 6125 | const condbr_extra = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{ |
| 6107 | 6126 | .condition = cond, |
| 6108 | 6127 | .then_body_len = then_body_len, |
| 6109 | 6128 | .else_body_len = else_body_len, |
| 6110 | 6129 | }); |
| 6111 | | zir_datas[condbr].pl_node.payload_index = condbr_pl; |
| 6112 | | const then_body_len_index = condbr_pl + 1; |
| 6113 | | const else_body_len_index = condbr_pl + 2; |
| 6130 | zir_datas[condbr].pl_node.payload_index = condbr_extra; |
| 6114 | 6131 | |
| 6115 | 6132 | // The break instructions need to have their operands coerced if the |
| 6116 | 6133 | // switch's result location is a `ty`. In this case we overwrite the |
| 6117 | 6134 | // `store_to_block_ptr` instruction with an `as` instruction and repurpose |
| 6118 | 6135 | // it as the break operand. |
| 6119 | 6136 | // This corresponds to similar code in `labeledBlockExpr`. |
| 6137 | var then_as_inst: Zir.Inst.Index = 0; |
| 6120 | 6138 | for (then_body) |src_inst| { |
| 6121 | 6139 | if (zir_tags[src_inst] == .store_to_block_ptr and |
| 6122 | 6140 | zir_datas[src_inst].bin.lhs == block_ptr) |
| 6123 | 6141 | { |
| 6124 | 6142 | if (then_scope.rl_ty_inst != .none and has_then_break) { |
| 6125 | | zir_tags[src_inst] = .as; |
| 6126 | | zir_datas[src_inst].bin = .{ |
| 6127 | | .lhs = then_scope.rl_ty_inst, |
| 6128 | | .rhs = zir_datas[then_break].@"break".operand, |
| 6129 | | }; |
| 6130 | | zir_datas[then_break].@"break".operand = indexToRef(src_inst); |
| 6143 | then_as_inst = src_inst; |
| 6131 | 6144 | } else { |
| 6132 | | astgen.extra.items[then_body_len_index] -= 1; |
| 6145 | astgen.extra.items[ |
| 6146 | condbr_extra + std.meta.fieldIndex(Zir.Inst.CondBr, "then_body_len").? |
| 6147 | ] -= 1; |
| 6133 | 6148 | continue; |
| 6134 | 6149 | } |
| 6135 | 6150 | } |
| ... | ... | @@ -6137,25 +6152,47 @@ fn setCondBrPayloadElideBlockStorePtr( |
| 6137 | 6152 | } |
| 6138 | 6153 | if (has_then_break) astgen.extra.appendAssumeCapacity(then_break); |
| 6139 | 6154 | |
| 6155 | var else_as_inst: Zir.Inst.Index = 0; |
| 6140 | 6156 | for (else_body) |src_inst| { |
| 6141 | 6157 | if (zir_tags[src_inst] == .store_to_block_ptr and |
| 6142 | 6158 | zir_datas[src_inst].bin.lhs == block_ptr) |
| 6143 | 6159 | { |
| 6144 | 6160 | if (else_scope.rl_ty_inst != .none and has_else_break) { |
| 6145 | | zir_tags[src_inst] = .as; |
| 6146 | | zir_datas[src_inst].bin = .{ |
| 6147 | | .lhs = else_scope.rl_ty_inst, |
| 6148 | | .rhs = zir_datas[else_break].@"break".operand, |
| 6149 | | }; |
| 6150 | | zir_datas[else_break].@"break".operand = indexToRef(src_inst); |
| 6161 | else_as_inst = src_inst; |
| 6151 | 6162 | } else { |
| 6152 | | astgen.extra.items[else_body_len_index] -= 1; |
| 6163 | astgen.extra.items[ |
| 6164 | condbr_extra + std.meta.fieldIndex(Zir.Inst.CondBr, "else_body_len").? |
| 6165 | ] -= 1; |
| 6153 | 6166 | continue; |
| 6154 | 6167 | } |
| 6155 | 6168 | } |
| 6156 | 6169 | appendPossiblyRefdBodyInst(astgen, &astgen.extra, src_inst); |
| 6157 | 6170 | } |
| 6158 | 6171 | if (has_else_break) astgen.extra.appendAssumeCapacity(else_break); |
| 6172 | |
| 6173 | if (then_as_inst != 0) { |
| 6174 | zir_tags[then_as_inst] = .as_node; |
| 6175 | zir_datas[then_as_inst] = .{ .pl_node = .{ |
| 6176 | .src_node = then_scope.nodeIndexToRelative(then_src_node), |
| 6177 | .payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.As{ |
| 6178 | .dest_type = then_scope.rl_ty_inst, |
| 6179 | .operand = zir_datas[then_break].@"break".operand, |
| 6180 | }), |
| 6181 | } }; |
| 6182 | zir_datas[then_break].@"break".operand = indexToRef(then_as_inst); |
| 6183 | } |
| 6184 | |
| 6185 | if (else_as_inst != 0) { |
| 6186 | zir_tags[else_as_inst] = .as_node; |
| 6187 | zir_datas[else_as_inst] = .{ .pl_node = .{ |
| 6188 | .src_node = else_scope.nodeIndexToRelative(else_src_node), |
| 6189 | .payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.As{ |
| 6190 | .dest_type = else_scope.rl_ty_inst, |
| 6191 | .operand = zir_datas[else_break].@"break".operand, |
| 6192 | }), |
| 6193 | } }; |
| 6194 | zir_datas[else_break].@"break".operand = indexToRef(else_as_inst); |
| 6195 | } |
| 6159 | 6196 | } |
| 6160 | 6197 | |
| 6161 | 6198 | fn whileExpr( |
| ... | ... | @@ -6313,10 +6350,10 @@ fn whileExpr( |
| 6313 | 6350 | loop_scope.break_block = loop_block; |
| 6314 | 6351 | loop_scope.continue_block = continue_block; |
| 6315 | 6352 | if (while_full.label_token) |label_token| { |
| 6316 | | loop_scope.label = @as(?GenZir.Label, GenZir.Label{ |
| 6353 | loop_scope.label = .{ |
| 6317 | 6354 | .token = label_token, |
| 6318 | 6355 | .block_inst = loop_block, |
| 6319 | | }); |
| 6356 | }; |
| 6320 | 6357 | } |
| 6321 | 6358 | |
| 6322 | 6359 | // done adding instructions to loop_scope, can now stack then_scope |
| ... | ... | @@ -6929,7 +6966,7 @@ fn switchExpr( |
| 6929 | 6966 | |
| 6930 | 6967 | // If any prong has an inline tag capture, allocate a shared dummy instruction for it |
| 6931 | 6968 | const tag_inst = if (any_has_tag_capture) tag_inst: { |
| 6932 | | const inst = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 6969 | const inst: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 6933 | 6970 | try astgen.instructions.append(astgen.gpa, .{ |
| 6934 | 6971 | .tag = .extended, |
| 6935 | 6972 | .data = .{ .extended = .{ |
| ... | ... | @@ -7022,7 +7059,7 @@ fn switchExpr( |
| 7022 | 7059 | break :blk &tag_scope.base; |
| 7023 | 7060 | }; |
| 7024 | 7061 | |
| 7025 | | const header_index = @as(u32, @intCast(payloads.items.len)); |
| 7062 | const header_index: u32 = @intCast(payloads.items.len); |
| 7026 | 7063 | const body_len_index = if (is_multi_case) blk: { |
| 7027 | 7064 | payloads.items[multi_case_table + multi_case_index] = header_index; |
| 7028 | 7065 | multi_case_index += 1; |
| ... | ... | @@ -7112,12 +7149,12 @@ fn switchExpr( |
| 7112 | 7149 | }; |
| 7113 | 7150 | const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice); |
| 7114 | 7151 | try payloads.ensureUnusedCapacity(gpa, body_len); |
| 7115 | | payloads.items[body_len_index] = @as(u32, @bitCast(Zir.Inst.SwitchBlock.ProngInfo{ |
| 7116 | | .body_len = @as(u28, @intCast(body_len)), |
| 7152 | payloads.items[body_len_index] = @bitCast(Zir.Inst.SwitchBlock.ProngInfo{ |
| 7153 | .body_len = @intCast(body_len), |
| 7117 | 7154 | .capture = capture, |
| 7118 | 7155 | .is_inline = case.inline_token != null, |
| 7119 | 7156 | .has_tag_capture = has_tag_capture, |
| 7120 | | })); |
| 7157 | }); |
| 7121 | 7158 | if (astgen.ref_table.fetchRemove(switch_block)) |kv| { |
| 7122 | 7159 | appendPossiblyRefdBodyInst(astgen, payloads, kv.value); |
| 7123 | 7160 | } |
| ... | ... | @@ -7135,7 +7172,8 @@ fn switchExpr( |
| 7135 | 7172 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.SwitchBlock).Struct.fields.len + |
| 7136 | 7173 | @intFromBool(multi_cases_len != 0) + |
| 7137 | 7174 | @intFromBool(any_has_tag_capture) + |
| 7138 | | payloads.items.len - case_table_end); |
| 7175 | payloads.items.len - case_table_end + |
| 7176 | (case_table_end - case_table_start) * @typeInfo(Zir.Inst.As).Struct.fields.len); |
| 7139 | 7177 | |
| 7140 | 7178 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{ |
| 7141 | 7179 | .operand = raw_operand, |
| ... | ... | @@ -7144,7 +7182,7 @@ fn switchExpr( |
| 7144 | 7182 | .has_else = special_prong == .@"else", |
| 7145 | 7183 | .has_under = special_prong == .under, |
| 7146 | 7184 | .any_has_tag_capture = any_has_tag_capture, |
| 7147 | | .scalar_cases_len = @as(Zir.Inst.SwitchBlock.Bits.ScalarCasesLen, @intCast(scalar_cases_len)), |
| 7185 | .scalar_cases_len = @intCast(scalar_cases_len), |
| 7148 | 7186 | }, |
| 7149 | 7187 | }); |
| 7150 | 7188 | |
| ... | ... | @@ -7162,82 +7200,108 @@ fn switchExpr( |
| 7162 | 7200 | zir_datas[switch_block].pl_node.payload_index = payload_index; |
| 7163 | 7201 | |
| 7164 | 7202 | const strat = ri.rl.strategy(&block_scope); |
| 7165 | | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { |
| 7166 | | var body_len_index = start_index; |
| 7167 | | var end_index = start_index; |
| 7168 | | const table_index = case_table_start + i; |
| 7169 | | if (table_index < scalar_case_table) { |
| 7170 | | end_index += 1; |
| 7171 | | } else if (table_index < multi_case_table) { |
| 7172 | | body_len_index += 1; |
| 7173 | | end_index += 2; |
| 7174 | | } else { |
| 7175 | | body_len_index += 2; |
| 7176 | | const items_len = payloads.items[start_index]; |
| 7177 | | const ranges_len = payloads.items[start_index + 1]; |
| 7178 | | end_index += 3 + items_len + 2 * ranges_len; |
| 7179 | | } |
| 7180 | | |
| 7181 | | const body_len = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(payloads.items[body_len_index])).body_len; |
| 7182 | | end_index += body_len; |
| 7183 | | |
| 7184 | | switch (strat.tag) { |
| 7185 | | .break_operand => blk: { |
| 7186 | | // Switch expressions return `true` for `nodeMayNeedMemoryLocation` thus |
| 7187 | | // `elide_store_to_block_ptr_instructions` will either be true, |
| 7188 | | // or all prongs are noreturn. |
| 7189 | | if (!strat.elide_store_to_block_ptr_instructions) |
| 7190 | | break :blk; |
| 7191 | | |
| 7192 | | // There will necessarily be a store_to_block_ptr for |
| 7193 | | // all prongs, except for prongs that ended with a noreturn instruction. |
| 7194 | | // Elide all the `store_to_block_ptr` instructions. |
| 7195 | | |
| 7196 | | // The break instructions need to have their operands coerced if the |
| 7197 | | // switch's result location is a `ty`. In this case we overwrite the |
| 7198 | | // `store_to_block_ptr` instruction with an `as` instruction and repurpose |
| 7199 | | // it as the break operand. |
| 7200 | | if (body_len < 2) |
| 7201 | | break :blk; |
| 7202 | | |
| 7203 | | var store_index = end_index - 2; |
| 7204 | | while (true) : (store_index -= 1) switch (zir_tags[payloads.items[store_index]]) { |
| 7205 | | .dbg_block_end, .dbg_block_begin, .dbg_stmt, .dbg_var_val, .dbg_var_ptr => {}, |
| 7206 | | else => break, |
| 7207 | | }; |
| 7208 | | const store_inst = payloads.items[store_index]; |
| 7209 | | if (zir_tags[store_inst] != .store_to_block_ptr or |
| 7210 | | zir_datas[store_inst].bin.lhs != block_scope.rl_ptr) |
| 7211 | | break :blk; |
| 7212 | | const break_inst = payloads.items[end_index - 1]; |
| 7213 | | if (block_scope.rl_ty_inst != .none) { |
| 7214 | | zir_tags[store_inst] = .as; |
| 7215 | | zir_datas[store_inst].bin = .{ |
| 7216 | | .lhs = block_scope.rl_ty_inst, |
| 7217 | | .rhs = zir_datas[break_inst].@"break".operand, |
| 7203 | inline for (.{ .body, .breaks }) |pass| { |
| 7204 | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { |
| 7205 | var body_len_index = start_index; |
| 7206 | var end_index = start_index; |
| 7207 | const table_index = case_table_start + i; |
| 7208 | if (table_index < scalar_case_table) { |
| 7209 | end_index += 1; |
| 7210 | } else if (table_index < multi_case_table) { |
| 7211 | body_len_index += 1; |
| 7212 | end_index += 2; |
| 7213 | } else { |
| 7214 | body_len_index += 2; |
| 7215 | const items_len = payloads.items[start_index]; |
| 7216 | const ranges_len = payloads.items[start_index + 1]; |
| 7217 | end_index += 3 + items_len + 2 * ranges_len; |
| 7218 | } |
| 7219 | |
| 7220 | const prong_info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(payloads.items[body_len_index]); |
| 7221 | end_index += prong_info.body_len; |
| 7222 | |
| 7223 | switch (strat.tag) { |
| 7224 | .break_operand => blk: { |
| 7225 | // Switch expressions return `true` for `nodeMayNeedMemoryLocation` thus |
| 7226 | // `elide_store_to_block_ptr_instructions` will either be true, |
| 7227 | // or all prongs are noreturn. |
| 7228 | if (!strat.elide_store_to_block_ptr_instructions) |
| 7229 | break :blk; |
| 7230 | |
| 7231 | // There will necessarily be a store_to_block_ptr for |
| 7232 | // all prongs, except for prongs that ended with a noreturn instruction. |
| 7233 | // Elide all the `store_to_block_ptr` instructions. |
| 7234 | |
| 7235 | // The break instructions need to have their operands coerced if the |
| 7236 | // switch's result location is a `ty`. In this case we overwrite the |
| 7237 | // `store_to_block_ptr` instruction with an `as` instruction and repurpose |
| 7238 | // it as the break operand. |
| 7239 | if (prong_info.body_len < 2) |
| 7240 | break :blk; |
| 7241 | |
| 7242 | var store_index = end_index - 2; |
| 7243 | while (true) : (store_index -= 1) switch (zir_tags[payloads.items[store_index]]) { |
| 7244 | .dbg_block_end, .dbg_block_begin, .dbg_stmt, .dbg_var_val, .dbg_var_ptr => {}, |
| 7245 | else => break, |
| 7218 | 7246 | }; |
| 7219 | | zir_datas[break_inst].@"break".operand = indexToRef(store_inst); |
| 7220 | | } else { |
| 7221 | | payloads.items[body_len_index] -= 1; |
| 7222 | | astgen.extra.appendSliceAssumeCapacity(payloads.items[start_index .. end_index - 2]); |
| 7223 | | astgen.extra.appendAssumeCapacity(break_inst); |
| 7224 | | continue; |
| 7225 | | } |
| 7226 | | }, |
| 7227 | | .break_void => { |
| 7228 | | assert(!strat.elide_store_to_block_ptr_instructions); |
| 7229 | | const last_inst = payloads.items[end_index - 1]; |
| 7230 | | if (zir_tags[last_inst] == .@"break") { |
| 7231 | | const inst_data = zir_datas[last_inst].@"break"; |
| 7232 | | const block_inst = astgen.extra.items[inst_data.payload_index]; |
| 7233 | | if (block_inst == switch_block) { |
| 7234 | | zir_datas[last_inst].@"break".operand = .void_value; |
| 7247 | const store_inst = payloads.items[store_index]; |
| 7248 | if (zir_tags[store_inst] != .store_to_block_ptr or |
| 7249 | zir_datas[store_inst].bin.lhs != block_scope.rl_ptr) |
| 7250 | break :blk; |
| 7251 | const break_inst = payloads.items[end_index - 1]; |
| 7252 | if (block_scope.rl_ty_inst != .none) { |
| 7253 | if (pass == .breaks) { |
| 7254 | const break_data = &zir_datas[break_inst].@"break"; |
| 7255 | const break_src: i32 = @bitCast(astgen.extra.items[ |
| 7256 | break_data.payload_index + |
| 7257 | std.meta.fieldIndex(Zir.Inst.Break, "operand_src_node").? |
| 7258 | ]); |
| 7259 | if (break_src == Zir.Inst.Break.no_src_node) { |
| 7260 | zir_tags[store_inst] = .as; |
| 7261 | zir_datas[store_inst].bin = .{ |
| 7262 | .lhs = block_scope.rl_ty_inst, |
| 7263 | .rhs = break_data.operand, |
| 7264 | }; |
| 7265 | } else { |
| 7266 | zir_tags[store_inst] = .as_node; |
| 7267 | zir_datas[store_inst] = .{ .pl_node = .{ |
| 7268 | .src_node = break_src, |
| 7269 | .payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.As{ |
| 7270 | .dest_type = block_scope.rl_ty_inst, |
| 7271 | .operand = break_data.operand, |
| 7272 | }), |
| 7273 | } }; |
| 7274 | } |
| 7275 | break_data.operand = indexToRef(store_inst); |
| 7276 | } |
| 7277 | } else { |
| 7278 | if (pass == .body) { |
| 7279 | payloads.items[body_len_index] -= 1; |
| 7280 | astgen.extra.appendSliceAssumeCapacity( |
| 7281 | payloads.items[start_index .. end_index - 2], |
| 7282 | ); |
| 7283 | astgen.extra.appendAssumeCapacity(break_inst); |
| 7284 | } |
| 7285 | continue; |
| 7235 | 7286 | } |
| 7236 | | } |
| 7237 | | }, |
| 7238 | | } |
| 7287 | }, |
| 7288 | .break_void => if (pass == .breaks) { |
| 7289 | assert(!strat.elide_store_to_block_ptr_instructions); |
| 7290 | const last_inst = payloads.items[end_index - 1]; |
| 7291 | if (zir_tags[last_inst] == .@"break") { |
| 7292 | const break_data = &zir_datas[last_inst].@"break"; |
| 7293 | const block_inst = astgen.extra.items[ |
| 7294 | break_data.payload_index + |
| 7295 | std.meta.fieldIndex(Zir.Inst.Break, "block_inst").? |
| 7296 | ]; |
| 7297 | if (block_inst == switch_block) break_data.operand = .void_value; |
| 7298 | } |
| 7299 | }, |
| 7300 | } |
| 7239 | 7301 | |
| 7240 | | astgen.extra.appendSliceAssumeCapacity(payloads.items[start_index..end_index]); |
| 7302 | if (pass == .body) |
| 7303 | astgen.extra.appendSliceAssumeCapacity(payloads.items[start_index..end_index]); |
| 7304 | } |
| 7241 | 7305 | } |
| 7242 | 7306 | |
| 7243 | 7307 | const block_ref = indexToRef(switch_block); |
| ... | ... | @@ -7403,7 +7467,7 @@ fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 { |
| 7403 | 7467 | }; |
| 7404 | 7468 | |
| 7405 | 7469 | if (x != 0) x = try std.math.mul(u16, x, 10); |
| 7406 | | x = try std.math.add(u16, x, @as(u16, digit)); |
| 7470 | x = try std.math.add(u16, x, digit); |
| 7407 | 7471 | } |
| 7408 | 7472 | |
| 7409 | 7473 | return x; |
| ... | ... | @@ -7617,7 +7681,7 @@ fn tunnelThroughClosure( |
| 7617 | 7681 | .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token), |
| 7618 | 7682 | } }, |
| 7619 | 7683 | }); |
| 7620 | | gop.value_ptr.* = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len - 1)); |
| 7684 | gop.value_ptr.* = @intCast(gz.astgen.instructions.len - 1); |
| 7621 | 7685 | } |
| 7622 | 7686 | |
| 7623 | 7687 | // Add an instruction to get the value from the closure into |
| ... | ... | @@ -7697,7 +7761,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: |
| 7697 | 7761 | const gpa = astgen.gpa; |
| 7698 | 7762 | var big_int = try std.math.big.int.Managed.init(gpa); |
| 7699 | 7763 | defer big_int.deinit(); |
| 7700 | | const prefix_offset = @as(u8, 2) * @intFromBool(base != .decimal); |
| 7764 | const prefix_offset: usize = if (base == .decimal) 0 else 2; |
| 7701 | 7765 | big_int.setString(@intFromEnum(base), bytes[prefix_offset..]) catch |err| switch (err) { |
| 7702 | 7766 | error.InvalidCharacter => unreachable, // caught in `parseNumberLiteral` |
| 7703 | 7767 | error.InvalidBase => unreachable, // we only pass 16, 8, 2, see above |
| ... | ... | @@ -7718,7 +7782,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: |
| 7718 | 7782 | }; |
| 7719 | 7783 | // If the value fits into a f64 without losing any precision, store it that way. |
| 7720 | 7784 | @setFloatMode(.Strict); |
| 7721 | | const smaller_float = @as(f64, @floatCast(float_number)); |
| 7785 | const smaller_float: f64 = @floatCast(float_number); |
| 7722 | 7786 | const bigger_again: f128 = smaller_float; |
| 7723 | 7787 | if (bigger_again == float_number) { |
| 7724 | 7788 | const result = try gz.addFloat(smaller_float); |
| ... | ... | @@ -7726,12 +7790,12 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: |
| 7726 | 7790 | } |
| 7727 | 7791 | // We need to use 128 bits. Break the float into 4 u32 values so we can |
| 7728 | 7792 | // put it into the `extra` array. |
| 7729 | | const int_bits = @as(u128, @bitCast(float_number)); |
| 7793 | const int_bits: u128 = @bitCast(float_number); |
| 7730 | 7794 | const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{ |
| 7731 | | .piece0 = @as(u32, @truncate(int_bits)), |
| 7732 | | .piece1 = @as(u32, @truncate(int_bits >> 32)), |
| 7733 | | .piece2 = @as(u32, @truncate(int_bits >> 64)), |
| 7734 | | .piece3 = @as(u32, @truncate(int_bits >> 96)), |
| 7795 | .piece0 = @truncate(int_bits), |
| 7796 | .piece1 = @truncate(int_bits >> 32), |
| 7797 | .piece2 = @truncate(int_bits >> 64), |
| 7798 | .piece3 = @truncate(int_bits >> 96), |
| 7735 | 7799 | }); |
| 7736 | 7800 | return rvalue(gz, ri, result, source_node); |
| 7737 | 7801 | }, |
| ... | ... | @@ -7757,22 +7821,22 @@ fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token |
| 7757 | 7821 | }); |
| 7758 | 7822 | }, |
| 7759 | 7823 | .digit_after_base => return astgen.failTok(token, "expected a digit after base prefix", .{}), |
| 7760 | | .upper_case_base => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "base prefix must be lowercase", .{}), |
| 7761 | | .invalid_float_base => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "invalid base for float literal", .{}), |
| 7762 | | .repeated_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "repeated digit separator", .{}), |
| 7763 | | .invalid_underscore_after_special => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before digit separator", .{}), |
| 7764 | | .invalid_digit => |info| return astgen.failOff(token, @as(u32, @intCast(info.i)), "invalid digit '{c}' for {s} base", .{ bytes[info.i], @tagName(info.base) }), |
| 7765 | | .invalid_digit_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "invalid digit '{c}' in exponent", .{bytes[i]}), |
| 7766 | | .duplicate_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "duplicate exponent", .{}), |
| 7767 | | .exponent_after_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before exponent", .{}), |
| 7768 | | .special_after_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before '{c}'", .{bytes[i]}), |
| 7769 | | .trailing_special => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit after '{c}'", .{bytes[i - 1]}), |
| 7770 | | .trailing_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "trailing digit separator", .{}), |
| 7824 | .upper_case_base => |i| return astgen.failOff(token, @intCast(i), "base prefix must be lowercase", .{}), |
| 7825 | .invalid_float_base => |i| return astgen.failOff(token, @intCast(i), "invalid base for float literal", .{}), |
| 7826 | .repeated_underscore => |i| return astgen.failOff(token, @intCast(i), "repeated digit separator", .{}), |
| 7827 | .invalid_underscore_after_special => |i| return astgen.failOff(token, @intCast(i), "expected digit before digit separator", .{}), |
| 7828 | .invalid_digit => |info| return astgen.failOff(token, @intCast(info.i), "invalid digit '{c}' for {s} base", .{ bytes[info.i], @tagName(info.base) }), |
| 7829 | .invalid_digit_exponent => |i| return astgen.failOff(token, @intCast(i), "invalid digit '{c}' in exponent", .{bytes[i]}), |
| 7830 | .duplicate_exponent => |i| return astgen.failOff(token, @intCast(i), "duplicate exponent", .{}), |
| 7831 | .exponent_after_underscore => |i| return astgen.failOff(token, @intCast(i), "expected digit before exponent", .{}), |
| 7832 | .special_after_underscore => |i| return astgen.failOff(token, @intCast(i), "expected digit before '{c}'", .{bytes[i]}), |
| 7833 | .trailing_special => |i| return astgen.failOff(token, @intCast(i), "expected digit after '{c}'", .{bytes[i - 1]}), |
| 7834 | .trailing_underscore => |i| return astgen.failOff(token, @intCast(i), "trailing digit separator", .{}), |
| 7771 | 7835 | .duplicate_period => unreachable, // Validated by tokenizer |
| 7772 | 7836 | .invalid_character => unreachable, // Validated by tokenizer |
| 7773 | 7837 | .invalid_exponent_sign => |i| { |
| 7774 | 7838 | assert(bytes.len >= 2 and bytes[0] == '0' and bytes[1] == 'x'); // Validated by tokenizer |
| 7775 | | return astgen.failOff(token, @as(u32, @intCast(i)), "sign '{c}' cannot follow digit '{c}' in hex base", .{ bytes[i], bytes[i - 1] }); |
| 7839 | return astgen.failOff(token, @intCast(i), "sign '{c}' cannot follow digit '{c}' in hex base", .{ bytes[i], bytes[i - 1] }); |
| 7776 | 7840 | }, |
| 7777 | 7841 | } |
| 7778 | 7842 | } |
| ... | ... | @@ -7839,7 +7903,7 @@ fn asmExpr( |
| 7839 | 7903 | if (output_type_bits != 0) { |
| 7840 | 7904 | return astgen.failNode(output_node, "inline assembly allows up to one output value", .{}); |
| 7841 | 7905 | } |
| 7842 | | output_type_bits |= @as(u32, 1) << @as(u5, @intCast(i)); |
| 7906 | output_type_bits |= @as(u32, 1) << @intCast(i); |
| 7843 | 7907 | const out_type_node = node_datas[output_node].lhs; |
| 7844 | 7908 | const out_type_inst = try typeExpr(gz, scope, out_type_node); |
| 7845 | 7909 | outputs[i] = .{ |
| ... | ... | @@ -8062,7 +8126,7 @@ fn ptrCast( |
| 8062 | 8126 | node = node_datas[node].lhs; |
| 8063 | 8127 | } |
| 8064 | 8128 | |
| 8065 | | const flags_i = @as(u5, @bitCast(flags)); |
| 8129 | const flags_i: u5 = @bitCast(flags); |
| 8066 | 8130 | assert(flags_i != 0); |
| 8067 | 8131 | |
| 8068 | 8132 | const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true }; |
| ... | ... | @@ -8149,8 +8213,8 @@ fn typeOf( |
| 8149 | 8213 | const body = typeof_scope.instructionsSlice(); |
| 8150 | 8214 | const body_len = astgen.countBodyLenAfterFixups(body); |
| 8151 | 8215 | astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{ |
| 8152 | | .body_len = @as(u32, @intCast(body_len)), |
| 8153 | | .body_index = @as(u32, @intCast(astgen.extra.items.len)), |
| 8216 | .body_len = @intCast(body_len), |
| 8217 | .body_index = @intCast(astgen.extra.items.len), |
| 8154 | 8218 | .src_node = gz.nodeIndexToRelative(node), |
| 8155 | 8219 | }); |
| 8156 | 8220 | try astgen.extra.ensureUnusedCapacity(gpa, body_len); |
| ... | ... | @@ -8509,7 +8573,7 @@ fn builtinCall( |
| 8509 | 8573 | .node = gz.nodeIndexToRelative(node), |
| 8510 | 8574 | .operand = operand, |
| 8511 | 8575 | }); |
| 8512 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 8576 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 8513 | 8577 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 8514 | 8578 | .tag = .extended, |
| 8515 | 8579 | .data = .{ .extended = .{ |
| ... | ... | @@ -9164,7 +9228,7 @@ fn callExpr( |
| 9164 | 9228 | } |
| 9165 | 9229 | assert(node != 0); |
| 9166 | 9230 | |
| 9167 | | const call_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 9231 | const call_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 9168 | 9232 | const call_inst = Zir.indexToRef(call_index); |
| 9169 | 9233 | try gz.astgen.instructions.append(astgen.gpa, undefined); |
| 9170 | 9234 | try gz.instructions.append(astgen.gpa, call_index); |
| ... | ... | @@ -9188,7 +9252,7 @@ fn callExpr( |
| 9188 | 9252 | try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body)); |
| 9189 | 9253 | appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body); |
| 9190 | 9254 | |
| 9191 | | astgen.scratch.items[scratch_index] = @as(u32, @intCast(astgen.scratch.items.len - scratch_top)); |
| 9255 | astgen.scratch.items[scratch_index] = @intCast(astgen.scratch.items.len - scratch_top); |
| 9192 | 9256 | scratch_index += 1; |
| 9193 | 9257 | } |
| 9194 | 9258 | |
| ... | ... | @@ -9206,8 +9270,8 @@ fn callExpr( |
| 9206 | 9270 | .callee = callee_obj, |
| 9207 | 9271 | .flags = .{ |
| 9208 | 9272 | .pop_error_return_trace = !propagate_error_trace, |
| 9209 | | .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))), |
| 9210 | | .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)), |
| 9273 | .packed_modifier = @intCast(@intFromEnum(modifier)), |
| 9274 | .args_len = @intCast(call.ast.params.len), |
| 9211 | 9275 | }, |
| 9212 | 9276 | }); |
| 9213 | 9277 | if (call.ast.params.len != 0) { |
| ... | ... | @@ -9227,8 +9291,8 @@ fn callExpr( |
| 9227 | 9291 | .field_name_start = callee_field.field_name_start, |
| 9228 | 9292 | .flags = .{ |
| 9229 | 9293 | .pop_error_return_trace = !propagate_error_trace, |
| 9230 | | .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))), |
| 9231 | | .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)), |
| 9294 | .packed_modifier = @intCast(@intFromEnum(modifier)), |
| 9295 | .args_len = @intCast(call.ast.params.len), |
| 9232 | 9296 | }, |
| 9233 | 9297 | }); |
| 9234 | 9298 | if (call.ast.params.len != 0) { |
| ... | ... | @@ -10703,14 +10767,14 @@ fn appendErrorNodeNotes( |
| 10703 | 10767 | ) Allocator.Error!void { |
| 10704 | 10768 | @setCold(true); |
| 10705 | 10769 | const string_bytes = &astgen.string_bytes; |
| 10706 | | const msg = @as(u32, @intCast(string_bytes.items.len)); |
| 10770 | const msg: u32 = @intCast(string_bytes.items.len); |
| 10707 | 10771 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); |
| 10708 | 10772 | const notes_index: u32 = if (notes.len != 0) blk: { |
| 10709 | 10773 | const notes_start = astgen.extra.items.len; |
| 10710 | 10774 | try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len); |
| 10711 | | astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len))); |
| 10775 | astgen.extra.appendAssumeCapacity(@intCast(notes.len)); |
| 10712 | 10776 | astgen.extra.appendSliceAssumeCapacity(notes); |
| 10713 | | break :blk @as(u32, @intCast(notes_start)); |
| 10777 | break :blk @intCast(notes_start); |
| 10714 | 10778 | } else 0; |
| 10715 | 10779 | try astgen.compile_errors.append(astgen.gpa, .{ |
| 10716 | 10780 | .msg = msg, |
| ... | ... | @@ -10795,14 +10859,14 @@ fn appendErrorTokNotesOff( |
| 10795 | 10859 | @setCold(true); |
| 10796 | 10860 | const gpa = astgen.gpa; |
| 10797 | 10861 | const string_bytes = &astgen.string_bytes; |
| 10798 | | const msg = @as(u32, @intCast(string_bytes.items.len)); |
| 10862 | const msg: u32 = @intCast(string_bytes.items.len); |
| 10799 | 10863 | try string_bytes.writer(gpa).print(format ++ "\x00", args); |
| 10800 | 10864 | const notes_index: u32 = if (notes.len != 0) blk: { |
| 10801 | 10865 | const notes_start = astgen.extra.items.len; |
| 10802 | 10866 | try astgen.extra.ensureTotalCapacity(gpa, notes_start + 1 + notes.len); |
| 10803 | | astgen.extra.appendAssumeCapacity(@as(u32, @intCast(notes.len))); |
| 10867 | astgen.extra.appendAssumeCapacity(@intCast(notes.len)); |
| 10804 | 10868 | astgen.extra.appendSliceAssumeCapacity(notes); |
| 10805 | | break :blk @as(u32, @intCast(notes_start)); |
| 10869 | break :blk @intCast(notes_start); |
| 10806 | 10870 | } else 0; |
| 10807 | 10871 | try astgen.compile_errors.append(gpa, .{ |
| 10808 | 10872 | .msg = msg, |
| ... | ... | @@ -10831,7 +10895,7 @@ fn errNoteTokOff( |
| 10831 | 10895 | ) Allocator.Error!u32 { |
| 10832 | 10896 | @setCold(true); |
| 10833 | 10897 | const string_bytes = &astgen.string_bytes; |
| 10834 | | const msg = @as(u32, @intCast(string_bytes.items.len)); |
| 10898 | const msg: u32 = @intCast(string_bytes.items.len); |
| 10835 | 10899 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); |
| 10836 | 10900 | return astgen.addExtra(Zir.Inst.CompileErrors.Item{ |
| 10837 | 10901 | .msg = msg, |
| ... | ... | @@ -10850,7 +10914,7 @@ fn errNoteNode( |
| 10850 | 10914 | ) Allocator.Error!u32 { |
| 10851 | 10915 | @setCold(true); |
| 10852 | 10916 | const string_bytes = &astgen.string_bytes; |
| 10853 | | const msg = @as(u32, @intCast(string_bytes.items.len)); |
| 10917 | const msg: u32 = @intCast(string_bytes.items.len); |
| 10854 | 10918 | try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args); |
| 10855 | 10919 | return astgen.addExtra(Zir.Inst.CompileErrors.Item{ |
| 10856 | 10920 | .msg = msg, |
| ... | ... | @@ -10864,7 +10928,7 @@ fn errNoteNode( |
| 10864 | 10928 | fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 { |
| 10865 | 10929 | const gpa = astgen.gpa; |
| 10866 | 10930 | const string_bytes = &astgen.string_bytes; |
| 10867 | | const str_index = @as(u32, @intCast(string_bytes.items.len)); |
| 10931 | const str_index: u32 = @intCast(string_bytes.items.len); |
| 10868 | 10932 | try astgen.appendIdentStr(ident_token, string_bytes); |
| 10869 | 10933 | const key: []const u8 = string_bytes.items[str_index..]; |
| 10870 | 10934 | const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{ |
| ... | ... | @@ -10886,7 +10950,7 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 { |
| 10886 | 10950 | /// `end_token` must point at the first token after the last doc coment line. |
| 10887 | 10951 | /// Returns 0 if no doc comment is present. |
| 10888 | 10952 | fn docCommentAsString(astgen: *AstGen, end_token: Ast.TokenIndex) !u32 { |
| 10889 | | if (end_token == 0) return @as(u32, 0); |
| 10953 | if (end_token == 0) return 0; |
| 10890 | 10954 | |
| 10891 | 10955 | const token_tags = astgen.tree.tokens.items(.tag); |
| 10892 | 10956 | |
| ... | ... | @@ -10910,7 +10974,7 @@ fn docCommentAsStringFromFirst( |
| 10910 | 10974 | |
| 10911 | 10975 | const gpa = astgen.gpa; |
| 10912 | 10976 | const string_bytes = &astgen.string_bytes; |
| 10913 | | const str_index = @as(u32, @intCast(string_bytes.items.len)); |
| 10977 | const str_index: u32 = @intCast(string_bytes.items.len); |
| 10914 | 10978 | const token_starts = astgen.tree.tokens.items(.start); |
| 10915 | 10979 | const token_tags = astgen.tree.tokens.items(.tag); |
| 10916 | 10980 | |
| ... | ... | @@ -10931,8 +10995,8 @@ fn docCommentAsStringFromFirst( |
| 10931 | 10995 | } |
| 10932 | 10996 | } |
| 10933 | 10997 | |
| 10934 | | const key = string_bytes.items[str_index..]; |
| 10935 | | const gop = try astgen.string_table.getOrPutContextAdapted(gpa, @as([]const u8, key), StringIndexAdapter{ |
| 10998 | const key: []const u8 = string_bytes.items[str_index..]; |
| 10999 | const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{ |
| 10936 | 11000 | .bytes = string_bytes, |
| 10937 | 11001 | }, StringIndexContext{ |
| 10938 | 11002 | .bytes = string_bytes, |
| ... | ... | @@ -10953,11 +11017,11 @@ const IndexSlice = struct { index: u32, len: u32 }; |
| 10953 | 11017 | fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { |
| 10954 | 11018 | const gpa = astgen.gpa; |
| 10955 | 11019 | const string_bytes = &astgen.string_bytes; |
| 10956 | | const str_index = @as(u32, @intCast(string_bytes.items.len)); |
| 11020 | const str_index: u32 = @intCast(string_bytes.items.len); |
| 10957 | 11021 | const token_bytes = astgen.tree.tokenSlice(str_lit_token); |
| 10958 | 11022 | try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0); |
| 10959 | | const key = string_bytes.items[str_index..]; |
| 10960 | | const gop = try astgen.string_table.getOrPutContextAdapted(gpa, @as([]const u8, key), StringIndexAdapter{ |
| 11023 | const key: []const u8 = string_bytes.items[str_index..]; |
| 11024 | const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{ |
| 10961 | 11025 | .bytes = string_bytes, |
| 10962 | 11026 | }, StringIndexContext{ |
| 10963 | 11027 | .bytes = string_bytes, |
| ... | ... | @@ -10966,7 +11030,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { |
| 10966 | 11030 | string_bytes.shrinkRetainingCapacity(str_index); |
| 10967 | 11031 | return IndexSlice{ |
| 10968 | 11032 | .index = gop.key_ptr.*, |
| 10969 | | .len = @as(u32, @intCast(key.len)), |
| 11033 | .len = @intCast(key.len), |
| 10970 | 11034 | }; |
| 10971 | 11035 | } else { |
| 10972 | 11036 | gop.key_ptr.* = str_index; |
| ... | ... | @@ -10976,7 +11040,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { |
| 10976 | 11040 | try string_bytes.append(gpa, 0); |
| 10977 | 11041 | return IndexSlice{ |
| 10978 | 11042 | .index = str_index, |
| 10979 | | .len = @as(u32, @intCast(key.len)), |
| 11043 | .len = @intCast(key.len), |
| 10980 | 11044 | }; |
| 10981 | 11045 | } |
| 10982 | 11046 | } |
| ... | ... | @@ -11013,15 +11077,15 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice { |
| 11013 | 11077 | const len = string_bytes.items.len - str_index; |
| 11014 | 11078 | try string_bytes.append(gpa, 0); |
| 11015 | 11079 | return IndexSlice{ |
| 11016 | | .index = @as(u32, @intCast(str_index)), |
| 11017 | | .len = @as(u32, @intCast(len)), |
| 11080 | .index = @intCast(str_index), |
| 11081 | .len = @intCast(len), |
| 11018 | 11082 | }; |
| 11019 | 11083 | } |
| 11020 | 11084 | |
| 11021 | 11085 | fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 { |
| 11022 | 11086 | const gpa = astgen.gpa; |
| 11023 | 11087 | const string_bytes = &astgen.string_bytes; |
| 11024 | | const str_index = @as(u32, @intCast(string_bytes.items.len)); |
| 11088 | const str_index: u32 = @intCast(string_bytes.items.len); |
| 11025 | 11089 | const token_bytes = astgen.tree.tokenSlice(str_lit_token); |
| 11026 | 11090 | try string_bytes.append(gpa, 0); // Indicates this is a test. |
| 11027 | 11091 | try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0); |
| ... | ... | @@ -11340,7 +11404,10 @@ const GenZir = struct { |
| 11340 | 11404 | parent_gz.instructions.items.len -= src - dst; |
| 11341 | 11405 | as_scope.instructions_top = GenZir.unstacked_top; |
| 11342 | 11406 | // as_scope now unstacked, can add new instructions to parent_gz |
| 11343 | | const casted_result = try parent_gz.addBin(.as, dest_type, result); |
| 11407 | const casted_result = try parent_gz.addPlNode(.as_node, src_node, Zir.Inst.As{ |
| 11408 | .dest_type = dest_type, |
| 11409 | .operand = result, |
| 11410 | }); |
| 11344 | 11411 | return rvalue(parent_gz, ri, casted_result, src_node); |
| 11345 | 11412 | } else { |
| 11346 | 11413 | // implicitly move all as_scope instructions to parent_gz |
| ... | ... | @@ -11530,7 +11597,7 @@ const GenZir = struct { |
| 11530 | 11597 | const astgen = gz.astgen; |
| 11531 | 11598 | const gpa = astgen.gpa; |
| 11532 | 11599 | const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref; |
| 11533 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 11600 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 11534 | 11601 | |
| 11535 | 11602 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11536 | 11603 | |
| ... | ... | @@ -11548,8 +11615,8 @@ const GenZir = struct { |
| 11548 | 11615 | const block = node_datas[fn_decl].rhs; |
| 11549 | 11616 | const rbrace_start = token_starts[tree.lastToken(block)]; |
| 11550 | 11617 | astgen.advanceSourceCursor(rbrace_start); |
| 11551 | | const rbrace_line = @as(u32, @intCast(astgen.source_line - gz.decl_line)); |
| 11552 | | const rbrace_column = @as(u32, @intCast(astgen.source_column)); |
| 11618 | const rbrace_line: u32 = @intCast(astgen.source_line - gz.decl_line); |
| 11619 | const rbrace_column: u32 = @intCast(astgen.source_column); |
| 11553 | 11620 | |
| 11554 | 11621 | const columns = args.lbrace_column | (rbrace_column << 16); |
| 11555 | 11622 | src_locs_buffer[0] = args.lbrace_line; |
| ... | ... | @@ -11626,40 +11693,47 @@ const GenZir = struct { |
| 11626 | 11693 | if (align_body.len != 0) { |
| 11627 | 11694 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body)); |
| 11628 | 11695 | astgen.appendBodyWithFixups(align_body); |
| 11629 | | const inst_data = zir_datas[align_body[align_body.len - 1]].@"break"; |
| 11630 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11696 | const break_extra = zir_datas[align_body[align_body.len - 1]].@"break".payload_index; |
| 11697 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11698 | new_index; |
| 11631 | 11699 | } else if (args.align_ref != .none) { |
| 11632 | 11700 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref)); |
| 11633 | 11701 | } |
| 11634 | 11702 | if (addrspace_body.len != 0) { |
| 11635 | 11703 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body)); |
| 11636 | 11704 | astgen.appendBodyWithFixups(addrspace_body); |
| 11637 | | const inst_data = zir_datas[addrspace_body[addrspace_body.len - 1]].@"break"; |
| 11638 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11705 | const break_extra = |
| 11706 | zir_datas[addrspace_body[addrspace_body.len - 1]].@"break".payload_index; |
| 11707 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11708 | new_index; |
| 11639 | 11709 | } else if (args.addrspace_ref != .none) { |
| 11640 | 11710 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref)); |
| 11641 | 11711 | } |
| 11642 | 11712 | if (section_body.len != 0) { |
| 11643 | 11713 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body)); |
| 11644 | 11714 | astgen.appendBodyWithFixups(section_body); |
| 11645 | | const inst_data = zir_datas[section_body[section_body.len - 1]].@"break"; |
| 11646 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11715 | const break_extra = |
| 11716 | zir_datas[section_body[section_body.len - 1]].@"break".payload_index; |
| 11717 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11718 | new_index; |
| 11647 | 11719 | } else if (args.section_ref != .none) { |
| 11648 | 11720 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref)); |
| 11649 | 11721 | } |
| 11650 | 11722 | if (cc_body.len != 0) { |
| 11651 | 11723 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body)); |
| 11652 | 11724 | astgen.appendBodyWithFixups(cc_body); |
| 11653 | | const inst_data = zir_datas[cc_body[cc_body.len - 1]].@"break"; |
| 11654 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11725 | const break_extra = zir_datas[cc_body[cc_body.len - 1]].@"break".payload_index; |
| 11726 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11727 | new_index; |
| 11655 | 11728 | } else if (args.cc_ref != .none) { |
| 11656 | 11729 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref)); |
| 11657 | 11730 | } |
| 11658 | 11731 | if (ret_body.len != 0) { |
| 11659 | 11732 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body)); |
| 11660 | 11733 | astgen.appendBodyWithFixups(ret_body); |
| 11661 | | const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break"; |
| 11662 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11734 | const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index; |
| 11735 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11736 | new_index; |
| 11663 | 11737 | } else if (ret_ref != .none) { |
| 11664 | 11738 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11665 | 11739 | } |
| ... | ... | @@ -11714,8 +11788,9 @@ const GenZir = struct { |
| 11714 | 11788 | if (ret_body.len != 0) { |
| 11715 | 11789 | astgen.appendBodyWithFixups(ret_body); |
| 11716 | 11790 | |
| 11717 | | const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break"; |
| 11718 | | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11791 | const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index; |
| 11792 | astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] = |
| 11793 | new_index; |
| 11719 | 11794 | } else if (ret_ref != .none) { |
| 11720 | 11795 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 11721 | 11796 | } |
| ... | ... | @@ -11785,18 +11860,18 @@ const GenZir = struct { |
| 11785 | 11860 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.init)); |
| 11786 | 11861 | } |
| 11787 | 11862 | |
| 11788 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 11863 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 11789 | 11864 | astgen.instructions.appendAssumeCapacity(.{ |
| 11790 | 11865 | .tag = .extended, |
| 11791 | 11866 | .data = .{ .extended = .{ |
| 11792 | 11867 | .opcode = .variable, |
| 11793 | | .small = @as(u16, @bitCast(Zir.Inst.ExtendedVar.Small{ |
| 11868 | .small = @bitCast(Zir.Inst.ExtendedVar.Small{ |
| 11794 | 11869 | .has_lib_name = args.lib_name != 0, |
| 11795 | 11870 | .has_align = args.align_inst != .none, |
| 11796 | 11871 | .has_init = args.init != .none, |
| 11797 | 11872 | .is_extern = args.is_extern, |
| 11798 | 11873 | .is_threadlocal = args.is_threadlocal, |
| 11799 | | })), |
| 11874 | }), |
| 11800 | 11875 | .operand = payload_index, |
| 11801 | 11876 | } }, |
| 11802 | 11877 | }); |
| ... | ... | @@ -11816,7 +11891,7 @@ const GenZir = struct { |
| 11816 | 11891 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11817 | 11892 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11818 | 11893 | |
| 11819 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 11894 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 11820 | 11895 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11821 | 11896 | .tag = tag, |
| 11822 | 11897 | .data = .{ .bool_br = .{ |
| ... | ... | @@ -11842,12 +11917,12 @@ const GenZir = struct { |
| 11842 | 11917 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11843 | 11918 | try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len); |
| 11844 | 11919 | |
| 11845 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 11920 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 11846 | 11921 | astgen.instructions.appendAssumeCapacity(.{ |
| 11847 | 11922 | .tag = .int_big, |
| 11848 | 11923 | .data = .{ .str = .{ |
| 11849 | | .start = @as(u32, @intCast(astgen.string_bytes.items.len)), |
| 11850 | | .len = @as(u32, @intCast(limbs.len)), |
| 11924 | .start = @intCast(astgen.string_bytes.items.len), |
| 11925 | .len = @intCast(limbs.len), |
| 11851 | 11926 | } }, |
| 11852 | 11927 | }); |
| 11853 | 11928 | gz.instructions.appendAssumeCapacity(new_index); |
| ... | ... | @@ -11887,7 +11962,7 @@ const GenZir = struct { |
| 11887 | 11962 | src_node: Ast.Node.Index, |
| 11888 | 11963 | ) !Zir.Inst.Index { |
| 11889 | 11964 | assert(operand != .none); |
| 11890 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 11965 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 11891 | 11966 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 11892 | 11967 | .tag = tag, |
| 11893 | 11968 | .data = .{ .un_node = .{ |
| ... | ... | @@ -11910,7 +11985,7 @@ const GenZir = struct { |
| 11910 | 11985 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11911 | 11986 | |
| 11912 | 11987 | const payload_index = try gz.astgen.addExtra(extra); |
| 11913 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 11988 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 11914 | 11989 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11915 | 11990 | .tag = tag, |
| 11916 | 11991 | .data = .{ .pl_node = .{ |
| ... | ... | @@ -11962,12 +12037,12 @@ const GenZir = struct { |
| 11962 | 12037 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{ |
| 11963 | 12038 | .name = name, |
| 11964 | 12039 | .doc_comment = doc_comment_index, |
| 11965 | | .body_len = @as(u32, @intCast(body_len)), |
| 12040 | .body_len = @intCast(body_len), |
| 11966 | 12041 | }); |
| 11967 | 12042 | gz.astgen.appendBodyWithFixups(param_body); |
| 11968 | 12043 | param_gz.unstack(); |
| 11969 | 12044 | |
| 11970 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12045 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 11971 | 12046 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11972 | 12047 | .tag = tag, |
| 11973 | 12048 | .data = .{ .pl_tok = .{ |
| ... | ... | @@ -11995,7 +12070,7 @@ const GenZir = struct { |
| 11995 | 12070 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11996 | 12071 | |
| 11997 | 12072 | const payload_index = try gz.astgen.addExtra(extra); |
| 11998 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12073 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 11999 | 12074 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 12000 | 12075 | .tag = .extended, |
| 12001 | 12076 | .data = .{ .extended = .{ |
| ... | ... | @@ -12027,12 +12102,12 @@ const GenZir = struct { |
| 12027 | 12102 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{ |
| 12028 | 12103 | .src_node = gz.nodeIndexToRelative(node), |
| 12029 | 12104 | }); |
| 12030 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 12105 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 12031 | 12106 | astgen.instructions.appendAssumeCapacity(.{ |
| 12032 | 12107 | .tag = .extended, |
| 12033 | 12108 | .data = .{ .extended = .{ |
| 12034 | 12109 | .opcode = opcode, |
| 12035 | | .small = @as(u16, @intCast(operands.len)), |
| 12110 | .small = @intCast(operands.len), |
| 12036 | 12111 | .operand = payload_index, |
| 12037 | 12112 | } }, |
| 12038 | 12113 | }); |
| ... | ... | @@ -12052,12 +12127,12 @@ const GenZir = struct { |
| 12052 | 12127 | |
| 12053 | 12128 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12054 | 12129 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12055 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 12130 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 12056 | 12131 | astgen.instructions.appendAssumeCapacity(.{ |
| 12057 | 12132 | .tag = .extended, |
| 12058 | 12133 | .data = .{ .extended = .{ |
| 12059 | 12134 | .opcode = opcode, |
| 12060 | | .small = @as(u16, @intCast(trailing_len)), |
| 12135 | .small = @intCast(trailing_len), |
| 12061 | 12136 | .operand = payload_index, |
| 12062 | 12137 | } }, |
| 12063 | 12138 | }); |
| ... | ... | @@ -12090,7 +12165,7 @@ const GenZir = struct { |
| 12090 | 12165 | abs_tok_index: Ast.TokenIndex, |
| 12091 | 12166 | ) !Zir.Inst.Index { |
| 12092 | 12167 | const astgen = gz.astgen; |
| 12093 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 12168 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 12094 | 12169 | assert(operand != .none); |
| 12095 | 12170 | try astgen.instructions.append(astgen.gpa, .{ |
| 12096 | 12171 | .tag = tag, |
| ... | ... | @@ -12169,21 +12244,8 @@ const GenZir = struct { |
| 12169 | 12244 | ) !Zir.Inst.Index { |
| 12170 | 12245 | const gpa = gz.astgen.gpa; |
| 12171 | 12246 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12172 | | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12173 | 12247 | |
| 12174 | | const extra: Zir.Inst.Break = .{ |
| 12175 | | .block_inst = block_inst, |
| 12176 | | .operand_src_node = Zir.Inst.Break.no_src_node, |
| 12177 | | }; |
| 12178 | | const payload_index = try gz.astgen.addExtra(extra); |
| 12179 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12180 | | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 12181 | | .tag = tag, |
| 12182 | | .data = .{ .@"break" = .{ |
| 12183 | | .operand = operand, |
| 12184 | | .payload_index = payload_index, |
| 12185 | | } }, |
| 12186 | | }); |
| 12248 | const new_index = try gz.makeBreak(tag, block_inst, operand); |
| 12187 | 12249 | gz.instructions.appendAssumeCapacity(new_index); |
| 12188 | 12250 | return new_index; |
| 12189 | 12251 | } |
| ... | ... | @@ -12194,23 +12256,7 @@ const GenZir = struct { |
| 12194 | 12256 | block_inst: Zir.Inst.Index, |
| 12195 | 12257 | operand: Zir.Inst.Ref, |
| 12196 | 12258 | ) !Zir.Inst.Index { |
| 12197 | | const gpa = gz.astgen.gpa; |
| 12198 | | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12199 | | |
| 12200 | | const extra: Zir.Inst.Break = .{ |
| 12201 | | .block_inst = block_inst, |
| 12202 | | .operand_src_node = Zir.Inst.Break.no_src_node, |
| 12203 | | }; |
| 12204 | | const payload_index = try gz.astgen.addExtra(extra); |
| 12205 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12206 | | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 12207 | | .tag = tag, |
| 12208 | | .data = .{ .@"break" = .{ |
| 12209 | | .operand = operand, |
| 12210 | | .payload_index = payload_index, |
| 12211 | | } }, |
| 12212 | | }); |
| 12213 | | return new_index; |
| 12259 | return gz.makeBreakCommon(tag, block_inst, operand, null); |
| 12214 | 12260 | } |
| 12215 | 12261 | |
| 12216 | 12262 | fn addBreakWithSrcNode( |
| ... | ... | @@ -12222,21 +12268,8 @@ const GenZir = struct { |
| 12222 | 12268 | ) !Zir.Inst.Index { |
| 12223 | 12269 | const gpa = gz.astgen.gpa; |
| 12224 | 12270 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12225 | | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12226 | 12271 | |
| 12227 | | const extra: Zir.Inst.Break = .{ |
| 12228 | | .block_inst = block_inst, |
| 12229 | | .operand_src_node = gz.nodeIndexToRelative(operand_src_node), |
| 12230 | | }; |
| 12231 | | const payload_index = try gz.astgen.addExtra(extra); |
| 12232 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12233 | | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 12234 | | .tag = tag, |
| 12235 | | .data = .{ .@"break" = .{ |
| 12236 | | .operand = operand, |
| 12237 | | .payload_index = payload_index, |
| 12238 | | } }, |
| 12239 | | }); |
| 12272 | const new_index = try gz.makeBreakWithSrcNode(tag, block_inst, operand, operand_src_node); |
| 12240 | 12273 | gz.instructions.appendAssumeCapacity(new_index); |
| 12241 | 12274 | return new_index; |
| 12242 | 12275 | } |
| ... | ... | @@ -12247,21 +12280,33 @@ const GenZir = struct { |
| 12247 | 12280 | block_inst: Zir.Inst.Index, |
| 12248 | 12281 | operand: Zir.Inst.Ref, |
| 12249 | 12282 | operand_src_node: Ast.Node.Index, |
| 12283 | ) !Zir.Inst.Index { |
| 12284 | return gz.makeBreakCommon(tag, block_inst, operand, operand_src_node); |
| 12285 | } |
| 12286 | |
| 12287 | fn makeBreakCommon( |
| 12288 | gz: *GenZir, |
| 12289 | tag: Zir.Inst.Tag, |
| 12290 | block_inst: Zir.Inst.Index, |
| 12291 | operand: Zir.Inst.Ref, |
| 12292 | operand_src_node: ?Ast.Node.Index, |
| 12250 | 12293 | ) !Zir.Inst.Index { |
| 12251 | 12294 | const gpa = gz.astgen.gpa; |
| 12252 | 12295 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12296 | try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).Struct.fields.len); |
| 12253 | 12297 | |
| 12254 | | const extra: Zir.Inst.Break = .{ |
| 12255 | | .block_inst = block_inst, |
| 12256 | | .operand_src_node = gz.nodeIndexToRelative(operand_src_node), |
| 12257 | | }; |
| 12258 | | const payload_index = try gz.astgen.addExtra(extra); |
| 12259 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12298 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12260 | 12299 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 12261 | 12300 | .tag = tag, |
| 12262 | 12301 | .data = .{ .@"break" = .{ |
| 12263 | 12302 | .operand = operand, |
| 12264 | | .payload_index = payload_index, |
| 12303 | .payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Break{ |
| 12304 | .operand_src_node = if (operand_src_node) |src_node| |
| 12305 | gz.nodeIndexToRelative(src_node) |
| 12306 | else |
| 12307 | Zir.Inst.Break.no_src_node, |
| 12308 | .block_inst = block_inst, |
| 12309 | }), |
| 12265 | 12310 | } }, |
| 12266 | 12311 | }); |
| 12267 | 12312 | return new_index; |
| ... | ... | @@ -12348,7 +12393,7 @@ const GenZir = struct { |
| 12348 | 12393 | .data = .{ .extended = .{ |
| 12349 | 12394 | .opcode = opcode, |
| 12350 | 12395 | .small = undefined, |
| 12351 | | .operand = @as(u32, @bitCast(gz.nodeIndexToRelative(src_node))), |
| 12396 | .operand = @bitCast(gz.nodeIndexToRelative(src_node)), |
| 12352 | 12397 | } }, |
| 12353 | 12398 | }); |
| 12354 | 12399 | } |
| ... | ... | @@ -12372,8 +12417,8 @@ const GenZir = struct { |
| 12372 | 12417 | try astgen.extra.ensureUnusedCapacity( |
| 12373 | 12418 | gpa, |
| 12374 | 12419 | @typeInfo(Zir.Inst.AllocExtended).Struct.fields.len + |
| 12375 | | @as(usize, @intFromBool(args.type_inst != .none)) + |
| 12376 | | @as(usize, @intFromBool(args.align_inst != .none)), |
| 12420 | @intFromBool(args.type_inst != .none) + |
| 12421 | @intFromBool(args.align_inst != .none), |
| 12377 | 12422 | ); |
| 12378 | 12423 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.AllocExtended{ |
| 12379 | 12424 | .src_node = gz.nodeIndexToRelative(args.node), |
| ... | ... | @@ -12391,7 +12436,7 @@ const GenZir = struct { |
| 12391 | 12436 | const is_comptime: u4 = @intFromBool(args.is_comptime); |
| 12392 | 12437 | const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3); |
| 12393 | 12438 | |
| 12394 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 12439 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 12395 | 12440 | astgen.instructions.appendAssumeCapacity(.{ |
| 12396 | 12441 | .tag = .extended, |
| 12397 | 12442 | .data = .{ .extended = .{ |
| ... | ... | @@ -12450,7 +12495,7 @@ const GenZir = struct { |
| 12450 | 12495 | @as(u16, @intCast(args.clobbers.len << 10)) | |
| 12451 | 12496 | (@as(u16, @intFromBool(args.is_volatile)) << 15); |
| 12452 | 12497 | |
| 12453 | | const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len)); |
| 12498 | const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len); |
| 12454 | 12499 | astgen.instructions.appendAssumeCapacity(.{ |
| 12455 | 12500 | .tag = .extended, |
| 12456 | 12501 | .data = .{ .extended = .{ |
| ... | ... | @@ -12467,7 +12512,7 @@ const GenZir = struct { |
| 12467 | 12512 | /// Does *not* append the block instruction to the scope. |
| 12468 | 12513 | /// Leaves the `payload_index` field undefined. |
| 12469 | 12514 | fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { |
| 12470 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12515 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12471 | 12516 | const gpa = gz.astgen.gpa; |
| 12472 | 12517 | try gz.astgen.instructions.append(gpa, .{ |
| 12473 | 12518 | .tag = tag, |
| ... | ... | @@ -12484,7 +12529,7 @@ const GenZir = struct { |
| 12484 | 12529 | fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index { |
| 12485 | 12530 | const gpa = gz.astgen.gpa; |
| 12486 | 12531 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12487 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12532 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12488 | 12533 | try gz.astgen.instructions.append(gpa, .{ |
| 12489 | 12534 | .tag = tag, |
| 12490 | 12535 | .data = .{ .pl_node = .{ |
| ... | ... | @@ -12511,11 +12556,11 @@ const GenZir = struct { |
| 12511 | 12556 | const gpa = astgen.gpa; |
| 12512 | 12557 | |
| 12513 | 12558 | try astgen.extra.ensureUnusedCapacity(gpa, 6); |
| 12514 | | const payload_index = @as(u32, @intCast(astgen.extra.items.len)); |
| 12559 | const payload_index: u32 = @intCast(astgen.extra.items.len); |
| 12515 | 12560 | |
| 12516 | 12561 | if (args.src_node != 0) { |
| 12517 | 12562 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| 12518 | | astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset))); |
| 12563 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); |
| 12519 | 12564 | } |
| 12520 | 12565 | if (args.fields_len != 0) { |
| 12521 | 12566 | astgen.extra.appendAssumeCapacity(args.fields_len); |
| ... | ... | @@ -12533,7 +12578,7 @@ const GenZir = struct { |
| 12533 | 12578 | .tag = .extended, |
| 12534 | 12579 | .data = .{ .extended = .{ |
| 12535 | 12580 | .opcode = .struct_decl, |
| 12536 | | .small = @as(u16, @bitCast(Zir.Inst.StructDecl.Small{ |
| 12581 | .small = @bitCast(Zir.Inst.StructDecl.Small{ |
| 12537 | 12582 | .has_src_node = args.src_node != 0, |
| 12538 | 12583 | .has_fields_len = args.fields_len != 0, |
| 12539 | 12584 | .has_decls_len = args.decls_len != 0, |
| ... | ... | @@ -12543,7 +12588,7 @@ const GenZir = struct { |
| 12543 | 12588 | .is_tuple = args.is_tuple, |
| 12544 | 12589 | .name_strategy = gz.anon_name_strategy, |
| 12545 | 12590 | .layout = args.layout, |
| 12546 | | })), |
| 12591 | }), |
| 12547 | 12592 | .operand = payload_index, |
| 12548 | 12593 | } }, |
| 12549 | 12594 | }); |
| ... | ... | @@ -12562,11 +12607,11 @@ const GenZir = struct { |
| 12562 | 12607 | const gpa = astgen.gpa; |
| 12563 | 12608 | |
| 12564 | 12609 | try astgen.extra.ensureUnusedCapacity(gpa, 5); |
| 12565 | | const payload_index = @as(u32, @intCast(astgen.extra.items.len)); |
| 12610 | const payload_index: u32 = @intCast(astgen.extra.items.len); |
| 12566 | 12611 | |
| 12567 | 12612 | if (args.src_node != 0) { |
| 12568 | 12613 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| 12569 | | astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset))); |
| 12614 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); |
| 12570 | 12615 | } |
| 12571 | 12616 | if (args.tag_type != .none) { |
| 12572 | 12617 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); |
| ... | ... | @@ -12584,7 +12629,7 @@ const GenZir = struct { |
| 12584 | 12629 | .tag = .extended, |
| 12585 | 12630 | .data = .{ .extended = .{ |
| 12586 | 12631 | .opcode = .union_decl, |
| 12587 | | .small = @as(u16, @bitCast(Zir.Inst.UnionDecl.Small{ |
| 12632 | .small = @bitCast(Zir.Inst.UnionDecl.Small{ |
| 12588 | 12633 | .has_src_node = args.src_node != 0, |
| 12589 | 12634 | .has_tag_type = args.tag_type != .none, |
| 12590 | 12635 | .has_body_len = args.body_len != 0, |
| ... | ... | @@ -12593,7 +12638,7 @@ const GenZir = struct { |
| 12593 | 12638 | .name_strategy = gz.anon_name_strategy, |
| 12594 | 12639 | .layout = args.layout, |
| 12595 | 12640 | .auto_enum_tag = args.auto_enum_tag, |
| 12596 | | })), |
| 12641 | }), |
| 12597 | 12642 | .operand = payload_index, |
| 12598 | 12643 | } }, |
| 12599 | 12644 | }); |
| ... | ... | @@ -12611,11 +12656,11 @@ const GenZir = struct { |
| 12611 | 12656 | const gpa = astgen.gpa; |
| 12612 | 12657 | |
| 12613 | 12658 | try astgen.extra.ensureUnusedCapacity(gpa, 5); |
| 12614 | | const payload_index = @as(u32, @intCast(astgen.extra.items.len)); |
| 12659 | const payload_index: u32 = @intCast(astgen.extra.items.len); |
| 12615 | 12660 | |
| 12616 | 12661 | if (args.src_node != 0) { |
| 12617 | 12662 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| 12618 | | astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset))); |
| 12663 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); |
| 12619 | 12664 | } |
| 12620 | 12665 | if (args.tag_type != .none) { |
| 12621 | 12666 | astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type)); |
| ... | ... | @@ -12633,7 +12678,7 @@ const GenZir = struct { |
| 12633 | 12678 | .tag = .extended, |
| 12634 | 12679 | .data = .{ .extended = .{ |
| 12635 | 12680 | .opcode = .enum_decl, |
| 12636 | | .small = @as(u16, @bitCast(Zir.Inst.EnumDecl.Small{ |
| 12681 | .small = @bitCast(Zir.Inst.EnumDecl.Small{ |
| 12637 | 12682 | .has_src_node = args.src_node != 0, |
| 12638 | 12683 | .has_tag_type = args.tag_type != .none, |
| 12639 | 12684 | .has_body_len = args.body_len != 0, |
| ... | ... | @@ -12641,7 +12686,7 @@ const GenZir = struct { |
| 12641 | 12686 | .has_decls_len = args.decls_len != 0, |
| 12642 | 12687 | .name_strategy = gz.anon_name_strategy, |
| 12643 | 12688 | .nonexhaustive = args.nonexhaustive, |
| 12644 | | })), |
| 12689 | }), |
| 12645 | 12690 | .operand = payload_index, |
| 12646 | 12691 | } }, |
| 12647 | 12692 | }); |
| ... | ... | @@ -12655,11 +12700,11 @@ const GenZir = struct { |
| 12655 | 12700 | const gpa = astgen.gpa; |
| 12656 | 12701 | |
| 12657 | 12702 | try astgen.extra.ensureUnusedCapacity(gpa, 2); |
| 12658 | | const payload_index = @as(u32, @intCast(astgen.extra.items.len)); |
| 12703 | const payload_index: u32 = @intCast(astgen.extra.items.len); |
| 12659 | 12704 | |
| 12660 | 12705 | if (args.src_node != 0) { |
| 12661 | 12706 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| 12662 | | astgen.extra.appendAssumeCapacity(@as(u32, @bitCast(node_offset))); |
| 12707 | astgen.extra.appendAssumeCapacity(@bitCast(node_offset)); |
| 12663 | 12708 | } |
| 12664 | 12709 | if (args.decls_len != 0) { |
| 12665 | 12710 | astgen.extra.appendAssumeCapacity(args.decls_len); |
| ... | ... | @@ -12668,11 +12713,11 @@ const GenZir = struct { |
| 12668 | 12713 | .tag = .extended, |
| 12669 | 12714 | .data = .{ .extended = .{ |
| 12670 | 12715 | .opcode = .opaque_decl, |
| 12671 | | .small = @as(u16, @bitCast(Zir.Inst.OpaqueDecl.Small{ |
| 12716 | .small = @bitCast(Zir.Inst.OpaqueDecl.Small{ |
| 12672 | 12717 | .has_src_node = args.src_node != 0, |
| 12673 | 12718 | .has_decls_len = args.decls_len != 0, |
| 12674 | 12719 | .name_strategy = gz.anon_name_strategy, |
| 12675 | | })), |
| 12720 | }), |
| 12676 | 12721 | .operand = payload_index, |
| 12677 | 12722 | } }, |
| 12678 | 12723 | }); |
| ... | ... | @@ -12687,7 +12732,7 @@ const GenZir = struct { |
| 12687 | 12732 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12688 | 12733 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12689 | 12734 | |
| 12690 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12735 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12691 | 12736 | gz.astgen.instructions.appendAssumeCapacity(inst); |
| 12692 | 12737 | gz.instructions.appendAssumeCapacity(new_index); |
| 12693 | 12738 | return new_index; |
| ... | ... | @@ -12698,7 +12743,7 @@ const GenZir = struct { |
| 12698 | 12743 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12699 | 12744 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12700 | 12745 | |
| 12701 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12746 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12702 | 12747 | gz.astgen.instructions.len += 1; |
| 12703 | 12748 | gz.instructions.appendAssumeCapacity(new_index); |
| 12704 | 12749 | return new_index; |
| ... | ... | @@ -12750,7 +12795,7 @@ const GenZir = struct { |
| 12750 | 12795 | return; |
| 12751 | 12796 | } |
| 12752 | 12797 | |
| 12753 | | const new_index = @as(Zir.Inst.Index, @intCast(gz.astgen.instructions.len)); |
| 12798 | const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len); |
| 12754 | 12799 | try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined }); |
| 12755 | 12800 | try gz.instructions.append(gpa, new_index); |
| 12756 | 12801 | } |
| ... | ... | @@ -12759,7 +12804,7 @@ const GenZir = struct { |
| 12759 | 12804 | /// This can only be for short-lived references; the memory becomes invalidated |
| 12760 | 12805 | /// when another string is added. |
| 12761 | 12806 | fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 { |
| 12762 | | return @as([*:0]const u8, @ptrCast(astgen.string_bytes.items.ptr)) + index; |
| 12807 | return @ptrCast(astgen.string_bytes.items[index..]); |
| 12763 | 12808 | } |
| 12764 | 12809 | |
| 12765 | 12810 | /// Local variables shadowing detection, including function parameters. |
| ... | ... | @@ -13038,7 +13083,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool { |
| 13038 | 13083 | .extended => { |
| 13039 | 13084 | const zir_data = astgen.instructions.items(.data); |
| 13040 | 13085 | if (zir_data[inst].extended.opcode != .alloc) return false; |
| 13041 | | const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(zir_data[inst].extended.small)); |
| 13086 | const small: Zir.Inst.AllocExtended.Small = @bitCast(zir_data[inst].extended.small); |
| 13042 | 13087 | return !small.has_type; |
| 13043 | 13088 | }, |
| 13044 | 13089 | |
| ... | ... | @@ -13082,7 +13127,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 { |
| 13082 | 13127 | check_inst = ref_inst; |
| 13083 | 13128 | } |
| 13084 | 13129 | } |
| 13085 | | return @as(u32, @intCast(count)); |
| 13130 | return @intCast(count); |
| 13086 | 13131 | } |
| 13087 | 13132 | |
| 13088 | 13133 | fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void { |
| ... | ... | @@ -13114,7 +13159,7 @@ fn lowerAstErrors(astgen: *AstGen) !void { |
| 13114 | 13159 | |
| 13115 | 13160 | if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) { |
| 13116 | 13161 | const tok = parse_err.token + @intFromBool(parse_err.token_is_prev); |
| 13117 | | const bad_off = @as(u32, @intCast(tree.tokenSlice(parse_err.token + @intFromBool(parse_err.token_is_prev)).len)); |
| 13162 | const bad_off: u32 = @intCast(tree.tokenSlice(parse_err.token + @intFromBool(parse_err.token_is_prev)).len); |
| 13118 | 13163 | const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off; |
| 13119 | 13164 | try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{ |
| 13120 | 13165 | std.zig.fmtEscapes(tree.source[byte_abs..][0..1]), |