| ... | ... | @@ -3332,31 +3332,11 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void { |
| 3332 | 3332 | // If the current block will be evaluated only during semantic analysis |
| 3333 | 3333 | // then no dbg_stmt ZIR instruction is needed. |
| 3334 | 3334 | if (gz.is_comptime) return; |
| 3335 | | |
| 3336 | 3335 | const astgen = gz.astgen; |
| 3337 | 3336 | astgen.advanceSourceCursorToNode(node); |
| 3338 | 3337 | const line = astgen.source_line - gz.decl_line; |
| 3339 | 3338 | const column = astgen.source_column; |
| 3340 | | |
| 3341 | | if (gz.instructions.items.len > 0) { |
| 3342 | | const last = gz.instructions.items[gz.instructions.items.len - 1]; |
| 3343 | | const zir_tags = astgen.instructions.items(.tag); |
| 3344 | | if (zir_tags[@intFromEnum(last)] == .dbg_stmt) { |
| 3345 | | const zir_datas = astgen.instructions.items(.data); |
| 3346 | | zir_datas[@intFromEnum(last)].dbg_stmt = .{ |
| 3347 | | .line = line, |
| 3348 | | .column = column, |
| 3349 | | }; |
| 3350 | | return; |
| 3351 | | } |
| 3352 | | } |
| 3353 | | |
| 3354 | | _ = try gz.add(.{ .tag = .dbg_stmt, .data = .{ |
| 3355 | | .dbg_stmt = .{ |
| 3356 | | .line = line, |
| 3357 | | .column = column, |
| 3358 | | }, |
| 3359 | | } }); |
| 3339 | try emitDbgStmt(gz, .{ line, column }); |
| 3360 | 3340 | } |
| 3361 | 3341 | |
| 3362 | 3342 | fn assign(gz: *GenZir, scope: *Scope, infix_node: Ast.Node.Index) InnerError!void { |
| ... | ... | @@ -7143,7 +7123,7 @@ fn switchExprErrUnion( |
| 7143 | 7123 | block_scope.setBreakResultInfo(block_ri); |
| 7144 | 7124 | |
| 7145 | 7125 | // Sema expects a dbg_stmt immediately before switch_block_err_union |
| 7146 | | try emitDbgStmt(parent_gz, operand_lc); |
| 7126 | try emitDbgStmtForceCurrentIndex(parent_gz, operand_lc); |
| 7147 | 7127 | // This gets added to the parent block later, after the item expressions. |
| 7148 | 7128 | const switch_block = try parent_gz.makeBlockInst(.switch_block_err_union, switch_node); |
| 7149 | 7129 | |
| ... | ... | @@ -7723,7 +7703,7 @@ fn switchExpr( |
| 7723 | 7703 | block_scope.setBreakResultInfo(block_ri); |
| 7724 | 7704 | |
| 7725 | 7705 | // Sema expects a dbg_stmt immediately before switch_block(_ref) |
| 7726 | | try emitDbgStmt(parent_gz, operand_lc); |
| 7706 | try emitDbgStmtForceCurrentIndex(parent_gz, operand_lc); |
| 7727 | 7707 | // This gets added to the parent block later, after the item expressions. |
| 7728 | 7708 | const switch_tag: Zir.Inst.Tag = if (any_payload_is_ref) .switch_block_ref else .switch_block; |
| 7729 | 7709 | const switch_block = try parent_gz.makeBlockInst(switch_tag, switch_node); |
| ... | ... | @@ -9847,13 +9827,8 @@ fn callExpr( |
| 9847 | 9827 | astgen.advanceSourceCursor(astgen.tree.tokens.items(.start)[call.ast.lparen]); |
| 9848 | 9828 | const line = astgen.source_line - gz.decl_line; |
| 9849 | 9829 | const column = astgen.source_column; |
| 9850 | | |
| 9851 | | _ = try gz.add(.{ .tag = .dbg_stmt, .data = .{ |
| 9852 | | .dbg_stmt = .{ |
| 9853 | | .line = line, |
| 9854 | | .column = column, |
| 9855 | | }, |
| 9856 | | } }); |
| 9830 | // Sema expects a dbg_stmt immediately before call, |
| 9831 | try emitDbgStmtForceCurrentIndex(gz, .{ line, column }); |
| 9857 | 9832 | } |
| 9858 | 9833 | |
| 9859 | 9834 | switch (callee) { |
| ... | ... | @@ -13536,6 +13511,44 @@ fn countBodyLenAfterFixups(astgen: *AstGen, body: []const Zir.Inst.Index) u32 { |
| 13536 | 13511 | |
| 13537 | 13512 | fn emitDbgStmt(gz: *GenZir, lc: LineColumn) !void { |
| 13538 | 13513 | if (gz.is_comptime) return; |
| 13514 | if (gz.instructions.items.len > 0) { |
| 13515 | const astgen = gz.astgen; |
| 13516 | const last = gz.instructions.items[gz.instructions.items.len - 1]; |
| 13517 | if (astgen.instructions.items(.tag)[@intFromEnum(last)] == .dbg_stmt) { |
| 13518 | astgen.instructions.items(.data)[@intFromEnum(last)].dbg_stmt = .{ |
| 13519 | .line = lc[0], |
| 13520 | .column = lc[1], |
| 13521 | }; |
| 13522 | return; |
| 13523 | } |
| 13524 | } |
| 13525 | |
| 13526 | _ = try gz.add(.{ .tag = .dbg_stmt, .data = .{ |
| 13527 | .dbg_stmt = .{ |
| 13528 | .line = lc[0], |
| 13529 | .column = lc[1], |
| 13530 | }, |
| 13531 | } }); |
| 13532 | } |
| 13533 | |
| 13534 | /// In some cases, Sema expects us to generate a `dbg_stmt` at the instruction |
| 13535 | /// *index* directly preceding the next instruction (e.g. if a call is %10, it |
| 13536 | /// expects a dbg_stmt at %9). TODO: this logic may allow redundant dbg_stmt |
| 13537 | /// instructions; fix up Sema so we don't need it! |
| 13538 | fn emitDbgStmtForceCurrentIndex(gz: *GenZir, lc: LineColumn) !void { |
| 13539 | const astgen = gz.astgen; |
| 13540 | if (gz.instructions.items.len > 0 and |
| 13541 | @intFromEnum(gz.instructions.items[gz.instructions.items.len - 1]) == astgen.instructions.len - 1) |
| 13542 | { |
| 13543 | const last = astgen.instructions.len - 1; |
| 13544 | if (astgen.instructions.items(.tag)[last] == .dbg_stmt) { |
| 13545 | astgen.instructions.items(.data)[last].dbg_stmt = .{ |
| 13546 | .line = lc[0], |
| 13547 | .column = lc[1], |
| 13548 | }; |
| 13549 | return; |
| 13550 | } |
| 13551 | } |
| 13539 | 13552 | |
| 13540 | 13553 | _ = try gz.add(.{ .tag = .dbg_stmt, .data = .{ |
| 13541 | 13554 | .dbg_stmt = .{ |