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 {...@@ -24,7 +24,7 @@ pub const Message = struct {
24 @"fatal error",24 @"fatal error",
25 };25 };
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 {
28 try config.setColor(w, .bold);28 try config.setColor(w, .bold);
29 if (msg.location) |loc| {29 if (msg.location) |loc| {
30 try w.print("{s}:{d}:{d}: ", .{ loc.path, loc.line_no, loc.col });30 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...@@ -1065,11 +1065,13 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
10651065
1066fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) void {1066fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) void {
1067 @branchHint(.cold);1067 @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);
1069 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });1071 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
10701072
1071 var stderr_buf: [4096]u8 = undefined;1073 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);
1073 const w = &stderr.interface;1075 const w = &stderr.interface;
10741076
1075 w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;1077 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 {...@@ -106,6 +106,7 @@ pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
106106
107pub fn atomicFile(107pub fn atomicFile(
108 p: Path,108 p: Path,
109 io: Io,
109 sub_path: []const u8,110 sub_path: []const u8,
110 options: Io.Dir.AtomicFileOptions,111 options: Io.Dir.AtomicFileOptions,
111 buf: *[fs.max_path_bytes]u8,112 buf: *[fs.max_path_bytes]u8,
...@@ -115,7 +116,7 @@ pub fn atomicFile(...@@ -115,7 +116,7 @@ pub fn atomicFile(
115 p.sub_path, sub_path,116 p.sub_path, sub_path,
116 }) catch return error.NameTooLong;117 }) catch return error.NameTooLong;
117 };118 };
118 return p.root_dir.handle.atomicFile(joined_path, options);119 return p.root_dir.handle.atomicFile(io, joined_path, options);
119}120}
120121
121pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {122pub 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(...@@ -1645,7 +1645,7 @@ pub fn copyFile(
1645 .permissions = permissions,1645 .permissions = permissions,
1646 .write_buffer = &buffer,1646 .write_buffer = &buffer,
1647 });1647 });
1648 defer atomic_file.deinit(io);1648 defer atomic_file.deinit();
16491649
1650 _ = atomic_file.file_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {1650 _ = atomic_file.file_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {
1651 error.ReadFailed => return file_reader.err.?,1651 error.ReadFailed => return file_reader.err.?,
lib/std/crypto/Certificate/Bundle.zig+2-1
...@@ -202,7 +202,7 @@ pub const AddCertsFromDirError = AddCertsFromFilePathError;...@@ -202,7 +202,7 @@ pub const AddCertsFromDirError = AddCertsFromFilePathError;
202202
203pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, iterable_dir: Io.Dir) AddCertsFromDirError!void {203pub fn addCertsFromDir(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp, iterable_dir: Io.Dir) AddCertsFromDirError!void {
204 var it = iterable_dir.iterate();204 var it = iterable_dir.iterate();
205 while (try it.next()) |entry| {205 while (try it.next(io)) |entry| {
206 switch (entry.kind) {206 switch (entry.kind) {
207 .file, .sym_link => {},207 .file, .sym_link => {},
208 else => continue,208 else => continue,
...@@ -243,6 +243,7 @@ pub fn addCertsFromFilePath(...@@ -243,6 +243,7 @@ pub fn addCertsFromFilePath(
243243
244pub const AddCertsFromFileError = Allocator.Error ||244pub const AddCertsFromFileError = Allocator.Error ||
245 Io.File.Reader.Error ||245 Io.File.Reader.Error ||
246 Io.File.Reader.SizeError ||
246 ParseCertError ||247 ParseCertError ||
247 std.base64.Error ||248 std.base64.Error ||
248 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };249 error{ CertificateAuthorityBundleTooBig, MissingEndCertificateMarker, Streaming };
lib/std/fs/test.zig+1-1
...@@ -1598,7 +1598,7 @@ test "AtomicFile" {...@@ -1598,7 +1598,7 @@ test "AtomicFile" {
15981598
1599 {1599 {
1600 var buffer: [100]u8 = undefined;1600 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 });
1602 defer af.deinit();1602 defer af.deinit();
1603 try af.file_writer.interface.writeAll(test_content);1603 try af.file_writer.interface.writeAll(test_content);
1604 try af.finish();1604 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...@@ -648,7 +648,7 @@ pub fn printAstErrorsToStderr(gpa: Allocator, io: Io, tree: Ast, path: []const u
648648
649 var error_bundle = try wip_errors.toOwnedBundle("");649 var error_bundle = try wip_errors.toOwnedBundle("");
650 defer error_bundle.deinit(gpa);650 defer error_bundle.deinit(gpa);
651 error_bundle.renderToStderr(io, .{}, color);651 return error_bundle.renderToStderr(io, .{}, color);
652}652}
653653
654pub fn putAstErrorsIntoBundle(654pub fn putAstErrorsIntoBundle(
lib/std/zig/ErrorBundle.zig+2-2
...@@ -162,14 +162,14 @@ pub const RenderOptions = struct {...@@ -162,14 +162,14 @@ pub const RenderOptions = struct {
162 include_log_text: bool = true,162 include_log_text: bool = true,
163};163};
164164
165pub const RenderToStderrError = Io.Cancelable || Io.File.Writer.Mode.SetColorError;165pub const RenderToStderrError = Io.Cancelable || Io.File.Writer.Error;
166166
167pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: std.zig.Color) RenderToStderrError!void {167pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: std.zig.Color) RenderToStderrError!void {
168 var buffer: [256]u8 = undefined;168 var buffer: [256]u8 = undefined;
169 const stderr = try io.lockStderrWriter(&buffer);169 const stderr = try io.lockStderrWriter(&buffer);
170 defer io.unlockStderrWriter();170 defer io.unlockStderrWriter();
171 renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)) catch |err| switch (err) {171 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.?,
173 else => |e| return e,173 else => |e| return e,
174 };174 };
175}175}
lib/std/zig/LibCDirs.zig+11-8
...@@ -1,3 +1,11 @@...@@ -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
1libc_include_dir_list: []const []const u8,9libc_include_dir_list: []const []const u8,
2libc_installation: ?*const LibCInstallation,10libc_installation: ?*const LibCInstallation,
3libc_framework_dir_list: []const []const u8,11libc_framework_dir_list: []const []const u8,
...@@ -14,6 +22,7 @@ pub const DarwinSdkLayout = enum {...@@ -14,6 +22,7 @@ pub const DarwinSdkLayout = enum {
1422
15pub fn detect(23pub fn detect(
16 arena: Allocator,24 arena: Allocator,
25 io: Io,
17 zig_lib_dir: []const u8,26 zig_lib_dir: []const u8,
18 target: *const std.Target,27 target: *const std.Target,
19 is_native_abi: bool,28 is_native_abi: bool,
...@@ -38,7 +47,7 @@ pub fn detect(...@@ -38,7 +47,7 @@ pub fn detect(
38 // using the system libc installation.47 // using the system libc installation.
39 if (is_native_abi and !target.isMinGW()) {48 if (is_native_abi and !target.isMinGW()) {
40 const libc = try arena.create(LibCInstallation);49 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) {
42 error.CCompilerExitCode,51 error.CCompilerExitCode,
43 error.CCompilerCrashed,52 error.CCompilerCrashed,
44 error.CCompilerCannotFindHeaders,53 error.CCompilerCannotFindHeaders,
...@@ -75,7 +84,7 @@ pub fn detect(...@@ -75,7 +84,7 @@ pub fn detect(
7584
76 if (use_system_abi) {85 if (use_system_abi) {
77 const libc = try arena.create(LibCInstallation);86 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 });
79 return detectFromInstallation(arena, target, libc);88 return detectFromInstallation(arena, target, libc);
80 }89 }
8190
...@@ -265,9 +274,3 @@ fn libCGenericName(target: *const std.Target) [:0]const u8 {...@@ -265,9 +274,3 @@ fn libCGenericName(target: *const std.Target) [:0]const u8 {
265 => unreachable,274 => unreachable,
266 }275 }
267}276}
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...@@ -204,7 +204,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
204 try self.findNativeIncludeDirWindows(gpa, io, args, sdk);204 try self.findNativeIncludeDirWindows(gpa, io, args, sdk);
205 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);205 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);
206 } else if (is_haiku) {206 } else if (is_haiku) {
207 try self.findNativeIncludeDirPosix(args);207 try self.findNativeIncludeDirPosix(gpa, io, args);
208 try self.findNativeGccDirHaiku(gpa, io, args);208 try self.findNativeGccDirHaiku(gpa, io, args);
209 self.crt_dir = try gpa.dupeZ(u8, "/system/develop/lib");209 self.crt_dir = try gpa.dupeZ(u8, "/system/develop/lib");
210 } else if (builtin.target.os.tag == .illumos) {210 } else if (builtin.target.os.tag == .illumos) {
...@@ -213,7 +213,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib...@@ -213,7 +213,7 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
213 self.sys_include_dir = try gpa.dupeZ(u8, "/usr/include");213 self.sys_include_dir = try gpa.dupeZ(u8, "/usr/include");
214 self.crt_dir = try gpa.dupeZ(u8, "/usr/lib/64");214 self.crt_dir = try gpa.dupeZ(u8, "/usr/lib/64");
215 } else if (std.process.can_spawn) {215 } else if (std.process.can_spawn) {
216 try self.findNativeIncludeDirPosix(args);216 try self.findNativeIncludeDirPosix(gpa, io, args);
217 switch (builtin.target.os.tag) {217 switch (builtin.target.os.tag) {
218 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupeZ(u8, "/usr/lib"),218 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupeZ(u8, "/usr/lib"),
219 .linux => try self.findNativeCrtDirPosix(gpa, io, args),219 .linux => try self.findNativeCrtDirPosix(gpa, io, args),
...@@ -335,7 +335,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar...@@ -335,7 +335,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
335 defer search_dir.close(io);335 defer search_dir.close(io);
336336
337 if (self.include_dir == null) {337 if (self.include_dir == null) {
338 if (search_dir.access(include_dir_example_file, .{})) |_| {338 if (search_dir.access(io, include_dir_example_file, .{})) |_| {
339 self.include_dir = try gpa.dupeZ(u8, search_path);339 self.include_dir = try gpa.dupeZ(u8, search_path);
340 } else |err| switch (err) {340 } else |err| switch (err) {
341 error.FileNotFound => {},341 error.FileNotFound => {},
src/Builtin.zig+1-1
...@@ -343,7 +343,7 @@ pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {...@@ -343,7 +343,7 @@ pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {
343 }343 }
344344
345 // `make_path` matters because the dir hasn't actually been created yet.345 // `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 = &.{} });
347 defer af.deinit();347 defer af.deinit();
348 try af.file_writer.interface.writeAll(file.source.?);348 try af.file_writer.interface.writeAll(file.source.?);
349 af.finish() catch |err| switch (err) {349 af.finish() catch |err| switch (err) {
src/Compilation.zig+68-70
...@@ -771,8 +771,8 @@ pub const Directories = struct {...@@ -771,8 +771,8 @@ pub const Directories = struct {
771 const zig_lib: Cache.Directory = d: {771 const zig_lib: Cache.Directory = d: {
772 if (override_zig_lib) |path| break :d openUnresolved(arena, io, cwd, path, .@"zig lib");772 if (override_zig_lib) |path| break :d openUnresolved(arena, io, cwd, path, .@"zig lib");
773 if (wasi) break :d openWasiPreopen(wasi_preopens, "/lib");773 if (wasi) break :d openWasiPreopen(wasi_preopens, "/lib");
774 break :d introspect.findZigLibDirFromSelfExe(arena, cwd, self_exe_path) catch |err| {774 break :d introspect.findZigLibDirFromSelfExe(arena, io, cwd, self_exe_path) catch |err| {
775 fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });775 fatal("unable to find zig installation directory '{s}': {t}", .{ self_exe_path, err });
776 };776 };
777 };777 };
778778
...@@ -780,7 +780,7 @@ pub const Directories = struct {...@@ -780,7 +780,7 @@ pub const Directories = struct {
780 if (override_global_cache) |path| break :d openUnresolved(arena, io, cwd, path, .@"global cache");780 if (override_global_cache) |path| break :d openUnresolved(arena, io, cwd, path, .@"global cache");
781 if (wasi) break :d openWasiPreopen(wasi_preopens, "/cache");781 if (wasi) break :d openWasiPreopen(wasi_preopens, "/cache");
782 const path = introspect.resolveGlobalCacheDir(arena) catch |err| {782 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});
784 };784 };
785 break :d openUnresolved(arena, io, cwd, path, .@"global cache");785 break :d openUnresolved(arena, io, cwd, path, .@"global cache");
786 };786 };
...@@ -789,7 +789,7 @@ pub const Directories = struct {...@@ -789,7 +789,7 @@ pub const Directories = struct {
789 .override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"),789 .override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"),
790 .search => d: {790 .search => d: {
791 const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, io, cwd) catch |err| {791 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});
793 };793 };
794 const path = maybe_path orelse break :d global_cache;794 const path = maybe_path orelse break :d global_cache;
795 break :d openUnresolved(arena, io, cwd, path, .@"local cache");795 break :d openUnresolved(arena, io, cwd, path, .@"local cache");
...@@ -919,8 +919,8 @@ pub const CrtFile = struct {...@@ -919,8 +919,8 @@ pub const CrtFile = struct {
919 lock: Cache.Lock,919 lock: Cache.Lock,
920 full_object_path: Cache.Path,920 full_object_path: Cache.Path,
921921
922 pub fn deinit(self: *CrtFile, gpa: Allocator) void {922 pub fn deinit(self: *CrtFile, gpa: Allocator, io: Io) void {
923 self.lock.release();923 self.lock.release(io);
924 gpa.free(self.full_object_path.sub_path);924 gpa.free(self.full_object_path.sub_path);
925 self.* = undefined;925 self.* = undefined;
926 }926 }
...@@ -1317,7 +1317,7 @@ pub const CObject = struct {...@@ -1317,7 +1317,7 @@ pub const CObject = struct {
1317 };1317 };
13181318
1319 /// Returns if there was failure.1319 /// 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 {
1321 switch (self.status) {1321 switch (self.status) {
1322 .new => return false,1322 .new => return false,
1323 .failure, .failure_retryable => {1323 .failure, .failure_retryable => {
...@@ -1326,15 +1326,15 @@ pub const CObject = struct {...@@ -1326,15 +1326,15 @@ pub const CObject = struct {
1326 },1326 },
1327 .success => |*success| {1327 .success => |*success| {
1328 gpa.free(success.object_path.sub_path);1328 gpa.free(success.object_path.sub_path);
1329 success.lock.release();1329 success.lock.release(io);
1330 self.status = .new;1330 self.status = .new;
1331 return false;1331 return false;
1332 },1332 },
1333 }1333 }
1334 }1334 }
13351335
1336 pub fn destroy(self: *CObject, gpa: Allocator) void {1336 pub fn destroy(self: *CObject, gpa: Allocator, io: Io) void {
1337 _ = self.clearStatus(gpa);1337 _ = self.clearStatus(gpa, io);
1338 gpa.destroy(self);1338 gpa.destroy(self);
1339 }1339 }
1340};1340};
...@@ -1364,7 +1364,7 @@ pub const Win32Resource = struct {...@@ -1364,7 +1364,7 @@ pub const Win32Resource = struct {
1364 },1364 },
13651365
1366 /// Returns true if there was failure.1366 /// 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 {
1368 switch (self.status) {1368 switch (self.status) {
1369 .new => return false,1369 .new => return false,
1370 .failure, .failure_retryable => {1370 .failure, .failure_retryable => {
...@@ -1373,15 +1373,15 @@ pub const Win32Resource = struct {...@@ -1373,15 +1373,15 @@ pub const Win32Resource = struct {
1373 },1373 },
1374 .success => |*success| {1374 .success => |*success| {
1375 gpa.free(success.res_path);1375 gpa.free(success.res_path);
1376 success.lock.release();1376 success.lock.release(io);
1377 self.status = .new;1377 self.status = .new;
1378 return false;1378 return false;
1379 },1379 },
1380 }1380 }
1381 }1381 }
13821382
1383 pub fn destroy(self: *Win32Resource, gpa: Allocator) void {1383 pub fn destroy(self: *Win32Resource, gpa: Allocator, io: Io) void {
1384 _ = self.clearStatus(gpa);1384 _ = self.clearStatus(gpa, io);
1385 gpa.destroy(self);1385 gpa.destroy(self);
1386 }1386 }
1387};1387};
...@@ -1610,9 +1610,9 @@ const CacheUse = union(CacheMode) {...@@ -1610,9 +1610,9 @@ const CacheUse = union(CacheMode) {
1610 /// Prevents other processes from clobbering files in the output directory.1610 /// Prevents other processes from clobbering files in the output directory.
1611 lock: ?Cache.Lock,1611 lock: ?Cache.Lock,
16121612
1613 fn releaseLock(whole: *Whole) void {1613 fn releaseLock(whole: *Whole, io: Io) void {
1614 if (whole.lock) |*lock| {1614 if (whole.lock) |*lock| {
1615 lock.release();1615 lock.release(io);
1616 whole.lock = null;1616 whole.lock = null;
1617 }1617 }
1618 }1618 }
...@@ -1634,7 +1634,7 @@ const CacheUse = union(CacheMode) {...@@ -1634,7 +1634,7 @@ const CacheUse = union(CacheMode) {
1634 },1634 },
1635 .whole => |whole| {1635 .whole => |whole| {
1636 assert(whole.tmp_artifact_directory == null);1636 assert(whole.tmp_artifact_directory == null);
1637 whole.releaseLock();1637 whole.releaseLock(io);
1638 },1638 },
1639 }1639 }
1640 }1640 }
...@@ -1903,13 +1903,17 @@ pub const CreateDiagnostic = union(enum) {...@@ -1903,13 +1903,17 @@ pub const CreateDiagnostic = union(enum) {
1903 return error.CreateFail;1903 return error.CreateFail;
1904 }1904 }
1905};1905};
1906pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, options: CreateOptions) error{1906
1907pub const CreateError = error{
1907 OutOfMemory,1908 OutOfMemory,
1909 Canceled,
1908 Unexpected,1910 Unexpected,
1909 CurrentWorkingDirectoryUnlinked,1911 CurrentWorkingDirectoryUnlinked,
1910 /// An error has been stored to `diag`.1912 /// An error has been stored to `diag`.
1911 CreateFail,1913 CreateFail,
1912}!*Compilation {1914};
1915
1916pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, options: CreateOptions) CreateError!*Compilation {
1913 const output_mode = options.config.output_mode;1917 const output_mode = options.config.output_mode;
1914 const is_dyn_lib = switch (output_mode) {1918 const is_dyn_lib = switch (output_mode) {
1915 .Obj, .Exe => false,1919 .Obj, .Exe => false,
...@@ -1957,6 +1961,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -1957,6 +1961,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
19571961
1958 const libc_dirs = std.zig.LibCDirs.detect(1962 const libc_dirs = std.zig.LibCDirs.detect(
1959 arena,1963 arena,
1964 io,
1960 options.dirs.zig_lib.path.?,1965 options.dirs.zig_lib.path.?,
1961 target,1966 target,
1962 options.root_mod.resolved_target.is_native_abi,1967 options.root_mod.resolved_target.is_native_abi,
...@@ -2701,7 +2706,7 @@ pub fn destroy(comp: *Compilation) void {...@@ -2701,7 +2706,7 @@ pub fn destroy(comp: *Compilation) void {
27012706
2702 if (comp.bin_file) |lf| lf.destroy();2707 if (comp.bin_file) |lf| lf.destroy();
2703 if (comp.zcu) |zcu| zcu.deinit();2708 if (comp.zcu) |zcu| zcu.deinit();
2704 comp.cache_use.deinit();2709 comp.cache_use.deinit(io);
27052710
2706 for (&comp.work_queues) |*work_queue| work_queue.deinit(gpa);2711 for (&comp.work_queues) |*work_queue| work_queue.deinit(gpa);
2707 comp.c_object_work_queue.deinit(gpa);2712 comp.c_object_work_queue.deinit(gpa);
...@@ -2714,36 +2719,36 @@ pub fn destroy(comp: *Compilation) void {...@@ -2714,36 +2719,36 @@ pub fn destroy(comp: *Compilation) void {
2714 var it = comp.crt_files.iterator();2719 var it = comp.crt_files.iterator();
2715 while (it.next()) |entry| {2720 while (it.next()) |entry| {
2716 gpa.free(entry.key_ptr.*);2721 gpa.free(entry.key_ptr.*);
2717 entry.value_ptr.deinit(gpa);2722 entry.value_ptr.deinit(gpa, io);
2718 }2723 }
2719 comp.crt_files.deinit(gpa);2724 comp.crt_files.deinit(gpa);
2720 }2725 }
2721 if (comp.libcxx_static_lib) |*crt_file| crt_file.deinit(gpa);2726 if (comp.libcxx_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2722 if (comp.libcxxabi_static_lib) |*crt_file| crt_file.deinit(gpa);2727 if (comp.libcxxabi_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2723 if (comp.libunwind_static_lib) |*crt_file| crt_file.deinit(gpa);2728 if (comp.libunwind_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2724 if (comp.tsan_lib) |*crt_file| crt_file.deinit(gpa);2729 if (comp.tsan_lib) |*crt_file| crt_file.deinit(gpa, io);
2725 if (comp.ubsan_rt_lib) |*crt_file| crt_file.deinit(gpa);2730 if (comp.ubsan_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
2726 if (comp.ubsan_rt_obj) |*crt_file| crt_file.deinit(gpa);2731 if (comp.ubsan_rt_obj) |*crt_file| crt_file.deinit(gpa, io);
2727 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa);2732 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2728 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa);2733 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
2729 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa);2734 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa, io);
2730 if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa);2735 if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa, io);
2731 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa);2736 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io);
27322737
2733 if (comp.glibc_so_files) |*glibc_file| {2738 if (comp.glibc_so_files) |*glibc_file| {
2734 glibc_file.deinit(gpa);2739 glibc_file.deinit(gpa, io);
2735 }2740 }
27362741
2737 if (comp.freebsd_so_files) |*freebsd_file| {2742 if (comp.freebsd_so_files) |*freebsd_file| {
2738 freebsd_file.deinit(gpa);2743 freebsd_file.deinit(gpa, io);
2739 }2744 }
27402745
2741 if (comp.netbsd_so_files) |*netbsd_file| {2746 if (comp.netbsd_so_files) |*netbsd_file| {
2742 netbsd_file.deinit(gpa);2747 netbsd_file.deinit(gpa, io);
2743 }2748 }
27442749
2745 for (comp.c_object_table.keys()) |key| {2750 for (comp.c_object_table.keys()) |key| {
2746 key.destroy(gpa);2751 key.destroy(gpa, io);
2747 }2752 }
2748 comp.c_object_table.deinit(gpa);2753 comp.c_object_table.deinit(gpa);
27492754
...@@ -2753,7 +2758,7 @@ pub fn destroy(comp: *Compilation) void {...@@ -2753,7 +2758,7 @@ pub fn destroy(comp: *Compilation) void {
2753 comp.failed_c_objects.deinit(gpa);2758 comp.failed_c_objects.deinit(gpa);
27542759
2755 for (comp.win32_resource_table.keys()) |key| {2760 for (comp.win32_resource_table.keys()) |key| {
2756 key.destroy(gpa);2761 key.destroy(gpa, io);
2757 }2762 }
2758 comp.win32_resource_table.deinit(gpa);2763 comp.win32_resource_table.deinit(gpa);
27592764
...@@ -2906,7 +2911,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -2906,7 +2911,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
2906 .whole => |whole| {2911 .whole => |whole| {
2907 assert(comp.bin_file == null);2912 assert(comp.bin_file == null);
2908 // We are about to obtain this lock, so here we give other processes a chance first.2913 // We are about to obtain this lock, so here we give other processes a chance first.
2909 whole.releaseLock();2914 whole.releaseLock(io);
29102915
2911 man = comp.cache_parent.obtain();2916 man = comp.cache_parent.obtain();
2912 whole.cache_manifest = &man;2917 whole.cache_manifest = &man;
...@@ -3092,17 +3097,12 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE...@@ -3092,17 +3097,12 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
3092 }3097 }
30933098
3094 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {3099 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
3095 std.debug.print("intern pool stats for '{s}':\n", .{3100 std.debug.print("intern pool stats for '{s}':\n", .{comp.root_name});
3096 comp.root_name,3101 zcu.intern_pool.dump(io);
3097 });
3098 zcu.intern_pool.dump();
3099 }3102 }
31003103
3101 if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {3104 if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {
3102 std.debug.print("generic instances for '{s}:0x{x}':\n", .{3105 std.debug.print("generic instances for '{s}:0x{x}':\n", .{ comp.root_name, @intFromPtr(zcu) });
3103 comp.root_name,
3104 @intFromPtr(zcu),
3105 });
3106 zcu.intern_pool.dumpGenericInstances(gpa);3106 zcu.intern_pool.dumpGenericInstances(gpa);
3107 }3107 }
3108 }3108 }
...@@ -3680,6 +3680,7 @@ pub fn saveState(comp: *Compilation) !void {...@@ -3680,6 +3680,7 @@ pub fn saveState(comp: *Compilation) !void {
3680 const lf = comp.bin_file orelse return;3680 const lf = comp.bin_file orelse return;
36813681
3682 const gpa = comp.gpa;3682 const gpa = comp.gpa;
3683 const io = comp.io;
36833684
3684 var bufs = std.array_list.Managed([]const u8).init(gpa);3685 var bufs = std.array_list.Managed([]const u8).init(gpa);
3685 defer bufs.deinit();3686 defer bufs.deinit();
...@@ -3900,7 +3901,7 @@ pub fn saveState(comp: *Compilation) !void {...@@ -3900,7 +3901,7 @@ pub fn saveState(comp: *Compilation) !void {
3900 // Using an atomic file prevents a crash or power failure from corrupting3901 // Using an atomic file prevents a crash or power failure from corrupting
3901 // the previous incremental compilation state.3902 // the previous incremental compilation state.
3902 var write_buffer: [1024]u8 = undefined;3903 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 });
3904 defer af.deinit();3905 defer af.deinit();
3905 try af.file_writer.interface.writeVecAll(bufs.items);3906 try af.file_writer.interface.writeVecAll(bufs.items);
3906 try af.finish();3907 try af.finish();
...@@ -4258,8 +4259,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle {...@@ -4258,8 +4259,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle {
4258 // However, we haven't reported any such error.4259 // However, we haven't reported any such error.
4259 // This is a compiler bug.4260 // This is a compiler bug.
4260 print_ctx: {4261 print_ctx: {
4261 const stderr = try io.lockStderrWriter(&.{});4262 const stderr = std.debug.lockStderrWriter(&.{});
4262 defer io.unlockStderrWriter();4263 defer std.debug.unlockStderrWriter();
4263 const w = &stderr.interface;4264 const w = &stderr.interface;
4264 w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx;4265 w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx;
4265 w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx;4266 w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx;
...@@ -5219,13 +5220,10 @@ fn processOneJob(...@@ -5219,13 +5220,10 @@ fn processOneJob(
5219 }5220 }
5220}5221}
52215222
5222fn createDepFile(5223fn createDepFile(comp: *Compilation, depfile: []const u8, binfile: Cache.Path) anyerror!void {
5223 comp: *Compilation,5224 const io = comp.io;
5224 depfile: []const u8,
5225 binfile: Cache.Path,
5226) anyerror!void {
5227 var buf: [4096]u8 = undefined;5225 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 });
5229 defer af.deinit();5227 defer af.deinit();
52305228
5231 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;5229 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;
...@@ -5280,13 +5278,8 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {...@@ -5280,13 +5278,8 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
52805278
5281 for (&[_][]const u8{ "docs/main.js", "docs/index.html" }) |sub_path| {5279 for (&[_][]const u8{ "docs/main.js", "docs/index.html" }) |sub_path| {
5282 const basename = fs.path.basename(sub_path);5280 const basename = fs.path.basename(sub_path);
5283 comp.dirs.zig_lib.handle.copyFile(sub_path, out_dir, basename, .{}) catch |err| {5281 comp.dirs.zig_lib.handle.copyFile(sub_path, out_dir, basename, io, .{}) catch |err|
5284 comp.lockAndSetMiscFailure(.docs_copy, "unable to copy {s}: {s}", .{5282 return comp.lockAndSetMiscFailure(.docs_copy, "unable to copy {s}: {t}", .{ sub_path, err });
5285 sub_path,
5286 @errorName(err),
5287 });
5288 return;
5289 };
5290 }5283 }
52915284
5292 var tar_file = out_dir.createFile(io, "sources.tar", .{}) catch |err| {5285 var tar_file = out_dir.createFile(io, "sources.tar", .{}) catch |err| {
...@@ -5350,7 +5343,7 @@ fn docsCopyModule(...@@ -5350,7 +5343,7 @@ fn docsCopyModule(
53505343
5351 var buffer: [1024]u8 = undefined;5344 var buffer: [1024]u8 = undefined;
53525345
5353 while (try walker.next()) |entry| {5346 while (try walker.next(io)) |entry| {
5354 switch (entry.kind) {5347 switch (entry.kind) {
5355 .file => {5348 .file => {
5356 if (!std.mem.endsWith(u8, entry.basename, ".zig")) continue;5349 if (!std.mem.endsWith(u8, entry.basename, ".zig")) continue;
...@@ -5505,7 +5498,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU...@@ -5505,7 +5498,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
5505 try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node);5498 try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node);
55065499
5507 var crt_file = try sub_compilation.toCrtFile();5500 var crt_file = try sub_compilation.toCrtFile();
5508 defer crt_file.deinit(gpa);5501 defer crt_file.deinit(gpa, io);
55095502
5510 const docs_bin_file = crt_file.full_object_path;5503 const docs_bin_file = crt_file.full_object_path;
5511 assert(docs_bin_file.sub_path.len > 0); // emitted binary is not a directory5504 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...@@ -5521,10 +5514,12 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
5521 };5514 };
5522 defer out_dir.close(io);5515 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,
5525 crt_file.full_object_path.sub_path,5519 crt_file.full_object_path.sub_path,
5526 out_dir,5520 out_dir,
5527 "main.wasm",5521 "main.wasm",
5522 io,
5528 .{},5523 .{},
5529 ) catch |err| {5524 ) catch |err| {
5530 comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{f}' to '{f}': {t}", .{5525 comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{f}' to '{f}': {t}", .{
...@@ -5758,7 +5753,7 @@ pub fn translateC(...@@ -5758,7 +5753,7 @@ pub fn translateC(
5758 try argv.appendSlice(comp.global_cc_argv);5753 try argv.appendSlice(comp.global_cc_argv);
5759 try argv.appendSlice(owner_mod.cc_argv);5754 try argv.appendSlice(owner_mod.cc_argv);
5760 try argv.appendSlice(&.{ source_path, "-o", translated_path });5755 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);
5762 }5757 }
57635758
5764 var stdout: []u8 = undefined;5759 var stdout: []u8 = undefined;
...@@ -6153,7 +6148,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr...@@ -6153,7 +6148,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
6153 const gpa = comp.gpa;6148 const gpa = comp.gpa;
6154 const io = comp.io;6149 const io = comp.io;
61556150
6156 if (c_object.clearStatus(gpa)) {6151 if (c_object.clearStatus(gpa, io)) {
6157 // There was previous failure.6152 // There was previous failure.
6158 comp.mutex.lockUncancelable(io);6153 comp.mutex.lockUncancelable(io);
6159 defer comp.mutex.unlock(io);6154 defer comp.mutex.unlock(io);
...@@ -6500,7 +6495,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32...@@ -6500,7 +6495,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
6500 defer arena_allocator.deinit();6495 defer arena_allocator.deinit();
6501 const arena = arena_allocator.allocator();6496 const arena = arena_allocator.allocator();
65026497
6503 if (win32_resource.clearStatus(comp.gpa)) {6498 if (win32_resource.clearStatus(comp.gpa, io)) {
6504 // There was previous failure.6499 // There was previous failure.
6505 comp.mutex.lockUncancelable(io);6500 comp.mutex.lockUncancelable(io);
6506 defer comp.mutex.unlock(io);6501 defer comp.mutex.unlock(io);
...@@ -6768,7 +6763,7 @@ fn spawnZigRc(...@@ -6768,7 +6763,7 @@ fn spawnZigRc(
6768 // Just in case there's a failure that didn't send an ErrorBundle (e.g. an error return trace)6763 // Just in case there's a failure that didn't send an ErrorBundle (e.g. an error return trace)
6769 const stderr = poller.reader(.stderr);6764 const stderr = poller.reader(.stderr);
67706765
6771 const term = child.wait() catch |err| {6766 const term = child.wait(io) catch |err| {
6772 return comp.failWin32Resource(win32_resource, "unable to wait for {s} rc: {s}", .{ argv[0], @errorName(err) });6767 return comp.failWin32Resource(win32_resource, "unable to wait for {s} rc: {s}", .{ argv[0], @errorName(err) });
6773 };6768 };
67746769
...@@ -7781,7 +7776,10 @@ pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void {...@@ -7781,7 +7776,10 @@ pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void {
7781 defer io.unlockStderrWriter();7776 defer io.unlockStderrWriter();
7782 const w = &stderr.interface;7777 const w = &stderr.interface;
7783 return dumpArgvWriter(w, argv) catch |err| switch (err) {7778 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 },
7785 };7783 };
7786}7784}
77877785
src/Package/Fetch.zig+16-21
...@@ -501,7 +501,7 @@ fn runResource(...@@ -501,7 +501,7 @@ fn runResource(
501 .path = tmp_directory_path,501 .path = tmp_directory_path,
502 .handle = handle: {502 .handle = handle: {
503 const dir = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{503 const dir = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
504 .iterate = true,504 .open_options = .{ .iterate = true },
505 }) catch |err| {505 }) catch |err| {
506 try eb.addRootErrorMessage(.{506 try eb.addRootErrorMessage(.{
507 .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{507 .msg = try eb.printString("unable to create temporary directory '{s}': {t}", .{
...@@ -525,7 +525,7 @@ fn runResource(...@@ -525,7 +525,7 @@ fn runResource(
525 // https://github.com/ziglang/zig/issues/17095525 // https://github.com/ziglang/zig/issues/17095
526 pkg_path.root_dir.handle.close(io);526 pkg_path.root_dir.handle.close(io);
527 pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{527 pkg_path.root_dir.handle = cache_root.handle.makeOpenPath(io, tmp_dir_sub_path, .{
528 .iterate = true,528 .open_options = .{ .iterate = true },
529 }) catch @panic("btrfs workaround failed");529 }) catch @panic("btrfs workaround failed");
530 }530 }
531531
...@@ -1334,7 +1334,7 @@ fn unzip(...@@ -1334,7 +1334,7 @@ fn unzip(
1334 f.location_tok,1334 f.location_tok,
1335 try eb.printString("failed writing temporary zip file: {t}", .{err}),1335 try eb.printString("failed writing temporary zip file: {t}", .{err}),
1336 );1336 );
1337 break :b zip_file_writer.moveToReader(io);1337 break :b zip_file_writer.moveToReader();
1338 };1338 };
13391339
1340 var diagnostics: std.zip.Diagnostics = .{ .allocator = f.arena.allocator() };1340 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...@@ -1376,7 +1376,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1376 const fetch_reader = &resource.fetch_stream.reader;1376 const fetch_reader = &resource.fetch_stream.reader;
1377 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);1377 _ = try fetch_reader.streamRemaining(&pack_file_writer.interface);
1378 try pack_file_writer.interface.flush();1378 try pack_file_writer.interface.flush();
1379 break :b pack_file_writer.moveToReader(io);1379 break :b pack_file_writer.moveToReader();
1380 };1380 };
13811381
1382 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });1382 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...@@ -1421,26 +1421,21 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
1421 // Recursive directory copy.1421 // Recursive directory copy.
1422 var it = try dir.walk(gpa);1422 var it = try dir.walk(gpa);
1423 defer it.deinit();1423 defer it.deinit();
1424 while (try it.next()) |entry| {1424 while (try it.next(io)) |entry| {
1425 switch (entry.kind) {1425 switch (entry.kind) {
1426 .directory => {}, // omit empty directories1426 .directory => {}, // omit empty directories
1427 .file => {1427 .file => {
1428 dir.copyFile(1428 dir.copyFile(entry.path, tmp_dir, entry.path, io, .{}) catch |err| switch (err) {
1429 entry.path,
1430 tmp_dir,
1431 entry.path,
1432 .{},
1433 ) catch |err| switch (err) {
1434 error.FileNotFound => {1429 error.FileNotFound => {
1435 if (fs.path.dirname(entry.path)) |dirname| try tmp_dir.makePath(io, dirname);1430 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, .{});
1437 },1432 },
1438 else => |e| return e,1433 else => |e| return e,
1439 };1434 };
1440 },1435 },
1441 .sym_link => {1436 .sym_link => {
1442 var buf: [fs.max_path_bytes]u8 = undefined;1437 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)];
1444 // TODO: if this would create a symlink to outside1439 // TODO: if this would create a symlink to outside
1445 // the destination directory, fail with an error instead.1440 // the destination directory, fail with an error instead.
1446 tmp_dir.symLink(io, link_name, entry.path, .{}) catch |err| switch (err) {1441 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...@@ -1524,7 +1519,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
1524 var group: Io.Group = .init;1519 var group: Io.Group = .init;
1525 defer group.wait(io);1520 defer group.wait(io);
15261521
1527 while (walker.next() catch |err| {1522 while (walker.next(io) catch |err| {
1528 try eb.addRootErrorMessage(.{ .msg = try eb.printString(1523 try eb.addRootErrorMessage(.{ .msg = try eb.printString(
1529 "unable to walk temporary directory '{f}': {s}",1524 "unable to walk temporary directory '{f}': {s}",
1530 .{ pkg_path, @errorName(err) },1525 .{ pkg_path, @errorName(err) },
...@@ -1575,7 +1570,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1575,7 +1570,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
1575 .failure = undefined, // to be populated by the worker1570 .failure = undefined, // to be populated by the worker
1576 .size = undefined, // to be populated by the worker1571 .size = undefined, // to be populated by the worker
1577 };1572 };
1578 group.async(io, workerHashFile, .{ root_dir, hashed_file });1573 group.async(io, workerHashFile, .{ io, root_dir, hashed_file });
1579 try all_files.append(hashed_file);1574 try all_files.append(hashed_file);
1580 }1575 }
1581 }1576 }
...@@ -1643,7 +1638,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1643,7 +1638,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
1643 assert(!f.job_queue.recursive);1638 assert(!f.job_queue.recursive);
1644 // Print something to stdout that can be text diffed to figure out why1639 // Print something to stdout that can be text diffed to figure out why
1645 // the package hash is different.1640 // the package hash is different.
1646 dumpHashInfo(all_files.items) catch |err| {1641 dumpHashInfo(io, all_files.items) catch |err| {
1647 std.debug.print("unable to write to stdout: {s}\n", .{@errorName(err)});1642 std.debug.print("unable to write to stdout: {s}\n", .{@errorName(err)});
1648 std.process.exit(1);1643 std.process.exit(1);
1649 };1644 };
...@@ -1655,9 +1650,9 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute...@@ -1655,9 +1650,9 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
1655 };1650 };
1656}1651}
16571652
1658fn dumpHashInfo(all_files: []const *const HashedFile) !void {1653fn dumpHashInfo(io: Io, all_files: []const *const HashedFile) !void {
1659 var stdout_buffer: [1024]u8 = undefined;1654 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);
1661 const w = &stdout_writer.interface;1656 const w = &stdout_writer.interface;
1662 for (all_files) |hashed_file| {1657 for (all_files) |hashed_file| {
1663 try w.print("{t}: {x}: {s}\n", .{ hashed_file.kind, &hashed_file.hash, hashed_file.normalized_path });1658 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 {...@@ -1665,8 +1660,8 @@ fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1665 try w.flush();1660 try w.flush();
1666}1661}
16671662
1668fn workerHashFile(dir: Io.Dir, hashed_file: *HashedFile) void {1663fn workerHashFile(io: Io, dir: Io.Dir, hashed_file: *HashedFile) void {
1669 hashed_file.failure = hashFileFallible(dir, hashed_file);1664 hashed_file.failure = hashFileFallible(io, dir, hashed_file);
1670}1665}
16711666
1672fn workerDeleteFile(io: Io, dir: Io.Dir, deleted_file: *DeletedFile) void {1667fn workerDeleteFile(io: Io, dir: Io.Dir, deleted_file: *DeletedFile) void {
...@@ -1745,7 +1740,7 @@ const HashedFile = struct {...@@ -1745,7 +1740,7 @@ const HashedFile = struct {
1745 Io.File.OpenError ||1740 Io.File.OpenError ||
1746 Io.File.Reader.Error ||1741 Io.File.Reader.Error ||
1747 Io.File.StatError ||1742 Io.File.StatError ||
1748 Io.File.ChmodError ||1743 Io.File.SetPermissionsError ||
1749 Io.Dir.ReadLinkError;1744 Io.Dir.ReadLinkError;
17501745
1751 const Kind = enum { file, link };1746 const Kind = enum { file, link };
src/Package/Fetch/git.zig+1-1
...@@ -274,7 +274,7 @@ pub const Repository = struct {...@@ -274,7 +274,7 @@ pub const Repository = struct {
274 continue;274 continue;
275 };275 };
276 defer file.close(io);276 defer file.close(io);
277 try file.writeAll(file_object.data);277 try file.writePositionalAll(io, file_object.data, 0);
278 },278 },
279 .symlink => {279 .symlink => {
280 try repository.odb.seekOid(entry.oid);280 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...@@ -2679,7 +2679,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg
2679 Compilation.addModuleErrorMsg(zcu, &wip_errors, err_msg.*, false) catch @panic("out of memory");2679 Compilation.addModuleErrorMsg(zcu, &wip_errors, err_msg.*, false) catch @panic("out of memory");
2680 std.debug.print("compile error during Sema:\n", .{});2680 std.debug.print("compile error during Sema:\n", .{});
2681 var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory");2681 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");
2683 std.debug.panicExtra(@returnAddress(), "unexpected compile error occurred", .{});2683 std.debug.panicExtra(@returnAddress(), "unexpected compile error occurred", .{});
2684 }2684 }
26852685
src/Zcu.zig+7-10
...@@ -2988,11 +2988,10 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader...@@ -2988,11 +2988,10 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *Io.Reader
29882988
2989pub fn saveZirCache(2989pub fn saveZirCache(
2990 gpa: Allocator,2990 gpa: Allocator,
2991 io: Io,2991 cache_file_writer: *Io.File.Writer,
2992 cache_file: Io.File,
2993 stat: Io.File.Stat,2992 stat: Io.File.Stat,
2994 zir: Zir,2993 zir: Zir,
2995) (Io.File.WriteError || Allocator.Error)!void {2994) (Io.File.Writer.Error || Allocator.Error)!void {
2996 const safety_buffer = if (data_has_safety_tag)2995 const safety_buffer = if (data_has_safety_tag)
2997 try gpa.alloc([8]u8, zir.instructions.len)2996 try gpa.alloc([8]u8, zir.instructions.len)
2998 else2997 else
...@@ -3026,13 +3025,12 @@ pub fn saveZirCache(...@@ -3026,13 +3025,12 @@ pub fn saveZirCache(
3026 zir.string_bytes,3025 zir.string_bytes,
3027 @ptrCast(zir.extra),3026 @ptrCast(zir.extra),
3028 };3027 };
3029 var cache_fw = cache_file.writer(io, &.{});3028 cache_file_writer.interface.writeVecAll(&vecs) catch |err| switch (err) {
3030 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {3029 error.WriteFailed => return cache_file_writer.err.?,
3031 error.WriteFailed => return cache_fw.err.?,
3032 };3030 };
3033}3031}
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 {
3036 const header: Zoir.Header = .{3034 const header: Zoir.Header = .{
3037 .nodes_len = @intCast(zoir.nodes.len),3035 .nodes_len = @intCast(zoir.nodes.len),
3038 .extra_len = @intCast(zoir.extra.len),3036 .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...@@ -3056,9 +3054,8 @@ pub fn saveZoirCache(io: Io, cache_file: Io.File, stat: Io.File.Stat, zoir: Zoir
3056 @ptrCast(zoir.compile_errors),3054 @ptrCast(zoir.compile_errors),
3057 @ptrCast(zoir.error_notes),3055 @ptrCast(zoir.error_notes),
3058 };3056 };
3059 var cache_fw = cache_file.writer(io, &.{});3057 cache_file_writer.interface.writeVecAll(&vecs) catch |err| switch (err) {
3060 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {3058 error.WriteFailed => return cache_file_writer.err.?,
3061 error.WriteFailed => return cache_fw.err.?,
3062 };3059 };
3063}3060}
30643061
src/Zcu/PerThread.zig+35-15
...@@ -238,18 +238,13 @@ pub fn updateFile(...@@ -238,18 +238,13 @@ pub fn updateFile(
238 if (builtin.os.tag == .wasi or lock == .exclusive) break true;238 if (builtin.os.tag == .wasi or lock == .exclusive) break true;
239 // Otherwise, unlock to give someone a chance to get the exclusive lock239 // Otherwise, unlock to give someone a chance to get the exclusive lock
240 // and then upgrade to an exclusive lock.240 // and then upgrade to an exclusive lock.
241 cache_file.unlock();241 cache_file.unlock(io);
242 lock = .exclusive;242 lock = .exclusive;
243 try cache_file.lock(lock);243 try cache_file.lock(io, lock);
244 };244 };
245245
246 if (need_update) {246 if (need_update) {
247 // The cache is definitely stale so delete the contents to avoid an underwrite later.247 var cache_file_writer: Io.File.Writer = .init(cache_file, io, &.{});
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);
253248
254 if (stat.size > std.math.maxInt(u32))249 if (stat.size > std.math.maxInt(u32))
255 return error.FileTooBig;250 return error.FileTooBig;
...@@ -278,7 +273,7 @@ pub fn updateFile(...@@ -278,7 +273,7 @@ pub fn updateFile(
278 switch (file.getMode()) {273 switch (file.getMode()) {
279 .zig => {274 .zig => {
280 file.zir = try AstGen.generate(gpa, file.tree.?);275 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) {
282 error.OutOfMemory => |e| return e,277 error.OutOfMemory => |e| return e,
283 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{278 else => log.warn("unable to write cached ZIR code for {f} to {f}{s}: {t}", .{
284 file.path.fmt(comp), cache_directory, &hex_digest, err,279 file.path.fmt(comp), cache_directory, &hex_digest, err,
...@@ -287,13 +282,19 @@ pub fn updateFile(...@@ -287,13 +282,19 @@ pub fn updateFile(
287 },282 },
288 .zon => {283 .zon => {
289 file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});284 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| {
291 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{286 log.warn("unable to write cached ZOIR code for {f} to {f}{s}: {t}", .{
292 file.path.fmt(comp), cache_directory, &hex_digest, err,287 file.path.fmt(comp), cache_directory, &hex_digest, err,
293 });288 });
294 };289 };
295 },290 },
296 }291 }
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
297 if (timer.finish()) |ns_astgen| {298 if (timer.finish()) |ns_astgen| {
298 comp.mutex.lockUncancelable(io);299 comp.mutex.lockUncancelable(io);
299 defer comp.mutex.unlock(io);300 defer comp.mutex.unlock(io);
...@@ -4524,12 +4525,14 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) Ru...@@ -4524,12 +4525,14 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) Ru
4524 .stage2_llvm,4525 .stage2_llvm,
4525 => {},4526 => {},
4526 },4527 },
4528 error.Canceled => |e| return e,
4527 }4529 }
4528 return error.AlreadyReported;4530 return error.AlreadyReported;
4529 };4531 };
4530}4532}
4531fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) error{4533fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) error{
4532 OutOfMemory,4534 OutOfMemory,
4535 Canceled,
4533 CodegenFail,4536 CodegenFail,
4534 NoLinkFile,4537 NoLinkFile,
4535 BackendDoesNotProduceMir,4538 BackendDoesNotProduceMir,
...@@ -4555,13 +4558,16 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e...@@ -4555,13 +4558,16 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
4555 null;4558 null;
4556 defer if (liveness) |*l| l.deinit(gpa);4559 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: {
4559 const io = comp.io;4562 const io = comp.io;
4560 const stderr = try io.lockStderrWriter(&.{});4563 const stderr = try io.lockStderrWriter(&.{});
4561 defer io.unlockStderrWriter();4564 defer io.unlockStderrWriter();
4562 stderr.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {};4565 printVerboseAir(pt, liveness, fqn, air, &stderr.interface) catch |err| switch (err) {
4563 air.write(stderr, pt, liveness);4566 error.WriteFailed => switch (stderr.err.?) {
4564 stderr.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {};4567 error.Canceled => |e| return e,
4568 else => break :p,
4569 },
4570 };
4565 }4571 }
45664572
4567 if (std.debug.runtime_safety) verify_liveness: {4573 if (std.debug.runtime_safety) verify_liveness: {
...@@ -4576,7 +4582,7 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e...@@ -4576,7 +4582,7 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
45764582
4577 verify.verify() catch |err| switch (err) {4583 verify.verify() catch |err| switch (err) {
4578 error.OutOfMemory => return error.OutOfMemory,4584 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}),
4580 };4586 };
4581 }4587 }
45824588
...@@ -4612,3 +4618,17 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e...@@ -4612,3 +4618,17 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
4612 => return zcu.codegenFail(nav, "unable to codegen: {s}", .{@errorName(err)}),4618 => return zcu.codegenFail(nav, "unable to codegen: {s}", .{@errorName(err)}),
4613 };4619 };
4614}4620}
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) !...@@ -124,7 +124,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
124 try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>");124 try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>");
125 var error_bundle = try wip_errors.toOwnedBundle("");125 var error_bundle = try wip_errors.toOwnedBundle("");
126 defer error_bundle.deinit(gpa);126 defer error_bundle.deinit(gpa);
127 error_bundle.renderToStderr(io, .{}, color);127 error_bundle.renderToStderr(io, .{}, color) catch {};
128 process.exit(2);128 process.exit(2);
129 }129 }
130 } else {130 } else {
...@@ -138,12 +138,12 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -138,12 +138,12 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
138 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>");138 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>");
139 var error_bundle = try wip_errors.toOwnedBundle("");139 var error_bundle = try wip_errors.toOwnedBundle("");
140 defer error_bundle.deinit(gpa);140 defer error_bundle.deinit(gpa);
141 error_bundle.renderToStderr(io, .{}, color);141 error_bundle.renderToStderr(io, .{}, color) catch {};
142 process.exit(2);142 process.exit(2);
143 }143 }
144 }144 }
145 } else if (tree.errors.len != 0) {145 } 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 {};
147 process.exit(2);147 process.exit(2);
148 }148 }
149 const formatted = try tree.renderAlloc(gpa);149 const formatted = try tree.renderAlloc(gpa);
...@@ -298,7 +298,7 @@ fn fmtPathFile(...@@ -298,7 +298,7 @@ fn fmtPathFile(
298 defer tree.deinit(gpa);298 defer tree.deinit(gpa);
299299
300 if (tree.errors.len != 0) {300 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);
302 fmt.any_error = true;302 fmt.any_error = true;
303 return;303 return;
304 }304 }
...@@ -319,7 +319,7 @@ fn fmtPathFile(...@@ -319,7 +319,7 @@ fn fmtPathFile(
319 try wip_errors.addZirErrorMessages(zir, tree, source_code, file_path);319 try wip_errors.addZirErrorMessages(zir, tree, source_code, file_path);
320 var error_bundle = try wip_errors.toOwnedBundle("");320 var error_bundle = try wip_errors.toOwnedBundle("");
321 defer error_bundle.deinit(gpa);321 defer error_bundle.deinit(gpa);
322 error_bundle.renderToStderr(io, .{}, fmt.color);322 try error_bundle.renderToStderr(io, .{}, fmt.color);
323 fmt.any_error = true;323 fmt.any_error = true;
324 }324 }
325 },325 },
...@@ -334,7 +334,7 @@ fn fmtPathFile(...@@ -334,7 +334,7 @@ fn fmtPathFile(
334 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, file_path);334 try wip_errors.addZoirErrorMessages(zoir, tree, source_code, file_path);
335 var error_bundle = try wip_errors.toOwnedBundle("");335 var error_bundle = try wip_errors.toOwnedBundle("");
336 defer error_bundle.deinit(gpa);336 defer error_bundle.deinit(gpa);
337 error_bundle.renderToStderr(io, .{}, fmt.color);337 try error_bundle.renderToStderr(io, .{}, fmt.color);
338 fmt.any_error = true;338 fmt.any_error = true;
339 }339 }
340 },340 },
src/libs/freebsd.zig+2-2
...@@ -401,8 +401,8 @@ pub const BuiltSharedObjects = struct {...@@ -401,8 +401,8 @@ pub const BuiltSharedObjects = struct {
401 lock: Cache.Lock,401 lock: Cache.Lock,
402 dir_path: Path,402 dir_path: Path,
403403
404 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {404 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
405 self.lock.release();405 self.lock.release(io);
406 gpa.free(self.dir_path.sub_path);406 gpa.free(self.dir_path.sub_path);
407 self.* = undefined;407 self.* = undefined;
408 }408 }
src/libs/glibc.zig+2-2
...@@ -640,8 +640,8 @@ pub const BuiltSharedObjects = struct {...@@ -640,8 +640,8 @@ pub const BuiltSharedObjects = struct {
640 lock: Cache.Lock,640 lock: Cache.Lock,
641 dir_path: Path,641 dir_path: Path,
642642
643 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {643 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
644 self.lock.release();644 self.lock.release(io);
645 gpa.free(self.dir_path.sub_path);645 gpa.free(self.dir_path.sub_path);
646 self.* = undefined;646 self.* = undefined;
647 }647 }
src/libs/netbsd.zig+2-2
...@@ -346,8 +346,8 @@ pub const BuiltSharedObjects = struct {...@@ -346,8 +346,8 @@ pub const BuiltSharedObjects = struct {
346 lock: Cache.Lock,346 lock: Cache.Lock,
347 dir_path: Path,347 dir_path: Path,
348348
349 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void {349 pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator, io: Io) void {
350 self.lock.release();350 self.lock.release(io);
351 gpa.free(self.dir_path.sub_path);351 gpa.free(self.dir_path.sub_path);
352 self.* = undefined;352 self.* = undefined;
353 }353 }
src/link.zig+2-3
...@@ -2246,13 +2246,12 @@ fn resolvePathInputLib(...@@ -2246,13 +2246,12 @@ fn resolvePathInputLib(
2246 var error_bundle = try wip_errors.toOwnedBundle("");2246 var error_bundle = try wip_errors.toOwnedBundle("");
2247 defer error_bundle.deinit(gpa);2247 defer error_bundle.deinit(gpa);
22482248
2249 error_bundle.renderToStderr(io, .{}, color);2249 error_bundle.renderToStderr(io, .{}, color) catch {};
2250
2251 std.process.exit(1);2250 std.process.exit(1);
2252 }2251 }
22532252
2254 var ld_script = ld_script_result catch |err|2253 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 });
2256 defer ld_script.deinit(gpa);2255 defer ld_script.deinit(gpa);
22572256
2258 try unresolved_inputs.ensureUnusedCapacity(gpa, ld_script.args.len);2257 try unresolved_inputs.ensureUnusedCapacity(gpa, ld_script.args.len);
src/main.zig+6-1
...@@ -4598,6 +4598,8 @@ const UpdateModuleError = Compilation.UpdateError || error{...@@ -4598,6 +4598,8 @@ const UpdateModuleError = Compilation.UpdateError || error{
4598 /// The update caused compile errors. The error bundle has already been4598 /// The update caused compile errors. The error bundle has already been
4599 /// reported to the user by being rendered to stderr.4599 /// reported to the user by being rendered to stderr.
4600 CompileErrorsReported,4600 CompileErrorsReported,
4601 /// Error occurred printing compilation errors to stderr.
4602 PrintingErrorsFailed,
4601};4603};
4602fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node) UpdateModuleError!void {4604fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node) UpdateModuleError!void {
4603 try comp.update(prog_node);4605 try comp.update(prog_node);
...@@ -4607,7 +4609,10 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)...@@ -4607,7 +4609,10 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
46074609
4608 if (errors.errorMessageCount() > 0) {4610 if (errors.errorMessageCount() > 0) {
4609 const io = comp.io;4611 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 };
4611 return error.CompileErrorsReported;4616 return error.CompileErrorsReported;
4612 }4617 }
4613}4618}