authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 19:33:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:53-07:00
logd8e26275f29b304772bfeed9359e1ff5fe7038a8
treeb255b2a136beedb6a411ad0eae273354d9c4040c
parentc873c2eed9f9bcd4e8d8d6937ea7c3644d382440

update standalone and incremental tests to new API


72 files changed, 335 insertions(+), 880 deletions(-)

doc/langref.html.in+2-1
......@@ -374,7 +374,8 @@
374374 <p>
375375 Most of the time, it is more appropriate to write to stderr rather than stdout, and
376376 whether or not the message is successfully written to the stream is irrelevant.
377 For this common case, there is a simpler API:
377 Also, formatted printing often comes in handy. For this common case,
378 there is a simpler API:
378379 </p>
379380 {#code|hello_again.zig#}
380381
doc/langref/bad_default_value.zig+1-1
......@@ -17,7 +17,7 @@ pub fn main() !void {
1717 .maximum = 0.20,
1818 };
1919 const category = threshold.categorize(0.90);
20 try std.io.getStdOut().writeAll(@tagName(category));
20 try std.fs.File.stdout().writeAll(@tagName(category));
2121}
2222
2323const std = @import("std");
doc/langref/hello.zig+1-2
......@@ -1,8 +1,7 @@
11const std = @import("std");
22
33pub fn main() !void {
4 const stdout = std.io.getStdOut().writer();
5 try stdout.print("Hello, {s}!\n", .{"world"});
4 try std.fs.File.stdout().writeAll("Hello, World!\n");
65}
76
87// exe=succeed
doc/langref/hello_again.zig+1-1
......@@ -1,7 +1,7 @@
11const std = @import("std");
22
33pub fn main() void {
4 std.debug.print("Hello, world!\n", .{});
4 std.debug.print("Hello, {s}!\n", .{"World"});
55}
66
77// exe=succeed
lib/compiler/resinator/cli.zig+13-14
......@@ -125,13 +125,12 @@ pub const Diagnostics = struct {
125125 }
126126
127127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {
128 std.debug.lockStdErr();
129 defer std.debug.unlockStdErr();
130 const stderr = std.fs.File.stderr().deprecatedWriter();
128 const stderr = std.debug.lockStderrWriter(&.{});
129 defer std.debug.unlockStderrWriter();
131130 self.renderToWriter(args, stderr, config) catch return;
132131 }
133132
134 pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: anytype, config: std.io.tty.Config) !void {
133 pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: *std.io.Writer, config: std.io.tty.Config) !void {
135134 for (self.errors.items) |err_details| {
136135 try renderErrorMessage(writer, config, err_details, args);
137136 }
......@@ -1403,7 +1402,7 @@ test parsePercent {
14031402 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));
14041403}
14051404
1406pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
1405pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
14071406 try config.setColor(writer, .dim);
14081407 try writer.writeAll("<cli>");
14091408 try config.setColor(writer, .reset);
......@@ -1481,27 +1480,27 @@ pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, err_detail
14811480 try writer.writeByte('\n');
14821481
14831482 try config.setColor(writer, .green);
1484 try writer.writeByteNTimes(' ', prefix.len);
1483 try writer.splatByteAll(' ', prefix.len);
14851484 // Special case for when the option is *only* a prefix (e.g. invalid option: -)
14861485 if (err_details.arg_span.prefix_len == arg_with_name.len) {
1487 try writer.writeByteNTimes('^', err_details.arg_span.prefix_len);
1486 try writer.splatByteAll('^', err_details.arg_span.prefix_len);
14881487 } else {
1489 try writer.writeByteNTimes('~', err_details.arg_span.prefix_len);
1490 try writer.writeByteNTimes(' ', err_details.arg_span.name_offset - err_details.arg_span.prefix_len);
1488 try writer.splatByteAll('~', err_details.arg_span.prefix_len);
1489 try writer.splatByteAll(' ', err_details.arg_span.name_offset - err_details.arg_span.prefix_len);
14911490 if (!err_details.arg_span.point_at_next_arg and err_details.arg_span.value_offset == 0) {
14921491 try writer.writeByte('^');
1493 try writer.writeByteNTimes('~', name_slice.len - 1);
1492 try writer.splatByteAll('~', name_slice.len - 1);
14941493 } else if (err_details.arg_span.value_offset > 0) {
1495 try writer.writeByteNTimes('~', err_details.arg_span.value_offset - err_details.arg_span.name_offset);
1494 try writer.splatByteAll('~', err_details.arg_span.value_offset - err_details.arg_span.name_offset);
14961495 try writer.writeByte('^');
14971496 if (err_details.arg_span.value_offset < arg_with_name.len) {
1498 try writer.writeByteNTimes('~', arg_with_name.len - err_details.arg_span.value_offset - 1);
1497 try writer.splatByteAll('~', arg_with_name.len - err_details.arg_span.value_offset - 1);
14991498 }
15001499 } else if (err_details.arg_span.point_at_next_arg) {
1501 try writer.writeByteNTimes('~', arg_with_name.len - err_details.arg_span.name_offset + 1);
1500 try writer.splatByteAll('~', arg_with_name.len - err_details.arg_span.name_offset + 1);
15021501 try writer.writeByte('^');
15031502 if (next_arg_len > 0) {
1504 try writer.writeByteNTimes('~', next_arg_len - 1);
1503 try writer.splatByteAll('~', next_arg_len - 1);
15051504 }
15061505 }
15071506 }
lib/compiler/resinator/errors.zig+18-19
......@@ -62,9 +62,8 @@ pub const Diagnostics = struct {
6262 }
6363
6464 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {
65 std.debug.lockStdErr();
66 defer std.debug.unlockStdErr();
67 const stderr = std.fs.File.stderr().deprecatedWriter();
65 const stderr = std.debug.lockStderrWriter(&.{});
66 defer std.debug.unlockStderrWriter();
6867 for (self.errors.items) |err_details| {
6968 renderErrorMessage(stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return;
7069 }
......@@ -445,7 +444,7 @@ pub const ErrorDetails = struct {
445444 pub fn render(self: ErrorDetails, writer: anytype, source: []const u8, strings: []const []const u8) !void {
446445 switch (self.err) {
447446 .unfinished_string_literal => {
448 return writer.print("unfinished string literal at '{s}', expected closing '\"'", .{self.fmtToken(source)});
447 return writer.print("unfinished string literal at '{f}', expected closing '\"'", .{self.fmtToken(source)});
449448 },
450449 .string_literal_too_long => {
451450 return writer.print("string literal too long (max is currently {} characters)", .{self.extra.number});
......@@ -524,26 +523,26 @@ pub const ErrorDetails = struct {
524523 return writer.print("unsupported code page '{s} (id={})' in #pragma code_page", .{ @tagName(code_page), number });
525524 },
526525 .unfinished_raw_data_block => {
527 return writer.print("unfinished raw data block at '{s}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
526 return writer.print("unfinished raw data block at '{f}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
528527 },
529528 .unfinished_string_table_block => {
530 return writer.print("unfinished STRINGTABLE block at '{s}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
529 return writer.print("unfinished STRINGTABLE block at '{f}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
531530 },
532531 .expected_token => {
533 return writer.print("expected '{s}', got '{s}'", .{ self.extra.expected.nameForErrorDisplay(), self.fmtToken(source) });
532 return writer.print("expected '{s}', got '{f}'", .{ self.extra.expected.nameForErrorDisplay(), self.fmtToken(source) });
534533 },
535534 .expected_something_else => {
536535 try writer.writeAll("expected ");
537536 try self.extra.expected_types.writeCommaSeparated(writer);
538 return writer.print("; got '{s}'", .{self.fmtToken(source)});
537 return writer.print("; got '{f}'", .{self.fmtToken(source)});
539538 },
540539 .resource_type_cant_use_raw_data => switch (self.type) {
541 .err, .warning => try writer.print("expected '<filename>', found '{s}' (resource type '{s}' can't use raw data)", .{ self.fmtToken(source), self.extra.resource.nameForErrorDisplay() }),
542 .note => try writer.print("if '{s}' is intended to be a filename, it must be specified as a quoted string literal", .{self.fmtToken(source)}),
540 .err, .warning => try writer.print("expected '<filename>', found '{f}' (resource type '{s}' can't use raw data)", .{ self.fmtToken(source), self.extra.resource.nameForErrorDisplay() }),
541 .note => try writer.print("if '{f}' is intended to be a filename, it must be specified as a quoted string literal", .{self.fmtToken(source)}),
543542 .hint => return,
544543 },
545544 .id_must_be_ordinal => {
546 try writer.print("id of resource type '{s}' must be an ordinal (u16), got '{s}'", .{ self.extra.resource.nameForErrorDisplay(), self.fmtToken(source) });
545 try writer.print("id of resource type '{s}' must be an ordinal (u16), got '{f}'", .{ self.extra.resource.nameForErrorDisplay(), self.fmtToken(source) });
547546 },
548547 .name_or_id_not_allowed => {
549548 try writer.print("name or id is not allowed for resource type '{s}'", .{self.extra.resource.nameForErrorDisplay()});
......@@ -559,7 +558,7 @@ pub const ErrorDetails = struct {
559558 try writer.writeAll("ASCII character not equivalent to virtual key code");
560559 },
561560 .empty_menu_not_allowed => {
562 try writer.print("empty menu of type '{s}' not allowed", .{self.fmtToken(source)});
561 try writer.print("empty menu of type '{f}' not allowed", .{self.fmtToken(source)});
563562 },
564563 .rc_would_miscompile_version_value_padding => switch (self.type) {
565564 .err, .warning => return writer.print("the padding before this quoted string value would be miscompiled by the Win32 RC compiler", .{}),
......@@ -624,7 +623,7 @@ pub const ErrorDetails = struct {
624623 .string_already_defined => switch (self.type) {
625624 .err, .warning => {
626625 const language = self.extra.string_and_language.language;
627 return writer.print("string with id {d} (0x{X}) already defined for language {}", .{ self.extra.string_and_language.id, self.extra.string_and_language.id, language });
626 return writer.print("string with id {d} (0x{X}) already defined for language {f}", .{ self.extra.string_and_language.id, self.extra.string_and_language.id, language });
628627 },
629628 .note => return writer.print("previous definition of string with id {d} (0x{X}) here", .{ self.extra.string_and_language.id, self.extra.string_and_language.id }),
630629 .hint => return,
......@@ -639,7 +638,7 @@ pub const ErrorDetails = struct {
639638 try writer.print("unable to open file '{s}': {s}", .{ strings[self.extra.file_open_error.filename_string_index], @tagName(self.extra.file_open_error.err) });
640639 },
641640 .invalid_accelerator_key => {
642 try writer.print("invalid accelerator key '{s}': {s}", .{ self.fmtToken(source), @tagName(self.extra.accelerator_error.err) });
641 try writer.print("invalid accelerator key '{f}': {s}", .{ self.fmtToken(source), @tagName(self.extra.accelerator_error.err) });
643642 },
644643 .accelerator_type_required => {
645644 try writer.writeAll("accelerator type [ASCII or VIRTKEY] required when key is an integer");
......@@ -895,7 +894,7 @@ fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usiz
895894
896895const truncated_str = "<...truncated...>";
897896
898pub fn renderErrorMessage(writer: anytype, tty_config: std.io.tty.Config, cwd: std.fs.Dir, err_details: ErrorDetails, source: []const u8, strings: []const []const u8, source_mappings: ?SourceMappings) !void {
897pub fn renderErrorMessage(writer: *std.io.Writer, tty_config: std.io.tty.Config, cwd: std.fs.Dir, err_details: ErrorDetails, source: []const u8, strings: []const []const u8, source_mappings: ?SourceMappings) !void {
899898 if (err_details.type == .hint) return;
900899
901900 const source_line_start = err_details.token.getLineStartForErrorDisplay(source);
......@@ -978,10 +977,10 @@ pub fn renderErrorMessage(writer: anytype, tty_config: std.io.tty.Config, cwd: s
978977
979978 try tty_config.setColor(writer, .green);
980979 const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len;
981 try writer.writeByteNTimes(' ', num_spaces);
982 try writer.writeByteNTimes('~', truncated_visual_info.before_len);
980 try writer.splatByteAll(' ', num_spaces);
981 try writer.splatByteAll('~', truncated_visual_info.before_len);
983982 try writer.writeByte('^');
984 try writer.writeByteNTimes('~', truncated_visual_info.after_len);
983 try writer.splatByteAll('~', truncated_visual_info.after_len);
985984 try writer.writeByte('\n');
986985 try tty_config.setColor(writer, .reset);
987986
......@@ -1082,7 +1081,7 @@ const CorrespondingLines = struct {
10821081 buffered_reader: BufferedReaderType,
10831082 code_page: SupportedCodePage,
10841083
1085 const BufferedReaderType = std.io.BufferedReader(512, std.fs.File.Reader);
1084 const BufferedReaderType = std.io.BufferedReader(512, std.fs.File.DeprecatedReader);
10861085
10871086 pub fn init(cwd: std.fs.Dir, err_details: ErrorDetails, line_for_comparison: []const u8, corresponding_span: SourceMappings.CorrespondingSpan, corresponding_file: []const u8) !CorrespondingLines {
10881087 // We don't do line comparison for this error, so don't print the note if the line
lib/compiler/resinator/main.zig+10-6
......@@ -29,7 +29,7 @@ pub fn main() !void {
2929 defer std.process.argsFree(allocator, args);
3030
3131 if (args.len < 2) {
32 try renderErrorMessage(stderr.deprecatedWriter(), stderr_config, .err, "expected zig lib dir as first argument", .{});
32 try renderErrorMessage(std.debug.lockStderrWriter(&.{}), stderr_config, .err, "expected zig lib dir as first argument", .{});
3333 std.process.exit(1);
3434 }
3535 const zig_lib_dir = args[1];
......@@ -343,7 +343,7 @@ pub fn main() !void {
343343 switch (err) {
344344 error.DuplicateResource => {
345345 const duplicate_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
346 try error_handler.emitMessage(allocator, .err, "duplicate resource [id: {}, type: {}, language: {}]", .{
346 try error_handler.emitMessage(allocator, .err, "duplicate resource [id: {f}, type: {f}, language: {f}]", .{
347347 duplicate_resource.name_value,
348348 fmtResourceType(duplicate_resource.type_value),
349349 duplicate_resource.language,
......@@ -352,7 +352,7 @@ pub fn main() !void {
352352 error.ResourceDataTooLong => {
353353 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
354354 try error_handler.emitMessage(allocator, .err, "resource has a data length that is too large to be written into a coff section", .{});
355 try error_handler.emitMessage(allocator, .note, "the resource with the invalid size is [id: {}, type: {}, language: {}]", .{
355 try error_handler.emitMessage(allocator, .note, "the resource with the invalid size is [id: {f}, type: {f}, language: {f}]", .{
356356 overflow_resource.name_value,
357357 fmtResourceType(overflow_resource.type_value),
358358 overflow_resource.language,
......@@ -361,7 +361,7 @@ pub fn main() !void {
361361 error.TotalResourceDataTooLong => {
362362 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
363363 try error_handler.emitMessage(allocator, .err, "total resource data exceeds the maximum of the coff 'size of raw data' field", .{});
364 try error_handler.emitMessage(allocator, .note, "size overflow occurred when attempting to write this resource: [id: {}, type: {}, language: {}]", .{
364 try error_handler.emitMessage(allocator, .note, "size overflow occurred when attempting to write this resource: [id: {f}, type: {f}, language: {f}]", .{
365365 overflow_resource.name_value,
366366 fmtResourceType(overflow_resource.type_value),
367367 overflow_resource.language,
......@@ -645,7 +645,9 @@ const ErrorHandler = union(enum) {
645645 },
646646 .tty => {
647647 // extra newline to separate this line from the aro errors
648 try renderErrorMessage(std.fs.File.stderr().deprecatedWriter(), self.tty, .err, "{s}\n", .{fail_msg});
648 const stderr = std.debug.lockStderrWriter(&.{});
649 defer std.debug.unlockStderrWriter();
650 try renderErrorMessage(stderr, self.tty, .err, "{s}\n", .{fail_msg});
649651 aro.Diagnostics.render(comp, self.tty);
650652 },
651653 }
......@@ -690,7 +692,9 @@ const ErrorHandler = union(enum) {
690692 try server.serveErrorBundle(error_bundle);
691693 },
692694 .tty => {
693 try renderErrorMessage(std.fs.File.stderr().deprecatedWriter(), self.tty, msg_type, format, args);
695 const stderr = std.debug.lockStderrWriter(&.{});
696 defer std.debug.unlockStderrWriter();
697 try renderErrorMessage(stderr, self.tty, msg_type, format, args);
694698 },
695699 }
696700 }
lib/compiler/resinator/res.zig+2-2
......@@ -442,7 +442,7 @@ pub const NameOrOrdinal = union(enum) {
442442 pub fn format(self: NameOrOrdinal, w: *std.io.Writer) !void {
443443 switch (self) {
444444 .name => |name| {
445 try w.print("{s}", .{std.unicode.fmtUtf16Le(name)});
445 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
446446 },
447447 .ordinal => |ordinal| {
448448 try w.print("{d}", .{ordinal});
......@@ -453,7 +453,7 @@ pub const NameOrOrdinal = union(enum) {
453453 fn formatResourceType(self: NameOrOrdinal, w: *std.io.Writer) std.io.Writer.Error!void {
454454 switch (self) {
455455 .name => |name| {
456 try w.print("{s}", .{std.unicode.fmtUtf16Le(name)});
456 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
457457 },
458458 .ordinal => |ordinal| {
459459 if (std.enums.tagName(RT, @enumFromInt(ordinal))) |predefined_type_name| {
lib/compiler/resinator/utils.zig+1-1
......@@ -86,7 +86,7 @@ pub const ErrorMessageType = enum { err, warning, note };
8686
8787/// Used for generic colored errors/warnings/notes, more context-specific error messages
8888/// are handled elsewhere.
89pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
89pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
9090 switch (msg_type) {
9191 .err => {
9292 try config.setColor(writer, .bold);
lib/fuzzer.zig+12-9
......@@ -9,7 +9,8 @@ pub const std_options = std.Options{
99 .logFn = logOverride,
1010};
1111
12var log_file: ?std.fs.File = null;
12var log_file_buffer: [256]u8 = undefined;
13var log_file_writer: ?std.fs.File.Writer = null;
1314
1415fn logOverride(
1516 comptime level: std.log.Level,
......@@ -17,15 +18,17 @@ fn logOverride(
1718 comptime format: []const u8,
1819 args: anytype,
1920) void {
20 const f = if (log_file) |f| f else f: {
21 const fw = if (log_file_writer) |*f| f else f: {
2122 const f = fuzzer.cache_dir.createFile("tmp/libfuzzer.log", .{}) catch
2223 @panic("failed to open fuzzer log file");
23 log_file = f;
24 break :f f;
24 log_file_writer = f.writer(&log_file_buffer);
25 break :f &log_file_writer.?;
2526 };
2627 const prefix1 = comptime level.asText();
2728 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
28 f.writer().print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch @panic("failed to write to fuzzer log");
29 fw.interface.print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch
30 @panic("failed to write to fuzzer log");
31 fw.interface.flush() catch @panic("failed to flush fuzzer log");
2932}
3033
3134/// Helps determine run uniqueness in the face of recursion.
......@@ -226,18 +229,18 @@ const Fuzzer = struct {
226229 .read = true,
227230 }) catch |e| switch (e) {
228231 error.PathAlreadyExists => continue,
229 else => fatal("unable to create '{}{d}: {s}", .{ f.corpus_directory, i, @errorName(err) }),
232 else => fatal("unable to create '{f}{d}: {s}", .{ f.corpus_directory, i, @errorName(err) }),
230233 };
231234 errdefer input_file.close();
232235 // Initialize the mmap for the current input.
233236 f.input = MemoryMappedList.create(input_file, 0, std.heap.page_size_max) catch |e| {
234 fatal("unable to init memory map for input at '{}{d}': {s}", .{
237 fatal("unable to init memory map for input at '{f}{d}': {s}", .{
235238 f.corpus_directory, i, @errorName(e),
236239 });
237240 };
238241 break;
239242 },
240 else => fatal("unable to read '{}{d}': {s}", .{ f.corpus_directory, i, @errorName(err) }),
243 else => fatal("unable to read '{f}{d}': {s}", .{ f.corpus_directory, i, @errorName(err) }),
241244 };
242245 errdefer gpa.free(input);
243246 f.corpus.append(gpa, .{
......@@ -263,7 +266,7 @@ const Fuzzer = struct {
263266 const sub_path = try std.fmt.allocPrint(gpa, "f/{s}", .{f.unit_test_name});
264267 f.corpus_directory = .{
265268 .handle = f.cache_dir.makeOpenPath(sub_path, .{}) catch |err|
266 fatal("unable to open corpus directory 'f/{s}': {s}", .{ sub_path, @errorName(err) }),
269 fatal("unable to open corpus directory 'f/{s}': {t}", .{ sub_path, err }),
267270 .path = sub_path,
268271 };
269272 initNextInput(f);
lib/std/elf.zig+5-5
......@@ -511,7 +511,7 @@ pub const Header = struct {
511511 pub fn read(parse_source: anytype) !Header {
512512 var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined;
513513 try parse_source.seekableStream().seekTo(0);
514 try parse_source.reader().readNoEof(&hdr_buf);
514 try parse_source.deprecatedReader().readNoEof(&hdr_buf);
515515 return Header.parse(&hdr_buf);
516516 }
517517
......@@ -586,7 +586,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {
586586 var phdr: Elf64_Phdr = undefined;
587587 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
588588 try self.parse_source.seekableStream().seekTo(offset);
589 try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));
589 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&phdr));
590590
591591 // ELF endianness matches native endianness.
592592 if (self.elf_header.endian == native_endian) return phdr;
......@@ -599,7 +599,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {
599599 var phdr: Elf32_Phdr = undefined;
600600 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
601601 try self.parse_source.seekableStream().seekTo(offset);
602 try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));
602 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&phdr));
603603
604604 // ELF endianness does NOT match native endianness.
605605 if (self.elf_header.endian != native_endian) {
......@@ -636,7 +636,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {
636636 var shdr: Elf64_Shdr = undefined;
637637 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
638638 try self.parse_source.seekableStream().seekTo(offset);
639 try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));
639 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&shdr));
640640
641641 // ELF endianness matches native endianness.
642642 if (self.elf_header.endian == native_endian) return shdr;
......@@ -649,7 +649,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {
649649 var shdr: Elf32_Shdr = undefined;
650650 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
651651 try self.parse_source.seekableStream().seekTo(offset);
652 try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));
652 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&shdr));
653653
654654 // ELF endianness does NOT match native endianness.
655655 if (self.elf_header.endian != native_endian) {
lib/std/io/Writer.zig+2
......@@ -705,6 +705,8 @@ pub fn sendFileReading(w: *Writer, file_reader: *File.Reader, limit: Limit) File
705705 return n;
706706}
707707
708/// Number of bytes logically written is returned. This excludes bytes from
709/// `buffer` because they have already been logically written.
708710pub fn sendFileAll(w: *Writer, file_reader: *File.Reader, limit: Limit) FileAllError!usize {
709711 var remaining = @intFromEnum(limit);
710712 while (remaining > 0) {
lib/std/os/windows.zig+2-3
......@@ -2812,9 +2812,8 @@ pub fn unexpectedError(err: Win32Error) UnexpectedError {
28122812 buf_wstr.len,
28132813 null,
28142814 );
2815 std.debug.print("error.Unexpected: GetLastError({}): {}\n", .{
2816 @intFromEnum(err),
2817 std.unicode.fmtUtf16Le(buf_wstr[0..len]),
2815 std.debug.print("error.Unexpected: GetLastError({d}): {f}\n", .{
2816 err, std.unicode.fmtUtf16Le(buf_wstr[0..len]),
28182817 });
28192818 std.debug.dumpCurrentStackTrace(@returnAddress());
28202819 }
lib/std/zig/parser_test.zig+4-4
......@@ -2744,11 +2744,11 @@ test "zig fmt: preserve spacing" {
27442744 \\const std = @import("std");
27452745 \\
27462746 \\pub fn main() !void {
2747 \\ var stdout_file = std.io.getStdOut;
2748 \\ var stdout_file = std.io.getStdOut;
2747 \\ var stdout_file = std.lol.abcd;
2748 \\ var stdout_file = std.lol.abcd;
27492749 \\
2750 \\ var stdout_file = std.io.getStdOut;
2751 \\ var stdout_file = std.io.getStdOut;
2750 \\ var stdout_file = std.lol.abcd;
2751 \\ var stdout_file = std.lol.abcd;
27522752 \\}
27532753 \\
27542754 );
src/main.zig+6-6
......@@ -6074,7 +6074,7 @@ fn cmdAstCheck(
60746074
60756075 const tree = try Ast.parse(arena, source, mode);
60766076
6077 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6077 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
60786078 const stdout_bw = &stdout_writer.interface;
60796079 switch (mode) {
60806080 .zig => {
......@@ -6289,7 +6289,7 @@ fn detectNativeCpuWithLLVM(
62896289}
62906290
62916291fn printCpu(cpu: std.Target.Cpu) !void {
6292 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6292 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
62936293 const stdout_bw = &stdout_writer.interface;
62946294
62956295 if (cpu.model.llvm_name) |llvm_name| {
......@@ -6338,7 +6338,7 @@ fn cmdDumpLlvmInts(
63386338 const dl = tm.createTargetDataLayout();
63396339 const context = llvm.Context.create();
63406340
6341 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6341 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
63426342 const stdout_bw = &stdout_writer.interface;
63436343 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
63446344 const int_type = context.intType(bits);
......@@ -6367,7 +6367,7 @@ fn cmdDumpZir(
63676367 defer f.close();
63686368
63696369 const zir = try Zcu.loadZirCache(arena, f);
6370 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6370 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
63716371 const stdout_bw = &stdout_writer.interface;
63726372
63736373 {
......@@ -6453,7 +6453,7 @@ fn cmdChangelist(
64536453 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
64546454 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64556455
6456 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6456 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
64576457 const stdout_bw = &stdout_writer.interface;
64586458 {
64596459 try stdout_bw.print("Instruction mappings:\n", .{});
......@@ -6913,7 +6913,7 @@ fn cmdFetch(
69136913
69146914 const name = switch (save) {
69156915 .no => {
6916 var stdout = fs.File.stdout().writer(&stdio_buffer);
6916 var stdout = fs.File.stdout().writerStreaming(&stdio_buffer);
69176917 try stdout.interface.print("{s}\n", .{package_hash_slice});
69186918 try stdout.interface.flush();
69196919 return cleanExit();
test/compare_output.zig+3-286
......@@ -17,15 +17,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
1717 \\}
1818 , "Hello, world!" ++ if (@import("builtin").os.tag == .windows) "\r\n" else "\n");
1919
20 cases.add("hello world without libc",
21 \\const io = @import("std").io;
22 \\
23 \\pub fn main() void {
24 \\ const stdout = io.getStdOut().writer();
25 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable;
26 \\}
27 , "Hello, world!\n 12 12 a\n");
28
2920 cases.addC("number literals",
3021 \\const std = @import("std");
3122 \\const builtin = @import("builtin");
......@@ -158,24 +149,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
158149 \\
159150 );
160151
161 cases.add("order-independent declarations",
162 \\const io = @import("std").io;
163 \\const z = io.stdin_fileno;
164 \\const x : @TypeOf(y) = 1234;
165 \\const y : u16 = 5678;
166 \\pub fn main() void {
167 \\ var x_local : i32 = print_ok(x);
168 \\ _ = &x_local;
169 \\}
170 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
171 \\ _ = val;
172 \\ const stdout = io.getStdOut().writer();
173 \\ stdout.print("OK\n", .{}) catch unreachable;
174 \\ return 0;
175 \\}
176 \\const foo : i32 = 0;
177 , "OK\n");
178
179152 cases.addC("expose function pointer to C land",
180153 \\const c = @cImport(@cInclude("stdlib.h"));
181154 \\
......@@ -236,267 +209,11 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
236209 \\}
237210 , "3.25\n3\n3.00\n-0.40\n");
238211
239 cases.add("same named methods in incomplete struct",
240 \\const io = @import("std").io;
241 \\
242 \\const Foo = struct {
243 \\ field1: Bar,
244 \\
245 \\ fn method(a: *const Foo) bool {
246 \\ _ = a;
247 \\ return true;
248 \\ }
249 \\};
250 \\
251 \\const Bar = struct {
252 \\ field2: i32,
253 \\
254 \\ fn method(b: *const Bar) bool {
255 \\ _ = b;
256 \\ return true;
257 \\ }
258 \\};
259 \\
260 \\pub fn main() void {
261 \\ const bar = Bar {.field2 = 13,};
262 \\ const foo = Foo {.field1 = bar,};
263 \\ const stdout = io.getStdOut().writer();
264 \\ if (!foo.method()) {
265 \\ stdout.print("BAD\n", .{}) catch unreachable;
266 \\ }
267 \\ if (!bar.method()) {
268 \\ stdout.print("BAD\n", .{}) catch unreachable;
269 \\ }
270 \\ stdout.print("OK\n", .{}) catch unreachable;
271 \\}
272 , "OK\n");
273
274 cases.add("defer with only fallthrough",
275 \\const io = @import("std").io;
276 \\pub fn main() void {
277 \\ const stdout = io.getStdOut().writer();
278 \\ stdout.print("before\n", .{}) catch unreachable;
279 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
280 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
281 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
282 \\ stdout.print("after\n", .{}) catch unreachable;
283 \\}
284 , "before\nafter\ndefer3\ndefer2\ndefer1\n");
285
286 cases.add("defer with return",
287 \\const io = @import("std").io;
288 \\const os = @import("std").os;
289 \\pub fn main() void {
290 \\ const stdout = io.getStdOut().writer();
291 \\ stdout.print("before\n", .{}) catch unreachable;
292 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
293 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
294 \\ var gpa: @import("std").heap.GeneralPurposeAllocator(.{}) = .init;
295 \\ defer _ = gpa.deinit();
296 \\ var arena = @import("std").heap.ArenaAllocator.init(gpa.allocator());
297 \\ defer arena.deinit();
298 \\ var args_it = @import("std").process.argsWithAllocator(arena.allocator()) catch unreachable;
299 \\ if (args_it.skip() and !args_it.skip()) return;
300 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
301 \\ stdout.print("after\n", .{}) catch unreachable;
302 \\}
303 , "before\ndefer2\ndefer1\n");
304
305 cases.add("errdefer and it fails",
306 \\const io = @import("std").io;
307 \\pub fn main() void {
308 \\ do_test() catch return;
309 \\}
310 \\fn do_test() !void {
311 \\ const stdout = io.getStdOut().writer();
312 \\ stdout.print("before\n", .{}) catch unreachable;
313 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
314 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
315 \\ try its_gonna_fail();
316 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
317 \\ stdout.print("after\n", .{}) catch unreachable;
318 \\}
319 \\fn its_gonna_fail() !void {
320 \\ return error.IToldYouItWouldFail;
321 \\}
322 , "before\ndeferErr\ndefer1\n");
323
324 cases.add("errdefer and it passes",
325 \\const io = @import("std").io;
326 \\pub fn main() void {
327 \\ do_test() catch return;
328 \\}
329 \\fn do_test() !void {
330 \\ const stdout = io.getStdOut().writer();
331 \\ stdout.print("before\n", .{}) catch unreachable;
332 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
333 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
334 \\ try its_gonna_pass();
335 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
336 \\ stdout.print("after\n", .{}) catch unreachable;
337 \\}
338 \\fn its_gonna_pass() anyerror!void { }
339 , "before\nafter\ndefer3\ndefer1\n");
340
341 cases.addCase(x: {
342 var tc = cases.create("@embedFile",
343 \\const foo_txt = @embedFile("foo.txt");
344 \\const io = @import("std").io;
345 \\
346 \\pub fn main() void {
347 \\ const stdout = io.getStdOut().writer();
348 \\ stdout.print(foo_txt, .{}) catch unreachable;
349 \\}
350 , "1234\nabcd\n");
351
352 tc.addSourceFile("foo.txt", "1234\nabcd\n");
353
354 break :x tc;
355 });
356
357 cases.addCase(x: {
358 var tc = cases.create("parsing args",
359 \\const std = @import("std");
360 \\const io = std.io;
361 \\const os = std.os;
362 \\
363 \\pub fn main() !void {
364 \\ var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
365 \\ defer _ = gpa.deinit();
366 \\ var arena = std.heap.ArenaAllocator.init(gpa.allocator());
367 \\ defer arena.deinit();
368 \\ var args_it = try std.process.argsWithAllocator(arena.allocator());
369 \\ const stdout = io.getStdOut().writer();
370 \\ var index: usize = 0;
371 \\ _ = args_it.skip();
372 \\ while (args_it.next()) |arg| : (index += 1) {
373 \\ try stdout.print("{}: {s}\n", .{index, arg});
374 \\ }
375 \\}
376 ,
377 \\0: first arg
378 \\1: 'a' 'b' \
379 \\2: bare
380 \\3: ba""re
381 \\4: "
382 \\5: last arg
383 \\
384 );
385
386 tc.setCommandLineArgs(&[_][]const u8{
387 "first arg",
388 "'a' 'b' \\",
389 "bare",
390 "ba\"\"re",
391 "\"",
392 "last arg",
393 });
394
395 break :x tc;
396 });
397
398 cases.addCase(x: {
399 var tc = cases.create("parsing args new API",
400 \\const std = @import("std");
401 \\const io = std.io;
402 \\const os = std.os;
403 \\
404 \\pub fn main() !void {
405 \\ var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
406 \\ defer _ = gpa.deinit();
407 \\ var arena = std.heap.ArenaAllocator.init(gpa.allocator());
408 \\ defer arena.deinit();
409 \\ var args_it = try std.process.argsWithAllocator(arena.allocator());
410 \\ const stdout = io.getStdOut().writer();
411 \\ var index: usize = 0;
412 \\ _ = args_it.skip();
413 \\ while (args_it.next()) |arg| : (index += 1) {
414 \\ try stdout.print("{}: {s}\n", .{index, arg});
415 \\ }
416 \\}
417 ,
418 \\0: first arg
419 \\1: 'a' 'b' \
420 \\2: bare
421 \\3: ba""re
422 \\4: "
423 \\5: last arg
424 \\
425 );
426
427 tc.setCommandLineArgs(&[_][]const u8{
428 "first arg",
429 "'a' 'b' \\",
430 "bare",
431 "ba\"\"re",
432 "\"",
433 "last arg",
434 });
435
436 break :x tc;
437 });
438
439 // It is required to override the log function in order to print to stdout instead of stderr
440 cases.add("std.log per scope log level override",
441 \\const std = @import("std");
442 \\
443 \\pub const std_options: std.Options = .{
444 \\ .log_level = .debug,
445 \\
446 \\ .log_scope_levels = &.{
447 \\ .{ .scope = .a, .level = .warn },
448 \\ .{ .scope = .c, .level = .err },
449 \\ },
450 \\ .logFn = log,
451 \\};
452 \\
453 \\const loga = std.log.scoped(.a);
454 \\const logb = std.log.scoped(.b);
455 \\const logc = std.log.scoped(.c);
456 \\
457 \\pub fn main() !void {
458 \\ loga.debug("", .{});
459 \\ logb.debug("", .{});
460 \\ logc.debug("", .{});
461 \\
462 \\ loga.info("", .{});
463 \\ logb.info("", .{});
464 \\ logc.info("", .{});
465 \\
466 \\ loga.warn("", .{});
467 \\ logb.warn("", .{});
468 \\ logc.warn("", .{});
469 \\
470 \\ loga.err("", .{});
471 \\ logb.err("", .{});
472 \\ logc.err("", .{});
473 \\}
474 \\pub fn log(
475 \\ comptime level: std.log.Level,
476 \\ comptime scope: @TypeOf(.EnumLiteral),
477 \\ comptime format: []const u8,
478 \\ args: anytype,
479 \\) void {
480 \\ const level_txt = comptime level.asText();
481 \\ const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "):";
482 \\ const stdout = std.io.getStdOut().writer();
483 \\ nosuspend stdout.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
484 \\}
485 ,
486 \\debug(b):
487 \\info(b):
488 \\warning(a):
489 \\warning(b):
490 \\error(a):
491 \\error(b):
492 \\error(c):
493 \\
494 );
495
496 cases.add("valid carriage return example", "const io = @import(\"std\").io;\r\n" ++ // Testing CRLF line endings are valid
212 cases.add("valid carriage return example", "const std = @import(\"std\");\r\n" ++ // Testing CRLF line endings are valid
497213 "\r\n" ++
498214 "pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid
499 " const stdout = io.getStdOut().writer();\r\n" ++
215 " var file_writer = std.fs.File.stdout().writerStreaming(&.{});\r\n" ++
216 " const stdout = &file_writer.interface;\r\n" ++
500217 " stdout.print(\\\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output
501218 " \\\\String\r\n" ++
502219 " , .{}) catch unreachable;\r\n" ++
test/incremental/add_decl+7-7
......@@ -6,7 +6,7 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writeAll(foo);
9 try std.fs.File.stdout().writeAll(foo);
1010}
1111const foo = "good morning\n";
1212#expect_stdout="good morning\n"
......@@ -15,7 +15,7 @@ const foo = "good morning\n";
1515#file=main.zig
1616const std = @import("std");
1717pub fn main() !void {
18 try std.io.getStdOut().writeAll(foo);
18 try std.fs.File.stdout().writeAll(foo);
1919}
2020const foo = "good morning\n";
2121const bar = "good evening\n";
......@@ -25,7 +25,7 @@ const bar = "good evening\n";
2525#file=main.zig
2626const std = @import("std");
2727pub fn main() !void {
28 try std.io.getStdOut().writeAll(bar);
28 try std.fs.File.stdout().writeAll(bar);
2929}
3030const foo = "good morning\n";
3131const bar = "good evening\n";
......@@ -35,17 +35,17 @@ const bar = "good evening\n";
3535#file=main.zig
3636const std = @import("std");
3737pub fn main() !void {
38 try std.io.getStdOut().writeAll(qux);
38 try std.fs.File.stdout().writeAll(qux);
3939}
4040const foo = "good morning\n";
4141const bar = "good evening\n";
42#expect_error=main.zig:3:37: error: use of undeclared identifier 'qux'
42#expect_error=main.zig:3:39: error: use of undeclared identifier 'qux'
4343
4444#update=add missing declaration
4545#file=main.zig
4646const std = @import("std");
4747pub fn main() !void {
48 try std.io.getStdOut().writeAll(qux);
48 try std.fs.File.stdout().writeAll(qux);
4949}
5050const foo = "good morning\n";
5151const bar = "good evening\n";
......@@ -56,7 +56,7 @@ const qux = "good night\n";
5656#file=main.zig
5757const std = @import("std");
5858pub fn main() !void {
59 try std.io.getStdOut().writeAll(qux);
59 try std.fs.File.stdout().writeAll(qux);
6060}
6161const qux = "good night\n";
6262#expect_stdout="good night\n"
test/incremental/add_decl_namespaced+7-7
......@@ -6,7 +6,7 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writeAll(@This().foo);
9 try std.fs.File.stdout().writeAll(@This().foo);
1010}
1111const foo = "good morning\n";
1212#expect_stdout="good morning\n"
......@@ -15,7 +15,7 @@ const foo = "good morning\n";
1515#file=main.zig
1616const std = @import("std");
1717pub fn main() !void {
18 try std.io.getStdOut().writeAll(@This().foo);
18 try std.fs.File.stdout().writeAll(@This().foo);
1919}
2020const foo = "good morning\n";
2121const bar = "good evening\n";
......@@ -25,7 +25,7 @@ const bar = "good evening\n";
2525#file=main.zig
2626const std = @import("std");
2727pub fn main() !void {
28 try std.io.getStdOut().writeAll(@This().bar);
28 try std.fs.File.stdout().writeAll(@This().bar);
2929}
3030const foo = "good morning\n";
3131const bar = "good evening\n";
......@@ -35,18 +35,18 @@ const bar = "good evening\n";
3535#file=main.zig
3636const std = @import("std");
3737pub fn main() !void {
38 try std.io.getStdOut().writeAll(@This().qux);
38 try std.fs.File.stdout().writeAll(@This().qux);
3939}
4040const foo = "good morning\n";
4141const bar = "good evening\n";
42#expect_error=main.zig:3:44: error: root source file struct 'main' has no member named 'qux'
42#expect_error=main.zig:3:46: error: root source file struct 'main' has no member named 'qux'
4343#expect_error=main.zig:1:1: note: struct declared here
4444
4545#update=add missing declaration
4646#file=main.zig
4747const std = @import("std");
4848pub fn main() !void {
49 try std.io.getStdOut().writeAll(@This().qux);
49 try std.fs.File.stdout().writeAll(@This().qux);
5050}
5151const foo = "good morning\n";
5252const bar = "good evening\n";
......@@ -57,7 +57,7 @@ const qux = "good night\n";
5757#file=main.zig
5858const std = @import("std");
5959pub fn main() !void {
60 try std.io.getStdOut().writeAll(@This().qux);
60 try std.fs.File.stdout().writeAll(@This().qux);
6161}
6262const qux = "good night\n";
6363#expect_stdout="good night\n"
test/incremental/bad_import+2-2
......@@ -7,7 +7,7 @@
77#file=main.zig
88pub fn main() !void {
99 _ = @import("foo.zig");
10 try std.io.getStdOut().writeAll("success\n");
10 try std.fs.File.stdout().writeAll("success\n");
1111}
1212const std = @import("std");
1313#file=foo.zig
......@@ -29,7 +29,7 @@ comptime {
2929#file=main.zig
3030pub fn main() !void {
3131 //_ = @import("foo.zig");
32 try std.io.getStdOut().writeAll("success\n");
32 try std.fs.File.stdout().writeAll("success\n");
3333}
3434const std = @import("std");
3535#expect_stdout="success\n"
test/incremental/change_embed_file+3-3
......@@ -7,7 +7,7 @@
77const std = @import("std");
88const string = @embedFile("string.txt");
99pub fn main() !void {
10 try std.io.getStdOut().writeAll(string);
10 try std.fs.File.stdout().writeAll(string);
1111}
1212#file=string.txt
1313Hello, World!
......@@ -27,7 +27,7 @@ Hello again, World!
2727const std = @import("std");
2828const string = @embedFile("string.txt");
2929pub fn main() !void {
30 try std.io.getStdOut().writeAll("a hardcoded string\n");
30 try std.fs.File.stdout().writeAll("a hardcoded string\n");
3131}
3232#expect_stdout="a hardcoded string\n"
3333
......@@ -36,7 +36,7 @@ pub fn main() !void {
3636const std = @import("std");
3737const string = @embedFile("string.txt");
3838pub fn main() !void {
39 try std.io.getStdOut().writeAll(string);
39 try std.fs.File.stdout().writeAll(string);
4040}
4141#expect_error=main.zig:2:27: error: unable to open 'string.txt': FileNotFound
4242
test/incremental/change_enum_tag_type+6-3
......@@ -14,7 +14,8 @@ const Foo = enum(Tag) {
1414pub fn main() !void {
1515 var val: Foo = undefined;
1616 val = .a;
17 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});
17 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
18 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
1819}
1920const std = @import("std");
2021#expect_stdout="a\n"
......@@ -31,7 +32,8 @@ const Foo = enum(Tag) {
3132pub fn main() !void {
3233 var val: Foo = undefined;
3334 val = .a;
34 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});
35 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
36 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
3537}
3638comptime {
3739 // These can't be true at the same time; analysis should stop as soon as it sees `Foo`
......@@ -53,7 +55,8 @@ const Foo = enum(Tag) {
5355pub fn main() !void {
5456 var val: Foo = undefined;
5557 val = .a;
56 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});
58 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
59 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
5760}
5861const std = @import("std");
5962#expect_stdout="a\n"
test/incremental/change_exports+12-6
......@@ -16,7 +16,8 @@ pub fn main() !void {
1616 extern const bar: u32;
1717 };
1818 S.foo();
19 try std.io.getStdOut().writer().print("{}\n", .{S.bar});
19 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
20 try stdout_writer.interface.print("{}\n", .{S.bar});
2021}
2122const std = @import("std");
2223#expect_stdout="123\n"
......@@ -37,7 +38,8 @@ pub fn main() !void {
3738 extern const other: u32;
3839 };
3940 S.foo();
40 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });
41 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
42 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
4143}
4244const std = @import("std");
4345#expect_error=main.zig:6:5: error: exported symbol collision: foo
......@@ -59,7 +61,8 @@ pub fn main() !void {
5961 extern const other: u32;
6062 };
6163 S.foo();
62 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });
64 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
65 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
6366}
6467const std = @import("std");
6568#expect_stdout="123 456\n"
......@@ -83,7 +86,8 @@ pub fn main() !void {
8386 extern const other: u32;
8487 };
8588 S.foo();
86 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });
89 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
90 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
8791}
8892const std = @import("std");
8993#expect_stdout="123 456\n"
......@@ -128,7 +132,8 @@ pub fn main() !void {
128132 extern const other: u32;
129133 };
130134 S.foo();
131 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });
135 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
136 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
132137}
133138const std = @import("std");
134139#expect_stdout="123 456\n"
......@@ -152,7 +157,8 @@ pub fn main() !void {
152157 extern const other: u32;
153158 };
154159 S.foo();
155 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });
160 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
161 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
156162}
157163const std = @import("std");
158164#expect_error=main.zig:5:5: error: exported symbol collision: bar
test/incremental/change_fn_type+6-3
......@@ -7,7 +7,8 @@ pub fn main() !void {
77 try foo(123);
88}
99fn foo(x: u8) !void {
10 return std.io.getStdOut().writer().print("{d}\n", .{x});
10 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
11 return stdout_writer.interface.print("{d}\n", .{x});
1112}
1213const std = @import("std");
1314#expect_stdout="123\n"
......@@ -18,7 +19,8 @@ pub fn main() !void {
1819 try foo(123);
1920}
2021fn foo(x: i64) !void {
21 return std.io.getStdOut().writer().print("{d}\n", .{x});
22 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
23 return stdout_writer.interface.print("{d}\n", .{x});
2224}
2325const std = @import("std");
2426#expect_stdout="123\n"
......@@ -29,7 +31,8 @@ pub fn main() !void {
2931 try foo(-42);
3032}
3133fn foo(x: i64) !void {
32 return std.io.getStdOut().writer().print("{d}\n", .{x});
34 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
35 return stdout_writer.interface.print("{d}\n", .{x});
3336}
3437const std = @import("std");
3538#expect_stdout="-42\n"
test/incremental/change_generic_line_number+2-2
......@@ -6,7 +6,7 @@ const std = @import("std");
66fn Printer(message: []const u8) type {
77 return struct {
88 fn print() !void {
9 try std.io.getStdOut().writeAll(message);
9 try std.fs.File.stdout().writeAll(message);
1010 }
1111 };
1212}
......@@ -22,7 +22,7 @@ const std = @import("std");
2222fn Printer(message: []const u8) type {
2323 return struct {
2424 fn print() !void {
25 try std.io.getStdOut().writeAll(message);
25 try std.fs.File.stdout().writeAll(message);
2626 }
2727 };
2828}
test/incremental/change_line_number+2-2
......@@ -4,7 +4,7 @@
44#file=main.zig
55const std = @import("std");
66pub fn main() !void {
7 try std.io.getStdOut().writeAll("foo\n");
7 try std.fs.File.stdout().writeAll("foo\n");
88}
99#expect_stdout="foo\n"
1010#update=change line number
......@@ -12,6 +12,6 @@ pub fn main() !void {
1212const std = @import("std");
1313
1414pub fn main() !void {
15 try std.io.getStdOut().writeAll("foo\n");
15 try std.fs.File.stdout().writeAll("foo\n");
1616}
1717#expect_stdout="foo\n"
test/incremental/change_panic_handler+6-3
......@@ -11,7 +11,8 @@ pub fn main() !u8 {
1111}
1212pub const panic = std.debug.FullPanic(myPanic);
1313fn myPanic(msg: []const u8, _: ?usize) noreturn {
14 std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {};
14 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
15 stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {};
1516 std.process.exit(0);
1617}
1718const std = @import("std");
......@@ -27,7 +28,8 @@ pub fn main() !u8 {
2728}
2829pub const panic = std.debug.FullPanic(myPanic);
2930fn myPanic(msg: []const u8, _: ?usize) noreturn {
30 std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {};
31 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
32 stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {};
3133 std.process.exit(0);
3234}
3335const std = @import("std");
......@@ -43,7 +45,8 @@ pub fn main() !u8 {
4345}
4446pub const panic = std.debug.FullPanic(myPanicNew);
4547fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
46 std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {};
48 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
49 stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
4750 std.process.exit(0);
4851}
4952const std = @import("std");
test/incremental/change_panic_handler_explicit+6-3
......@@ -41,7 +41,8 @@ pub const panic = struct {
4141 pub const noreturnReturned = no_panic.noreturnReturned;
4242};
4343fn myPanic(msg: []const u8, _: ?usize) noreturn {
44 std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {};
44 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
45 stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {};
4546 std.process.exit(0);
4647}
4748const std = @import("std");
......@@ -87,7 +88,8 @@ pub const panic = struct {
8788 pub const noreturnReturned = no_panic.noreturnReturned;
8889};
8990fn myPanic(msg: []const u8, _: ?usize) noreturn {
90 std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {};
91 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
92 stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {};
9193 std.process.exit(0);
9294}
9395const std = @import("std");
......@@ -133,7 +135,8 @@ pub const panic = struct {
133135 pub const noreturnReturned = no_panic.noreturnReturned;
134136};
135137fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
136 std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {};
138 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
139 stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
137140 std.process.exit(0);
138141}
139142const std = @import("std");
test/incremental/change_shift_op+4-2
......@@ -8,7 +8,8 @@ pub fn main() !void {
88 try foo(0x1300);
99}
1010fn foo(x: u16) !void {
11 try std.io.getStdOut().writer().print("0x{x}\n", .{x << 4});
11 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
12 try stdout_writer.interface.print("0x{x}\n", .{x << 4});
1213}
1314const std = @import("std");
1415#expect_stdout="0x3000\n"
......@@ -18,7 +19,8 @@ pub fn main() !void {
1819 try foo(0x1300);
1920}
2021fn foo(x: u16) !void {
21 try std.io.getStdOut().writer().print("0x{x}\n", .{x >> 4});
22 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
23 try stdout_writer.interface.print("0x{x}\n", .{x >> 4});
2224}
2325const std = @import("std");
2426#expect_stdout="0x130\n"
test/incremental/change_struct_same_fields+6-3
......@@ -10,7 +10,8 @@ pub fn main() !void {
1010 try foo(&val);
1111}
1212fn foo(val: *const S) !void {
13 try std.io.getStdOut().writer().print(
13 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
14 try stdout_writer.interface.print(
1415 "{d} {d}\n",
1516 .{ val.x, val.y },
1617 );
......@@ -26,7 +27,8 @@ pub fn main() !void {
2627 try foo(&val);
2728}
2829fn foo(val: *const S) !void {
29 try std.io.getStdOut().writer().print(
30 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
31 try stdout_writer.interface.print(
3032 "{d} {d}\n",
3133 .{ val.x, val.y },
3234 );
......@@ -42,7 +44,8 @@ pub fn main() !void {
4244 try foo(&val);
4345}
4446fn foo(val: *const S) !void {
45 try std.io.getStdOut().writer().print(
47 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
48 try stdout_writer.interface.print(
4649 "{d} {d}\n",
4750 .{ val.x, val.y },
4851 );
test/incremental/change_zon_file+3-3
......@@ -7,7 +7,7 @@
77const std = @import("std");
88const message: []const u8 = @import("message.zon");
99pub fn main() !void {
10 try std.io.getStdOut().writeAll(message);
10 try std.fs.File.stdout().writeAll(message);
1111}
1212#file=message.zon
1313"Hello, World!\n"
......@@ -28,7 +28,7 @@ pub fn main() !void {
2828const std = @import("std");
2929const message: []const u8 = @import("message.zon");
3030pub fn main() !void {
31 try std.io.getStdOut().writeAll("a hardcoded string\n");
31 try std.fs.File.stdout().writeAll("a hardcoded string\n");
3232}
3333#expect_error=message.zon:1:1: error: unable to load 'message.zon': FileNotFound
3434#expect_error=main.zig:2:37: note: file imported here
......@@ -43,6 +43,6 @@ pub fn main() !void {
4343const std = @import("std");
4444const message: []const u8 = @import("message.zon");
4545pub fn main() !void {
46 try std.io.getStdOut().writeAll(message);
46 try std.fs.File.stdout().writeAll(message);
4747}
4848#expect_stdout="We're back, World!\n"
test/incremental/change_zon_file_no_result_type+1-1
......@@ -6,7 +6,7 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writeAll(@import("foo.zon").message);
9 try std.fs.File.stdout().writeAll(@import("foo.zon").message);
1010}
1111#file=foo.zon
1212.{
test/incremental/compile_log+3-3
......@@ -7,7 +7,7 @@
77#file=main.zig
88const std = @import("std");
99pub fn main() !void {
10 try std.io.getStdOut().writeAll("Hello, World!\n");
10 try std.fs.File.stdout().writeAll("Hello, World!\n");
1111}
1212#expect_stdout="Hello, World!\n"
1313
......@@ -15,7 +15,7 @@ pub fn main() !void {
1515#file=main.zig
1616const std = @import("std");
1717pub fn main() !void {
18 try std.io.getStdOut().writeAll("Hello, World!\n");
18 try std.fs.File.stdout().writeAll("Hello, World!\n");
1919 @compileLog("this is a log");
2020}
2121#expect_error=main.zig:4:5: error: found compile log statement
......@@ -25,6 +25,6 @@ pub fn main() !void {
2525#file=main.zig
2626const std = @import("std");
2727pub fn main() !void {
28 try std.io.getStdOut().writeAll("Hello, World!\n");
28 try std.fs.File.stdout().writeAll("Hello, World!\n");
2929}
3030#expect_stdout="Hello, World!\n"
test/incremental/fix_astgen_failure+5-5
......@@ -9,28 +9,28 @@ pub fn main() !void {
99}
1010#file=foo.zig
1111pub fn hello() !void {
12 try std.io.getStdOut().writeAll("Hello, World!\n");
12 try std.fs.File.stdout().writeAll("Hello, World!\n");
1313}
1414#expect_error=foo.zig:2:9: error: use of undeclared identifier 'std'
1515#update=fix the error
1616#file=foo.zig
1717const std = @import("std");
1818pub fn hello() !void {
19 try std.io.getStdOut().writeAll("Hello, World!\n");
19 try std.fs.File.stdout().writeAll("Hello, World!\n");
2020}
2121#expect_stdout="Hello, World!\n"
2222#update=add new error
2323#file=foo.zig
2424const std = @import("std");
2525pub fn hello() !void {
26 try std.io.getStdOut().writeAll(hello_str);
26 try std.fs.File.stdout().writeAll(hello_str);
2727}
28#expect_error=foo.zig:3:37: error: use of undeclared identifier 'hello_str'
28#expect_error=foo.zig:3:39: error: use of undeclared identifier 'hello_str'
2929#update=fix the new error
3030#file=foo.zig
3131const std = @import("std");
3232const hello_str = "Hello, World! Again!\n";
3333pub fn hello() !void {
34 try std.io.getStdOut().writeAll(hello_str);
34 try std.fs.File.stdout().writeAll(hello_str);
3535}
3636#expect_stdout="Hello, World! Again!\n"
test/incremental/function_becomes_inline+3-3
......@@ -7,7 +7,7 @@ pub fn main() !void {
77 try foo();
88}
99fn foo() !void {
10 try std.io.getStdOut().writer().writeAll("Hello, World!\n");
10 try std.fs.File.stdout().writeAll("Hello, World!\n");
1111}
1212const std = @import("std");
1313#expect_stdout="Hello, World!\n"
......@@ -18,7 +18,7 @@ pub fn main() !void {
1818 try foo();
1919}
2020inline fn foo() !void {
21 try std.io.getStdOut().writer().writeAll("Hello, World!\n");
21 try std.fs.File.stdout().writeAll("Hello, World!\n");
2222}
2323const std = @import("std");
2424#expect_stdout="Hello, World!\n"
......@@ -29,7 +29,7 @@ pub fn main() !void {
2929 try foo();
3030}
3131inline fn foo() !void {
32 try std.io.getStdOut().writer().writeAll("Hello, `inline` World!\n");
32 try std.fs.File.stdout().writeAll("Hello, `inline` World!\n");
3333}
3434const std = @import("std");
3535#expect_stdout="Hello, `inline` World!\n"
test/incremental/hello+2-2
......@@ -6,13 +6,13 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writeAll("good morning\n");
9 try std.fs.File.stdout().writeAll("good morning\n");
1010}
1111#expect_stdout="good morning\n"
1212#update=change the string
1313#file=main.zig
1414const std = @import("std");
1515pub fn main() !void {
16 try std.io.getStdOut().writeAll("おはようございます\n");
16 try std.fs.File.stdout().writeAll("おはようございます\n");
1717}
1818#expect_stdout="おはようございます\n"
test/incremental/make_decl_pub+2-2
......@@ -11,7 +11,7 @@ pub fn main() !void {
1111#file=foo.zig
1212const std = @import("std");
1313fn hello() !void {
14 try std.io.getStdOut().writeAll("Hello, World!\n");
14 try std.fs.File.stdout().writeAll("Hello, World!\n");
1515}
1616#expect_error=main.zig:3:12: error: 'hello' is not marked 'pub'
1717#expect_error=foo.zig:2:1: note: declared here
......@@ -20,6 +20,6 @@ fn hello() !void {
2020#file=foo.zig
2121const std = @import("std");
2222pub fn hello() !void {
23 try std.io.getStdOut().writeAll("Hello, World!\n");
23 try std.fs.File.stdout().writeAll("Hello, World!\n");
2424}
2525#expect_stdout="Hello, World!\n"
test/incremental/modify_inline_fn+2-2
......@@ -7,7 +7,7 @@
77const std = @import("std");
88pub fn main() !void {
99 const str = getStr();
10 try std.io.getStdOut().writeAll(str);
10 try std.fs.File.stdout().writeAll(str);
1111}
1212inline fn getStr() []const u8 {
1313 return "foo\n";
......@@ -18,7 +18,7 @@ inline fn getStr() []const u8 {
1818const std = @import("std");
1919pub fn main() !void {
2020 const str = getStr();
21 try std.io.getStdOut().writeAll(str);
21 try std.fs.File.stdout().writeAll(str);
2222}
2323inline fn getStr() []const u8 {
2424 return "bar\n";
test/incremental/move_src+6-4
......@@ -6,7 +6,8 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writer().print("{d} {d}\n", .{ foo(), bar() });
9 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
10 try stdout_writer.interface.print("{d} {d}\n", .{ foo(), bar() });
1011}
1112fn foo() u32 {
1213 return @src().line;
......@@ -14,13 +15,14 @@ fn foo() u32 {
1415fn bar() u32 {
1516 return 123;
1617}
17#expect_stdout="6 123\n"
18#expect_stdout="7 123\n"
1819
1920#update=add newline
2021#file=main.zig
2122const std = @import("std");
2223pub fn main() !void {
23 try std.io.getStdOut().writer().print("{d} {d}\n", .{ foo(), bar() });
24 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
25 try stdout_writer.interface.print("{d} {d}\n", .{ foo(), bar() });
2426}
2527
2628fn foo() u32 {
......@@ -29,4 +31,4 @@ fn foo() u32 {
2931fn bar() u32 {
3032 return 123;
3133}
32#expect_stdout="7 123\n"
34#expect_stdout="8 123\n"
test/incremental/no_change_preserves_tag_names+2-2
......@@ -7,7 +7,7 @@
77const std = @import("std");
88var some_enum: enum { first, second } = .first;
99pub fn main() !void {
10 try std.io.getStdOut().writeAll(@tagName(some_enum));
10 try std.fs.File.stdout().writeAll(@tagName(some_enum));
1111}
1212#expect_stdout="first"
1313#update=no change
......@@ -15,6 +15,6 @@ pub fn main() !void {
1515const std = @import("std");
1616var some_enum: enum { first, second } = .first;
1717pub fn main() !void {
18 try std.io.getStdOut().writeAll(@tagName(some_enum));
18 try std.fs.File.stdout().writeAll(@tagName(some_enum));
1919}
2020#expect_stdout="first"
test/incremental/recursive_function_becomes_non_recursive+2-2
......@@ -8,7 +8,7 @@ pub fn main() !void {
88 try foo(false);
99}
1010fn foo(recurse: bool) !void {
11 const stdout = std.io.getStdOut().writer();
11 const stdout = std.fs.File.stdout();
1212 if (recurse) return foo(true);
1313 try stdout.writeAll("non-recursive path\n");
1414}
......@@ -21,7 +21,7 @@ pub fn main() !void {
2121 try foo(true);
2222}
2323fn foo(recurse: bool) !void {
24 const stdout = std.io.getStdOut().writer();
24 const stdout = std.fs.File.stdout();
2525 if (recurse) return stdout.writeAll("x==1\n");
2626 try stdout.writeAll("non-recursive path\n");
2727}
test/incremental/remove_enum_field+5-3
......@@ -9,7 +9,8 @@ const MyEnum = enum(u8) {
99 bar = 2,
1010};
1111pub fn main() !void {
12 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});
12 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
13 try stdout_writer.interface.print("{}\n", .{@intFromEnum(MyEnum.foo)});
1314}
1415const std = @import("std");
1516#expect_stdout="1\n"
......@@ -20,8 +21,9 @@ const MyEnum = enum(u8) {
2021 bar = 2,
2122};
2223pub fn main() !void {
23 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});
24 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
25 try stdout_writer.interface.print("{}\n", .{@intFromEnum(MyEnum.foo)});
2426}
2527const std = @import("std");
26#expect_error=main.zig:6:73: error: enum 'main.MyEnum' has no member named 'foo'
28#expect_error=main.zig:7:69: error: enum 'main.MyEnum' has no member named 'foo'
2729#expect_error=main.zig:1:16: note: enum declared here
test/incremental/unreferenced_error+4-4
......@@ -6,7 +6,7 @@
66#file=main.zig
77const std = @import("std");
88pub fn main() !void {
9 try std.io.getStdOut().writeAll(a);
9 try std.fs.File.stdout().writeAll(a);
1010}
1111const a = "Hello, World!\n";
1212#expect_stdout="Hello, World!\n"
......@@ -15,7 +15,7 @@ const a = "Hello, World!\n";
1515#file=main.zig
1616const std = @import("std");
1717pub fn main() !void {
18 try std.io.getStdOut().writeAll(a);
18 try std.fs.File.stdout().writeAll(a);
1919}
2020const a = @compileError("bad a");
2121#expect_error=main.zig:5:11: error: bad a
......@@ -24,7 +24,7 @@ const a = @compileError("bad a");
2424#file=main.zig
2525const std = @import("std");
2626pub fn main() !void {
27 try std.io.getStdOut().writeAll(b);
27 try std.fs.File.stdout().writeAll(b);
2828}
2929const a = @compileError("bad a");
3030const b = "Hi there!\n";
......@@ -34,7 +34,7 @@ const b = "Hi there!\n";
3434#file=main.zig
3535const std = @import("std");
3636pub fn main() !void {
37 try std.io.getStdOut().writeAll(a);
37 try std.fs.File.stdout().writeAll(a);
3838}
3939const a = "Back to a\n";
4040const b = @compileError("bad b");
test/link/bss/main.zig+4-1
......@@ -4,8 +4,11 @@ const std = @import("std");
44var buffer: [0x1000000]u64 = [1]u64{0} ** 0x1000000;
55
66pub fn main() anyerror!void {
7 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
8
79 buffer[0x10] = 1;
8 try std.io.getStdOut().writer().print("{d}, {d}, {d}\n", .{
10
11 try stdout_writer.interface.print("{d}, {d}, {d}\n", .{
912 // workaround the dreaded decl_val
1013 (&buffer)[0],
1114 (&buffer)[0x10],
test/link/elf.zig+4-4
......@@ -1315,8 +1315,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {
13151315 \\extern var live_var2: i32;
13161316 \\extern fn live_fn2() void;
13171317 \\pub fn main() void {
1318 \\ const stdout = std.io.getStdOut();
1319 \\ stdout.deprecatedWriter().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable;
1318 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
1319 \\ stdout_writer.interface.print("{d} {d}\n", .{ live_var1, live_var2 }) catch @panic("fail");
13201320 \\ live_fn2();
13211321 \\}
13221322 ,
......@@ -1357,8 +1357,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {
13571357 \\extern var live_var2: i32;
13581358 \\extern fn live_fn2() void;
13591359 \\pub fn main() void {
1360 \\ const stdout = std.io.getStdOut();
1361 \\ stdout.deprecatedWriter().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable;
1360 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
1361 \\ stdout_writer.interface.print("{d} {d}\n", .{ live_var1, live_var2 }) catch @panic("fail");
13621362 \\ live_fn2();
13631363 \\}
13641364 ,
test/link/macho.zig+4-3
......@@ -710,7 +710,7 @@ fn testHelloZig(b: *Build, opts: Options) *Step {
710710 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
711711 \\const std = @import("std");
712712 \\pub fn main() void {
713 \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable;
713 \\ std.fs.File.stdout().writeAll("Hello world!\n") catch @panic("fail");
714714 \\}
715715 });
716716
......@@ -2365,10 +2365,11 @@ fn testTlsZig(b: *Build, opts: Options) *Step {
23652365 \\threadlocal var x: i32 = 0;
23662366 \\threadlocal var y: i32 = -1;
23672367 \\pub fn main() void {
2368 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2368 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
2369 \\ stdout_writer.interface.print("{d} {d}\n", .{x, y}) catch unreachable;
23692370 \\ x -= 1;
23702371 \\ y += 1;
2371 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2372 \\ stdout_writer.interface.print("{d} {d}\n", .{x, y}) catch unreachable;
23722373 \\}
23732374 });
23742375
test/link/wasm/extern/main.zig+2-2
......@@ -3,6 +3,6 @@ const std = @import("std");
33extern const foo: u32;
44
55pub fn main() void {
6 const std_out = std.io.getStdOut();
7 std_out.writer().print("Result: {d}", .{foo}) catch {};
6 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
7 stdout_writer.interface.print("Result: {d}", .{foo}) catch {};
88}
test/src/check-stack-trace.zig+1-1
......@@ -84,5 +84,5 @@ pub fn main() !void {
8484 break :got_result try buf.toOwnedSlice();
8585 };
8686
87 try std.io.getStdOut().writeAll(got);
87 try std.fs.File.stdout().writeAll(got);
8888}
test/standalone/child_process/child.zig+4-3
......@@ -27,12 +27,12 @@ fn run(allocator: std.mem.Allocator) !void {
2727 }
2828
2929 // test stdout pipe; parent verifies
30 try std.io.getStdOut().writer().writeAll("hello from stdout");
30 try std.fs.File.stdout().writeAll("hello from stdout");
3131
3232 // test stdin pipe from parent
3333 const hello_stdin = "hello from stdin";
3434 var buf: [hello_stdin.len]u8 = undefined;
35 const stdin = std.io.getStdIn().reader();
35 const stdin: std.fs.File = .stdin();
3636 const n = try stdin.readAll(&buf);
3737 if (!std.mem.eql(u8, buf[0..n], hello_stdin)) {
3838 testError("stdin: '{s}'; want '{s}'", .{ buf[0..n], hello_stdin });
......@@ -40,7 +40,8 @@ fn run(allocator: std.mem.Allocator) !void {
4040}
4141
4242fn testError(comptime fmt: []const u8, args: anytype) void {
43 const stderr = std.io.getStdErr().writer();
43 var stderr_writer = std.fs.File.stderr().writer(&.{});
44 const stderr = &stderr_writer.interface;
4445 stderr.print("CHILD TEST ERROR: ", .{}) catch {};
4546 stderr.print(fmt, args) catch {};
4647 if (fmt[fmt.len - 1] != '\n') {
test/standalone/child_process/main.zig+4-3
......@@ -19,13 +19,13 @@ pub fn main() !void {
1919 child.stderr_behavior = .Inherit;
2020 try child.spawn();
2121 const child_stdin = child.stdin.?;
22 try child_stdin.writer().writeAll("hello from stdin"); // verified in child
22 try child_stdin.writeAll("hello from stdin"); // verified in child
2323 child_stdin.close();
2424 child.stdin = null;
2525
2626 const hello_stdout = "hello from stdout";
2727 var buf: [hello_stdout.len]u8 = undefined;
28 const n = try child.stdout.?.reader().readAll(&buf);
28 const n = try child.stdout.?.deprecatedReader().readAll(&buf);
2929 if (!std.mem.eql(u8, buf[0..n], hello_stdout)) {
3030 testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout });
3131 }
......@@ -45,7 +45,8 @@ pub fn main() !void {
4545var parent_test_error = false;
4646
4747fn testError(comptime fmt: []const u8, args: anytype) void {
48 const stderr = std.io.getStdErr().writer();
48 var stderr_writer = std.fs.File.stderr().writer(&.{});
49 const stderr = &stderr_writer.interface;
4950 stderr.print("PARENT TEST ERROR: ", .{}) catch {};
5051 stderr.print(fmt, args) catch {};
5152 if (fmt[fmt.len - 1] != '\n') {
test/standalone/sigpipe/breakpipe.zig+1-1
......@@ -10,7 +10,7 @@ pub fn main() !void {
1010 std.posix.close(pipe[0]);
1111 _ = std.posix.write(pipe[1], "a") catch |err| switch (err) {
1212 error.BrokenPipe => {
13 try std.io.getStdOut().writer().writeAll("BrokenPipe\n");
13 try std.fs.File.stdout().writeAll("BrokenPipe\n");
1414 std.posix.exit(123);
1515 },
1616 else => |e| return e,
test/standalone/simple/brace_expansion.zig deleted-292
......@@ -1,292 +0,0 @@
1const std = @import("std");
2const io = std.io;
3const mem = std.mem;
4const debug = std.debug;
5const assert = debug.assert;
6const testing = std.testing;
7const ArrayList = std.ArrayList;
8const maxInt = std.math.maxInt;
9
10const Token = union(enum) {
11 Word: []const u8,
12 OpenBrace,
13 CloseBrace,
14 Comma,
15 Eof,
16};
17
18var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
19var global_allocator = gpa.allocator();
20
21fn tokenize(input: []const u8) !ArrayList(Token) {
22 const State = enum {
23 Start,
24 Word,
25 };
26
27 var token_list = ArrayList(Token).init(global_allocator);
28 errdefer token_list.deinit();
29 var tok_begin: usize = undefined;
30 var state = State.Start;
31
32 for (input, 0..) |b, i| {
33 switch (state) {
34 .Start => switch (b) {
35 'a'...'z', 'A'...'Z' => {
36 state = State.Word;
37 tok_begin = i;
38 },
39 '{' => try token_list.append(Token.OpenBrace),
40 '}' => try token_list.append(Token.CloseBrace),
41 ',' => try token_list.append(Token.Comma),
42 else => return error.InvalidInput,
43 },
44 .Word => switch (b) {
45 'a'...'z', 'A'...'Z' => {},
46 '{', '}', ',' => {
47 try token_list.append(Token{ .Word = input[tok_begin..i] });
48 switch (b) {
49 '{' => try token_list.append(Token.OpenBrace),
50 '}' => try token_list.append(Token.CloseBrace),
51 ',' => try token_list.append(Token.Comma),
52 else => unreachable,
53 }
54 state = State.Start;
55 },
56 else => return error.InvalidInput,
57 },
58 }
59 }
60 switch (state) {
61 State.Start => {},
62 State.Word => try token_list.append(Token{ .Word = input[tok_begin..] }),
63 }
64 try token_list.append(Token.Eof);
65 return token_list;
66}
67
68const Node = union(enum) {
69 Scalar: []const u8,
70 List: ArrayList(Node),
71 Combine: []Node,
72
73 fn deinit(self: Node) void {
74 switch (self) {
75 .Scalar => {},
76 .Combine => |pair| {
77 pair[0].deinit();
78 pair[1].deinit();
79 global_allocator.free(pair);
80 },
81 .List => |list| {
82 for (list.items) |item| {
83 item.deinit();
84 }
85 list.deinit();
86 },
87 }
88 }
89};
90
91const ParseError = error{
92 InvalidInput,
93 OutOfMemory,
94};
95
96fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
97 const first_token = tokens.items[token_index.*];
98 token_index.* += 1;
99
100 const result_node = switch (first_token) {
101 .Word => |word| Node{ .Scalar = word },
102 .OpenBrace => blk: {
103 var list = ArrayList(Node).init(global_allocator);
104 errdefer {
105 for (list.items) |node| node.deinit();
106 list.deinit();
107 }
108 while (true) {
109 try list.append(try parse(tokens, token_index));
110
111 const token = tokens.items[token_index.*];
112 token_index.* += 1;
113
114 switch (token) {
115 .CloseBrace => break,
116 .Comma => continue,
117 else => return error.InvalidInput,
118 }
119 }
120 break :blk Node{ .List = list };
121 },
122 else => return error.InvalidInput,
123 };
124
125 switch (tokens.items[token_index.*]) {
126 .Word, .OpenBrace => {
127 const pair = try global_allocator.alloc(Node, 2);
128 errdefer global_allocator.free(pair);
129 pair[0] = result_node;
130 pair[1] = try parse(tokens, token_index);
131 return Node{ .Combine = pair };
132 },
133 else => return result_node,
134 }
135}
136
137fn expandString(input: []const u8, output: *ArrayList(u8)) !void {
138 const tokens = try tokenize(input);
139 defer tokens.deinit();
140 if (tokens.items.len == 1) {
141 return output.resize(0);
142 }
143
144 var token_index: usize = 0;
145 const root = try parse(&tokens, &token_index);
146 defer root.deinit();
147 const last_token = tokens.items[token_index];
148 switch (last_token) {
149 Token.Eof => {},
150 else => return error.InvalidInput,
151 }
152
153 var result_list = ArrayList(ArrayList(u8)).init(global_allocator);
154 defer {
155 for (result_list.items) |*buf| buf.deinit();
156 result_list.deinit();
157 }
158
159 try expandNode(root, &result_list);
160
161 try output.resize(0);
162 for (result_list.items, 0..) |buf, i| {
163 if (i != 0) {
164 try output.append(' ');
165 }
166 try output.appendSlice(buf.items);
167 }
168}
169
170const ExpandNodeError = error{OutOfMemory};
171
172fn expandNode(node: Node, output: *ArrayList(ArrayList(u8))) ExpandNodeError!void {
173 assert(output.items.len == 0);
174 switch (node) {
175 .Scalar => |scalar| {
176 var list = ArrayList(u8).init(global_allocator);
177 errdefer list.deinit();
178 try list.appendSlice(scalar);
179 try output.append(list);
180 },
181 .Combine => |pair| {
182 const a_node = pair[0];
183 const b_node = pair[1];
184
185 var child_list_a = ArrayList(ArrayList(u8)).init(global_allocator);
186 defer {
187 for (child_list_a.items) |*buf| buf.deinit();
188 child_list_a.deinit();
189 }
190 try expandNode(a_node, &child_list_a);
191
192 var child_list_b = ArrayList(ArrayList(u8)).init(global_allocator);
193 defer {
194 for (child_list_b.items) |*buf| buf.deinit();
195 child_list_b.deinit();
196 }
197 try expandNode(b_node, &child_list_b);
198
199 for (child_list_a.items) |buf_a| {
200 for (child_list_b.items) |buf_b| {
201 var combined_buf = ArrayList(u8).init(global_allocator);
202 errdefer combined_buf.deinit();
203
204 try combined_buf.appendSlice(buf_a.items);
205 try combined_buf.appendSlice(buf_b.items);
206 try output.append(combined_buf);
207 }
208 }
209 },
210 .List => |list| {
211 for (list.items) |child_node| {
212 var child_list = ArrayList(ArrayList(u8)).init(global_allocator);
213 errdefer for (child_list.items) |*buf| buf.deinit();
214 defer child_list.deinit();
215
216 try expandNode(child_node, &child_list);
217
218 for (child_list.items) |buf| {
219 try output.append(buf);
220 }
221 }
222 },
223 }
224}
225
226pub fn main() !void {
227 defer _ = gpa.deinit();
228 const stdin_file = io.getStdIn();
229 const stdout_file = io.getStdOut();
230
231 const stdin = try stdin_file.deprecatedReader().readAllAlloc(global_allocator, std.math.maxInt(usize));
232 defer global_allocator.free(stdin);
233
234 var result_buf = ArrayList(u8).init(global_allocator);
235 defer result_buf.deinit();
236
237 try expandString(stdin, &result_buf);
238 try stdout_file.writeAll(result_buf.items);
239}
240
241test "invalid inputs" {
242 global_allocator = std.testing.allocator;
243
244 try expectError("}ABC", error.InvalidInput);
245 try expectError("{ABC", error.InvalidInput);
246 try expectError("}{", error.InvalidInput);
247 try expectError("{}", error.InvalidInput);
248 try expectError("A,B,C", error.InvalidInput);
249 try expectError("{A{B,C}", error.InvalidInput);
250 try expectError("{A,}", error.InvalidInput);
251
252 try expectError("\n", error.InvalidInput);
253}
254
255fn expectError(test_input: []const u8, expected_err: anyerror) !void {
256 var output_buf = ArrayList(u8).init(global_allocator);
257 defer output_buf.deinit();
258
259 try testing.expectError(expected_err, expandString(test_input, &output_buf));
260}
261
262test "valid inputs" {
263 global_allocator = std.testing.allocator;
264
265 try expectExpansion("{x,y,z}", "x y z");
266 try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
267 try expectExpansion("{A,B{x,y}}", "A Bx By");
268
269 try expectExpansion("{ABC}", "ABC");
270 try expectExpansion("{A,B,C}", "A B C");
271 try expectExpansion("ABC", "ABC");
272
273 try expectExpansion("", "");
274 try expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
275 try expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
276 try expectExpansion("{A,B}a", "Aa Ba");
277 try expectExpansion("{C,{x,y}}", "C x y");
278 try expectExpansion("z{C,{x,y}}", "zC zx zy");
279 try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
280 try expectExpansion("a{x,y}b", "axb ayb");
281 try expectExpansion("z{{a,b}}", "za zb");
282 try expectExpansion("a{b}", "ab");
283}
284
285fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void {
286 var result = ArrayList(u8).init(global_allocator);
287 defer result.deinit();
288
289 expandString(test_input, &result) catch unreachable;
290
291 try testing.expectEqualSlices(u8, expected_result, result.items);
292}
test/standalone/simple/build.zig-4
......@@ -109,10 +109,6 @@ const cases = [_]Case{
109109 //.{
110110 // .src_path = "issue_9693/main.zig",
111111 //},
112 .{
113 .src_path = "brace_expansion.zig",
114 .is_test = true,
115 },
116112 .{
117113 .src_path = "issue_7030.zig",
118114 .target = .{
test/standalone/simple/cat/main.zig+10-10
......@@ -1,42 +1,42 @@
11const std = @import("std");
22const io = std.io;
3const process = std.process;
43const fs = std.fs;
54const mem = std.mem;
65const warn = std.log.warn;
6const fatal = std.process.fatal;
77
88pub fn main() !void {
99 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
1010 defer arena_instance.deinit();
1111 const arena = arena_instance.allocator();
1212
13 const args = try process.argsAlloc(arena);
13 const args = try std.process.argsAlloc(arena);
1414
1515 const exe = args[0];
1616 var catted_anything = false;
17 const stdout_file = io.getStdOut();
17 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
18 const stdout = &stdout_writer.interface;
19 var stdin_reader = std.fs.File.stdin().reader(&.{});
1820
1921 const cwd = fs.cwd();
2022
2123 for (args[1..]) |arg| {
2224 if (mem.eql(u8, arg, "-")) {
2325 catted_anything = true;
24 try stdout_file.writeFileAll(io.getStdIn(), .{});
26 _ = try stdout.sendFileAll(&stdin_reader, .unlimited);
2527 } else if (mem.startsWith(u8, arg, "-")) {
2628 return usage(exe);
2729 } else {
28 const file = cwd.openFile(arg, .{}) catch |err| {
29 warn("Unable to open file: {s}\n", .{@errorName(err)});
30 return err;
31 };
30 const file = cwd.openFile(arg, .{}) catch |err| fatal("unable to open file: {t}\n", .{err});
3231 defer file.close();
3332
3433 catted_anything = true;
35 try stdout_file.writeFileAll(file, .{});
34 var file_reader = file.reader(&.{});
35 _ = try stdout.sendFileAll(&file_reader, .unlimited);
3636 }
3737 }
3838 if (!catted_anything) {
39 try stdout_file.writeFileAll(io.getStdIn(), .{});
39 _ = try stdout.sendFileAll(&stdin_reader, .unlimited);
4040 }
4141}
4242
test/standalone/simple/guess_number/main.zig+11-13
......@@ -1,37 +1,35 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const io = std.io;
4const fmt = std.fmt;
53
64pub fn main() !void {
7 const stdout = io.getStdOut().writer();
8 const stdin = io.getStdIn();
5 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
6 const out = &stdout_writer.interface;
7 const stdin: std.fs.File = .stdin();
98
10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});
9 try out.writeAll("Welcome to the Guess Number Game in Zig.\n");
1110
1211 const answer = std.crypto.random.intRangeLessThan(u8, 0, 100) + 1;
1312
1413 while (true) {
15 try stdout.print("\nGuess a number between 1 and 100: ", .{});
14 try out.writeAll("\nGuess a number between 1 and 100: ");
1615 var line_buf: [20]u8 = undefined;
17
1816 const amt = try stdin.read(&line_buf);
1917 if (amt == line_buf.len) {
20 try stdout.print("Input too long.\n", .{});
18 try out.writeAll("Input too long.\n");
2119 continue;
2220 }
2321 const line = std.mem.trimEnd(u8, line_buf[0..amt], "\r\n");
2422
25 const guess = fmt.parseUnsigned(u8, line, 10) catch {
26 try stdout.print("Invalid number.\n", .{});
23 const guess = std.fmt.parseUnsigned(u8, line, 10) catch {
24 try out.writeAll("Invalid number.\n");
2725 continue;
2826 };
2927 if (guess > answer) {
30 try stdout.print("Guess lower.\n", .{});
28 try out.writeAll("Guess lower.\n");
3129 } else if (guess < answer) {
32 try stdout.print("Guess higher.\n", .{});
30 try out.writeAll("Guess higher.\n");
3331 } else {
34 try stdout.print("You win!\n", .{});
32 try out.writeAll("You win!\n");
3533 return;
3634 }
3735 }
test/standalone/simple/hello_world/hello.zig+1-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
22
33pub fn main() !void {
4 try std.io.getStdOut().writeAll("Hello, World!\n");
4 try std.fs.File.stdout().writeAll("Hello, World!\n");
55}
test/standalone/simple/std_enums_big_enums.zig+1
......@@ -6,6 +6,7 @@ pub fn main() void {
66 const Big = @Type(.{ .@"enum" = .{
77 .tag_type = u16,
88 .fields = make_fields: {
9 @setEvalBranchQuota(500000);
910 var fields: [1001]std.builtin.Type.EnumField = undefined;
1011 for (&fields, 0..) |*field, i| {
1112 field.* = .{ .name = std.fmt.comptimePrint("field_{d}", .{i}), .value = i };
test/standalone/windows_bat_args/echo-args.zig+2-1
......@@ -5,7 +5,8 @@ pub fn main() !void {
55 defer arena_state.deinit();
66 const arena = arena_state.allocator();
77
8 const stdout = std.io.getStdOut().writer();
8 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
9 const stdout = &stdout_writer.interface;
910 var args = try std.process.argsAlloc(arena);
1011 for (args[1..], 1..) |arg, i| {
1112 try stdout.writeAll(arg);
test/standalone/windows_spawn/hello.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("std");
22
33pub fn main() !void {
4 const stdout = std.io.getStdOut().writer();
4 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
5 const stdout = &stdout_writer.interface;
56 try stdout.writeAll("hello from exe\n");
67}
tools/docgen.zig+1-2
......@@ -43,8 +43,7 @@ pub fn main() !void {
4343 while (args_it.next()) |arg| {
4444 if (mem.startsWith(u8, arg, "-")) {
4545 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
46 const stdout = io.getStdOut().writer();
47 try stdout.writeAll(usage);
46 try fs.File.stdout().writeAll(usage);
4847 process.exit(0);
4948 } else if (mem.eql(u8, arg, "--code-dir")) {
5049 if (args_it.next()) |param| {
tools/doctest.zig+1-1
......@@ -44,7 +44,7 @@ pub fn main() !void {
4444 while (args_it.next()) |arg| {
4545 if (mem.startsWith(u8, arg, "-")) {
4646 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
47 try std.io.getStdOut().writeAll(usage);
47 try std.fs.File.stdout().writeAll(usage);
4848 process.exit(0);
4949 } else if (mem.eql(u8, arg, "-i")) {
5050 opt_input = args_it.next() orelse fatal("expected parameter after -i", .{});
tools/dump-cov.zig+4-3
......@@ -48,8 +48,9 @@ pub fn main() !void {
4848 fatal("failed to load coverage file {}: {s}", .{ cov_path, @errorName(err) });
4949 };
5050
51 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
52 const stdout = bw.writer();
51 var stdout_buffer: [4000]u8 = undefined;
52 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
53 const stdout = &stdout_writer.interface;
5354
5455 const header: *SeenPcsHeader = @ptrCast(cov_bytes);
5556 try stdout.print("{any}\n", .{header.*});
......@@ -83,5 +84,5 @@ pub fn main() !void {
8384 });
8485 }
8586
86 try bw.flush();
87 try stdout.flush();
8788}
tools/fetch_them_macos_headers.zig+2-13
......@@ -5,6 +5,8 @@ const mem = std.mem;
55const process = std.process;
66const assert = std.debug.assert;
77const tmpDir = std.testing.tmpDir;
8const fatal = std.process.fatal;
9const info = std.log.info;
810
911const Allocator = mem.Allocator;
1012const OsTag = std.Target.Os.Tag;
......@@ -245,19 +247,6 @@ const ArgsIterator = struct {
245247 }
246248};
247249
248fn info(comptime format: []const u8, args: anytype) void {
249 const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
250 std.io.getStdOut().writeAll(msg) catch {};
251}
252
253fn fatal(comptime format: []const u8, args: anytype) noreturn {
254 ret: {
255 const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
256 std.io.getStdErr().writeAll(msg) catch {};
257 }
258 std.process.exit(1);
259}
260
261250const Version = struct {
262251 major: u16,
263252 minor: u8,
tools/gen_macos_headers_c.zig+9-17
......@@ -1,5 +1,7 @@
11const std = @import("std");
22const assert = std.debug.assert;
3const info = std.log.info;
4const fatal = std.process.fatal;
35
46const Allocator = std.mem.Allocator;
57
......@@ -13,19 +15,6 @@ const usage =
1315 \\-h, --help Print this help and exit
1416;
1517
16fn info(comptime format: []const u8, args: anytype) void {
17 const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
18 std.io.getStdOut().writeAll(msg) catch {};
19}
20
21fn fatal(comptime format: []const u8, args: anytype) noreturn {
22 ret: {
23 const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
24 std.io.getStdErr().writeAll(msg) catch {};
25 }
26 std.process.exit(1);
27}
28
2918pub fn main() anyerror!void {
3019 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
3120 defer arena_allocator.deinit();
......@@ -58,16 +47,19 @@ pub fn main() anyerror!void {
5847
5948 std.mem.sort([]const u8, paths.items, {}, SortFn.lessThan);
6049
61 const stdout = std.io.getStdOut().writer();
62 try stdout.writeAll("#define _XOPEN_SOURCE\n");
50 var buffer: [2000]u8 = undefined;
51 var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
52 const w = &stdout_writer.interface;
53 try w.writeAll("#define _XOPEN_SOURCE\n");
6354 for (paths.items) |path| {
64 try stdout.print("#include <{s}>\n", .{path});
55 try w.print("#include <{s}>\n", .{path});
6556 }
66 try stdout.writeAll(
57 try w.writeAll(
6758 \\int main(int argc, char **argv) {
6859 \\ return 0;
6960 \\}
7061 );
62 try w.flush();
7163}
7264
7365fn findHeaders(
tools/gen_outline_atomics.zig+4-3
......@@ -17,8 +17,9 @@ pub fn main() !void {
1717
1818 //const args = try std.process.argsAlloc(arena);
1919
20 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
21 const w = bw.writer();
20 var stdout_buffer: [2000]u8 = undefined;
21 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
22 const w = &stdout_writer.interface;
2223
2324 try w.writeAll(
2425 \\//! This file is generated by tools/gen_outline_atomics.zig.
......@@ -57,7 +58,7 @@ pub fn main() !void {
5758
5859 try w.writeAll(footer.items);
5960 try w.writeAll("}\n");
60 try bw.flush();
61 try w.flush();
6162}
6263
6364fn writeFunction(
tools/gen_spirv_spec.zig+9-12
......@@ -91,9 +91,10 @@ pub fn main() !void {
9191
9292 try readExtRegistry(&exts, a, std.fs.cwd(), args[2]);
9393
94 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
95 try render(bw.writer(), a, core_spec, exts.items);
96 try bw.flush();
94 var buffer: [4000]u8 = undefined;
95 var w = std.fs.File.stdout().writerStreaming(&buffer);
96 try render(&w, a, core_spec, exts.items);
97 try w.flush();
9798}
9899
99100fn readExtRegistry(exts: *std.ArrayList(Extension), a: Allocator, dir: std.fs.Dir, sub_path: []const u8) !void {
......@@ -166,7 +167,7 @@ fn tagPriorityScore(tag: []const u8) usize {
166167 }
167168}
168169
169fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {
170fn render(writer: *std.io.Writer, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {
170171 try writer.writeAll(
171172 \\//! This file is auto-generated by tools/gen_spirv_spec.zig.
172173 \\
......@@ -188,15 +189,10 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
188189 \\ none,
189190 \\ _,
190191 \\
191 \\ pub fn format(
192 \\ self: IdResult,
193 \\ comptime _: []const u8,
194 \\ _: std.fmt.FormatOptions,
195 \\ writer: anytype,
196 \\ ) @TypeOf(writer).Error!void {
192 \\ pub fn format(self: IdResult, writer: *std.io.Writer) std.io.Writer.Error!void {
197193 \\ switch (self) {
198194 \\ .none => try writer.writeAll("(none)"),
199 \\ else => try writer.print("%{}", .{@intFromEnum(self)}),
195 \\ else => try writer.print("%{d}", .{@intFromEnum(self)}),
200196 \\ }
201197 \\ }
202198 \\};
......@@ -899,7 +895,8 @@ fn parseHexInt(text: []const u8) !u31 {
899895}
900896
901897fn usageAndExit(arg0: []const u8, code: u8) noreturn {
902 std.io.getStdErr().writer().print(
898 const stderr = std.debug.lockStderrWriter(&.{});
899 stderr.print(
903900 \\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>
904901 \\
905902 \\Generates Zig bindings for SPIR-V specifications found in the SPIRV-Headers
tools/gen_stubs.zig+5-1
......@@ -333,7 +333,9 @@ pub fn main() !void {
333333 }
334334 }
335335
336 const stdout = std.io.getStdOut().writer();
336 var stdout_buffer: [2000]u8 = undefined;
337 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
338 const stdout = &stdout_writer.interface;
337339 try stdout.writeAll(
338340 \\#ifdef PTR64
339341 \\#define WEAK64 .weak
......@@ -533,6 +535,8 @@ pub fn main() !void {
533535 .all => {},
534536 .single, .multi, .family, .time32 => try stdout.writeAll("#endif\n"),
535537 }
538
539 try stdout.flush();
536540}
537541
538542fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) !void {
tools/generate_JSONTestSuite.zig+5-1
......@@ -6,7 +6,9 @@ pub fn main() !void {
66 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
77 var allocator = gpa.allocator();
88
9 var output = std.io.getStdOut().writer();
9 var stdout_buffer: [2000]u8 = undefined;
10 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
11 const output = &stdout_writer.interface;
1012 try output.writeAll(
1113 \\// This file was generated by _generate_JSONTestSuite.zig
1214 \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite
......@@ -44,6 +46,8 @@ pub fn main() !void {
4446 try writeString(output, contents);
4547 try output.writeAll(");\n}\n");
4648 }
49
50 try output.flush();
4751}
4852
4953const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500;
tools/generate_c_size_and_align_checks.zig+7-4
......@@ -42,20 +42,23 @@ pub fn main() !void {
4242 const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] });
4343 const target = try std.zig.system.resolveTargetQuery(query);
4444
45 const stdout = std.io.getStdOut().writer();
45 var buffer: [2000]u8 = undefined;
46 var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
47 const w = &stdout_writer.interface;
4648 inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {
4749 const c_type: std.Target.CType = @enumFromInt(field.value);
48 try stdout.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
50 try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
4951 cName(c_type),
5052 target.cTypeByteSize(c_type),
5153 });
52 try stdout.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
54 try w.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
5355 cName(c_type),
5456 target.cTypeAlignment(c_type),
5557 });
56 try stdout.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
58 try w.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
5759 cName(c_type),
5860 target.cTypePreferredAlignment(c_type),
5961 });
6062 }
63 try w.flush();
6164}
tools/generate_linux_syscalls.zig+11-9
......@@ -666,13 +666,16 @@ pub fn main() !void {
666666 const allocator = arena.allocator();
667667
668668 const args = try std.process.argsAlloc(allocator);
669 if (args.len < 3 or mem.eql(u8, args[1], "--help"))
670 usageAndExit(std.io.getStdErr(), args[0], 1);
669 if (args.len < 3 or mem.eql(u8, args[1], "--help")) {
670 usage(std.debug.lockStderrWriter(&.{}), args[0]) catch std.process.exit(2);
671 std.process.exit(1);
672 }
671673 const zig_exe = args[1];
672674 const linux_path = args[2];
673675
674 var buf_out = std.io.bufferedWriter(std.io.getStdOut().writer());
675 const writer = buf_out.writer();
676 var stdout_buffer: [2000]u8 = undefined;
677 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
678 const writer = &stdout_writer.interface;
676679
677680 var linux_dir = try std.fs.cwd().openDir(linux_path, .{});
678681 defer linux_dir.close();
......@@ -714,17 +717,16 @@ pub fn main() !void {
714717 }
715718 }
716719
717 try buf_out.flush();
720 try writer.flush();
718721}
719722
720fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
721 file.writer().print(
723fn usage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
724 try w.print(
722725 \\Usage: {s} /path/to/zig /path/to/linux
723726 \\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux
724727 \\
725728 \\Generates the list of Linux syscalls for each supported cpu arch, using the Linux development tree.
726729 \\Prints to stdout Zig code which you can use to replace the file lib/std/os/linux/syscalls.zig.
727730 \\
728 , .{arg0}) catch std.process.exit(1);
729 std.process.exit(code);
731 , .{arg0});
730732}
tools/update_clang_options.zig+22-20
......@@ -634,25 +634,25 @@ pub fn main() anyerror!void {
634634 const allocator = arena.allocator();
635635 const args = try std.process.argsAlloc(allocator);
636636
637 if (args.len <= 1) {
638 usageAndExit(std.io.getStdErr(), args[0], 1);
639 }
637 var stdout_buffer: [4000]u8 = undefined;
638 var stdout_writer = fs.stdout().writerStreaming(&stdout_buffer);
639 const stdout = &stdout_writer.interface;
640
641 if (args.len <= 1) printUsageAndExit(args[0]);
642
640643 if (std.mem.eql(u8, args[1], "--help")) {
641 usageAndExit(std.io.getStdOut(), args[0], 0);
642 }
643 if (args.len < 3) {
644 usageAndExit(std.io.getStdErr(), args[0], 1);
644 printUsage(stdout, args[0]) catch std.process.exit(2);
645 stdout.flush() catch std.process.exit(2);
646 std.process.exit(0);
645647 }
646648
649 if (args.len < 3) printUsageAndExit(args[0]);
650
647651 const llvm_tblgen_exe = args[1];
648 if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) {
649 usageAndExit(std.io.getStdErr(), args[0], 1);
650 }
652 if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) printUsageAndExit(args[0]);
651653
652654 const llvm_src_root = args[2];
653 if (std.mem.startsWith(u8, llvm_src_root, "-")) {
654 usageAndExit(std.io.getStdErr(), args[0], 1);
655 }
655 if (std.mem.startsWith(u8, llvm_src_root, "-")) printUsageAndExit(args[0]);
656656
657657 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(allocator);
658658
......@@ -719,8 +719,6 @@ pub fn main() anyerror!void {
719719 // "W" and "Wl,". So we sort this list in order of descending priority.
720720 std.mem.sort(*json.ObjectMap, all_objects.items, {}, objectLessThan);
721721
722 var buffered_stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
723 const stdout = buffered_stdout.writer();
724722 try stdout.writeAll(
725723 \\// This file is generated by tools/update_clang_options.zig.
726724 \\// zig fmt: off
......@@ -815,7 +813,7 @@ pub fn main() anyerror!void {
815813 \\
816814 );
817815
818 try buffered_stdout.flush();
816 try stdout.flush();
819817}
820818
821819// TODO we should be able to import clang_options.zig but currently this is problematic because it will
......@@ -966,13 +964,17 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
966964 return std.mem.lessThan(u8, a_key, b_key);
967965}
968966
969fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
970 file.writer().print(
967fn printUsageAndExit(arg0: []const u8) noreturn {
968 printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
969 std.process.exit(1);
970}
971
972fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
973 try w.print(
971974 \\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
972975 \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
973976 \\
974977 \\Prints to stdout Zig code which you can use to replace the file src/clang_options_data.zig.
975978 \\
976 , .{arg0}) catch std.process.exit(1);
977 std.process.exit(code);
979 , .{arg0});
978980}
tools/update_cpu_features.zig+2-2
......@@ -2082,8 +2082,8 @@ fn processOneTarget(job: Job) void {
20822082}
20832083
20842084fn usageAndExit(arg0: []const u8, code: u8) noreturn {
2085 const stderr = std.io.getStdErr();
2086 stderr.writer().print(
2085 const stderr = std.debug.lockStderrWriter(&.{});
2086 stderr.print(
20872087 \\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]
20882088 \\
20892089 \\Updates lib/std/target/<target>.zig from llvm/lib/Target/<Target>/<Target>.td .
tools/update_crc_catalog.zig+10-10
......@@ -11,14 +11,10 @@ pub fn main() anyerror!void {
1111 const arena = arena_state.allocator();
1212
1313 const args = try std.process.argsAlloc(arena);
14 if (args.len <= 1) {
15 usageAndExit(std.io.getStdErr(), args[0], 1);
16 }
14 if (args.len <= 1) printUsageAndExit(args[0]);
1715
1816 const zig_src_root = args[1];
19 if (mem.startsWith(u8, zig_src_root, "-")) {
20 usageAndExit(std.io.getStdErr(), args[0], 1);
21 }
17 if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);
2218
2319 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
2420 defer zig_src_dir.close();
......@@ -193,10 +189,14 @@ pub fn main() anyerror!void {
193189 }
194190}
195191
196fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
197 file.writer().print(
192fn printUsageAndExit(arg0: []const u8) noreturn {
193 printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
194 std.process.exit(1);
195}
196
197fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
198 return w.print(
198199 \\Usage: {s} /path/git/zig
199200 \\
200 , .{arg0}) catch std.process.exit(1);
201 std.process.exit(code);
201 , .{arg0});
202202}