| author | |
| committer | |
| log | 1925e0319f1337b4856bd5a181bf4f6d3ac7d428 |
| tree | b38839cca2604368b01b4312119083a5cdf3d224 |
| parent | ec56696503e702e063af8740a77376b2e7694c29 |
use the application's Io implementation where possible. This correctly
makes writing to stderr cancelable, fallible, and participate in the
application's event loop. It also removes one more hard-coded
dependency on a secondary Io implementation.32 files changed, 345 insertions(+), 247 deletions(-)
lib/compiler/build_runner.zig+10-8| ... | ... | @@ -522,7 +522,7 @@ pub fn main() !void { |
| 522 | 522 | // Perhaps in the future there could be an Advanced Options flag |
| 523 | 523 | // such as --debug-build-runner-leaks which would make this code |
| 524 | 524 | // return instead of calling exit. |
| 525 | _ = std.debug.lockStderrWriter(&.{}); | |
| 525 | _ = io.lockStderrWriter(&.{}) catch {}; | |
| 526 | 526 | process.exit(1); |
| 527 | 527 | }, |
| 528 | 528 | else => |e| return e, |
| ... | ... | @@ -554,8 +554,8 @@ pub fn main() !void { |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | rebuild: while (true) : (if (run.error_style.clearOnUpdate()) { |
| 557 | const stderr = std.debug.lockStderrWriter(&stdio_buffer_allocation); | |
| 558 | defer std.debug.unlockStderrWriter(); | |
| 557 | const stderr = try io.lockStderrWriter(&stdio_buffer_allocation); | |
| 558 | defer io.unlockStderrWriter(); | |
| 559 | 559 | try stderr.writeAllUnescaped("\x1B[2J\x1B[3J\x1B[H"); |
| 560 | 560 | }) { |
| 561 | 561 | if (run.web_server) |*ws| ws.startBuild(); |
| ... | ... | @@ -856,8 +856,8 @@ fn runStepNames( |
| 856 | 856 | .none => break :summary, |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | const stderr = std.debug.lockStderrWriter(&stdio_buffer_allocation); | |
| 860 | defer std.debug.unlockStderrWriter(); | |
| 859 | const stderr = try io.lockStderrWriter(&stdio_buffer_allocation); | |
| 860 | defer io.unlockStderrWriter(); | |
| 861 | 861 | |
| 862 | 862 | const w = &stderr.interface; |
| 863 | 863 | const fwm = stderr.mode; |
| ... | ... | @@ -954,7 +954,7 @@ fn runStepNames( |
| 954 | 954 | if (run.error_style.verboseContext()) break :code 1; // failure; print build command |
| 955 | 955 | break :code 2; // failure; do not print build command |
| 956 | 956 | }; |
| 957 | _ = std.debug.lockStderrWriter(&.{}); | |
| 957 | _ = io.lockStderrWriter(&.{}) catch {}; | |
| 958 | 958 | process.exit(code); |
| 959 | 959 | } |
| 960 | 960 | |
| ... | ... | @@ -1369,8 +1369,10 @@ fn workerMakeOneStep( |
| 1369 | 1369 | const show_error_msgs = s.result_error_msgs.items.len > 0; |
| 1370 | 1370 | const show_stderr = s.result_stderr.len > 0; |
| 1371 | 1371 | if (show_error_msgs or show_compile_errors or show_stderr) { |
| 1372 | const stderr = std.debug.lockStderrWriter(&stdio_buffer_allocation); | |
| 1373 | defer std.debug.unlockStderrWriter(); | |
| 1372 | const stderr = io.lockStderrWriter(&stdio_buffer_allocation) catch |err| switch (err) { | |
| 1373 | error.Canceled => return, | |
| 1374 | }; | |
| 1375 | defer io.unlockStderrWriter(); | |
| 1374 | 1376 | printErrorMessages(gpa, s, .{}, &stderr.interface, stderr.mode, run.error_style, run.multiline_errors) catch {}; |
| 1375 | 1377 | } |
| 1376 | 1378 |
lib/compiler/resinator/cli.zig+4-4| ... | ... | @@ -125,10 +125,10 @@ pub const Diagnostics = struct { |
| 125 | 125 | try self.errors.append(self.allocator, error_details); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8) void { | |
| 129 | const stderr, const ttyconf = std.debug.lockStderrWriter(&.{}); | |
| 130 | defer std.debug.unlockStderrWriter(); | |
| 131 | self.renderToWriter(args, stderr, ttyconf) catch return; | |
| 128 | pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) void { | |
| 129 | const stderr = io.lockStderrWriter(&.{}); | |
| 130 | defer io.unlockStderrWriter(); | |
| 131 | self.renderToWriter(args, &stderr.interface, stderr.mode) catch return; | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: *std.Io.Writer, config: std.Io.tty.Config) !void { |
lib/compiler/resinator/errors.zig+4-4| ... | ... | @@ -67,12 +67,12 @@ pub const Diagnostics = struct { |
| 67 | 67 | return @intCast(index); |
| 68 | 68 | } |
| 69 | 69 | |
| 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) void { | |
| 71 | 71 | const io = self.io; |
| 72 | const stderr, const ttyconf = std.debug.lockStderrWriter(&.{}); | |
| 73 | defer std.debug.unlockStderrWriter(); | |
| 72 | const stderr = io.lockStderrWriter(&.{}); | |
| 73 | defer io.unlockStderrWriter(); | |
| 74 | 74 | for (self.errors.items) |err_details| { |
| 75 | renderErrorMessage(io, stderr, ttyconf, cwd, err_details, source, self.strings.items, source_mappings) catch return; | |
| 75 | renderErrorMessage(io, &stderr.interface, stderr.mode, cwd, err_details, source, self.strings.items, source_mappings) catch return; | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 |
lib/compiler/resinator/main.zig+51-47| ... | ... | @@ -24,6 +24,10 @@ pub fn main() !void { |
| 24 | 24 | defer std.debug.assert(debug_allocator.deinit() == .ok); |
| 25 | 25 | const gpa = debug_allocator.allocator(); |
| 26 | 26 | |
| 27 | var threaded: std.Io.Threaded = .init(gpa); | |
| 28 | defer threaded.deinit(); | |
| 29 | const io = threaded.io(); | |
| 30 | ||
| 27 | 31 | var arena_state = std.heap.ArenaAllocator.init(gpa); |
| 28 | 32 | defer arena_state.deinit(); |
| 29 | 33 | const arena = arena_state.allocator(); |
| ... | ... | @@ -31,8 +35,8 @@ pub fn main() !void { |
| 31 | 35 | const args = try std.process.argsAlloc(arena); |
| 32 | 36 | |
| 33 | 37 | if (args.len < 2) { |
| 34 | const w, const ttyconf = std.debug.lockStderrWriter(&.{}); | |
| 35 | try renderErrorMessage(w, ttyconf, .err, "expected zig lib dir as first argument", .{}); | |
| 38 | const stderr = io.lockStderrWriter(&.{}); | |
| 39 | try renderErrorMessage(&stderr.interface, stderr.mode, .err, "expected zig lib dir as first argument", .{}); | |
| 36 | 40 | std.process.exit(1); |
| 37 | 41 | } |
| 38 | 42 | const zig_lib_dir = args[1]; |
| ... | ... | @@ -45,7 +49,7 @@ pub fn main() !void { |
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | var stdout_buffer: [1024]u8 = undefined; |
| 48 | var stdout_writer = Io.File.stdout().writer(&stdout_buffer); | |
| 52 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); | |
| 49 | 53 | const stdout = &stdout_writer.interface; |
| 50 | 54 | var error_handler: ErrorHandler = switch (zig_integration) { |
| 51 | 55 | true => .{ |
| ... | ... | @@ -71,24 +75,20 @@ pub fn main() !void { |
| 71 | 75 | |
| 72 | 76 | if (!zig_integration) { |
| 73 | 77 | // print any warnings/notes |
| 74 | cli_diagnostics.renderToStdErr(cli_args); | |
| 78 | cli_diagnostics.renderToStderr(io, cli_args); | |
| 75 | 79 | // If there was something printed, then add an extra newline separator |
| 76 | 80 | // so that there is a clear separation between the cli diagnostics and whatever |
| 77 | 81 | // gets printed after |
| 78 | 82 | if (cli_diagnostics.errors.items.len > 0) { |
| 79 | const stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 80 | defer std.debug.unlockStderrWriter(); | |
| 81 | try stderr.writeByte('\n'); | |
| 83 | const stderr = io.lockStderrWriter(&.{}); | |
| 84 | defer io.unlockStderrWriter(); | |
| 85 | try stderr.interface.writeByte('\n'); | |
| 82 | 86 | } |
| 83 | 87 | } |
| 84 | 88 | break :options options; |
| 85 | 89 | }; |
| 86 | 90 | defer options.deinit(); |
| 87 | 91 | |
| 88 | var threaded: std.Io.Threaded = .init(gpa); | |
| 89 | defer threaded.deinit(); | |
| 90 | const io = threaded.io(); | |
| 91 | ||
| 92 | 92 | if (options.print_help_and_exit) { |
| 93 | 93 | try cli.writeUsage(stdout, "zig rc"); |
| 94 | 94 | try stdout.flush(); |
| ... | ... | @@ -130,10 +130,10 @@ pub fn main() !void { |
| 130 | 130 | var stderr_buf: [512]u8 = undefined; |
| 131 | 131 | var diagnostics: aro.Diagnostics = .{ .output = output: { |
| 132 | 132 | if (zig_integration) break :output .{ .to_list = .{ .arena = .init(gpa) } }; |
| 133 | const w, const ttyconf = std.debug.lockStderrWriter(&stderr_buf); | |
| 133 | const stderr = io.lockStderrWriter(&stderr_buf); | |
| 134 | 134 | break :output .{ .to_writer = .{ |
| 135 | .writer = w, | |
| 136 | .color = ttyconf, | |
| 135 | .writer = &stderr.interface, | |
| 136 | .color = stderr.mode, | |
| 137 | 137 | } }; |
| 138 | 138 | } }; |
| 139 | 139 | defer { |
| ... | ... | @@ -175,11 +175,11 @@ pub fn main() !void { |
| 175 | 175 | std.process.exit(1); |
| 176 | 176 | }, |
| 177 | 177 | error.FileTooBig => { |
| 178 | try error_handler.emitMessage(gpa, .err, "failed during preprocessing: maximum file size exceeded", .{}); | |
| 178 | try error_handler.emitMessage(gpa, io, .err, "failed during preprocessing: maximum file size exceeded", .{}); | |
| 179 | 179 | std.process.exit(1); |
| 180 | 180 | }, |
| 181 | 181 | error.WriteFailed => { |
| 182 | try error_handler.emitMessage(gpa, .err, "failed during preprocessing: error writing the preprocessed output", .{}); | |
| 182 | try error_handler.emitMessage(gpa, io, .err, "failed during preprocessing: error writing the preprocessed output", .{}); | |
| 183 | 183 | std.process.exit(1); |
| 184 | 184 | }, |
| 185 | 185 | error.OutOfMemory => |e| return e, |
| ... | ... | @@ -191,13 +191,13 @@ pub fn main() !void { |
| 191 | 191 | .stdio => |file| { |
| 192 | 192 | var file_reader = file.reader(io, &.{}); |
| 193 | 193 | break :full_input file_reader.interface.allocRemaining(gpa, .unlimited) catch |err| { |
| 194 | try error_handler.emitMessage(gpa, .err, "unable to read input from stdin: {s}", .{@errorName(err)}); | |
| 194 | try error_handler.emitMessage(gpa, io, .err, "unable to read input from stdin: {s}", .{@errorName(err)}); | |
| 195 | 195 | std.process.exit(1); |
| 196 | 196 | }; |
| 197 | 197 | }, |
| 198 | 198 | .filename => |input_filename| { |
| 199 | 199 | break :full_input Io.Dir.cwd().readFileAlloc(input_filename, gpa, .unlimited) catch |err| { |
| 200 | try error_handler.emitMessage(gpa, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) }); | |
| 200 | try error_handler.emitMessage(gpa, io, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) }); | |
| 201 | 201 | std.process.exit(1); |
| 202 | 202 | }; |
| 203 | 203 | }, |
| ... | ... | @@ -228,12 +228,12 @@ pub fn main() !void { |
| 228 | 228 | } |
| 229 | 229 | else if (options.input_format == .res) |
| 230 | 230 | IoStream.fromIoSource(options.input_source, .input) catch |err| { |
| 231 | try error_handler.emitMessage(gpa, .err, "unable to read res file path '{s}': {s}", .{ options.input_source.filename, @errorName(err) }); | |
| 231 | try error_handler.emitMessage(gpa, io, .err, "unable to read res file path '{s}': {s}", .{ options.input_source.filename, @errorName(err) }); | |
| 232 | 232 | std.process.exit(1); |
| 233 | 233 | } |
| 234 | 234 | else |
| 235 | 235 | IoStream.fromIoSource(options.output_source, .output) catch |err| { |
| 236 | try error_handler.emitMessage(gpa, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); | |
| 236 | try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); | |
| 237 | 237 | std.process.exit(1); |
| 238 | 238 | }; |
| 239 | 239 | defer res_stream.deinit(gpa); |
| ... | ... | @@ -246,17 +246,17 @@ pub fn main() !void { |
| 246 | 246 | var mapping_results = parseAndRemoveLineCommands(gpa, full_input, full_input, .{ .initial_filename = options.input_source.filename }) catch |err| switch (err) { |
| 247 | 247 | error.InvalidLineCommand => { |
| 248 | 248 | // TODO: Maybe output the invalid line command |
| 249 | try error_handler.emitMessage(gpa, .err, "invalid line command in the preprocessed source", .{}); | |
| 249 | try error_handler.emitMessage(gpa, io, .err, "invalid line command in the preprocessed source", .{}); | |
| 250 | 250 | if (options.preprocess == .no) { |
| 251 | try error_handler.emitMessage(gpa, .note, "line commands must be of the format: #line <num> \"<path>\"", .{}); | |
| 251 | try error_handler.emitMessage(gpa, io, .note, "line commands must be of the format: #line <num> \"<path>\"", .{}); | |
| 252 | 252 | } else { |
| 253 | try error_handler.emitMessage(gpa, .note, "this is likely to be a bug, please report it", .{}); | |
| 253 | try error_handler.emitMessage(gpa, io, .note, "this is likely to be a bug, please report it", .{}); | |
| 254 | 254 | } |
| 255 | 255 | std.process.exit(1); |
| 256 | 256 | }, |
| 257 | 257 | error.LineNumberOverflow => { |
| 258 | 258 | // TODO: Better error message |
| 259 | try error_handler.emitMessage(gpa, .err, "line number count exceeded maximum of {}", .{std.math.maxInt(usize)}); | |
| 259 | try error_handler.emitMessage(gpa, io, .err, "line number count exceeded maximum of {}", .{std.math.maxInt(usize)}); | |
| 260 | 260 | std.process.exit(1); |
| 261 | 261 | }, |
| 262 | 262 | error.OutOfMemory => |e| return e, |
| ... | ... | @@ -306,13 +306,13 @@ pub fn main() !void { |
| 306 | 306 | |
| 307 | 307 | // print any warnings/notes |
| 308 | 308 | if (!zig_integration) { |
| 309 | diagnostics.renderToStdErr(Io.Dir.cwd(), final_input, mapping_results.mappings); | |
| 309 | diagnostics.renderToStderr(io, Io.Dir.cwd(), final_input, mapping_results.mappings); | |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // write the depfile |
| 313 | 313 | if (options.depfile_path) |depfile_path| { |
| 314 | 314 | var depfile = Io.Dir.cwd().createFile(io, depfile_path, .{}) catch |err| { |
| 315 | try error_handler.emitMessage(gpa, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) }); | |
| 315 | try error_handler.emitMessage(gpa, io, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) }); | |
| 316 | 316 | std.process.exit(1); |
| 317 | 317 | }; |
| 318 | 318 | defer depfile.close(io); |
| ... | ... | @@ -340,7 +340,7 @@ pub fn main() !void { |
| 340 | 340 | if (options.output_format != .coff) return; |
| 341 | 341 | |
| 342 | 342 | break :res_data res_stream.source.readAll(gpa, io) catch |err| { |
| 343 | try error_handler.emitMessage(gpa, .err, "unable to read res from '{s}': {s}", .{ res_stream.name, @errorName(err) }); | |
| 343 | try error_handler.emitMessage(gpa, io, .err, "unable to read res from '{s}': {s}", .{ res_stream.name, @errorName(err) }); | |
| 344 | 344 | std.process.exit(1); |
| 345 | 345 | }; |
| 346 | 346 | }; |
| ... | ... | @@ -353,14 +353,14 @@ pub fn main() !void { |
| 353 | 353 | var res_reader: std.Io.Reader = .fixed(res_data.bytes); |
| 354 | 354 | break :resources cvtres.parseRes(gpa, &res_reader, .{ .max_size = res_data.bytes.len }) catch |err| { |
| 355 | 355 | // TODO: Better errors |
| 356 | try error_handler.emitMessage(gpa, .err, "unable to parse res from '{s}': {s}", .{ res_stream.name, @errorName(err) }); | |
| 356 | try error_handler.emitMessage(gpa, io, .err, "unable to parse res from '{s}': {s}", .{ res_stream.name, @errorName(err) }); | |
| 357 | 357 | std.process.exit(1); |
| 358 | 358 | }; |
| 359 | 359 | }; |
| 360 | 360 | defer resources.deinit(); |
| 361 | 361 | |
| 362 | 362 | var coff_stream = IoStream.fromIoSource(options.output_source, .output) catch |err| { |
| 363 | try error_handler.emitMessage(gpa, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); | |
| 363 | try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); | |
| 364 | 364 | std.process.exit(1); |
| 365 | 365 | }; |
| 366 | 366 | defer coff_stream.deinit(gpa); |
| ... | ... | @@ -373,7 +373,7 @@ pub fn main() !void { |
| 373 | 373 | switch (err) { |
| 374 | 374 | error.DuplicateResource => { |
| 375 | 375 | const duplicate_resource = resources.list.items[cvtres_diagnostics.duplicate_resource]; |
| 376 | try error_handler.emitMessage(gpa, .err, "duplicate resource [id: {f}, type: {f}, language: {f}]", .{ | |
| 376 | try error_handler.emitMessage(gpa, io, .err, "duplicate resource [id: {f}, type: {f}, language: {f}]", .{ | |
| 377 | 377 | duplicate_resource.name_value, |
| 378 | 378 | fmtResourceType(duplicate_resource.type_value), |
| 379 | 379 | duplicate_resource.language, |
| ... | ... | @@ -381,8 +381,8 @@ pub fn main() !void { |
| 381 | 381 | }, |
| 382 | 382 | error.ResourceDataTooLong => { |
| 383 | 383 | const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource]; |
| 384 | try error_handler.emitMessage(gpa, .err, "resource has a data length that is too large to be written into a coff section", .{}); | |
| 385 | try error_handler.emitMessage(gpa, .note, "the resource with the invalid size is [id: {f}, type: {f}, language: {f}]", .{ | |
| 384 | try error_handler.emitMessage(gpa, io, .err, "resource has a data length that is too large to be written into a coff section", .{}); | |
| 385 | try error_handler.emitMessage(gpa, io, .note, "the resource with the invalid size is [id: {f}, type: {f}, language: {f}]", .{ | |
| 386 | 386 | overflow_resource.name_value, |
| 387 | 387 | fmtResourceType(overflow_resource.type_value), |
| 388 | 388 | overflow_resource.language, |
| ... | ... | @@ -390,15 +390,15 @@ pub fn main() !void { |
| 390 | 390 | }, |
| 391 | 391 | error.TotalResourceDataTooLong => { |
| 392 | 392 | const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource]; |
| 393 | try error_handler.emitMessage(gpa, .err, "total resource data exceeds the maximum of the coff 'size of raw data' field", .{}); | |
| 394 | try error_handler.emitMessage(gpa, .note, "size overflow occurred when attempting to write this resource: [id: {f}, type: {f}, language: {f}]", .{ | |
| 393 | try error_handler.emitMessage(gpa, io, .err, "total resource data exceeds the maximum of the coff 'size of raw data' field", .{}); | |
| 394 | try error_handler.emitMessage(gpa, io, .note, "size overflow occurred when attempting to write this resource: [id: {f}, type: {f}, language: {f}]", .{ | |
| 395 | 395 | overflow_resource.name_value, |
| 396 | 396 | fmtResourceType(overflow_resource.type_value), |
| 397 | 397 | overflow_resource.language, |
| 398 | 398 | }); |
| 399 | 399 | }, |
| 400 | 400 | else => { |
| 401 | try error_handler.emitMessage(gpa, .err, "unable to write coff output file '{s}': {s}", .{ coff_stream.name, @errorName(err) }); | |
| 401 | try error_handler.emitMessage(gpa, io, .err, "unable to write coff output file '{s}': {s}", .{ coff_stream.name, @errorName(err) }); | |
| 402 | 402 | }, |
| 403 | 403 | } |
| 404 | 404 | // Delete the output file on error |
| ... | ... | @@ -550,16 +550,16 @@ const LazyIncludePaths = struct { |
| 550 | 550 | else => |e| { |
| 551 | 551 | switch (e) { |
| 552 | 552 | error.UnsupportedAutoIncludesMachineType => { |
| 553 | try error_handler.emitMessage(self.arena, .err, "automatic include path detection is not supported for target '{s}'", .{@tagName(self.target_machine_type)}); | |
| 553 | try error_handler.emitMessage(self.arena, io, .err, "automatic include path detection is not supported for target '{s}'", .{@tagName(self.target_machine_type)}); | |
| 554 | 554 | }, |
| 555 | 555 | error.MsvcIncludesNotFound => { |
| 556 | try error_handler.emitMessage(self.arena, .err, "MSVC include paths could not be automatically detected", .{}); | |
| 556 | try error_handler.emitMessage(self.arena, io, .err, "MSVC include paths could not be automatically detected", .{}); | |
| 557 | 557 | }, |
| 558 | 558 | error.MingwIncludesNotFound => { |
| 559 | try error_handler.emitMessage(self.arena, .err, "MinGW include paths could not be automatically detected", .{}); | |
| 559 | try error_handler.emitMessage(self.arena, io, .err, "MinGW include paths could not be automatically detected", .{}); | |
| 560 | 560 | }, |
| 561 | 561 | } |
| 562 | try error_handler.emitMessage(self.arena, .note, "to disable auto includes, use the option /:auto-includes none", .{}); | |
| 562 | try error_handler.emitMessage(self.arena, io, .note, "to disable auto includes, use the option /:auto-includes none", .{}); | |
| 563 | 563 | std.process.exit(1); |
| 564 | 564 | }, |
| 565 | 565 | }; |
| ... | ... | @@ -664,6 +664,7 @@ const ErrorHandler = union(enum) { |
| 664 | 664 | pub fn emitCliDiagnostics( |
| 665 | 665 | self: *ErrorHandler, |
| 666 | 666 | allocator: Allocator, |
| 667 | io: Io, | |
| 667 | 668 | args: []const []const u8, |
| 668 | 669 | diagnostics: *cli.Diagnostics, |
| 669 | 670 | ) !void { |
| ... | ... | @@ -674,7 +675,7 @@ const ErrorHandler = union(enum) { |
| 674 | 675 | |
| 675 | 676 | try server.serveErrorBundle(error_bundle); |
| 676 | 677 | }, |
| 677 | .stderr => diagnostics.renderToStdErr(args), | |
| 678 | .stderr => diagnostics.renderToStderr(io, args), | |
| 678 | 679 | } |
| 679 | 680 | } |
| 680 | 681 | |
| ... | ... | @@ -684,6 +685,7 @@ const ErrorHandler = union(enum) { |
| 684 | 685 | fail_msg: []const u8, |
| 685 | 686 | comp: *aro.Compilation, |
| 686 | 687 | ) !void { |
| 688 | const io = comp.io; | |
| 687 | 689 | switch (self.*) { |
| 688 | 690 | .server => |*server| { |
| 689 | 691 | var error_bundle = try compiler_util.aroDiagnosticsToErrorBundle( |
| ... | ... | @@ -697,9 +699,9 @@ const ErrorHandler = union(enum) { |
| 697 | 699 | }, |
| 698 | 700 | .stderr => { |
| 699 | 701 | // aro errors have already been emitted |
| 700 | const stderr, const ttyconf = std.debug.lockStderrWriter(&.{}); | |
| 701 | defer std.debug.unlockStderrWriter(); | |
| 702 | try renderErrorMessage(stderr, ttyconf, .err, "{s}", .{fail_msg}); | |
| 702 | const stderr = io.lockStderrWriter(&.{}); | |
| 703 | defer io.unlockStderrWriter(); | |
| 704 | try renderErrorMessage(&stderr.interface, stderr.mode, .err, "{s}", .{fail_msg}); | |
| 703 | 705 | }, |
| 704 | 706 | } |
| 705 | 707 | } |
| ... | ... | @@ -707,6 +709,7 @@ const ErrorHandler = union(enum) { |
| 707 | 709 | pub fn emitDiagnostics( |
| 708 | 710 | self: *ErrorHandler, |
| 709 | 711 | allocator: Allocator, |
| 712 | io: Io, | |
| 710 | 713 | cwd: Io.Dir, |
| 711 | 714 | source: []const u8, |
| 712 | 715 | diagnostics: *Diagnostics, |
| ... | ... | @@ -719,13 +722,14 @@ const ErrorHandler = union(enum) { |
| 719 | 722 | |
| 720 | 723 | try server.serveErrorBundle(error_bundle); |
| 721 | 724 | }, |
| 722 | .stderr => diagnostics.renderToStdErr(cwd, source, mappings), | |
| 725 | .stderr => diagnostics.renderToStderr(io, cwd, source, mappings), | |
| 723 | 726 | } |
| 724 | 727 | } |
| 725 | 728 | |
| 726 | 729 | pub fn emitMessage( |
| 727 | 730 | self: *ErrorHandler, |
| 728 | 731 | allocator: Allocator, |
| 732 | io: Io, | |
| 729 | 733 | msg_type: @import("utils.zig").ErrorMessageType, |
| 730 | 734 | comptime format: []const u8, |
| 731 | 735 | args: anytype, |
| ... | ... | @@ -741,9 +745,9 @@ const ErrorHandler = union(enum) { |
| 741 | 745 | try server.serveErrorBundle(error_bundle); |
| 742 | 746 | }, |
| 743 | 747 | .stderr => { |
| 744 | const stderr, const ttyconf = std.debug.lockStderrWriter(&.{}); | |
| 745 | defer std.debug.unlockStderrWriter(); | |
| 746 | try renderErrorMessage(stderr, ttyconf, msg_type, format, args); | |
| 748 | const stderr = io.lockStderrWriter(&.{}); | |
| 749 | defer io.unlockStderrWriter(); | |
| 750 | try renderErrorMessage(&stderr.interface, stderr.mode, msg_type, format, args); | |
| 747 | 751 | }, |
| 748 | 752 | } |
| 749 | 753 | } |
lib/compiler/std-docs.zig+1-1| ... | ... | @@ -407,7 +407,7 @@ fn buildWasmBinary( |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (result_error_bundle.errorMessageCount() > 0) { |
| 410 | result_error_bundle.renderToStdErr(.{}, true); | |
| 410 | result_error_bundle.renderToStderr(io, .{}, true); | |
| 411 | 411 | std.log.err("the following command failed with {d} compilation errors:\n{s}", .{ |
| 412 | 412 | result_error_bundle.errorMessageCount(), |
| 413 | 413 | try std.Build.Step.allocPrintCmd(arena, null, argv.items), |
lib/compiler/test_runner.zig-3| ... | ... | @@ -411,16 +411,13 @@ pub fn fuzz( |
| 411 | 411 | std.debug.writeStackTrace(trace, &stderr.interface, stderr.mode) catch break :p; |
| 412 | 412 | } |
| 413 | 413 | stderr.interface.print("failed with error.{t}\n", .{err}) catch break :p; |
| 414 | stderr.interface.flush() catch break :p; | |
| 415 | 414 | } |
| 416 | stderr.interface.flush() catch {}; | |
| 417 | 415 | std.process.exit(1); |
| 418 | 416 | }, |
| 419 | 417 | }; |
| 420 | 418 | if (log_err_count != 0) { |
| 421 | 419 | const stderr = std.debug.lockStderrWriter(&.{}); |
| 422 | 420 | stderr.interface.print("error logs detected\n", .{}) catch {}; |
| 423 | stderr.interface.flush() catch {}; | |
| 424 | 421 | std.process.exit(1); |
| 425 | 422 | } |
| 426 | 423 | } |
lib/std/Build.zig+23-8| ... | ... | @@ -2238,7 +2238,7 @@ pub const GeneratedFile = struct { |
| 2238 | 2238 | /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards. |
| 2239 | 2239 | path: ?[]const u8 = null, |
| 2240 | 2240 | |
| 2241 | /// Deprecated, see `getPath2`. | |
| 2241 | /// Deprecated, see `getPath3`. | |
| 2242 | 2242 | pub fn getPath(gen: GeneratedFile) []const u8 { |
| 2243 | 2243 | return gen.step.owner.pathFromCwd(gen.path orelse std.debug.panic( |
| 2244 | 2244 | "getPath() was called on a GeneratedFile that wasn't built yet. Is there a missing Step dependency on step '{s}'?", |
| ... | ... | @@ -2246,11 +2246,18 @@ pub const GeneratedFile = struct { |
| 2246 | 2246 | )); |
| 2247 | 2247 | } |
| 2248 | 2248 | |
| 2249 | /// Deprecated, see `getPath3`. | |
| 2249 | 2250 | pub fn getPath2(gen: GeneratedFile, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2251 | return getPath3(gen, src_builder, asking_step) catch |err| switch (err) { | |
| 2252 | error.Canceled => std.process.exit(1), | |
| 2253 | }; | |
| 2254 | } | |
| 2255 | ||
| 2256 | pub fn getPath3(gen: GeneratedFile, src_builder: *Build, asking_step: ?*Step) Io.Cancelable![]const u8 { | |
| 2250 | 2257 | return gen.path orelse { |
| 2251 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 2258 | const io = gen.step.owner.graph.io; | |
| 2259 | const stderr = try io.lockStderrWriter(&.{}); | |
| 2252 | 2260 | dumpBadGetPathHelp(gen.step, &stderr.interface, stderr.mode, src_builder, asking_step) catch {}; |
| 2253 | std.debug.unlockStderrWriter(); | |
| 2254 | 2261 | @panic("misconfigured build script"); |
| 2255 | 2262 | }; |
| 2256 | 2263 | } |
| ... | ... | @@ -2425,22 +2432,29 @@ pub const LazyPath = union(enum) { |
| 2425 | 2432 | } |
| 2426 | 2433 | } |
| 2427 | 2434 | |
| 2428 | /// Deprecated, see `getPath3`. | |
| 2435 | /// Deprecated, see `getPath4`. | |
| 2429 | 2436 | pub fn getPath(lazy_path: LazyPath, src_builder: *Build) []const u8 { |
| 2430 | 2437 | return getPath2(lazy_path, src_builder, null); |
| 2431 | 2438 | } |
| 2432 | 2439 | |
| 2433 | /// Deprecated, see `getPath3`. | |
| 2440 | /// Deprecated, see `getPath4`. | |
| 2434 | 2441 | pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2435 | 2442 | const p = getPath3(lazy_path, src_builder, asking_step); |
| 2436 | 2443 | return src_builder.pathResolve(&.{ p.root_dir.path orelse ".", p.sub_path }); |
| 2437 | 2444 | } |
| 2438 | 2445 | |
| 2446 | /// Deprecated, see `getPath4`. | |
| 2447 | pub fn getPath3(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Cache.Path { | |
| 2448 | return getPath4(lazy_path, src_builder, asking_step) catch |err| switch (err) { | |
| 2449 | error.Canceled => std.process.exit(1), | |
| 2450 | }; | |
| 2451 | } | |
| 2452 | ||
| 2439 | 2453 | /// Intended to be used during the make phase only. |
| 2440 | 2454 | /// |
| 2441 | 2455 | /// `asking_step` is only used for debugging purposes; it's the step being |
| 2442 | 2456 | /// run that is asking for the path. |
| 2443 | pub fn getPath3(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Cache.Path { | |
| 2457 | pub fn getPath4(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Io.Cancelable!Cache.Path { | |
| 2444 | 2458 | switch (lazy_path) { |
| 2445 | 2459 | .src_path => |sp| return .{ |
| 2446 | 2460 | .root_dir = sp.owner.build_root, |
| ... | ... | @@ -2457,9 +2471,10 @@ pub const LazyPath = union(enum) { |
| 2457 | 2471 | var file_path: Cache.Path = .{ |
| 2458 | 2472 | .root_dir = Cache.Directory.cwd(), |
| 2459 | 2473 | .sub_path = gen.file.path orelse { |
| 2460 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 2474 | const io = src_builder.graph.io; | |
| 2475 | const stderr = try io.lockStderrWriter(&.{}); | |
| 2461 | 2476 | dumpBadGetPathHelp(gen.file.step, &stderr.interface, stderr.mode, src_builder, asking_step) catch {}; |
| 2462 | std.debug.unlockStderrWriter(); | |
| 2477 | io.unlockStderrWriter(); | |
| 2463 | 2478 | @panic("misconfigured build script"); |
| 2464 | 2479 | }, |
| 2465 | 2480 | }; |
lib/std/Build/Fuzz.zig+11-10| ... | ... | @@ -158,6 +158,7 @@ fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, parent_prog_node: std.P |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, parent_prog_node: std.Progress.Node) !void { |
| 161 | const io = run.step.owner.graph.io; | |
| 161 | 162 | const compile = run.producer.?; |
| 162 | 163 | const prog_node = parent_prog_node.start(compile.step.name, 0); |
| 163 | 164 | defer prog_node.end(); |
| ... | ... | @@ -170,8 +171,8 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, parent_prog_nod |
| 170 | 171 | |
| 171 | 172 | if (show_error_msgs or show_compile_errors or show_stderr) { |
| 172 | 173 | var buf: [256]u8 = undefined; |
| 173 | const stderr = std.debug.lockStderrWriter(&buf); | |
| 174 | defer std.debug.unlockStderrWriter(); | |
| 174 | const stderr = try io.lockStderrWriter(&buf); | |
| 175 | defer io.unlockStderrWriter(); | |
| 175 | 176 | build_runner.printErrorMessages(gpa, &compile.step, .{}, &stderr.interface, stderr.mode, .verbose, .indent) catch {}; |
| 176 | 177 | } |
| 177 | 178 | |
| ... | ... | @@ -182,12 +183,10 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, parent_prog_nod |
| 182 | 183 | run.rebuilt_executable = try rebuilt_bin_path.join(gpa, compile.out_filename); |
| 183 | 184 | } |
| 184 | 185 | |
| 185 | fn fuzzWorkerRun( | |
| 186 | fuzz: *Fuzz, | |
| 187 | run: *Step.Run, | |
| 188 | unit_test_index: u32, | |
| 189 | ) void { | |
| 190 | const gpa = run.step.owner.allocator; | |
| 186 | fn fuzzWorkerRun(fuzz: *Fuzz, run: *Step.Run, unit_test_index: u32) void { | |
| 187 | const owner = run.step.owner; | |
| 188 | const gpa = owner.allocator; | |
| 189 | const io = owner.graph.io; | |
| 191 | 190 | const test_name = run.cached_test_metadata.?.testName(unit_test_index); |
| 192 | 191 | |
| 193 | 192 | const prog_node = fuzz.prog_node.start(test_name, 0); |
| ... | ... | @@ -196,8 +195,10 @@ fn fuzzWorkerRun( |
| 196 | 195 | run.rerunInFuzzMode(fuzz, unit_test_index, prog_node) catch |err| switch (err) { |
| 197 | 196 | error.MakeFailed => { |
| 198 | 197 | var buf: [256]u8 = undefined; |
| 199 | const stderr = std.debug.lockStderrWriter(&buf); | |
| 200 | defer std.debug.unlockStderrWriter(); | |
| 198 | const stderr = io.lockStderrWriter(&buf) catch |e| switch (e) { | |
| 199 | error.Canceled => return, | |
| 200 | }; | |
| 201 | defer io.unlockStderrWriter(); | |
| 201 | 202 | build_runner.printErrorMessages(gpa, &run.step, .{}, &stderr.interface, stderr.mode, .verbose, .indent) catch {}; |
| 202 | 203 | return; |
| 203 | 204 | }, |
lib/std/Build/Step/Compile.zig+10-7| ... | ... | @@ -922,20 +922,23 @@ const CliNamedModules = struct { |
| 922 | 922 | } |
| 923 | 923 | }; |
| 924 | 924 | |
| 925 | fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking_step: ?*Step) []const u8 { | |
| 925 | fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking_step: ?*Step) ![]const u8 { | |
| 926 | const step = &compile.step; | |
| 927 | const b = step.owner; | |
| 928 | const io = b.graph.io; | |
| 926 | 929 | const maybe_path: ?*GeneratedFile = @field(compile, tag_name); |
| 927 | 930 | |
| 928 | 931 | const generated_file = maybe_path orelse { |
| 929 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 932 | const stderr = try io.lockStderrWriter(&.{}); | |
| 930 | 933 | std.Build.dumpBadGetPathHelp(&compile.step, &stderr.interface, stderr.mode, compile.step.owner, asking_step) catch {}; |
| 931 | std.debug.unlockStderrWriter(); | |
| 934 | io.unlockStderrWriter(); | |
| 932 | 935 | @panic("missing emit option for " ++ tag_name); |
| 933 | 936 | }; |
| 934 | 937 | |
| 935 | 938 | const path = generated_file.path orelse { |
| 936 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 939 | const stderr = try io.lockStderrWriter(&.{}); | |
| 937 | 940 | std.Build.dumpBadGetPathHelp(&compile.step, &stderr.interface, stderr.mode, compile.step.owner, asking_step) catch {}; |
| 938 | std.debug.unlockStderrWriter(); | |
| 941 | io.unlockStderrWriter(); | |
| 939 | 942 | @panic(tag_name ++ " is null. Is there a missing step dependency?"); |
| 940 | 943 | }; |
| 941 | 944 | |
| ... | ... | @@ -1149,9 +1152,9 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1149 | 1152 | // For everything else, we directly link |
| 1150 | 1153 | // against the library file. |
| 1151 | 1154 | const full_path_lib = if (other_produces_implib) |
| 1152 | other.getGeneratedFilePath("generated_implib", &compile.step) | |
| 1155 | try other.getGeneratedFilePath("generated_implib", &compile.step) | |
| 1153 | 1156 | else |
| 1154 | other.getGeneratedFilePath("generated_bin", &compile.step); | |
| 1157 | try other.getGeneratedFilePath("generated_bin", &compile.step); | |
| 1155 | 1158 | |
| 1156 | 1159 | try zig_args.append(full_path_lib); |
| 1157 | 1160 | total_linker_objects += 1; |
lib/std/Build/Step/Run.zig+3-2| ... | ... | @@ -1559,6 +1559,7 @@ fn spawnChildAndCollect( |
| 1559 | 1559 | ) !?EvalGenericResult { |
| 1560 | 1560 | const b = run.step.owner; |
| 1561 | 1561 | const arena = b.allocator; |
| 1562 | const io = b.graph.io; | |
| 1562 | 1563 | |
| 1563 | 1564 | if (fuzz_context != null) { |
| 1564 | 1565 | assert(!has_side_effects); |
| ... | ... | @@ -1625,10 +1626,10 @@ fn spawnChildAndCollect( |
| 1625 | 1626 | child.progress_node = options.progress_node; |
| 1626 | 1627 | } |
| 1627 | 1628 | if (inherit) { |
| 1628 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 1629 | const stderr = try io.lockStderrWriter(&.{}); | |
| 1629 | 1630 | try setColorEnvironmentVariables(run, env_map, stderr.mode); |
| 1630 | 1631 | } |
| 1631 | defer if (inherit) std.debug.unlockStderrWriter(); | |
| 1632 | defer if (inherit) io.unlockStderrWriter(); | |
| 1632 | 1633 | var timer = try std.time.Timer.start(); |
| 1633 | 1634 | const res = try evalGeneric(run, &child); |
| 1634 | 1635 | run.step.result_duration_ns = timer.read(); |
lib/std/Build/WebServer.zig+1-1| ... | ... | @@ -655,7 +655,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | if (result_error_bundle.errorMessageCount() > 0) { |
| 658 | result_error_bundle.renderToStdErr(.{}, .auto); | |
| 658 | try result_error_bundle.renderToStderr(io, .{}, .auto); | |
| 659 | 659 | log.err("the following command failed with {d} compilation errors:\n{s}", .{ |
| 660 | 660 | result_error_bundle.errorMessageCount(), |
| 661 | 661 | try Build.Step.allocPrintCmd(arena, null, argv.items), |
lib/std/Progress.zig+1-1| ... | ... | @@ -764,7 +764,7 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize { |
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void { | |
| 767 | pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) Io.Writer.Error!void { | |
| 768 | 768 | if (noop_impl or !global_progress.need_clear) return; |
| 769 | 769 | try file_writer.writeAllUnescaped(clear ++ progress_remove); |
| 770 | 770 | global_progress.need_clear = false; |
lib/std/json/dynamic.zig+2-3| ... | ... | @@ -47,10 +47,9 @@ pub const Value = union(enum) { |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | pub fn dump(v: Value) void { |
| 50 | const w, _ = std.debug.lockStderrWriter(&.{}); | |
| 50 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 51 | 51 | defer std.debug.unlockStderrWriter(); |
| 52 | ||
| 53 | json.Stringify.value(v, .{}, w) catch return; | |
| 52 | json.Stringify.value(v, .{}, &stderr.interface) catch return; | |
| 54 | 53 | } |
| 55 | 54 | |
| 56 | 55 | pub fn jsonStringify(value: @This(), jws: anytype) !void { |
lib/std/process.zig+1-1| ... | ... | @@ -1849,7 +1849,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 { |
| 1849 | 1849 | /// and does not return. |
| 1850 | 1850 | pub fn cleanExit(io: Io) void { |
| 1851 | 1851 | if (builtin.mode == .Debug) return; |
| 1852 | _ = io.lockStderrWriter(&.{}); | |
| 1852 | _ = io.lockStderrWriter(&.{}) catch {}; | |
| 1853 | 1853 | exit(0); |
| 1854 | 1854 | } |
| 1855 | 1855 |
lib/std/testing.zig+12-4| ... | ... | @@ -368,13 +368,21 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const |
| 368 | 368 | break :diff_index if (expected.len == actual.len) return else shortest; |
| 369 | 369 | }; |
| 370 | 370 | if (!backend_can_print) return error.TestExpectedEqual; |
| 371 | const stderr = std.debug.lockStderrWriter(&.{}); | |
| 372 | defer std.debug.unlockStderrWriter(); | |
| 373 | failEqualSlices(T, expected, actual, diff_index, &stderr.interface, stderr.mode) catch {}; | |
| 371 | if (io.lockStderrWriter(&.{})) |stderr| { | |
| 372 | defer io.unlockStderrWriter(); | |
| 373 | failEqualSlices(T, expected, actual, diff_index, &stderr.interface, stderr.mode) catch {}; | |
| 374 | } else |_| {} | |
| 374 | 375 | return error.TestExpectedEqual; |
| 375 | 376 | } |
| 376 | 377 | |
| 377 | fn failEqualSlices(comptime T: type, expected: []const T, actual: []const T, diff_index: usize, w: *Io.Writer, fwm: Io.File.Writer.Mode) !void { | |
| 378 | fn failEqualSlices( | |
| 379 | comptime T: type, | |
| 380 | expected: []const T, | |
| 381 | actual: []const T, | |
| 382 | diff_index: usize, | |
| 383 | w: *Io.Writer, | |
| 384 | fwm: Io.File.Writer.Mode, | |
| 385 | ) !void { | |
| 378 | 386 | try w.print("slices differ. first difference occurs at index {d} (0x{X})\n", .{ diff_index, diff_index }); |
| 379 | 387 | |
| 380 | 388 | // TODO: Should this be configurable by the caller? |
lib/std/zig.zig+2-2| ... | ... | @@ -639,7 +639,7 @@ pub fn readSourceFileToEndAlloc(gpa: Allocator, file_reader: *Io.File.Reader) ![ |
| 639 | 639 | return buffer.toOwnedSliceSentinel(gpa, 0); |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | pub fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color: Color) !void { | |
| 642 | pub fn printAstErrorsToStderr(gpa: Allocator, io: Io, tree: Ast, path: []const u8, color: Color) !void { | |
| 643 | 643 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 644 | 644 | try wip_errors.init(gpa); |
| 645 | 645 | defer wip_errors.deinit(); |
| ... | ... | @@ -648,7 +648,7 @@ pub fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color |
| 648 | 648 | |
| 649 | 649 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 650 | 650 | defer error_bundle.deinit(gpa); |
| 651 | error_bundle.renderToStdErr(.{}, color); | |
| 651 | error_bundle.renderToStderr(io, .{}, color); | |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | pub fn putAstErrorsIntoBundle( |
lib/std/zig/ErrorBundle.zig+6-4| ... | ... | @@ -162,11 +162,13 @@ pub const RenderOptions = struct { |
| 162 | 162 | include_log_text: bool = true, |
| 163 | 163 | }; |
| 164 | 164 | |
| 165 | pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions, color: std.zig.Color) void { | |
| 165 | pub const RenderToStderrError = Io.Cancelable || Io.File.Writer.Mode.SetColorError; | |
| 166 | ||
| 167 | pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: std.zig.Color) RenderToStderrError!void { | |
| 166 | 168 | var buffer: [256]u8 = undefined; |
| 167 | const stderr = std.debug.lockStderrWriter(&buffer); | |
| 168 | defer std.debug.unlockStderrWriter(); | |
| 169 | renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)) catch return; | |
| 169 | const stderr = try io.lockStderrWriter(&buffer); | |
| 170 | defer io.unlockStderrWriter(); | |
| 171 | try renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)); | |
| 170 | 172 | } |
| 171 | 173 | |
| 172 | 174 | pub fn renderToWriter( |
lib/std/zig/parser_test.zig+19-11| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const mem = std.mem; | |
| 3 | const print = std.debug.print; | |
| 4 | const maxInt = std.math.maxInt; | |
| 2 | const Io = std.Io; | |
| 3 | const Allocator = std.mem.Allocator; | |
| 5 | 4 | |
| 6 | 5 | test "zig fmt: remove extra whitespace at start and end of file with comment between" { |
| 7 | 6 | try testTransform( |
| ... | ... | @@ -6332,10 +6331,10 @@ test "ampersand" { |
| 6332 | 6331 | |
| 6333 | 6332 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 6334 | 6333 | |
| 6335 | fn testParse(source: [:0]const u8, allocator: mem.Allocator, anything_changed: *bool) ![]u8 { | |
| 6334 | fn testParse(io: Io, source: [:0]const u8, allocator: Allocator, anything_changed: *bool) ![]u8 { | |
| 6336 | 6335 | var buffer: [64]u8 = undefined; |
| 6337 | const stderr = std.debug.lockStderrWriter(&buffer); | |
| 6338 | defer std.debug.unlockStderrWriter(); | |
| 6336 | const stderr = try io.lockStderrWriter(&buffer); | |
| 6337 | defer io.unlockStderrWriter(); | |
| 6339 | 6338 | |
| 6340 | 6339 | var tree = try std.zig.Ast.parse(allocator, source, .zig); |
| 6341 | 6340 | defer tree.deinit(allocator); |
| ... | ... | @@ -6359,27 +6358,36 @@ fn testParse(source: [:0]const u8, allocator: mem.Allocator, anything_changed: * |
| 6359 | 6358 | } |
| 6360 | 6359 | |
| 6361 | 6360 | const formatted = try tree.renderAlloc(allocator); |
| 6362 | anything_changed.* = !mem.eql(u8, formatted, source); | |
| 6361 | anything_changed.* = !std.mem.eql(u8, formatted, source); | |
| 6363 | 6362 | return formatted; |
| 6364 | 6363 | } |
| 6365 | fn testTransformImpl(allocator: mem.Allocator, fba: *std.heap.FixedBufferAllocator, source: [:0]const u8, expected_source: []const u8) !void { | |
| 6364 | fn testTransformImpl( | |
| 6365 | io: Io, | |
| 6366 | allocator: Allocator, | |
| 6367 | fba: *std.heap.FixedBufferAllocator, | |
| 6368 | source: [:0]const u8, | |
| 6369 | expected_source: []const u8, | |
| 6370 | ) !void { | |
| 6366 | 6371 | // reset the fixed buffer allocator each run so that it can be re-used for each |
| 6367 | 6372 | // iteration of the failing index |
| 6368 | 6373 | fba.reset(); |
| 6369 | 6374 | var anything_changed: bool = undefined; |
| 6370 | const result_source = try testParse(source, allocator, &anything_changed); | |
| 6375 | const result_source = try testParse(io, source, allocator, &anything_changed); | |
| 6371 | 6376 | try std.testing.expectEqualStrings(expected_source, result_source); |
| 6372 | 6377 | const changes_expected = source.ptr != expected_source.ptr; |
| 6373 | 6378 | if (anything_changed != changes_expected) { |
| 6374 | print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); | |
| 6379 | std.debug.print("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); | |
| 6375 | 6380 | return error.TestFailed; |
| 6376 | 6381 | } |
| 6377 | 6382 | try std.testing.expect(anything_changed == changes_expected); |
| 6378 | 6383 | allocator.free(result_source); |
| 6379 | 6384 | } |
| 6380 | 6385 | fn testTransform(source: [:0]const u8, expected_source: []const u8) !void { |
| 6386 | const io = std.testing.io; | |
| 6381 | 6387 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 6382 | return std.testing.checkAllAllocationFailures(fixed_allocator.allocator(), testTransformImpl, .{ &fixed_allocator, source, expected_source }); | |
| 6388 | return std.testing.checkAllAllocationFailures(fixed_allocator.allocator(), testTransformImpl, .{ | |
| 6389 | io, &fixed_allocator, source, expected_source, | |
| 6390 | }); | |
| 6383 | 6391 | } |
| 6384 | 6392 | fn testCanonical(source: [:0]const u8) !void { |
| 6385 | 6393 | return testTransform(source, source); |
src/Air/print.zig+18-10| ... | ... | @@ -9,7 +9,7 @@ const Type = @import("../Type.zig"); |
| 9 | 9 | const Air = @import("../Air.zig"); |
| 10 | 10 | const InternPool = @import("../InternPool.zig"); |
| 11 | 11 | |
| 12 | pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { | |
| 12 | pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) !void { | |
| 13 | 13 | comptime assert(build_options.enable_debug_extensions); |
| 14 | 14 | const instruction_bytes = air.instructions.len * |
| 15 | 15 | // Here we don't use @sizeOf(Air.Inst.Data) because it would include |
| ... | ... | @@ -24,7 +24,7 @@ pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air |
| 24 | 24 | liveness_special_bytes + tomb_bytes; |
| 25 | 25 | |
| 26 | 26 | // zig fmt: off |
| 27 | stream.print( | |
| 27 | try stream.print( | |
| 28 | 28 | \\# Total AIR+Liveness bytes: {Bi} |
| 29 | 29 | \\# AIR Instructions: {d} ({Bi}) |
| 30 | 30 | \\# AIR Extra Data: {d} ({Bi}) |
| ... | ... | @@ -39,7 +39,7 @@ pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air |
| 39 | 39 | tomb_bytes, |
| 40 | 40 | if (liveness) |l| l.extra.len else 0, liveness_extra_bytes, |
| 41 | 41 | if (liveness) |l| l.special.count() else 0, liveness_special_bytes, |
| 42 | }) catch return; | |
| 42 | }); | |
| 43 | 43 | // zig fmt: on |
| 44 | 44 | |
| 45 | 45 | var writer: Writer = .{ |
| ... | ... | @@ -50,7 +50,7 @@ pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air |
| 50 | 50 | .indent = 2, |
| 51 | 51 | .skip_body = false, |
| 52 | 52 | }; |
| 53 | writer.writeBody(stream, air.getMainBody()) catch return; | |
| 53 | try writer.writeBody(stream, air.getMainBody()); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | pub fn writeInst( |
| ... | ... | @@ -73,15 +73,23 @@ pub fn writeInst( |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 76 | const stderr_bw, _ = std.debug.lockStderrWriter(&.{}); | |
| 77 | defer std.debug.unlockStderrWriter(); | |
| 78 | air.write(stderr_bw, pt, liveness); | |
| 76 | const comp = pt.zcu.comp; | |
| 77 | const io = comp.io; | |
| 78 | var buffer: [512]u8 = undefined; | |
| 79 | const stderr = try io.lockStderrWriter(&buffer); | |
| 80 | defer io.unlockStderrWriter(); | |
| 81 | const w = &stderr.interface; | |
| 82 | air.write(w, pt, liveness); | |
| 79 | 83 | } |
| 80 | 84 | |
| 81 | 85 | pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { |
| 82 | const stderr_bw, _ = std.debug.lockStderrWriter(&.{}); | |
| 83 | defer std.debug.unlockStderrWriter(); | |
| 84 | air.writeInst(stderr_bw, inst, pt, liveness); | |
| 86 | const comp = pt.zcu.comp; | |
| 87 | const io = comp.io; | |
| 88 | var buffer: [512]u8 = undefined; | |
| 89 | const stderr = try io.lockStderrWriter(&buffer); | |
| 90 | defer io.unlockStderrWriter(); | |
| 91 | const w = &stderr.interface; | |
| 92 | air.writeInst(w, inst, pt, liveness); | |
| 85 | 93 | } |
| 86 | 94 | |
| 87 | 95 | const Writer = struct { |
src/Compilation.zig+30-23| ... | ... | @@ -2088,12 +2088,13 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2088 | 2088 | |
| 2089 | 2089 | if (options.verbose_llvm_cpu_features) { |
| 2090 | 2090 | if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: { |
| 2091 | const stderr_w, _ = std.debug.lockStderrWriter(&.{}); | |
| 2092 | defer std.debug.unlockStderrWriter(); | |
| 2093 | stderr_w.print("compilation: {s}\n", .{options.root_name}) catch break :print; | |
| 2094 | stderr_w.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print; | |
| 2095 | stderr_w.print(" cpu: {s}\n", .{target.cpu.model.name}) catch break :print; | |
| 2096 | stderr_w.print(" features: {s}\n", .{cf}) catch {}; | |
| 2091 | const stderr = try io.lockStderrWriter(&.{}); | |
| 2092 | defer io.unlockStderrWriter(); | |
| 2093 | const w = &stderr.interface; | |
| 2094 | w.print("compilation: {s}\n", .{options.root_name}) catch break :print; | |
| 2095 | w.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print; | |
| 2096 | w.print(" cpu: {s}\n", .{target.cpu.model.name}) catch break :print; | |
| 2097 | w.print(" features: {s}\n", .{cf}) catch {}; | |
| 2097 | 2098 | } |
| 2098 | 2099 | } |
| 2099 | 2100 | |
| ... | ... | @@ -4257,12 +4258,13 @@ pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle { |
| 4257 | 4258 | // However, we haven't reported any such error. |
| 4258 | 4259 | // This is a compiler bug. |
| 4259 | 4260 | print_ctx: { |
| 4260 | var stderr_w, _ = std.debug.lockStderrWriter(&.{}); | |
| 4261 | defer std.debug.unlockStderrWriter(); | |
| 4262 | stderr_w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx; | |
| 4263 | stderr_w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx; | |
| 4261 | const stderr = try io.lockStderrWriter(&.{}); | |
| 4262 | defer io.unlockStderrWriter(); | |
| 4263 | const w = &stderr.interface; | |
| 4264 | 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; | |
| 4264 | 4266 | while (ref) |r| { |
| 4265 | stderr_w.print("referenced by: {f}{s}\n", .{ | |
| 4267 | w.print("referenced by: {f}{s}\n", .{ | |
| 4266 | 4268 | zcu.fmtAnalUnit(r.referencer), |
| 4267 | 4269 | if (zcu.transitive_failed_analysis.contains(r.referencer)) " [transitive failure]" else "", |
| 4268 | 4270 | }) catch break :print_ctx; |
| ... | ... | @@ -5756,7 +5758,7 @@ pub fn translateC( |
| 5756 | 5758 | try argv.appendSlice(comp.global_cc_argv); |
| 5757 | 5759 | try argv.appendSlice(owner_mod.cc_argv); |
| 5758 | 5760 | try argv.appendSlice(&.{ source_path, "-o", translated_path }); |
| 5759 | if (comp.verbose_cimport) dump_argv(argv.items); | |
| 5761 | if (comp.verbose_cimport) dumpArgv(io, argv.items); | |
| 5760 | 5762 | } |
| 5761 | 5763 | |
| 5762 | 5764 | var stdout: []u8 = undefined; |
| ... | ... | @@ -6264,7 +6266,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr |
| 6264 | 6266 | } |
| 6265 | 6267 | |
| 6266 | 6268 | if (comp.verbose_cc) { |
| 6267 | dump_argv(argv.items); | |
| 6269 | dumpArgv(io, argv.items); | |
| 6268 | 6270 | } |
| 6269 | 6271 | |
| 6270 | 6272 | const err = std.process.execv(arena, argv.items); |
| ... | ... | @@ -6310,7 +6312,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr |
| 6310 | 6312 | } |
| 6311 | 6313 | |
| 6312 | 6314 | if (comp.verbose_cc) { |
| 6313 | dump_argv(argv.items); | |
| 6315 | dumpArgv(io, argv.items); | |
| 6314 | 6316 | } |
| 6315 | 6317 | |
| 6316 | 6318 | // Just to save disk space, we delete the files that are never needed again. |
| ... | ... | @@ -7773,17 +7775,22 @@ pub fn lockAndSetMiscFailure( |
| 7773 | 7775 | return setMiscFailure(comp, tag, format, args); |
| 7774 | 7776 | } |
| 7775 | 7777 | |
| 7776 | pub fn dump_argv(argv: []const []const u8) void { | |
| 7778 | pub fn dumpArgv(io: Io, argv: []const []const u8) Io.Cancelable!void { | |
| 7777 | 7779 | var buffer: [64]u8 = undefined; |
| 7778 | const stderr, _ = std.debug.lockStderrWriter(&buffer); | |
| 7779 | defer std.debug.unlockStderrWriter(); | |
| 7780 | nosuspend { | |
| 7781 | for (argv, 0..) |arg, i| { | |
| 7782 | if (i != 0) stderr.writeByte(' ') catch return; | |
| 7783 | stderr.writeAll(arg) catch return; | |
| 7784 | } | |
| 7785 | stderr.writeByte('\n') catch return; | |
| 7780 | const stderr = try io.lockStderrWriter(&buffer); | |
| 7781 | defer io.unlockStderrWriter(); | |
| 7782 | const w = &stderr.interface; | |
| 7783 | return dumpArgvWriter(w, argv) catch |err| switch (err) { | |
| 7784 | error.WriteFailed => return stderr.err.?, | |
| 7785 | }; | |
| 7786 | } | |
| 7787 | ||
| 7788 | fn dumpArgvWriter(w: *Io.Writer, argv: []const []const u8) Io.Writer.Error!void { | |
| 7789 | for (argv, 0..) |arg, i| { | |
| 7790 | if (i != 0) try w.writeByte(' '); | |
| 7791 | try w.writeAll(arg); | |
| 7786 | 7792 | } |
| 7793 | try w.writeByte('\n'); | |
| 7787 | 7794 | } |
| 7788 | 7795 | |
| 7789 | 7796 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
src/InternPool.zig+32-31| ... | ... | @@ -1,8 +1,11 @@ |
| 1 | 1 | //! All interned objects have both a value and a type. |
| 2 | 2 | //! This data structure is self-contained. |
| 3 | const InternPool = @This(); | |
| 3 | 4 | |
| 4 | 5 | const builtin = @import("builtin"); |
| 6 | ||
| 5 | 7 | const std = @import("std"); |
| 8 | const Io = std.Io; | |
| 6 | 9 | const Allocator = std.mem.Allocator; |
| 7 | 10 | const assert = std.debug.assert; |
| 8 | 11 | const BigIntConst = std.math.big.int.Const; |
| ... | ... | @@ -11,10 +14,9 @@ const Cache = std.Build.Cache; |
| 11 | 14 | const Io = std.Io; |
| 12 | 15 | const Limb = std.math.big.Limb; |
| 13 | 16 | const Hash = std.hash.Wyhash; |
| 17 | const Zir = std.zig.Zir; | |
| 14 | 18 | |
| 15 | const InternPool = @This(); | |
| 16 | 19 | const Zcu = @import("Zcu.zig"); |
| 17 | const Zir = std.zig.Zir; | |
| 18 | 20 | |
| 19 | 21 | /// One item per thread, indexed by `tid`, which is dense and unique per thread. |
| 20 | 22 | locals: []Local, |
| ... | ... | @@ -11165,12 +11167,16 @@ pub fn mutateVarInit(ip: *InternPool, io: Io, index: Index, init_index: Index) v |
| 11165 | 11167 | @atomicStore(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.Variable, "init").?], @intFromEnum(init_index), .release); |
| 11166 | 11168 | } |
| 11167 | 11169 | |
| 11168 | pub fn dump(ip: *const InternPool) void { | |
| 11169 | dumpStatsFallible(ip, std.heap.page_allocator) catch return; | |
| 11170 | dumpAllFallible(ip) catch return; | |
| 11170 | pub fn dump(ip: *const InternPool, io: Io) Io.Cancelable!void { | |
| 11171 | var buffer: [4096]u8 = undefined; | |
| 11172 | const stderr_writer = try io.lockStderrWriter(&buffer); | |
| 11173 | defer io.unlockStderrWriter(); | |
| 11174 | const w = &stderr_writer.interface; | |
| 11175 | try dumpStatsFallible(ip, w, std.heap.page_allocator); | |
| 11176 | try dumpAllFallible(ip, w); | |
| 11171 | 11177 | } |
| 11172 | 11178 | |
| 11173 | fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { | |
| 11179 | fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) anyerror!void { | |
| 11174 | 11180 | var items_len: usize = 0; |
| 11175 | 11181 | var extra_len: usize = 0; |
| 11176 | 11182 | var limbs_len: usize = 0; |
| ... | ... | @@ -11423,18 +11429,13 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 11423 | 11429 | }; |
| 11424 | 11430 | counts.sort(SortContext{ .map = &counts }); |
| 11425 | 11431 | const len = @min(50, counts.count()); |
| 11426 | std.debug.print(" top 50 tags:\n", .{}); | |
| 11432 | w.print(" top 50 tags:\n", .{}); | |
| 11427 | 11433 | for (counts.keys()[0..len], counts.values()[0..len]) |tag, stats| { |
| 11428 | std.debug.print(" {s}: {d} occurrences, {d} total bytes\n", .{ | |
| 11429 | @tagName(tag), stats.count, stats.bytes, | |
| 11430 | }); | |
| 11434 | w.print(" {t}: {d} occurrences, {d} total bytes\n", .{ tag, stats.count, stats.bytes }); | |
| 11431 | 11435 | } |
| 11432 | 11436 | } |
| 11433 | 11437 | |
| 11434 | fn dumpAllFallible(ip: *const InternPool) anyerror!void { | |
| 11435 | var buffer: [4096]u8 = undefined; | |
| 11436 | const stderr_bw, _ = std.debug.lockStderrWriter(&buffer); | |
| 11437 | defer std.debug.unlockStderrWriter(); | |
| 11438 | fn dumpAllFallible(ip: *const InternPool, w: *Io.Writer) anyerror!void { | |
| 11438 | 11439 | for (ip.locals, 0..) |*local, tid| { |
| 11439 | 11440 | const items = local.shared.items.view(); |
| 11440 | 11441 | for ( |
| ... | ... | @@ -11443,12 +11444,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 11443 | 11444 | 0.., |
| 11444 | 11445 | ) |tag, data, index| { |
| 11445 | 11446 | const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip); |
| 11446 | try stderr_bw.print("${d} = {s}(", .{ i, @tagName(tag) }); | |
| 11447 | try w.print("${d} = {s}(", .{ i, @tagName(tag) }); | |
| 11447 | 11448 | switch (tag) { |
| 11448 | 11449 | .removed => {}, |
| 11449 | 11450 | |
| 11450 | .simple_type => try stderr_bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}), | |
| 11451 | .simple_value => try stderr_bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}), | |
| 11451 | .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}), | |
| 11452 | .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}), | |
| 11452 | 11453 | |
| 11453 | 11454 | .type_int_signed, |
| 11454 | 11455 | .type_int_unsigned, |
| ... | ... | @@ -11521,23 +11522,27 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 11521 | 11522 | .func_coerced, |
| 11522 | 11523 | .union_value, |
| 11523 | 11524 | .memoized_call, |
| 11524 | => try stderr_bw.print("{d}", .{data}), | |
| 11525 | => try w.print("{d}", .{data}), | |
| 11525 | 11526 | |
| 11526 | 11527 | .opt_null, |
| 11527 | 11528 | .type_slice, |
| 11528 | 11529 | .only_possible_value, |
| 11529 | => try stderr_bw.print("${d}", .{data}), | |
| 11530 | => try w.print("${d}", .{data}), | |
| 11530 | 11531 | } |
| 11531 | try stderr_bw.writeAll(")\n"); | |
| 11532 | try w.writeAll(")\n"); | |
| 11532 | 11533 | } |
| 11533 | 11534 | } |
| 11534 | 11535 | } |
| 11535 | 11536 | |
| 11536 | pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void { | |
| 11537 | ip.dumpGenericInstancesFallible(allocator) catch return; | |
| 11537 | pub fn dumpGenericInstances(ip: *const InternPool, io: Io, allocator: Allocator) Io.Cancelable!void { | |
| 11538 | var buffer: [4096]u8 = undefined; | |
| 11539 | const stderr_writer = try io.lockStderrWriter(&buffer); | |
| 11540 | defer io.unlockStderrWriter(); | |
| 11541 | const w = &stderr_writer.interface; | |
| 11542 | try ip.dumpGenericInstancesFallible(allocator, w); | |
| 11538 | 11543 | } |
| 11539 | 11544 | |
| 11540 | pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) anyerror!void { | |
| 11545 | pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator, w: *Io.Writer) !void { | |
| 11541 | 11546 | var arena_allocator = std.heap.ArenaAllocator.init(allocator); |
| 11542 | 11547 | defer arena_allocator.deinit(); |
| 11543 | 11548 | const arena = arena_allocator.allocator(); |
| ... | ... | @@ -11564,10 +11569,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 11564 | 11569 | } |
| 11565 | 11570 | } |
| 11566 | 11571 | |
| 11567 | var buffer: [4096]u8 = undefined; | |
| 11568 | const stderr_bw, _ = std.debug.lockStderrWriter(&buffer); | |
| 11569 | defer std.debug.unlockStderrWriter(); | |
| 11570 | ||
| 11571 | 11572 | const SortContext = struct { |
| 11572 | 11573 | values: []std.ArrayList(Index), |
| 11573 | 11574 | pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { |
| ... | ... | @@ -11579,19 +11580,19 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 11579 | 11580 | var it = instances.iterator(); |
| 11580 | 11581 | while (it.next()) |entry| { |
| 11581 | 11582 | const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav); |
| 11582 | try stderr_bw.print("{f} ({d}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len }); | |
| 11583 | try w.print("{f} ({d}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len }); | |
| 11583 | 11584 | for (entry.value_ptr.items) |index| { |
| 11584 | 11585 | const unwrapped_index = index.unwrap(ip); |
| 11585 | 11586 | const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip)); |
| 11586 | 11587 | const owner_nav = ip.getNav(func.owner_nav); |
| 11587 | try stderr_bw.print(" {f}: (", .{owner_nav.name.fmt(ip)}); | |
| 11588 | try w.print(" {f}: (", .{owner_nav.name.fmt(ip)}); | |
| 11588 | 11589 | for (func.comptime_args.get(ip)) |arg| { |
| 11589 | 11590 | if (arg != .none) { |
| 11590 | 11591 | const key = ip.indexToKey(arg); |
| 11591 | try stderr_bw.print(" {} ", .{key}); | |
| 11592 | try w.print(" {} ", .{key}); | |
| 11592 | 11593 | } |
| 11593 | 11594 | } |
| 11594 | try stderr_bw.writeAll(")\n"); | |
| 11595 | try w.writeAll(")\n"); | |
| 11595 | 11596 | } |
| 11596 | 11597 | } |
| 11597 | 11598 | } |
src/Sema.zig+5-3| ... | ... | @@ -2668,16 +2668,18 @@ fn failWithTypeMismatch(sema: *Sema, block: *Block, src: LazySrcLoc, expected: T |
| 2668 | 2668 | |
| 2669 | 2669 | pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } { |
| 2670 | 2670 | @branchHint(.cold); |
| 2671 | const gpa = sema.gpa; | |
| 2672 | 2671 | const zcu = sema.pt.zcu; |
| 2672 | const comp = zcu.comp; | |
| 2673 | const gpa = comp.gpa; | |
| 2674 | const io = comp.io; | |
| 2673 | 2675 | |
| 2674 | if (build_options.enable_debug_extensions and zcu.comp.debug_compile_errors) { | |
| 2676 | if (build_options.enable_debug_extensions and comp.debug_compile_errors) { | |
| 2675 | 2677 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 2676 | 2678 | wip_errors.init(gpa) catch @panic("out of memory"); |
| 2677 | 2679 | Compilation.addModuleErrorMsg(zcu, &wip_errors, err_msg.*, false) catch @panic("out of memory"); |
| 2678 | 2680 | std.debug.print("compile error during Sema:\n", .{}); |
| 2679 | 2681 | var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory"); |
| 2680 | error_bundle.renderToStdErr(.{}, .auto); | |
| 2682 | error_bundle.renderToStderr(io, .{}, .auto); | |
| 2681 | 2683 | std.debug.panicExtra(@returnAddress(), "unexpected compile error occurred", .{}); |
| 2682 | 2684 | } |
| 2683 | 2685 |
src/Zcu/PerThread.zig+3-2| ... | ... | @@ -4556,8 +4556,9 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e |
| 4556 | 4556 | defer if (liveness) |*l| l.deinit(gpa); |
| 4557 | 4557 | |
| 4558 | 4558 | if (build_options.enable_debug_extensions and comp.verbose_air) { |
| 4559 | const stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 4560 | defer std.debug.unlockStderrWriter(); | |
| 4559 | const io = comp.io; | |
| 4560 | const stderr = try io.lockStderrWriter(&.{}); | |
| 4561 | defer io.unlockStderrWriter(); | |
| 4561 | 4562 | stderr.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}) catch {}; |
| 4562 | 4563 | air.write(stderr, pt, liveness); |
| 4563 | 4564 | stderr.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}) catch {}; |
src/codegen/aarch64/Select.zig+7-4| ... | ... | @@ -11273,15 +11273,18 @@ fn initValueAdvanced( |
| 11273 | 11273 | return @enumFromInt(isel.values.items.len); |
| 11274 | 11274 | } |
| 11275 | 11275 | pub fn dumpValues(isel: *Select, which: enum { only_referenced, all }) void { |
| 11276 | errdefer |err| @panic(@errorName(err)); | |
| 11277 | const stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 11278 | defer std.debug.unlockStderrWriter(); | |
| 11279 | ||
| 11280 | 11276 | const zcu = isel.pt.zcu; |
| 11277 | const io = zcu.comp.io; | |
| 11281 | 11278 | const gpa = zcu.gpa; |
| 11282 | 11279 | const ip = &zcu.intern_pool; |
| 11283 | 11280 | const nav = ip.getNav(isel.nav_index); |
| 11284 | 11281 | |
| 11282 | errdefer |err| @panic(@errorName(err)); | |
| 11283 | ||
| 11284 | const stderr_writer = io.lockStderrWriter(&.{}) catch return; | |
| 11285 | defer io.unlockStderrWriter(); | |
| 11286 | const stderr = &stderr_writer.interface; | |
| 11287 | ||
| 11285 | 11288 | var reverse_live_values: std.AutoArrayHashMapUnmanaged(Value.Index, std.ArrayList(Air.Inst.Index)) = .empty; |
| 11286 | 11289 | defer { |
| 11287 | 11290 | for (reverse_live_values.values()) |*list| list.deinit(gpa); |
src/crash_report.zig+5-4| ... | ... | @@ -97,17 +97,18 @@ fn dumpCrashContext() Io.Writer.Error!void { |
| 97 | 97 | // and the actual panic printing, which would be quite confusing. |
| 98 | 98 | const stderr = std.debug.lockStderrWriter(&.{}); |
| 99 | 99 | defer std.debug.unlockStderrWriter(); |
| 100 | const w = &stderr.interface; | |
| 100 | 101 | |
| 101 | try stderr.interface.writeAll("Compiler crash context:\n"); | |
| 102 | try w.writeAll("Compiler crash context:\n"); | |
| 102 | 103 | |
| 103 | 104 | if (CodegenFunc.current) |*cg| { |
| 104 | 105 | const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav; |
| 105 | 106 | const func_fqn = cg.zcu.intern_pool.getNav(func_nav).fqn; |
| 106 | try stderr.interface.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)}); | |
| 107 | try w.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)}); | |
| 107 | 108 | } else if (AnalyzeBody.current) |anal| { |
| 108 | try dumpCrashContextSema(anal, &stderr.interface, &S.crash_heap); | |
| 109 | try dumpCrashContextSema(anal, w, &S.crash_heap); | |
| 109 | 110 | } else { |
| 110 | try stderr.interface.writeAll("(no context)\n\n"); | |
| 111 | try w.writeAll("(no context)\n\n"); | |
| 111 | 112 | } |
| 112 | 113 | } |
| 113 | 114 | fn dumpCrashContextSema(anal: *AnalyzeBody, stderr: *Io.Writer, crash_heap: []u8) Io.Writer.Error!void { |
src/fmt.zig+4-4| ... | ... | @@ -124,7 +124,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 124 | 124 | try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>"); |
| 125 | 125 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 126 | 126 | defer error_bundle.deinit(gpa); |
| 127 | error_bundle.renderToStdErr(.{}, color); | |
| 127 | error_bundle.renderToStderr(io, .{}, color); | |
| 128 | 128 | process.exit(2); |
| 129 | 129 | } |
| 130 | 130 | } else { |
| ... | ... | @@ -138,7 +138,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) ! |
| 138 | 138 | try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>"); |
| 139 | 139 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 140 | 140 | defer error_bundle.deinit(gpa); |
| 141 | error_bundle.renderToStdErr(.{}, color); | |
| 141 | error_bundle.renderToStderr(io, .{}, color); | |
| 142 | 142 | process.exit(2); |
| 143 | 143 | } |
| 144 | 144 | } |
| ... | ... | @@ -319,7 +319,7 @@ fn fmtPathFile( |
| 319 | 319 | try wip_errors.addZirErrorMessages(zir, tree, source_code, file_path); |
| 320 | 320 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 321 | 321 | defer error_bundle.deinit(gpa); |
| 322 | error_bundle.renderToStdErr(.{}, fmt.color); | |
| 322 | error_bundle.renderToStderr(io, .{}, fmt.color); | |
| 323 | 323 | fmt.any_error = true; |
| 324 | 324 | } |
| 325 | 325 | }, |
| ... | ... | @@ -334,7 +334,7 @@ fn fmtPathFile( |
| 334 | 334 | try wip_errors.addZoirErrorMessages(zoir, tree, source_code, file_path); |
| 335 | 335 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 336 | 336 | defer error_bundle.deinit(gpa); |
| 337 | error_bundle.renderToStdErr(.{}, fmt.color); | |
| 337 | error_bundle.renderToStderr(io, .{}, fmt.color); | |
| 338 | 338 | fmt.any_error = true; |
| 339 | 339 | } |
| 340 | 340 | }, |
src/libs/mingw.zig+19-10| ... | ... | @@ -312,11 +312,17 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 312 | 312 | |
| 313 | 313 | const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" }); |
| 314 | 314 | |
| 315 | if (comp.verbose_cc) print: { | |
| 316 | var stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 317 | defer std.debug.unlockStderrWriter(); | |
| 318 | nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print; | |
| 319 | nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print; | |
| 315 | if (comp.verbose_cc) { | |
| 316 | var buffer: [256]u8 = undefined; | |
| 317 | const stderr = try io.lockStderrWriter(&buffer); | |
| 318 | defer io.unlockStderrWriter(); | |
| 319 | const w = &stderr.interface; | |
| 320 | w.print("def file: {s}\n", .{def_file_path}) catch |err| switch (err) { | |
| 321 | error.WriteFailed => return stderr.err.?, | |
| 322 | }; | |
| 323 | w.print("include dir: {s}\n", .{include_dir}) catch |err| switch (err) { | |
| 324 | error.WriteFailed => return stderr.err.?, | |
| 325 | }; | |
| 320 | 326 | } |
| 321 | 327 | |
| 322 | 328 | try aro_comp.search_path.append(gpa, .{ .path = include_dir, .kind = .normal }); |
| ... | ... | @@ -333,11 +339,13 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 333 | 339 | |
| 334 | 340 | if (aro_comp.diagnostics.output.to_list.messages.items.len != 0) { |
| 335 | 341 | var buffer: [64]u8 = undefined; |
| 336 | const w, const ttyconf = std.debug.lockStderrWriter(&buffer); | |
| 337 | defer std.debug.unlockStderrWriter(); | |
| 342 | const stderr = try io.lockStderrWriter(&buffer); | |
| 343 | defer io.unlockStderrWriter(); | |
| 338 | 344 | for (aro_comp.diagnostics.output.to_list.messages.items) |msg| { |
| 339 | 345 | if (msg.kind == .@"fatal error" or msg.kind == .@"error") { |
| 340 | msg.write(w, ttyconf, true) catch {}; | |
| 346 | msg.write(&stderr.interface, stderr.mode, true) catch |err| switch (err) { | |
| 347 | error.WriteFailed => return stderr.err.?, | |
| 348 | }; | |
| 341 | 349 | return error.AroPreprocessorFailed; |
| 342 | 350 | } |
| 343 | 351 | } |
| ... | ... | @@ -357,8 +365,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 357 | 365 | error.OutOfMemory => |e| return e, |
| 358 | 366 | error.ParseError => { |
| 359 | 367 | var buffer: [64]u8 = undefined; |
| 360 | const w, _ = std.debug.lockStderrWriter(&buffer); | |
| 361 | defer std.debug.unlockStderrWriter(); | |
| 368 | const stderr = try io.lockStderrWriter(&buffer); | |
| 369 | defer io.unlockStderrWriter(); | |
| 370 | const w = &stderr.interface; | |
| 362 | 371 | try w.writeAll("error: "); |
| 363 | 372 | try def_diagnostics.writeMsg(w, input); |
| 364 | 373 | try w.writeByte('\n'); |
src/libs/mingw/def.zig+22-10| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const Io = std.Io; | |
| 2 | 3 | |
| 3 | 4 | pub const ModuleDefinitionType = enum { |
| 4 | 5 | mingw, |
| ... | ... | @@ -663,7 +664,9 @@ test parse { |
| 663 | 664 | \\ |
| 664 | 665 | ; |
| 665 | 666 | |
| 666 | try testParse(.AMD64, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 667 | const io = std.testing.io; | |
| 668 | ||
| 669 | try testParse(io, .AMD64, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 667 | 670 | .{ |
| 668 | 671 | .name = "foo", |
| 669 | 672 | .mangled_symbol_name = null, |
| ... | ... | @@ -743,7 +746,7 @@ test parse { |
| 743 | 746 | }, |
| 744 | 747 | }); |
| 745 | 748 | |
| 746 | try testParse(.I386, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 749 | try testParse(io, .I386, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 747 | 750 | .{ |
| 748 | 751 | .name = "_foo", |
| 749 | 752 | .mangled_symbol_name = null, |
| ... | ... | @@ -823,7 +826,7 @@ test parse { |
| 823 | 826 | }, |
| 824 | 827 | }); |
| 825 | 828 | |
| 826 | try testParse(.ARMNT, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 829 | try testParse(io, .ARMNT, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 827 | 830 | .{ |
| 828 | 831 | .name = "foo", |
| 829 | 832 | .mangled_symbol_name = null, |
| ... | ... | @@ -903,7 +906,7 @@ test parse { |
| 903 | 906 | }, |
| 904 | 907 | }); |
| 905 | 908 | |
| 906 | try testParse(.ARM64, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 909 | try testParse(io, .ARM64, source, "foo.dll", &[_]ModuleDefinition.Export{ | |
| 907 | 910 | .{ |
| 908 | 911 | .name = "foo", |
| 909 | 912 | .mangled_symbol_name = null, |
| ... | ... | @@ -997,7 +1000,9 @@ test "ntdll" { |
| 997 | 1000 | \\RtlActivateActivationContextUnsafeFast@0 |
| 998 | 1001 | ; |
| 999 | 1002 | |
| 1000 | try testParse(.AMD64, source, "ntdll.dll", &[_]ModuleDefinition.Export{ | |
| 1003 | const io = std.testing.io; | |
| 1004 | ||
| 1005 | try testParse(io, .AMD64, source, "ntdll.dll", &[_]ModuleDefinition.Export{ | |
| 1001 | 1006 | .{ |
| 1002 | 1007 | .name = "RtlDispatchAPC@12", |
| 1003 | 1008 | .mangled_symbol_name = null, |
| ... | ... | @@ -1023,15 +1028,22 @@ test "ntdll" { |
| 1023 | 1028 | }); |
| 1024 | 1029 | } |
| 1025 | 1030 | |
| 1026 | fn testParse(machine_type: std.coff.IMAGE.FILE.MACHINE, source: [:0]const u8, expected_module_name: []const u8, expected_exports: []const ModuleDefinition.Export) !void { | |
| 1031 | fn testParse( | |
| 1032 | io: Io, | |
| 1033 | machine_type: std.coff.IMAGE.FILE.MACHINE, | |
| 1034 | source: [:0]const u8, | |
| 1035 | expected_module_name: []const u8, | |
| 1036 | expected_exports: []const ModuleDefinition.Export, | |
| 1037 | ) !void { | |
| 1027 | 1038 | var diagnostics: Diagnostics = undefined; |
| 1028 | 1039 | const module = parse(std.testing.allocator, source, machine_type, .mingw, &diagnostics) catch |err| switch (err) { |
| 1029 | 1040 | error.OutOfMemory => |e| return e, |
| 1030 | 1041 | error.ParseError => { |
| 1031 | const stderr, _ = std.debug.lockStderrWriter(&.{}); | |
| 1032 | defer std.debug.unlockStderrWriter(); | |
| 1033 | try diagnostics.writeMsg(stderr, source); | |
| 1034 | try stderr.writeByte('\n'); | |
| 1042 | const stderr = try io.lockStderrWriter(&.{}); | |
| 1043 | defer io.unlockStderrWriter(); | |
| 1044 | const w = &stderr.interface; | |
| 1045 | try diagnostics.writeMsg(w, source); | |
| 1046 | try w.writeByte('\n'); | |
| 1035 | 1047 | return err; |
| 1036 | 1048 | }, |
| 1037 | 1049 | }; |
src/link.zig+1-1| ... | ... | @@ -2246,7 +2246,7 @@ fn resolvePathInputLib( |
| 2246 | 2246 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 2247 | 2247 | defer error_bundle.deinit(gpa); |
| 2248 | 2248 | |
| 2249 | error_bundle.renderToStdErr(.{}, color); | |
| 2249 | error_bundle.renderToStderr(io, .{}, color); | |
| 2250 | 2250 | |
| 2251 | 2251 | std.process.exit(1); |
| 2252 | 2252 | } |
src/link/Coff.zig+11-4| ... | ... | @@ -4,6 +4,7 @@ const builtin = @import("builtin"); |
| 4 | 4 | const native_endian = builtin.cpu.arch.endian(); |
| 5 | 5 | |
| 6 | 6 | const std = @import("std"); |
| 7 | const Io = std.Io; | |
| 7 | 8 | const assert = std.debug.assert; |
| 8 | 9 | const log = std.log.scoped(.link); |
| 9 | 10 | |
| ... | ... | @@ -2377,10 +2378,16 @@ pub fn deleteExport(coff: *Coff, exported: Zcu.Exported, name: InternPool.NullTe |
| 2377 | 2378 | _ = name; |
| 2378 | 2379 | } |
| 2379 | 2380 | |
| 2380 | pub fn dump(coff: *Coff, tid: Zcu.PerThread.Id) void { | |
| 2381 | const w, _ = std.debug.lockStderrWriter(&.{}); | |
| 2382 | defer std.debug.unlockStderrWriter(); | |
| 2383 | coff.printNode(tid, w, .root, 0) catch {}; | |
| 2381 | pub fn dump(coff: *Coff, tid: Zcu.PerThread.Id) Io.Cancelable!void { | |
| 2382 | const comp = coff.base.comp; | |
| 2383 | const io = comp.io; | |
| 2384 | var buffer: [512]u8 = undefined; | |
| 2385 | const stderr = try io.lockStderrWriter(&buffer); | |
| 2386 | defer io.unlockStderrWriter(); | |
| 2387 | const w = &stderr.interface; | |
| 2388 | coff.printNode(tid, w, .root, 0) catch |err| switch (err) { | |
| 2389 | error.WriteFailed => return stderr.err.?, | |
| 2390 | }; | |
| 2384 | 2391 | } |
| 2385 | 2392 | |
| 2386 | 2393 | pub fn printNode( |
src/link/Elf2.zig+10-4| ... | ... | @@ -3729,10 +3729,16 @@ pub fn deleteExport(elf: *Elf, exported: Zcu.Exported, name: InternPool.NullTerm |
| 3729 | 3729 | _ = name; |
| 3730 | 3730 | } |
| 3731 | 3731 | |
| 3732 | pub fn dump(elf: *Elf, tid: Zcu.PerThread.Id) void { | |
| 3733 | const w, _ = std.debug.lockStderrWriter(&.{}); | |
| 3734 | defer std.debug.unlockStderrWriter(); | |
| 3735 | elf.printNode(tid, w, .root, 0) catch {}; | |
| 3732 | pub fn dump(elf: *Elf, tid: Zcu.PerThread.Id) Io.Cancelable!void { | |
| 3733 | const comp = elf.base.comp; | |
| 3734 | const io = comp.io; | |
| 3735 | var buffer: [512]u8 = undefined; | |
| 3736 | const stderr = try io.lockStderrWriter(&buffer); | |
| 3737 | defer io.unlockStderrWriter(); | |
| 3738 | const w = &stderr.interface; | |
| 3739 | elf.printNode(tid, w, .root, 0) catch |err| switch (err) { | |
| 3740 | error.WriteFailed => return stderr.err.?, | |
| 3741 | }; | |
| 3736 | 3742 | } |
| 3737 | 3743 | |
| 3738 | 3744 | pub fn printNode( |
src/main.zig+17-16| ... | ... | @@ -4429,9 +4429,9 @@ fn runOrTest( |
| 4429 | 4429 | // the error message and invocation below. |
| 4430 | 4430 | if (process.can_execv and arg_mode == .run) { |
| 4431 | 4431 | // execv releases the locks; no need to destroy the Compilation here. |
| 4432 | _ = std.debug.lockStderrWriter(&.{}); | |
| 4432 | _ = try io.lockStderrWriter(&.{}); | |
| 4433 | 4433 | const err = process.execve(gpa, argv.items, &env_map); |
| 4434 | std.debug.unlockStderrWriter(); | |
| 4434 | io.unlockStderrWriter(); | |
| 4435 | 4435 | try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc); |
| 4436 | 4436 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 4437 | 4437 | fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd }); |
| ... | ... | @@ -4448,8 +4448,8 @@ fn runOrTest( |
| 4448 | 4448 | comp_destroyed.* = true; |
| 4449 | 4449 | |
| 4450 | 4450 | const term_result = t: { |
| 4451 | _ = std.debug.lockStderrWriter(); | |
| 4452 | defer std.debug.unlockStderrWriter(); | |
| 4451 | _ = try io.lockStderrWriter(&.{}); | |
| 4452 | defer io.unlockStderrWriter(); | |
| 4453 | 4453 | break :t child.spawnAndWait(io); |
| 4454 | 4454 | }; |
| 4455 | 4455 | const term = term_result catch |err| { |
| ... | ... | @@ -4606,7 +4606,8 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node) |
| 4606 | 4606 | defer errors.deinit(comp.gpa); |
| 4607 | 4607 | |
| 4608 | 4608 | if (errors.errorMessageCount() > 0) { |
| 4609 | errors.renderToStdErr(.{}, color); | |
| 4609 | const io = comp.io; | |
| 4610 | errors.renderToStderr(io, .{}, color); | |
| 4610 | 4611 | return error.CompileErrorsReported; |
| 4611 | 4612 | } |
| 4612 | 4613 | } |
| ... | ... | @@ -4659,7 +4660,7 @@ fn cmdTranslateC( |
| 4659 | 4660 | return; |
| 4660 | 4661 | } else { |
| 4661 | 4662 | const color: Color = .auto; |
| 4662 | result.errors.renderToStdErr(.{}, color); | |
| 4663 | result.errors.renderToStderr(io, .{}, color); | |
| 4663 | 4664 | process.exit(1); |
| 4664 | 4665 | } |
| 4665 | 4666 | } |
| ... | ... | @@ -5280,7 +5281,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5280 | 5281 | |
| 5281 | 5282 | if (fetch.error_bundle.root_list.items.len > 0) { |
| 5282 | 5283 | var errors = try fetch.error_bundle.toOwnedBundle(""); |
| 5283 | errors.renderToStdErr(.{}, color); | |
| 5284 | errors.renderToStderr(io, .{}, color); | |
| 5284 | 5285 | process.exit(1); |
| 5285 | 5286 | } |
| 5286 | 5287 | |
| ... | ... | @@ -5412,8 +5413,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5412 | 5413 | child.stderr_behavior = .Inherit; |
| 5413 | 5414 | |
| 5414 | 5415 | const term = t: { |
| 5415 | _ = std.debug.lockStderrWriter(&.{}); | |
| 5416 | defer std.debug.unlockStderrWriter(); | |
| 5416 | _ = try io.lockStderrWriter(&.{}); | |
| 5417 | defer io.unlockStderrWriter(); | |
| 5417 | 5418 | break :t child.spawnAndWait(io) catch |err| |
| 5418 | 5419 | fatal("failed to spawn build runner {s}: {t}", .{ child_argv.items[0], err }); |
| 5419 | 5420 | }; |
| ... | ... | @@ -6212,7 +6213,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6212 | 6213 | try wip_errors.init(arena); |
| 6213 | 6214 | try wip_errors.addZirErrorMessages(zir, tree, source, display_path); |
| 6214 | 6215 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 6215 | error_bundle.renderToStdErr(.{}, color); | |
| 6216 | error_bundle.renderToStderr(io, .{}, color); | |
| 6216 | 6217 | if (zir.loweringFailed()) { |
| 6217 | 6218 | process.exit(1); |
| 6218 | 6219 | } |
| ... | ... | @@ -6283,7 +6284,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6283 | 6284 | try wip_errors.init(arena); |
| 6284 | 6285 | try wip_errors.addZoirErrorMessages(zoir, tree, source, display_path); |
| 6285 | 6286 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 6286 | error_bundle.renderToStdErr(.{}, color); | |
| 6287 | error_bundle.renderToStderr(io, .{}, color); | |
| 6287 | 6288 | process.exit(1); |
| 6288 | 6289 | } |
| 6289 | 6290 | |
| ... | ... | @@ -6557,7 +6558,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6557 | 6558 | try wip_errors.init(arena); |
| 6558 | 6559 | try wip_errors.addZirErrorMessages(old_zir, old_tree, old_source, old_source_path); |
| 6559 | 6560 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 6560 | error_bundle.renderToStdErr(.{}, color); | |
| 6561 | error_bundle.renderToStderr(io, .{}, color); | |
| 6561 | 6562 | process.exit(1); |
| 6562 | 6563 | } |
| 6563 | 6564 | |
| ... | ... | @@ -6569,7 +6570,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void { |
| 6569 | 6570 | try wip_errors.init(arena); |
| 6570 | 6571 | try wip_errors.addZirErrorMessages(new_zir, new_tree, new_source, new_source_path); |
| 6571 | 6572 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 6572 | error_bundle.renderToStdErr(.{}, color); | |
| 6573 | error_bundle.renderToStderr(io, .{}, color); | |
| 6573 | 6574 | process.exit(1); |
| 6574 | 6575 | } |
| 6575 | 6576 | |
| ... | ... | @@ -7005,7 +7006,7 @@ fn cmdFetch( |
| 7005 | 7006 | |
| 7006 | 7007 | if (fetch.error_bundle.root_list.items.len > 0) { |
| 7007 | 7008 | var errors = try fetch.error_bundle.toOwnedBundle(""); |
| 7008 | errors.renderToStdErr(.{}, color); | |
| 7009 | errors.renderToStderr(io, .{}, color); | |
| 7009 | 7010 | process.exit(1); |
| 7010 | 7011 | } |
| 7011 | 7012 | |
| ... | ... | @@ -7345,7 +7346,7 @@ fn loadManifest( |
| 7345 | 7346 | errdefer ast.deinit(gpa); |
| 7346 | 7347 | |
| 7347 | 7348 | if (ast.errors.len > 0) { |
| 7348 | try std.zig.printAstErrorsToStderr(gpa, ast, Package.Manifest.basename, options.color); | |
| 7349 | try std.zig.printAstErrorsToStderr(gpa, io, ast, Package.Manifest.basename, options.color); | |
| 7349 | 7350 | process.exit(2); |
| 7350 | 7351 | } |
| 7351 | 7352 | |
| ... | ... | @@ -7362,7 +7363,7 @@ fn loadManifest( |
| 7362 | 7363 | |
| 7363 | 7364 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| 7364 | 7365 | defer error_bundle.deinit(gpa); |
| 7365 | error_bundle.renderToStdErr(.{}, options.color); | |
| 7366 | error_bundle.renderToStderr(io, .{}, options.color); | |
| 7366 | 7367 | |
| 7367 | 7368 | process.exit(2); |
| 7368 | 7369 | } |