std.debug.lockStderrWriter: also return ttyconf

`std.Io.tty.Config.detect` may be an expensive check (e.g. involving
syscalls), and doing it every time we need to print isn't really
necessary; under normal usage, we can compute the value once and cache
it for the whole program's execution. Since anyone outputting to stderr
may reasonably want this information (in fact they are very likely to),
it makes sense to cache it and return it from `lockStderrWriter`. Call
sites who do not need it will experience no significant overhead, and
can just ignore the TTY config with a `const w, _` destructure.
This commit is contained in:
Matthew Lugg
2025-10-28 12:42:05 +00:00
parent 74c23a237e
commit 74931fe25c
37 changed files with 169 additions and 193 deletions
+5 -6
View File
@@ -1056,15 +1056,15 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
const maybe_path: ?*GeneratedFile = @field(compile, tag_name);
const generated_file = maybe_path orelse {
const w = std.debug.lockStderrWriter(&.{});
std.Build.dumpBadGetPathHelp(&compile.step, w, .detect(.stderr()), compile.step.owner, asking_step) catch {};
const w, const ttyconf = std.debug.lockStderrWriter(&.{});
std.Build.dumpBadGetPathHelp(&compile.step, w, ttyconf, compile.step.owner, asking_step) catch {};
std.debug.unlockStderrWriter();
@panic("missing emit option for " ++ tag_name);
};
const path = generated_file.path orelse {
const w = std.debug.lockStderrWriter(&.{});
std.Build.dumpBadGetPathHelp(&compile.step, w, .detect(.stderr()), compile.step.owner, asking_step) catch {};
const w, const ttyconf = std.debug.lockStderrWriter(&.{});
std.Build.dumpBadGetPathHelp(&compile.step, w, ttyconf, compile.step.owner, asking_step) catch {};
std.debug.unlockStderrWriter();
@panic(tag_name ++ " is null. Is there a missing step dependency?");
};
@@ -2027,10 +2027,9 @@ fn checkCompileErrors(compile: *Compile) !void {
var aw: std.Io.Writer.Allocating = .init(arena);
defer aw.deinit();
try actual_eb.renderToWriter(.{
.ttyconf = .no_color,
.include_reference_trace = false,
.include_source_line = false,
}, &aw.writer);
}, &aw.writer, .no_color);
break :ae try aw.toOwnedSlice();
};