authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-14 23:35:33-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log16bd2e137e56f842a9ff5e015425f9e08eeb97fd
tree4a4b46fd3eeeb52fa964f8753515e8c0ca4a6781
parent4458e423bf2d2cf485031d1f527e407bfc9113df

compiler: fix most compilation errors from std.fs changes


23 files changed, 177 insertions(+), 156 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+1-1
......@@ -24,7 +24,7 @@ pub const Message = struct {
2424 @"fatal error",
2525 };
2626
27 pub fn write(msg: Message, w: *std.Io.Writer, config: std.Io.tty.Config, details: bool) std.Io.tty.Config.SetColorError!void {
27 pub fn write(msg: Message, w: *std.Io.Writer, config: std.Io.File.Writer.Mode, details: bool) std.Io.tty.Config.SetColorError!void {
2828 try config.setColor(w, .bold);
2929 if (msg.location) |loc| {
3030 try w.print("{s}:{d}:{d}: ", .{ loc.path, loc.line_no, loc.col });
lib/compiler/aro/aro/Preprocessor.zig+4-2
......@@ -1065,11 +1065,13 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
10651065
10661066fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) void {
10671067 @branchHint(.cold);
1068 const source = pp.comp.getSource(raw.source);
1068 const comp = pp.comp;
1069 const io = comp.io;
1070 const source = comp.getSource(raw.source);
10691071 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
10701072
10711073 var stderr_buf: [4096]u8 = undefined;
1072 var stderr = Io.File.stderr().writer(&stderr_buf);
1074 var stderr = Io.File.stderr().writer(io, &stderr_buf);
10731075 const w = &stderr.interface;
10741076
10751077 w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
lib/std/Build/Cache/Path.zig+2-1
......@@ -106,6 +106,7 @@ pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
106106
107107pub fn atomicFile(
108108 p: Path,
109 io: Io,
109110 sub_path: []const u8,
110111 options: Io.Dir.AtomicFileOptions,
111112 buf: *[fs.max_path_bytes]u8,
......@@ -115,7 +116,7 @@ pub fn atomicFile(
115116 p.sub_path, sub_path,
116117 }) catch return error.NameTooLong;
117118 };
118 return p.root_dir.handle.atomicFile(joined_path, options);
119 return p.root_dir.handle.atomicFile(io, joined_path, options);
119120}
120121
121122pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
lib/std/Io/Dir.zig+1-1
......@@ -1645,7 +1645,7 @@ pub fn copyFile(
16451645 .permissions = permissions,
16461646 .write_buffer = &buffer,
16471647 });
1648 defer atomic_file.deinit(io);
1648 defer atomic_file.deinit();
16491649
16501650 _ = atomic_file.file_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {
16511651 error.ReadFailed => return file_reader.err.?,
lib/std/crypto/Certificate/Bundle.zig+2-1
......@@ -202,7 +202,7 @@ pub const AddCertsFromDirError = AddCertsFromFilePathError;
202202
203203pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, iterable_dir: Io.Dir) AddCertsFromDirError!void {
204204 var it = iterable_dir.iterate();
205 while (try it.next()) |entry| {
205 while (try it.next(io)) |entry| {
206206 switch (entry.kind) {
207207 .file, .sym_link => {},
208208 else => continue,
......@@ -243,6 +243,7 @@ pub fn addCertsFromFilePath(
243243
244244pub const AddCertsFromFileError = Allocator.Error ||
245245 Io.File.Reader.Error ||
246 Io.File.Reader.SizeError ||
246247 ParseCertError ||
247248 std.base64.Error ||
248249 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
lib/std/fs/test.zig+1-1
......@@ -1598,7 +1598,7 @@ test "AtomicFile" {
15981598
15991599 {
16001600 var buffer: [100]u8 = undefined;
1601 var af = try ctx.dir.atomicFile(test_out_file, .{ .write_buffer = &buffer });
1601 var af = try ctx.dir.atomicFile(io, test_out_file, .{ .write_buffer = &buffer });
16021602 defer af.deinit();
16031603 try af.file_writer.interface.writeAll(test_content);
16041604 try af.finish();
lib/std/zig.zig+1-1
......@@ -648,7 +648,7 @@ pub fn printAstErrorsToStderr(gpa: Allocator, io: Io, tree: Ast, path: []const u
648648
649649 var error_bundle = try wip_errors.toOwnedBundle("");
650650 defer error_bundle.deinit(gpa);
651 error_bundle.renderToStderr(io, .{}, color);
651 return error_bundle.renderToStderr(io, .{}, color);
652652}
653653
654654pub fn putAstErrorsIntoBundle(
lib/std/zig/ErrorBundle.zig+2-2
......@@ -162,14 +162,14 @@ pub const RenderOptions = struct {
162162 include_log_text: bool = true,
163163};
164164
165pub const RenderToStderrError = Io.Cancelable || Io.File.Writer.Mode.SetColorError;
165pub const RenderToStderrError = Io.Cancelable || Io.File.Writer.Error;
166166
167167pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: std.zig.Color) RenderToStderrError!void {
168168 var buffer: [256]u8 = undefined;
169169 const stderr = try io.lockStderrWriter(&buffer);
170170 defer io.unlockStderrWriter();
171171 renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)) catch |err| switch (err) {
172 error.WriteFailed => return stderr.interface.err.?,
172 error.WriteFailed => return stderr.err.?,
173173 else => |e| return e,
174174 };
175175}
lib/std/zig/LibCDirs.zig+11-8
......@@ -1,3 +1,11 @@
1const LibCDirs = @This();
2const builtin = @import("builtin");
3
4const std = @import("../std.zig");
5const Io = std.Io;
6const LibCInstallation = std.zig.LibCInstallation;
7const Allocator = std.mem.Allocator;
8
19libc_include_dir_list: []const []const u8,
210libc_installation: ?*const LibCInstallation,
311libc_framework_dir_list: []const []const u8,
......@@ -14,6 +22,7 @@ pub const DarwinSdkLayout = enum {
1422
1523pub fn detect(
1624 arena: Allocator,
25 io: Io,
1726 zig_lib_dir: []const u8,
1827 target: *const std.Target,
1928 is_native_abi: bool,
......@@ -38,7 +47,7 @@ pub fn detect(
3847 // using the system libc installation.
3948 if (is_native_abi and !target.isMinGW()) {
4049 const libc = try arena.create(LibCInstallation);
41 libc.* = LibCInstallation.findNative(.{ .allocator = arena, .target = target }) catch |err| switch (err) {
50 libc.* = LibCInstallation.findNative(arena, io, .{ .target = target }) catch |err| switch (err) {
4251 error.CCompilerExitCode,
4352 error.CCompilerCrashed,
4453 error.CCompilerCannotFindHeaders,
......@@ -75,7 +84,7 @@ pub fn detect(
7584
7685 if (use_system_abi) {
7786 const libc = try arena.create(LibCInstallation);
78 libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true, .target = target });
87 libc.* = try LibCInstallation.findNative(arena, io, .{ .verbose = true, .target = target });
7988 return detectFromInstallation(arena, target, libc);
8089 }
8190
......@@ -265,9 +274,3 @@ fn libCGenericName(target: *const std.Target) [:0]const u8 {
265274 => unreachable,
266275 }
267276}
268
269const LibCDirs = @This();
270const builtin = @import("builtin");
271const std = @import("../std.zig");
272const LibCInstallation = std.zig.LibCInstallation;
273const Allocator = std.mem.Allocator;
lib/std/zig/LibCInstallation.zig+3-3
......@@ -204,7 +204,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
204204 try self.findNativeIncludeDirWindows(gpa, io, args, sdk);
205205 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);
206206 } else if (is_haiku) {
207 try self.findNativeIncludeDirPosix(args);
207 try self.findNativeIncludeDirPosix(gpa, io, args);
208208 try self.findNativeGccDirHaiku(gpa, io, args);
209209 self.crt_dir = try gpa.dupeZ(u8, "/system/develop/lib");
210210 } else if (builtin.target.os.tag == .illumos) {
......@@ -213,7 +213,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
213213 self.sys_include_dir = try gpa.dupeZ(u8, "/usr/include");
214214 self.crt_dir = try gpa.dupeZ(u8, "/usr/lib/64");
215215 } else if (std.process.can_spawn) {
216 try self.findNativeIncludeDirPosix(args);
216 try self.findNativeIncludeDirPosix(gpa, io, args);
217217 switch (builtin.target.os.tag) {
218218 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupeZ(u8, "/usr/lib"),
219219 .linux => try self.findNativeCrtDirPosix(gpa, io, args),
......@@ -335,7 +335,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
335335 defer search_dir.close(io);
336336
337337 if (self.include_dir == null) {
338 if (search_dir.access(include_dir_example_file, .{})) |_| {
338 if (search_dir.access(io, include_dir_example_file, .{})) |_| {
339339 self.include_dir = try gpa.dupeZ(u8, search_path);
340340 } else |err| switch (err) {
341341 error.FileNotFound => {},
src/Builtin.zig+1-1
......@@ -343,7 +343,7 @@ pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {
343343 }
344344
345345 // `make_path` matters because the dir hasn't actually been created yet.
346 var af = try root_dir.atomicFile(sub_path, .{ .make_path = true, .write_buffer = &.{} });
346 var af = try root_dir.atomicFile(io, sub_path, .{ .make_path = true, .write_buffer = &.{} });
347347 defer af.deinit();
348348 try af.file_writer.interface.writeAll(file.source.?);
349349 af.finish() catch |err| switch (err) {
src/Compilation.zig+68-70
......@@ -771,8 +771,8 @@ pub const Directories = struct {
771771 const zig_lib: Cache.Directory = d: {
772772 if (override_zig_lib) |path| break :d openUnresolved(arena, io, cwd, path, .@"zig lib");
773773 if (wasi) break :d openWasiPreopen(wasi_preopens, "/lib");
774 break :d introspect.findZigLibDirFromSelfExe(arena, cwd, self_exe_path) catch |err| {
775 fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
774 break :d introspect.findZigLibDirFromSelfExe(arena, io, cwd, self_exe_path) catch |err| {
775 fatal("unable to find zig installation directory '{s}': {t}", .{ self_exe_path, err });
776776 };
777777 };
778778
......@@ -780,7 +780,7 @@ pub const Directories = struct {
780780 if (override_global_cache) |path| break :d openUnresolved(arena, io, cwd, path, .@"global cache");
781781 if (wasi) break :d openWasiPreopen(wasi_preopens, "/cache");
782782 const path = introspect.resolveGlobalCacheDir(arena) catch |err| {
783 fatal("unable to resolve zig cache directory: {s}", .{@errorName(err)});
783 fatal("unable to resolve zig cache directory: {t}", .{err});
784784 };
785785 break :d openUnresolved(arena, io, cwd, path, .@"global cache");
786786 };
......@@ -789,7 +789,7 @@ pub const Directories = struct {
789789 .override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"),
790790 .search => d: {
791791 const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, io, cwd) catch |err| {
792 fatal("unable to resolve zig cache directory: {s}", .{@errorName(err)});
792 fatal("unable to resolve zig cache directory: {t}", .{err});
793793 };
794794 const path = maybe_path orelse break :d global_cache;
795795 break :d openUnresolved(arena, io, cwd, path, .@"local cache");
......@@ -919,8 +919,8 @@ pub const CrtFile = struct {
919919 lock: Cache.Lock,
920920 full_object_path: Cache.Path,
921921
922 pub fn deinit(self: *CrtFile, gpa: Allocator) void {
923 self.lock.release();
922 pub fn deinit(self: *CrtFile, gpa: Allocator, io: Io) void {
923 self.lock.release(io);
924924 gpa.free(self.full_object_path.sub_path);
925925 self.* = undefined;
926926 }
......@@ -1317,7 +1317,7 @@ pub const CObject = struct {
13171317 };
13181318
13191319 /// Returns if there was failure.
1320 pub fn clearStatus(self: *CObject, gpa: Allocator) bool {
1320 pub fn clearStatus(self: *CObject, gpa: Allocator, io: Io) bool {
13211321 switch (self.status) {
13221322 .new => return false,
13231323 .failure, .failure_retryable => {
......@@ -1326,15 +1326,15 @@ pub const CObject = struct {
13261326 },
13271327 .success => |*success| {
13281328 gpa.free(success.object_path.sub_path);
1329 success.lock.release();
1329 success.lock.release(io);
13301330 self.status = .new;
13311331 return false;
13321332 },
13331333 }
13341334 }
13351335
1336 pub fn destroy(self: *CObject, gpa: Allocator) void {
1337 _ = self.clearStatus(gpa);
1336 pub fn destroy(self: *CObject, gpa: Allocator, io: Io) void {
1337 _ = self.clearStatus(gpa, io);
13381338 gpa.destroy(self);
13391339 }
13401340};
......@@ -1364,7 +1364,7 @@ pub const Win32Resource = struct {
13641364 },
13651365
13661366 /// Returns true if there was failure.
1367 pub fn clearStatus(self: *Win32Resource, gpa: Allocator) bool {
1367 pub fn clearStatus(self: *Win32Resource, gpa: Allocator, io: Io) bool {
13681368 switch (self.status) {
13691369 .new => return false,
13701370 .failure, .failure_retryable => {
......@@ -1373,15 +1373,15 @@ pub const Win32Resource = struct {
13731373 },
13741374 .success => |*success| {
13751375 gpa.free(success.res_path);
1376 success.lock.release();
1376 success.lock.release(io);
13771377 self.status = .new;
13781378 return false;
13791379 },
13801380 }
13811381 }
13821382
1383 pub fn destroy(self: *Win32Resource, gpa: Allocator) void {
1384 _ = self.clearStatus(gpa);
1383 pub fn destroy(self: *Win32Resource, gpa: Allocator, io: Io) void {
1384 _ = self.clearStatus(gpa, io);
13851385 gpa.destroy(self);
13861386 }
13871387};
......@@ -1610,9 +1610,9 @@ const CacheUse = union(CacheMode) {
16101610 /// Prevents other processes from clobbering files in the output directory.
16111611 lock: ?Cache.Lock,
16121612
1613 fn releaseLock(whole: *Whole) void {
1613 fn releaseLock(whole: *Whole, io: Io) void {
16141614 if (whole.lock) |*lock| {
1615 lock.release();
1615 lock.release(io);
16161616 whole.lock = null;
16171617 }
16181618 }
......@@ -1634,7 +1634,7 @@ const CacheUse = union(CacheMode) {
16341634 },
16351635 .whole => |whole| {
16361636 assert(whole.tmp_artifact_directory == null);
1637 whole.releaseLock();
1637 whole.releaseLock(io);
16381638 },
16391639 }
16401640 }
......@@ -1903,13 +1903,17 @@ pub const CreateDiagnostic = union(enum) {
19031903 return error.CreateFail;
19041904 }
19051905};
1906pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, options: CreateOptions) error{
1906
1907pub const CreateError = error{
19071908 OutOfMemory,
1909 Canceled,
19081910 Unexpected,
19091911 CurrentWorkingDirectoryUnlinked,
19101912 /// An error has been stored to `diag`.
19111913 CreateFail,
1912}!*Compilation {
1914};
1915
1916pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, options: CreateOptions) CreateError!*Compilation {
19131917 const output_mode = options.config.output_mode;
19141918 const is_dyn_lib = switch (output_mode) {
19151919 .Obj, .Exe => false,
......@@ -1957,6 +1961,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
19571961
19581962 const libc_dirs = std.zig.LibCDirs.detect(
19591963 arena,
1964 io,
19601965 options.dirs.zig_lib.path.?,
19611966 target,
19621967 options.root_mod.resolved_target.is_native_abi,
......@@ -2701,7 +2706,7 @@ pub fn destroy(comp: *Compilation) void {
27012706
27022707 if (comp.bin_file) |lf| lf.destroy();
27032708 if (comp.zcu) |zcu| zcu.deinit();
2704 comp.cache_use.deinit();
2709 comp.cache_use.deinit(io);
27052710
27062711 for (&comp.work_queues) |*work_queue| work_queue.deinit(gpa);
27072712 comp.c_object_work_queue.deinit(gpa);
......@@ -2714,36 +2719,36 @@ pub fn destroy(comp: *Compilation) void {
27142719 var it = comp.crt_files.iterator();
27152720 while (it.next()) |entry| {
27162721 gpa.free(entry.key_ptr.*);
2717 entry.value_ptr.deinit(gpa);
2722 entry.value_ptr.deinit(gpa, io);
27182723 }
27192724 comp.crt_files.deinit(gpa);
27202725 }
2721 if (comp.libcxx_static_lib) |*crt_file| crt_file.deinit(gpa);
2722 if (comp.libcxxabi_static_lib) |*crt_file| crt_file.deinit(gpa);
2723 if (comp.libunwind_static_lib) |*crt_file| crt_file.deinit(gpa);
2724 if (comp.tsan_lib) |*crt_file| crt_file.deinit(gpa);
2725 if (comp.ubsan_rt_lib) |*crt_file| crt_file.deinit(gpa);
2726 if (comp.ubsan_rt_obj) |*crt_file| crt_file.deinit(gpa);
2727 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa);
2728 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa);
2729 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa);
2730 if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa);
2731 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa);
2726 if (comp.libcxx_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2727 if (comp.libcxxabi_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2728 if (comp.libunwind_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2729 if (comp.tsan_lib) |*crt_file| crt_file.deinit(gpa, io);
2730 if (comp.ubsan_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
2731 if (comp.ubsan_rt_obj) |*crt_file| crt_file.deinit(gpa, io);
2732 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2733 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
2734 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa, io);
2735 if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa, io);
2736 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io);
27322737
27332738 if (comp.glibc_so_files) |*glibc_file| {
2734 glibc_file.deinit(gpa);
2739 glibc_file.deinit(gpa, io);
27352740 }
27362741
27372742 if (comp.freebsd_so_files) |*freebsd_file| {
2738 freebsd_file.deinit(gpa);
2743 freebsd_file.deinit(gpa, io);
27392744 }
27402745
27412746 if (comp.netbsd_so_files) |*netbsd_file| {
2742 netbsd_file.deinit(gpa);
2747 netbsd_file.deinit(gpa, io);
27432748 }
27442749
27452750 for (comp.c_object_table.keys()) |key| {
2746 key.destroy(gpa);
2751 key.destroy(gpa, io);
27472752 }
27482753 comp.c_object_table.deinit(gpa);
27492754
......@@ -2753,7 +2758,7 @@ pub fn destroy(comp: *Compilation) void {
27532758 comp.failed_c_objects.deinit(gpa);
27542759
27552760 for (comp.win32_resource_table.keys()) |key| {
2756 key.destroy(gpa);
2761 key.destroy(gpa, io);
27572762 }
27582763 comp.win32_resource_table.deinit(gpa);
27592764
......@@ -2906,7 +2911,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
29062911 .whole => |whole| {
29072912 assert(comp.bin_file == null);
29082913 // We are about to obtain this lock, so here we give other processes a chance first.
2909 whole.releaseLock();
2914 whole.releaseLock(io);
29102915
29112916 man = comp.cache_parent.obtain();
29122917 whole.cache_manifest = &man;
......@@ -3092,17 +3097,12 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
30923097 }
30933098
30943099 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
3095 std.debug.print("intern pool stats for '{s}':\n", .{
3096 comp.root_name,
3097 });
3098 zcu.intern_pool.dump();
3100 std.debug.print("intern pool stats for '{s}':\n", .{comp.root_name});
3101 zcu.intern_pool.dump(io);
30993102 }
31003103
31013104 if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {
3102 std.debug.print("generic instances for '{s}:0x{x}':\n", .{
3103 comp.root_name,
3104 @intFromPtr(zcu),
3105 });
3105 std.debug.print("generic instances for '{s}:0x{x}':\n", .{ comp.root_name, @intFromPtr(zcu) });
31063106 zcu.intern_pool.dumpGenericInstances(gpa);
31073107 }
31083108 }
......@@ -3680,6 +3680,7 @@ pub fn saveState(comp: *Compilation) !void {
36803680 const lf = comp.bin_file orelse return;
36813681
36823682 const gpa = comp.gpa;
3683 const io = comp.io;
36833684
36843685 var bufs = std.array_list.Managed([]const u8).init(gpa);
36853686 defer bufs.deinit();
......@@ -3900,7 +3901,7 @@ pub fn saveState(comp: *Compilation) !void {
39003901 // Using an atomic file prevents a crash or power failure from corrupting
39013902 // the previous incremental compilation state.
39023903 var write_buffer: [1024]u8 = undefined;
3903 var af = try lf.emit.root_dir.handle.atomicFile(basename, .{ .write_buffer = &write_buffer });
3904 var af = try lf.emit.root_dir.handle.atomicFile(io, basename, .{ .write_buffer = &write_buffer });
39043905 defer af.deinit();
39053906 try af.file_writer.interface.writeVecAll(bufs.items);
39063907 try af.finish();
......@@ -4258,8 +4259,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle {
42584259 // However, we haven't reported any such error.
42594260 // This is a compiler bug.
42604261 print_ctx: {
4261 const stderr = try io.lockStderrWriter(&.{});
4262 defer io.unlockStderrWriter();
4262 const stderr = std.debug.lockStderrWriter(&.{});
4263 defer std.debug.unlockStderrWriter();
42634264 const w = &stderr.interface;
42644265 w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx;
42654266 w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx;
......@@ -5219,13 +5220,10 @@ fn processOneJob(
52195220 }
52205221}
52215222
5222fn createDepFile(
5223 comp: *Compilation,
5224 depfile: []const u8,
5225 binfile: Cache.Path,
5226) anyerror!void {
5223fn createDepFile(comp: *Compilation, depfile: []const u8, binfile: Cache.Path) anyerror!void {
5224 const io = comp.io;
52275225 var buf: [4096]u8 = undefined;
5228 var af = try Io.Dir.cwd().atomicFile(depfile, .{ .write_buffer = &buf });
5226 var af = try Io.Dir.cwd().atomicFile(io, depfile, .{ .write_buffer = &buf });
52295227 defer af.deinit();
52305228
52315229 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;
......@@ -5280,13 +5278,8 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
52805278
52815279 for (&[_][]const u8{ "docs/main.js", "docs/index.html" }) |sub_path| {
52825280 const basename = fs.path.basename(sub_path);
5283 comp.dirs.zig_lib.handle.copyFile(sub_path, out_dir, basename, .{}) catch |err| {
5284 comp.lockAndSetMiscFailure(.docs_copy, "unable to copy {s}: {s}", .{
5285 sub_path,
5286 @errorName(err),
5287 });
5288 return;
5289 };
5281 comp.dirs.zig_lib.handle.copyFile(sub_path, out_dir, basename, io, .{}) catch |err|
5282 return comp.lockAndSetMiscFailure(.docs_copy, "unable to copy {s}: {t}", .{ sub_path, err });
52905283 }
52915284
52925285 var tar_file = out_dir.createFile(io, "sources.tar", .{}) catch |err| {
......@@ -5350,7 +5343,7 @@ fn docsCopyModule(
53505343
53515344 var buffer: [1024]u8 = undefined;
53525345
5353 while (try walker.next()) |entry| {
5346 while (try walker.next(io)) |entry| {
53545347 switch (entry.kind) {
53555348 .file => {
53565349 if (!std.mem.endsWith(u8, entry.basename, ".zig")) continue;
......@@ -5505,7 +5498,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
55055498 try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node);
55065499
55075500 var crt_file = try sub_compilation.toCrtFile();
5508 defer crt_file.deinit(gpa);
5501 defer crt_file.deinit(gpa, io);
55095502
55105503 const docs_bin_file = crt_file.full_object_path;
55115504 assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory
......@@ -5521,10 +5514,12 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
55215514 };
55225515 defer out_dir.close(io);
55235516
5524 crt_file.full_object_path.root_dir.handle.copyFile(
5517 Io.Dir.copyFile(
5518 crt_file.full_object_path.root_dir.handle,
55255519 crt_file.full_object_path.sub_path,
55265520 out_dir,
55275521 "main.wasm",
5522 io,
55285523 .{},
55295524 ) catch |err| {
55305525 comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{f}' to '{f}': {t}", .{
......@@ -5758,7 +5753,7 @@ pub fn translateC(
57585753 try argv.appendSlice(comp.global_cc_argv);
57595754 try argv.appendSlice(owner_mod.cc_argv);
57605755 try argv.appendSlice(&.{ source_path, "-o", translated_path });
5761 if (comp.verbose_cimport) dumpArgv(io, argv.items);
5756 if (comp.verbose_cimport) try dumpArgv(io, argv.items);
57625757 }
57635758
57645759 var stdout: []u8 = undefined;
......@@ -6153,7 +6148,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
61536148 const gpa = comp.gpa;
61546149 const io = comp.io;
61556150
6156 if (c_object.clearStatus(gpa)) {
6151 if (c_object.clearStatus(gpa, io)) {
61576152 // There was previous failure.
61586153 comp.mutex.lockUncancelable(io);
61596154 defer comp.mutex.unlock(io);
......@@ -6500,7 +6495,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
65006495 defer arena_allocator.deinit();
65016496 const arena = arena_allocator.allocator();
65026497
6503 if (win32_resource.clearStatus(comp.gpa)) {
6498 if (win32_resource.clearStatus(comp.gpa, io)) {
65046499 // There was previous failure.
65056500 comp.mutex.lockUncancelable(io);
65066501 defer comp.mutex.unlock(io);
......@@ -6768,7 +6763,7 @@ fn spawnZigRc(
67686763 // Just in case there's a failure that didn't send an ErrorBundle (e.g. an error return trace)
67696764 const stderr = poller.reader(.stderr);
67706765
6771 const term = child.wait() catch |err| {
6766 const term = child.wait(io) catch |err| {
67726767 return comp.failWin32Resource(win32_resource, "unable to wait for {s} rc: {s}", .{ argv[0], @errorName(err) });
67736768 };
67746769
......@@ -7781,7 +7776,10 @@ pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void {
77817776 defer io.unlockStderrWriter();
77827777 const w = &stderr.interface;
77837778 return dumpArgvWriter(w, argv) catch |err| switch (err) {
7784 error.WriteFailed => return stderr.err.?,
7779 error.WriteFailed => switch (stderr.err.?) {
7780 error.Canceled => return error.Canceled,
7781 else => return,
7782 },
77857783 };
77867784}
77877785
src/Package/Fetch.zig+16-21
......@@ -501,7 +501,7 @@ fn runResource(
501501 .path = tmp_directory_path,
502502 .handle = handle: {
503503 const dir = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
504 .iterate = true,
504 .open_options = .{ .iterate = true },
505505 }) catch |err| {
506506 try eb.addRootErrorMessage(.{
507507 .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{
......@@ -525,7 +525,7 @@ fn runResource(
525525 // https://github.com/ziglang/zig/issues/17095
526526 pkg_path.root_dir.handle.close(io);
527527 pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
528 .iterate = true,
528 .open_options = .{ .iterate = true },
529529 }) catch @panic("btrfs workaround failed");
530530 }
531531
......@@ -1334,7 +1334,7 @@ fn unzip(
13341334 f.location_tok,
13351335 try eb.printString("failed writing temporary zip file: {t}", .{err}),
13361336 );
1337 break :b zip_file_writer.moveToReader(io);
1337 break :b zip_file_writer.moveToReader();
13381338 };
13391339
13401340 var diagnostics: std.zip.Diagnostics = .{ .allocator = f.arena.allocator() };
......@@ -1376,7 +1376,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13761376 const fetch_reader = &resource.fetch_stream.reader;
13771377 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);
13781378 try pack_file_writer.interface.flush();
1379 break :b pack_file_writer.moveToReader(io);
1379 break :b pack_file_writer.moveToReader();
13801380 };
13811381
13821382 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });
......@@ -1421,26 +1421,21 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
14211421 // Recursive directory copy.
14221422 var it = try dir.walk(gpa);
14231423 defer it.deinit();
1424 while (try it.next()) |entry| {
1424 while (try it.next(io)) |entry| {
14251425 switch (entry.kind) {
14261426 .directory => {}, // omit empty directories
14271427 .file => {
1428 dir.copyFile(
1429 entry.path,
1430 tmp_dir,
1431 entry.path,
1432 .{},
1433 ) catch |err| switch (err) {
1428 dir.copyFile(entry.path, tmp_dir, entry.path, io, .{}) catch |err| switch (err) {
14341429 error.FileNotFound => {
14351430 if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(io, dirname);
1436 try dir.copyFile(entry.path, tmp_dir, entry.path, .{});
1431 try dir.copyFile(entry.path, tmp_dir, entry.path, io, .{});
14371432 },
14381433 else => |e| return e,
14391434 };
14401435 },
14411436 .sym_link => {
14421437 var buf: [fs.max_path_bytes]u8 = undefined;
1443 const link_name = try dir.readLink(io, entry.path, &buf);
1438 const link_name = buf[0..try dir.readLink(io, entry.path, &buf)];
14441439 // TODO: if this would create a symlink to outside
14451440 // the destination directory, fail with an error instead.
14461441 tmp_dir.symLink(io, link_name, entry.path, .{}) catch |err| switch (err) {
......@@ -1524,7 +1519,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
15241519 var group: Io.Group = .init;
15251520 defer group.wait(io);
15261521
1527 while (walker.next() catch |err| {
1522 while (walker.next(io) catch |err| {
15281523 try eb.addRootErrorMessage(.{ .msg = try eb.printString(
15291524 "unable to walk temporary directory '{f}': {s}",
15301525 .{ pkg_path, @errorName(err) },
......@@ -1575,7 +1570,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
15751570 .failure = undefined, // to be populated by the worker
15761571 .size = undefined, // to be populated by the worker
15771572 };
1578 group.async(io, workerHashFile, .{ root_dir, hashed_file });
1573 group.async(io, workerHashFile, .{ io, root_dir, hashed_file });
15791574 try all_files.append(hashed_file);
15801575 }
15811576 }
......@@ -1643,7 +1638,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16431638 assert(!f.job_queue.recursive);
16441639 // Print something to stdout that can be text diffed to figure out why
16451640 // the package hash is different.
1646 dumpHashInfo(all_files.items) catch |err| {
1641 dumpHashInfo(io, all_files.items) catch |err| {
16471642 std.debug.print("unable to write to stdout: {s}\n", .{@errorName(err)});
16481643 std.process.exit(1);
16491644 };
......@@ -1655,9 +1650,9 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16551650 };
16561651}
16571652
1658fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1653fn dumpHashInfo(io: Io, all_files: []const *const HashedFile) !void {
16591654 var stdout_buffer: [1024]u8 = undefined;
1660 var stdout_writer: Io.File.Writer = .initStreaming(.stdout(), &stdout_buffer);
1655 var stdout_writer: Io.File.Writer = .initStreaming(.stdout(), io, &stdout_buffer);
16611656 const w = &stdout_writer.interface;
16621657 for (all_files) |hashed_file| {
16631658 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });
......@@ -1665,8 +1660,8 @@ fn dumpHashInfo(all_files: []const *const HashedFile) !void {
16651660 try w.flush();
16661661}
16671662
1668fn workerHashFile(dir: Io.Dir, hashed_file: *HashedFile) void {
1669 hashed_file.failure = hashFileFallible(dir, hashed_file);
1663fn workerHashFile(io: Io, dir: Io.Dir, hashed_file: *HashedFile) void {
1664 hashed_file.failure = hashFileFallible(io, dir, hashed_file);
16701665}
16711666
16721667fn workerDeleteFile(io: Io, dir: Io.Dir, deleted_file: *DeletedFile) void {
......@@ -1745,7 +1740,7 @@ const HashedFile = struct {
17451740 Io.File.OpenError ||
17461741 Io.File.Reader.Error ||
17471742 Io.File.StatError ||
1748 Io.File.ChmodError ||
1743 Io.File.SetPermissionsError ||
17491744 Io.Dir.ReadLinkError;
17501745
17511746 const Kind = enum { file, link };
src/Package/Fetch/git.zig+1-1
......@@ -274,7 +274,7 @@ pub const Repository = struct {
274274 continue;
275275 };
276276 defer file.close(io);
277 try file.writeAll(file_object.data);
277 try file.writePositionalAll(io, file_object.data, 0);
278278 },
279279 .symlink => {
280280 try repository.odb.seekOid(entry.oid);
src/Sema.zig+1-1
......@@ -2679,7 +2679,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg
26792679 Compilation.addModuleErrorMsg(zcu, &wip_errors, err_msg.*, false) catch @panic("out of memory");
26802680 std.debug.print("compile error during Sema:\n", .{});
26812681 var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory");
2682 error_bundle.renderToStderr(io, .{}, .auto);
2682 error_bundle.renderToStderr(io, .{}, .auto) catch @panic("failed to print to stderr");
26832683 std.debug.panicExtra(@returnAddress(), "unexpected compile error occurred", .{});
26842684 }
26852685
src/Zcu.zig+7-10
......@@ -2988,11 +2988,10 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader
29882988
29892989pub fn saveZirCache(
29902990 gpa: Allocator,
2991 io: Io,
2992 cache_file: Io.File,
2991 cache_file_writer: *Io.File.Writer,
29932992 stat: Io.File.Stat,
29942993 zir: Zir,
2995) (Io.File.WriteError || Allocator.Error)!void {
2994) (Io.File.Writer.Error || Allocator.Error)!void {
29962995 const safety_buffer = if (data_has_safety_tag)
29972996 try gpa.alloc([8]u8, zir.instructions.len)
29982997 else
......@@ -3026,13 +3025,12 @@ pub fn saveZirCache(
30263025 zir.string_bytes,
30273026 @ptrCast(zir.extra),
30283027 };
3029 var cache_fw = cache_file.writer(io, &.{});
3030 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
3031 error.WriteFailed => return cache_fw.err.?,
3028 cache_file_writer.interface.writeVecAll(&vecs) catch |err| switch (err) {
3029 error.WriteFailed => return cache_file_writer.err.?,
30323030 };
30333031}
30343032
3035pub fn saveZoirCache(io: Io, cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir) Io.File.WriteError!void {
3033pub fn saveZoirCache(cache_file_writer: *Io.File.Writer, stat: Io.File.Stat, zoir: Zoir) Io.File.Writer.Error!void {
30363034 const header: Zoir.Header = .{
30373035 .nodes_len = @intCast(zoir.nodes.len),
30383036 .extra_len = @intCast(zoir.extra.len),
......@@ -3056,9 +3054,8 @@ pub fn saveZoirCache(io: Io, cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir
30563054 @ptrCast(zoir.compile_errors),
30573055 @ptrCast(zoir.error_notes),
30583056 };
3059 var cache_fw = cache_file.writer(io, &.{});
3060 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
3061 error.WriteFailed => return cache_fw.err.?,
3057 cache_file_writer.interface.writeVecAll(&vecs) catch |err| switch (err) {
3058 error.WriteFailed => return cache_file_writer.err.?,
30623059 };
30633060}
30643061
src/Zcu/PerThread.zig+35-15
......@@ -238,18 +238,13 @@ pub fn updateFile(
238238 if (builtin.os.tag == .wasi or lock == .exclusive) break true;
239239 // Otherwise, unlock to give someone a chance to get the exclusive lock
240240 // and then upgrade to an exclusive lock.
241 cache_file.unlock();
241 cache_file.unlock(io);
242242 lock = .exclusive;
243 try cache_file.lock(lock);
243 try cache_file.lock(io, lock);
244244 };
245245
246246 if (need_update) {
247 // The cache is definitely stale so delete the contents to avoid an underwrite later.
248 cache_file.setLength(io, 0) catch |err| switch (err) {
249 error.FileTooBig => unreachable, // 0 is not too big
250 else => |e| return e,
251 };
252 try cache_file.seekTo(0);
247 var cache_file_writer: Io.File.Writer = .init(cache_file, io, &.{});
253248
254249 if (stat.size > std.math.maxInt(u32))
255250 return error.FileTooBig;
......@@ -278,7 +273,7 @@ pub fn updateFile(
278273 switch (file.getMode()) {
279274 .zig => {
280275 file.zir = try AstGen.generate(gpa, file.tree.?);
281 Zcu.saveZirCache(gpa, io, cache_file, stat, file.zir.?) catch |err| switch (err) {
276 Zcu.saveZirCache(gpa, &cache_file_writer, stat, file.zir.?) catch |err| switch (err) {
282277 error.OutOfMemory => |e| return e,
283278 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{
284279 file.path.fmt(comp), cache_directory, &hex_digest, err,
......@@ -287,13 +282,19 @@ pub fn updateFile(
287282 },
288283 .zon => {
289284 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});
290 Zcu.saveZoirCache(io, cache_file, stat, file.zoir.?) catch |err| {
285 Zcu.saveZoirCache(&cache_file_writer, stat, file.zoir.?) catch |err| {
291286 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{
292287 file.path.fmt(comp), cache_directory, &hex_digest, err,
293288 });
294289 };
295290 },
296291 }
292
293 cache_file_writer.end() catch |err| switch (err) {
294 error.WriteFailed => return cache_file_writer.err.?,
295 else => |e| return e,
296 };
297
297298 if (timer.finish()) |ns_astgen| {
298299 comp.mutex.lockUncancelable(io);
299300 defer comp.mutex.unlock(io);
......@@ -4524,12 +4525,14 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) Ru
45244525 .stage2_llvm,
45254526 => {},
45264527 },
4528 error.Canceled => |e| return e,
45274529 }
45284530 return error.AlreadyReported;
45294531 };
45304532}
45314533fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) error{
45324534 OutOfMemory,
4535 Canceled,
45334536 CodegenFail,
45344537 NoLinkFile,
45354538 BackendDoesNotProduceMir,
......@@ -4555,13 +4558,16 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
45554558 null;
45564559 defer if (liveness) |*l| l.deinit(gpa);
45574560
4558 if (build_options.enable_debug_extensions and comp.verbose_air) {
4561 if (build_options.enable_debug_extensions and comp.verbose_air) p: {
45594562 const io = comp.io;
45604563 const stderr = try io.lockStderrWriter(&.{});
45614564 defer io.unlockStderrWriter();
4562 stderr.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {};
4563 air.write(stderr, pt, liveness);
4564 stderr.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {};
4565 printVerboseAir(pt, liveness, fqn, air, &stderr.interface) catch |err| switch (err) {
4566 error.WriteFailed => switch (stderr.err.?) {
4567 error.Canceled => |e| return e,
4568 else => break :p,
4569 },
4570 };
45654571 }
45664572
45674573 if (std.debug.runtime_safety) verify_liveness: {
......@@ -4576,7 +4582,7 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
45764582
45774583 verify.verify() catch |err| switch (err) {
45784584 error.OutOfMemory => return error.OutOfMemory,
4579 else => return zcu.codegenFail(nav, "invalid liveness: {s}", .{@errorName(err)}),
4585 else => return zcu.codegenFail(nav, "invalid liveness: {t}", .{err}),
45804586 };
45814587 }
45824588
......@@ -4612,3 +4618,17 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
46124618 => return zcu.codegenFail(nav, "unable to codegen: {s}", .{@errorName(err)}),
46134619 };
46144620}
4621
4622fn printVerboseAir(
4623 pt: Zcu.PerThread,
4624 liveness: ?Air.Liveness,
4625 fqn: InternPool.NullTerminatedString,
4626 air: *const Air,
4627 w: *Io.Writer,
4628) Io.Writer.Error!void {
4629 const zcu = pt.zcu;
4630 const ip = &zcu.intern_pool;
4631 try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)});
4632 try air.write(w, pt, liveness);
4633 try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)});
4634}
src/fmt.zig+6-6
......@@ -124,7 +124,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
124124 try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>");
125125 var error_bundle = try wip_errors.toOwnedBundle("");
126126 defer error_bundle.deinit(gpa);
127 error_bundle.renderToStderr(io, .{}, color);
127 error_bundle.renderToStderr(io, .{}, color) catch {};
128128 process.exit(2);
129129 }
130130 } else {
......@@ -138,12 +138,12 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
138138 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>");
139139 var error_bundle = try wip_errors.toOwnedBundle("");
140140 defer error_bundle.deinit(gpa);
141 error_bundle.renderToStderr(io, .{}, color);
141 error_bundle.renderToStderr(io, .{}, color) catch {};
142142 process.exit(2);
143143 }
144144 }
145145 } else if (tree.errors.len != 0) {
146 try std.zig.printAstErrorsToStderr(gpa, tree, "<stdin>", color);
146 std.zig.printAstErrorsToStderr(gpa, io, tree, "<stdin>", color) catch {};
147147 process.exit(2);
148148 }
149149 const formatted = try tree.renderAlloc(gpa);
......@@ -298,7 +298,7 @@ fn fmtPathFile(
298298 defer tree.deinit(gpa);
299299
300300 if (tree.errors.len != 0) {
301 try std.zig.printAstErrorsToStderr(gpa, tree, file_path, fmt.color);
301 try std.zig.printAstErrorsToStderr(gpa, io, tree, file_path, fmt.color);
302302 fmt.any_error = true;
303303 return;
304304 }
......@@ -319,7 +319,7 @@ fn fmtPathFile(
319319 try wip_errors.addZirErrorMessages(zir, tree, source_code, file_path);
320320 var error_bundle = try wip_errors.toOwnedBundle("");
321321 defer error_bundle.deinit(gpa);
322 error_bundle.renderToStderr(io, .{}, fmt.color);
322 try error_bundle.renderToStderr(io, .{}, fmt.color);
323323 fmt.any_error = true;
324324 }
325325 },
......@@ -334,7 +334,7 @@ fn fmtPathFile(
334334 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, file_path);
335335 var error_bundle = try wip_errors.toOwnedBundle("");
336336 defer error_bundle.deinit(gpa);
337 error_bundle.renderToStderr(io, .{}, fmt.color);
337 try error_bundle.renderToStderr(io, .{}, fmt.color);
338338 fmt.any_error = true;
339339 }
340340 },
src/libs/freebsd.zig+2-2
......@@ -401,8 +401,8 @@ pub const BuiltSharedObjects = struct {
401401 lock: Cache.Lock,
402402 dir_path: Path,
403403
404 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {
405 self.lock.release();
404 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
405 self.lock.release(io);
406406 gpa.free(self.dir_path.sub_path);
407407 self.* = undefined;
408408 }
src/libs/glibc.zig+2-2
......@@ -640,8 +640,8 @@ pub const BuiltSharedObjects = struct {
640640 lock: Cache.Lock,
641641 dir_path: Path,
642642
643 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {
644 self.lock.release();
643 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
644 self.lock.release(io);
645645 gpa.free(self.dir_path.sub_path);
646646 self.* = undefined;
647647 }
src/libs/netbsd.zig+2-2
......@@ -346,8 +346,8 @@ pub const BuiltSharedObjects = struct {
346346 lock: Cache.Lock,
347347 dir_path: Path,
348348
349 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {
350 self.lock.release();
349 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
350 self.lock.release(io);
351351 gpa.free(self.dir_path.sub_path);
352352 self.* = undefined;
353353 }
src/link.zig+2-3
......@@ -2246,13 +2246,12 @@ fn resolvePathInputLib(
22462246 var error_bundle = try wip_errors.toOwnedBundle("");
22472247 defer error_bundle.deinit(gpa);
22482248
2249 error_bundle.renderToStderr(io, .{}, color);
2250
2249 error_bundle.renderToStderr(io, .{}, color) catch {};
22512250 std.process.exit(1);
22522251 }
22532252
22542253 var ld_script = ld_script_result catch |err|
2255 fatal("{f}: failed to parse linker script: {s}", .{ test_path, @errorName(err) });
2254 fatal("{f}: failed to parse linker script: {t}", .{ test_path, err });
22562255 defer ld_script.deinit(gpa);
22572256
22582257 try unresolved_inputs.ensureUnusedCapacity(gpa, ld_script.args.len);
src/main.zig+6-1
......@@ -4598,6 +4598,8 @@ const UpdateModuleError = Compilation.UpdateError || error{
45984598 /// The update caused compile errors. The error bundle has already been
45994599 /// reported to the user by being rendered to stderr.
46004600 CompileErrorsReported,
4601 /// Error occurred printing compilation errors to stderr.
4602 PrintingErrorsFailed,
46014603};
46024604fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node) UpdateModuleError!void {
46034605 try comp.update(prog_node);
......@@ -4607,7 +4609,10 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
46074609
46084610 if (errors.errorMessageCount() > 0) {
46094611 const io = comp.io;
4610 try errors.renderToStderr(io, .{}, color);
4612 errors.renderToStderr(io, .{}, color) catch |err| switch (err) {
4613 error.Canceled => |e| return e,
4614 else => return error.PrintingErrorsFailed,
4615 };
46114616 return error.CompileErrorsReported;
46124617 }
46134618}