diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-04-20 03:43:02 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-04-20 18:11:53 +0100 |
| commit | 8c9c24e09b8a1e1ea92a16edd654a4b27e9ecf94 (patch) | |
| tree | ca9b15c23345a9ed82e0d8f25b28510583cf1b8e /src/Sema.zig | |
| parent | 6561a98a61bb54c9d6c868f788da3eaa6f48d2c3 (diff) | |
| download | zig-8c9c24e09b8a1e1ea92a16edd654a4b27e9ecf94.tar.gz zig-8c9c24e09b8a1e1ea92a16edd654a4b27e9ecf94.zip | |
compiler: integrate `@compileLog` with incremental compilation
Compile log output is now separated based on the `AnalUnit` which
perfomred the `@compileLog` call, so that we can omit the output for
unreferenced ("dead") units. The units are also sorted when collecting
the `ErrorBundle`, so that compile logs are always printed in a
consistent order, like compile errors are. This is important not only
for incremental compilation, but also for parallel analysis.
Resolves: #23609
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 5dbf26f375..7d7d275e9b 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5884,10 +5884,12 @@ fn zirCompileLog( ) CompileError!Air.Inst.Ref { const pt = sema.pt; const zcu = pt.zcu; + const gpa = zcu.gpa; + + var buf: std.ArrayListUnmanaged(u8) = .empty; + defer buf.deinit(gpa); - var managed = zcu.compile_log_text.toManaged(sema.gpa); - defer pt.zcu.compile_log_text = managed.moveToUnmanaged(); - const writer = managed.writer(); + const writer = buf.writer(gpa); const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); const src_node = extra.data.src_node; @@ -5906,13 +5908,37 @@ fn zirCompileLog( try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(pt)}); } } - try writer.print("\n", .{}); - const gop = try zcu.compile_log_sources.getOrPut(sema.gpa, sema.owner); - if (!gop.found_existing) gop.value_ptr.* = .{ - .base_node_inst = block.src_base_inst, - .node_offset = src_node, + const line_data = try zcu.intern_pool.getOrPutString(gpa, pt.tid, buf.items, .no_embedded_nulls); + + const line_idx: Zcu.CompileLogLine.Index = if (zcu.free_compile_log_lines.pop()) |idx| idx: { + zcu.compile_log_lines.items[@intFromEnum(idx)] = .{ + .next = .none, + .data = line_data, + }; + break :idx idx; + } else idx: { + try zcu.compile_log_lines.append(gpa, .{ + .next = .none, + .data = line_data, + }); + break :idx @enumFromInt(zcu.compile_log_lines.items.len - 1); }; + + const gop = try zcu.compile_logs.getOrPut(gpa, sema.owner); + if (gop.found_existing) { + const prev_line = gop.value_ptr.last_line.get(zcu); + assert(prev_line.next == .none); + prev_line.next = line_idx.toOptional(); + gop.value_ptr.last_line = line_idx; + } else { + gop.value_ptr.* = .{ + .base_node_inst = block.src_base_inst, + .node_offset = src_node, + .first_line = line_idx, + .last_line = line_idx, + }; + } return .void_value; } |
