authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-22 23:23:01-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:12-08:00
log0870f17501aa7d2eaaf2d774ccbc5d72291664ca
treebeaa280f67fa4ef4b03905e9f6b5fc3780ec8dc2
parentc05e2720a1acf0dc86e7f8a2661daae095d4d59b

fix aro and resinator compilation errors


6 files changed, 104 insertions(+), 102 deletions(-)

lib/compiler/aro/aro/Driver.zig+2-1
...@@ -134,8 +134,9 @@ strip: bool = false,...@@ -134,8 +134,9 @@ strip: bool = false,
134unwindlib: ?[]const u8 = null,134unwindlib: ?[]const u8 = null,
135135
136pub fn deinit(d: *Driver) void {136pub fn deinit(d: *Driver) void {
137 const io = d.comp.io;
137 for (d.link_objects.items[d.link_objects.items.len - d.temp_file_count ..]) |obj| {138 for (d.link_objects.items[d.link_objects.items.len - d.temp_file_count ..]) |obj| {
138 std.fs.deleteFileAbsolute(obj) catch {};139 Io.Dir.deleteFileAbsolute(io, obj) catch {};
139 d.comp.gpa.free(obj);140 d.comp.gpa.free(obj);
140 }141 }
141 d.inputs.deinit(d.comp.gpa);142 d.inputs.deinit(d.comp.gpa);
lib/compiler/resinator/cli.zig+27-26
...@@ -125,8 +125,8 @@ pub const Diagnostics = struct {...@@ -125,8 +125,8 @@ pub const Diagnostics = struct {
125 try self.errors.append(self.allocator, error_details);125 try self.errors.append(self.allocator, error_details);
126 }126 }
127127
128 pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) void {128 pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) Io.Cancelable!void {
129 const stderr = io.lockStderr(&.{}, null);129 const stderr = try io.lockStderr(&.{}, null);
130 defer io.unlockStderr();130 defer io.unlockStderr();
131 self.renderToWriter(args, stderr.terminal()) catch return;131 self.renderToWriter(args, stderr.terminal()) catch return;
132 }132 }
...@@ -419,7 +419,7 @@ pub const Arg = struct {...@@ -419,7 +419,7 @@ pub const Arg = struct {
419 };419 };
420 }420 }
421421
422 pub fn looksLikeFilepath(self: Arg) bool {422 pub fn looksLikeFilepath(self: Arg, io: Io) bool {
423 const meets_min_requirements = self.prefix == .slash and isSupportedInputExtension(std.fs.path.extension(self.full));423 const meets_min_requirements = self.prefix == .slash and isSupportedInputExtension(std.fs.path.extension(self.full));
424 if (!meets_min_requirements) return false;424 if (!meets_min_requirements) return false;
425425
...@@ -438,7 +438,7 @@ pub const Arg = struct {...@@ -438,7 +438,7 @@ pub const Arg = struct {
438 // It's still possible for a file path to look like a /fo option but not actually438 // It's still possible for a file path to look like a /fo option but not actually
439 // be one, e.g. `/foo/bar.rc`. As a last ditch effort to reduce false negatives,439 // be one, e.g. `/foo/bar.rc`. As a last ditch effort to reduce false negatives,
440 // check if the file path exists and, if so, then we ignore the 'could be /fo option'-ness440 // check if the file path exists and, if so, then we ignore the 'could be /fo option'-ness
441 std.fs.accessAbsolute(self.full, .{}) catch return false;441 Io.Dir.accessAbsolute(io, self.full, .{}) catch return false;
442 return true;442 return true;
443 }443 }
444444
...@@ -490,7 +490,7 @@ pub const ParseError = error{ParseError} || Allocator.Error;...@@ -490,7 +490,7 @@ pub const ParseError = error{ParseError} || Allocator.Error;
490490
491/// Note: Does not run `Options.maybeAppendRC` automatically. If that behavior is desired,491/// Note: Does not run `Options.maybeAppendRC` automatically. If that behavior is desired,
492/// it must be called separately.492/// it must be called separately.
493pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagnostics) ParseError!Options {493pub fn parse(allocator: Allocator, io: Io, args: []const []const u8, diagnostics: *Diagnostics) ParseError!Options {
494 var options = Options{ .allocator = allocator };494 var options = Options{ .allocator = allocator };
495 errdefer options.deinit();495 errdefer options.deinit();
496496
...@@ -530,7 +530,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn...@@ -530,7 +530,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn
530 }530 }
531531
532 const args_remaining = args.len - arg_i;532 const args_remaining = args.len - arg_i;
533 if (args_remaining <= 2 and arg.looksLikeFilepath()) {533 if (args_remaining <= 2 and arg.looksLikeFilepath(io)) {
534 var err_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i };534 var err_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i };
535 try err_details.msg.appendSlice(allocator, "this argument was inferred to be a filepath, so argument parsing was terminated");535 try err_details.msg.appendSlice(allocator, "this argument was inferred to be a filepath, so argument parsing was terminated");
536 try diagnostics.append(err_details);536 try diagnostics.append(err_details);
...@@ -1344,41 +1344,42 @@ test parsePercent {...@@ -1344,41 +1344,42 @@ test parsePercent {
1344 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));1344 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));
1345}1345}
13461346
1347pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {1347pub fn renderErrorMessage(t: Io.Terminal, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
1348 try config.setColor(writer, .dim);1348 const writer = t.writer;
1349 try t.setColor(.dim);
1349 try writer.writeAll("<cli>");1350 try writer.writeAll("<cli>");
1350 try config.setColor(writer, .reset);1351 try t.setColor(.reset);
1351 try config.setColor(writer, .bold);1352 try t.setColor(.bold);
1352 try writer.writeAll(": ");1353 try writer.writeAll(": ");
1353 switch (err_details.type) {1354 switch (err_details.type) {
1354 .err => {1355 .err => {
1355 try config.setColor(writer, .red);1356 try t.setColor(.red);
1356 try writer.writeAll("error: ");1357 try writer.writeAll("error: ");
1357 },1358 },
1358 .warning => {1359 .warning => {
1359 try config.setColor(writer, .yellow);1360 try t.setColor(.yellow);
1360 try writer.writeAll("warning: ");1361 try writer.writeAll("warning: ");
1361 },1362 },
1362 .note => {1363 .note => {
1363 try config.setColor(writer, .cyan);1364 try t.setColor(.cyan);
1364 try writer.writeAll("note: ");1365 try writer.writeAll("note: ");
1365 },1366 },
1366 }1367 }
1367 try config.setColor(writer, .reset);1368 try t.setColor(.reset);
1368 try config.setColor(writer, .bold);1369 try t.setColor(.bold);
1369 try writer.writeAll(err_details.msg.items);1370 try writer.writeAll(err_details.msg.items);
1370 try writer.writeByte('\n');1371 try writer.writeByte('\n');
1371 try config.setColor(writer, .reset);1372 try t.setColor(.reset);
13721373
1373 if (!err_details.print_args) {1374 if (!err_details.print_args) {
1374 try writer.writeByte('\n');1375 try writer.writeByte('\n');
1375 return;1376 return;
1376 }1377 }
13771378
1378 try config.setColor(writer, .dim);1379 try t.setColor(.dim);
1379 const prefix = " ... ";1380 const prefix = " ... ";
1380 try writer.writeAll(prefix);1381 try writer.writeAll(prefix);
1381 try config.setColor(writer, .reset);1382 try t.setColor(.reset);
13821383
1383 const arg_with_name = args[err_details.arg_index];1384 const arg_with_name = args[err_details.arg_index];
1384 const prefix_slice = arg_with_name[0..err_details.arg_span.prefix_len];1385 const prefix_slice = arg_with_name[0..err_details.arg_span.prefix_len];
...@@ -1389,15 +1390,15 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err...@@ -1389,15 +1390,15 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err
13891390
1390 try writer.writeAll(prefix_slice);1391 try writer.writeAll(prefix_slice);
1391 if (before_name_slice.len > 0) {1392 if (before_name_slice.len > 0) {
1392 try config.setColor(writer, .dim);1393 try t.setColor(.dim);
1393 try writer.writeAll(before_name_slice);1394 try writer.writeAll(before_name_slice);
1394 try config.setColor(writer, .reset);1395 try t.setColor(.reset);
1395 }1396 }
1396 try writer.writeAll(name_slice);1397 try writer.writeAll(name_slice);
1397 if (after_name_slice.len > 0) {1398 if (after_name_slice.len > 0) {
1398 try config.setColor(writer, .dim);1399 try t.setColor(.dim);
1399 try writer.writeAll(after_name_slice);1400 try writer.writeAll(after_name_slice);
1400 try config.setColor(writer, .reset);1401 try t.setColor(.reset);
1401 }1402 }
14021403
1403 var next_arg_len: usize = 0;1404 var next_arg_len: usize = 0;
...@@ -1415,13 +1416,13 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err...@@ -1415,13 +1416,13 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err
1415 if (err_details.arg_span.value_offset >= arg_with_name.len) {1416 if (err_details.arg_span.value_offset >= arg_with_name.len) {
1416 try writer.writeByte(' ');1417 try writer.writeByte(' ');
1417 }1418 }
1418 try config.setColor(writer, .dim);1419 try t.setColor(.dim);
1419 try writer.writeAll(" ...");1420 try writer.writeAll(" ...");
1420 try config.setColor(writer, .reset);1421 try t.setColor(.reset);
1421 }1422 }
1422 try writer.writeByte('\n');1423 try writer.writeByte('\n');
14231424
1424 try config.setColor(writer, .green);1425 try t.setColor(.green);
1425 try writer.splatByteAll(' ', prefix.len);1426 try writer.splatByteAll(' ', prefix.len);
1426 // Special case for when the option is *only* a prefix (e.g. invalid option: -)1427 // Special case for when the option is *only* a prefix (e.g. invalid option: -)
1427 if (err_details.arg_span.prefix_len == arg_with_name.len) {1428 if (err_details.arg_span.prefix_len == arg_with_name.len) {
...@@ -1447,7 +1448,7 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err...@@ -1447,7 +1448,7 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err
1447 }1448 }
1448 }1449 }
1449 try writer.writeByte('\n');1450 try writer.writeByte('\n');
1450 try config.setColor(writer, .reset);1451 try t.setColor(.reset);
1451}1452}
14521453
1453fn testParse(args: []const []const u8) !Options {1454fn testParse(args: []const []const u8) !Options {
lib/compiler/resinator/compile.zig+3-3
...@@ -96,7 +96,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io...@@ -96,7 +96,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io
96 var search_dirs: std.ArrayList(SearchDir) = .empty;96 var search_dirs: std.ArrayList(SearchDir) = .empty;
97 defer {97 defer {
98 for (search_dirs.items) |*search_dir| {98 for (search_dirs.items) |*search_dir| {
99 search_dir.deinit(allocator);99 search_dir.deinit(allocator, io);
100 }100 }
101 search_dirs.deinit(allocator);101 search_dirs.deinit(allocator);
102 }102 }
...@@ -406,7 +406,7 @@ pub const Compiler = struct {...@@ -406,7 +406,7 @@ pub const Compiler = struct {
406 // `/test.bin` relative to include paths and instead only treats it as406 // `/test.bin` relative to include paths and instead only treats it as
407 // an absolute path.407 // an absolute path.
408 if (std.fs.path.isAbsolute(path)) {408 if (std.fs.path.isAbsolute(path)) {
409 const file = try utils.openFileNotDir(Io.Dir.cwd(), path, .{});409 const file = try utils.openFileNotDir(Io.Dir.cwd(), io, path, .{});
410 errdefer file.close(io);410 errdefer file.close(io);
411411
412 if (self.dependencies) |dependencies| {412 if (self.dependencies) |dependencies| {
...@@ -418,7 +418,7 @@ pub const Compiler = struct {...@@ -418,7 +418,7 @@ pub const Compiler = struct {
418418
419 var first_error: ?(std.Io.File.OpenError || std.Io.File.StatError) = null;419 var first_error: ?(std.Io.File.OpenError || std.Io.File.StatError) = null;
420 for (self.search_dirs) |search_dir| {420 for (self.search_dirs) |search_dir| {
421 if (utils.openFileNotDir(search_dir.dir, path, .{})) |file| {421 if (utils.openFileNotDir(search_dir.dir, io, path, .{})) |file| {
422 errdefer file.close(io);422 errdefer file.close(io);
423423
424 if (self.dependencies) |dependencies| {424 if (self.dependencies) |dependencies| {
lib/compiler/resinator/errors.zig+35-35
...@@ -67,9 +67,9 @@ pub const Diagnostics = struct {...@@ -67,9 +67,9 @@ pub const Diagnostics = struct {
67 return @intCast(index);67 return @intCast(index);
68 }68 }
6969
70 pub fn renderToStderr(self: *Diagnostics, cwd: Io.Dir, source: []const u8, source_mappings: ?SourceMappings) void {70 pub fn renderToStderr(self: *Diagnostics, cwd: Io.Dir, source: []const u8, source_mappings: ?SourceMappings) Io.Cancelable!void {
71 const io = self.io;71 const io = self.io;
72 const stderr = io.lockStderr(&.{}, null);72 const stderr = try io.lockStderr(&.{}, null);
73 defer io.unlockStderr();73 defer io.unlockStderr();
74 for (self.errors.items) |err_details| {74 for (self.errors.items) |err_details| {
75 renderErrorMessage(io, stderr.terminal(), cwd, err_details, source, self.strings.items, source_mappings) catch return;75 renderErrorMessage(io, stderr.terminal(), cwd, err_details, source, self.strings.items, source_mappings) catch return;
...@@ -901,8 +901,7 @@ const truncated_str = "<...truncated...>";...@@ -901,8 +901,7 @@ const truncated_str = "<...truncated...>";
901901
902pub fn renderErrorMessage(902pub fn renderErrorMessage(
903 io: Io,903 io: Io,
904 writer: *std.Io.Writer,904 t: Io.Terminal,
905 tty_config: std.Io.tty.Config,
906 cwd: Io.Dir,905 cwd: Io.Dir,
907 err_details: ErrorDetails,906 err_details: ErrorDetails,
908 source: []const u8,907 source: []const u8,
...@@ -927,36 +926,37 @@ pub fn renderErrorMessage(...@@ -927,36 +926,37 @@ pub fn renderErrorMessage(
927926
928 const err_line = if (corresponding_span) |span| span.start_line else err_details.token.line_number;927 const err_line = if (corresponding_span) |span| span.start_line else err_details.token.line_number;
929928
930 try tty_config.setColor(writer, .bold);929 const writer = t.writer;
930 try t.setColor(.bold);
931 if (corresponding_file) |file| {931 if (corresponding_file) |file| {
932 try writer.writeAll(file);932 try writer.writeAll(file);
933 } else {933 } else {
934 try tty_config.setColor(writer, .dim);934 try t.setColor(.dim);
935 try writer.writeAll("<after preprocessor>");935 try writer.writeAll("<after preprocessor>");
936 try tty_config.setColor(writer, .reset);936 try t.setColor(.reset);
937 try tty_config.setColor(writer, .bold);937 try t.setColor(.bold);
938 }938 }
939 try writer.print(":{d}:{d}: ", .{ err_line, column });939 try writer.print(":{d}:{d}: ", .{ err_line, column });
940 switch (err_details.type) {940 switch (err_details.type) {
941 .err => {941 .err => {
942 try tty_config.setColor(writer, .red);942 try t.setColor(.red);
943 try writer.writeAll("error: ");943 try writer.writeAll("error: ");
944 },944 },
945 .warning => {945 .warning => {
946 try tty_config.setColor(writer, .yellow);946 try t.setColor(.yellow);
947 try writer.writeAll("warning: ");947 try writer.writeAll("warning: ");
948 },948 },
949 .note => {949 .note => {
950 try tty_config.setColor(writer, .cyan);950 try t.setColor(.cyan);
951 try writer.writeAll("note: ");951 try writer.writeAll("note: ");
952 },952 },
953 .hint => unreachable,953 .hint => unreachable,
954 }954 }
955 try tty_config.setColor(writer, .reset);955 try t.setColor(.reset);
956 try tty_config.setColor(writer, .bold);956 try t.setColor(.bold);
957 try err_details.render(writer, source, strings);957 try err_details.render(writer, source, strings);
958 try writer.writeByte('\n');958 try writer.writeByte('\n');
959 try tty_config.setColor(writer, .reset);959 try t.setColor(.reset);
960960
961 if (!err_details.print_source_line) {961 if (!err_details.print_source_line) {
962 try writer.writeByte('\n');962 try writer.writeByte('\n');
...@@ -983,20 +983,20 @@ pub fn renderErrorMessage(...@@ -983,20 +983,20 @@ pub fn renderErrorMessage(
983983
984 try writer.writeAll(source_line_for_display.line);984 try writer.writeAll(source_line_for_display.line);
985 if (source_line_for_display.truncated) {985 if (source_line_for_display.truncated) {
986 try tty_config.setColor(writer, .dim);986 try t.setColor(.dim);
987 try writer.writeAll(truncated_str);987 try writer.writeAll(truncated_str);
988 try tty_config.setColor(writer, .reset);988 try t.setColor(.reset);
989 }989 }
990 try writer.writeByte('\n');990 try writer.writeByte('\n');
991991
992 try tty_config.setColor(writer, .green);992 try t.setColor(.green);
993 const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len;993 const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len;
994 try writer.splatByteAll(' ', num_spaces);994 try writer.splatByteAll(' ', num_spaces);
995 try writer.splatByteAll('~', truncated_visual_info.before_len);995 try writer.splatByteAll('~', truncated_visual_info.before_len);
996 try writer.writeByte('^');996 try writer.writeByte('^');
997 try writer.splatByteAll('~', truncated_visual_info.after_len);997 try writer.splatByteAll('~', truncated_visual_info.after_len);
998 try writer.writeByte('\n');998 try writer.writeByte('\n');
999 try tty_config.setColor(writer, .reset);999 try t.setColor(.reset);
10001000
1001 if (corresponding_span != null and corresponding_file != null) {1001 if (corresponding_span != null and corresponding_file != null) {
1002 var worth_printing_lines: bool = true;1002 var worth_printing_lines: bool = true;
...@@ -1021,22 +1021,22 @@ pub fn renderErrorMessage(...@@ -1021,22 +1021,22 @@ pub fn renderErrorMessage(
1021 break :blk null;1021 break :blk null;
1022 },1022 },
1023 };1023 };
1024 defer if (corresponding_lines) |*cl| cl.deinit();1024 defer if (corresponding_lines) |*cl| cl.deinit(io);
10251025
1026 try tty_config.setColor(writer, .bold);1026 try t.setColor(.bold);
1027 if (corresponding_file) |file| {1027 if (corresponding_file) |file| {
1028 try writer.writeAll(file);1028 try writer.writeAll(file);
1029 } else {1029 } else {
1030 try tty_config.setColor(writer, .dim);1030 try t.setColor(.dim);
1031 try writer.writeAll("<after preprocessor>");1031 try writer.writeAll("<after preprocessor>");
1032 try tty_config.setColor(writer, .reset);1032 try t.setColor(.reset);
1033 try tty_config.setColor(writer, .bold);1033 try t.setColor(.bold);
1034 }1034 }
1035 try writer.print(":{d}:{d}: ", .{ err_line, column });1035 try writer.print(":{d}:{d}: ", .{ err_line, column });
1036 try tty_config.setColor(writer, .cyan);1036 try t.setColor(.cyan);
1037 try writer.writeAll("note: ");1037 try writer.writeAll("note: ");
1038 try tty_config.setColor(writer, .reset);1038 try t.setColor(.reset);
1039 try tty_config.setColor(writer, .bold);1039 try t.setColor(.bold);
1040 try writer.writeAll("this line originated from line");1040 try writer.writeAll("this line originated from line");
1041 if (corresponding_span.?.start_line != corresponding_span.?.end_line) {1041 if (corresponding_span.?.start_line != corresponding_span.?.end_line) {
1042 try writer.print("s {}-{}", .{ corresponding_span.?.start_line, corresponding_span.?.end_line });1042 try writer.print("s {}-{}", .{ corresponding_span.?.start_line, corresponding_span.?.end_line });
...@@ -1044,7 +1044,7 @@ pub fn renderErrorMessage(...@@ -1044,7 +1044,7 @@ pub fn renderErrorMessage(
1044 try writer.print(" {}", .{corresponding_span.?.start_line});1044 try writer.print(" {}", .{corresponding_span.?.start_line});
1045 }1045 }
1046 try writer.print(" of file '{s}'\n", .{corresponding_file.?});1046 try writer.print(" of file '{s}'\n", .{corresponding_file.?});
1047 try tty_config.setColor(writer, .reset);1047 try t.setColor(.reset);
10481048
1049 if (!worth_printing_lines) return;1049 if (!worth_printing_lines) return;
10501050
...@@ -1055,21 +1055,21 @@ pub fn renderErrorMessage(...@@ -1055,21 +1055,21 @@ pub fn renderErrorMessage(
1055 }) |display_line| {1055 }) |display_line| {
1056 try writer.writeAll(display_line.line);1056 try writer.writeAll(display_line.line);
1057 if (display_line.truncated) {1057 if (display_line.truncated) {
1058 try tty_config.setColor(writer, .dim);1058 try t.setColor(.dim);
1059 try writer.writeAll(truncated_str);1059 try writer.writeAll(truncated_str);
1060 try tty_config.setColor(writer, .reset);1060 try t.setColor(.reset);
1061 }1061 }
1062 try writer.writeByte('\n');1062 try writer.writeByte('\n');
1063 }1063 }
1064 break :write_lines null;1064 break :write_lines null;
1065 };1065 };
1066 if (write_lines_err) |err| {1066 if (write_lines_err) |err| {
1067 try tty_config.setColor(writer, .red);1067 try t.setColor(.red);
1068 try writer.writeAll(" | ");1068 try writer.writeAll(" | ");
1069 try tty_config.setColor(writer, .reset);1069 try t.setColor(.reset);
1070 try tty_config.setColor(writer, .dim);1070 try t.setColor(.dim);
1071 try writer.print("unable to print line(s) from file: {s}\n", .{@errorName(err)});1071 try writer.print("unable to print line(s) from file: {s}\n", .{@errorName(err)});
1072 try tty_config.setColor(writer, .reset);1072 try t.setColor(.reset);
1073 }1073 }
1074 try writer.writeByte('\n');1074 try writer.writeByte('\n');
1075 }1075 }
...@@ -1120,12 +1120,12 @@ const CorrespondingLines = struct {...@@ -1120,12 +1120,12 @@ const CorrespondingLines = struct {
11201120
1121 var corresponding_lines = CorrespondingLines{1121 var corresponding_lines = CorrespondingLines{
1122 .span = corresponding_span,1122 .span = corresponding_span,
1123 .file = try utils.openFileNotDir(cwd, corresponding_file, .{}),1123 .file = try utils.openFileNotDir(cwd, io, corresponding_file, .{}),
1124 .code_page = err_details.code_page,1124 .code_page = err_details.code_page,
1125 .file_reader = undefined,1125 .file_reader = undefined,
1126 };1126 };
1127 corresponding_lines.file_reader = corresponding_lines.file.reader(io, file_reader_buf);1127 corresponding_lines.file_reader = corresponding_lines.file.reader(io, file_reader_buf);
1128 errdefer corresponding_lines.deinit();1128 errdefer corresponding_lines.deinit(io);
11291129
1130 try corresponding_lines.writeLineFromStreamVerbatim(1130 try corresponding_lines.writeLineFromStreamVerbatim(
1131 &corresponding_lines.file_reader.interface,1131 &corresponding_lines.file_reader.interface,
lib/compiler/resinator/main.zig+26-27
...@@ -64,18 +64,18 @@ pub fn main() !void {...@@ -64,18 +64,18 @@ pub fn main() !void {
64 var options = options: {64 var options = options: {
65 var cli_diagnostics = cli.Diagnostics.init(gpa);65 var cli_diagnostics = cli.Diagnostics.init(gpa);
66 defer cli_diagnostics.deinit();66 defer cli_diagnostics.deinit();
67 var options = cli.parse(gpa, cli_args, &cli_diagnostics) catch |err| switch (err) {67 var options = cli.parse(gpa, io, cli_args, &cli_diagnostics) catch |err| switch (err) {
68 error.ParseError => {68 error.ParseError => {
69 try error_handler.emitCliDiagnostics(gpa, cli_args, &cli_diagnostics);69 try error_handler.emitCliDiagnostics(gpa, io, cli_args, &cli_diagnostics);
70 std.process.exit(1);70 std.process.exit(1);
71 },71 },
72 else => |e| return e,72 else => |e| return e,
73 };73 };
74 try options.maybeAppendRC(Io.Dir.cwd());74 try options.maybeAppendRC(io, Io.Dir.cwd());
7575
76 if (!zig_integration) {76 if (!zig_integration) {
77 // print any warnings/notes77 // print any warnings/notes
78 cli_diagnostics.renderToStderr(io, cli_args);78 try cli_diagnostics.renderToStderr(io, cli_args);
79 // If there was something printed, then add an extra newline separator79 // If there was something printed, then add an extra newline separator
80 // so that there is a clear separation between the cli diagnostics and whatever80 // so that there is a clear separation between the cli diagnostics and whatever
81 // gets printed after81 // gets printed after
...@@ -193,7 +193,7 @@ pub fn main() !void {...@@ -193,7 +193,7 @@ pub fn main() !void {
193 };193 };
194 },194 },
195 .filename => |input_filename| {195 .filename => |input_filename| {
196 break :full_input Io.Dir.cwd().readFileAlloc(input_filename, gpa, .unlimited) catch |err| {196 break :full_input Io.Dir.cwd().readFileAlloc(io, input_filename, gpa, .unlimited) catch |err| {
197 try error_handler.emitMessage(gpa, io, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });197 try error_handler.emitMessage(gpa, io, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });
198 std.process.exit(1);198 std.process.exit(1);
199 };199 };
...@@ -206,7 +206,7 @@ pub fn main() !void {...@@ -206,7 +206,7 @@ pub fn main() !void {
206 if (options.preprocess == .only) {206 if (options.preprocess == .only) {
207 switch (options.output_source) {207 switch (options.output_source) {
208 .stdio => |output_file| {208 .stdio => |output_file| {
209 try output_file.writeAll(full_input);209 try output_file.writeStreamingAll(io, full_input);
210 },210 },
211 .filename => |output_filename| {211 .filename => |output_filename| {
212 try Io.Dir.cwd().writeFile(io, .{ .sub_path = output_filename, .data = full_input });212 try Io.Dir.cwd().writeFile(io, .{ .sub_path = output_filename, .data = full_input });
...@@ -224,16 +224,16 @@ pub fn main() !void {...@@ -224,16 +224,16 @@ pub fn main() !void {
224 .source = .{ .memory = .empty },224 .source = .{ .memory = .empty },
225 }225 }
226 else if (options.input_format == .res)226 else if (options.input_format == .res)
227 IoStream.fromIoSource(options.input_source, .input) catch |err| {227 IoStream.fromIoSource(io, options.input_source, .input) catch |err| {
228 try error_handler.emitMessage(gpa, io, .err, "unable to read res file path '{s}': {s}", .{ options.input_source.filename, @errorName(err) });228 try error_handler.emitMessage(gpa, io, .err, "unable to read res file path '{s}': {s}", .{ options.input_source.filename, @errorName(err) });
229 std.process.exit(1);229 std.process.exit(1);
230 }230 }
231 else231 else
232 IoStream.fromIoSource(options.output_source, .output) catch |err| {232 IoStream.fromIoSource(io, options.output_source, .output) catch |err| {
233 try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) });233 try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) });
234 std.process.exit(1);234 std.process.exit(1);
235 };235 };
236 defer res_stream.deinit(gpa);236 defer res_stream.deinit(gpa, io);
237237
238 const res_data = res_data: {238 const res_data = res_data: {
239 if (options.input_format != .res) {239 if (options.input_format != .res) {
...@@ -269,7 +269,7 @@ pub fn main() !void {...@@ -269,7 +269,7 @@ pub fn main() !void {
269 defer diagnostics.deinit();269 defer diagnostics.deinit();
270270
271 var output_buffer: [4096]u8 = undefined;271 var output_buffer: [4096]u8 = undefined;
272 var res_stream_writer = res_stream.source.writer(gpa, &output_buffer);272 var res_stream_writer = res_stream.source.writer(gpa, io, &output_buffer);
273 defer res_stream_writer.deinit(&res_stream.source);273 defer res_stream_writer.deinit(&res_stream.source);
274 const output_buffered_stream = res_stream_writer.interface();274 const output_buffered_stream = res_stream_writer.interface();
275275
...@@ -303,7 +303,7 @@ pub fn main() !void {...@@ -303,7 +303,7 @@ pub fn main() !void {
303303
304 // print any warnings/notes304 // print any warnings/notes
305 if (!zig_integration) {305 if (!zig_integration) {
306 diagnostics.renderToStderr(io, Io.Dir.cwd(), final_input, mapping_results.mappings);306 try diagnostics.renderToStderr(Io.Dir.cwd(), final_input, mapping_results.mappings);
307 }307 }
308308
309 // write the depfile309 // write the depfile
...@@ -356,14 +356,14 @@ pub fn main() !void {...@@ -356,14 +356,14 @@ pub fn main() !void {
356 };356 };
357 defer resources.deinit();357 defer resources.deinit();
358358
359 var coff_stream = IoStream.fromIoSource(options.output_source, .output) catch |err| {359 var coff_stream = IoStream.fromIoSource(io, options.output_source, .output) catch |err| {
360 try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) });360 try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) });
361 std.process.exit(1);361 std.process.exit(1);
362 };362 };
363 defer coff_stream.deinit(gpa);363 defer coff_stream.deinit(gpa, io);
364364
365 var coff_output_buffer: [4096]u8 = undefined;365 var coff_output_buffer: [4096]u8 = undefined;
366 var coff_output_buffered_stream = coff_stream.source.writer(gpa, &coff_output_buffer);366 var coff_output_buffered_stream = coff_stream.source.writer(gpa, io, &coff_output_buffer);
367367
368 var cvtres_diagnostics: cvtres.Diagnostics = .{ .none = {} };368 var cvtres_diagnostics: cvtres.Diagnostics = .{ .none = {} };
369 cvtres.writeCoff(gpa, coff_output_buffered_stream.interface(), resources.list.items, options.coff_options, &cvtres_diagnostics) catch |err| {369 cvtres.writeCoff(gpa, coff_output_buffered_stream.interface(), resources.list.items, options.coff_options, &cvtres_diagnostics) catch |err| {
...@@ -413,22 +413,22 @@ const IoStream = struct {...@@ -413,22 +413,22 @@ const IoStream = struct {
413413
414 pub const IoDirection = enum { input, output };414 pub const IoDirection = enum { input, output };
415415
416 pub fn fromIoSource(source: cli.Options.IoSource, io: IoDirection) !IoStream {416 pub fn fromIoSource(io: Io, source: cli.Options.IoSource, io_direction: IoDirection) !IoStream {
417 return .{417 return .{
418 .name = switch (source) {418 .name = switch (source) {
419 .filename => |filename| filename,419 .filename => |filename| filename,
420 .stdio => switch (io) {420 .stdio => switch (io_direction) {
421 .input => "<stdin>",421 .input => "<stdin>",
422 .output => "<stdout>",422 .output => "<stdout>",
423 },423 },
424 },424 },
425 .intermediate = false,425 .intermediate = false,
426 .source = try Source.fromIoSource(source, io),426 .source = try Source.fromIoSource(io, source, io_direction),
427 };427 };
428 }428 }
429429
430 pub fn deinit(self: *IoStream, allocator: Allocator) void {430 pub fn deinit(self: *IoStream, allocator: Allocator, io: Io) void {
431 self.source.deinit(allocator);431 self.source.deinit(allocator, io);
432 }432 }
433433
434 pub fn cleanupAfterError(self: *IoStream, io: Io) void {434 pub fn cleanupAfterError(self: *IoStream, io: Io) void {
...@@ -450,11 +450,11 @@ const IoStream = struct {...@@ -450,11 +450,11 @@ const IoStream = struct {
450 /// The source has been closed and any usage of the Source in this state is illegal (except deinit).450 /// The source has been closed and any usage of the Source in this state is illegal (except deinit).
451 closed: void,451 closed: void,
452452
453 pub fn fromIoSource(source: cli.Options.IoSource, io: IoDirection) !Source {453 pub fn fromIoSource(io: Io, source: cli.Options.IoSource, io_direction: IoDirection) !Source {
454 switch (source) {454 switch (source) {
455 .filename => |filename| return .{455 .filename => |filename| return .{
456 .file = switch (io) {456 .file = switch (io_direction) {
457 .input => try openFileNotDir(Io.Dir.cwd(), filename, .{}),457 .input => try openFileNotDir(Io.Dir.cwd(), io, filename, .{}),
458 .output => try Io.Dir.cwd().createFile(io, filename, .{}),458 .output => try Io.Dir.cwd().createFile(io, filename, .{}),
459 },459 },
460 },460 },
...@@ -641,7 +641,7 @@ fn getIncludePaths(...@@ -641,7 +641,7 @@ fn getIncludePaths(
641 };641 };
642 const target = std.zig.resolveTargetQueryOrFatal(io, target_query);642 const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
643 const is_native_abi = target_query.isNativeAbi();643 const is_native_abi = target_query.isNativeAbi();
644 const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {644 const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
645 error.OutOfMemory => |e| return e,645 error.OutOfMemory => |e| return e,
646 else => return error.MingwIncludesNotFound,646 else => return error.MingwIncludesNotFound,
647 };647 };
...@@ -672,7 +672,7 @@ const ErrorHandler = union(enum) {...@@ -672,7 +672,7 @@ const ErrorHandler = union(enum) {
672672
673 try server.serveErrorBundle(error_bundle);673 try server.serveErrorBundle(error_bundle);
674 },674 },
675 .stderr => diagnostics.renderToStderr(io, args),675 .stderr => return diagnostics.renderToStderr(io, args),
676 }676 }
677 }677 }
678678
...@@ -696,7 +696,7 @@ const ErrorHandler = union(enum) {...@@ -696,7 +696,7 @@ const ErrorHandler = union(enum) {
696 },696 },
697 .stderr => {697 .stderr => {
698 // aro errors have already been emitted698 // aro errors have already been emitted
699 const stderr = io.lockStderr(&.{}, null);699 const stderr = try io.lockStderr(&.{}, null);
700 defer io.unlockStderr();700 defer io.unlockStderr();
701 try renderErrorMessage(stderr.terminal(), .err, "{s}", .{fail_msg});701 try renderErrorMessage(stderr.terminal(), .err, "{s}", .{fail_msg});
702 },702 },
...@@ -706,7 +706,6 @@ const ErrorHandler = union(enum) {...@@ -706,7 +706,6 @@ const ErrorHandler = union(enum) {
706 pub fn emitDiagnostics(706 pub fn emitDiagnostics(
707 self: *ErrorHandler,707 self: *ErrorHandler,
708 allocator: Allocator,708 allocator: Allocator,
709 io: Io,
710 cwd: Io.Dir,709 cwd: Io.Dir,
711 source: []const u8,710 source: []const u8,
712 diagnostics: *Diagnostics,711 diagnostics: *Diagnostics,
...@@ -719,7 +718,7 @@ const ErrorHandler = union(enum) {...@@ -719,7 +718,7 @@ const ErrorHandler = union(enum) {
719718
720 try server.serveErrorBundle(error_bundle);719 try server.serveErrorBundle(error_bundle);
721 },720 },
722 .stderr => diagnostics.renderToStderr(io, cwd, source, mappings),721 .stderr => return diagnostics.renderToStderr(cwd, source, mappings),
723 }722 }
724 }723 }
725724
lib/compiler/resinator/utils.zig+11-10
...@@ -92,31 +92,32 @@ pub const ErrorMessageType = enum { err, warning, note };...@@ -92,31 +92,32 @@ pub const ErrorMessageType = enum { err, warning, note };
9292
93/// Used for generic colored errors/warnings/notes, more context-specific error messages93/// Used for generic colored errors/warnings/notes, more context-specific error messages
94/// are handled elsewhere.94/// are handled elsewhere.
95pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {95pub fn renderErrorMessage(t: Io.Terminal, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
96 const writer = t.writer;
96 switch (msg_type) {97 switch (msg_type) {
97 .err => {98 .err => {
98 try config.setColor(writer, .bold);99 try t.setColor(.bold);
99 try config.setColor(writer, .red);100 try t.setColor(.red);
100 try writer.writeAll("error: ");101 try writer.writeAll("error: ");
101 },102 },
102 .warning => {103 .warning => {
103 try config.setColor(writer, .bold);104 try t.setColor(.bold);
104 try config.setColor(writer, .yellow);105 try t.setColor(.yellow);
105 try writer.writeAll("warning: ");106 try writer.writeAll("warning: ");
106 },107 },
107 .note => {108 .note => {
108 try config.setColor(writer, .reset);109 try t.setColor(.reset);
109 try config.setColor(writer, .cyan);110 try t.setColor(.cyan);
110 try writer.writeAll("note: ");111 try writer.writeAll("note: ");
111 },112 },
112 }113 }
113 try config.setColor(writer, .reset);114 try t.setColor(.reset);
114 if (msg_type == .err) {115 if (msg_type == .err) {
115 try config.setColor(writer, .bold);116 try t.setColor(.bold);
116 }117 }
117 try writer.print(format, args);118 try writer.print(format, args);
118 try writer.writeByte('\n');119 try writer.writeByte('\n');
119 try config.setColor(writer, .reset);120 try t.setColor(.reset);
120}121}
121122
122pub fn isLineEndingPair(first: u8, second: u8) bool {123pub fn isLineEndingPair(first: u8, second: u8) bool {