aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-17 17:00:41 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:10 -0800
commit608145c2f07d90c46cdaa8bc2013f31b965a5b8b (patch)
treea8704744b3808887c25ecf7b674eed030b2f6c7d /src
parentaa57793b680b3da05f1d888b4df15807905e57c8 (diff)
downloadzig-608145c2f07d90c46cdaa8bc2013f31b965a5b8b.tar.gz
zig-608145c2f07d90c46cdaa8bc2013f31b965a5b8b.zip
fix more fallout from locking stderr
Diffstat (limited to 'src')
-rw-r--r--src/Air/print.zig12
-rw-r--r--src/Compilation.zig45
-rw-r--r--src/InternPool.zig10
-rw-r--r--src/Zcu/PerThread.zig8
-rw-r--r--src/codegen/aarch64/Select.zig7
-rw-r--r--src/crash_report.zig6
-rw-r--r--src/libs/mingw.zig24
-rw-r--r--src/libs/mingw/def.zig6
-rw-r--r--src/link/Coff.zig6
-rw-r--r--src/link/Elf2.zig6
-rw-r--r--src/main.zig12
11 files changed, 78 insertions, 64 deletions
diff --git a/src/Air/print.zig b/src/Air/print.zig
index 05614a0ed3..98b0a0b242 100644
--- a/src/Air/print.zig
+++ b/src/Air/print.zig
@@ -76,9 +76,9 @@ pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
const comp = pt.zcu.comp;
const io = comp.io;
var buffer: [512]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
air.write(w, pt, liveness);
}
@@ -86,9 +86,9 @@ pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Ai
const comp = pt.zcu.comp;
const io = comp.io;
var buffer: [512]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
air.writeInst(w, inst, pt, liveness);
}
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 37e15ab171..f3fcef40a0 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -2092,14 +2092,16 @@ 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 = try io.lockStderrWriter(&.{});
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
- w.print("compilation: {s}\n", .{options.root_name}) catch break :print;
- w.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print;
- w.print(" cpu: {s}\n", .{target.cpu.model.name}) catch break :print;
- w.print(" features: {s}\n", .{cf}) catch {};
+ if (options.root_mod.resolved_target.llvm_cpu_features) |cf| {
+ const stderr = try io.lockStderr(&.{}, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
+ printVerboseLlvmCpuFeatures(w, arena, options.root_name, target, cf) catch |err| switch (err) {
+ error.WriteFailed => switch (stderr.file_writer.err.?) {
+ error.Canceled => |e| return e,
+ else => {},
+ },
+ };
}
}
@@ -2700,6 +2702,19 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
return comp;
}
+fn printVerboseLlvmCpuFeatures(
+ w: *Writer,
+ arena: Allocator,
+ root_name: []const u8,
+ target: *const std.Target,
+ cf: [*:0]const u8,
+) Writer.Error!void {
+ try w.print("compilation: {s}\n", .{root_name});
+ try w.print(" target: {s}\n", .{try target.zigTriple(arena)});
+ try w.print(" cpu: {s}\n", .{target.cpu.model.name});
+ try w.print(" features: {s}\n", .{cf});
+}
+
pub fn destroy(comp: *Compilation) void {
const gpa = comp.gpa;
const io = comp.io;
@@ -4259,9 +4274,9 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle {
// However, we haven't reported any such error.
// This is a compiler bug.
print_ctx: {
- const stderr = std.debug.lockStderrWriter(&.{});
- defer std.debug.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = std.debug.lockStderr(&.{}).terminal();
+ defer std.debug.unlockStderr();
+ const w = stderr.writer;
w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx;
w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx;
while (ref) |r| {
@@ -7772,11 +7787,11 @@ pub fn lockAndSetMiscFailure(
pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void {
var buffer: [64]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
return dumpArgvWriter(w, argv) catch |err| switch (err) {
- error.WriteFailed => switch (stderr.err.?) {
+ error.WriteFailed => switch (stderr.file_writer.err.?) {
error.Canceled => return error.Canceled,
else => return,
},
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 539cb441c5..98bde244c5 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -11169,9 +11169,9 @@ pub fn mutateVarInit(ip: *InternPool, io: Io, index: Index, init_index: Index) v
pub fn dump(ip: *const InternPool, io: Io) Io.Cancelable!void {
var buffer: [4096]u8 = undefined;
- const stderr_writer = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr_writer.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
try dumpStatsFallible(ip, w, std.heap.page_allocator);
try dumpAllFallible(ip, w);
}
@@ -11536,8 +11536,8 @@ fn dumpAllFallible(ip: *const InternPool, w: *Io.Writer) anyerror!void {
pub fn dumpGenericInstances(ip: *const InternPool, io: Io, allocator: Allocator) Io.Cancelable!void {
var buffer: [4096]u8 = undefined;
- const stderr_writer = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
+ const stderr_writer = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
const w = &stderr_writer.interface;
try ip.dumpGenericInstancesFallible(allocator, w);
}
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
index 76ab3e229c..103cbaaaae 100644
--- a/src/Zcu/PerThread.zig
+++ b/src/Zcu/PerThread.zig
@@ -4560,10 +4560,10 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
if (build_options.enable_debug_extensions and comp.verbose_air) p: {
const io = comp.io;
- const stderr = try io.lockStderrWriter(&.{});
- defer io.unlockStderrWriter();
- printVerboseAir(pt, liveness, fqn, air, &stderr.interface) catch |err| switch (err) {
- error.WriteFailed => switch (stderr.err.?) {
+ const stderr = try io.lockStderr(&.{}, null);
+ defer io.unlockStderr();
+ printVerboseAir(pt, liveness, fqn, air, &stderr.file_writer.interface) catch |err| switch (err) {
+ error.WriteFailed => switch (stderr.file_writer.err.?) {
error.Canceled => |e| return e,
else => break :p,
},
diff --git a/src/codegen/aarch64/Select.zig b/src/codegen/aarch64/Select.zig
index 138c70fecf..93a6e0a768 100644
--- a/src/codegen/aarch64/Select.zig
+++ b/src/codegen/aarch64/Select.zig
@@ -11274,16 +11274,15 @@ fn initValueAdvanced(
}
pub fn dumpValues(isel: *Select, which: enum { only_referenced, all }) void {
const zcu = isel.pt.zcu;
- const io = zcu.comp.io;
const gpa = zcu.gpa;
const ip = &zcu.intern_pool;
const nav = ip.getNav(isel.nav_index);
errdefer |err| @panic(@errorName(err));
- const stderr_writer = io.lockStderrWriter(&.{}) catch return;
- defer io.unlockStderrWriter();
- const stderr = &stderr_writer.interface;
+ const locked_stderr = std.debug.lockStderr(&.{}, null);
+ defer std.debug.unlockStderr();
+ const stderr = &locked_stderr.file_writer.interface;
var reverse_live_values: std.AutoArrayHashMapUnmanaged(Value.Index, std.ArrayList(Air.Inst.Index)) = .empty;
defer {
diff --git a/src/crash_report.zig b/src/crash_report.zig
index f23806b758..e56bc7cec5 100644
--- a/src/crash_report.zig
+++ b/src/crash_report.zig
@@ -95,9 +95,9 @@ fn dumpCrashContext() Io.Writer.Error!void {
// TODO: this does mean that a different thread could grab the stderr mutex between the context
// and the actual panic printing, which would be quite confusing.
- const stderr = std.debug.lockStderrWriter(&.{});
- defer std.debug.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = std.debug.lockStderr(&.{});
+ defer std.debug.unlockStderr();
+ const w = &stderr.file_writer.interface;
try w.writeAll("Compiler crash context:\n");
diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig
index a76fec9237..8cf1dfa303 100644
--- a/src/libs/mingw.zig
+++ b/src/libs/mingw.zig
@@ -314,14 +314,14 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
if (comp.verbose_cc) {
var buffer: [256]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
w.print("def file: {s}\n", .{def_file_path}) catch |err| switch (err) {
- error.WriteFailed => return stderr.err.?,
+ error.WriteFailed => return stderr.file_writer.err.?,
};
w.print("include dir: {s}\n", .{include_dir}) catch |err| switch (err) {
- error.WriteFailed => return stderr.err.?,
+ error.WriteFailed => return stderr.file_writer.err.?,
};
}
@@ -339,12 +339,12 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
if (aro_comp.diagnostics.output.to_list.messages.items.len != 0) {
var buffer: [64]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
for (aro_comp.diagnostics.output.to_list.messages.items) |msg| {
if (msg.kind == .@"fatal error" or msg.kind == .@"error") {
- msg.write(&stderr.interface, stderr.mode, true) catch |err| switch (err) {
- error.WriteFailed => return stderr.err.?,
+ msg.write(stderr.terminal(), true) catch |err| switch (err) {
+ error.WriteFailed => return stderr.file_writer.err.?,
};
return error.AroPreprocessorFailed;
}
@@ -365,9 +365,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
error.OutOfMemory => |e| return e,
error.ParseError => {
var buffer: [64]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
try w.writeAll("error: ");
try def_diagnostics.writeMsg(w, input);
try w.writeByte('\n');
diff --git a/src/libs/mingw/def.zig b/src/libs/mingw/def.zig
index 9a105b6182..f1c112d16e 100644
--- a/src/libs/mingw/def.zig
+++ b/src/libs/mingw/def.zig
@@ -1039,9 +1039,9 @@ fn testParse(
const module = parse(std.testing.allocator, source, machine_type, .mingw, &diagnostics) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
error.ParseError => {
- const stderr = try io.lockStderrWriter(&.{});
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&.{}, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
try diagnostics.writeMsg(w, source);
try w.writeByte('\n');
return err;
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index d379669613..03b757f5b4 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -2382,9 +2382,9 @@ pub fn dump(coff: *Coff, tid: Zcu.PerThread.Id) Io.Cancelable!void {
const comp = coff.base.comp;
const io = comp.io;
var buffer: [512]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.unlockStderr();
+ const w = &stderr.file_writer.interface;
coff.printNode(tid, w, .root, 0) catch |err| switch (err) {
error.WriteFailed => return stderr.err.?,
};
diff --git a/src/link/Elf2.zig b/src/link/Elf2.zig
index 3c511f1ee9..bbdb439385 100644
--- a/src/link/Elf2.zig
+++ b/src/link/Elf2.zig
@@ -3733,9 +3733,9 @@ pub fn dump(elf: *Elf, tid: Zcu.PerThread.Id) Io.Cancelable!void {
const comp = elf.base.comp;
const io = comp.io;
var buffer: [512]u8 = undefined;
- const stderr = try io.lockStderrWriter(&buffer);
- defer io.unlockStderrWriter();
- const w = &stderr.interface;
+ const stderr = try io.lockStderr(&buffer, null);
+ defer io.lockStderr();
+ const w = &stderr.file_writer.interface;
elf.printNode(tid, w, .root, 0) catch |err| switch (err) {
error.WriteFailed => return stderr.err.?,
};
diff --git a/src/main.zig b/src/main.zig
index c5ed278921..8e30febb81 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -4429,9 +4429,9 @@ fn runOrTest(
// the error message and invocation below.
if (process.can_execv and arg_mode == .run) {
// execv releases the locks; no need to destroy the Compilation here.
- _ = try io.lockStderrWriter(&.{});
+ _ = try io.lockStderr(&.{}, .no_color);
const err = process.execve(gpa, argv.items, &env_map);
- io.unlockStderrWriter();
+ io.unlockStderr();
try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd });
@@ -4448,8 +4448,8 @@ fn runOrTest(
comp_destroyed.* = true;
const term_result = t: {
- _ = try io.lockStderrWriter(&.{});
- defer io.unlockStderrWriter();
+ _ = try io.lockStderr(&.{}, .no_color);
+ defer io.unlockStderr();
break :t child.spawnAndWait(io);
};
const term = term_result catch |err| {
@@ -5418,8 +5418,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
child.stderr_behavior = .Inherit;
const term = t: {
- _ = try io.lockStderrWriter(&.{});
- defer io.unlockStderrWriter();
+ _ = try io.lockStderr(&.{}, .no_color);
+ defer io.unlockStderr();
break :t child.spawnAndWait(io) catch |err|
fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err });
};