authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-28 06:59:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:51-07:00
log0b3f0124dc33403d329fb8ee63a93215d9af1f1e
tree3a94c321398ab21810b73c55411523d005b503fa
parent7c42517151cf06b67268aec3be715b3e303e014a

std.io: move getStdIn, getStdOut, getStdErr functions to fs.File

preparing to rearrange std.io namespace into an interface how to upgrade: std.io.getStdIn() -> std.fs.File.stdin() std.io.getStdOut() -> std.fs.File.stdout() std.io.getStdErr() -> std.fs.File.stderr()

46 files changed, 175 insertions(+), 222 deletions(-)

lib/compiler/aro/aro/Diagnostics.zig+1-1
......@@ -541,7 +541,7 @@ const MsgWriter = struct {
541541 fn init(config: std.io.tty.Config) MsgWriter {
542542 std.debug.lockStdErr();
543543 return .{
544 .w = std.io.bufferedWriter(std.io.getStdErr().writer()),
544 .w = std.io.bufferedWriter(std.fs.File.stderr().writer()),
545545 .config = config,
546546 };
547547 }
lib/compiler/aro/aro/Driver.zig+7-7
......@@ -519,7 +519,7 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 {
519519
520520fn addSource(d: *Driver, path: []const u8) !Source {
521521 if (mem.eql(u8, "-", path)) {
522 const stdin = std.io.getStdIn().reader();
522 const stdin = std.fs.File.stdin().reader();
523523 const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32));
524524 defer d.comp.gpa.free(input);
525525 return d.comp.addSourceFromBuffer("<stdin>", input);
......@@ -541,7 +541,7 @@ pub fn fatal(d: *Driver, comptime fmt: []const u8, args: anytype) error{ FatalEr
541541}
542542
543543pub fn renderErrors(d: *Driver) void {
544 Diagnostics.render(d.comp, d.detectConfig(std.io.getStdErr()));
544 Diagnostics.render(d.comp, d.detectConfig(std.fs.File.stderr()));
545545}
546546
547547pub fn detectConfig(d: *Driver, file: std.fs.File) std.io.tty.Config {
......@@ -591,7 +591,7 @@ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_
591591 var macro_buf = std.ArrayList(u8).init(d.comp.gpa);
592592 defer macro_buf.deinit();
593593
594 const std_out = std.io.getStdOut().writer();
594 const std_out = std.fs.File.stdout().writer();
595595 if (try parseArgs(d, std_out, macro_buf.writer(), args)) return;
596596
597597 const linking = !(d.only_preprocess or d.only_syntax or d.only_compile or d.only_preprocess_and_compile);
......@@ -686,7 +686,7 @@ fn processSource(
686686 std.fs.cwd().createFile(some, .{}) catch |er|
687687 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
688688 else
689 std.io.getStdOut();
689 std.fs.File.stdout();
690690 defer if (d.output_name != null) file.close();
691691
692692 var buf_w = std.io.bufferedWriter(file.writer());
......@@ -704,7 +704,7 @@ fn processSource(
704704 defer tree.deinit();
705705
706706 if (d.verbose_ast) {
707 const stdout = std.io.getStdOut();
707 const stdout = std.fs.File.stdout();
708708 var buf_writer = std.io.bufferedWriter(stdout.writer());
709709 tree.dump(d.detectConfig(stdout), buf_writer.writer()) catch {};
710710 buf_writer.flush() catch {};
......@@ -734,7 +734,7 @@ fn processSource(
734734 defer ir.deinit(d.comp.gpa);
735735
736736 if (d.verbose_ir) {
737 const stdout = std.io.getStdOut();
737 const stdout = std.fs.File.stdout();
738738 var buf_writer = std.io.bufferedWriter(stdout.writer());
739739 ir.dump(d.comp.gpa, d.detectConfig(stdout), buf_writer.writer()) catch {};
740740 buf_writer.flush() catch {};
......@@ -806,7 +806,7 @@ fn processSource(
806806}
807807
808808fn dumpLinkerArgs(items: []const []const u8) !void {
809 const stdout = std.io.getStdOut().writer();
809 const stdout = std.fs.File.stdout().writer();
810810 for (items, 0..) |item, i| {
811811 if (i > 0) try stdout.writeByte(' ');
812812 try stdout.print("\"{}\"", .{std.zig.fmtEscapes(item)});
lib/compiler/aro/aro/Preprocessor.zig+1-1
......@@ -811,7 +811,7 @@ fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args:
811811 const source = pp.comp.getSource(raw.source);
812812 const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
813813
814 const stderr = std.io.getStdErr().writer();
814 const stderr = std.fs.File.stderr().writer();
815815 var buf_writer = std.io.bufferedWriter(stderr);
816816 const writer = buf_writer.writer();
817817 defer buf_writer.flush() catch {};
lib/compiler/aro_translate_c.zig+2-2
......@@ -1781,7 +1781,7 @@ test "Macro matching" {
17811781fn renderErrorsAndExit(comp: *aro.Compilation) noreturn {
17821782 defer std.process.exit(1);
17831783
1784 var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.io.getStdErr()));
1784 var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.fs.File.stderr()));
17851785 defer writer.deinit(); // writer deinit must run *before* exit so that stderr is flushed
17861786
17871787 var saw_error = false;
......@@ -1824,6 +1824,6 @@ pub fn main() !void {
18241824 defer tree.deinit(gpa);
18251825
18261826 const formatted = try tree.render(arena);
1827 try std.io.getStdOut().writeAll(formatted);
1827 try std.fs.File.stdout().writeAll(formatted);
18281828 return std.process.cleanExit();
18291829}
lib/compiler/build_runner.zig+2-2
......@@ -330,7 +330,7 @@ pub fn main() !void {
330330 }
331331 }
332332
333 const stderr = std.io.getStdErr();
333 const stderr = std.fs.File.stderr();
334334 const ttyconf = get_tty_conf(color, stderr);
335335 switch (ttyconf) {
336336 .no_color => try graph.env_map.put("NO_COLOR", "1"),
......@@ -378,7 +378,7 @@ pub fn main() !void {
378378
379379 validateSystemLibraryOptions(builder);
380380
381 const stdout_writer = io.getStdOut().writer();
381 const stdout_writer = std.fs.File.stdout().writer();
382382
383383 if (help_menu)
384384 return usage(builder, stdout_writer);
lib/compiler/libc.zig+3-3
......@@ -40,7 +40,7 @@ pub fn main() !void {
4040 const arg = args[i];
4141 if (mem.startsWith(u8, arg, "-")) {
4242 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
43 const stdout = std.io.getStdOut().writer();
43 const stdout = std.fs.File.stdout().writer();
4444 try stdout.writeAll(usage_libc);
4545 return std.process.cleanExit();
4646 } else if (mem.eql(u8, arg, "-target")) {
......@@ -97,7 +97,7 @@ pub fn main() !void {
9797 fatal("no include dirs detected for target {s}", .{zig_target});
9898 }
9999
100 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
100 var bw = std.io.bufferedWriter(std.fs.File.stdout().writer());
101101 var writer = bw.writer();
102102 for (libc_dirs.libc_include_dir_list) |include_dir| {
103103 try writer.writeAll(include_dir);
......@@ -125,7 +125,7 @@ pub fn main() !void {
125125 };
126126 defer libc.deinit(gpa);
127127
128 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
128 var bw = std.io.bufferedWriter(std.fs.File.stdout().writer());
129129 try libc.render(bw.writer());
130130 try bw.flush();
131131 }
lib/compiler/objcopy.zig+3-3
......@@ -54,7 +54,7 @@ fn cmdObjCopy(
5454 fatal("unexpected positional argument: '{s}'", .{arg});
5555 }
5656 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
57 return std.io.getStdOut().writeAll(usage);
57 return std.fs.File.stdout().writeAll(usage);
5858 } else if (mem.eql(u8, arg, "-O") or mem.eql(u8, arg, "--output-target")) {
5959 i += 1;
6060 if (i >= args.len) fatal("expected another argument after '{s}'", .{arg});
......@@ -227,8 +227,8 @@ fn cmdObjCopy(
227227 if (listen) {
228228 var server = try Server.init(.{
229229 .gpa = gpa,
230 .in = std.io.getStdIn(),
231 .out = std.io.getStdOut(),
230 .in = .stdin(),
231 .out = .stdout(),
232232 .zig_version = builtin.zig_version_string,
233233 });
234234 defer server.deinit();
lib/compiler/reduce.zig+1-1
......@@ -68,7 +68,7 @@ pub fn main() !void {
6868 const arg = args[i];
6969 if (mem.startsWith(u8, arg, "-")) {
7070 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
71 const stdout = std.io.getStdOut().writer();
71 const stdout = std.fs.File.stdout().writer();
7272 try stdout.writeAll(usage);
7373 return std.process.cleanExit();
7474 } else if (mem.eql(u8, arg, "--")) {
lib/compiler/resinator/cli.zig+1-1
......@@ -127,7 +127,7 @@ pub const Diagnostics = struct {
127127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {
128128 std.debug.lockStdErr();
129129 defer std.debug.unlockStdErr();
130 const stderr = std.io.getStdErr().writer();
130 const stderr = std.fs.File.stderr().writer();
131131 self.renderToWriter(args, stderr, config) catch return;
132132 }
133133
lib/compiler/resinator/errors.zig+2-2
......@@ -63,14 +63,14 @@ pub const Diagnostics = struct {
6363 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {
6464 std.debug.lockStdErr();
6565 defer std.debug.unlockStdErr();
66 const stderr = std.io.getStdErr().writer();
66 const stderr = std.fs.File.stderr().writer();
6767 for (self.errors.items) |err_details| {
6868 renderErrorMessage(stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return;
6969 }
7070 }
7171
7272 pub fn renderToStdErrDetectTTY(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, source_mappings: ?SourceMappings) void {
73 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());
73 const tty_config = std.io.tty.detectConfig(std.fs.File.stderr());
7474 return self.renderToStdErr(cwd, source, tty_config, source_mappings);
7575 }
7676
lib/compiler/resinator/main.zig+6-6
......@@ -22,7 +22,7 @@ pub fn main() !void {
2222 defer arena_state.deinit();
2323 const arena = arena_state.allocator();
2424
25 const stderr = std.io.getStdErr();
25 const stderr = std.fs.File.stderr();
2626 const stderr_config = std.io.tty.detectConfig(stderr);
2727
2828 const args = try std.process.argsAlloc(allocator);
......@@ -44,7 +44,7 @@ pub fn main() !void {
4444 var error_handler: ErrorHandler = switch (zig_integration) {
4545 true => .{
4646 .server = .{
47 .out = std.io.getStdOut(),
47 .out = std.fs.File.stdout(),
4848 .in = undefined, // won't be receiving messages
4949 .receive_fifo = undefined, // won't be receiving messages
5050 },
......@@ -81,7 +81,7 @@ pub fn main() !void {
8181 defer options.deinit();
8282
8383 if (options.print_help_and_exit) {
84 const stdout = std.io.getStdOut();
84 const stdout = std.fs.File.stdout();
8585 try cli.writeUsage(stdout.writer(), "zig rc");
8686 return;
8787 }
......@@ -89,7 +89,7 @@ pub fn main() !void {
8989 // Don't allow verbose when integrating with Zig via stdout
9090 options.verbose = false;
9191
92 const stdout_writer = std.io.getStdOut().writer();
92 const stdout_writer = std.fs.File.stdout().writer();
9393 if (options.verbose) {
9494 try options.dumpVerbose(stdout_writer);
9595 try stdout_writer.writeByte('\n');
......@@ -645,7 +645,7 @@ const ErrorHandler = union(enum) {
645645 },
646646 .tty => {
647647 // extra newline to separate this line from the aro errors
648 try renderErrorMessage(std.io.getStdErr().writer(), self.tty, .err, "{s}\n", .{fail_msg});
648 try renderErrorMessage(std.fs.File.stderr().writer(), self.tty, .err, "{s}\n", .{fail_msg});
649649 aro.Diagnostics.render(comp, self.tty);
650650 },
651651 }
......@@ -690,7 +690,7 @@ const ErrorHandler = union(enum) {
690690 try server.serveErrorBundle(error_bundle);
691691 },
692692 .tty => {
693 try renderErrorMessage(std.io.getStdErr().writer(), self.tty, msg_type, format, args);
693 try renderErrorMessage(std.fs.File.stderr().writer(), self.tty, msg_type, format, args);
694694 },
695695 }
696696 }
lib/compiler/std-docs.zig+2-2
......@@ -7,7 +7,7 @@ const assert = std.debug.assert;
77const Cache = std.Build.Cache;
88
99fn usage() noreturn {
10 io.getStdOut().writeAll(
10 std.fs.File.stdout().writeAll(
1111 \\Usage: zig std [options]
1212 \\
1313 \\Options:
......@@ -63,7 +63,7 @@ pub fn main() !void {
6363 var http_server = try address.listen(.{});
6464 const port = http_server.listen_address.in.getPort();
6565 const url_with_newline = try std.fmt.allocPrint(arena, "http://127.0.0.1:{d}/\n", .{port});
66 std.io.getStdOut().writeAll(url_with_newline) catch {};
66 std.fs.File.stdout().writeAll(url_with_newline) catch {};
6767 if (should_open_browser) {
6868 openBrowserTab(gpa, url_with_newline[0 .. url_with_newline.len - 1 :'\n']) catch |err| {
6969 std.log.err("unable to open browser: {s}", .{@errorName(err)});
lib/compiler/test_runner.zig+4-4
......@@ -69,8 +69,8 @@ fn mainServer() !void {
6969 @disableInstrumentation();
7070 var server = try std.zig.Server.init(.{
7171 .gpa = fba.allocator(),
72 .in = std.io.getStdIn(),
73 .out = std.io.getStdOut(),
72 .in = .stdin(),
73 .out = .stdout(),
7474 .zig_version = builtin.zig_version_string,
7575 });
7676 defer server.deinit();
......@@ -191,7 +191,7 @@ fn mainTerminal() void {
191191 .root_name = "Test",
192192 .estimated_total_items = test_fn_list.len,
193193 });
194 const have_tty = std.io.getStdErr().isTty();
194 const have_tty = std.fs.File.stderr().isTty();
195195
196196 var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
197197 // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
......@@ -301,7 +301,7 @@ pub fn mainSimple() anyerror!void {
301301 var failed: u64 = 0;
302302
303303 // we don't want to bring in File and Writer if the backend doesn't support it
304 const stderr = if (comptime enable_print) std.io.getStdErr() else {};
304 const stderr = if (comptime enable_print) std.fs.File.stderr() else {};
305305
306306 for (builtin.test_functions) |test_fn| {
307307 if (test_fn.func()) |_| {
lib/docs/wasm/markdown.zig+2-2
......@@ -145,7 +145,7 @@ fn mainImpl() !void {
145145 var parser = try Parser.init(gpa);
146146 defer parser.deinit();
147147
148 var stdin_buf = std.io.bufferedReader(std.io.getStdIn().reader());
148 var stdin_buf = std.io.bufferedReader(std.fs.File.stdin().reader());
149149 var line_buf = std.ArrayList(u8).init(gpa);
150150 defer line_buf.deinit();
151151 while (stdin_buf.reader().streamUntilDelimiter(line_buf.writer(), '\n', null)) {
......@@ -160,7 +160,7 @@ fn mainImpl() !void {
160160 var doc = try parser.endInput();
161161 defer doc.deinit(gpa);
162162
163 var stdout_buf = std.io.bufferedWriter(std.io.getStdOut().writer());
163 var stdout_buf = std.io.bufferedWriter(std.fs.File.stdout().writer());
164164 try doc.render(stdout_buf.writer());
165165 try stdout_buf.flush();
166166}
lib/init/src/root.zig+1-1
......@@ -5,7 +5,7 @@ pub fn bufferedPrint() !void {
55 // Stdout is for the actual output of your application, for example if you
66 // are implementing gzip, then only the compressed bytes should be sent to
77 // stdout, not any debugging messages.
8 const stdout_file = std.io.getStdOut().writer();
8 const stdout_file = std.fs.File.stdout().writer();
99 // Buffering can improve performance significantly in print-heavy programs.
1010 var bw = std.io.bufferedWriter(stdout_file);
1111 const stdout = bw.writer();
lib/std/Build.zig+3-3
......@@ -2467,7 +2467,7 @@ pub const GeneratedFile = struct {
24672467 pub fn getPath2(gen: GeneratedFile, src_builder: *Build, asking_step: ?*Step) []const u8 {
24682468 return gen.path orelse {
24692469 std.debug.lockStdErr();
2470 const stderr = std.io.getStdErr();
2470 const stderr = std.fs.File.stderr();
24712471 dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {};
24722472 std.debug.unlockStdErr();
24732473 @panic("misconfigured build script");
......@@ -2677,7 +2677,7 @@ pub const LazyPath = union(enum) {
26772677 .root_dir = Cache.Directory.cwd(),
26782678 .sub_path = gen.file.path orelse {
26792679 std.debug.lockStdErr();
2680 const stderr = std.io.getStdErr();
2680 const stderr: fs.File = .stderr();
26812681 dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
26822682 std.debug.unlockStdErr();
26832683 @panic("misconfigured build script");
......@@ -2769,7 +2769,7 @@ fn dumpBadDirnameHelp(
27692769 debug.lockStdErr();
27702770 defer debug.unlockStdErr();
27712771
2772 const stderr = io.getStdErr();
2772 const stderr: fs.File = .stderr();
27732773 const w = stderr.writer();
27742774 try w.print(msg, args);
27752775
lib/std/Build/Cache/DepTokenizer.zig+1-1
......@@ -1072,7 +1072,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
10721072 return;
10731073 }
10741074
1075 const out = std.io.getStdErr().writer();
1075 const out = std.fs.File.stderr().writer();
10761076
10771077 try out.writeAll("\n");
10781078 try printSection(out, "<<<< input", input);
lib/std/Build/Fuzz.zig+2-2
......@@ -112,7 +112,7 @@ fn rebuildTestsWorkerRun(run: *Step.Run, ttyconf: std.io.tty.Config, parent_prog
112112
113113fn rebuildTestsWorkerRunFallible(run: *Step.Run, ttyconf: std.io.tty.Config, parent_prog_node: std.Progress.Node) !void {
114114 const gpa = run.step.owner.allocator;
115 const stderr = std.io.getStdErr();
115 const stderr = std.fs.File.stderr();
116116
117117 const compile = run.producer.?;
118118 const prog_node = parent_prog_node.start(compile.step.name, 0);
......@@ -152,7 +152,7 @@ fn fuzzWorkerRun(
152152
153153 run.rerunInFuzzMode(web_server, unit_test_index, prog_node) catch |err| switch (err) {
154154 error.MakeFailed => {
155 const stderr = std.io.getStdErr();
155 const stderr = std.fs.File.stderr();
156156 std.debug.lockStdErr();
157157 defer std.debug.unlockStdErr();
158158 build_runner.printErrorMessages(gpa, &run.step, .{ .ttyconf = ttyconf }, stderr, false) catch {};
lib/std/Build/Step/Compile.zig+2-2
......@@ -1018,7 +1018,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
10181018
10191019 const generated_file = maybe_path orelse {
10201020 std.debug.lockStdErr();
1021 const stderr = std.io.getStdErr();
1021 const stderr: fs.File = .stderr();
10221022
10231023 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
10241024
......@@ -1027,7 +1027,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
10271027
10281028 const path = generated_file.path orelse {
10291029 std.debug.lockStdErr();
1030 const stderr = std.io.getStdErr();
1030 const stderr: fs.File = .stderr();
10311031
10321032 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
10331033
lib/std/Progress.zig+1-1
......@@ -451,7 +451,7 @@ pub fn start(options: Options) Node {
451451 if (options.disable_printing) {
452452 return Node.none;
453453 }
454 const stderr = std.io.getStdErr();
454 const stderr: std.fs.File = .stderr();
455455 global_progress.terminal = stderr;
456456 if (stderr.getOrEnableAnsiEscapeSupport()) {
457457 global_progress.terminal_mode = .ansi_escape_codes;
lib/std/Random/benchmark.zig+1-1
......@@ -122,7 +122,7 @@ fn mode(comptime x: comptime_int) comptime_int {
122122}
123123
124124pub fn main() !void {
125 const stdout = std.io.getStdOut().writer();
125 const stdout = std.fs.File.stdout().writer();
126126
127127 var buffer: [1024]u8 = undefined;
128128 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
lib/std/builtin.zig+1-1
......@@ -51,7 +51,7 @@ pub const StackTrace = struct {
5151 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
5252 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
5353 };
54 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());
54 const tty_config = std.io.tty.detectConfig(std.fs.File.stderr());
5555 try writer.writeAll("\n");
5656 std.debug.writeStackTrace(self, writer, debug_info, tty_config) catch |err| {
5757 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
lib/std/crypto/benchmark.zig+1-1
......@@ -458,7 +458,7 @@ fn mode(comptime x: comptime_int) comptime_int {
458458}
459459
460460pub fn main() !void {
461 const stdout = std.io.getStdOut().writer();
461 const stdout = std.fs.File.stdout().writer();
462462
463463 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
464464 defer arena.deinit();
lib/std/debug.zig+19-19
......@@ -209,7 +209,7 @@ pub fn unlockStdErr() void {
209209pub fn print(comptime fmt: []const u8, args: anytype) void {
210210 lockStdErr();
211211 defer unlockStdErr();
212 const stderr = io.getStdErr().writer();
212 const stderr = fs.File.stderr().writer();
213213 nosuspend stderr.print(fmt, args) catch return;
214214}
215215
......@@ -239,7 +239,7 @@ pub fn dumpHex(bytes: []const u8) void {
239239
240240/// Prints a hexadecimal view of the bytes, unbuffered, returning any error that occurs.
241241pub fn dumpHexFallible(bytes: []const u8) !void {
242 const stderr = std.io.getStdErr();
242 const stderr: fs.File = .stderr();
243243 const ttyconf = std.io.tty.detectConfig(stderr);
244244 const writer = stderr.writer();
245245 try dumpHexInternal(bytes, ttyconf, writer);
......@@ -318,12 +318,12 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
318318 nosuspend {
319319 if (builtin.target.cpu.arch.isWasm()) {
320320 if (native_os == .wasi) {
321 const stderr = io.getStdErr().writer();
321 const stderr = fs.File.stderr().writer();
322322 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
323323 }
324324 return;
325325 }
326 const stderr = io.getStdErr().writer();
326 const stderr = fs.File.stderr().writer();
327327 if (builtin.strip_debug_info) {
328328 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
329329 return;
......@@ -332,7 +332,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
332332 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
333333 return;
334334 };
335 writeCurrentStackTrace(stderr, debug_info, io.tty.detectConfig(io.getStdErr()), start_addr) catch |err| {
335 writeCurrentStackTrace(stderr, debug_info, io.tty.detectConfig(fs.File.stderr()), start_addr) catch |err| {
336336 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
337337 return;
338338 };
......@@ -406,12 +406,12 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext) void {
406406 nosuspend {
407407 if (builtin.target.cpu.arch.isWasm()) {
408408 if (native_os == .wasi) {
409 const stderr = io.getStdErr().writer();
409 const stderr = fs.File.stderr().writer();
410410 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
411411 }
412412 return;
413413 }
414 const stderr = io.getStdErr().writer();
414 const stderr = fs.File.stderr().writer();
415415 if (builtin.strip_debug_info) {
416416 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
417417 return;
......@@ -420,7 +420,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext) void {
420420 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
421421 return;
422422 };
423 const tty_config = io.tty.detectConfig(io.getStdErr());
423 const tty_config = io.tty.detectConfig(fs.File.stderr());
424424 if (native_os == .windows) {
425425 // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context
426426 // provided by the exception handler. On x86, RtlVirtualUnwind doesn't exist. Instead, a new backtrace
......@@ -510,12 +510,12 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
510510 nosuspend {
511511 if (builtin.target.cpu.arch.isWasm()) {
512512 if (native_os == .wasi) {
513 const stderr = io.getStdErr().writer();
513 const stderr = fs.File.stderr().writer();
514514 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
515515 }
516516 return;
517517 }
518 const stderr = io.getStdErr().writer();
518 const stderr = fs.File.stderr().writer();
519519 if (builtin.strip_debug_info) {
520520 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
521521 return;
......@@ -524,7 +524,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
524524 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
525525 return;
526526 };
527 writeStackTrace(stack_trace, stderr, debug_info, io.tty.detectConfig(io.getStdErr())) catch |err| {
527 writeStackTrace(stack_trace, stderr, debug_info, io.tty.detectConfig(fs.File.stderr())) catch |err| {
528528 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
529529 return;
530530 };
......@@ -678,7 +678,7 @@ pub fn defaultPanic(
678678 lockStdErr();
679679 defer unlockStdErr();
680680
681 const stderr = io.getStdErr().writer();
681 const stderr = fs.File.stderr().writer();
682682 if (builtin.single_threaded) {
683683 stderr.print("panic: ", .{}) catch posix.abort();
684684 } else {
......@@ -699,7 +699,7 @@ pub fn defaultPanic(
699699 // A panic happened while trying to print a previous panic message.
700700 // We're still holding the mutex but that's fine as we're going to
701701 // call abort().
702 io.getStdErr().writeAll("aborting due to recursive panic\n") catch {};
702 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};
703703 },
704704 else => {}, // Panicked while printing the recursive panic message.
705705 };
......@@ -1461,7 +1461,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
14611461}
14621462
14631463fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void {
1464 const stderr = io.getStdErr().writer();
1464 const stderr = fs.File.stderr().writer();
14651465 _ = switch (sig) {
14661466 posix.SIG.SEGV => if (native_arch == .x86_64 and native_os == .linux and code == 128) // SI_KERNEL
14671467 // x86_64 doesn't have a full 64-bit virtual address space.
......@@ -1549,7 +1549,7 @@ fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, msg: u8, label:
15491549 },
15501550 1 => {
15511551 panic_stage = 2;
1552 io.getStdErr().writeAll("aborting due to recursive panic\n") catch {};
1552 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};
15531553 },
15541554 else => {},
15551555 };
......@@ -1557,7 +1557,7 @@ fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, msg: u8, label:
15571557}
15581558
15591559fn dumpSegfaultInfoWindows(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[]const u8) void {
1560 const stderr = io.getStdErr().writer();
1560 const stderr = fs.File.stderr().writer();
15611561 _ = switch (msg) {
15621562 0 => stderr.print("{s}\n", .{label.?}),
15631563 1 => stderr.print("Segmentation fault at address 0x{x}\n", .{info.ExceptionRecord.ExceptionInformation[1]}),
......@@ -1591,7 +1591,7 @@ test "manage resources correctly" {
15911591 const writer = std.io.null_writer;
15921592 var di = try SelfInfo.open(testing.allocator);
15931593 defer di.deinit();
1594 try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(std.io.getStdErr()));
1594 try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(std.fs.File.stderr()));
15951595}
15961596
15971597noinline fn showMyTrace() usize {
......@@ -1657,8 +1657,8 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
16571657 pub fn dump(t: @This()) void {
16581658 if (!enabled) return;
16591659
1660 const tty_config = io.tty.detectConfig(std.io.getStdErr());
1661 const stderr = io.getStdErr().writer();
1660 const tty_config = io.tty.detectConfig(std.fs.File.stderr());
1661 const stderr = fs.File.stderr().writer();
16621662 const end = @min(t.index, size);
16631663 const debug_info = getSelfDebugInfo() catch |err| {
16641664 stderr.print(
lib/std/debug/simple_panic.zig+1-1
......@@ -15,7 +15,7 @@ pub fn call(msg: []const u8, ra: ?usize) noreturn {
1515 @branchHint(.cold);
1616 _ = ra;
1717 std.debug.lockStdErr();
18 const stderr = std.io.getStdErr();
18 const stderr: std.fs.File = .stderr();
1919 stderr.writeAll(msg) catch {};
2020 @trap();
2121}
lib/std/hash/benchmark.zig+1-1
......@@ -346,7 +346,7 @@ fn mode(comptime x: comptime_int) comptime_int {
346346}
347347
348348pub fn main() !void {
349 const stdout = std.io.getStdOut().writer();
349 const stdout = std.fs.File.stdout().writer();
350350
351351 var buffer: [1024]u8 = undefined;
352352 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
lib/std/io.zig-48
......@@ -77,54 +77,6 @@ pub const Limit = enum(usize) {
7777pub const Reader = @import("io/Reader.zig");
7878pub const Writer = @import("io/Writer.zig");
7979
80fn getStdOutHandle() posix.fd_t {
81 if (is_windows) {
82 return windows.peb().ProcessParameters.hStdOutput;
83 }
84
85 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdOutHandle")) {
86 return root.os.io.getStdOutHandle();
87 }
88
89 return posix.STDOUT_FILENO;
90}
91
92pub fn getStdOut() File {
93 return .{ .handle = getStdOutHandle() };
94}
95
96fn getStdErrHandle() posix.fd_t {
97 if (is_windows) {
98 return windows.peb().ProcessParameters.hStdError;
99 }
100
101 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdErrHandle")) {
102 return root.os.io.getStdErrHandle();
103 }
104
105 return posix.STDERR_FILENO;
106}
107
108pub fn getStdErr() File {
109 return .{ .handle = getStdErrHandle() };
110}
111
112fn getStdInHandle() posix.fd_t {
113 if (is_windows) {
114 return windows.peb().ProcessParameters.hStdInput;
115 }
116
117 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdInHandle")) {
118 return root.os.io.getStdInHandle();
119 }
120
121 return posix.STDIN_FILENO;
122}
123
124pub fn getStdIn() File {
125 return .{ .handle = getStdInHandle() };
126}
127
12880/// Deprecated in favor of `Reader`.
12981pub fn GenericReader(
13082 comptime Context: type,
lib/std/json/dynamic.zig+1-1
......@@ -56,7 +56,7 @@ pub const Value = union(enum) {
5656 std.debug.lockStdErr();
5757 defer std.debug.unlockStdErr();
5858
59 const stderr = std.io.getStdErr().writer();
59 const stderr = std.fs.File.stderr().writer();
6060 stringify(self, .{}, stderr) catch return;
6161 }
6262
lib/std/log.zig+2-2
......@@ -47,7 +47,7 @@
4747//! // Print the message to stderr, silently ignoring any errors
4848//! std.debug.lockStdErr();
4949//! defer std.debug.unlockStdErr();
50//! const stderr = std.io.getStdErr().writer();
50//! const stderr = std.fs.File.stderr().writer();
5151//! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5252//! }
5353//!
......@@ -148,7 +148,7 @@ pub fn defaultLog(
148148) void {
149149 const level_txt = comptime message_level.asText();
150150 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
151 const stderr = std.io.getStdErr().writer();
151 const stderr = std.fs.File.stderr().writer();
152152 var bw = std.io.bufferedWriter(stderr);
153153 const writer = bw.writer();
154154
lib/std/testing.zig+1-1
......@@ -390,7 +390,7 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
390390 const actual_window = actual[window_start..@min(actual.len, window_start + max_window_size)];
391391 const actual_truncated = window_start + actual_window.len < actual.len;
392392
393 const stderr = std.io.getStdErr();
393 const stderr: std.fs.File = .stderr();
394394 const ttyconf = std.io.tty.detectConfig(stderr);
395395 var differ = if (T == u8) BytesDiffer{
396396 .expected = expected_window,
lib/std/unicode/throughput_test.zig+1-1
......@@ -39,7 +39,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
3939}
4040
4141pub fn main() !void {
42 const stdout = std.io.getStdOut().writer();
42 const stdout = std.fs.File.stdout().writer();
4343
4444 try stdout.print("short ASCII strings\n", .{});
4545 {
lib/std/zig.zig+1-1
......@@ -48,7 +48,7 @@ pub const Color = enum {
4848
4949 pub fn get_tty_conf(color: Color) std.io.tty.Config {
5050 return switch (color) {
51 .auto => std.io.tty.detectConfig(std.io.getStdErr()),
51 .auto => std.io.tty.detectConfig(std.fs.File.stderr()),
5252 .on => .escape_codes,
5353 .off => .no_color,
5454 };
lib/std/zig/ErrorBundle.zig+6-6
......@@ -7,6 +7,11 @@
77//! empty, it means there are no errors. This special encoding exists so that
88//! heap allocation is not needed in the common case of no errors.
99
10const std = @import("std");
11const ErrorBundle = @This();
12const Allocator = std.mem.Allocator;
13const assert = std.debug.assert;
14
1015string_bytes: []const u8,
1116/// The first thing in this array is an `ErrorMessageList`.
1217extra: []const u32,
......@@ -159,7 +164,7 @@ pub const RenderOptions = struct {
159164pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {
160165 std.debug.lockStdErr();
161166 defer std.debug.unlockStdErr();
162 const stderr = std.io.getStdErr();
167 const stderr: std.fs.File = .stderr();
163168 return renderToWriter(eb, options, stderr.writer()) catch return;
164169}
165170
......@@ -305,11 +310,6 @@ fn writeMsg(eb: ErrorBundle, err_msg: ErrorMessage, stderr: anytype, indent: usi
305310 }
306311}
307312
308const std = @import("std");
309const ErrorBundle = @This();
310const Allocator = std.mem.Allocator;
311const assert = std.debug.assert;
312
313313pub const Wip = struct {
314314 gpa: Allocator,
315315 string_bytes: std.ArrayListUnmanaged(u8),
lib/std/zig/llvm/Builder.zig+2-1
......@@ -9493,7 +9493,8 @@ pub fn asmValue(
94939493}
94949494
94959495pub fn dump(self: *Builder) void {
9496 self.print(std.io.getStdErr().writer()) catch {};
9496 const stderr: std.fs.File = .stderr();
9497 self.print(stderr.writer()) catch {};
94979498}
94989499
94999500pub fn printToFile(self: *Builder, path: []const u8) Allocator.Error!bool {
lib/std/zig/parser_test.zig+7-7
......@@ -1,3 +1,9 @@
1const std = @import("std");
2const mem = std.mem;
3const print = std.debug.print;
4const io = std.io;
5const maxInt = std.math.maxInt;
6
17test "zig fmt: remove extra whitespace at start and end of file with comment between" {
28 try testTransform(
39 \\
......@@ -6315,16 +6321,10 @@ test "ampersand" {
63156321 , &.{});
63166322}
63176323
6318const std = @import("std");
6319const mem = std.mem;
6320const print = std.debug.print;
6321const io = std.io;
6322const maxInt = std.math.maxInt;
6323
63246324var fixed_buffer_mem: [100 * 1024]u8 = undefined;
63256325
63266326fn testParse(source: [:0]const u8, allocator: mem.Allocator, anything_changed: *bool) ![]u8 {
6327 const stderr = io.getStdErr().writer();
6327 const stderr = std.fs.File.stderr().writer();
63286328
63296329 var tree = try std.zig.Ast.parse(allocator, source, .zig);
63306330 defer tree.deinit(allocator);
lib/std/zig/perf_test.zig+1-1
......@@ -22,7 +22,7 @@ pub fn main() !void {
2222 const bytes_per_sec_float = @as(f64, @floatFromInt(source.len * iterations)) / elapsed_s;
2323 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));
2424
25 var stdout_file = std.io.getStdOut();
25 var stdout_file: std.fs.File = .stdout();
2626 const stdout = stdout_file.writer();
2727 try stdout.print("parsing speed: {:.2}/s, {:.2} used \n", .{
2828 fmtIntSizeBin(bytes_per_sec),
src/Air/print.zig+2-2
......@@ -73,11 +73,11 @@ pub fn writeInst(
7373}
7474
7575pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
76 air.write(std.io.getStdErr().writer(), pt, liveness);
76 air.write(std.fs.File.stderr().writer(), pt, liveness);
7777}
7878
7979pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
80 air.writeInst(std.io.getStdErr().writer(), inst, pt, liveness);
80 air.writeInst(std.fs.File.stderr().writer(), inst, pt, liveness);
8181}
8282
8383const Writer = struct {
src/Compilation.zig+3-3
......@@ -1875,7 +1875,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18751875 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
18761876 std.debug.lockStdErr();
18771877 defer std.debug.unlockStdErr();
1878 const stderr = std.io.getStdErr().writer();
1878 const stderr = std.fs.File.stderr().writer();
18791879 nosuspend {
18801880 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
18811881 stderr.print(" target: {s}\n", .{try target.zigTriple(arena)}) catch break :print;
......@@ -3932,7 +3932,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
39323932 // This AU is referenced and has a transitive compile error, meaning it referenced something with a compile error.
39333933 // However, we haven't reported any such error.
39343934 // This is a compiler bug.
3935 const stderr = std.io.getStdErr().writer();
3935 const stderr = std.fs.File.stderr().writer();
39363936 try stderr.writeAll("referenced transitive analysis errors, but none actually emitted\n");
39373937 try stderr.print("{} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)});
39383938 while (ref) |r| {
......@@ -7214,7 +7214,7 @@ pub fn lockAndSetMiscFailure(
72147214pub fn dump_argv(argv: []const []const u8) void {
72157215 std.debug.lockStdErr();
72167216 defer std.debug.unlockStdErr();
7217 const stderr = std.io.getStdErr().writer();
7217 const stderr = std.fs.File.stderr().writer();
72187218 for (argv[0 .. argv.len - 1]) |arg| {
72197219 nosuspend stderr.print("{s} ", .{arg}) catch return;
72207220 }
src/InternPool.zig+2-2
......@@ -11259,7 +11259,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
1125911259}
1126011260
1126111261fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11262 var bw = std.io.bufferedWriter(std.io.getStdErr().writer());
11262 var bw = std.io.bufferedWriter(std.fs.File.stderr().writer());
1126311263 const w = bw.writer();
1126411264 for (ip.locals, 0..) |*local, tid| {
1126511265 const items = local.shared.items.view();
......@@ -11369,7 +11369,7 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1136911369 defer arena_allocator.deinit();
1137011370 const arena = arena_allocator.allocator();
1137111371
11372 var bw = std.io.bufferedWriter(std.io.getStdErr().writer());
11372 var bw = std.io.bufferedWriter(std.fs.File.stderr().writer());
1137311373 const w = bw.writer();
1137411374
1137511375 var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;
src/Package/Fetch.zig+23-23
......@@ -27,6 +27,22 @@
2727//! All of this must be done with only referring to the state inside this struct
2828//! because this work will be done in a dedicated thread.
2929
30const builtin = @import("builtin");
31const std = @import("std");
32const fs = std.fs;
33const assert = std.debug.assert;
34const ascii = std.ascii;
35const Allocator = std.mem.Allocator;
36const Cache = std.Build.Cache;
37const ThreadPool = std.Thread.Pool;
38const WaitGroup = std.Thread.WaitGroup;
39const Fetch = @This();
40const git = @import("Fetch/git.zig");
41const Package = @import("../Package.zig");
42const Manifest = Package.Manifest;
43const ErrorBundle = std.zig.ErrorBundle;
44const native_os = builtin.os.tag;
45
3046arena: std.heap.ArenaAllocator,
3147location: Location,
3248location_tok: std.zig.Ast.TokenIndex,
......@@ -1638,7 +1654,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16381654}
16391655
16401656fn dumpHashInfo(all_files: []const *const HashedFile) !void {
1641 const stdout = std.io.getStdOut();
1657 const stdout: std.fs.File = .stdout();
16421658 var bw = std.io.bufferedWriter(stdout.writer());
16431659 const w = bw.writer();
16441660
......@@ -1817,28 +1833,6 @@ pub fn depDigest(pkg_root: Cache.Path, cache_root: Cache.Directory, dep: Manifes
18171833 }
18181834}
18191835
1820const builtin = @import("builtin");
1821const std = @import("std");
1822const fs = std.fs;
1823const assert = std.debug.assert;
1824const ascii = std.ascii;
1825const Allocator = std.mem.Allocator;
1826const Cache = std.Build.Cache;
1827const ThreadPool = std.Thread.Pool;
1828const WaitGroup = std.Thread.WaitGroup;
1829const Fetch = @This();
1830const git = @import("Fetch/git.zig");
1831const Package = @import("../Package.zig");
1832const Manifest = Package.Manifest;
1833const ErrorBundle = std.zig.ErrorBundle;
1834const native_os = builtin.os.tag;
1835
1836test {
1837 _ = Filter;
1838 _ = FileType;
1839 _ = UnpackResult;
1840}
1841
18421836// Detects executable header: ELF or Macho-O magic header or shebang line.
18431837const FileHeader = struct {
18441838 header: [4]u8 = undefined,
......@@ -2437,3 +2431,9 @@ const TestFetchBuilder = struct {
24372431 try std.testing.expectEqualStrings(msg, al.items);
24382432 }
24392433};
2434
2435test {
2436 _ = Filter;
2437 _ = FileType;
2438 _ = UnpackResult;
2439}
src/Zcu/PerThread.zig+1-1
......@@ -4378,7 +4378,7 @@ fn runCodegenInner(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) e
43784378 if (build_options.enable_debug_extensions and comp.verbose_air) {
43794379 std.debug.lockStdErr();
43804380 defer std.debug.unlockStdErr();
4381 const stderr = std.io.getStdErr().writer();
4381 const stderr = std.fs.File.stderr().writer();
43824382 stderr.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)}) catch {};
43834383 air.write(stderr, pt, liveness);
43844384 stderr.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)}) catch {};
src/crash_report.zig+7-7
......@@ -80,7 +80,7 @@ fn dumpStatusReport() !void {
8080 var fba = std.heap.FixedBufferAllocator.init(&crash_heap);
8181 const allocator = fba.allocator();
8282
83 const stderr = io.getStdErr().writer();
83 const stderr = std.fs.File.stderr().writer();
8484 const block: *Sema.Block = anal.block;
8585 const zcu = anal.sema.pt.zcu;
8686
......@@ -271,7 +271,7 @@ const StackContext = union(enum) {
271271 debug.dumpStackTraceFromBase(context);
272272 },
273273 .not_supported => {
274 const stderr = io.getStdErr().writer();
274 const stderr = std.fs.File.stderr().writer();
275275 stderr.writeAll("Stack trace not supported on this platform.\n") catch {};
276276 },
277277 }
......@@ -379,7 +379,7 @@ const PanicSwitch = struct {
379379
380380 state.recover_stage = .release_mutex;
381381
382 const stderr = io.getStdErr().writer();
382 const stderr = std.fs.File.stderr().writer();
383383 if (builtin.single_threaded) {
384384 stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state});
385385 } else {
......@@ -406,7 +406,7 @@ const PanicSwitch = struct {
406406 recover(state, trace, stack, msg);
407407
408408 state.recover_stage = .release_mutex;
409 const stderr = io.getStdErr().writer();
409 const stderr = std.fs.File.stderr().writer();
410410 stderr.writeAll("\nOriginal Error:\n") catch {};
411411 goTo(reportStack, .{state});
412412 }
......@@ -477,7 +477,7 @@ const PanicSwitch = struct {
477477 recover(state, trace, stack, msg);
478478
479479 state.recover_stage = .silent_abort;
480 const stderr = io.getStdErr().writer();
480 const stderr = std.fs.File.stderr().writer();
481481 stderr.writeAll("Aborting...\n") catch {};
482482 goTo(abort, .{});
483483 }
......@@ -505,7 +505,7 @@ const PanicSwitch = struct {
505505 // lower the verbosity, and restore it at the end if we don't panic.
506506 state.recover_verbosity = .message_only;
507507
508 const stderr = io.getStdErr().writer();
508 const stderr = std.fs.File.stderr().writer();
509509 stderr.writeAll("\nPanicked during a panic: ") catch {};
510510 stderr.writeAll(msg) catch {};
511511 stderr.writeAll("\nInner panic stack:\n") catch {};
......@@ -519,7 +519,7 @@ const PanicSwitch = struct {
519519 .message_only => {
520520 state.recover_verbosity = .silent;
521521
522 const stderr = io.getStdErr().writer();
522 const stderr = std.fs.File.stderr().writer();
523523 stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {};
524524 stderr.writeAll(msg) catch {};
525525 stderr.writeAll("\n") catch {};
src/fmt.zig+13-13
......@@ -1,3 +1,11 @@
1const std = @import("std");
2const mem = std.mem;
3const fs = std.fs;
4const process = std.process;
5const Allocator = std.mem.Allocator;
6const Color = std.zig.Color;
7const fatal = std.process.fatal;
8
19const usage_fmt =
210 \\Usage: zig fmt [file]...
311 \\
......@@ -52,7 +60,7 @@ pub fn run(
5260 const arg = args[i];
5361 if (mem.startsWith(u8, arg, "-")) {
5462 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
55 const stdout = std.io.getStdOut().writer();
63 const stdout = std.fs.File.stdout().writer();
5664 try stdout.writeAll(usage_fmt);
5765 return process.cleanExit();
5866 } else if (mem.eql(u8, arg, "--color")) {
......@@ -93,7 +101,7 @@ pub fn run(
93101 fatal("cannot use --stdin with positional arguments", .{});
94102 }
95103
96 const stdin = std.io.getStdIn();
104 const stdin: fs.File = .stdin();
97105 const source_code = std.zig.readSourceFileToEndAlloc(gpa, stdin, null) catch |err| {
98106 fatal("unable to read stdin: {}", .{err});
99107 };
......@@ -146,7 +154,7 @@ pub fn run(
146154 process.exit(code);
147155 }
148156
149 return std.io.getStdOut().writeAll(formatted);
157 return std.fs.File.stdout().writeAll(formatted);
150158 }
151159
152160 if (input_files.items.len == 0) {
......@@ -363,7 +371,7 @@ fn fmtPathFile(
363371 return;
364372
365373 if (check_mode) {
366 const stdout = std.io.getStdOut().writer();
374 const stdout = std.fs.File.stdout().writer();
367375 try stdout.print("{s}\n", .{file_path});
368376 fmt.any_error = true;
369377 } else {
......@@ -372,15 +380,7 @@ fn fmtPathFile(
372380
373381 try af.file.writeAll(fmt.out_buffer.items);
374382 try af.finish();
375 const stdout = std.io.getStdOut().writer();
383 const stdout = std.fs.File.stdout().writer();
376384 try stdout.print("{s}\n", .{file_path});
377385 }
378386}
379
380const std = @import("std");
381const mem = std.mem;
382const fs = std.fs;
383const process = std.process;
384const Allocator = std.mem.Allocator;
385const Color = std.zig.Color;
386const fatal = std.process.fatal;
src/libs/mingw.zig+2-2
......@@ -306,7 +306,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
306306 if (comp.verbose_cc) print: {
307307 std.debug.lockStdErr();
308308 defer std.debug.unlockStdErr();
309 const stderr = std.io.getStdErr().writer();
309 const stderr = std.fs.File.stderr().writer();
310310 nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;
311311 nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;
312312 nosuspend stderr.print("output path: {s}\n", .{def_final_path}) catch break :print;
......@@ -326,7 +326,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
326326
327327 for (aro_comp.diagnostics.list.items) |diagnostic| {
328328 if (diagnostic.kind == .@"fatal error" or diagnostic.kind == .@"error") {
329 aro.Diagnostics.render(&aro_comp, std.io.tty.detectConfig(std.io.getStdErr()));
329 aro.Diagnostics.render(&aro_comp, std.io.tty.detectConfig(std.fs.File.stderr()));
330330 return error.AroPreprocessorFailed;
331331 }
332332 }
src/link/Elf/gc.zig+1-1
......@@ -163,7 +163,7 @@ fn prune(elf_file: *Elf) void {
163163}
164164
165165pub fn dumpPrunedAtoms(elf_file: *Elf) !void {
166 const stderr = std.io.getStdErr().writer();
166 const stderr = std.fs.File.stderr().writer();
167167 for (elf_file.objects.items) |index| {
168168 const file = elf_file.file(index).?;
169169 for (file.atoms()) |atom_index| {
src/main.zig+28-28
......@@ -340,11 +340,11 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
340340 } else if (mem.eql(u8, cmd, "targets")) {
341341 dev.check(.targets_command);
342342 const host = std.zig.resolveTargetQueryOrFatal(.{});
343 const stdout = io.getStdOut().writer();
343 const stdout = fs.File.stdout().writer();
344344 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, &host);
345345 } else if (mem.eql(u8, cmd, "version")) {
346346 dev.check(.version_command);
347 try std.io.getStdOut().writeAll(build_options.version ++ "\n");
347 try fs.File.stdout().writeAll(build_options.version ++ "\n");
348348 // Check libc++ linkage to make sure Zig was built correctly, but only
349349 // for "env" and "version" to avoid affecting the startup time for
350350 // build-critical commands (check takes about ~10 μs)
......@@ -352,7 +352,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
352352 } else if (mem.eql(u8, cmd, "env")) {
353353 dev.check(.env_command);
354354 verifyLibcxxCorrectlyLinked();
355 return @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().writer());
355 return @import("print_env.zig").cmdEnv(arena, cmd_args, fs.File.stdout().writer());
356356 } else if (mem.eql(u8, cmd, "reduce")) {
357357 return jitCmd(gpa, arena, cmd_args, .{
358358 .cmd_name = "reduce",
......@@ -360,10 +360,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
360360 });
361361 } else if (mem.eql(u8, cmd, "zen")) {
362362 dev.check(.zen_command);
363 return io.getStdOut().writeAll(info_zen);
363 return fs.File.stdout().writeAll(info_zen);
364364 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
365365 dev.check(.help_command);
366 return io.getStdOut().writeAll(usage);
366 return fs.File.stdout().writeAll(usage);
367367 } else if (mem.eql(u8, cmd, "ast-check")) {
368368 return cmdAstCheck(arena, cmd_args);
369369 } else if (mem.eql(u8, cmd, "detect-cpu")) {
......@@ -1038,7 +1038,7 @@ fn buildOutputType(
10381038 };
10391039 } else if (mem.startsWith(u8, arg, "-")) {
10401040 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
1041 try io.getStdOut().writeAll(usage_build_generic);
1041 try fs.File.stdout().writeAll(usage_build_generic);
10421042 return cleanExit();
10431043 } else if (mem.eql(u8, arg, "--")) {
10441044 if (arg_mode == .run) {
......@@ -2766,9 +2766,9 @@ fn buildOutputType(
27662766 } else if (mem.eql(u8, arg, "-V")) {
27672767 warn("ignoring request for supported emulations: unimplemented", .{});
27682768 } else if (mem.eql(u8, arg, "-v")) {
2769 try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
2769 try fs.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
27702770 } else if (mem.eql(u8, arg, "--version")) {
2771 try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
2771 try fs.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
27722772 process.exit(0);
27732773 } else {
27742774 fatal("unsupported linker arg: {s}", .{arg});
......@@ -3328,7 +3328,7 @@ fn buildOutputType(
33283328 var hasher = Cache.Hasher.init("0123456789abcdef");
33293329 var w = io.multiWriter(.{ f.writer(), hasher.writer() });
33303330 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();
3331 try fifo.pump(io.getStdIn().reader(), w.writer());
3331 try fifo.pump(fs.File.stdin().reader(), w.writer());
33323332
33333333 var bin_digest: Cache.BinDigest = undefined;
33343334 hasher.final(&bin_digest);
......@@ -3546,15 +3546,15 @@ fn buildOutputType(
35463546 if (show_builtin) {
35473547 const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);
35483548 const source = try builtin_opts.generate(arena);
3549 return std.io.getStdOut().writeAll(source);
3549 return fs.File.stdout().writeAll(source);
35503550 }
35513551 switch (listen) {
35523552 .none => {},
35533553 .stdio => {
35543554 try serve(
35553555 comp,
3556 std.io.getStdIn(),
3557 std.io.getStdOut(),
3556 .stdin(),
3557 .stdout(),
35583558 test_exec_args.items,
35593559 self_exe_path,
35603560 arg_mode,
......@@ -4606,7 +4606,7 @@ fn cmdTranslateC(
46064606 fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{ path, fs.path.sep_str, out_zig_path, @errorName(err) });
46074607 };
46084608 defer zig_file.close();
4609 try io.getStdOut().writeFileAll(zig_file, .{});
4609 try fs.File.stdout().writeFileAll(zig_file, .{});
46104610 return cleanExit();
46114611 }
46124612}
......@@ -4636,7 +4636,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
46364636 if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip")) {
46374637 strip = true;
46384638 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
4639 try io.getStdOut().writeAll(usage_init);
4639 try fs.File.stdout().writeAll(usage_init);
46404640 return cleanExit();
46414641 } else {
46424642 fatal("unrecognized parameter: '{s}'", .{arg});
......@@ -5482,7 +5482,7 @@ fn jitCmd(
54825482
54835483 if (options.server) {
54845484 var server = std.zig.Server{
5485 .out = std.io.getStdOut(),
5485 .out = fs.File.stdout(),
54865486 .in = undefined, // won't be receiving messages
54875487 .receive_fifo = undefined, // won't be receiving messages
54885488 };
......@@ -6015,7 +6015,7 @@ fn cmdAstCheck(
60156015 const arg = args[i];
60166016 if (mem.startsWith(u8, arg, "-")) {
60176017 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6018 try io.getStdOut().writeAll(usage_ast_check);
6018 try fs.File.stdout().writeAll(usage_ast_check);
60196019 return cleanExit();
60206020 } else if (mem.eql(u8, arg, "-t")) {
60216021 want_output_text = true;
......@@ -6046,7 +6046,7 @@ fn cmdAstCheck(
60466046 break :file fs.cwd().openFile(p, .{}) catch |err| {
60476047 fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
60486048 };
6049 } else io.getStdIn();
6049 } else fs.File.stdin();
60506050 defer if (zig_source_path != null) f.close();
60516051 break :s std.zig.readSourceFileToEndAlloc(arena, f, null) catch |err| {
60526052 fatal("unable to load file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
......@@ -6107,7 +6107,7 @@ fn cmdAstCheck(
61076107 const extra_bytes = zir.extra.len * @sizeOf(u32);
61086108 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
61096109 zir.string_bytes.len * @sizeOf(u8);
6110 const stdout = io.getStdOut();
6110 const stdout = fs.File.stdout();
61116111 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
61126112 // zig fmt: off
61136113 try stdout.writer().print(
......@@ -6131,7 +6131,7 @@ fn cmdAstCheck(
61316131 // zig fmt: on
61326132 }
61336133
6134 try @import("print_zir.zig").renderAsTextToFile(arena, tree, zir, io.getStdOut());
6134 try @import("print_zir.zig").renderAsTextToFile(arena, tree, zir, fs.File.stdout());
61356135
61366136 if (zir.hasCompileErrors()) {
61376137 process.exit(1);
......@@ -6158,7 +6158,7 @@ fn cmdAstCheck(
61586158 fatal("-t option only available in builds of zig with debug extensions", .{});
61596159 }
61606160
6161 try @import("print_zoir.zig").renderToFile(zoir, arena, io.getStdOut());
6161 try @import("print_zoir.zig").renderToFile(zoir, arena, fs.File.stdout());
61626162 return cleanExit();
61636163 },
61646164 }
......@@ -6186,7 +6186,7 @@ fn cmdDetectCpu(args: []const []const u8) !void {
61866186 const arg = args[i];
61876187 if (mem.startsWith(u8, arg, "-")) {
61886188 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6189 const stdout = io.getStdOut().writer();
6189 const stdout = fs.File.stdout().writer();
61906190 try stdout.writeAll(detect_cpu_usage);
61916191 return cleanExit();
61926192 } else if (mem.eql(u8, arg, "--llvm")) {
......@@ -6279,7 +6279,7 @@ fn detectNativeCpuWithLLVM(
62796279}
62806280
62816281fn printCpu(cpu: std.Target.Cpu) !void {
6282 var bw = io.bufferedWriter(io.getStdOut().writer());
6282 var bw = io.bufferedWriter(fs.File.stdout().writer());
62836283 const stdout = bw.writer();
62846284
62856285 if (cpu.model.llvm_name) |llvm_name| {
......@@ -6328,7 +6328,7 @@ fn cmdDumpLlvmInts(
63286328 const dl = tm.createTargetDataLayout();
63296329 const context = llvm.Context.create();
63306330
6331 var bw = io.bufferedWriter(io.getStdOut().writer());
6331 var bw = io.bufferedWriter(fs.File.stdout().writer());
63326332 const stdout = bw.writer();
63336333
63346334 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
......@@ -6368,7 +6368,7 @@ fn cmdDumpZir(
63686368 const extra_bytes = zir.extra.len * @sizeOf(u32);
63696369 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
63706370 zir.string_bytes.len * @sizeOf(u8);
6371 const stdout = io.getStdOut();
6371 const stdout = fs.File.stdout();
63726372 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
63736373 // zig fmt: off
63746374 try stdout.writer().print(
......@@ -6386,7 +6386,7 @@ fn cmdDumpZir(
63866386 // zig fmt: on
63876387 }
63886388
6389 return @import("print_zir.zig").renderAsTextToFile(arena, null, zir, io.getStdOut());
6389 return @import("print_zir.zig").renderAsTextToFile(arena, null, zir, fs.File.stdout());
63906390}
63916391
63926392/// This is only enabled for debug builds.
......@@ -6444,7 +6444,7 @@ fn cmdChangelist(
64446444 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
64456445 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64466446
6447 var bw = io.bufferedWriter(io.getStdOut().writer());
6447 var bw = io.bufferedWriter(fs.File.stdout().writer());
64486448 const stdout = bw.writer();
64496449 {
64506450 try stdout.print("Instruction mappings:\n", .{});
......@@ -6794,7 +6794,7 @@ fn cmdFetch(
67946794 const arg = args[i];
67956795 if (mem.startsWith(u8, arg, "-")) {
67966796 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6797 const stdout = io.getStdOut().writer();
6797 const stdout = fs.File.stdout().writer();
67986798 try stdout.writeAll(usage_fetch);
67996799 return cleanExit();
68006800 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
......@@ -6908,7 +6908,7 @@ fn cmdFetch(
69086908
69096909 const name = switch (save) {
69106910 .no => {
6911 try io.getStdOut().writer().print("{s}\n", .{package_hash_slice});
6911 try fs.File.stdout().writer().print("{s}\n", .{package_hash_slice});
69126912 return cleanExit();
69136913 },
69146914 .yes, .exact => |name| name: {