diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-10-28 12:42:05 +0000 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-10-30 09:31:28 +0000 |
| commit | 74931fe25cdd94e1cd08b5ece9dcce19959bc079 (patch) | |
| tree | 75449b1d594d55a872aeb03f2dd3be16ac396274 /src/Compilation.zig | |
| parent | 74c23a237ef5245b63eb06b832a511aabeb715c0 (diff) | |
| download | zig-74931fe25cdd94e1cd08b5ece9dcce19959bc079.tar.gz zig-74931fe25cdd94e1cd08b5ece9dcce19959bc079.zip | |
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.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 3670bc51b5..c72ef32fb5 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2093,7 +2093,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, if (options.verbose_llvm_cpu_features) { if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: { - const stderr_w = std.debug.lockStderrWriter(&.{}); + const stderr_w, _ = std.debug.lockStderrWriter(&.{}); defer std.debug.unlockStderrWriter(); stderr_w.print("compilation: {s}\n", .{options.root_name}) catch break :print; stderr_w.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print; @@ -4270,7 +4270,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle { // However, we haven't reported any such error. // This is a compiler bug. print_ctx: { - var stderr_w = std.debug.lockStderrWriter(&.{}); + var stderr_w, _ = std.debug.lockStderrWriter(&.{}); defer std.debug.unlockStderrWriter(); stderr_w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx; stderr_w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx; @@ -7752,7 +7752,7 @@ pub fn lockAndSetMiscFailure( pub fn dump_argv(argv: []const []const u8) void { var buffer: [64]u8 = undefined; - const stderr = std.debug.lockStderrWriter(&buffer); + const stderr, _ = std.debug.lockStderrWriter(&buffer); defer std.debug.unlockStderrWriter(); nosuspend { for (argv, 0..) |arg, i| { |
