authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-17 23:12:11-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:10-08:00
loga5b719e9eb0a196a43a88af8f62c897d1ecfa04f
treec16e729ed99629d26e529dd48f2fee668fbfd030
parent608145c2f07d90c46cdaa8bc2013f31b965a5b8b

compiler: fix build failures from std.Io-fs


17 files changed, 67 insertions(+), 71 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+5-5
......@@ -541,11 +541,11 @@ fn addMessage(d: *Diagnostics, msg: Message) Compilation.Error!void {
541541
542542 switch (d.output) {
543543 .ignore => {},
544 .to_writer => |writer| {
545 var config = writer.color;
546 if (d.color == false) config = .no_color;
547 if (d.color == true and config == .no_color) config = .escape_codes;
548 msg.write(writer.writer, config, d.details) catch {
544 .to_writer => |t| {
545 var new_mode = t.mode;
546 if (d.color == false) new_mode = .no_color;
547 if (d.color == true and new_mode == .no_color) new_mode = .escape_codes;
548 msg.write(.{ .writer = t.writer, .mode = new_mode }, d.details) catch {
549549 return error.FatalError;
550550 };
551551 },
lib/std/Io/Dir.zig+1-1
......@@ -1739,7 +1739,7 @@ pub fn setFilePermissions(
17391739 new_permissions: File.Permissions,
17401740 options: SetFilePermissionsOptions,
17411741) SetFilePermissionsError!void {
1742 return io.vtable.dirSetFilePermissions(io.userdata, sub_path, dir, new_permissions, options);
1742 return io.vtable.dirSetFilePermissions(io.userdata, dir, sub_path, new_permissions, options);
17431743}
17441744
17451745pub const SetOwnerError = File.SetOwnerError;
lib/std/Io/Threaded.zig+1-1
......@@ -10139,7 +10139,7 @@ fn initLockedStderr(
1013910139 t.stderr_writer.interface.buffer = buffer;
1014010140 return .{
1014110141 .file_writer = &t.stderr_writer,
10142 .terminal_mode = t.stderr_mode,
10142 .terminal_mode = terminal_mode orelse t.stderr_mode,
1014310143 };
1014410144}
1014510145
lib/std/zig/llvm/Builder.zig+2-2
......@@ -9576,10 +9576,10 @@ pub fn asmValue(
95769576 return (try self.asmConst(ty, info, assembly, constraints)).toValue();
95779577}
95789578
9579pub fn dump(b: *Builder) void {
9579pub fn dump(b: *Builder, io: Io) void {
95809580 var buffer: [4000]u8 = undefined;
95819581 const stderr: Io.File = .stderr();
9582 b.printToFile(stderr, &buffer) catch {};
9582 b.printToFile(io, stderr, &buffer) catch {};
95839583}
95849584
95859585pub fn printToFilePath(b: *Builder, io: Io, dir: Io.Dir, path: []const u8) !void {
src/Compilation.zig+13-19
......@@ -2101,6 +2101,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21012101 error.Canceled => |e| return e,
21022102 else => {},
21032103 },
2104 error.OutOfMemory => |e| return e,
21042105 };
21052106 }
21062107 }
......@@ -2708,7 +2709,7 @@ fn printVerboseLlvmCpuFeatures(
27082709 root_name: []const u8,
27092710 target: *const std.Target,
27102711 cf: [*:0]const u8,
2711) Writer.Error!void {
2712) (Writer.Error || Allocator.Error)!void {
27122713 try w.print("compilation: {s}\n", .{root_name});
27132714 try w.print(" target: {s}\n", .{try target.zigTriple(arena)});
27142715 try w.print(" cpu: {s}\n", .{target.cpu.model.name});
......@@ -3113,7 +3114,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
31133114
31143115 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
31153116 std.debug.print("intern pool stats for '{s}':\n", .{comp.root_name});
3116 zcu.intern_pool.dump(io);
3117 zcu.intern_pool.dump();
31173118 }
31183119
31193120 if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {
......@@ -3320,11 +3321,8 @@ pub fn resolveEmitPathFlush(
33203321 },
33213322 }
33223323}
3323fn flush(
3324 comp: *Compilation,
3325 arena: Allocator,
3326 tid: Zcu.PerThread.Id,
3327) Allocator.Error!void {
3324
3325fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id) (Io.Cancelable || Allocator.Error)!void {
33283326 const io = comp.io;
33293327 if (comp.zcu) |zcu| {
33303328 if (zcu.llvm_object) |llvm_object| {
......@@ -3390,7 +3388,7 @@ fn flush(
33903388 // This is needed before reading the error flags.
33913389 lf.flush(arena, tid, comp.link_prog_node) catch |err| switch (err) {
33923390 error.LinkFailure => {}, // Already reported.
3393 error.OutOfMemory => return error.OutOfMemory,
3391 error.OutOfMemory, error.Canceled => |e| return e,
33943392 };
33953393 }
33963394 if (comp.zcu) |zcu| {
......@@ -3614,6 +3612,7 @@ fn emitFromCObject(
36143612 new_ext: []const u8,
36153613 unresolved_emit_path: []const u8,
36163614) Allocator.Error!void {
3615 const io = comp.io;
36173616 // The dirname and stem (i.e. everything but the extension), of the sub path of the C object.
36183617 // We'll append `new_ext` to it to get the path to the right thing (asm, LLVM IR, etc).
36193618 const c_obj_dir_and_stem: []const u8 = p: {
......@@ -3623,23 +3622,18 @@ fn emitFromCObject(
36233622 };
36243623 const src_path: Cache.Path = .{
36253624 .root_dir = c_obj_path.root_dir,
3626 .sub_path = try std.fmt.allocPrint(arena, "{s}{s}", .{
3627 c_obj_dir_and_stem,
3628 new_ext,
3629 }),
3625 .sub_path = try std.fmt.allocPrint(arena, "{s}{s}", .{ c_obj_dir_and_stem, new_ext }),
36303626 };
36313627 const emit_path = comp.resolveEmitPath(unresolved_emit_path);
36323628
3633 src_path.root_dir.handle.copyFile(
3629 Io.Dir.copyFile(
3630 src_path.root_dir.handle,
36343631 src_path.sub_path,
36353632 emit_path.root_dir.handle,
36363633 emit_path.sub_path,
3634 io,
36373635 .{},
3638 ) catch |err| log.err("unable to copy '{f}' to '{f}': {s}", .{
3639 src_path,
3640 emit_path,
3641 @errorName(err),
3642 });
3636 ) catch |err| log.err("unable to copy '{f}' to '{f}': {t}", .{ src_path, emit_path, err });
36433637}
36443638
36453639/// Having the file open for writing is problematic as far as executing the
......@@ -7787,7 +7781,7 @@ pub fn lockAndSetMiscFailure(
77877781
77887782pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void {
77897783 var buffer: [64]u8 = undefined;
7790 const stderr = try io.lockStderr(&buffer);
7784 const stderr = try io.lockStderr(&buffer, null);
77917785 defer io.unlockStderr();
77927786 const w = &stderr.file_writer.interface;
77937787 return dumpArgvWriter(w, argv) catch |err| switch (err) {
src/InternPool.zig+13-13
......@@ -11167,16 +11167,16 @@ pub fn mutateVarInit(ip: *InternPool, io: Io, index: Index, init_index: Index) v
1116711167 @atomicStore(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.Variable, "init").?], @intFromEnum(init_index), .release);
1116811168}
1116911169
11170pub fn dump(ip: *const InternPool, io: Io) Io.Cancelable!void {
11170pub fn dump(ip: *const InternPool) void {
1117111171 var buffer: [4096]u8 = undefined;
11172 const stderr = try io.lockStderr(&buffer, null);
11173 defer io.unlockStderr();
11172 const stderr = std.debug.lockStderr(&buffer);
11173 defer std.debug.unlockStderr();
1117411174 const w = &stderr.file_writer.interface;
11175 try dumpStatsFallible(ip, w, std.heap.page_allocator);
11176 try dumpAllFallible(ip, w);
11175 dumpStatsFallible(ip, w, std.heap.page_allocator) catch return;
11176 dumpAllFallible(ip, w) catch return;
1117711177}
1117811178
11179fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) anyerror!void {
11179fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !void {
1118011180 var items_len: usize = 0;
1118111181 var extra_len: usize = 0;
1118211182 var limbs_len: usize = 0;
......@@ -11429,9 +11429,9 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) any
1142911429 };
1143011430 counts.sort(SortContext{ .map = &counts });
1143111431 const len = @min(50, counts.count());
11432 w.print(" top 50 tags:\n", .{});
11432 try w.print(" top 50 tags:\n", .{});
1143311433 for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| {
11434 w.print(" {t}: {d} occurrences, {d} total bytes\n", .{ tag, stats.count, stats.bytes });
11434 try w.print(" {t}: {d} occurrences, {d} total bytes\n", .{ tag, stats.count, stats.bytes });
1143511435 }
1143611436}
1143711437
......@@ -11534,12 +11534,12 @@ fn dumpAllFallible(ip: *const InternPool, w: *Io.Writer) anyerror!void {
1153411534 }
1153511535}
1153611536
11537pub fn dumpGenericInstances(ip: *const InternPool, io: Io, allocator: Allocator) Io.Cancelable!void {
11537pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void {
1153811538 var buffer: [4096]u8 = undefined;
11539 const stderr_writer = try io.lockStderr(&buffer, null);
11540 defer io.unlockStderr();
11541 const w = &stderr_writer.interface;
11542 try ip.dumpGenericInstancesFallible(allocator, w);
11539 const stderr = std.debug.lockStderr(&buffer);
11540 defer std.debug.unlockStderr();
11541 const w = &stderr.file_writer.interface;
11542 ip.dumpGenericInstancesFallible(allocator, w) catch return;
1154311543}
1154411544
1154511545pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator, w: *Io.Writer) !void {
src/Package/Fetch.zig+6-9
......@@ -1682,18 +1682,18 @@ fn hashFileFallible(io: Io, dir: Io.Dir, hashed_file: *HashedFile) HashedFile.Er
16821682 hasher.update(&.{ 0, 0 });
16831683 var file_header: FileHeader = .{};
16841684 while (true) {
1685 const bytes_read = try file.read(&buf);
1685 const bytes_read = try file.readPositional(io, &.{&buf}, file_size);
16861686 if (bytes_read == 0) break;
16871687 file_size += bytes_read;
16881688 hasher.update(buf[0..bytes_read]);
16891689 file_header.update(buf[0..bytes_read]);
16901690 }
16911691 if (file_header.isExecutable()) {
1692 try setExecutable(file);
1692 try setExecutable(io, file);
16931693 }
16941694 },
16951695 .link => {
1696 const link_name = try dir.readLink(io, hashed_file.fs_path, &buf);
1696 const link_name = buf[0..try dir.readLink(io, hashed_file.fs_path, &buf)];
16971697 if (fs.path.sep != canonical_sep) {
16981698 // Package hashes are intended to be consistent across
16991699 // platforms which means we must normalize path separators
......@@ -1711,12 +1711,9 @@ fn deleteFileFallible(io: Io, dir: Io.Dir, deleted_file: *DeletedFile) DeletedFi
17111711 try dir.deleteFile(io, deleted_file.fs_path);
17121712}
17131713
1714fn setExecutable(file: Io.File) !void {
1714fn setExecutable(io: Io, file: Io.File) !void {
17151715 if (!Io.File.Permissions.has_executable_bit) return;
1716
1717 const S = std.posix.S;
1718 const mode = Io.File.default_mode | S.IXUSR | S.IXGRP | S.IXOTH;
1719 try file.chmod(mode);
1716 try file.setPermissions(io, .executable_file);
17201717}
17211718
17221719const DeletedFile = struct {
......@@ -1738,7 +1735,7 @@ const HashedFile = struct {
17381735
17391736 const Error =
17401737 Io.File.OpenError ||
1741 Io.File.Reader.Error ||
1738 Io.File.ReadPositionalError ||
17421739 Io.File.StatError ||
17431740 Io.File.SetPermissionsError ||
17441741 Io.Dir.ReadLinkError;
src/codegen/aarch64/Select.zig+1-1
......@@ -11280,7 +11280,7 @@ pub fn dumpValues(isel: *Select, which: enum { only_referenced, all }) void {
1128011280
1128111281 errdefer |err| @panic(@errorName(err));
1128211282
11283 const locked_stderr = std.debug.lockStderr(&.{}, null);
11283 const locked_stderr = std.debug.lockStderr(&.{});
1128411284 defer std.debug.unlockStderr();
1128511285 const stderr = &locked_stderr.file_writer.interface;
1128611286
src/codegen/llvm.zig+9-9
......@@ -965,10 +965,10 @@ pub const Object = struct {
965965 const context, const module = emit: {
966966 if (options.pre_ir_path) |path| {
967967 if (std.mem.eql(u8, path, "-")) {
968 o.builder.dump();
968 o.builder.dump(io);
969969 } else {
970 o.builder.printToFilePath(Io.Dir.cwd(), path) catch |err| {
971 log.err("failed printing LLVM module to \"{s}\": {s}", .{ path, @errorName(err) });
970 o.builder.printToFilePath(io, Io.Dir.cwd(), path) catch |err| {
971 log.err("failed printing LLVM module to \"{s}\": {t}", .{ path, err });
972972 };
973973 }
974974 }
......@@ -982,12 +982,12 @@ pub const Object = struct {
982982
983983 if (options.pre_bc_path) |path| {
984984 var file = Io.Dir.cwd().createFile(io, path, .{}) catch |err|
985 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
985 return diags.fail("failed to create '{s}': {t}", .{ path, err });
986986 defer file.close(io);
987987
988988 const ptr: [*]const u8 = @ptrCast(bitcode.ptr);
989 file.writeAll(ptr[0..(bitcode.len * 4)]) catch |err|
990 return diags.fail("failed to write to '{s}': {s}", .{ path, @errorName(err) });
989 file.writeStreamingAll(io, ptr[0..(bitcode.len * 4)]) catch |err|
990 return diags.fail("failed to write to '{s}': {t}", .{ path, err });
991991 }
992992
993993 if (options.asm_path == null and options.bin_path == null and
......@@ -995,12 +995,12 @@ pub const Object = struct {
995995
996996 if (options.post_bc_path) |path| {
997997 var file = Io.Dir.cwd().createFile(io, path, .{}) catch |err|
998 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
998 return diags.fail("failed to create '{s}': {t}", .{ path, err });
999999 defer file.close(io);
10001000
10011001 const ptr: [*]const u8 = @ptrCast(bitcode.ptr);
1002 file.writeAll(ptr[0..(bitcode.len * 4)]) catch |err|
1003 return diags.fail("failed to write to '{s}': {s}", .{ path, @errorName(err) });
1002 file.writeStreamingAll(io, ptr[0..(bitcode.len * 4)]) catch |err|
1003 return diags.fail("failed to write to '{s}': {t}", .{ path, err });
10041004 }
10051005
10061006 if (!build_options.have_llvm or !comp.config.use_lib_llvm) {
src/libs/mingw.zig+1
......@@ -345,6 +345,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
345345 if (msg.kind == .@"fatal error" or msg.kind == .@"error") {
346346 msg.write(stderr.terminal(), true) catch |err| switch (err) {
347347 error.WriteFailed => return stderr.file_writer.err.?,
348 error.Unexpected => |e| return e,
348349 };
349350 return error.AroPreprocessorFailed;
350351 }
src/link.zig+1-2
......@@ -900,10 +900,9 @@ pub const File = struct {
900900 }
901901 }
902902
903 pub const FlushError = error{
903 pub const FlushError = Io.Cancelable || Allocator.Error || error{
904904 /// Indicates an error will be present in `Compilation.link_diags`.
905905 LinkFailure,
906 OutOfMemory,
907906 };
908907
909908 /// Commit pending changes and write headers. Takes into account final output mode.
src/link/Elf.zig+3-2
......@@ -748,9 +748,10 @@ pub fn flush(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std
748748 defer tracy.end();
749749
750750 const comp = self.base.comp;
751 const io = comp.io;
751752 const diags = &comp.link_diags;
752753
753 if (comp.verbose_link) Compilation.dump_argv(self.dump_argv_list.items);
754 if (comp.verbose_link) try Compilation.dumpArgv(io, self.dump_argv_list.items);
754755
755756 const sub_prog_node = prog_node.start("ELF Flush", 0);
756757 defer sub_prog_node.end();
......@@ -758,7 +759,7 @@ pub fn flush(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std
758759 return flushInner(self, arena, tid) catch |err| switch (err) {
759760 error.OutOfMemory => return error.OutOfMemory,
760761 error.LinkFailure => return error.LinkFailure,
761 else => |e| return diags.fail("ELF flush failed: {s}", .{@errorName(e)}),
762 else => |e| return diags.fail("ELF flush failed: {t}", .{e}),
762763 };
763764}
764765
src/link/Lld.zig+1-1
......@@ -1588,7 +1588,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi
15881588
15891589 if (comp.verbose_link) {
15901590 // Skip over our own name so that the LLD linker name is the first argv item.
1591 Compilation.dump_argv(argv[1..]);
1591 try Compilation.dumpArgv(io, argv[1..]);
15921592 }
15931593
15941594 // If possible, we run LLD as a child process because it does not always
src/link/MachO.zig+5-3
......@@ -618,14 +618,16 @@ pub fn flush(
618618 };
619619 const emit = self.base.emit;
620620 invalidateKernelCache(emit.root_dir.handle, emit.sub_path) catch |err| switch (err) {
621 else => |e| return diags.fail("failed to invalidate kernel cache: {s}", .{@errorName(e)}),
621 else => |e| return diags.fail("failed to invalidate kernel cache: {t}", .{e}),
622622 };
623623 }
624624}
625625
626626/// --verbose-link output
627627fn dumpArgv(self: *MachO, comp: *Compilation) !void {
628 const gpa = self.base.comp.gpa;
628 const gpa = comp.gpa;
629 const io = comp.io;
630
629631 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
630632 defer arena_allocator.deinit();
631633 const arena = arena_allocator.allocator();
......@@ -820,7 +822,7 @@ fn dumpArgv(self: *MachO, comp: *Compilation) !void {
820822 if (comp.ubsan_rt_obj) |obj| try argv.append(try obj.full_object_path.toString(arena));
821823 }
822824
823 Compilation.dump_argv(argv.items);
825 try Compilation.dumpArgv(io, argv.items);
824826}
825827
826828/// TODO delete this, libsystem must be resolved when setting up the compilation pipeline
src/link/MappedFile.zig+2-2
......@@ -476,8 +476,8 @@ pub const Node = extern struct {
476476 return n;
477477 },
478478 .streaming,
479 .streaming_reading,
480 .positional_reading,
479 .streaming_simple,
480 .positional_simple,
481481 .failure,
482482 => {
483483 const dest = limit.slice(interface.unusedCapacitySlice());
src/link/Queue.zig+1
......@@ -175,6 +175,7 @@ fn runLinkTasks(q: *Queue, comp: *Compilation) void {
175175 lf.post_prelink = true;
176176 } else |err| switch (err) {
177177 error.OutOfMemory => comp.link_diags.setAllocFailure(),
178 error.Canceled => @panic("TODO"),
178179 error.LinkFailure => {},
179180 }
180181 }
src/link/Wasm.zig+2-1
......@@ -3828,8 +3828,9 @@ pub fn flush(
38283828 const comp = wasm.base.comp;
38293829 const diags = &comp.link_diags;
38303830 const gpa = comp.gpa;
3831 const io = comp.io;
38313832
3832 if (comp.verbose_link) Compilation.dump_argv(wasm.dump_argv_list.items);
3833 if (comp.verbose_link) try Compilation.dumpArgv(io, wasm.dump_argv_list.items);
38333834
38343835 if (wasm.base.zcu_object_basename) |raw| {
38353836 const zcu_obj_path: Path = try comp.resolveEmitPathFlush(arena, .temp, raw);