authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-13 01:54:57+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-16 11:26:33+00:00
log434537213e406191959818f573b24ca45c1b0e45
tree5892fc8f71a48ef1188cee96112a5d7a5706c14f
parentaba29f9789aff0c1ace2a1d0031818ec2c04070c
signaturelock-open Commit is signed but in an unrecognized format.

Sema: eliminate `src` field

`sema.src` is a failed experiment. It introduces complexity, and makes often unwarranted assumptions about the existence of instructions providing source locations, requiring an unreasonable amount of caution in AstGen for correctness. Eliminating it simplifies the whole frontend. This required adding source locations to a few instructions, but the cost in ZIR bytes should be counteracted by the other work on this branch.

5 files changed, 221 insertions(+), 204 deletions(-)

src/AstGen.zig+79-61
...@@ -2122,7 +2122,7 @@ fn restoreErrRetIndex(...@@ -2122,7 +2122,7 @@ fn restoreErrRetIndex(
2122 else => .none, // always restore/pop2122 else => .none, // always restore/pop
2123 },2123 },
2124 };2124 };
2125 _ = try gz.addRestoreErrRetIndex(bt, .{ .if_non_error = op });2125 _ = try gz.addRestoreErrRetIndex(bt, .{ .if_non_error = op }, node);
2126}2126}
21272127
2128fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref {2128fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref {
...@@ -2179,7 +2179,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn...@@ -2179,7 +2179,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn
21792179
2180 // As our last action before the break, "pop" the error trace if needed2180 // As our last action before the break, "pop" the error trace if needed
2181 if (!block_gz.is_comptime)2181 if (!block_gz.is_comptime)
2182 _ = try parent_gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always);2182 _ = try parent_gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, node);
21832183
2184 _ = try parent_gz.addBreak(break_tag, block_inst, .void_value);2184 _ = try parent_gz.addBreak(break_tag, block_inst, .void_value);
2185 return Zir.Inst.Ref.unreachable_value;2185 return Zir.Inst.Ref.unreachable_value;
...@@ -2271,7 +2271,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)...@@ -2271,7 +2271,7 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index)
22712271
2272 // As our last action before the continue, "pop" the error trace if needed2272 // As our last action before the continue, "pop" the error trace if needed
2273 if (!gen_zir.is_comptime)2273 if (!gen_zir.is_comptime)
2274 _ = try parent_gz.addRestoreErrRetIndex(.{ .block = continue_block }, .always);2274 _ = try parent_gz.addRestoreErrRetIndex(.{ .block = continue_block }, .always, node);
22752275
2276 _ = try parent_gz.addBreak(break_tag, continue_block, .void_value);2276 _ = try parent_gz.addBreak(break_tag, continue_block, .void_value);
2277 return Zir.Inst.Ref.unreachable_value;2277 return Zir.Inst.Ref.unreachable_value;
...@@ -2331,7 +2331,7 @@ fn blockExpr(...@@ -2331,7 +2331,7 @@ fn blockExpr(
23312331
2332 if (!block_scope.endsWithNoReturn()) {2332 if (!block_scope.endsWithNoReturn()) {
2333 // As our last action before the break, "pop" the error trace if needed2333 // As our last action before the break, "pop" the error trace if needed
2334 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always);2334 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
2335 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);2335 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);
2336 }2336 }
23372337
...@@ -2426,7 +2426,7 @@ fn labeledBlockExpr(...@@ -2426,7 +2426,7 @@ fn labeledBlockExpr(
2426 try blockExprStmts(&block_scope, &block_scope.base, statements);2426 try blockExprStmts(&block_scope, &block_scope.base, statements);
2427 if (!block_scope.endsWithNoReturn()) {2427 if (!block_scope.endsWithNoReturn()) {
2428 // As our last action before the return, "pop" the error trace if needed2428 // As our last action before the return, "pop" the error trace if needed
2429 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always);2429 _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node);
2430 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);2430 _ = try block_scope.addBreak(.@"break", block_inst, .void_value);
2431 }2431 }
24322432
...@@ -2818,7 +2818,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2818,7 +2818,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2818 .export_value,2818 .export_value,
2819 .set_eval_branch_quota,2819 .set_eval_branch_quota,
2820 .atomic_store,2820 .atomic_store,
2821 .store,
2822 .store_node,2821 .store_node,
2823 .store_to_inferred_ptr,2822 .store_to_inferred_ptr,
2824 .resolve_inferred_alloc,2823 .resolve_inferred_alloc,
...@@ -2829,7 +2828,8 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As...@@ -2829,7 +2828,8 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
2829 .validate_deref,2828 .validate_deref,
2830 .validate_destructure,2829 .validate_destructure,
2831 .save_err_ret_index,2830 .save_err_ret_index,
2832 .restore_err_ret_index,2831 .restore_err_ret_index_unconditional,
2832 .restore_err_ret_index_fn_entry,
2833 .validate_struct_init_ty,2833 .validate_struct_init_ty,
2834 .validate_struct_init_result_ty,2834 .validate_struct_init_result_ty,
2835 .validate_ptr_struct_init,2835 .validate_ptr_struct_init,
...@@ -3692,7 +3692,10 @@ fn assignOp(...@@ -3692,7 +3692,10 @@ fn assignOp(
3692 .lhs = lhs,3692 .lhs = lhs,
3693 .rhs = rhs,3693 .rhs = rhs,
3694 });3694 });
3695 _ = try gz.addBin(.store, lhs_ptr, result);3695 _ = try gz.addPlNode(.store_node, infix_node, Zir.Inst.Bin{
3696 .lhs = lhs_ptr,
3697 .rhs = result,
3698 });
3696}3699}
36973700
3698fn assignShift(3701fn assignShift(
...@@ -3715,7 +3718,10 @@ fn assignShift(...@@ -3715,7 +3718,10 @@ fn assignShift(
3715 .lhs = lhs,3718 .lhs = lhs,
3716 .rhs = rhs,3719 .rhs = rhs,
3717 });3720 });
3718 _ = try gz.addBin(.store, lhs_ptr, result);3721 _ = try gz.addPlNode(.store_node, infix_node, Zir.Inst.Bin{
3722 .lhs = lhs_ptr,
3723 .rhs = result,
3724 });
3719}3725}
37203726
3721fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerError!void {3727fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerError!void {
...@@ -3733,7 +3739,10 @@ fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerE...@@ -3733,7 +3739,10 @@ fn assignShiftSat(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerE
3733 .lhs = lhs,3739 .lhs = lhs,
3734 .rhs = rhs,3740 .rhs = rhs,
3735 });3741 });
3736 _ = try gz.addBin(.store, lhs_ptr, result);3742 _ = try gz.addPlNode(.store_node, infix_node, Zir.Inst.Bin{
3743 .lhs = lhs_ptr,
3744 .rhs = result,
3745 });
3737}3746}
37383747
3739fn ptrType(3748fn ptrType(
...@@ -4294,7 +4303,7 @@ fn fnDecl(...@@ -4294,7 +4303,7 @@ fn fnDecl(
42944303
4295 if (!fn_gz.endsWithNoReturn()) {4304 if (!fn_gz.endsWithNoReturn()) {
4296 // As our last action before the return, "pop" the error trace if needed4305 // As our last action before the return, "pop" the error trace if needed
4297 _ = try gz.addRestoreErrRetIndex(.ret, .always);4306 _ = try gz.addRestoreErrRetIndex(.ret, .always, decl_node);
42984307
4299 // Add implicit return at end of function.4308 // Add implicit return at end of function.
4300 _ = try fn_gz.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));4309 _ = try fn_gz.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));
...@@ -4742,7 +4751,7 @@ fn testDecl(...@@ -4742,7 +4751,7 @@ fn testDecl(
4742 if (fn_block.isEmpty() or !fn_block.refIsNoReturn(block_result)) {4751 if (fn_block.isEmpty() or !fn_block.refIsNoReturn(block_result)) {
47434752
4744 // As our last action before the return, "pop" the error trace if needed4753 // As our last action before the return, "pop" the error trace if needed
4745 _ = try gz.addRestoreErrRetIndex(.ret, .always);4754 _ = try gz.addRestoreErrRetIndex(.ret, .always, node);
47464755
4747 // Add implicit return at end of function.4756 // Add implicit return at end of function.
4748 _ = try fn_block.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));4757 _ = try fn_block.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));
...@@ -6149,7 +6158,7 @@ fn boolBinOp(...@@ -6149,7 +6158,7 @@ fn boolBinOp(
6149 const node_datas = tree.nodes.items(.data);6158 const node_datas = tree.nodes.items(.data);
61506159
6151 const lhs = try expr(gz, scope, bool_ri, node_datas[node].lhs);6160 const lhs = try expr(gz, scope, bool_ri, node_datas[node].lhs);
6152 const bool_br = try gz.addBoolBr(zir_tag, lhs);6161 const bool_br = (try gz.addPlNodePayloadIndex(zir_tag, node, undefined)).toIndex().?;
61536162
6154 var rhs_scope = gz.makeSubBlock(scope);6163 var rhs_scope = gz.makeSubBlock(scope);
6155 defer rhs_scope.unstack();6164 defer rhs_scope.unstack();
...@@ -6157,7 +6166,7 @@ fn boolBinOp(...@@ -6157,7 +6166,7 @@ fn boolBinOp(
6157 if (!gz.refIsNoReturn(rhs)) {6166 if (!gz.refIsNoReturn(rhs)) {
6158 _ = try rhs_scope.addBreakWithSrcNode(.break_inline, bool_br, rhs, node_datas[node].rhs);6167 _ = try rhs_scope.addBreakWithSrcNode(.break_inline, bool_br, rhs, node_datas[node].rhs);
6159 }6168 }
6160 try rhs_scope.setBoolBrBody(bool_br);6169 try rhs_scope.setBoolBrBody(bool_br, lhs);
61616170
6162 const block_ref = bool_br.toRef();6171 const block_ref = bool_br.toRef();
6163 return rvalue(gz, ri, block_ref, node);6172 return rvalue(gz, ri, block_ref, node);
...@@ -6725,7 +6734,10 @@ fn forExpr(...@@ -6725,7 +6734,10 @@ fn forExpr(
6725 const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc;6734 const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc;
6726 const index_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node);6735 const index_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node);
6727 // initialize to zero6736 // initialize to zero
6728 _ = try parent_gz.addBin(.store, index_ptr, .zero_usize);6737 _ = try parent_gz.addPlNode(.store_node, node, Zir.Inst.Bin{
6738 .lhs = index_ptr,
6739 .rhs = .zero_usize,
6740 });
6729 break :blk index_ptr;6741 break :blk index_ptr;
6730 };6742 };
67316743
...@@ -6955,7 +6967,10 @@ fn forExpr(...@@ -6955,7 +6967,10 @@ fn forExpr(
6955 .lhs = index,6967 .lhs = index,
6956 .rhs = .one_usize,6968 .rhs = .one_usize,
6957 });6969 });
6958 _ = try loop_scope.addBin(.store, index_ptr, index_plus_one);6970 _ = try loop_scope.addPlNode(.store_node, node, Zir.Inst.Bin{
6971 .lhs = index_ptr,
6972 .rhs = index_plus_one,
6973 });
6959 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;6974 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
6960 _ = try loop_scope.addNode(repeat_tag, node);6975 _ = try loop_scope.addNode(repeat_tag, node);
69616976
...@@ -8008,7 +8023,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -8008,7 +8023,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
8008 try genDefers(gz, defer_outer, scope, .normal_only);8023 try genDefers(gz, defer_outer, scope, .normal_only);
80098024
8010 // As our last action before the return, "pop" the error trace if needed8025 // As our last action before the return, "pop" the error trace if needed
8011 _ = try gz.addRestoreErrRetIndex(.ret, .always);8026 _ = try gz.addRestoreErrRetIndex(.ret, .always, node);
80128027
8013 _ = try gz.addUnNode(.ret_node, .void_value, node);8028 _ = try gz.addUnNode(.ret_node, .void_value, node);
8014 return Zir.Inst.Ref.unreachable_value;8029 return Zir.Inst.Ref.unreachable_value;
...@@ -8051,7 +8066,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -8051,7 +8066,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
8051 try genDefers(gz, defer_outer, scope, .normal_only);8066 try genDefers(gz, defer_outer, scope, .normal_only);
80528067
8053 // As our last action before the return, "pop" the error trace if needed8068 // As our last action before the return, "pop" the error trace if needed
8054 _ = try gz.addRestoreErrRetIndex(.ret, .always);8069 _ = try gz.addRestoreErrRetIndex(.ret, .always, node);
80558070
8056 try emitDbgStmt(gz, ret_lc);8071 try emitDbgStmt(gz, ret_lc);
8057 try gz.addRet(ri, operand, node);8072 try gz.addRet(ri, operand, node);
...@@ -8074,7 +8089,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -8074,7 +8089,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
80748089
8075 // As our last action before the return, "pop" the error trace if needed8090 // As our last action before the return, "pop" the error trace if needed
8076 const result = if (ri.rl == .ptr) try gz.addUnNode(.load, ri.rl.ptr.inst, node) else operand;8091 const result = if (ri.rl == .ptr) try gz.addUnNode(.load, ri.rl.ptr.inst, node) else operand;
8077 _ = try gz.addRestoreErrRetIndex(.ret, .{ .if_non_error = result });8092 _ = try gz.addRestoreErrRetIndex(.ret, .{ .if_non_error = result }, node);
80788093
8079 try gz.addRet(ri, operand, node);8094 try gz.addRet(ri, operand, node);
8080 return Zir.Inst.Ref.unreachable_value;8095 return Zir.Inst.Ref.unreachable_value;
...@@ -8091,7 +8106,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -8091,7 +8106,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
8091 try genDefers(&then_scope, defer_outer, scope, .normal_only);8106 try genDefers(&then_scope, defer_outer, scope, .normal_only);
80928107
8093 // As our last action before the return, "pop" the error trace if needed8108 // As our last action before the return, "pop" the error trace if needed
8094 _ = try then_scope.addRestoreErrRetIndex(.ret, .always);8109 _ = try then_scope.addRestoreErrRetIndex(.ret, .always, node);
80958110
8096 try emitDbgStmt(&then_scope, ret_lc);8111 try emitDbgStmt(&then_scope, ret_lc);
8097 try then_scope.addRet(ri, operand, node);8112 try then_scope.addRet(ri, operand, node);
...@@ -10979,7 +10994,10 @@ fn rvalueInner(...@@ -10979,7 +10994,10 @@ fn rvalueInner(
10979 return .void_value;10994 return .void_value;
10980 },10995 },
10981 .inferred_ptr => |alloc| {10996 .inferred_ptr => |alloc| {
10982 _ = try gz.addBin(.store_to_inferred_ptr, alloc, result);10997 _ = try gz.addPlNode(.store_to_inferred_ptr, src_node, Zir.Inst.Bin{
10998 .lhs = alloc,
10999 .rhs = result,
11000 });
10983 return .void_value;11001 return .void_value;
10984 },11002 },
10985 .destructure => |destructure| {11003 .destructure => |destructure| {
...@@ -11006,7 +11024,10 @@ fn rvalueInner(...@@ -11006,7 +11024,10 @@ fn rvalueInner(
11006 });11024 });
11007 },11025 },
11008 .inferred_ptr => |ptr_inst| {11026 .inferred_ptr => |ptr_inst| {
11009 _ = try gz.addBin(.store_to_inferred_ptr, ptr_inst, elem_val);11027 _ = try gz.addPlNode(.store_to_inferred_ptr, src_node, Zir.Inst.Bin{
11028 .lhs = ptr_inst,
11029 .rhs = elem_val,
11030 });
11010 },11031 },
11011 .discard => unreachable,11032 .discard => unreachable,
11012 }11033 }
...@@ -11828,19 +11849,20 @@ const GenZir = struct {...@@ -11828,19 +11849,20 @@ const GenZir = struct {
11828 }11849 }
1182911850
11830 /// Assumes nothing stacked on `gz`. Unstacks `gz`.11851 /// Assumes nothing stacked on `gz`. Unstacks `gz`.
11831 fn setBoolBrBody(gz: *GenZir, inst: Zir.Inst.Index) !void {11852 fn setBoolBrBody(gz: *GenZir, bool_br: Zir.Inst.Index, bool_br_lhs: Zir.Inst.Ref) !void {
11832 const astgen = gz.astgen;11853 const astgen = gz.astgen;
11833 const gpa = astgen.gpa;11854 const gpa = astgen.gpa;
11834 const body = gz.instructionsSlice();11855 const body = gz.instructionsSlice();
11835 const body_len = astgen.countBodyLenAfterFixups(body);11856 const body_len = astgen.countBodyLenAfterFixups(body);
11836 try astgen.extra.ensureUnusedCapacity(11857 try astgen.extra.ensureUnusedCapacity(
11837 gpa,11858 gpa,
11838 @typeInfo(Zir.Inst.Block).Struct.fields.len + body_len,11859 @typeInfo(Zir.Inst.BoolBr).Struct.fields.len + body_len,
11839 );11860 );
11840 const zir_datas = astgen.instructions.items(.data);11861 const zir_datas = astgen.instructions.items(.data);
11841 zir_datas[@intFromEnum(inst)].bool_br.payload_index = astgen.addExtraAssumeCapacity(11862 zir_datas[@intFromEnum(bool_br)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.BoolBr{
11842 Zir.Inst.Block{ .body_len = body_len },11863 .lhs = bool_br_lhs,
11843 );11864 .body_len = body_len,
11865 });
11844 astgen.appendBodyWithFixups(body);11866 astgen.appendBodyWithFixups(body);
11845 gz.unstack();11867 gz.unstack();
11846 }11868 }
...@@ -12225,30 +12247,6 @@ const GenZir = struct {...@@ -12225,30 +12247,6 @@ const GenZir = struct {
12225 return new_index.toRef();12247 return new_index.toRef();
12226 }12248 }
1222712249
12228 /// Note that this returns a `Zir.Inst.Index` not a ref.
12229 /// Leaves the `payload_index` field undefined.
12230 fn addBoolBr(
12231 gz: *GenZir,
12232 tag: Zir.Inst.Tag,
12233 lhs: Zir.Inst.Ref,
12234 ) !Zir.Inst.Index {
12235 assert(lhs != .none);
12236 const gpa = gz.astgen.gpa;
12237 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12238 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
12239
12240 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
12241 gz.astgen.instructions.appendAssumeCapacity(.{
12242 .tag = tag,
12243 .data = .{ .bool_br = .{
12244 .lhs = lhs,
12245 .payload_index = undefined,
12246 } },
12247 });
12248 gz.instructions.appendAssumeCapacity(new_index);
12249 return new_index;
12250 }
12251
12252 fn addInt(gz: *GenZir, integer: u64) !Zir.Inst.Ref {12250 fn addInt(gz: *GenZir, integer: u64) !Zir.Inst.Ref {
12253 return gz.add(.{12251 return gz.add(.{
12254 .tag = .int,12252 .tag = .int,
...@@ -12569,17 +12567,37 @@ const GenZir = struct {...@@ -12569,17 +12567,37 @@ const GenZir = struct {
12569 always: void,12567 always: void,
12570 if_non_error: Zir.Inst.Ref,12568 if_non_error: Zir.Inst.Ref,
12571 },12569 },
12570 src_node: Ast.Node.Index,
12572 ) !Zir.Inst.Index {12571 ) !Zir.Inst.Index {
12573 return gz.addAsIndex(.{12572 switch (cond) {
12574 .tag = .restore_err_ret_index,12573 .always => return gz.addAsIndex(.{
12575 .data = .{ .restore_err_ret_index = .{12574 .tag = .restore_err_ret_index_unconditional,
12576 .block = switch (bt) {12575 .data = .{ .un_node = .{
12577 .ret => .none,12576 .operand = switch (bt) {
12578 .block => |b| b.toRef(),12577 .ret => .none,
12579 },12578 .block => |b| b.toRef(),
12580 .operand = if (cond == .if_non_error) cond.if_non_error else .none,12579 },
12581 } },12580 .src_node = gz.nodeIndexToRelative(src_node),
12582 });12581 } },
12582 }),
12583 .if_non_error => |operand| switch (bt) {
12584 .ret => return gz.addAsIndex(.{
12585 .tag = .restore_err_ret_index_fn_entry,
12586 .data = .{ .un_node = .{
12587 .operand = operand,
12588 .src_node = gz.nodeIndexToRelative(src_node),
12589 } },
12590 }),
12591 .block => |block| return (try gz.addExtendedPayload(
12592 .restore_err_ret_index,
12593 Zir.Inst.RestoreErrRetIndex{
12594 .src_node = gz.nodeIndexToRelative(src_node),
12595 .block = block.toRef(),
12596 .operand = operand,
12597 },
12598 )).toIndex().?,
12599 },
12600 }
12583 }12601 }
1258412602
12585 fn addBreak(12603 fn addBreak(
src/Autodoc.zig+3-3
...@@ -1799,7 +1799,8 @@ fn walkInstruction(...@@ -1799,7 +1799,8 @@ fn walkInstruction(
1799 };1799 };
1800 },1800 },
1801 .bool_br_and, .bool_br_or => {1801 .bool_br_and, .bool_br_or => {
1802 const bool_br = data[@intFromEnum(inst)].bool_br;1802 const pl_node = data[@intFromEnum(inst)].pl_node;
1803 const extra = file.zir.extraData(Zir.Inst.BoolBr, pl_node.payload_index);
18031804
1804 const bin_index = self.exprs.items.len;1805 const bin_index = self.exprs.items.len;
1805 try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });1806 try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
...@@ -1808,14 +1809,13 @@ fn walkInstruction(...@@ -1808,14 +1809,13 @@ fn walkInstruction(
1808 file,1809 file,
1809 parent_scope,1810 parent_scope,
1810 parent_src,1811 parent_src,
1811 bool_br.lhs,1812 extra.data.lhs,
1812 false,1813 false,
1813 call_ctx,1814 call_ctx,
1814 );1815 );
1815 const lhs_index = self.exprs.items.len;1816 const lhs_index = self.exprs.items.len;
1816 try self.exprs.append(self.arena, lhs.expr);1817 try self.exprs.append(self.arena, lhs.expr);
18171818
1818 const extra = file.zir.extraData(Zir.Inst.Block, bool_br.payload_index);
1819 const rhs = try self.walkInstruction(1819 const rhs = try self.walkInstruction(
1820 file,1820 file,
1821 parent_scope,1821 parent_scope,
src/Sema.zig+71-86
...@@ -50,11 +50,6 @@ branch_count: u32 = 0,...@@ -50,11 +50,6 @@ branch_count: u32 = 0,
50/// Populated when returning `error.ComptimeBreak`. Used to communicate the50/// Populated when returning `error.ComptimeBreak`. Used to communicate the
51/// break instruction up the stack to find the corresponding Block.51/// break instruction up the stack to find the corresponding Block.
52comptime_break_inst: Zir.Inst.Index = undefined,52comptime_break_inst: Zir.Inst.Index = undefined,
53/// This field is updated when a new source location becomes active, so that
54/// instructions which do not have explicitly mapped source locations still have
55/// access to the source location set by the previous instruction which did
56/// contain a mapped source location.
57src: LazySrcLoc = .{ .token_offset = 0 },
58decl_val_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Air.Inst.Ref) = .{},53decl_val_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Air.Inst.Ref) = .{},
59/// When doing a generic function instantiation, this array collects a value54/// When doing a generic function instantiation, this array collects a value
60/// for each parameter of the generic owner. `none` for non-comptime parameters.55/// for each parameter of the generic owner. `none` for non-comptime parameters.
...@@ -1006,10 +1001,10 @@ fn analyzeBodyInner(...@@ -1006,10 +1001,10 @@ fn analyzeBodyInner(
1006 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {1001 const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) {
1007 // zig fmt: off1002 // zig fmt: off
1008 .alloc => try sema.zirAlloc(block, inst),1003 .alloc => try sema.zirAlloc(block, inst),
1009 .alloc_inferred => try sema.zirAllocInferred(block, inst, true),1004 .alloc_inferred => try sema.zirAllocInferred(block, true),
1010 .alloc_inferred_mut => try sema.zirAllocInferred(block, inst, false),1005 .alloc_inferred_mut => try sema.zirAllocInferred(block, false),
1011 .alloc_inferred_comptime => try sema.zirAllocInferredComptime(inst, true),1006 .alloc_inferred_comptime => try sema.zirAllocInferredComptime(true),
1012 .alloc_inferred_comptime_mut => try sema.zirAllocInferredComptime(inst, false),1007 .alloc_inferred_comptime_mut => try sema.zirAllocInferredComptime(false),
1013 .alloc_mut => try sema.zirAllocMut(block, inst),1008 .alloc_mut => try sema.zirAllocMut(block, inst),
1014 .alloc_comptime_mut => try sema.zirAllocComptime(block, inst),1009 .alloc_comptime_mut => try sema.zirAllocComptime(block, inst),
1015 .make_ptr_const => try sema.zirMakePtrConst(block, inst),1010 .make_ptr_const => try sema.zirMakePtrConst(block, inst),
...@@ -1308,6 +1303,11 @@ fn analyzeBodyInner(...@@ -1308,6 +1303,11 @@ fn analyzeBodyInner(
1308 i += 1;1303 i += 1;
1309 continue;1304 continue;
1310 },1305 },
1306 .restore_err_ret_index => {
1307 try sema.zirRestoreErrRetIndex(block, extended);
1308 i += 1;
1309 continue;
1310 },
1311 .value_placeholder => unreachable, // never appears in a body1311 .value_placeholder => unreachable, // never appears in a body
1312 };1312 };
1313 },1313 },
...@@ -1369,11 +1369,6 @@ fn analyzeBodyInner(...@@ -1369,11 +1369,6 @@ fn analyzeBodyInner(
1369 i += 1;1369 i += 1;
1370 continue;1370 continue;
1371 },1371 },
1372 .store => {
1373 try sema.zirStore(block, inst);
1374 i += 1;
1375 continue;
1376 },
1377 .store_node => {1372 .store_node => {
1378 try sema.zirStoreNode(block, inst);1373 try sema.zirStoreNode(block, inst);
1379 i += 1;1374 i += 1;
...@@ -1518,8 +1513,15 @@ fn analyzeBodyInner(...@@ -1518,8 +1513,15 @@ fn analyzeBodyInner(
1518 i += 1;1513 i += 1;
1519 continue;1514 continue;
1520 },1515 },
1521 .restore_err_ret_index => {1516 .restore_err_ret_index_unconditional => {
1522 try sema.zirRestoreErrRetIndex(block, inst);1517 const un_node = datas[@intFromEnum(inst)].un_node;
1518 try sema.restoreErrRetIndex(block, un_node.src(), un_node.operand, .none);
1519 i += 1;
1520 continue;
1521 },
1522 .restore_err_ret_index_fn_entry => {
1523 const un_node = datas[@intFromEnum(inst)].un_node;
1524 try sema.restoreErrRetIndex(block, un_node.src(), .none, un_node.operand);
1523 i += 1;1525 i += 1;
1524 continue;1526 continue;
1525 },1527 },
...@@ -2779,7 +2781,7 @@ fn zirStructDecl(...@@ -2779,7 +2781,7 @@ fn zirStructDecl(
2779 const src: LazySrcLoc = if (small.has_src_node) blk: {2781 const src: LazySrcLoc = if (small.has_src_node) blk: {
2780 const node_offset: i32 = @bitCast(sema.code.extra[extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len]);2782 const node_offset: i32 = @bitCast(sema.code.extra[extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len]);
2781 break :blk LazySrcLoc.nodeOffset(node_offset);2783 break :blk LazySrcLoc.nodeOffset(node_offset);
2782 } else sema.src;2784 } else unreachable; // MLUGG TODO
27832785
2784 // Because these three things each reference each other, `undefined`2786 // Because these three things each reference each other, `undefined`
2785 // placeholders are used before being set after the struct type gains an2787 // placeholders are used before being set after the struct type gains an
...@@ -2945,7 +2947,7 @@ fn zirEnumDecl(...@@ -2945,7 +2947,7 @@ fn zirEnumDecl(
2945 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);2947 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);
2946 extra_index += 1;2948 extra_index += 1;
2947 break :blk LazySrcLoc.nodeOffset(node_offset);2949 break :blk LazySrcLoc.nodeOffset(node_offset);
2948 } else sema.src;2950 } else unreachable; // MLUGG TODO
2949 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };2951 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
29502952
2951 const tag_type_ref = if (small.has_tag_type) blk: {2953 const tag_type_ref = if (small.has_tag_type) blk: {
...@@ -3218,7 +3220,7 @@ fn zirUnionDecl(...@@ -3218,7 +3220,7 @@ fn zirUnionDecl(
3218 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);3220 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);
3219 extra_index += 1;3221 extra_index += 1;
3220 break :blk LazySrcLoc.nodeOffset(node_offset);3222 break :blk LazySrcLoc.nodeOffset(node_offset);
3221 } else sema.src;3223 } else unreachable; // MLUGG TODO
32223224
3223 extra_index += @intFromBool(small.has_tag_type);3225 extra_index += @intFromBool(small.has_tag_type);
3224 extra_index += @intFromBool(small.has_body_len);3226 extra_index += @intFromBool(small.has_body_len);
...@@ -3327,7 +3329,7 @@ fn zirOpaqueDecl(...@@ -3327,7 +3329,7 @@ fn zirOpaqueDecl(
3327 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);3329 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);
3328 extra_index += 1;3330 extra_index += 1;
3329 break :blk LazySrcLoc.nodeOffset(node_offset);3331 break :blk LazySrcLoc.nodeOffset(node_offset);
3330 } else sema.src;3332 } else unreachable; // MLUGG TODO
33313333
3332 const decls_len = if (small.has_decls_len) blk: {3334 const decls_len = if (small.has_decls_len) blk: {
3333 const decls_len = sema.code.extra[extra_index];3335 const decls_len = sema.code.extra[extra_index];
...@@ -3977,13 +3979,9 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai...@@ -3977,13 +3979,9 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai
39773979
3978fn zirAllocInferredComptime(3980fn zirAllocInferredComptime(
3979 sema: *Sema,3981 sema: *Sema,
3980 inst: Zir.Inst.Index,
3981 is_const: bool,3982 is_const: bool,
3982) CompileError!Air.Inst.Ref {3983) CompileError!Air.Inst.Ref {
3983 const gpa = sema.gpa;3984 const gpa = sema.gpa;
3984 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
3985 const src = LazySrcLoc.nodeOffset(src_node);
3986 sema.src = src;
39873985
3988 try sema.air_instructions.append(gpa, .{3986 try sema.air_instructions.append(gpa, .{
3989 .tag = .inferred_alloc_comptime,3987 .tag = .inferred_alloc_comptime,
...@@ -4042,16 +4040,12 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -4042,16 +4040,12 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
4042fn zirAllocInferred(4040fn zirAllocInferred(
4043 sema: *Sema,4041 sema: *Sema,
4044 block: *Block,4042 block: *Block,
4045 inst: Zir.Inst.Index,
4046 is_const: bool,4043 is_const: bool,
4047) CompileError!Air.Inst.Ref {4044) CompileError!Air.Inst.Ref {
4048 const tracy = trace(@src());4045 const tracy = trace(@src());
4049 defer tracy.end();4046 defer tracy.end();
40504047
4051 const gpa = sema.gpa;4048 const gpa = sema.gpa;
4052 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
4053 const src = LazySrcLoc.nodeOffset(src_node);
4054 sema.src = src;
40554049
4056 if (block.is_comptime) {4050 if (block.is_comptime) {
4057 try sema.air_instructions.append(gpa, .{4051 try sema.air_instructions.append(gpa, .{
...@@ -5428,10 +5422,11 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -5428,10 +5422,11 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
5428 const tracy = trace(@src());5422 const tracy = trace(@src());
5429 defer tracy.end();5423 defer tracy.end();
54305424
5431 const src: LazySrcLoc = sema.src;5425 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5432 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;5426 const src = pl_node.src();
5433 const ptr = try sema.resolveInst(bin_inst.lhs);5427 const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
5434 const operand = try sema.resolveInst(bin_inst.rhs);5428 const ptr = try sema.resolveInst(bin.lhs);
5429 const operand = try sema.resolveInst(bin.rhs);
5435 const ptr_inst = ptr.toIndex().?;5430 const ptr_inst = ptr.toIndex().?;
5436 const air_datas = sema.air_instructions.items(.data);5431 const air_datas = sema.air_instructions.items(.data);
54375432
...@@ -5496,16 +5491,6 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -5496,16 +5491,6 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
5496 sema.branch_quota = @max(sema.branch_quota, quota);5491 sema.branch_quota = @max(sema.branch_quota, quota);
5497}5492}
54985493
5499fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5500 const tracy = trace(@src());
5501 defer tracy.end();
5502
5503 const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
5504 const ptr = try sema.resolveInst(bin_inst.lhs);
5505 const value = try sema.resolveInst(bin_inst.rhs);
5506 return sema.storePtr(block, sema.src, ptr, value);
5507}
5508
5509fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5494fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5510 const tracy = trace(@src());5495 const tracy = trace(@src());
5511 defer tracy.end();5496 defer tracy.end();
...@@ -5709,7 +5694,6 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I...@@ -5709,7 +5694,6 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I
5709fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {5694fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
5710 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;5695 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
5711 const src = LazySrcLoc.nodeOffset(src_node);5696 const src = LazySrcLoc.nodeOffset(src_node);
5712 sema.src = src;
5713 if (block.is_comptime)5697 if (block.is_comptime)
5714 return sema.fail(block, src, "encountered @trap at comptime", .{});5698 return sema.fail(block, src, "encountered @trap at comptime", .{});
5715 _ = try block.addNoOp(.trap);5699 _ = try block.addNoOp(.trap);
...@@ -6384,10 +6368,6 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6384,10 +6368,6 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
6384}6368}
63856369
6386fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {6370fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
6387 // We do not set sema.src here because dbg_stmt instructions are only emitted for
6388 // ZIR code that possibly will need to generate runtime code. So error messages
6389 // and other source locations must not rely on sema.src being set from dbg_stmt
6390 // instructions.
6391 if (block.is_comptime or block.ownerModule().strip) return;6371 if (block.is_comptime or block.ownerModule().strip) return;
63926372
6393 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;6373 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
...@@ -6632,7 +6612,6 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {...@@ -6632,7 +6612,6 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {
6632pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {6612pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {
6633 const mod = sema.mod;6613 const mod = sema.mod;
6634 const gpa = sema.gpa;6614 const gpa = sema.gpa;
6635 const src = sema.src;
66366615
6637 if (block.is_comptime or block.is_typeof) {6616 if (block.is_comptime or block.is_typeof) {
6638 const index_val = try mod.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len);6617 const index_val = try mod.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len);
...@@ -6650,9 +6629,10 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6650,9 +6629,10 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6650 else => |e| return e,6629 else => |e| return e,
6651 };6630 };
6652 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");6631 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");
6653 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, src) catch |err| switch (err) {6632 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {
6654 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6633 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),
6655 else => |e| return e,6634 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6635 error.OutOfMemory => |e| return e,
6656 };6636 };
66576637
6658 return try block.addInst(.{6638 return try block.addInst(.{
...@@ -9900,7 +9880,6 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -9900,7 +9880,6 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
9900 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;9880 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
9901 const src = inst_data.src();9881 const src = inst_data.src();
9902 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;9882 const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
9903 sema.src = src;
9904 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);9883 return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false);
9905}9884}
99069885
...@@ -10855,7 +10834,7 @@ const SwitchProngAnalysis = struct {...@@ -10855,7 +10834,7 @@ const SwitchProngAnalysis = struct {
10855 .address_space = operand_ptr_ty.ptrAddressSpace(mod),10834 .address_space = operand_ptr_ty.ptrAddressSpace(mod),
10856 },10835 },
10857 });10836 });
10858 if (try sema.resolveDefinedValue(block, sema.src, spa.operand_ptr)) |union_ptr| {10837 if (try sema.resolveDefinedValue(block, operand_src, spa.operand_ptr)) |union_ptr| {
10859 return Air.internedToRef((try mod.intern(.{ .ptr = .{10838 return Air.internedToRef((try mod.intern(.{ .ptr = .{
10860 .ty = ptr_field_ty.toIntern(),10839 .ty = ptr_field_ty.toIntern(),
10861 .addr = .{ .field = .{10840 .addr = .{ .field = .{
...@@ -10866,7 +10845,7 @@ const SwitchProngAnalysis = struct {...@@ -10866,7 +10845,7 @@ const SwitchProngAnalysis = struct {
10866 }10845 }
10867 return block.addStructFieldPtr(spa.operand_ptr, field_index, ptr_field_ty);10846 return block.addStructFieldPtr(spa.operand_ptr, field_index, ptr_field_ty);
10868 } else {10847 } else {
10869 if (try sema.resolveDefinedValue(block, sema.src, spa.operand)) |union_val| {10848 if (try sema.resolveDefinedValue(block, operand_src, spa.operand)) |union_val| {
10870 const tag_and_val = ip.indexToKey(union_val.toIntern()).un;10849 const tag_and_val = ip.indexToKey(union_val.toIntern()).un;
10871 return Air.internedToRef(tag_and_val.val);10850 return Air.internedToRef(tag_and_val.val);
10872 }10851 }
...@@ -13191,6 +13170,7 @@ fn validateErrSetSwitch(...@@ -13191,6 +13170,7 @@ fn validateErrSetSwitch(
13191 // else => |e| return e,13170 // else => |e| return e,
13192 // even if all the possible errors were already handled.13171 // even if all the possible errors were already handled.
13193 const tags = sema.code.instructions.items(.tag);13172 const tags = sema.code.instructions.items(.tag);
13173 const datas = sema.code.instructions.items(.data);
13194 for (else_case.body) |else_inst| switch (tags[@intFromEnum(else_inst)]) {13174 for (else_case.body) |else_inst| switch (tags[@intFromEnum(else_inst)]) {
13195 .dbg_block_begin,13175 .dbg_block_begin,
13196 .dbg_block_end,13176 .dbg_block_end,
...@@ -13205,11 +13185,16 @@ fn validateErrSetSwitch(...@@ -13205,11 +13185,16 @@ fn validateErrSetSwitch(
13205 .err_union_code,13185 .err_union_code,
13206 .ret_err_value_code,13186 .ret_err_value_code,
13207 .save_err_ret_index,13187 .save_err_ret_index,
13208 .restore_err_ret_index,13188 .restore_err_ret_index_unconditional,
13189 .restore_err_ret_index_fn_entry,
13209 .is_non_err,13190 .is_non_err,
13210 .ret_is_non_err,13191 .ret_is_non_err,
13211 .condbr,13192 .condbr,
13212 => {},13193 => {},
13194 .extended => switch (datas[@intFromEnum(else_inst)].extended.opcode) {
13195 .restore_err_ret_index => {},
13196 else => break,
13197 },
13213 else => break,13198 else => break,
13214 } else break :else_validation;13199 } else break :else_validation;
1321513200
...@@ -13707,7 +13692,6 @@ fn zirShl(...@@ -13707,7 +13692,6 @@ fn zirShl(
13707 const mod = sema.mod;13692 const mod = sema.mod;
13708 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13693 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13709 const src = inst_data.src();13694 const src = inst_data.src();
13710 sema.src = src;
13711 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };13695 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
13712 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };13696 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
13713 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13697 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -13878,7 +13862,6 @@ fn zirShr(...@@ -13878,7 +13862,6 @@ fn zirShr(
13878 const mod = sema.mod;13862 const mod = sema.mod;
13879 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13863 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13880 const src = inst_data.src();13864 const src = inst_data.src();
13881 sema.src = src;
13882 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };13865 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
13883 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };13866 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
13884 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13867 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -14014,7 +13997,6 @@ fn zirBitwise(...@@ -14014,7 +13997,6 @@ fn zirBitwise(
14014 const mod = sema.mod;13997 const mod = sema.mod;
14015 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13998 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14016 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };13999 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14017 sema.src = src;
14018 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14000 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14019 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14001 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14020 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14002 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -14795,21 +14777,20 @@ fn zirArithmetic(...@@ -14795,21 +14777,20 @@ fn zirArithmetic(
14795 defer tracy.end();14777 defer tracy.end();
1479614778
14797 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14779 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14798 sema.src = .{ .node_offset_bin_op = inst_data.src_node };14780 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14799 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14781 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14800 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14782 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14801 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14783 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14802 const lhs = try sema.resolveInst(extra.lhs);14784 const lhs = try sema.resolveInst(extra.lhs);
14803 const rhs = try sema.resolveInst(extra.rhs);14785 const rhs = try sema.resolveInst(extra.rhs);
1480414786
14805 return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src, safety);14787 return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, src, lhs_src, rhs_src, safety);
14806}14788}
1480714789
14808fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {14790fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
14809 const mod = sema.mod;14791 const mod = sema.mod;
14810 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14792 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14811 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };14793 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14812 sema.src = src;
14813 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14794 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14814 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14795 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14815 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14796 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -14975,7 +14956,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14975,7 +14956,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14975 const mod = sema.mod;14956 const mod = sema.mod;
14976 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14957 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14977 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };14958 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14978 sema.src = src;
14979 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14959 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14980 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14960 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14981 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14961 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -15141,7 +15121,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15141,7 +15121,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15141 const mod = sema.mod;15121 const mod = sema.mod;
15142 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15122 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15143 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15123 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15144 sema.src = src;
15145 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15124 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15146 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15125 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15147 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15126 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -15252,7 +15231,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15252,7 +15231,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15252 const mod = sema.mod;15231 const mod = sema.mod;
15253 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15232 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15254 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15233 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15255 sema.src = src;
15256 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15234 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15257 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15235 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15258 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15236 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -15494,7 +15472,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15494,7 +15472,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15494 const mod = sema.mod;15472 const mod = sema.mod;
15495 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15473 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15496 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15474 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15497 sema.src = src;
15498 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15475 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15499 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15476 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15500 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15477 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -15679,7 +15656,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15679,7 +15656,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15679 const mod = sema.mod;15656 const mod = sema.mod;
15680 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15657 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15681 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15658 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15682 sema.src = src;
15683 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15659 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15684 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15660 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15685 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15661 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -15775,7 +15751,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15775,7 +15751,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15775 const mod = sema.mod;15751 const mod = sema.mod;
15776 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15777 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15753 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15778 sema.src = src;
15779 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15754 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15780 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15755 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15781 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15756 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -18741,13 +18716,16 @@ fn zirBoolBr(...@@ -18741,13 +18716,16 @@ fn zirBoolBr(
18741 defer tracy.end();18716 defer tracy.end();
1874218717
18743 const mod = sema.mod;18718 const mod = sema.mod;
18719 const gpa = sema.gpa;
18720
18744 const datas = sema.code.instructions.items(.data);18721 const datas = sema.code.instructions.items(.data);
18745 const inst_data = datas[@intFromEnum(inst)].bool_br;18722 const inst_data = datas[@intFromEnum(inst)].pl_node;
18746 const lhs = try sema.resolveInst(inst_data.lhs);18723 const extra = sema.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);
18747 const lhs_src = sema.src;18724
18748 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);18725 const lhs = try sema.resolveInst(extra.data.lhs);
18749 const body = sema.code.bodySlice(extra.end, extra.data.body_len);18726 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
18750 const gpa = sema.gpa;18727 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
18728 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
1875118729
18752 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {18730 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
18753 if (is_bool_or and lhs_val.toBool()) {18731 if (is_bool_or and lhs_val.toBool()) {
...@@ -18795,7 +18773,7 @@ fn zirBoolBr(...@@ -18795,7 +18773,7 @@ fn zirBoolBr(
1879518773
18796 const result = sema.finishCondBr(parent_block, &child_block, &then_block, &else_block, lhs, block_inst);18774 const result = sema.finishCondBr(parent_block, &child_block, &then_block, &else_block, lhs, block_inst);
18797 if (!sema.typeOf(rhs_result).isNoReturn(mod)) {18775 if (!sema.typeOf(rhs_result).isNoReturn(mod)) {
18798 if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| {18776 if (try sema.resolveDefinedValue(rhs_block, rhs_src, rhs_result)) |rhs_val| {
18799 if (is_bool_or and rhs_val.toBool()) {18777 if (is_bool_or and rhs_val.toBool()) {
18800 return .bool_true;18778 return .bool_true;
18801 } else if (!is_bool_or and !rhs_val.toBool()) {18779 } else if (!is_bool_or and !rhs_val.toBool()) {
...@@ -19375,17 +19353,21 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -19375,17 +19353,21 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
19375 block.error_return_trace_index = try sema.analyzeSaveErrRetIndex(block);19353 block.error_return_trace_index = try sema.analyzeSaveErrRetIndex(block);
19376}19354}
1937719355
19378fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void {19356fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
19379 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;19357 const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
19380 const src = sema.src; // TODO19358 return sema.restoreErrRetIndex(start_block, extra.src(), extra.block, extra.operand);
1938119359}
19382 const mod = sema.mod;
19383 const ip = &mod.intern_pool;
1938419360
19361/// If `operand` is non-error (or is `none`), restores the error return trace to
19362/// its state at the point `block` was reached (or, if `block` is `none`, the
19363/// point this function began execution).
19364fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_block: Zir.Inst.Ref, operand_zir: Zir.Inst.Ref) CompileError!void {
19385 const tracy = trace(@src());19365 const tracy = trace(@src());
19386 defer tracy.end();19366 defer tracy.end();
1938719367
19388 const saved_index = if (inst_data.block.toIndexAllowNone()) |zir_block| b: {19368 const mod = sema.mod;
19369
19370 const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: {
19389 var block = start_block;19371 var block = start_block;
19390 while (true) {19372 while (true) {
19391 if (block.label) |label| {19373 if (block.label) |label| {
...@@ -19409,7 +19391,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)...@@ -19409,7 +19391,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)
19409 return; // No need to restore19391 return; // No need to restore
19410 };19392 };
1941119393
19412 const operand = try sema.resolveInstAllowNone(inst_data.operand);19394 const operand = try sema.resolveInstAllowNone(operand_zir);
1941319395
19414 if (start_block.is_comptime or start_block.is_typeof) {19396 if (start_block.is_comptime or start_block.is_typeof) {
19415 const is_non_error = if (operand != .none) blk: {19397 const is_non_error = if (operand != .none) blk: {
...@@ -19427,7 +19409,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)...@@ -19427,7 +19409,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)
19427 return;19409 return;
19428 }19410 }
1942919411
19430 if (!ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return;19412 if (!mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return;
19431 if (!start_block.ownerModule().error_tracing) return;19413 if (!start_block.ownerModule().error_tracing) return;
1943219414
19433 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere19415 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere
...@@ -23161,7 +23143,6 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23161,7 +23143,6 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23161fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {23143fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
23162 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23144 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23163 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };23145 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
23164 sema.src = src;
23165 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };23146 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
23166 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };23147 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
23167 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;23148 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
...@@ -26416,12 +26397,16 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP...@@ -26416,12 +26397,16 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
26416 try sema.prepareSimplePanic(block);26397 try sema.prepareSimplePanic(block);
2641726398
26418 const panic_messages_ty = try sema.getBuiltinType("panic_messages");26399 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
26419 const msg_decl_index = (try sema.namespaceLookup(26400 const msg_decl_index = (sema.namespaceLookup(
26420 block,26401 block,
26421 sema.src,26402 .unneeded,
26422 panic_messages_ty.getNamespaceIndex(mod).unwrap().?,26403 panic_messages_ty.getNamespaceIndex(mod).unwrap().?,
26423 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)),26404 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)),
26424 )).?;26405 ) catch |err| switch (err) {
26406 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),
26407 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
26408 error.OutOfMemory => |e| return e,
26409 }).?;
26425 try sema.ensureDeclAnalyzed(msg_decl_index);26410 try sema.ensureDeclAnalyzed(msg_decl_index);
26426 mod.panic_messages[@intFromEnum(panic_id)] = msg_decl_index.toOptional();26411 mod.panic_messages[@intFromEnum(panic_id)] = msg_decl_index.toOptional();
26427 return msg_decl_index;26412 return msg_decl_index;
src/Zir.zig+52-33
...@@ -303,11 +303,11 @@ pub const Inst = struct {...@@ -303,11 +303,11 @@ pub const Inst = struct {
303 bool_not,303 bool_not,
304 /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand304 /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand
305 /// is a block, which is evaluated if `lhs` is `true`.305 /// is a block, which is evaluated if `lhs` is `true`.
306 /// Uses the `bool_br` union field.306 /// Uses the `pl_node` union field. Payload is `BoolBr`.
307 bool_br_and,307 bool_br_and,
308 /// Short-circuiting boolean `or`. `lhs` is a boolean `Ref` and the other operand308 /// Short-circuiting boolean `or`. `lhs` is a boolean `Ref` and the other operand
309 /// is a block, which is evaluated if `lhs` is `false`.309 /// is a block, which is evaluated if `lhs` is `false`.
310 /// Uses the `bool_br` union field.310 /// Uses the `pl_node` union field. Payload is `BoolBr`.
311 bool_br_or,311 bool_br_or,
312 /// Return a value from a block.312 /// Return a value from a block.
313 /// Uses the `break` union field.313 /// Uses the `break` union field.
...@@ -592,16 +592,12 @@ pub const Inst = struct {...@@ -592,16 +592,12 @@ pub const Inst = struct {
592 /// Returns a pointer to the subslice.592 /// Returns a pointer to the subslice.
593 /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceLength`.593 /// Uses the `pl_node` field. AST node is the slice syntax. Payload is `SliceLength`.
594 slice_length,594 slice_length,
595 /// Write a value to a pointer. For loading, see `load`.
596 /// Source location is assumed to be same as previous instruction.
597 /// Uses the `bin` union field.
598 store,
599 /// Same as `store` except provides a source location.595 /// Same as `store` except provides a source location.
600 /// Uses the `pl_node` union field. Payload is `Bin`.596 /// Uses the `pl_node` union field. Payload is `Bin`.
601 store_node,597 store_node,
602 /// Same as `store` but the type of the value being stored will be used to infer598 /// Same as `store_node` but the type of the value being stored will be
603 /// the pointer type.599 /// used to infer the pointer type of an `alloc_inferred`.
604 /// Uses the `bin` union field.600 /// Uses the `pl_node` union field. Payload is `Bin`.
605 store_to_inferred_ptr,601 store_to_inferred_ptr,
606 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.602 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
607 /// Uses the `str` union field.603 /// Uses the `str` union field.
...@@ -1036,10 +1032,18 @@ pub const Inst = struct {...@@ -1036,10 +1032,18 @@ pub const Inst = struct {
1036 /// block, if the operand is .none or of an error/error-union type.1032 /// block, if the operand is .none or of an error/error-union type.
1037 /// Uses the `save_err_ret_index` field.1033 /// Uses the `save_err_ret_index` field.
1038 save_err_ret_index,1034 save_err_ret_index,
1039 /// Sets error return trace to zero if no operand is given,1035 /// Specialized form of `Extended.restore_err_ret_index`.
1040 /// otherwise sets the value to the given amount.1036 /// Unconditionally restores the error return index to its last saved state
1041 /// Uses the `restore_err_ret_index` union field.1037 /// in the block referred to by `operand`. If `operand` is `none`, restores
1042 restore_err_ret_index,1038 /// to the point of function entry.
1039 /// Uses the `un_node` field.
1040 restore_err_ret_index_unconditional,
1041 /// Specialized form of `Extended.restore_err_ret_index`.
1042 /// Restores the error return index to its state at the entry of
1043 /// the current function conditional on `operand` being a non-error.
1044 /// If `operand` is `none`, restores unconditionally.
1045 /// Uses the `un_node` field.
1046 restore_err_ret_index_fn_entry,
10431047
1044 /// The ZIR instruction tag is one of the `Extended` ones.1048 /// The ZIR instruction tag is one of the `Extended` ones.
1045 /// Uses the `extended` union field.1049 /// Uses the `extended` union field.
...@@ -1145,7 +1149,6 @@ pub const Inst = struct {...@@ -1145,7 +1149,6 @@ pub const Inst = struct {
1145 .shl,1149 .shl,
1146 .shl_sat,1150 .shl_sat,
1147 .shr,1151 .shr,
1148 .store,
1149 .store_node,1152 .store_node,
1150 .store_to_inferred_ptr,1153 .store_to_inferred_ptr,
1151 .str,1154 .str,
...@@ -1265,7 +1268,6 @@ pub const Inst = struct {...@@ -1265,7 +1268,6 @@ pub const Inst = struct {
1265 .@"defer",1268 .@"defer",
1266 .defer_err_code,1269 .defer_err_code,
1267 .save_err_ret_index,1270 .save_err_ret_index,
1268 .restore_err_ret_index,
1269 .for_len,1271 .for_len,
1270 .opt_eu_base_ptr_init,1272 .opt_eu_base_ptr_init,
1271 .coerce_ptr_elem_ty,1273 .coerce_ptr_elem_ty,
...@@ -1290,6 +1292,8 @@ pub const Inst = struct {...@@ -1290,6 +1292,8 @@ pub const Inst = struct {
1290 .array_init_elem_type,1292 .array_init_elem_type,
1291 .array_init_elem_ptr,1293 .array_init_elem_ptr,
1292 .validate_ref_ty,1294 .validate_ref_ty,
1295 .restore_err_ret_index_unconditional,
1296 .restore_err_ret_index_fn_entry,
1293 => false,1297 => false,
12941298
1295 .@"break",1299 .@"break",
...@@ -1338,7 +1342,6 @@ pub const Inst = struct {...@@ -1338,7 +1342,6 @@ pub const Inst = struct {
1338 .ensure_err_union_payload_void,1342 .ensure_err_union_payload_void,
1339 .set_eval_branch_quota,1343 .set_eval_branch_quota,
1340 .atomic_store,1344 .atomic_store,
1341 .store,
1342 .store_node,1345 .store_node,
1343 .store_to_inferred_ptr,1346 .store_to_inferred_ptr,
1344 .resolve_inferred_alloc,1347 .resolve_inferred_alloc,
...@@ -1352,8 +1355,9 @@ pub const Inst = struct {...@@ -1352,8 +1355,9 @@ pub const Inst = struct {
1352 .check_comptime_control_flow,1355 .check_comptime_control_flow,
1353 .@"defer",1356 .@"defer",
1354 .defer_err_code,1357 .defer_err_code,
1355 .restore_err_ret_index,
1356 .save_err_ret_index,1358 .save_err_ret_index,
1359 .restore_err_ret_index_unconditional,
1360 .restore_err_ret_index_fn_entry,
1357 .validate_struct_init_ty,1361 .validate_struct_init_ty,
1358 .validate_struct_init_result_ty,1362 .validate_struct_init_result_ty,
1359 .validate_ptr_struct_init,1363 .validate_ptr_struct_init,
...@@ -1635,8 +1639,8 @@ pub const Inst = struct {...@@ -1635,8 +1639,8 @@ pub const Inst = struct {
1635 .declaration = .pl_node,1639 .declaration = .pl_node,
1636 .suspend_block = .pl_node,1640 .suspend_block = .pl_node,
1637 .bool_not = .un_node,1641 .bool_not = .un_node,
1638 .bool_br_and = .bool_br,1642 .bool_br_and = .pl_node,
1639 .bool_br_or = .bool_br,1643 .bool_br_or = .pl_node,
1640 .@"break" = .@"break",1644 .@"break" = .@"break",
1641 .break_inline = .@"break",1645 .break_inline = .@"break",
1642 .check_comptime_control_flow = .un_node,1646 .check_comptime_control_flow = .un_node,
...@@ -1713,9 +1717,8 @@ pub const Inst = struct {...@@ -1713,9 +1717,8 @@ pub const Inst = struct {
1713 .slice_end = .pl_node,1717 .slice_end = .pl_node,
1714 .slice_sentinel = .pl_node,1718 .slice_sentinel = .pl_node,
1715 .slice_length = .pl_node,1719 .slice_length = .pl_node,
1716 .store = .bin,
1717 .store_node = .pl_node,1720 .store_node = .pl_node,
1718 .store_to_inferred_ptr = .bin,1721 .store_to_inferred_ptr = .pl_node,
1719 .str = .str,1722 .str = .str,
1720 .negate = .un_node,1723 .negate = .un_node,
1721 .negate_wrap = .un_node,1724 .negate_wrap = .un_node,
...@@ -1845,7 +1848,8 @@ pub const Inst = struct {...@@ -1845,7 +1848,8 @@ pub const Inst = struct {
1845 .defer_err_code = .defer_err_code,1848 .defer_err_code = .defer_err_code,
18461849
1847 .save_err_ret_index = .save_err_ret_index,1850 .save_err_ret_index = .save_err_ret_index,
1848 .restore_err_ret_index = .restore_err_ret_index,1851 .restore_err_ret_index_unconditional = .un_node,
1852 .restore_err_ret_index_fn_entry = .un_node,
18491853
1850 .struct_init_empty = .un_node,1854 .struct_init_empty = .un_node,
1851 .struct_init_empty_result = .un_node,1855 .struct_init_empty_result = .un_node,
...@@ -2075,6 +2079,13 @@ pub const Inst = struct {...@@ -2075,6 +2079,13 @@ pub const Inst = struct {
2075 /// Implements the `@inComptime` builtin.2079 /// Implements the `@inComptime` builtin.
2076 /// `operand` is `src_node: i32`.2080 /// `operand` is `src_node: i32`.
2077 in_comptime,2081 in_comptime,
2082 /// Restores the error return index to its last saved state in a given
2083 /// block. If the block is `.none`, restores to the state from the point
2084 /// of function entry. If the operand is not `.none`, the restore is
2085 /// conditional on the operand value not being an error.
2086 /// `operand` is payload index to `RestoreErrRetIndex`.
2087 /// `small` is undefined.
2088 restore_err_ret_index,
2078 /// Used as a placeholder instruction which is just a dummy index for Sema to replace2089 /// Used as a placeholder instruction which is just a dummy index for Sema to replace
2079 /// with a specific value. For instance, this is used for the capture of an `errdefer`.2090 /// with a specific value. For instance, this is used for the capture of an `errdefer`.
2080 /// This should never appear in a body.2091 /// This should never appear in a body.
...@@ -2345,11 +2356,6 @@ pub const Inst = struct {...@@ -2345,11 +2356,6 @@ pub const Inst = struct {
2345 return LazySrcLoc.nodeOffset(self.src_node);2356 return LazySrcLoc.nodeOffset(self.src_node);
2346 }2357 }
2347 },2358 },
2348 bool_br: struct {
2349 lhs: Ref,
2350 /// Points to a `Block`.
2351 payload_index: u32,
2352 },
2353 @"unreachable": struct {2359 @"unreachable": struct {
2354 /// Offset from Decl AST node index.2360 /// Offset from Decl AST node index.
2355 /// `Tag` determines which kind of AST node this points to.2361 /// `Tag` determines which kind of AST node this points to.
...@@ -2396,10 +2402,6 @@ pub const Inst = struct {...@@ -2396,10 +2402,6 @@ pub const Inst = struct {
2396 save_err_ret_index: struct {2402 save_err_ret_index: struct {
2397 operand: Ref, // If error type (or .none), save new trace index2403 operand: Ref, // If error type (or .none), save new trace index
2398 },2404 },
2399 restore_err_ret_index: struct {
2400 block: Ref, // If restored, the index is from this block's entrypoint
2401 operand: Ref, // If non-error (or .none), then restore the index
2402 },
2403 elem_val_imm: struct {2405 elem_val_imm: struct {
2404 /// The indexable value being accessed.2406 /// The indexable value being accessed.
2405 operand: Ref,2407 operand: Ref,
...@@ -2435,7 +2437,6 @@ pub const Inst = struct {...@@ -2435,7 +2437,6 @@ pub const Inst = struct {
2435 float,2437 float,
2436 ptr_type,2438 ptr_type,
2437 int_type,2439 int_type,
2438 bool_br,
2439 @"unreachable",2440 @"unreachable",
2440 @"break",2441 @"break",
2441 dbg_stmt,2442 dbg_stmt,
...@@ -2444,7 +2445,6 @@ pub const Inst = struct {...@@ -2444,7 +2445,6 @@ pub const Inst = struct {
2444 @"defer",2445 @"defer",
2445 defer_err_code,2446 defer_err_code,
2446 save_err_ret_index,2447 save_err_ret_index,
2447 restore_err_ret_index,
2448 elem_val_imm,2448 elem_val_imm,
2449 };2449 };
2450 };2450 };
...@@ -2630,6 +2630,13 @@ pub const Inst = struct {...@@ -2630,6 +2630,13 @@ pub const Inst = struct {
2630 body_len: u32,2630 body_len: u32,
2631 };2631 };
26322632
2633 /// Trailing:
2634 /// * inst: Index // for each `body_len`
2635 pub const BoolBr = struct {
2636 lhs: Ref,
2637 body_len: u32,
2638 };
2639
2633 /// Trailing:2640 /// Trailing:
2634 /// 0. doc_comment: u32 // if `has_doc_comment`; null-terminated string index2641 /// 0. doc_comment: u32 // if `has_doc_comment`; null-terminated string index
2635 /// 1. align_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `align`2642 /// 1. align_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `align`
...@@ -3439,6 +3446,18 @@ pub const Inst = struct {...@@ -3439,6 +3446,18 @@ pub const Inst = struct {
3439 /// The RHS of the array multiplication.3446 /// The RHS of the array multiplication.
3440 rhs: Ref,3447 rhs: Ref,
3441 };3448 };
3449
3450 pub const RestoreErrRetIndex = struct {
3451 src_node: i32,
3452 /// If `.none`, restore the trace to its state upon function entry.
3453 block: Ref,
3454 /// If `.none`, restore unconditionally.
3455 operand: Ref,
3456
3457 pub fn src(self: RestoreErrRetIndex) LazySrcLoc {
3458 return LazySrcLoc.nodeOffset(self.src_node);
3459 }
3460 };
3442};3461};
34433462
3444pub const SpecialProng = enum { none, @"else", under };3463pub const SpecialProng = enum { none, @"else", under };
src/print_zir.zig+16-21
...@@ -199,10 +199,6 @@ const Writer = struct {...@@ -199,10 +199,6 @@ const Writer = struct {
199 const tag = tags[@intFromEnum(inst)];199 const tag = tags[@intFromEnum(inst)];
200 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});200 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});
201 switch (tag) {201 switch (tag) {
202 .store,
203 .store_to_inferred_ptr,
204 => try self.writeBin(stream, inst),
205
206 .alloc,202 .alloc,
207 .alloc_mut,203 .alloc_mut,
208 .alloc_comptime_mut,204 .alloc_comptime_mut,
...@@ -280,6 +276,8 @@ const Writer = struct {...@@ -280,6 +276,8 @@ const Writer = struct {
280 .validate_deref,276 .validate_deref,
281 .check_comptime_control_flow,277 .check_comptime_control_flow,
282 .opt_eu_base_ptr_init,278 .opt_eu_base_ptr_init,
279 .restore_err_ret_index_unconditional,
280 .restore_err_ret_index_fn_entry,
283 => try self.writeUnNode(stream, inst),281 => try self.writeUnNode(stream, inst),
284282
285 .ref,283 .ref,
...@@ -303,7 +301,6 @@ const Writer = struct {...@@ -303,7 +301,6 @@ const Writer = struct {
303 .int_type => try self.writeIntType(stream, inst),301 .int_type => try self.writeIntType(stream, inst),
304302
305 .save_err_ret_index => try self.writeSaveErrRetIndex(stream, inst),303 .save_err_ret_index => try self.writeSaveErrRetIndex(stream, inst),
306 .restore_err_ret_index => try self.writeRestoreErrRetIndex(stream, inst),
307304
308 .@"break",305 .@"break",
309 .break_inline,306 .break_inline,
...@@ -392,6 +389,7 @@ const Writer = struct {...@@ -392,6 +389,7 @@ const Writer = struct {
392 .shr_exact,389 .shr_exact,
393 .xor,390 .xor,
394 .store_node,391 .store_node,
392 .store_to_inferred_ptr,
395 .error_union_type,393 .error_union_type,
396 .merge_error_sets,394 .merge_error_sets,
397 .bit_and,395 .bit_and,
...@@ -615,6 +613,8 @@ const Writer = struct {...@@ -615,6 +613,8 @@ const Writer = struct {
615 .cmpxchg => try self.writeCmpxchg(stream, extended),613 .cmpxchg => try self.writeCmpxchg(stream, extended),
616 .ptr_cast_full => try self.writePtrCastFull(stream, extended),614 .ptr_cast_full => try self.writePtrCastFull(stream, extended),
617 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),615 .ptr_cast_no_dest => try self.writePtrCastNoDest(stream, extended),
616
617 .restore_err_ret_index => try self.writeRestoreErrRetIndex(stream, extended),
618 }618 }
619 }619 }
620620
...@@ -624,14 +624,6 @@ const Writer = struct {...@@ -624,14 +624,6 @@ const Writer = struct {
624 try self.writeSrc(stream, src);624 try self.writeSrc(stream, src);
625 }625 }
626626
627 fn writeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
628 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
629 try self.writeInstRef(stream, inst_data.lhs);
630 try stream.writeAll(", ");
631 try self.writeInstRef(stream, inst_data.rhs);
632 try stream.writeByte(')');
633 }
634
635 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {627 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
636 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;628 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
637 try self.writeInstRef(stream, inst_data.lhs);629 try self.writeInstRef(stream, inst_data.lhs);
...@@ -2505,12 +2497,14 @@ const Writer = struct {...@@ -2505,12 +2497,14 @@ const Writer = struct {
2505 }2497 }
25062498
2507 fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2499 fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2508 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bool_br;2500 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2509 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);2501 const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);
2510 const body = self.code.bodySlice(extra.end, extra.data.body_len);2502 const body = self.code.bodySlice(extra.end, extra.data.body_len);
2511 try self.writeInstRef(stream, inst_data.lhs);2503 try self.writeInstRef(stream, extra.data.lhs);
2512 try stream.writeAll(", ");2504 try stream.writeAll(", ");
2513 try self.writeBracedBody(stream, body);2505 try self.writeBracedBody(stream, body);
2506 try stream.writeAll(") ");
2507 try self.writeSrc(stream, inst_data.src());
2514 }2508 }
25152509
2516 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2510 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -2531,13 +2525,14 @@ const Writer = struct {...@@ -2531,13 +2525,14 @@ const Writer = struct {
2531 try stream.writeAll(")");2525 try stream.writeAll(")");
2532 }2526 }
25332527
2534 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2528 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2535 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;2529 const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
25362530
2537 try self.writeInstRef(stream, inst_data.block);2531 try self.writeInstRef(stream, extra.block);
2538 try self.writeInstRef(stream, inst_data.operand);2532 try self.writeInstRef(stream, extra.operand);
25392533
2540 try stream.writeAll(")");2534 try stream.writeAll(") ");
2535 try self.writeSrc(stream, extra.src());
2541 }2536 }
25422537
2543 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2538 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {