authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-12 10:28:26-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-08-12 10:28:26-07:00
loge4d05358e18a49c80079ead3bb31966cea564f87
tree5991f6c784c4bdd67477f00d1d2cf84131f8a5ba
parent5e0107fbce8f33f84af232c3edc912a81615175f
parent09b0070e876e11da0a5291106a115f66b548790b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16787 from jacobly0/as-srclocs

AstGen: create more `@as` with source locations

6 files changed, 526 insertions(+), 369 deletions(-)

src/AstGen.zig+393-348
...@@ -70,10 +70,10 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {...@@ -70,10 +70,10 @@ fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {
7070
71fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {71fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {
72 const fields = std.meta.fields(@TypeOf(extra));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 astgen.extra.items.len += fields.len;74 astgen.extra.items.len += fields.len;
75 setExtra(astgen, result, extra);75 setExtra(astgen, extra_index, extra);
76 return result;76 return extra_index;
77}77}
7878
79fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {79fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
...@@ -83,11 +83,12 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -83,11 +83,12 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
83 astgen.extra.items[i] = switch (field.type) {83 astgen.extra.items[i] = switch (field.type) {
84 u32 => @field(extra, field.name),84 u32 => @field(extra, field.name),
85 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),85 Zir.Inst.Ref => @intFromEnum(@field(extra, field.name)),
86 i32 => @as(u32, @bitCast(@field(extra, field.name))),86 i32,
87 Zir.Inst.Call.Flags => @as(u32, @bitCast(@field(extra, field.name))),87 Zir.Inst.Call.Flags,
88 Zir.Inst.BuiltinCall.Flags => @as(u32, @bitCast(@field(extra, field.name))),88 Zir.Inst.BuiltinCall.Flags,
89 Zir.Inst.SwitchBlock.Bits => @as(u32, @bitCast(@field(extra, field.name))),89 Zir.Inst.SwitchBlock.Bits,
90 Zir.Inst.FuncFancy.Bits => @as(u32, @bitCast(@field(extra, field.name))),90 Zir.Inst.FuncFancy.Bits,
91 => @bitCast(@field(extra, field.name)),
91 else => @compileError("bad field type"),92 else => @compileError("bad field type"),
92 };93 };
93 i += 1;94 i += 1;
...@@ -95,19 +96,17 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -95,19 +96,17 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
95}96}
9697
97fn reserveExtra(astgen: *AstGen, size: usize) Allocator.Error!u32 {98fn reserveExtra(astgen: *AstGen, size: usize) Allocator.Error!u32 {
98 const result = @as(u32, @intCast(astgen.extra.items.len));99 const extra_index: u32 = @intCast(astgen.extra.items.len);
99 try astgen.extra.resize(astgen.gpa, result + size);100 try astgen.extra.resize(astgen.gpa, extra_index + size);
100 return result;101 return extra_index;
101}102}
102103
103fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void {104fn appendRefs(astgen: *AstGen, refs: []const Zir.Inst.Ref) !void {
104 const coerced = @as([]const u32, @ptrCast(refs));105 return astgen.extra.appendSlice(astgen.gpa, @ptrCast(refs));
105 return astgen.extra.appendSlice(astgen.gpa, coerced);
106}106}
107107
108fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {108fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {
109 const coerced = @as([]const u32, @ptrCast(refs));109 astgen.extra.appendSliceAssumeCapacity(@ptrCast(refs));
110 astgen.extra.appendSliceAssumeCapacity(coerced);
111}110}
112111
113pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {112pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
...@@ -176,7 +175,7 @@ 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 @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len);175 @typeInfo(Zir.Inst.CompileErrors.Item).Struct.fields.len);
177176
178 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{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 });
181180
182 for (astgen.compile_errors.items) |item| {181 for (astgen.compile_errors.items) |item| {
...@@ -192,7 +191,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -192,7 +191,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
192 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len);191 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).Struct.fields.len);
193192
194 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{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 });
197196
198 var it = astgen.imports.iterator();197 var it = astgen.imports.iterator();
...@@ -1334,7 +1333,7 @@ fn fnProtoExpr(...@@ -1334,7 +1333,7 @@ fn fnProtoExpr(
1334 var param_gz = block_scope.makeSubBlock(scope);1333 var param_gz = block_scope.makeSubBlock(scope);
1335 defer param_gz.unstack();1334 defer param_gz.unstack();
1336 const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node);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 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);1337 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
1339 const main_tokens = tree.nodes.items(.main_token);1338 const main_tokens = tree.nodes.items(.main_token);
1340 const name_token = param.name_token orelse main_tokens[param_type_node];1339 const name_token = param.name_token orelse main_tokens[param_type_node];
...@@ -1468,7 +1467,7 @@ fn arrayInitExpr(...@@ -1468,7 +1467,7 @@ fn arrayInitExpr(
1468 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);1467 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);
1469 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{1468 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{
1470 .ty = array_type_inst,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 break :inst .{1472 break :inst .{
1474 .array = array_type_inst,1473 .array = array_type_inst,
...@@ -1552,7 +1551,7 @@ fn arrayInitExprRlNone(...@@ -1552,7 +1551,7 @@ fn arrayInitExprRlNone(
1552 const astgen = gz.astgen;1551 const astgen = gz.astgen;
15531552
1554 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{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 var extra_index = try reserveExtra(astgen, elements.len);1556 var extra_index = try reserveExtra(astgen, elements.len);
15581557
...@@ -1577,7 +1576,7 @@ fn arrayInitExprInner(...@@ -1577,7 +1576,7 @@ fn arrayInitExprInner(
15771576
1578 const len = elements.len + @intFromBool(array_ty_inst != .none);1577 const len = elements.len + @intFromBool(array_ty_inst != .none);
1579 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{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 var extra_index = try reserveExtra(astgen, len);1581 var extra_index = try reserveExtra(astgen, len);
1583 if (array_ty_inst != .none) {1582 if (array_ty_inst != .none) {
...@@ -1593,7 +1592,7 @@ fn arrayInitExprInner(...@@ -1593,7 +1592,7 @@ fn arrayInitExprInner(
1593 .tag = .elem_type_index,1592 .tag = .elem_type_index,
1594 .data = .{ .bin = .{1593 .data = .{ .bin = .{
1595 .lhs = array_ty_inst,1594 .lhs = array_ty_inst,
1596 .rhs = @as(Zir.Inst.Ref, @enumFromInt(i)),1595 .rhs = @enumFromInt(i),
1597 } },1596 } },
1598 });1597 });
1599 break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } };1598 break :ri ResultInfo{ .rl = .{ .coerced_ty = ty_expr } };
...@@ -1638,14 +1637,14 @@ fn arrayInitExprRlPtrInner(...@@ -1638,14 +1637,14 @@ fn arrayInitExprRlPtrInner(
1638 const astgen = gz.astgen;1637 const astgen = gz.astgen;
16391638
1640 const payload_index = try addExtra(astgen, Zir.Inst.Block{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 var extra_index = try reserveExtra(astgen, elements.len);1642 var extra_index = try reserveExtra(astgen, elements.len);
16441643
1645 for (elements, 0..) |elem_init, i| {1644 for (elements, 0..) |elem_init, i| {
1646 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{1645 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{
1647 .ptr = result_ptr,1646 .ptr = result_ptr,
1648 .index = @as(u32, @intCast(i)),1647 .index = @intCast(i),
1649 });1648 });
1650 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;1649 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;
1651 extra_index += 1;1650 extra_index += 1;
...@@ -1797,7 +1796,7 @@ fn structInitExprRlNone(...@@ -1797,7 +1796,7 @@ fn structInitExprRlNone(
1797 const tree = astgen.tree;1796 const tree = astgen.tree;
17981797
1799 const payload_index = try addExtra(astgen, Zir.Inst.StructInitAnon{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 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len;1801 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).Struct.fields.len;
1803 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);1802 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
...@@ -1855,7 +1854,7 @@ fn structInitExprRlPtrInner(...@@ -1855,7 +1854,7 @@ fn structInitExprRlPtrInner(
1855 const tree = astgen.tree;1854 const tree = astgen.tree;
18561855
1857 const payload_index = try addExtra(astgen, Zir.Inst.Block{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 var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len);1859 var extra_index = try reserveExtra(astgen, struct_init.ast.fields.len);
18611860
...@@ -1887,7 +1886,7 @@ fn structInitExprRlTy(...@@ -1887,7 +1886,7 @@ fn structInitExprRlTy(
1887 const tree = astgen.tree;1886 const tree = astgen.tree;
18881887
1889 const payload_index = try addExtra(astgen, Zir.Inst.StructInit{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 const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len;1891 const field_size = @typeInfo(Zir.Inst.StructInit.Item).Struct.fields.len;
1893 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);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,7 +2125,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
2126 }2125 }
21272126
2128 const operand = try reachableExpr(parent_gz, parent_scope, block_gz.break_result_info, rhs, node);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);
21302129
2131 try genDefers(parent_gz, scope, parent_scope, .normal_only);2130 try genDefers(parent_gz, scope, parent_scope, .normal_only);
21322131
...@@ -2373,8 +2372,8 @@ fn labeledBlockExpr(...@@ -2373,8 +2372,8 @@ fn labeledBlockExpr(
2373 try astgen.appendErrorTok(label_token, "unused block label", .{});2372 try astgen.appendErrorTok(label_token, "unused block label", .{});
2374 }2373 }
23752374
2376 const zir_datas = gz.astgen.instructions.items(.data);2375 const zir_datas = astgen.instructions.items(.data);
2377 const zir_tags = gz.astgen.instructions.items(.tag);2376 const zir_tags = astgen.instructions.items(.tag);
2378 const strat = ri.rl.strategy(&block_scope);2377 const strat = ri.rl.strategy(&block_scope);
2379 switch (strat.tag) {2378 switch (strat.tag) {
2380 .break_void => {2379 .break_void => {
...@@ -2396,6 +2395,10 @@ fn labeledBlockExpr(...@@ -2396,6 +2395,10 @@ fn labeledBlockExpr(
2396 // it as the break operand.2395 // it as the break operand.
2397 // This corresponds to similar code in `setCondBrPayloadElideBlockStorePtr`.2396 // This corresponds to similar code in `setCondBrPayloadElideBlockStorePtr`.
2398 if (block_scope.rl_ty_inst != .none) {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 for (block_scope.labeled_breaks.items) |br| {2402 for (block_scope.labeled_breaks.items) |br| {
2400 // We expect the `store_to_block_ptr` to be created between 1-3 instructions2403 // We expect the `store_to_block_ptr` to be created between 1-3 instructions
2401 // prior to the break.2404 // prior to the break.
...@@ -2404,12 +2407,28 @@ fn labeledBlockExpr(...@@ -2404,12 +2407,28 @@ fn labeledBlockExpr(
2404 if (zir_tags[search_index] == .store_to_block_ptr and2407 if (zir_tags[search_index] == .store_to_block_ptr and
2405 zir_datas[search_index].bin.lhs == block_scope.rl_ptr)2408 zir_datas[search_index].bin.lhs == block_scope.rl_ptr)
2406 {2409 {
2407 zir_tags[search_index] = .as;2410 const break_data = &zir_datas[br.br].@"break";
2408 zir_datas[search_index].bin = .{2411 const break_src: i32 = @bitCast(astgen.extra.items[
2409 .lhs = block_scope.rl_ty_inst,2412 break_data.payload_index +
2410 .rhs = zir_datas[br.br].@"break".operand,2413 std.meta.fieldIndex(Zir.Inst.Break, "operand_src_node").?
2411 };2414 ]);
2412 zir_datas[br.br].@"break".operand = indexToRef(search_index);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 break;2432 break;
2414 }2433 }
2415 } else unreachable;2434 } else unreachable;
...@@ -2530,19 +2549,21 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2530,19 +2549,21 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2530 // For some instructions, modify the zir data2549 // For some instructions, modify the zir data
2531 // so we can avoid a separate ensure_result_used instruction.2550 // so we can avoid a separate ensure_result_used instruction.
2532 .call, .field_call => {2551 .call, .field_call => {
2533 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;2552 const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2534 const slot = &gz.astgen.extra.items[extra_index];2553 comptime assert(std.meta.fieldIndex(Zir.Inst.Call, "flags") ==
2535 var flags = @as(Zir.Inst.Call.Flags, @bitCast(slot.*));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 flags.ensure_result_used = true;2558 flags.ensure_result_used = true;
2537 slot.* = @as(u32, @bitCast(flags));
2538 break :b true;2559 break :b true;
2539 },2560 },
2540 .builtin_call => {2561 .builtin_call => {
2541 const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;2562 const break_extra = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index;
2542 const slot = &gz.astgen.extra.items[extra_index];2563 const flags: *Zir.Inst.BuiltinCall.Flags = @ptrCast(&gz.astgen.extra.items[
2543 var flags = @as(Zir.Inst.BuiltinCall.Flags, @bitCast(slot.*));2564 break_extra + std.meta.fieldIndex(Zir.Inst.BuiltinCall, "flags").?
2565 ]);
2544 flags.ensure_result_used = true;2566 flags.ensure_result_used = true;
2545 slot.* = @as(u32, @bitCast(flags));
2546 break :b true;2567 break :b true;
2547 },2568 },
25482569
...@@ -2920,7 +2941,7 @@ fn genDefers(...@@ -2920,7 +2941,7 @@ fn genDefers(
2920 .index = defer_scope.index,2941 .index = defer_scope.index,
2921 .len = defer_scope.len,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 gz.astgen.instructions.appendAssumeCapacity(.{2945 gz.astgen.instructions.appendAssumeCapacity(.{
2925 .tag = .defer_err_code,2946 .tag = .defer_err_code,
2926 .data = .{ .defer_err_code = .{2947 .data = .{ .defer_err_code = .{
...@@ -2999,7 +3020,7 @@ fn deferStmt(...@@ -2999,7 +3020,7 @@ fn deferStmt(
2999 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {3020 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {
3000 try gz.addDbgBlockBegin();3021 try gz.addDbgBlockBegin();
3001 const ident_name = try gz.astgen.identAsString(payload_token);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 try gz.astgen.instructions.append(gz.astgen.gpa, .{3024 try gz.astgen.instructions.append(gz.astgen.gpa, .{
3004 .tag = .extended,3025 .tag = .extended,
3005 .data = .{ .extended = .{3026 .data = .{ .extended = .{
...@@ -3039,7 +3060,7 @@ fn deferStmt(...@@ -3039,7 +3060,7 @@ fn deferStmt(
3039 break :blk gz.astgen.countBodyLenAfterFixups(body) + refs;3060 break :blk gz.astgen.countBodyLenAfterFixups(body) + refs;
3040 };3061 };
30413062
3042 const index = @as(u32, @intCast(gz.astgen.extra.items.len));3063 const index: u32 = @intCast(gz.astgen.extra.items.len);
3043 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);3064 try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len);
3044 if (have_err_code) {3065 if (have_err_code) {
3045 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {3066 if (gz.astgen.ref_table.fetchRemove(remapped_err_code)) |kv| {
...@@ -3580,7 +3601,7 @@ fn ptrType(...@@ -3580,7 +3601,7 @@ fn ptrType(
3580 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));3601 gz.astgen.extra.appendAssumeCapacity(@intFromEnum(bit_end_ref));
3581 }3602 }
35823603
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 const result = indexToRef(new_index);3605 const result = indexToRef(new_index);
3585 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{3606 gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{
3586 .ptr_type = .{3607 .ptr_type = .{
...@@ -3671,7 +3692,7 @@ const WipMembers = struct {...@@ -3671,7 +3692,7 @@ const WipMembers = struct {
3671 const max_decl_size = 11;3692 const max_decl_size = 11;
36723693
3673 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 {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 const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32;3696 const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32;
3676 const field_bits_start = decls_start + decl_count * max_decl_size;3697 const field_bits_start = decls_start + decl_count * max_decl_size;
3677 const fields_start = field_bits_start + if (bits_per_field > 0) blk: {3698 const fields_start = field_bits_start + if (bits_per_field > 0) blk: {
...@@ -3726,7 +3747,7 @@ const WipMembers = struct {...@@ -3726,7 +3747,7 @@ const WipMembers = struct {
3726 fn appendToDeclSlice(self: *Self, data: []const u32) void {3747 fn appendToDeclSlice(self: *Self, data: []const u32) void {
3727 assert(self.decls_end + data.len <= self.field_bits_start);3748 assert(self.decls_end + data.len <= self.field_bits_start);
3728 @memcpy(self.payload.items[self.decls_end..][0..data.len], data);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 }
37313752
3732 fn appendToField(self: *Self, data: u32) void {3753 fn appendToField(self: *Self, data: u32) void {
...@@ -3739,14 +3760,14 @@ const WipMembers = struct {...@@ -3739,14 +3760,14 @@ const WipMembers = struct {
3739 const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32);3760 const empty_decl_slots = decls_per_u32 - (self.decl_index % decls_per_u32);
3740 if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) {3761 if (self.decl_index > 0 and empty_decl_slots < decls_per_u32) {
3741 const index = self.payload_top + self.decl_index / decls_per_u32;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 if (bits_per_field > 0) {3765 if (bits_per_field > 0) {
3745 const fields_per_u32 = 32 / bits_per_field;3766 const fields_per_u32 = 32 / bits_per_field;
3746 const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32);3767 const empty_field_slots = fields_per_u32 - (self.field_index % fields_per_u32);
3747 if (self.field_index > 0 and empty_field_slots < fields_per_u32) {3768 if (self.field_index > 0 and empty_field_slots < fields_per_u32) {
3748 const index = self.field_bits_start + self.field_index / fields_per_u32;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,7 +3929,7 @@ fn fnDecl(
3908 var param_gz = decl_gz.makeSubBlock(scope);3929 var param_gz = decl_gz.makeSubBlock(scope);
3909 defer param_gz.unstack();3930 defer param_gz.unstack();
3910 const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node);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 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);3933 _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node);
39133934
3914 const main_tokens = tree.nodes.items(.main_token);3935 const main_tokens = tree.nodes.items(.main_token);
...@@ -4122,9 +4143,8 @@ fn fnDecl(...@@ -4122,9 +4143,8 @@ fn fnDecl(
4122 try decl_gz.setBlockBody(block_inst);4143 try decl_gz.setBlockBody(block_inst);
41234144
4124 {4145 {
4125 const contents_hash = std.zig.hashSrc(tree.getNodeSource(decl_node));4146 const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(decl_node));
4126 const casted = @as([4]u32, @bitCast(contents_hash));4147 wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash));
4127 wip_members.appendToDeclSlice(&casted);
4128 }4148 }
4129 {4149 {
4130 const line_delta = decl_gz.decl_line - gz.decl_line;4150 const line_delta = decl_gz.decl_line - gz.decl_line;
...@@ -4273,9 +4293,8 @@ fn globalVarDecl(...@@ -4273,9 +4293,8 @@ fn globalVarDecl(
4273 try block_scope.setBlockBody(block_inst);4293 try block_scope.setBlockBody(block_inst);
42744294
4275 {4295 {
4276 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4296 const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node));
4277 const casted = @as([4]u32, @bitCast(contents_hash));4297 wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash));
4278 wip_members.appendToDeclSlice(&casted);
4279 }4298 }
4280 {4299 {
4281 const line_delta = block_scope.decl_line - gz.decl_line;4300 const line_delta = block_scope.decl_line - gz.decl_line;
...@@ -4328,9 +4347,8 @@ fn comptimeDecl(...@@ -4328,9 +4347,8 @@ fn comptimeDecl(
4328 try decl_block.setBlockBody(block_inst);4347 try decl_block.setBlockBody(block_inst);
43294348
4330 {4349 {
4331 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4350 const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node));
4332 const casted = @as([4]u32, @bitCast(contents_hash));4351 wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash));
4333 wip_members.appendToDeclSlice(&casted);
4334 }4352 }
4335 {4353 {
4336 const line_delta = decl_block.decl_line - gz.decl_line;4354 const line_delta = decl_block.decl_line - gz.decl_line;
...@@ -4380,9 +4398,8 @@ fn usingnamespaceDecl(...@@ -4380,9 +4398,8 @@ fn usingnamespaceDecl(
4380 try decl_block.setBlockBody(block_inst);4398 try decl_block.setBlockBody(block_inst);
43814399
4382 {4400 {
4383 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4401 const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node));
4384 const casted = @as([4]u32, @bitCast(contents_hash));4402 wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash));
4385 wip_members.appendToDeclSlice(&casted);
4386 }4403 }
4387 {4404 {
4388 const line_delta = decl_block.decl_line - gz.decl_line;4405 const line_delta = decl_block.decl_line - gz.decl_line;
...@@ -4567,9 +4584,8 @@ fn testDecl(...@@ -4567,9 +4584,8 @@ fn testDecl(
4567 try decl_block.setBlockBody(block_inst);4584 try decl_block.setBlockBody(block_inst);
45684585
4569 {4586 {
4570 const contents_hash = std.zig.hashSrc(tree.getNodeSource(node));4587 const contents_hash align(@alignOf(u32)) = std.zig.hashSrc(tree.getNodeSource(node));
4571 const casted = @as([4]u32, @bitCast(contents_hash));4588 wip_members.appendToDeclSlice(std.mem.bytesAsSlice(u32, &contents_hash));
4572 wip_members.appendToDeclSlice(&casted);
4573 }4589 }
4574 {4590 {
4575 const line_delta = decl_block.decl_line - gz.decl_line;4591 const line_delta = decl_block.decl_line - gz.decl_line;
...@@ -4668,7 +4684,7 @@ fn structDeclInner(...@@ -4668,7 +4684,7 @@ fn structDeclInner(
4668 };4684 };
46694685
4670 const decl_count = try astgen.scanDecls(&namespace, container_decl.ast.members);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);
46724688
4673 const bits_per_field = 4;4689 const bits_per_field = 4;
4674 const max_field_size = 5;4690 const max_field_size = 5;
...@@ -4781,7 +4797,7 @@ fn structDeclInner(...@@ -4781,7 +4797,7 @@ fn structDeclInner(
4781 const old_scratch_len = astgen.scratch.items.len;4797 const old_scratch_len = astgen.scratch.items.len;
4782 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4798 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4783 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);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 block_scope.instructions.items.len = block_scope.instructions_top;4801 block_scope.instructions.items.len = block_scope.instructions_top;
4786 } else {4802 } else {
4787 wip_members.appendToField(@intFromEnum(field_type));4803 wip_members.appendToField(@intFromEnum(field_type));
...@@ -4799,7 +4815,7 @@ fn structDeclInner(...@@ -4799,7 +4815,7 @@ fn structDeclInner(
4799 const old_scratch_len = astgen.scratch.items.len;4815 const old_scratch_len = astgen.scratch.items.len;
4800 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4816 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4801 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);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 block_scope.instructions.items.len = block_scope.instructions_top;4819 block_scope.instructions.items.len = block_scope.instructions_top;
4804 }4820 }
48054821
...@@ -4814,7 +4830,7 @@ fn structDeclInner(...@@ -4814,7 +4830,7 @@ fn structDeclInner(
4814 const old_scratch_len = astgen.scratch.items.len;4830 const old_scratch_len = astgen.scratch.items.len;
4815 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));4831 try astgen.scratch.ensureUnusedCapacity(gpa, countBodyLenAfterFixups(astgen, body));
4816 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);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 block_scope.instructions.items.len = block_scope.instructions_top;4834 block_scope.instructions.items.len = block_scope.instructions_top;
4819 } else if (member.comptime_token) |comptime_token| {4835 } else if (member.comptime_token) |comptime_token| {
4820 return astgen.failTok(comptime_token, "comptime field without default initialization value", .{});4836 return astgen.failTok(comptime_token, "comptime field without default initialization value", .{});
...@@ -4827,7 +4843,7 @@ fn structDeclInner(...@@ -4827,7 +4843,7 @@ fn structDeclInner(
4827 .fields_len = field_count,4843 .fields_len = field_count,
4828 .decls_len = decl_count,4844 .decls_len = decl_count,
4829 .backing_int_ref = backing_int_ref,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 .known_non_opv = known_non_opv,4847 .known_non_opv = known_non_opv,
4832 .known_comptime_only = known_comptime_only,4848 .known_comptime_only = known_comptime_only,
4833 .is_tuple = is_tuple,4849 .is_tuple = is_tuple,
...@@ -4887,7 +4903,7 @@ fn unionDeclInner(...@@ -4887,7 +4903,7 @@ fn unionDeclInner(
4887 defer block_scope.unstack();4903 defer block_scope.unstack();
48884904
4889 const decl_count = try astgen.scanDecls(&namespace, members);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);
48914907
4892 if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) {4908 if (layout != .Auto and (auto_enum_tok != null or arg_node != 0)) {
4893 const layout_str = if (layout == .Extern) "extern" else "packed";4909 const layout_str = if (layout == .Extern) "extern" else "packed";
...@@ -5182,7 +5198,7 @@ fn containerDecl(...@@ -5182,7 +5198,7 @@ fn containerDecl(
51825198
5183 const bits_per_field = 1;5199 const bits_per_field = 1;
5184 const max_field_size = 3;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 defer wip_members.deinit();5202 defer wip_members.deinit();
51875203
5188 for (container_decl.ast.members) |member_node| {5204 for (container_decl.ast.members) |member_node| {
...@@ -5240,8 +5256,8 @@ fn containerDecl(...@@ -5240,8 +5256,8 @@ fn containerDecl(
5240 .nonexhaustive = nonexhaustive,5256 .nonexhaustive = nonexhaustive,
5241 .tag_type = arg_inst,5257 .tag_type = arg_inst,
5242 .body_len = body_len,5258 .body_len = body_len,
5243 .fields_len = @as(u32, @intCast(counts.total_fields)),5259 .fields_len = @intCast(counts.total_fields),
5244 .decls_len = @as(u32, @intCast(counts.decls)),5260 .decls_len = @intCast(counts.decls),
5245 });5261 });
52465262
5247 wip_members.finishBits(bits_per_field);5263 wip_members.finishBits(bits_per_field);
...@@ -5431,7 +5447,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi...@@ -5431,7 +5447,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
5431 }5447 }
54325448
5433 setExtra(astgen, payload_index, Zir.Inst.ErrorSetDecl{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 const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index);5452 const result = try gz.addPlNodePayloadIndex(.error_set_decl, node, payload_index);
5437 return rvalue(gz, ri, result, node);5453 return rvalue(gz, ri, result, node);
...@@ -5657,7 +5673,7 @@ fn finishThenElseBlock(...@@ -5657,7 +5673,7 @@ fn finishThenElseBlock(
5657 0;5673 0;
56585674
5659 if (strat.elide_store_to_block_ptr_instructions) {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 } else {5677 } else {
5662 try setCondBrPayload(condbr, cond, then_scope, then_break, else_scope, else_break);5678 try setCondBrPayload(condbr, cond, then_scope, then_break, else_scope, else_break);
5663 }5679 }
...@@ -6082,8 +6098,10 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -6082,8 +6098,10 @@ fn setCondBrPayloadElideBlockStorePtr(
6082 cond: Zir.Inst.Ref,6098 cond: Zir.Inst.Ref,
6083 then_scope: *GenZir,6099 then_scope: *GenZir,
6084 then_break: Zir.Inst.Index,6100 then_break: Zir.Inst.Index,
6101 then_src_node: Ast.Node.Index,
6085 else_scope: *GenZir,6102 else_scope: *GenZir,
6086 else_break: Zir.Inst.Index,6103 else_break: Zir.Inst.Index,
6104 else_src_node: Ast.Node.Index,
6087 block_ptr: Zir.Inst.Ref,6105 block_ptr: Zir.Inst.Ref,
6088) !void {6106) !void {
6089 defer then_scope.unstack();6107 defer then_scope.unstack();
...@@ -6097,39 +6115,36 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -6097,39 +6115,36 @@ fn setCondBrPayloadElideBlockStorePtr(
6097 const else_body_len = astgen.countBodyLenAfterFixups(else_body) + @intFromBool(has_else_break);6115 const else_body_len = astgen.countBodyLenAfterFixups(else_body) + @intFromBool(has_else_break);
6098 try astgen.extra.ensureUnusedCapacity(6116 try astgen.extra.ensureUnusedCapacity(
6099 astgen.gpa,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 );
61026121
6103 const zir_tags = astgen.instructions.items(.tag);6122 const zir_tags = astgen.instructions.items(.tag);
6104 const zir_datas = astgen.instructions.items(.data);6123 const zir_datas = astgen.instructions.items(.data);
61056124
6106 const condbr_pl = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{6125 const condbr_extra = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{
6107 .condition = cond,6126 .condition = cond,
6108 .then_body_len = then_body_len,6127 .then_body_len = then_body_len,
6109 .else_body_len = else_body_len,6128 .else_body_len = else_body_len,
6110 });6129 });
6111 zir_datas[condbr].pl_node.payload_index = condbr_pl;6130 zir_datas[condbr].pl_node.payload_index = condbr_extra;
6112 const then_body_len_index = condbr_pl + 1;
6113 const else_body_len_index = condbr_pl + 2;
61146131
6115 // The break instructions need to have their operands coerced if the6132 // The break instructions need to have their operands coerced if the
6116 // switch's result location is a `ty`. In this case we overwrite the6133 // switch's result location is a `ty`. In this case we overwrite the
6117 // `store_to_block_ptr` instruction with an `as` instruction and repurpose6134 // `store_to_block_ptr` instruction with an `as` instruction and repurpose
6118 // it as the break operand.6135 // it as the break operand.
6119 // This corresponds to similar code in `labeledBlockExpr`.6136 // This corresponds to similar code in `labeledBlockExpr`.
6137 var then_as_inst: Zir.Inst.Index = 0;
6120 for (then_body) |src_inst| {6138 for (then_body) |src_inst| {
6121 if (zir_tags[src_inst] == .store_to_block_ptr and6139 if (zir_tags[src_inst] == .store_to_block_ptr and
6122 zir_datas[src_inst].bin.lhs == block_ptr)6140 zir_datas[src_inst].bin.lhs == block_ptr)
6123 {6141 {
6124 if (then_scope.rl_ty_inst != .none and has_then_break) {6142 if (then_scope.rl_ty_inst != .none and has_then_break) {
6125 zir_tags[src_inst] = .as;6143 then_as_inst = src_inst;
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);
6131 } else {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 continue;6148 continue;
6134 }6149 }
6135 }6150 }
...@@ -6137,25 +6152,47 @@ fn setCondBrPayloadElideBlockStorePtr(...@@ -6137,25 +6152,47 @@ fn setCondBrPayloadElideBlockStorePtr(
6137 }6152 }
6138 if (has_then_break) astgen.extra.appendAssumeCapacity(then_break);6153 if (has_then_break) astgen.extra.appendAssumeCapacity(then_break);
61396154
6155 var else_as_inst: Zir.Inst.Index = 0;
6140 for (else_body) |src_inst| {6156 for (else_body) |src_inst| {
6141 if (zir_tags[src_inst] == .store_to_block_ptr and6157 if (zir_tags[src_inst] == .store_to_block_ptr and
6142 zir_datas[src_inst].bin.lhs == block_ptr)6158 zir_datas[src_inst].bin.lhs == block_ptr)
6143 {6159 {
6144 if (else_scope.rl_ty_inst != .none and has_else_break) {6160 if (else_scope.rl_ty_inst != .none and has_else_break) {
6145 zir_tags[src_inst] = .as;6161 else_as_inst = src_inst;
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);
6151 } else {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 continue;6166 continue;
6154 }6167 }
6155 }6168 }
6156 appendPossiblyRefdBodyInst(astgen, &astgen.extra, src_inst);6169 appendPossiblyRefdBodyInst(astgen, &astgen.extra, src_inst);
6157 }6170 }
6158 if (has_else_break) astgen.extra.appendAssumeCapacity(else_break);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}
61606197
6161fn whileExpr(6198fn whileExpr(
...@@ -6313,10 +6350,10 @@ fn whileExpr(...@@ -6313,10 +6350,10 @@ fn whileExpr(
6313 loop_scope.break_block = loop_block;6350 loop_scope.break_block = loop_block;
6314 loop_scope.continue_block = continue_block;6351 loop_scope.continue_block = continue_block;
6315 if (while_full.label_token) |label_token| {6352 if (while_full.label_token) |label_token| {
6316 loop_scope.label = @as(?GenZir.Label, GenZir.Label{6353 loop_scope.label = .{
6317 .token = label_token,6354 .token = label_token,
6318 .block_inst = loop_block,6355 .block_inst = loop_block,
6319 });6356 };
6320 }6357 }
63216358
6322 // done adding instructions to loop_scope, can now stack then_scope6359 // done adding instructions to loop_scope, can now stack then_scope
...@@ -6929,7 +6966,7 @@ fn switchExpr(...@@ -6929,7 +6966,7 @@ fn switchExpr(
69296966
6930 // If any prong has an inline tag capture, allocate a shared dummy instruction for it6967 // If any prong has an inline tag capture, allocate a shared dummy instruction for it
6931 const tag_inst = if (any_has_tag_capture) tag_inst: {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 try astgen.instructions.append(astgen.gpa, .{6970 try astgen.instructions.append(astgen.gpa, .{
6934 .tag = .extended,6971 .tag = .extended,
6935 .data = .{ .extended = .{6972 .data = .{ .extended = .{
...@@ -7022,7 +7059,7 @@ fn switchExpr(...@@ -7022,7 +7059,7 @@ fn switchExpr(
7022 break :blk &tag_scope.base;7059 break :blk &tag_scope.base;
7023 };7060 };
70247061
7025 const header_index = @as(u32, @intCast(payloads.items.len));7062 const header_index: u32 = @intCast(payloads.items.len);
7026 const body_len_index = if (is_multi_case) blk: {7063 const body_len_index = if (is_multi_case) blk: {
7027 payloads.items[multi_case_table + multi_case_index] = header_index;7064 payloads.items[multi_case_table + multi_case_index] = header_index;
7028 multi_case_index += 1;7065 multi_case_index += 1;
...@@ -7112,12 +7149,12 @@ fn switchExpr(...@@ -7112,12 +7149,12 @@ fn switchExpr(
7112 };7149 };
7113 const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice);7150 const body_len = refs_len + astgen.countBodyLenAfterFixups(case_slice);
7114 try payloads.ensureUnusedCapacity(gpa, body_len);7151 try payloads.ensureUnusedCapacity(gpa, body_len);
7115 payloads.items[body_len_index] = @as(u32, @bitCast(Zir.Inst.SwitchBlock.ProngInfo{7152 payloads.items[body_len_index] = @bitCast(Zir.Inst.SwitchBlock.ProngInfo{
7116 .body_len = @as(u28, @intCast(body_len)),7153 .body_len = @intCast(body_len),
7117 .capture = capture,7154 .capture = capture,
7118 .is_inline = case.inline_token != null,7155 .is_inline = case.inline_token != null,
7119 .has_tag_capture = has_tag_capture,7156 .has_tag_capture = has_tag_capture,
7120 }));7157 });
7121 if (astgen.ref_table.fetchRemove(switch_block)) |kv| {7158 if (astgen.ref_table.fetchRemove(switch_block)) |kv| {
7122 appendPossiblyRefdBodyInst(astgen, payloads, kv.value);7159 appendPossiblyRefdBodyInst(astgen, payloads, kv.value);
7123 }7160 }
...@@ -7135,7 +7172,8 @@ fn switchExpr(...@@ -7135,7 +7172,8 @@ fn switchExpr(
7135 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.SwitchBlock).Struct.fields.len +7172 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.SwitchBlock).Struct.fields.len +
7136 @intFromBool(multi_cases_len != 0) +7173 @intFromBool(multi_cases_len != 0) +
7137 @intFromBool(any_has_tag_capture) +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);
71397177
7140 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{7178 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.SwitchBlock{
7141 .operand = raw_operand,7179 .operand = raw_operand,
...@@ -7144,7 +7182,7 @@ fn switchExpr(...@@ -7144,7 +7182,7 @@ fn switchExpr(
7144 .has_else = special_prong == .@"else",7182 .has_else = special_prong == .@"else",
7145 .has_under = special_prong == .under,7183 .has_under = special_prong == .under,
7146 .any_has_tag_capture = any_has_tag_capture,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 });
71507188
...@@ -7162,82 +7200,108 @@ fn switchExpr(...@@ -7162,82 +7200,108 @@ fn switchExpr(
7162 zir_datas[switch_block].pl_node.payload_index = payload_index;7200 zir_datas[switch_block].pl_node.payload_index = payload_index;
71637201
7164 const strat = ri.rl.strategy(&block_scope);7202 const strat = ri.rl.strategy(&block_scope);
7165 for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| {7203 inline for (.{ .body, .breaks }) |pass| {
7166 var body_len_index = start_index;7204 for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| {
7167 var end_index = start_index;7205 var body_len_index = start_index;
7168 const table_index = case_table_start + i;7206 var end_index = start_index;
7169 if (table_index < scalar_case_table) {7207 const table_index = case_table_start + i;
7170 end_index += 1;7208 if (table_index < scalar_case_table) {
7171 } else if (table_index < multi_case_table) {7209 end_index += 1;
7172 body_len_index += 1;7210 } else if (table_index < multi_case_table) {
7173 end_index += 2;7211 body_len_index += 1;
7174 } else {7212 end_index += 2;
7175 body_len_index += 2;7213 } else {
7176 const items_len = payloads.items[start_index];7214 body_len_index += 2;
7177 const ranges_len = payloads.items[start_index + 1];7215 const items_len = payloads.items[start_index];
7178 end_index += 3 + items_len + 2 * ranges_len;7216 const ranges_len = payloads.items[start_index + 1];
7179 }7217 end_index += 3 + items_len + 2 * ranges_len;
71807218 }
7181 const body_len = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(payloads.items[body_len_index])).body_len;7219
7182 end_index += body_len;7220 const prong_info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(payloads.items[body_len_index]);
71837221 end_index += prong_info.body_len;
7184 switch (strat.tag) {7222
7185 .break_operand => blk: {7223 switch (strat.tag) {
7186 // Switch expressions return `true` for `nodeMayNeedMemoryLocation` thus7224 .break_operand => blk: {
7187 // `elide_store_to_block_ptr_instructions` will either be true,7225 // Switch expressions return `true` for `nodeMayNeedMemoryLocation` thus
7188 // or all prongs are noreturn.7226 // `elide_store_to_block_ptr_instructions` will either be true,
7189 if (!strat.elide_store_to_block_ptr_instructions)7227 // or all prongs are noreturn.
7190 break :blk;7228 if (!strat.elide_store_to_block_ptr_instructions)
71917229 break :blk;
7192 // There will necessarily be a store_to_block_ptr for7230
7193 // all prongs, except for prongs that ended with a noreturn instruction.7231 // There will necessarily be a store_to_block_ptr for
7194 // Elide all the `store_to_block_ptr` instructions.7232 // all prongs, except for prongs that ended with a noreturn instruction.
71957233 // Elide all the `store_to_block_ptr` instructions.
7196 // The break instructions need to have their operands coerced if the7234
7197 // switch's result location is a `ty`. In this case we overwrite the7235 // The break instructions need to have their operands coerced if the
7198 // `store_to_block_ptr` instruction with an `as` instruction and repurpose7236 // switch's result location is a `ty`. In this case we overwrite the
7199 // it as the break operand.7237 // `store_to_block_ptr` instruction with an `as` instruction and repurpose
7200 if (body_len < 2)7238 // it as the break operand.
7201 break :blk;7239 if (prong_info.body_len < 2)
72027240 break :blk;
7203 var store_index = end_index - 2;7241
7204 while (true) : (store_index -= 1) switch (zir_tags[payloads.items[store_index]]) {7242 var store_index = end_index - 2;
7205 .dbg_block_end, .dbg_block_begin, .dbg_stmt, .dbg_var_val, .dbg_var_ptr => {},7243 while (true) : (store_index -= 1) switch (zir_tags[payloads.items[store_index]]) {
7206 else => break,7244 .dbg_block_end, .dbg_block_begin, .dbg_stmt, .dbg_var_val, .dbg_var_ptr => {},
7207 };7245 else => break,
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,
7218 };7246 };
7219 zir_datas[break_inst].@"break".operand = indexToRef(store_inst);7247 const store_inst = payloads.items[store_index];
7220 } else {7248 if (zir_tags[store_inst] != .store_to_block_ptr or
7221 payloads.items[body_len_index] -= 1;7249 zir_datas[store_inst].bin.lhs != block_scope.rl_ptr)
7222 astgen.extra.appendSliceAssumeCapacity(payloads.items[start_index .. end_index - 2]);7250 break :blk;
7223 astgen.extra.appendAssumeCapacity(break_inst);7251 const break_inst = payloads.items[end_index - 1];
7224 continue;7252 if (block_scope.rl_ty_inst != .none) {
7225 }7253 if (pass == .breaks) {
7226 },7254 const break_data = &zir_datas[break_inst].@"break";
7227 .break_void => {7255 const break_src: i32 = @bitCast(astgen.extra.items[
7228 assert(!strat.elide_store_to_block_ptr_instructions);7256 break_data.payload_index +
7229 const last_inst = payloads.items[end_index - 1];7257 std.meta.fieldIndex(Zir.Inst.Break, "operand_src_node").?
7230 if (zir_tags[last_inst] == .@"break") {7258 ]);
7231 const inst_data = zir_datas[last_inst].@"break";7259 if (break_src == Zir.Inst.Break.no_src_node) {
7232 const block_inst = astgen.extra.items[inst_data.payload_index];7260 zir_tags[store_inst] = .as;
7233 if (block_inst == switch_block) {7261 zir_datas[store_inst].bin = .{
7234 zir_datas[last_inst].@"break".operand = .void_value;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 }7287 },
7237 },7288 .break_void => if (pass == .breaks) {
7238 }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 }
72397301
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 }
72427306
7243 const block_ref = indexToRef(switch_block);7307 const block_ref = indexToRef(switch_block);
...@@ -7403,7 +7467,7 @@ fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 {...@@ -7403,7 +7467,7 @@ fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 {
7403 };7467 };
74047468
7405 if (x != 0) x = try std.math.mul(u16, x, 10);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 }
74087472
7409 return x;7473 return x;
...@@ -7617,7 +7681,7 @@ fn tunnelThroughClosure(...@@ -7617,7 +7681,7 @@ fn tunnelThroughClosure(
7617 .src_tok = ns.?.declaring_gz.?.tokenIndexToRelative(token),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 }
76227686
7623 // Add an instruction to get the value from the closure into7687 // 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,7 +7761,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
7697 const gpa = astgen.gpa;7761 const gpa = astgen.gpa;
7698 var big_int = try std.math.big.int.Managed.init(gpa);7762 var big_int = try std.math.big.int.Managed.init(gpa);
7699 defer big_int.deinit();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 big_int.setString(@intFromEnum(base), bytes[prefix_offset..]) catch |err| switch (err) {7765 big_int.setString(@intFromEnum(base), bytes[prefix_offset..]) catch |err| switch (err) {
7702 error.InvalidCharacter => unreachable, // caught in `parseNumberLiteral`7766 error.InvalidCharacter => unreachable, // caught in `parseNumberLiteral`
7703 error.InvalidBase => unreachable, // we only pass 16, 8, 2, see above7767 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,7 +7782,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
7718 };7782 };
7719 // If the value fits into a f64 without losing any precision, store it that way.7783 // If the value fits into a f64 without losing any precision, store it that way.
7720 @setFloatMode(.Strict);7784 @setFloatMode(.Strict);
7721 const smaller_float = @as(f64, @floatCast(float_number));7785 const smaller_float: f64 = @floatCast(float_number);
7722 const bigger_again: f128 = smaller_float;7786 const bigger_again: f128 = smaller_float;
7723 if (bigger_again == float_number) {7787 if (bigger_again == float_number) {
7724 const result = try gz.addFloat(smaller_float);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,12 +7790,12 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
7726 }7790 }
7727 // We need to use 128 bits. Break the float into 4 u32 values so we can7791 // We need to use 128 bits. Break the float into 4 u32 values so we can
7728 // put it into the `extra` array.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 const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{7794 const result = try gz.addPlNode(.float128, node, Zir.Inst.Float128{
7731 .piece0 = @as(u32, @truncate(int_bits)),7795 .piece0 = @truncate(int_bits),
7732 .piece1 = @as(u32, @truncate(int_bits >> 32)),7796 .piece1 = @truncate(int_bits >> 32),
7733 .piece2 = @as(u32, @truncate(int_bits >> 64)),7797 .piece2 = @truncate(int_bits >> 64),
7734 .piece3 = @as(u32, @truncate(int_bits >> 96)),7798 .piece3 = @truncate(int_bits >> 96),
7735 });7799 });
7736 return rvalue(gz, ri, result, source_node);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,22 +7821,22 @@ fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token
7757 });7821 });
7758 },7822 },
7759 .digit_after_base => return astgen.failTok(token, "expected a digit after base prefix", .{}),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", .{}),7824 .upper_case_base => |i| return astgen.failOff(token, @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", .{}),7825 .invalid_float_base => |i| return astgen.failOff(token, @intCast(i), "invalid base for float literal", .{}),
7762 .repeated_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "repeated digit separator", .{}),7826 .repeated_underscore => |i| return astgen.failOff(token, @intCast(i), "repeated digit separator", .{}),
7763 .invalid_underscore_after_special => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before digit separator", .{}),7827 .invalid_underscore_after_special => |i| return astgen.failOff(token, @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) }),7828 .invalid_digit => |info| return astgen.failOff(token, @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]}),7829 .invalid_digit_exponent => |i| return astgen.failOff(token, @intCast(i), "invalid digit '{c}' in exponent", .{bytes[i]}),
7766 .duplicate_exponent => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "duplicate exponent", .{}),7830 .duplicate_exponent => |i| return astgen.failOff(token, @intCast(i), "duplicate exponent", .{}),
7767 .exponent_after_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "expected digit before exponent", .{}),7831 .exponent_after_underscore => |i| return astgen.failOff(token, @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]}),7832 .special_after_underscore => |i| return astgen.failOff(token, @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]}),7833 .trailing_special => |i| return astgen.failOff(token, @intCast(i), "expected digit after '{c}'", .{bytes[i - 1]}),
7770 .trailing_underscore => |i| return astgen.failOff(token, @as(u32, @intCast(i)), "trailing digit separator", .{}),7834 .trailing_underscore => |i| return astgen.failOff(token, @intCast(i), "trailing digit separator", .{}),
7771 .duplicate_period => unreachable, // Validated by tokenizer7835 .duplicate_period => unreachable, // Validated by tokenizer
7772 .invalid_character => unreachable, // Validated by tokenizer7836 .invalid_character => unreachable, // Validated by tokenizer
7773 .invalid_exponent_sign => |i| {7837 .invalid_exponent_sign => |i| {
7774 assert(bytes.len >= 2 and bytes[0] == '0' and bytes[1] == 'x'); // Validated by tokenizer7838 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,7 +7903,7 @@ fn asmExpr(
7839 if (output_type_bits != 0) {7903 if (output_type_bits != 0) {
7840 return astgen.failNode(output_node, "inline assembly allows up to one output value", .{});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 const out_type_node = node_datas[output_node].lhs;7907 const out_type_node = node_datas[output_node].lhs;
7844 const out_type_inst = try typeExpr(gz, scope, out_type_node);7908 const out_type_inst = try typeExpr(gz, scope, out_type_node);
7845 outputs[i] = .{7909 outputs[i] = .{
...@@ -8062,7 +8126,7 @@ fn ptrCast(...@@ -8062,7 +8126,7 @@ fn ptrCast(
8062 node = node_datas[node].lhs;8126 node = node_datas[node].lhs;
8063 }8127 }
80648128
8065 const flags_i = @as(u5, @bitCast(flags));8129 const flags_i: u5 = @bitCast(flags);
8066 assert(flags_i != 0);8130 assert(flags_i != 0);
80678131
8068 const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true };8132 const ptr_only: Zir.Inst.FullPtrCastFlags = .{ .ptr_cast = true };
...@@ -8149,8 +8213,8 @@ fn typeOf(...@@ -8149,8 +8213,8 @@ fn typeOf(
8149 const body = typeof_scope.instructionsSlice();8213 const body = typeof_scope.instructionsSlice();
8150 const body_len = astgen.countBodyLenAfterFixups(body);8214 const body_len = astgen.countBodyLenAfterFixups(body);
8151 astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{8215 astgen.setExtra(payload_index, Zir.Inst.TypeOfPeer{
8152 .body_len = @as(u32, @intCast(body_len)),8216 .body_len = @intCast(body_len),
8153 .body_index = @as(u32, @intCast(astgen.extra.items.len)),8217 .body_index = @intCast(astgen.extra.items.len),
8154 .src_node = gz.nodeIndexToRelative(node),8218 .src_node = gz.nodeIndexToRelative(node),
8155 });8219 });
8156 try astgen.extra.ensureUnusedCapacity(gpa, body_len);8220 try astgen.extra.ensureUnusedCapacity(gpa, body_len);
...@@ -8509,7 +8573,7 @@ fn builtinCall(...@@ -8509,7 +8573,7 @@ fn builtinCall(
8509 .node = gz.nodeIndexToRelative(node),8573 .node = gz.nodeIndexToRelative(node),
8510 .operand = operand,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 gz.astgen.instructions.appendAssumeCapacity(.{8577 gz.astgen.instructions.appendAssumeCapacity(.{
8514 .tag = .extended,8578 .tag = .extended,
8515 .data = .{ .extended = .{8579 .data = .{ .extended = .{
...@@ -9164,7 +9228,7 @@ fn callExpr(...@@ -9164,7 +9228,7 @@ fn callExpr(
9164 }9228 }
9165 assert(node != 0);9229 assert(node != 0);
91669230
9167 const call_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));9231 const call_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
9168 const call_inst = Zir.indexToRef(call_index);9232 const call_inst = Zir.indexToRef(call_index);
9169 try gz.astgen.instructions.append(astgen.gpa, undefined);9233 try gz.astgen.instructions.append(astgen.gpa, undefined);
9170 try gz.instructions.append(astgen.gpa, call_index);9234 try gz.instructions.append(astgen.gpa, call_index);
...@@ -9188,7 +9252,7 @@ fn callExpr(...@@ -9188,7 +9252,7 @@ fn callExpr(
9188 try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body));9252 try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body));
9189 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);9253 appendBodyWithFixupsArrayList(astgen, &astgen.scratch, body);
91909254
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 scratch_index += 1;9256 scratch_index += 1;
9193 }9257 }
91949258
...@@ -9206,8 +9270,8 @@ fn callExpr(...@@ -9206,8 +9270,8 @@ fn callExpr(
9206 .callee = callee_obj,9270 .callee = callee_obj,
9207 .flags = .{9271 .flags = .{
9208 .pop_error_return_trace = !propagate_error_trace,9272 .pop_error_return_trace = !propagate_error_trace,
9209 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),9273 .packed_modifier = @intCast(@intFromEnum(modifier)),
9210 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),9274 .args_len = @intCast(call.ast.params.len),
9211 },9275 },
9212 });9276 });
9213 if (call.ast.params.len != 0) {9277 if (call.ast.params.len != 0) {
...@@ -9227,8 +9291,8 @@ fn callExpr(...@@ -9227,8 +9291,8 @@ fn callExpr(
9227 .field_name_start = callee_field.field_name_start,9291 .field_name_start = callee_field.field_name_start,
9228 .flags = .{9292 .flags = .{
9229 .pop_error_return_trace = !propagate_error_trace,9293 .pop_error_return_trace = !propagate_error_trace,
9230 .packed_modifier = @as(Zir.Inst.Call.Flags.PackedModifier, @intCast(@intFromEnum(modifier))),9294 .packed_modifier = @intCast(@intFromEnum(modifier)),
9231 .args_len = @as(Zir.Inst.Call.Flags.PackedArgsLen, @intCast(call.ast.params.len)),9295 .args_len = @intCast(call.ast.params.len),
9232 },9296 },
9233 });9297 });
9234 if (call.ast.params.len != 0) {9298 if (call.ast.params.len != 0) {
...@@ -10703,14 +10767,14 @@ fn appendErrorNodeNotes(...@@ -10703,14 +10767,14 @@ fn appendErrorNodeNotes(
10703) Allocator.Error!void {10767) Allocator.Error!void {
10704 @setCold(true);10768 @setCold(true);
10705 const string_bytes = &astgen.string_bytes;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 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10771 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10708 const notes_index: u32 = if (notes.len != 0) blk: {10772 const notes_index: u32 = if (notes.len != 0) blk: {
10709 const notes_start = astgen.extra.items.len;10773 const notes_start = astgen.extra.items.len;
10710 try astgen.extra.ensureTotalCapacity(astgen.gpa, notes_start + 1 + notes.len);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 astgen.extra.appendSliceAssumeCapacity(notes);10776 astgen.extra.appendSliceAssumeCapacity(notes);
10713 break :blk @as(u32, @intCast(notes_start));10777 break :blk @intCast(notes_start);
10714 } else 0;10778 } else 0;
10715 try astgen.compile_errors.append(astgen.gpa, .{10779 try astgen.compile_errors.append(astgen.gpa, .{
10716 .msg = msg,10780 .msg = msg,
...@@ -10795,14 +10859,14 @@ fn appendErrorTokNotesOff(...@@ -10795,14 +10859,14 @@ fn appendErrorTokNotesOff(
10795 @setCold(true);10859 @setCold(true);
10796 const gpa = astgen.gpa;10860 const gpa = astgen.gpa;
10797 const string_bytes = &astgen.string_bytes;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 try string_bytes.writer(gpa).print(format ++ "\x00", args);10863 try string_bytes.writer(gpa).print(format ++ "\x00", args);
10800 const notes_index: u32 = if (notes.len != 0) blk: {10864 const notes_index: u32 = if (notes.len != 0) blk: {
10801 const notes_start = astgen.extra.items.len;10865 const notes_start = astgen.extra.items.len;
10802 try astgen.extra.ensureTotalCapacity(gpa, notes_start + 1 + notes.len);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 astgen.extra.appendSliceAssumeCapacity(notes);10868 astgen.extra.appendSliceAssumeCapacity(notes);
10805 break :blk @as(u32, @intCast(notes_start));10869 break :blk @intCast(notes_start);
10806 } else 0;10870 } else 0;
10807 try astgen.compile_errors.append(gpa, .{10871 try astgen.compile_errors.append(gpa, .{
10808 .msg = msg,10872 .msg = msg,
...@@ -10831,7 +10895,7 @@ fn errNoteTokOff(...@@ -10831,7 +10895,7 @@ fn errNoteTokOff(
10831) Allocator.Error!u32 {10895) Allocator.Error!u32 {
10832 @setCold(true);10896 @setCold(true);
10833 const string_bytes = &astgen.string_bytes;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 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10899 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10836 return astgen.addExtra(Zir.Inst.CompileErrors.Item{10900 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
10837 .msg = msg,10901 .msg = msg,
...@@ -10850,7 +10914,7 @@ fn errNoteNode(...@@ -10850,7 +10914,7 @@ fn errNoteNode(
10850) Allocator.Error!u32 {10914) Allocator.Error!u32 {
10851 @setCold(true);10915 @setCold(true);
10852 const string_bytes = &astgen.string_bytes;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 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);10918 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
10855 return astgen.addExtra(Zir.Inst.CompileErrors.Item{10919 return astgen.addExtra(Zir.Inst.CompileErrors.Item{
10856 .msg = msg,10920 .msg = msg,
...@@ -10864,7 +10928,7 @@ fn errNoteNode(...@@ -10864,7 +10928,7 @@ fn errNoteNode(
10864fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {10928fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {
10865 const gpa = astgen.gpa;10929 const gpa = astgen.gpa;
10866 const string_bytes = &astgen.string_bytes;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 try astgen.appendIdentStr(ident_token, string_bytes);10932 try astgen.appendIdentStr(ident_token, string_bytes);
10869 const key: []const u8 = string_bytes.items[str_index..];10933 const key: []const u8 = string_bytes.items[str_index..];
10870 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{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,7 +10950,7 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !u32 {
10886/// `end_token` must point at the first token after the last doc coment line.10950/// `end_token` must point at the first token after the last doc coment line.
10887/// Returns 0 if no doc comment is present.10951/// Returns 0 if no doc comment is present.
10888fn docCommentAsString(astgen: *AstGen, end_token: Ast.TokenIndex) !u32 {10952fn docCommentAsString(astgen: *AstGen, end_token: Ast.TokenIndex) !u32 {
10889 if (end_token == 0) return @as(u32, 0);10953 if (end_token == 0) return 0;
1089010954
10891 const token_tags = astgen.tree.tokens.items(.tag);10955 const token_tags = astgen.tree.tokens.items(.tag);
1089210956
...@@ -10910,7 +10974,7 @@ fn docCommentAsStringFromFirst(...@@ -10910,7 +10974,7 @@ fn docCommentAsStringFromFirst(
1091010974
10911 const gpa = astgen.gpa;10975 const gpa = astgen.gpa;
10912 const string_bytes = &astgen.string_bytes;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 const token_starts = astgen.tree.tokens.items(.start);10978 const token_starts = astgen.tree.tokens.items(.start);
10915 const token_tags = astgen.tree.tokens.items(.tag);10979 const token_tags = astgen.tree.tokens.items(.tag);
1091610980
...@@ -10931,8 +10995,8 @@ fn docCommentAsStringFromFirst(...@@ -10931,8 +10995,8 @@ fn docCommentAsStringFromFirst(
10931 }10995 }
10932 }10996 }
1093310997
10934 const key = string_bytes.items[str_index..];10998 const key: []const u8 = string_bytes.items[str_index..];
10935 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, @as([]const u8, key), StringIndexAdapter{10999 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{
10936 .bytes = string_bytes,11000 .bytes = string_bytes,
10937 }, StringIndexContext{11001 }, StringIndexContext{
10938 .bytes = string_bytes,11002 .bytes = string_bytes,
...@@ -10953,11 +11017,11 @@ const IndexSlice = struct { index: u32, len: u32 };...@@ -10953,11 +11017,11 @@ const IndexSlice = struct { index: u32, len: u32 };
10953fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {11017fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10954 const gpa = astgen.gpa;11018 const gpa = astgen.gpa;
10955 const string_bytes = &astgen.string_bytes;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 const token_bytes = astgen.tree.tokenSlice(str_lit_token);11021 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
10958 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);11022 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
10959 const key = string_bytes.items[str_index..];11023 const key: []const u8 = string_bytes.items[str_index..];
10960 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, @as([]const u8, key), StringIndexAdapter{11024 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{
10961 .bytes = string_bytes,11025 .bytes = string_bytes,
10962 }, StringIndexContext{11026 }, StringIndexContext{
10963 .bytes = string_bytes,11027 .bytes = string_bytes,
...@@ -10966,7 +11030,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {...@@ -10966,7 +11030,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10966 string_bytes.shrinkRetainingCapacity(str_index);11030 string_bytes.shrinkRetainingCapacity(str_index);
10967 return IndexSlice{11031 return IndexSlice{
10968 .index = gop.key_ptr.*,11032 .index = gop.key_ptr.*,
10969 .len = @as(u32, @intCast(key.len)),11033 .len = @intCast(key.len),
10970 };11034 };
10971 } else {11035 } else {
10972 gop.key_ptr.* = str_index;11036 gop.key_ptr.* = str_index;
...@@ -10976,7 +11040,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {...@@ -10976,7 +11040,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
10976 try string_bytes.append(gpa, 0);11040 try string_bytes.append(gpa, 0);
10977 return IndexSlice{11041 return IndexSlice{
10978 .index = str_index,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,15 +11077,15 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice {
11013 const len = string_bytes.items.len - str_index;11077 const len = string_bytes.items.len - str_index;
11014 try string_bytes.append(gpa, 0);11078 try string_bytes.append(gpa, 0);
11015 return IndexSlice{11079 return IndexSlice{
11016 .index = @as(u32, @intCast(str_index)),11080 .index = @intCast(str_index),
11017 .len = @as(u32, @intCast(len)),11081 .len = @intCast(len),
11018 };11082 };
11019}11083}
1102011084
11021fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 {11085fn testNameString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !u32 {
11022 const gpa = astgen.gpa;11086 const gpa = astgen.gpa;
11023 const string_bytes = &astgen.string_bytes;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 const token_bytes = astgen.tree.tokenSlice(str_lit_token);11089 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
11026 try string_bytes.append(gpa, 0); // Indicates this is a test.11090 try string_bytes.append(gpa, 0); // Indicates this is a test.
11027 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);11091 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
...@@ -11340,7 +11404,10 @@ const GenZir = struct {...@@ -11340,7 +11404,10 @@ const GenZir = struct {
11340 parent_gz.instructions.items.len -= src - dst;11404 parent_gz.instructions.items.len -= src - dst;
11341 as_scope.instructions_top = GenZir.unstacked_top;11405 as_scope.instructions_top = GenZir.unstacked_top;
11342 // as_scope now unstacked, can add new instructions to parent_gz11406 // 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 return rvalue(parent_gz, ri, casted_result, src_node);11411 return rvalue(parent_gz, ri, casted_result, src_node);
11345 } else {11412 } else {
11346 // implicitly move all as_scope instructions to parent_gz11413 // implicitly move all as_scope instructions to parent_gz
...@@ -11530,7 +11597,7 @@ const GenZir = struct {...@@ -11530,7 +11597,7 @@ const GenZir = struct {
11530 const astgen = gz.astgen;11597 const astgen = gz.astgen;
11531 const gpa = astgen.gpa;11598 const gpa = astgen.gpa;
11532 const ret_ref = if (args.ret_ref == .void_type) .none else args.ret_ref;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);
1153411601
11535 try astgen.instructions.ensureUnusedCapacity(gpa, 1);11602 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1153611603
...@@ -11548,8 +11615,8 @@ const GenZir = struct {...@@ -11548,8 +11615,8 @@ const GenZir = struct {
11548 const block = node_datas[fn_decl].rhs;11615 const block = node_datas[fn_decl].rhs;
11549 const rbrace_start = token_starts[tree.lastToken(block)];11616 const rbrace_start = token_starts[tree.lastToken(block)];
11550 astgen.advanceSourceCursor(rbrace_start);11617 astgen.advanceSourceCursor(rbrace_start);
11551 const rbrace_line = @as(u32, @intCast(astgen.source_line - gz.decl_line));11618 const rbrace_line: u32 = @intCast(astgen.source_line - gz.decl_line);
11552 const rbrace_column = @as(u32, @intCast(astgen.source_column));11619 const rbrace_column: u32 = @intCast(astgen.source_column);
1155311620
11554 const columns = args.lbrace_column | (rbrace_column << 16);11621 const columns = args.lbrace_column | (rbrace_column << 16);
11555 src_locs_buffer[0] = args.lbrace_line;11622 src_locs_buffer[0] = args.lbrace_line;
...@@ -11626,40 +11693,47 @@ const GenZir = struct {...@@ -11626,40 +11693,47 @@ const GenZir = struct {
11626 if (align_body.len != 0) {11693 if (align_body.len != 0) {
11627 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body));11694 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body));
11628 astgen.appendBodyWithFixups(align_body);11695 astgen.appendBodyWithFixups(align_body);
11629 const inst_data = zir_datas[align_body[align_body.len - 1]].@"break";11696 const break_extra = zir_datas[align_body[align_body.len - 1]].@"break".payload_index;
11630 astgen.extra.items[inst_data.payload_index] = new_index;11697 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11698 new_index;
11631 } else if (args.align_ref != .none) {11699 } else if (args.align_ref != .none) {
11632 astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref));11700 astgen.extra.appendAssumeCapacity(@intFromEnum(args.align_ref));
11633 }11701 }
11634 if (addrspace_body.len != 0) {11702 if (addrspace_body.len != 0) {
11635 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body));11703 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body));
11636 astgen.appendBodyWithFixups(addrspace_body);11704 astgen.appendBodyWithFixups(addrspace_body);
11637 const inst_data = zir_datas[addrspace_body[addrspace_body.len - 1]].@"break";11705 const break_extra =
11638 astgen.extra.items[inst_data.payload_index] = new_index;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 } else if (args.addrspace_ref != .none) {11709 } else if (args.addrspace_ref != .none) {
11640 astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref));11710 astgen.extra.appendAssumeCapacity(@intFromEnum(args.addrspace_ref));
11641 }11711 }
11642 if (section_body.len != 0) {11712 if (section_body.len != 0) {
11643 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body));11713 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body));
11644 astgen.appendBodyWithFixups(section_body);11714 astgen.appendBodyWithFixups(section_body);
11645 const inst_data = zir_datas[section_body[section_body.len - 1]].@"break";11715 const break_extra =
11646 astgen.extra.items[inst_data.payload_index] = new_index;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 } else if (args.section_ref != .none) {11719 } else if (args.section_ref != .none) {
11648 astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref));11720 astgen.extra.appendAssumeCapacity(@intFromEnum(args.section_ref));
11649 }11721 }
11650 if (cc_body.len != 0) {11722 if (cc_body.len != 0) {
11651 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body));11723 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body));
11652 astgen.appendBodyWithFixups(cc_body);11724 astgen.appendBodyWithFixups(cc_body);
11653 const inst_data = zir_datas[cc_body[cc_body.len - 1]].@"break";11725 const break_extra = zir_datas[cc_body[cc_body.len - 1]].@"break".payload_index;
11654 astgen.extra.items[inst_data.payload_index] = new_index;11726 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11727 new_index;
11655 } else if (args.cc_ref != .none) {11728 } else if (args.cc_ref != .none) {
11656 astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref));11729 astgen.extra.appendAssumeCapacity(@intFromEnum(args.cc_ref));
11657 }11730 }
11658 if (ret_body.len != 0) {11731 if (ret_body.len != 0) {
11659 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body));11732 astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body));
11660 astgen.appendBodyWithFixups(ret_body);11733 astgen.appendBodyWithFixups(ret_body);
11661 const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break";11734 const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index;
11662 astgen.extra.items[inst_data.payload_index] = new_index;11735 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11736 new_index;
11663 } else if (ret_ref != .none) {11737 } else if (ret_ref != .none) {
11664 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));11738 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));
11665 }11739 }
...@@ -11714,8 +11788,9 @@ const GenZir = struct {...@@ -11714,8 +11788,9 @@ const GenZir = struct {
11714 if (ret_body.len != 0) {11788 if (ret_body.len != 0) {
11715 astgen.appendBodyWithFixups(ret_body);11789 astgen.appendBodyWithFixups(ret_body);
1171611790
11717 const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break";11791 const break_extra = zir_datas[ret_body[ret_body.len - 1]].@"break".payload_index;
11718 astgen.extra.items[inst_data.payload_index] = new_index;11792 astgen.extra.items[break_extra + std.meta.fieldIndex(Zir.Inst.Break, "block_inst").?] =
11793 new_index;
11719 } else if (ret_ref != .none) {11794 } else if (ret_ref != .none) {
11720 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));11795 astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref));
11721 }11796 }
...@@ -11785,18 +11860,18 @@ const GenZir = struct {...@@ -11785,18 +11860,18 @@ const GenZir = struct {
11785 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));11860 astgen.extra.appendAssumeCapacity(@intFromEnum(args.init));
11786 }11861 }
1178711862
11788 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));11863 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11789 astgen.instructions.appendAssumeCapacity(.{11864 astgen.instructions.appendAssumeCapacity(.{
11790 .tag = .extended,11865 .tag = .extended,
11791 .data = .{ .extended = .{11866 .data = .{ .extended = .{
11792 .opcode = .variable,11867 .opcode = .variable,
11793 .small = @as(u16, @bitCast(Zir.Inst.ExtendedVar.Small{11868 .small = @bitCast(Zir.Inst.ExtendedVar.Small{
11794 .has_lib_name = args.lib_name != 0,11869 .has_lib_name = args.lib_name != 0,
11795 .has_align = args.align_inst != .none,11870 .has_align = args.align_inst != .none,
11796 .has_init = args.init != .none,11871 .has_init = args.init != .none,
11797 .is_extern = args.is_extern,11872 .is_extern = args.is_extern,
11798 .is_threadlocal = args.is_threadlocal,11873 .is_threadlocal = args.is_threadlocal,
11799 })),11874 }),
11800 .operand = payload_index,11875 .operand = payload_index,
11801 } },11876 } },
11802 });11877 });
...@@ -11816,7 +11891,7 @@ const GenZir = struct {...@@ -11816,7 +11891,7 @@ const GenZir = struct {
11816 try gz.instructions.ensureUnusedCapacity(gpa, 1);11891 try gz.instructions.ensureUnusedCapacity(gpa, 1);
11817 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11892 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1181811893
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 gz.astgen.instructions.appendAssumeCapacity(.{11895 gz.astgen.instructions.appendAssumeCapacity(.{
11821 .tag = tag,11896 .tag = tag,
11822 .data = .{ .bool_br = .{11897 .data = .{ .bool_br = .{
...@@ -11842,12 +11917,12 @@ const GenZir = struct {...@@ -11842,12 +11917,12 @@ const GenZir = struct {
11842 try astgen.instructions.ensureUnusedCapacity(gpa, 1);11917 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
11843 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);11918 try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);
1184411919
11845 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));11920 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
11846 astgen.instructions.appendAssumeCapacity(.{11921 astgen.instructions.appendAssumeCapacity(.{
11847 .tag = .int_big,11922 .tag = .int_big,
11848 .data = .{ .str = .{11923 .data = .{ .str = .{
11849 .start = @as(u32, @intCast(astgen.string_bytes.items.len)),11924 .start = @intCast(astgen.string_bytes.items.len),
11850 .len = @as(u32, @intCast(limbs.len)),11925 .len = @intCast(limbs.len),
11851 } },11926 } },
11852 });11927 });
11853 gz.instructions.appendAssumeCapacity(new_index);11928 gz.instructions.appendAssumeCapacity(new_index);
...@@ -11887,7 +11962,7 @@ const GenZir = struct {...@@ -11887,7 +11962,7 @@ const GenZir = struct {
11887 src_node: Ast.Node.Index,11962 src_node: Ast.Node.Index,
11888 ) !Zir.Inst.Index {11963 ) !Zir.Inst.Index {
11889 assert(operand != .none);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 try gz.astgen.instructions.append(gz.astgen.gpa, .{11966 try gz.astgen.instructions.append(gz.astgen.gpa, .{
11892 .tag = tag,11967 .tag = tag,
11893 .data = .{ .un_node = .{11968 .data = .{ .un_node = .{
...@@ -11910,7 +11985,7 @@ const GenZir = struct {...@@ -11910,7 +11985,7 @@ const GenZir = struct {
11910 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11985 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1191111986
11912 const payload_index = try gz.astgen.addExtra(extra);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 gz.astgen.instructions.appendAssumeCapacity(.{11989 gz.astgen.instructions.appendAssumeCapacity(.{
11915 .tag = tag,11990 .tag = tag,
11916 .data = .{ .pl_node = .{11991 .data = .{ .pl_node = .{
...@@ -11962,12 +12037,12 @@ const GenZir = struct {...@@ -11962,12 +12037,12 @@ const GenZir = struct {
11962 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{12037 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
11963 .name = name,12038 .name = name,
11964 .doc_comment = doc_comment_index,12039 .doc_comment = doc_comment_index,
11965 .body_len = @as(u32, @intCast(body_len)),12040 .body_len = @intCast(body_len),
11966 });12041 });
11967 gz.astgen.appendBodyWithFixups(param_body);12042 gz.astgen.appendBodyWithFixups(param_body);
11968 param_gz.unstack();12043 param_gz.unstack();
1196912044
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 gz.astgen.instructions.appendAssumeCapacity(.{12046 gz.astgen.instructions.appendAssumeCapacity(.{
11972 .tag = tag,12047 .tag = tag,
11973 .data = .{ .pl_tok = .{12048 .data = .{ .pl_tok = .{
...@@ -11995,7 +12070,7 @@ const GenZir = struct {...@@ -11995,7 +12070,7 @@ const GenZir = struct {
11995 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12070 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1199612071
11997 const payload_index = try gz.astgen.addExtra(extra);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 gz.astgen.instructions.appendAssumeCapacity(.{12074 gz.astgen.instructions.appendAssumeCapacity(.{
12000 .tag = .extended,12075 .tag = .extended,
12001 .data = .{ .extended = .{12076 .data = .{ .extended = .{
...@@ -12027,12 +12102,12 @@ const GenZir = struct {...@@ -12027,12 +12102,12 @@ const GenZir = struct {
12027 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{12102 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
12028 .src_node = gz.nodeIndexToRelative(node),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 astgen.instructions.appendAssumeCapacity(.{12106 astgen.instructions.appendAssumeCapacity(.{
12032 .tag = .extended,12107 .tag = .extended,
12033 .data = .{ .extended = .{12108 .data = .{ .extended = .{
12034 .opcode = opcode,12109 .opcode = opcode,
12035 .small = @as(u16, @intCast(operands.len)),12110 .small = @intCast(operands.len),
12036 .operand = payload_index,12111 .operand = payload_index,
12037 } },12112 } },
12038 });12113 });
...@@ -12052,12 +12127,12 @@ const GenZir = struct {...@@ -12052,12 +12127,12 @@ const GenZir = struct {
1205212127
12053 try gz.instructions.ensureUnusedCapacity(gpa, 1);12128 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12054 try astgen.instructions.ensureUnusedCapacity(gpa, 1);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 astgen.instructions.appendAssumeCapacity(.{12131 astgen.instructions.appendAssumeCapacity(.{
12057 .tag = .extended,12132 .tag = .extended,
12058 .data = .{ .extended = .{12133 .data = .{ .extended = .{
12059 .opcode = opcode,12134 .opcode = opcode,
12060 .small = @as(u16, @intCast(trailing_len)),12135 .small = @intCast(trailing_len),
12061 .operand = payload_index,12136 .operand = payload_index,
12062 } },12137 } },
12063 });12138 });
...@@ -12090,7 +12165,7 @@ const GenZir = struct {...@@ -12090,7 +12165,7 @@ const GenZir = struct {
12090 abs_tok_index: Ast.TokenIndex,12165 abs_tok_index: Ast.TokenIndex,
12091 ) !Zir.Inst.Index {12166 ) !Zir.Inst.Index {
12092 const astgen = gz.astgen;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 assert(operand != .none);12169 assert(operand != .none);
12095 try astgen.instructions.append(astgen.gpa, .{12170 try astgen.instructions.append(astgen.gpa, .{
12096 .tag = tag,12171 .tag = tag,
...@@ -12169,21 +12244,8 @@ const GenZir = struct {...@@ -12169,21 +12244,8 @@ const GenZir = struct {
12169 ) !Zir.Inst.Index {12244 ) !Zir.Inst.Index {
12170 const gpa = gz.astgen.gpa;12245 const gpa = gz.astgen.gpa;
12171 try gz.instructions.ensureUnusedCapacity(gpa, 1);12246 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12172 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1217312247
12174 const extra: Zir.Inst.Break = .{12248 const new_index = try gz.makeBreak(tag, block_inst, operand);
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 });
12187 gz.instructions.appendAssumeCapacity(new_index);12249 gz.instructions.appendAssumeCapacity(new_index);
12188 return new_index;12250 return new_index;
12189 }12251 }
...@@ -12194,23 +12256,7 @@ const GenZir = struct {...@@ -12194,23 +12256,7 @@ const GenZir = struct {
12194 block_inst: Zir.Inst.Index,12256 block_inst: Zir.Inst.Index,
12195 operand: Zir.Inst.Ref,12257 operand: Zir.Inst.Ref,
12196 ) !Zir.Inst.Index {12258 ) !Zir.Inst.Index {
12197 const gpa = gz.astgen.gpa;12259 return gz.makeBreakCommon(tag, block_inst, operand, null);
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;
12214 }12260 }
1221512261
12216 fn addBreakWithSrcNode(12262 fn addBreakWithSrcNode(
...@@ -12222,21 +12268,8 @@ const GenZir = struct {...@@ -12222,21 +12268,8 @@ const GenZir = struct {
12222 ) !Zir.Inst.Index {12268 ) !Zir.Inst.Index {
12223 const gpa = gz.astgen.gpa;12269 const gpa = gz.astgen.gpa;
12224 try gz.instructions.ensureUnusedCapacity(gpa, 1);12270 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12225 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1222612271
12227 const extra: Zir.Inst.Break = .{12272 const new_index = try gz.makeBreakWithSrcNode(tag, block_inst, operand, operand_src_node);
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 });
12240 gz.instructions.appendAssumeCapacity(new_index);12273 gz.instructions.appendAssumeCapacity(new_index);
12241 return new_index;12274 return new_index;
12242 }12275 }
...@@ -12247,21 +12280,33 @@ const GenZir = struct {...@@ -12247,21 +12280,33 @@ const GenZir = struct {
12247 block_inst: Zir.Inst.Index,12280 block_inst: Zir.Inst.Index,
12248 operand: Zir.Inst.Ref,12281 operand: Zir.Inst.Ref,
12249 operand_src_node: Ast.Node.Index,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 ) !Zir.Inst.Index {12293 ) !Zir.Inst.Index {
12251 const gpa = gz.astgen.gpa;12294 const gpa = gz.astgen.gpa;
12252 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12295 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
12296 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).Struct.fields.len);
1225312297
12254 const extra: Zir.Inst.Break = .{12298 const new_index: Zir.Inst.Index = @intCast(gz.astgen.instructions.len);
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));
12260 gz.astgen.instructions.appendAssumeCapacity(.{12299 gz.astgen.instructions.appendAssumeCapacity(.{
12261 .tag = tag,12300 .tag = tag,
12262 .data = .{ .@"break" = .{12301 .data = .{ .@"break" = .{
12263 .operand = operand,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 return new_index;12312 return new_index;
...@@ -12348,7 +12393,7 @@ const GenZir = struct {...@@ -12348,7 +12393,7 @@ const GenZir = struct {
12348 .data = .{ .extended = .{12393 .data = .{ .extended = .{
12349 .opcode = opcode,12394 .opcode = opcode,
12350 .small = undefined,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,8 +12417,8 @@ const GenZir = struct {
12372 try astgen.extra.ensureUnusedCapacity(12417 try astgen.extra.ensureUnusedCapacity(
12373 gpa,12418 gpa,
12374 @typeInfo(Zir.Inst.AllocExtended).Struct.fields.len +12419 @typeInfo(Zir.Inst.AllocExtended).Struct.fields.len +
12375 @as(usize, @intFromBool(args.type_inst != .none)) +12420 @intFromBool(args.type_inst != .none) +
12376 @as(usize, @intFromBool(args.align_inst != .none)),12421 @intFromBool(args.align_inst != .none),
12377 );12422 );
12378 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.AllocExtended{12423 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.AllocExtended{
12379 .src_node = gz.nodeIndexToRelative(args.node),12424 .src_node = gz.nodeIndexToRelative(args.node),
...@@ -12391,7 +12436,7 @@ const GenZir = struct {...@@ -12391,7 +12436,7 @@ const GenZir = struct {
12391 const is_comptime: u4 = @intFromBool(args.is_comptime);12436 const is_comptime: u4 = @intFromBool(args.is_comptime);
12392 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);12437 const small: u16 = has_type | (has_align << 1) | (is_const << 2) | (is_comptime << 3);
1239312438
12394 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));12439 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
12395 astgen.instructions.appendAssumeCapacity(.{12440 astgen.instructions.appendAssumeCapacity(.{
12396 .tag = .extended,12441 .tag = .extended,
12397 .data = .{ .extended = .{12442 .data = .{ .extended = .{
...@@ -12450,7 +12495,7 @@ const GenZir = struct {...@@ -12450,7 +12495,7 @@ const GenZir = struct {
12450 @as(u16, @intCast(args.clobbers.len << 10)) |12495 @as(u16, @intCast(args.clobbers.len << 10)) |
12451 (@as(u16, @intFromBool(args.is_volatile)) << 15);12496 (@as(u16, @intFromBool(args.is_volatile)) << 15);
1245212497
12453 const new_index = @as(Zir.Inst.Index, @intCast(astgen.instructions.len));12498 const new_index: Zir.Inst.Index = @intCast(astgen.instructions.len);
12454 astgen.instructions.appendAssumeCapacity(.{12499 astgen.instructions.appendAssumeCapacity(.{
12455 .tag = .extended,12500 .tag = .extended,
12456 .data = .{ .extended = .{12501 .data = .{ .extended = .{
...@@ -12467,7 +12512,7 @@ const GenZir = struct {...@@ -12467,7 +12512,7 @@ const GenZir = struct {
12467 /// Does *not* append the block instruction to the scope.12512 /// Does *not* append the block instruction to the scope.
12468 /// Leaves the `payload_index` field undefined.12513 /// Leaves the `payload_index` field undefined.
12469 fn makeBlockInst(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {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 const gpa = gz.astgen.gpa;12516 const gpa = gz.astgen.gpa;
12472 try gz.astgen.instructions.append(gpa, .{12517 try gz.astgen.instructions.append(gpa, .{
12473 .tag = tag,12518 .tag = tag,
...@@ -12484,7 +12529,7 @@ const GenZir = struct {...@@ -12484,7 +12529,7 @@ const GenZir = struct {
12484 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {12529 fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
12485 const gpa = gz.astgen.gpa;12530 const gpa = gz.astgen.gpa;
12486 try gz.instructions.ensureUnusedCapacity(gpa, 1);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 try gz.astgen.instructions.append(gpa, .{12533 try gz.astgen.instructions.append(gpa, .{
12489 .tag = tag,12534 .tag = tag,
12490 .data = .{ .pl_node = .{12535 .data = .{ .pl_node = .{
...@@ -12511,11 +12556,11 @@ const GenZir = struct {...@@ -12511,11 +12556,11 @@ const GenZir = struct {
12511 const gpa = astgen.gpa;12556 const gpa = astgen.gpa;
1251212557
12513 try astgen.extra.ensureUnusedCapacity(gpa, 6);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);
1251512560
12516 if (args.src_node != 0) {12561 if (args.src_node != 0) {
12517 const node_offset = gz.nodeIndexToRelative(args.src_node);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 if (args.fields_len != 0) {12565 if (args.fields_len != 0) {
12521 astgen.extra.appendAssumeCapacity(args.fields_len);12566 astgen.extra.appendAssumeCapacity(args.fields_len);
...@@ -12533,7 +12578,7 @@ const GenZir = struct {...@@ -12533,7 +12578,7 @@ const GenZir = struct {
12533 .tag = .extended,12578 .tag = .extended,
12534 .data = .{ .extended = .{12579 .data = .{ .extended = .{
12535 .opcode = .struct_decl,12580 .opcode = .struct_decl,
12536 .small = @as(u16, @bitCast(Zir.Inst.StructDecl.Small{12581 .small = @bitCast(Zir.Inst.StructDecl.Small{
12537 .has_src_node = args.src_node != 0,12582 .has_src_node = args.src_node != 0,
12538 .has_fields_len = args.fields_len != 0,12583 .has_fields_len = args.fields_len != 0,
12539 .has_decls_len = args.decls_len != 0,12584 .has_decls_len = args.decls_len != 0,
...@@ -12543,7 +12588,7 @@ const GenZir = struct {...@@ -12543,7 +12588,7 @@ const GenZir = struct {
12543 .is_tuple = args.is_tuple,12588 .is_tuple = args.is_tuple,
12544 .name_strategy = gz.anon_name_strategy,12589 .name_strategy = gz.anon_name_strategy,
12545 .layout = args.layout,12590 .layout = args.layout,
12546 })),12591 }),
12547 .operand = payload_index,12592 .operand = payload_index,
12548 } },12593 } },
12549 });12594 });
...@@ -12562,11 +12607,11 @@ const GenZir = struct {...@@ -12562,11 +12607,11 @@ const GenZir = struct {
12562 const gpa = astgen.gpa;12607 const gpa = astgen.gpa;
1256312608
12564 try astgen.extra.ensureUnusedCapacity(gpa, 5);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);
1256612611
12567 if (args.src_node != 0) {12612 if (args.src_node != 0) {
12568 const node_offset = gz.nodeIndexToRelative(args.src_node);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 if (args.tag_type != .none) {12616 if (args.tag_type != .none) {
12572 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));12617 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
...@@ -12584,7 +12629,7 @@ const GenZir = struct {...@@ -12584,7 +12629,7 @@ const GenZir = struct {
12584 .tag = .extended,12629 .tag = .extended,
12585 .data = .{ .extended = .{12630 .data = .{ .extended = .{
12586 .opcode = .union_decl,12631 .opcode = .union_decl,
12587 .small = @as(u16, @bitCast(Zir.Inst.UnionDecl.Small{12632 .small = @bitCast(Zir.Inst.UnionDecl.Small{
12588 .has_src_node = args.src_node != 0,12633 .has_src_node = args.src_node != 0,
12589 .has_tag_type = args.tag_type != .none,12634 .has_tag_type = args.tag_type != .none,
12590 .has_body_len = args.body_len != 0,12635 .has_body_len = args.body_len != 0,
...@@ -12593,7 +12638,7 @@ const GenZir = struct {...@@ -12593,7 +12638,7 @@ const GenZir = struct {
12593 .name_strategy = gz.anon_name_strategy,12638 .name_strategy = gz.anon_name_strategy,
12594 .layout = args.layout,12639 .layout = args.layout,
12595 .auto_enum_tag = args.auto_enum_tag,12640 .auto_enum_tag = args.auto_enum_tag,
12596 })),12641 }),
12597 .operand = payload_index,12642 .operand = payload_index,
12598 } },12643 } },
12599 });12644 });
...@@ -12611,11 +12656,11 @@ const GenZir = struct {...@@ -12611,11 +12656,11 @@ const GenZir = struct {
12611 const gpa = astgen.gpa;12656 const gpa = astgen.gpa;
1261212657
12613 try astgen.extra.ensureUnusedCapacity(gpa, 5);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);
1261512660
12616 if (args.src_node != 0) {12661 if (args.src_node != 0) {
12617 const node_offset = gz.nodeIndexToRelative(args.src_node);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 if (args.tag_type != .none) {12665 if (args.tag_type != .none) {
12621 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));12666 astgen.extra.appendAssumeCapacity(@intFromEnum(args.tag_type));
...@@ -12633,7 +12678,7 @@ const GenZir = struct {...@@ -12633,7 +12678,7 @@ const GenZir = struct {
12633 .tag = .extended,12678 .tag = .extended,
12634 .data = .{ .extended = .{12679 .data = .{ .extended = .{
12635 .opcode = .enum_decl,12680 .opcode = .enum_decl,
12636 .small = @as(u16, @bitCast(Zir.Inst.EnumDecl.Small{12681 .small = @bitCast(Zir.Inst.EnumDecl.Small{
12637 .has_src_node = args.src_node != 0,12682 .has_src_node = args.src_node != 0,
12638 .has_tag_type = args.tag_type != .none,12683 .has_tag_type = args.tag_type != .none,
12639 .has_body_len = args.body_len != 0,12684 .has_body_len = args.body_len != 0,
...@@ -12641,7 +12686,7 @@ const GenZir = struct {...@@ -12641,7 +12686,7 @@ const GenZir = struct {
12641 .has_decls_len = args.decls_len != 0,12686 .has_decls_len = args.decls_len != 0,
12642 .name_strategy = gz.anon_name_strategy,12687 .name_strategy = gz.anon_name_strategy,
12643 .nonexhaustive = args.nonexhaustive,12688 .nonexhaustive = args.nonexhaustive,
12644 })),12689 }),
12645 .operand = payload_index,12690 .operand = payload_index,
12646 } },12691 } },
12647 });12692 });
...@@ -12655,11 +12700,11 @@ const GenZir = struct {...@@ -12655,11 +12700,11 @@ const GenZir = struct {
12655 const gpa = astgen.gpa;12700 const gpa = astgen.gpa;
1265612701
12657 try astgen.extra.ensureUnusedCapacity(gpa, 2);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);
1265912704
12660 if (args.src_node != 0) {12705 if (args.src_node != 0) {
12661 const node_offset = gz.nodeIndexToRelative(args.src_node);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 if (args.decls_len != 0) {12709 if (args.decls_len != 0) {
12665 astgen.extra.appendAssumeCapacity(args.decls_len);12710 astgen.extra.appendAssumeCapacity(args.decls_len);
...@@ -12668,11 +12713,11 @@ const GenZir = struct {...@@ -12668,11 +12713,11 @@ const GenZir = struct {
12668 .tag = .extended,12713 .tag = .extended,
12669 .data = .{ .extended = .{12714 .data = .{ .extended = .{
12670 .opcode = .opaque_decl,12715 .opcode = .opaque_decl,
12671 .small = @as(u16, @bitCast(Zir.Inst.OpaqueDecl.Small{12716 .small = @bitCast(Zir.Inst.OpaqueDecl.Small{
12672 .has_src_node = args.src_node != 0,12717 .has_src_node = args.src_node != 0,
12673 .has_decls_len = args.decls_len != 0,12718 .has_decls_len = args.decls_len != 0,
12674 .name_strategy = gz.anon_name_strategy,12719 .name_strategy = gz.anon_name_strategy,
12675 })),12720 }),
12676 .operand = payload_index,12721 .operand = payload_index,
12677 } },12722 } },
12678 });12723 });
...@@ -12687,7 +12732,7 @@ const GenZir = struct {...@@ -12687,7 +12732,7 @@ const GenZir = struct {
12687 try gz.instructions.ensureUnusedCapacity(gpa, 1);12732 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12688 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12733 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1268912734
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 gz.astgen.instructions.appendAssumeCapacity(inst);12736 gz.astgen.instructions.appendAssumeCapacity(inst);
12692 gz.instructions.appendAssumeCapacity(new_index);12737 gz.instructions.appendAssumeCapacity(new_index);
12693 return new_index;12738 return new_index;
...@@ -12698,7 +12743,7 @@ const GenZir = struct {...@@ -12698,7 +12743,7 @@ const GenZir = struct {
12698 try gz.instructions.ensureUnusedCapacity(gpa, 1);12743 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12699 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12744 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1270012745
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 gz.astgen.instructions.len += 1;12747 gz.astgen.instructions.len += 1;
12703 gz.instructions.appendAssumeCapacity(new_index);12748 gz.instructions.appendAssumeCapacity(new_index);
12704 return new_index;12749 return new_index;
...@@ -12750,7 +12795,7 @@ const GenZir = struct {...@@ -12750,7 +12795,7 @@ const GenZir = struct {
12750 return;12795 return;
12751 }12796 }
1275212797
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 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });12799 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
12755 try gz.instructions.append(gpa, new_index);12800 try gz.instructions.append(gpa, new_index);
12756 }12801 }
...@@ -12759,7 +12804,7 @@ const GenZir = struct {...@@ -12759,7 +12804,7 @@ const GenZir = struct {
12759/// This can only be for short-lived references; the memory becomes invalidated12804/// This can only be for short-lived references; the memory becomes invalidated
12760/// when another string is added.12805/// when another string is added.
12761fn nullTerminatedString(astgen: AstGen, index: usize) [*:0]const u8 {12806fn 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}
1276412809
12765/// Local variables shadowing detection, including function parameters.12810/// Local variables shadowing detection, including function parameters.
...@@ -13038,7 +13083,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {...@@ -13038,7 +13083,7 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
13038 .extended => {13083 .extended => {
13039 const zir_data = astgen.instructions.items(.data);13084 const zir_data = astgen.instructions.items(.data);
13040 if (zir_data[inst].extended.opcode != .alloc) return false;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 return !small.has_type;13087 return !small.has_type;
13043 },13088 },
1304413089
...@@ -13082,7 +13127,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {...@@ -13082,7 +13127,7 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 {
13082 check_inst = ref_inst;13127 check_inst = ref_inst;
13083 }13128 }
13084 }13129 }
13085 return @as(u32, @intCast(count));13130 return @intCast(count);
13086}13131}
1308713132
13088fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void {13133fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void {
...@@ -13114,7 +13159,7 @@ fn lowerAstErrors(astgen: *AstGen) !void {...@@ -13114,7 +13159,7 @@ fn lowerAstErrors(astgen: *AstGen) !void {
1311413159
13115 if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) {13160 if (token_tags[parse_err.token + @intFromBool(parse_err.token_is_prev)] == .invalid) {
13116 const tok = parse_err.token + @intFromBool(parse_err.token_is_prev);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 const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off;13163 const byte_abs = token_starts[parse_err.token + @intFromBool(parse_err.token_is_prev)] + bad_off;
13119 try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{13164 try notes.append(gpa, try astgen.errNoteTokOff(tok, bad_off, "invalid byte: '{'}'", .{
13120 std.zig.fmtEscapes(tree.source[byte_abs..][0..1]),13165 std.zig.fmtEscapes(tree.source[byte_abs..][0..1]),
src/Zir.zig+21-21
...@@ -78,12 +78,13 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {...@@ -78,12 +78,13 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
78 inline for (fields) |field| {78 inline for (fields) |field| {
79 @field(result, field.name) = switch (field.type) {79 @field(result, field.name) = switch (field.type) {
80 u32 => code.extra[i],80 u32 => code.extra[i],
81 Inst.Ref => @as(Inst.Ref, @enumFromInt(code.extra[i])),81 Inst.Ref => @enumFromInt(code.extra[i]),
82 i32 => @as(i32, @bitCast(code.extra[i])),82 i32,
83 Inst.Call.Flags => @as(Inst.Call.Flags, @bitCast(code.extra[i])),83 Inst.Call.Flags,
84 Inst.BuiltinCall.Flags => @as(Inst.BuiltinCall.Flags, @bitCast(code.extra[i])),84 Inst.BuiltinCall.Flags,
85 Inst.SwitchBlock.Bits => @as(Inst.SwitchBlock.Bits, @bitCast(code.extra[i])),85 Inst.SwitchBlock.Bits,
86 Inst.FuncFancy.Bits => @as(Inst.FuncFancy.Bits, @bitCast(code.extra[i])),86 Inst.FuncFancy.Bits,
87 => @bitCast(code.extra[i]),
87 else => @compileError("bad field type"),88 else => @compileError("bad field type"),
88 };89 };
89 i += 1;90 i += 1;
...@@ -115,8 +116,7 @@ pub fn nullTerminatedString2(code: Zir, index: NullTerminatedString) [:0]const u...@@ -115,8 +116,7 @@ pub fn nullTerminatedString2(code: Zir, index: NullTerminatedString) [:0]const u
115}116}
116117
117pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {118pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
118 const raw_slice = code.extra[start..][0..len];119 return @ptrCast(code.extra[start..][0..len]);
119 return @as([]Inst.Ref, @ptrCast(raw_slice));
120}120}
121121
122pub fn hasCompileErrors(code: Zir) bool {122pub fn hasCompileErrors(code: Zir) bool {
...@@ -2347,8 +2347,8 @@ pub const Inst = struct {...@@ -2347,8 +2347,8 @@ pub const Inst = struct {
2347 pub const Break = struct {2347 pub const Break = struct {
2348 pub const no_src_node = std.math.maxInt(i32);2348 pub const no_src_node = std.math.maxInt(i32);
23492349
2350 block_inst: Index,
2351 operand_src_node: i32,2350 operand_src_node: i32,
2351 block_inst: Index,
2352 };2352 };
23532353
2354 /// Trailing:2354 /// Trailing:
...@@ -3266,10 +3266,10 @@ pub const DeclIterator = struct {...@@ -3266,10 +3266,10 @@ pub const DeclIterator = struct {
3266 }3266 }
3267 it.decl_i += 1;3267 it.decl_i += 1;
32683268
3269 const flags = @as(u4, @truncate(it.cur_bit_bag));3269 const flags: u4 = @truncate(it.cur_bit_bag);
3270 it.cur_bit_bag >>= 4;3270 it.cur_bit_bag >>= 4;
32713271
3272 const sub_index = @as(u32, @intCast(it.extra_index));3272 const sub_index: u32 = @intCast(it.extra_index);
3273 it.extra_index += 5; // src_hash(4) + line(1)3273 it.extra_index += 5; // src_hash(4) + line(1)
3274 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);3274 const name = it.zir.nullTerminatedString(it.zir.extra[it.extra_index]);
3275 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)3275 it.extra_index += 3; // name(1) + value(1) + doc_comment(1)
...@@ -3296,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3296,7 +3296,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3296 const extended = datas[decl_inst].extended;3296 const extended = datas[decl_inst].extended;
3297 switch (extended.opcode) {3297 switch (extended.opcode) {
3298 .struct_decl => {3298 .struct_decl => {
3299 const small = @as(Inst.StructDecl.Small, @bitCast(extended.small));3299 const small: Inst.StructDecl.Small = @bitCast(extended.small);
3300 var extra_index: usize = extended.operand;3300 var extra_index: usize = extended.operand;
3301 extra_index += @intFromBool(small.has_src_node);3301 extra_index += @intFromBool(small.has_src_node);
3302 extra_index += @intFromBool(small.has_fields_len);3302 extra_index += @intFromBool(small.has_fields_len);
...@@ -3319,7 +3319,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3319,7 +3319,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3319 return declIteratorInner(zir, extra_index, decls_len);3319 return declIteratorInner(zir, extra_index, decls_len);
3320 },3320 },
3321 .enum_decl => {3321 .enum_decl => {
3322 const small = @as(Inst.EnumDecl.Small, @bitCast(extended.small));3322 const small: Inst.EnumDecl.Small = @bitCast(extended.small);
3323 var extra_index: usize = extended.operand;3323 var extra_index: usize = extended.operand;
3324 extra_index += @intFromBool(small.has_src_node);3324 extra_index += @intFromBool(small.has_src_node);
3325 extra_index += @intFromBool(small.has_tag_type);3325 extra_index += @intFromBool(small.has_tag_type);
...@@ -3334,7 +3334,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3334,7 +3334,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3334 return declIteratorInner(zir, extra_index, decls_len);3334 return declIteratorInner(zir, extra_index, decls_len);
3335 },3335 },
3336 .union_decl => {3336 .union_decl => {
3337 const small = @as(Inst.UnionDecl.Small, @bitCast(extended.small));3337 const small: Inst.UnionDecl.Small = @bitCast(extended.small);
3338 var extra_index: usize = extended.operand;3338 var extra_index: usize = extended.operand;
3339 extra_index += @intFromBool(small.has_src_node);3339 extra_index += @intFromBool(small.has_src_node);
3340 extra_index += @intFromBool(small.has_tag_type);3340 extra_index += @intFromBool(small.has_tag_type);
...@@ -3349,7 +3349,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {...@@ -3349,7 +3349,7 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator {
3349 return declIteratorInner(zir, extra_index, decls_len);3349 return declIteratorInner(zir, extra_index, decls_len);
3350 },3350 },
3351 .opaque_decl => {3351 .opaque_decl => {
3352 const small = @as(Inst.OpaqueDecl.Small, @bitCast(extended.small));3352 const small: Inst.OpaqueDecl.Small = @bitCast(extended.small);
3353 var extra_index: usize = extended.operand;3353 var extra_index: usize = extended.operand;
3354 extra_index += @intFromBool(small.has_src_node);3354 extra_index += @intFromBool(small.has_src_node);
3355 const decls_len = if (small.has_decls_len) decls_len: {3355 const decls_len = if (small.has_decls_len) decls_len: {
...@@ -3545,7 +3545,7 @@ fn findDeclsSwitch(...@@ -3545,7 +3545,7 @@ fn findDeclsSwitch(
35453545
3546 const special_prong = extra.data.bits.specialProng();3546 const special_prong = extra.data.bits.specialProng();
3547 if (special_prong != .none) {3547 if (special_prong != .none) {
3548 const body_len = @as(u31, @truncate(zir.extra[extra_index]));3548 const body_len: u31 = @truncate(zir.extra[extra_index]);
3549 extra_index += 1;3549 extra_index += 1;
3550 const body = zir.extra[extra_index..][0..body_len];3550 const body = zir.extra[extra_index..][0..body_len];
3551 extra_index += body.len;3551 extra_index += body.len;
...@@ -3558,7 +3558,7 @@ fn findDeclsSwitch(...@@ -3558,7 +3558,7 @@ fn findDeclsSwitch(
3558 var scalar_i: usize = 0;3558 var scalar_i: usize = 0;
3559 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {3559 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
3560 extra_index += 1;3560 extra_index += 1;
3561 const body_len = @as(u31, @truncate(zir.extra[extra_index]));3561 const body_len: u31 = @truncate(zir.extra[extra_index]);
3562 extra_index += 1;3562 extra_index += 1;
3563 const body = zir.extra[extra_index..][0..body_len];3563 const body = zir.extra[extra_index..][0..body_len];
3564 extra_index += body_len;3564 extra_index += body_len;
...@@ -3573,7 +3573,7 @@ fn findDeclsSwitch(...@@ -3573,7 +3573,7 @@ fn findDeclsSwitch(
3573 extra_index += 1;3573 extra_index += 1;
3574 const ranges_len = zir.extra[extra_index];3574 const ranges_len = zir.extra[extra_index];
3575 extra_index += 1;3575 extra_index += 1;
3576 const body_len = @as(u31, @truncate(zir.extra[extra_index]));3576 const body_len: u31 = @truncate(zir.extra[extra_index]);
3577 extra_index += 1;3577 extra_index += 1;
3578 const items = zir.refSlice(extra_index, items_len);3578 const items = zir.refSlice(extra_index, items_len);
3579 extra_index += items_len;3579 extra_index += items_len;
...@@ -3655,7 +3655,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3655,7 +3655,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3655 ret_ty_ref = .void_type;3655 ret_ty_ref = .void_type;
3656 },3656 },
3657 1 => {3657 1 => {
3658 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));3658 ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
3659 extra_index += 1;3659 extra_index += 1;
3660 },3660 },
3661 else => {3661 else => {
...@@ -3709,7 +3709,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3709,7 +3709,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3709 ret_ty_body = zir.extra[extra_index..][0..body_len];3709 ret_ty_body = zir.extra[extra_index..][0..body_len];
3710 extra_index += ret_ty_body.len;3710 extra_index += ret_ty_body.len;
3711 } else if (extra.data.bits.has_ret_ty_ref) {3711 } else if (extra.data.bits.has_ret_ty_ref) {
3712 ret_ty_ref = @as(Inst.Ref, @enumFromInt(zir.extra[extra_index]));3712 ret_ty_ref = @enumFromInt(zir.extra[extra_index]);
3713 extra_index += 1;3713 extra_index += 1;
3714 }3714 }
37153715
...@@ -3753,7 +3753,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {...@@ -3753,7 +3753,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
3753pub const ref_start_index: u32 = InternPool.static_len;3753pub const ref_start_index: u32 = InternPool.static_len;
37543754
3755pub fn indexToRef(inst: Inst.Index) Inst.Ref {3755pub fn indexToRef(inst: Inst.Index) Inst.Ref {
3756 return @as(Inst.Ref, @enumFromInt(ref_start_index + inst));3756 return @enumFromInt(ref_start_index + inst);
3757}3757}
37583758
3759pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {3759pub fn refToIndex(inst: Inst.Ref) ?Inst.Index {
test/cases/compile_errors/invalid_coercion_in_aggregate_literal.zig created+22
...@@ -0,0 +1,22 @@
1export fn invalidArrayElem() u8 {
2 const array_literal = [1]u8{@as(u8, 256)};
3 return array_literal[0];
4}
5
6export fn invalidTupleElem() u8 {
7 const tuple_literal = struct { u8 }{@as(u8, 256)};
8 return tuple_literal[0];
9}
10
11export fn invalidStructField() u8 {
12 const struct_literal = struct { field: u8 }{ .field = @as(u8, 256) };
13 return struct_literal.field;
14}
15
16// error
17// backend=stage2
18// target=native
19//
20// :2:41: error: type 'u8' cannot represent integer value '256'
21// :7:49: error: type 'u8' cannot represent integer value '256'
22// :12:67: error: type 'u8' cannot represent integer value '256'
test/cases/compile_errors/invalid_coercion_in_labeled_break.zig created+12
...@@ -0,0 +1,12 @@
1export fn invalidBreak() u8 {
2 const result: u8 = label: {
3 break :label 256;
4 };
5 return result;
6}
7
8// error
9// backend=stage2
10// target=native
11//
12// :3:22: error: type 'u8' cannot represent integer value '256'
test/cases/compile_errors/invalid_if_expr_result_location_coercion.zig created+32
...@@ -0,0 +1,32 @@
1export fn invalidRuntimeThen(cond: bool) u0 {
2 const invalid: u16 = 256;
3 const result: u8 = if (cond) invalid else 0;
4 return result;
5}
6
7export fn invalidComptimeThen() u0 {
8 const invalid: u16 = 256;
9 const result: u8 = if (true) invalid else 0;
10 return result;
11}
12
13export fn invalidRuntimeElse(cond: bool) u0 {
14 const invalid: u16 = 256;
15 const result: u8 = if (cond) 0 else invalid;
16 return result;
17}
18
19export fn invalidComptimeElse() u0 {
20 const invalid: u16 = 256;
21 const result: u8 = if (false) 0 else invalid;
22 return result;
23}
24
25// error
26// backend=stage2
27// target=native
28//
29// :3:34: error: type 'u8' cannot represent integer value '256'
30// :9:34: error: type 'u8' cannot represent integer value '256'
31// :15:41: error: type 'u8' cannot represent integer value '256'
32// :21:42: error: type 'u8' cannot represent integer value '256'
test/cases/compile_errors/invalid_switch_expr_result_location_coercion.zig created+46
...@@ -0,0 +1,46 @@
1const Enum = enum(u8) { first, second, _ };
2
3export fn invalidFirstProng(enum_value: Enum) u8 {
4 const result: u8 = switch (enum_value) {
5 .first => 256,
6 .second => 0,
7 else => 0,
8 };
9 return result;
10}
11
12export fn invalidSecondProng(enum_value: Enum) u8 {
13 const result: u8 = switch (enum_value) {
14 .first => 0,
15 .second => 256,
16 _ => 0,
17 };
18 return result;
19}
20
21export fn invalidElseProng(enum_value: Enum) u8 {
22 const result: u8 = switch (enum_value) {
23 .first => 0,
24 .second => 0,
25 else => 256,
26 };
27 return result;
28}
29
30export fn invalidNonExhaustiveProng(enum_value: Enum) u8 {
31 const result: u8 = switch (enum_value) {
32 .first => 0,
33 .second => 0,
34 _ => 256,
35 };
36 return result;
37}
38
39// error
40// backend=stage2
41// target=native
42//
43// :5:19: error: type 'u8' cannot represent integer value '256'
44// :15:20: error: type 'u8' cannot represent integer value '256'
45// :25:17: error: type 'u8' cannot represent integer value '256'
46// :34:14: error: type 'u8' cannot represent integer value '256'