| ... | ... | @@ -1280,7 +1280,7 @@ fn fnProtoExpr( |
| 1280 | 1280 | defer param_gz.unstack(); |
| 1281 | 1281 | const param_type = try expr(&param_gz, scope, coerced_type_ri, param_type_node); |
| 1282 | 1282 | const param_inst_expected = @intCast(u32, astgen.instructions.len + 1); |
| 1283 | | _ = try param_gz.addBreak(.break_inline, param_inst_expected, param_type); |
| 1283 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 1284 | 1284 | const main_tokens = tree.nodes.items(.main_token); |
| 1285 | 1285 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| 1286 | 1286 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| ... | ... | @@ -1991,7 +1991,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn |
| 1991 | 1991 | |
| 1992 | 1992 | switch (block_gz.break_result_info.rl) { |
| 1993 | 1993 | .block_ptr => { |
| 1994 | | const br = try parent_gz.addBreak(break_tag, block_inst, operand); |
| 1994 | const br = try parent_gz.addBreakWithSrcNode(break_tag, block_inst, operand, rhs); |
| 1995 | 1995 | try block_gz.labeled_breaks.append(astgen.gpa, .{ .br = br, .search = search_index }); |
| 1996 | 1996 | }, |
| 1997 | 1997 | .ptr => { |
| ... | ... | @@ -2003,7 +2003,7 @@ fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) Inn |
| 2003 | 2003 | _ = try parent_gz.addBreak(break_tag, block_inst, .void_value); |
| 2004 | 2004 | }, |
| 2005 | 2005 | else => { |
| 2006 | | _ = try parent_gz.addBreak(break_tag, block_inst, operand); |
| 2006 | _ = try parent_gz.addBreakWithSrcNode(break_tag, block_inst, operand, rhs); |
| 2007 | 2007 | }, |
| 2008 | 2008 | } |
| 2009 | 2009 | return Zir.Inst.Ref.unreachable_value; |
| ... | ... | @@ -3754,7 +3754,7 @@ fn fnDecl( |
| 3754 | 3754 | defer param_gz.unstack(); |
| 3755 | 3755 | const param_type = try expr(&param_gz, params_scope, coerced_type_ri, param_type_node); |
| 3756 | 3756 | const param_inst_expected = @intCast(u32, astgen.instructions.len + 1); |
| 3757 | | _ = try param_gz.addBreak(.break_inline, param_inst_expected, param_type); |
| 3757 | _ = try param_gz.addBreakWithSrcNode(.break_inline, param_inst_expected, param_type, param_type_node); |
| 3758 | 3758 | |
| 3759 | 3759 | const main_tokens = tree.nodes.items(.main_token); |
| 3760 | 3760 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| ... | ... | @@ -4114,7 +4114,7 @@ fn globalVarDecl( |
| 4114 | 4114 | }; |
| 4115 | 4115 | // We do this at the end so that the instruction index marks the end |
| 4116 | 4116 | // range of a top level declaration. |
| 4117 | | _ = try block_scope.addBreak(.break_inline, block_inst, var_inst); |
| 4117 | _ = try block_scope.addBreakWithSrcNode(.break_inline, block_inst, var_inst, node); |
| 4118 | 4118 | try block_scope.setBlockBody(block_inst); |
| 4119 | 4119 | |
| 4120 | 4120 | { |
| ... | ... | @@ -5456,7 +5456,9 @@ fn orelseCatchExpr( |
| 5456 | 5456 | condbr, |
| 5457 | 5457 | cond, |
| 5458 | 5458 | then_result, |
| 5459 | node, |
| 5459 | 5460 | else_result, |
| 5461 | rhs, |
| 5460 | 5462 | block, |
| 5461 | 5463 | block, |
| 5462 | 5464 | break_tag, |
| ... | ... | @@ -5475,7 +5477,9 @@ fn finishThenElseBlock( |
| 5475 | 5477 | condbr: Zir.Inst.Index, |
| 5476 | 5478 | cond: Zir.Inst.Ref, |
| 5477 | 5479 | then_result: Zir.Inst.Ref, |
| 5480 | then_src_node: Ast.Node.Index, |
| 5478 | 5481 | else_result: Zir.Inst.Ref, |
| 5482 | else_src_node: Ast.Node.Index, |
| 5479 | 5483 | main_block: Zir.Inst.Index, |
| 5480 | 5484 | then_break_block: Zir.Inst.Index, |
| 5481 | 5485 | break_tag: Zir.Inst.Tag, |
| ... | ... | @@ -5498,11 +5502,11 @@ fn finishThenElseBlock( |
| 5498 | 5502 | return indexToRef(main_block); |
| 5499 | 5503 | }, |
| 5500 | 5504 | .break_operand => { |
| 5501 | | const then_break = if (!then_no_return) try then_scope.makeBreak(break_tag, then_break_block, then_result) else 0; |
| 5505 | const then_break = if (!then_no_return) try then_scope.makeBreakWithSrcNode(break_tag, then_break_block, then_result, then_src_node) else 0; |
| 5502 | 5506 | const else_break = if (else_result == .none) |
| 5503 | 5507 | try else_scope.makeBreak(break_tag, main_block, .void_value) |
| 5504 | 5508 | else if (!else_no_return) |
| 5505 | | try else_scope.makeBreak(break_tag, main_block, else_result) |
| 5509 | try else_scope.makeBreakWithSrcNode(break_tag, main_block, else_result, else_src_node) |
| 5506 | 5510 | else |
| 5507 | 5511 | 0; |
| 5508 | 5512 | |
| ... | ... | @@ -5683,7 +5687,7 @@ fn boolBinOp( |
| 5683 | 5687 | defer rhs_scope.unstack(); |
| 5684 | 5688 | const rhs = try expr(&rhs_scope, &rhs_scope.base, bool_ri, node_datas[node].rhs); |
| 5685 | 5689 | if (!gz.refIsNoReturn(rhs)) { |
| 5686 | | _ = try rhs_scope.addBreak(.break_inline, bool_br, rhs); |
| 5690 | _ = try rhs_scope.addBreakWithSrcNode(.break_inline, bool_br, rhs, node_datas[node].rhs); |
| 5687 | 5691 | } |
| 5688 | 5692 | try rhs_scope.setBoolBrBody(bool_br); |
| 5689 | 5693 | |
| ... | ... | @@ -5758,6 +5762,7 @@ fn ifExpr( |
| 5758 | 5762 | var payload_val_scope: Scope.LocalVal = undefined; |
| 5759 | 5763 | |
| 5760 | 5764 | try then_scope.addDbgBlockBegin(); |
| 5765 | const then_node = if_full.ast.then_expr; |
| 5761 | 5766 | const then_sub_scope = s: { |
| 5762 | 5767 | if (if_full.error_token != null) { |
| 5763 | 5768 | if (if_full.payload_token) |payload_token| { |
| ... | ... | @@ -5765,7 +5770,7 @@ fn ifExpr( |
| 5765 | 5770 | .err_union_payload_unsafe_ptr |
| 5766 | 5771 | else |
| 5767 | 5772 | .err_union_payload_unsafe; |
| 5768 | | const payload_inst = try then_scope.addUnNode(tag, cond.inst, if_full.ast.then_expr); |
| 5773 | const payload_inst = try then_scope.addUnNode(tag, cond.inst, then_node); |
| 5769 | 5774 | const token_name_index = payload_token + @boolToInt(payload_is_ref); |
| 5770 | 5775 | const ident_name = try astgen.identAsString(token_name_index); |
| 5771 | 5776 | const token_name_str = tree.tokenSlice(token_name_index); |
| ... | ... | @@ -5795,7 +5800,7 @@ fn ifExpr( |
| 5795 | 5800 | const ident_bytes = tree.tokenSlice(ident_token); |
| 5796 | 5801 | if (mem.eql(u8, "_", ident_bytes)) |
| 5797 | 5802 | break :s &then_scope.base; |
| 5798 | | const payload_inst = try then_scope.addUnNode(tag, cond.inst, if_full.ast.then_expr); |
| 5803 | const payload_inst = try then_scope.addUnNode(tag, cond.inst, then_node); |
| 5799 | 5804 | const ident_name = try astgen.identAsString(ident_token); |
| 5800 | 5805 | try astgen.detectLocalShadowing(&then_scope.base, ident_name, ident_token, ident_bytes, .capture); |
| 5801 | 5806 | payload_val_scope = .{ |
| ... | ... | @@ -5813,7 +5818,7 @@ fn ifExpr( |
| 5813 | 5818 | } |
| 5814 | 5819 | }; |
| 5815 | 5820 | |
| 5816 | | const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_info, if_full.ast.then_expr); |
| 5821 | const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_info, then_node); |
| 5817 | 5822 | if (!then_scope.endsWithNoReturn()) { |
| 5818 | 5823 | block_scope.break_count += 1; |
| 5819 | 5824 | } |
| ... | ... | @@ -5878,7 +5883,7 @@ fn ifExpr( |
| 5878 | 5883 | .result = e, |
| 5879 | 5884 | }; |
| 5880 | 5885 | } else .{ |
| 5881 | | .src = if_full.ast.then_expr, |
| 5886 | .src = then_node, |
| 5882 | 5887 | .result = switch (ri.rl) { |
| 5883 | 5888 | // Explicitly store void to ptr result loc if there is no else branch |
| 5884 | 5889 | .ptr, .block_ptr => try rvalue(&else_scope, ri, .void_value, node), |
| ... | ... | @@ -5897,7 +5902,9 @@ fn ifExpr( |
| 5897 | 5902 | condbr, |
| 5898 | 5903 | cond.bool_bit, |
| 5899 | 5904 | then_result, |
| 5905 | then_node, |
| 5900 | 5906 | else_info.result, |
| 5907 | else_info.src, |
| 5901 | 5908 | block, |
| 5902 | 5909 | block, |
| 5903 | 5910 | break_tag, |
| ... | ... | @@ -6185,6 +6192,7 @@ fn whileExpr( |
| 6185 | 6192 | then_scope.instructions_top = then_scope.instructions.items.len; |
| 6186 | 6193 | |
| 6187 | 6194 | try then_scope.addDbgBlockBegin(); |
| 6195 | const then_node = while_full.ast.then_expr; |
| 6188 | 6196 | if (payload_inst != 0) try then_scope.instructions.append(astgen.gpa, payload_inst); |
| 6189 | 6197 | if (dbg_var_name) |name| try then_scope.addDbgVar(.dbg_var_val, name, dbg_var_inst); |
| 6190 | 6198 | try then_scope.instructions.append(astgen.gpa, continue_block); |
| ... | ... | @@ -6198,7 +6206,7 @@ fn whileExpr( |
| 6198 | 6206 | try then_scope.addDbgBlockEnd(); |
| 6199 | 6207 | |
| 6200 | 6208 | continue_scope.instructions_top = continue_scope.instructions.items.len; |
| 6201 | | _ = try unusedResultExpr(&continue_scope, &continue_scope.base, while_full.ast.then_expr); |
| 6209 | _ = try unusedResultExpr(&continue_scope, &continue_scope.base, then_node); |
| 6202 | 6210 | try checkUsed(parent_gz, &then_scope.base, then_sub_scope); |
| 6203 | 6211 | const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break"; |
| 6204 | 6212 | if (!continue_scope.endsWithNoReturn()) { |
| ... | ... | @@ -6261,7 +6269,7 @@ fn whileExpr( |
| 6261 | 6269 | .result = else_result, |
| 6262 | 6270 | }; |
| 6263 | 6271 | } else .{ |
| 6264 | | .src = while_full.ast.then_expr, |
| 6272 | .src = then_node, |
| 6265 | 6273 | .result = .none, |
| 6266 | 6274 | }; |
| 6267 | 6275 | |
| ... | ... | @@ -6280,7 +6288,9 @@ fn whileExpr( |
| 6280 | 6288 | condbr, |
| 6281 | 6289 | cond.bool_bit, |
| 6282 | 6290 | .void_value, |
| 6291 | then_node, |
| 6283 | 6292 | else_info.result, |
| 6293 | else_info.src, |
| 6284 | 6294 | loop_block, |
| 6285 | 6295 | cond_block, |
| 6286 | 6296 | break_tag, |
| ... | ... | @@ -6468,6 +6478,7 @@ fn forExpr( |
| 6468 | 6478 | }); |
| 6469 | 6479 | } |
| 6470 | 6480 | |
| 6481 | var then_node = for_full.ast.then_expr; |
| 6471 | 6482 | var then_scope = parent_gz.makeSubBlock(&cond_scope.base); |
| 6472 | 6483 | defer then_scope.unstack(); |
| 6473 | 6484 | |
| ... | ... | @@ -6535,8 +6546,8 @@ fn forExpr( |
| 6535 | 6546 | break :blk capture_sub_scope; |
| 6536 | 6547 | }; |
| 6537 | 6548 | |
| 6538 | | const then_result = try expr(&then_scope, then_sub_scope, .{ .rl = .none }, for_full.ast.then_expr); |
| 6539 | | _ = try addEnsureResult(&then_scope, then_result, for_full.ast.then_expr); |
| 6549 | const then_result = try expr(&then_scope, then_sub_scope, .{ .rl = .none }, then_node); |
| 6550 | _ = try addEnsureResult(&then_scope, then_result, then_node); |
| 6540 | 6551 | |
| 6541 | 6552 | try checkUsed(parent_gz, &then_scope.base, then_sub_scope); |
| 6542 | 6553 | try then_scope.addDbgBlockEnd(); |
| ... | ... | @@ -6567,7 +6578,7 @@ fn forExpr( |
| 6567 | 6578 | .result = else_result, |
| 6568 | 6579 | }; |
| 6569 | 6580 | } else .{ |
| 6570 | | .src = for_full.ast.then_expr, |
| 6581 | .src = then_node, |
| 6571 | 6582 | .result = .none, |
| 6572 | 6583 | }; |
| 6573 | 6584 | |
| ... | ... | @@ -6587,7 +6598,9 @@ fn forExpr( |
| 6587 | 6598 | condbr, |
| 6588 | 6599 | cond, |
| 6589 | 6600 | then_result, |
| 6601 | then_node, |
| 6590 | 6602 | else_info.result, |
| 6603 | else_info.src, |
| 6591 | 6604 | loop_block, |
| 6592 | 6605 | cond_block, |
| 6593 | 6606 | break_tag, |
| ... | ... | @@ -6949,12 +6962,13 @@ fn switchExpr( |
| 6949 | 6962 | if (dbg_var_tag_name) |some| { |
| 6950 | 6963 | try case_scope.addDbgVar(.dbg_var_val, some, dbg_var_tag_inst); |
| 6951 | 6964 | } |
| 6952 | | const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_info, case.ast.target_expr); |
| 6965 | const target_expr_node = case.ast.target_expr; |
| 6966 | const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_info, target_expr_node); |
| 6953 | 6967 | try checkUsed(parent_gz, &case_scope.base, sub_scope); |
| 6954 | 6968 | try case_scope.addDbgBlockEnd(); |
| 6955 | 6969 | if (!parent_gz.refIsNoReturn(case_result)) { |
| 6956 | 6970 | block_scope.break_count += 1; |
| 6957 | | _ = try case_scope.addBreak(.@"break", switch_block, case_result); |
| 6971 | _ = try case_scope.addBreakWithSrcNode(.@"break", switch_block, case_result, target_expr_node); |
| 6958 | 6972 | } |
| 6959 | 6973 | |
| 6960 | 6974 | const case_slice = case_scope.instructionsSlice(); |
| ... | ... | @@ -7057,10 +7071,12 @@ fn switchExpr( |
| 7057 | 7071 | .break_void => { |
| 7058 | 7072 | assert(!strat.elide_store_to_block_ptr_instructions); |
| 7059 | 7073 | const last_inst = payloads.items[end_index - 1]; |
| 7060 | | if (zir_tags[last_inst] == .@"break" and |
| 7061 | | zir_datas[last_inst].@"break".block_inst == switch_block) |
| 7062 | | { |
| 7063 | | zir_datas[last_inst].@"break".operand = .void_value; |
| 7074 | if (zir_tags[last_inst] == .@"break") { |
| 7075 | const inst_data = zir_datas[last_inst].@"break"; |
| 7076 | const block_inst = astgen.extra.items[inst_data.payload_index]; |
| 7077 | if (block_inst == switch_block) { |
| 7078 | zir_datas[last_inst].@"break".operand = .void_value; |
| 7079 | } |
| 7064 | 7080 | } |
| 7065 | 7081 | }, |
| 7066 | 7082 | } |
| ... | ... | @@ -8856,7 +8872,7 @@ fn callExpr( |
| 8856 | 8872 | // `call_inst` is reused to provide the param type. |
| 8857 | 8873 | arg_block.rl_ty_inst = call_inst; |
| 8858 | 8874 | const arg_ref = try expr(&arg_block, &arg_block.base, .{ .rl = .{ .coerced_ty = call_inst }, .ctx = .fn_arg }, param_node); |
| 8859 | | _ = try arg_block.addBreak(.break_inline, call_index, arg_ref); |
| 8875 | _ = try arg_block.addBreakWithSrcNode(.break_inline, call_index, arg_ref, param_node); |
| 8860 | 8876 | |
| 8861 | 8877 | const body = arg_block.instructionsSlice(); |
| 8862 | 8878 | try astgen.scratch.ensureUnusedCapacity(astgen.gpa, countBodyLenAfterFixups(astgen, body)); |
| ... | ... | @@ -11262,35 +11278,40 @@ const GenZir = struct { |
| 11262 | 11278 | if (align_body.len != 0) { |
| 11263 | 11279 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, align_body)); |
| 11264 | 11280 | astgen.appendBodyWithFixups(align_body); |
| 11265 | | zir_datas[align_body[align_body.len - 1]].@"break".block_inst = new_index; |
| 11281 | const inst_data = zir_datas[align_body[align_body.len - 1]].@"break"; |
| 11282 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11266 | 11283 | } else if (args.align_ref != .none) { |
| 11267 | 11284 | astgen.extra.appendAssumeCapacity(@enumToInt(args.align_ref)); |
| 11268 | 11285 | } |
| 11269 | 11286 | if (addrspace_body.len != 0) { |
| 11270 | 11287 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, addrspace_body)); |
| 11271 | 11288 | astgen.appendBodyWithFixups(addrspace_body); |
| 11272 | | zir_datas[addrspace_body[addrspace_body.len - 1]].@"break".block_inst = new_index; |
| 11289 | const inst_data = zir_datas[addrspace_body[addrspace_body.len - 1]].@"break"; |
| 11290 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11273 | 11291 | } else if (args.addrspace_ref != .none) { |
| 11274 | 11292 | astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_ref)); |
| 11275 | 11293 | } |
| 11276 | 11294 | if (section_body.len != 0) { |
| 11277 | 11295 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, section_body)); |
| 11278 | 11296 | astgen.appendBodyWithFixups(section_body); |
| 11279 | | zir_datas[section_body[section_body.len - 1]].@"break".block_inst = new_index; |
| 11297 | const inst_data = zir_datas[section_body[section_body.len - 1]].@"break"; |
| 11298 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11280 | 11299 | } else if (args.section_ref != .none) { |
| 11281 | 11300 | astgen.extra.appendAssumeCapacity(@enumToInt(args.section_ref)); |
| 11282 | 11301 | } |
| 11283 | 11302 | if (cc_body.len != 0) { |
| 11284 | 11303 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, cc_body)); |
| 11285 | 11304 | astgen.appendBodyWithFixups(cc_body); |
| 11286 | | zir_datas[cc_body[cc_body.len - 1]].@"break".block_inst = new_index; |
| 11305 | const inst_data = zir_datas[cc_body[cc_body.len - 1]].@"break"; |
| 11306 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11287 | 11307 | } else if (args.cc_ref != .none) { |
| 11288 | 11308 | astgen.extra.appendAssumeCapacity(@enumToInt(args.cc_ref)); |
| 11289 | 11309 | } |
| 11290 | 11310 | if (ret_body.len != 0) { |
| 11291 | 11311 | astgen.extra.appendAssumeCapacity(countBodyLenAfterFixups(astgen, ret_body)); |
| 11292 | 11312 | astgen.appendBodyWithFixups(ret_body); |
| 11293 | | zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index; |
| 11313 | const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break"; |
| 11314 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11294 | 11315 | } else if (ret_ref != .none) { |
| 11295 | 11316 | astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref)); |
| 11296 | 11317 | } |
| ... | ... | @@ -11344,7 +11365,9 @@ const GenZir = struct { |
| 11344 | 11365 | const zir_datas = astgen.instructions.items(.data); |
| 11345 | 11366 | if (ret_body.len != 0) { |
| 11346 | 11367 | astgen.appendBodyWithFixups(ret_body); |
| 11347 | | zir_datas[ret_body[ret_body.len - 1]].@"break".block_inst = new_index; |
| 11368 | |
| 11369 | const inst_data = zir_datas[ret_body[ret_body.len - 1]].@"break"; |
| 11370 | astgen.extra.items[inst_data.payload_index] = new_index; |
| 11348 | 11371 | } else if (ret_ref != .none) { |
| 11349 | 11372 | astgen.extra.appendAssumeCapacity(@enumToInt(ret_ref)); |
| 11350 | 11373 | } |
| ... | ... | @@ -11790,30 +11813,104 @@ const GenZir = struct { |
| 11790 | 11813 | fn addBreak( |
| 11791 | 11814 | gz: *GenZir, |
| 11792 | 11815 | tag: Zir.Inst.Tag, |
| 11793 | | break_block: Zir.Inst.Index, |
| 11816 | block_inst: Zir.Inst.Index, |
| 11794 | 11817 | operand: Zir.Inst.Ref, |
| 11795 | 11818 | ) !Zir.Inst.Index { |
| 11796 | | return gz.addAsIndex(.{ |
| 11819 | const gpa = gz.astgen.gpa; |
| 11820 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11821 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11822 | |
| 11823 | const extra: Zir.Inst.Break = .{ |
| 11824 | .block_inst = block_inst, |
| 11825 | .operand_src_node = Zir.Inst.Break.no_src_node, |
| 11826 | }; |
| 11827 | const payload_index = try gz.astgen.addExtra(extra); |
| 11828 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 11829 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11797 | 11830 | .tag = tag, |
| 11798 | 11831 | .data = .{ .@"break" = .{ |
| 11799 | | .block_inst = break_block, |
| 11800 | 11832 | .operand = operand, |
| 11833 | .payload_index = payload_index, |
| 11801 | 11834 | } }, |
| 11802 | 11835 | }); |
| 11836 | gz.instructions.appendAssumeCapacity(new_index); |
| 11837 | return new_index; |
| 11803 | 11838 | } |
| 11804 | 11839 | |
| 11805 | 11840 | fn makeBreak( |
| 11806 | 11841 | gz: *GenZir, |
| 11807 | 11842 | tag: Zir.Inst.Tag, |
| 11808 | | break_block: Zir.Inst.Index, |
| 11843 | block_inst: Zir.Inst.Index, |
| 11809 | 11844 | operand: Zir.Inst.Ref, |
| 11810 | 11845 | ) !Zir.Inst.Index { |
| 11846 | const gpa = gz.astgen.gpa; |
| 11847 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11848 | |
| 11849 | const extra: Zir.Inst.Break = .{ |
| 11850 | .block_inst = block_inst, |
| 11851 | .operand_src_node = Zir.Inst.Break.no_src_node, |
| 11852 | }; |
| 11853 | const payload_index = try gz.astgen.addExtra(extra); |
| 11811 | 11854 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 11812 | | try gz.astgen.instructions.append(gz.astgen.gpa, .{ |
| 11855 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11813 | 11856 | .tag = tag, |
| 11814 | 11857 | .data = .{ .@"break" = .{ |
| 11815 | | .block_inst = break_block, |
| 11816 | 11858 | .operand = operand, |
| 11859 | .payload_index = payload_index, |
| 11860 | } }, |
| 11861 | }); |
| 11862 | return new_index; |
| 11863 | } |
| 11864 | |
| 11865 | fn addBreakWithSrcNode( |
| 11866 | gz: *GenZir, |
| 11867 | tag: Zir.Inst.Tag, |
| 11868 | block_inst: Zir.Inst.Index, |
| 11869 | operand: Zir.Inst.Ref, |
| 11870 | operand_src_node: Ast.Node.Index, |
| 11871 | ) !Zir.Inst.Index { |
| 11872 | const gpa = gz.astgen.gpa; |
| 11873 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 11874 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11875 | |
| 11876 | const extra: Zir.Inst.Break = .{ |
| 11877 | .block_inst = block_inst, |
| 11878 | .operand_src_node = gz.nodeIndexToRelative(operand_src_node), |
| 11879 | }; |
| 11880 | const payload_index = try gz.astgen.addExtra(extra); |
| 11881 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 11882 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11883 | .tag = tag, |
| 11884 | .data = .{ .@"break" = .{ |
| 11885 | .operand = operand, |
| 11886 | .payload_index = payload_index, |
| 11887 | } }, |
| 11888 | }); |
| 11889 | gz.instructions.appendAssumeCapacity(new_index); |
| 11890 | return new_index; |
| 11891 | } |
| 11892 | |
| 11893 | fn makeBreakWithSrcNode( |
| 11894 | gz: *GenZir, |
| 11895 | tag: Zir.Inst.Tag, |
| 11896 | block_inst: Zir.Inst.Index, |
| 11897 | operand: Zir.Inst.Ref, |
| 11898 | operand_src_node: Ast.Node.Index, |
| 11899 | ) !Zir.Inst.Index { |
| 11900 | const gpa = gz.astgen.gpa; |
| 11901 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11902 | |
| 11903 | const extra: Zir.Inst.Break = .{ |
| 11904 | .block_inst = block_inst, |
| 11905 | .operand_src_node = gz.nodeIndexToRelative(operand_src_node), |
| 11906 | }; |
| 11907 | const payload_index = try gz.astgen.addExtra(extra); |
| 11908 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 11909 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| 11910 | .tag = tag, |
| 11911 | .data = .{ .@"break" = .{ |
| 11912 | .operand = operand, |
| 11913 | .payload_index = payload_index, |
| 11817 | 11914 | } }, |
| 11818 | 11915 | }); |
| 11819 | 11916 | return new_index; |