From 0648177ed7a1ad5364c478b63ec28a6de15e4ad9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 8 Aug 2022 20:29:22 -0700 Subject: [PATCH] AstGen: avoid multiple dbg_stmt instructions in a row This is purely an optimization to emit fewer ZIR instructions. --- src/AstGen.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/AstGen.zig b/src/AstGen.zig index e53c59817ad5cf5374d74ce8f1a6c71a651f3eb0..5087ea629330f42c4bf471afa3437e4954f96dec 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -3071,6 +3071,19 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void { const line = astgen.source_line - gz.decl_line; const column = astgen.source_column; + if (gz.instructions.items.len > 0) { + const last = gz.instructions.items[gz.instructions.items.len - 1]; + const zir_tags = astgen.instructions.items(.tag); + if (zir_tags[last] == .dbg_stmt) { + const zir_datas = astgen.instructions.items(.data); + zir_datas[last].dbg_stmt = .{ + .line = line, + .column = column, + }; + return; + } + } + _ = try gz.add(.{ .tag = .dbg_stmt, .data = .{ .dbg_stmt = .{ .line = line, -- 2.54.0