From a9b505fa7774e2e8451bedfa7bea27d7227572e7 Mon Sep 17 00:00:00 2001 From: Jay Petacat Date: Tue, 5 Jan 2021 20:57:18 -0500 Subject: [PATCH] Reduce use of deprecated IO types Related: #4917 --- doc/docgen.zig | 8 +++--- lib/std/Progress.zig | 2 +- lib/std/atomic/queue.zig | 8 +++--- lib/std/build.zig | 10 ++++---- lib/std/build/run.zig | 4 +-- lib/std/child_process.zig | 2 +- lib/std/coff.zig | 8 +++--- lib/std/crypto/benchmark.zig | 2 +- lib/std/debug.zig | 36 +++++++++++++-------------- lib/std/dwarf.zig | 10 ++++---- lib/std/heap/logging_allocator.zig | 2 +- lib/std/io/buffered_atomic_file.zig | 2 +- lib/std/io/fixed_buffer_stream.zig | 2 +- lib/std/io/test.zig | 6 ++--- lib/std/json.zig | 16 ++++++------ lib/std/json/write_stream.zig | 2 +- lib/std/net.zig | 4 +-- lib/std/net/test.zig | 2 +- lib/std/os.zig | 2 +- lib/std/os/test.zig | 6 ++--- lib/std/special/build_runner.zig | 4 +-- lib/std/unicode/throughput_test.zig | 2 +- lib/std/zig/cross_target.zig | 14 +++++------ lib/std/zig/parser_test.zig | 6 ++--- lib/std/zig/perf_test.zig | 2 +- lib/std/zig/render.zig | 4 +-- src/Cache.zig | 2 +- src/Compilation.zig | 8 +++--- src/DepTokenizer.zig | 2 +- src/Module.zig | 2 +- src/codegen/llvm.zig | 8 +++--- src/libc_installation.zig | 6 ++--- src/main.zig | 38 ++++++++++++++--------------- src/print_env.zig | 10 ++++---- src/print_targets.zig | 10 ++++---- src/test.zig | 2 +- src/translate_c.zig | 2 +- src/zir.zig | 4 +-- test/compare_output.zig | 30 +++++++++++------------ test/stage1/behavior/bugs/5487.zig | 6 ++--- test/tests.zig | 8 +++--- tools/update_clang_options.zig | 8 +++--- tools/update_glibc.zig | 6 ++--- 43 files changed, 159 insertions(+), 159 deletions(-) diff --git a/doc/docgen.zig b/doc/docgen.zig index 7e0bedbb6c..90e3e32201 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -40,9 +40,9 @@ pub fn main() !void { var out_file = try fs.cwd().createFile(out_file_name, .{}); defer out_file.close(); - const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size); + const input_file_bytes = try in_file.reader().readAllAlloc(allocator, max_doc_file_size); - var buffered_out_stream = io.bufferedOutStream(out_file.writer()); + var buffered_writer = io.bufferedWriter(out_file.writer()); var tokenizer = Tokenizer.init(in_file_name, input_file_bytes); var toc = try genToc(allocator, &tokenizer); @@ -50,8 +50,8 @@ pub fn main() !void { try fs.cwd().makePath(tmp_dir_name); defer fs.cwd().deleteTree(tmp_dir_name) catch {}; - try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.writer(), zig_exe); - try buffered_out_stream.flush(); + try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe); + try buffered_writer.flush(); } const Token = struct { diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 6226e34248..ca9fb8ea1f 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -271,7 +271,7 @@ fn refreshWithHeldLock(self: *Progress) void { pub fn log(self: *Progress, comptime format: []const u8, args: anytype) void { const file = self.terminal orelse return; self.refresh(); - file.outStream().print(format, args) catch { + file.writer().print(format, args) catch { self.terminal = null; return; }; diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index 19d04d041a..fa3711cd9f 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -122,7 +122,7 @@ pub fn Queue(comptime T: type) type { /// Dumps the contents of the queue to `stderr`. pub fn dump(self: *Self) void { - self.dumpToStream(std.io.getStdErr().outStream()) catch return; + self.dumpToStream(std.io.getStdErr().writer()) catch return; } /// Dumps the contents of the queue to `stream`. @@ -351,7 +351,7 @@ test "std.atomic.Queue dump" { // Test empty stream fbs.reset(); - try queue.dumpToStream(fbs.outStream()); + try queue.dumpToStream(fbs.writer()); expect(mem.eql(u8, buffer[0..fbs.pos], \\head: (null) \\tail: (null) @@ -367,7 +367,7 @@ test "std.atomic.Queue dump" { queue.put(&node_0); fbs.reset(); - try queue.dumpToStream(fbs.outStream()); + try queue.dumpToStream(fbs.writer()); var expected = try std.fmt.bufPrint(expected_buffer[0..], \\head: 0x{x}=1 @@ -387,7 +387,7 @@ test "std.atomic.Queue dump" { queue.put(&node_1); fbs.reset(); - try queue.dumpToStream(fbs.outStream()); + try queue.dumpToStream(fbs.writer()); expected = try std.fmt.bufPrint(expected_buffer[0..], \\head: 0x{x}=1 diff --git a/lib/std/build.zig b/lib/std/build.zig index 0d17b4753a..cb4cb229e3 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1042,7 +1042,7 @@ pub const Builder = struct { try child.spawn(); - const stdout = try child.stdout.?.inStream().readAllAlloc(self.allocator, max_output_size); + const stdout = try child.stdout.?.reader().readAllAlloc(self.allocator, max_output_size); errdefer self.allocator.free(stdout); const term = try child.wait(); @@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct { } pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void { - const out = self.build_options_contents.outStream(); + const out = self.build_options_contents.writer(); switch (T) { []const []const u8 => { out.print("pub const {z}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable; @@ -2295,16 +2295,16 @@ pub const LibExeObjStep = struct { } else { var mcpu_buffer = std.ArrayList(u8).init(builder.allocator); - try mcpu_buffer.outStream().print("-mcpu={s}", .{cross.cpu.model.name}); + try mcpu_buffer.writer().print("-mcpu={s}", .{cross.cpu.model.name}); for (all_features) |feature, i_usize| { const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); const in_cpu_set = populated_cpu_features.isEnabled(i); const in_actual_set = cross.cpu.features.isEnabled(i); if (in_cpu_set and !in_actual_set) { - try mcpu_buffer.outStream().print("-{s}", .{feature.name}); + try mcpu_buffer.writer().print("-{s}", .{feature.name}); } else if (!in_cpu_set and in_actual_set) { - try mcpu_buffer.outStream().print("+{s}", .{feature.name}); + try mcpu_buffer.writer().print("+{s}", .{feature.name}); } } diff --git a/lib/std/build/run.zig b/lib/std/build/run.zig index 36a4a1a843..8f8fa2eba0 100644 --- a/lib/std/build/run.zig +++ b/lib/std/build/run.zig @@ -200,7 +200,7 @@ pub const RunStep = struct { switch (self.stdout_action) { .expect_exact, .expect_matches => { - stdout = child.stdout.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; + stdout = child.stdout.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; }, .inherit, .ignore => {}, } @@ -210,7 +210,7 @@ pub const RunStep = struct { switch (self.stderr_action) { .expect_exact, .expect_matches => { - stderr = child.stderr.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; + stderr = child.stderr.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; }, .inherit, .ignore => {}, } diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 4360cc7d73..d37dd9fdf5 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -922,7 +922,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void { .capable_io_mode = .blocking, .intended_io_mode = .blocking, }; - file.outStream().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources; + file.writer().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources; } fn readIntFd(fd: i32) !ErrInt { diff --git a/lib/std/coff.zig b/lib/std/coff.zig index fdc2ec5a82..85000bf8cb 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -127,7 +127,7 @@ pub const Coff = struct { pub fn loadHeader(self: *Coff) !void { const pe_pointer_offset = 0x3C; - const in = self.in_file.inStream(); + const in = self.in_file.reader(); var magic: [2]u8 = undefined; try in.readNoEof(magic[0..]); @@ -163,7 +163,7 @@ pub const Coff = struct { } fn loadOptionalHeader(self: *Coff) !void { - const in = self.in_file.inStream(); + const in = self.in_file.reader(); self.pe_header.magic = try in.readIntLittle(u16); // For now we're only interested in finding the reference to the .pdb, // so we'll skip most of this header, which size is different in 32 @@ -206,7 +206,7 @@ pub const Coff = struct { const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY]; const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; - const in = self.in_file.inStream(); + const in = self.in_file.reader(); try self.in_file.seekTo(file_offset); // Find the correct DebugDirectoryEntry, and where its data is stored. @@ -257,7 +257,7 @@ pub const Coff = struct { try self.sections.ensureCapacity(self.coff_header.number_of_sections); - const in = self.in_file.inStream(); + const in = self.in_file.reader(); var name: [8]u8 = undefined; diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig index 5b3b837d13..00336aef87 100644 --- a/lib/std/crypto/benchmark.zig +++ b/lib/std/crypto/benchmark.zig @@ -314,7 +314,7 @@ fn mode(comptime x: comptime_int) comptime_int { } pub fn main() !void { - const stdout = std.io.getStdOut().outStream(); + const stdout = std.io.getStdOut().writer(); var buffer: [1024]u8 = undefined; var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 073f68da5d..b19f96892f 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -517,15 +517,15 @@ fn populateModule(di: *ModuleDebugInfo, mod: *Module) !void { const modi = di.pdb.getStreamById(mod.mod_info.ModuleSymStream) orelse return error.MissingDebugInfo; - const signature = try modi.inStream().readIntLittle(u32); + const signature = try modi.reader().readIntLittle(u32); if (signature != 4) return error.InvalidDebugInfo; mod.symbols = try allocator.alloc(u8, mod.mod_info.SymByteSize - 4); - try modi.inStream().readNoEof(mod.symbols); + try modi.reader().readNoEof(mod.symbols); mod.subsect_info = try allocator.alloc(u8, mod.mod_info.C13ByteSize); - try modi.inStream().readNoEof(mod.subsect_info); + try modi.reader().readNoEof(mod.subsect_info); var sect_offset: usize = 0; var skip_len: usize = undefined; @@ -704,11 +704,11 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf try di.pdb.openFile(di.coff, path); var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo; - const version = try pdb_stream.inStream().readIntLittle(u32); - const signature = try pdb_stream.inStream().readIntLittle(u32); - const age = try pdb_stream.inStream().readIntLittle(u32); + const version = try pdb_stream.reader().readIntLittle(u32); + const signature = try pdb_stream.reader().readIntLittle(u32); + const age = try pdb_stream.reader().readIntLittle(u32); var guid: [16]u8 = undefined; - try pdb_stream.inStream().readNoEof(&guid); + try pdb_stream.reader().readNoEof(&guid); if (version != 20000404) // VC70, only value observed by LLVM team return error.UnknownPDBVersion; if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age) @@ -716,9 +716,9 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf // We validated the executable and pdb match. const string_table_index = str_tab_index: { - const name_bytes_len = try pdb_stream.inStream().readIntLittle(u32); + const name_bytes_len = try pdb_stream.reader().readIntLittle(u32); const name_bytes = try allocator.alloc(u8, name_bytes_len); - try pdb_stream.inStream().readNoEof(name_bytes); + try pdb_stream.reader().readNoEof(name_bytes); const HashTableHeader = packed struct { Size: u32, @@ -728,17 +728,17 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf return cap * 2 / 3 + 1; } }; - const hash_tbl_hdr = try pdb_stream.inStream().readStruct(HashTableHeader); + const hash_tbl_hdr = try pdb_stream.reader().readStruct(HashTableHeader); if (hash_tbl_hdr.Capacity == 0) return error.InvalidDebugInfo; if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity)) return error.InvalidDebugInfo; - const present = try readSparseBitVector(&pdb_stream.inStream(), allocator); + const present = try readSparseBitVector(&pdb_stream.reader(), allocator); if (present.len != hash_tbl_hdr.Size) return error.InvalidDebugInfo; - const deleted = try readSparseBitVector(&pdb_stream.inStream(), allocator); + const deleted = try readSparseBitVector(&pdb_stream.reader(), allocator); const Bucket = struct { first: u32, @@ -746,8 +746,8 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf }; const bucket_list = try allocator.alloc(Bucket, present.len); for (present) |_| { - const name_offset = try pdb_stream.inStream().readIntLittle(u32); - const name_index = try pdb_stream.inStream().readIntLittle(u32); + const name_offset = try pdb_stream.reader().readIntLittle(u32); + const name_index = try pdb_stream.reader().readIntLittle(u32); const name = mem.spanZ(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0)); if (mem.eql(u8, name, "/names")) { break :str_tab_index name_index; @@ -762,7 +762,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf const dbi = di.pdb.dbi; // Dbi Header - const dbi_stream_header = try dbi.inStream().readStruct(pdb.DbiStreamHeader); + const dbi_stream_header = try dbi.reader().readStruct(pdb.DbiStreamHeader); if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team return error.UnknownPDBVersion; if (dbi_stream_header.Age != age) @@ -776,7 +776,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf // Module Info Substream var mod_info_offset: usize = 0; while (mod_info_offset != mod_info_size) { - const mod_info = try dbi.inStream().readStruct(pdb.ModInfo); + const mod_info = try dbi.reader().readStruct(pdb.ModInfo); var this_record_len: usize = @sizeOf(pdb.ModInfo); const module_name = try dbi.readNullTermString(allocator); @@ -814,14 +814,14 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator); var sect_cont_offset: usize = 0; if (section_contrib_size != 0) { - const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.inStream().readIntLittle(u32)); + const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.reader().readIntLittle(u32)); if (ver != pdb.SectionContrSubstreamVersion.Ver60) return error.InvalidDebugInfo; sect_cont_offset += @sizeOf(u32); } while (sect_cont_offset != section_contrib_size) { const entry = try sect_contribs.addOne(); - entry.* = try dbi.inStream().readStruct(pdb.SectionContribEntry); + entry.* = try dbi.reader().readStruct(pdb.SectionContribEntry); sect_cont_offset += @sizeOf(pdb.SectionContribEntry); if (sect_cont_offset > section_contrib_size) diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 2e732cbc75..6769a139da 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -408,7 +408,7 @@ pub const DwarfInfo = struct { fn scanAllFunctions(di: *DwarfInfo) !void { var stream = io.fixedBufferStream(di.debug_info); - const in = &stream.inStream(); + const in = &stream.reader(); const seekable = &stream.seekableStream(); var this_unit_offset: u64 = 0; @@ -512,7 +512,7 @@ pub const DwarfInfo = struct { fn scanAllCompileUnits(di: *DwarfInfo) !void { var stream = io.fixedBufferStream(di.debug_info); - const in = &stream.inStream(); + const in = &stream.reader(); const seekable = &stream.seekableStream(); var this_unit_offset: u64 = 0; @@ -585,7 +585,7 @@ pub const DwarfInfo = struct { if (di.debug_ranges) |debug_ranges| { if (compile_unit.die.getAttrSecOffset(AT_ranges)) |ranges_offset| { var stream = io.fixedBufferStream(debug_ranges); - const in = &stream.inStream(); + const in = &stream.reader(); const seekable = &stream.seekableStream(); // All the addresses in the list are relative to the value @@ -640,7 +640,7 @@ pub const DwarfInfo = struct { fn parseAbbrevTable(di: *DwarfInfo, offset: u64) !AbbrevTable { var stream = io.fixedBufferStream(di.debug_abbrev); - const in = &stream.inStream(); + const in = &stream.reader(); const seekable = &stream.seekableStream(); try seekable.seekTo(offset); @@ -691,7 +691,7 @@ pub const DwarfInfo = struct { pub fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !debug.LineInfo { var stream = io.fixedBufferStream(di.debug_line); - const in = &stream.inStream(); + const in = &stream.reader(); const seekable = &stream.seekableStream(); const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT_comp_dir); diff --git a/lib/std/heap/logging_allocator.zig b/lib/std/heap/logging_allocator.zig index 47a584bb1d..7920138e9b 100644 --- a/lib/std/heap/logging_allocator.zig +++ b/lib/std/heap/logging_allocator.zig @@ -89,7 +89,7 @@ test "LoggingAllocator" { var allocator_buf: [10]u8 = undefined; var fixedBufferAllocator = std.mem.validationWrap(std.heap.FixedBufferAllocator.init(&allocator_buf)); - const allocator = &loggingAllocator(&fixedBufferAllocator.allocator, fbs.outStream()).allocator; + const allocator = &loggingAllocator(&fixedBufferAllocator.allocator, fbs.writer()).allocator; var a = try allocator.alloc(u8, 10); a = allocator.shrink(a, 5); diff --git a/lib/std/io/buffered_atomic_file.zig b/lib/std/io/buffered_atomic_file.zig index 9d65e9d193..66c349d318 100644 --- a/lib/std/io/buffered_atomic_file.zig +++ b/lib/std/io/buffered_atomic_file.zig @@ -38,7 +38,7 @@ pub const BufferedAtomicFile = struct { self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options); errdefer self.atomic_file.deinit(); - self.file_stream = self.atomic_file.file.outStream(); + self.file_stream = self.atomic_file.file.writer(); self.buffered_stream = .{ .unbuffered_writer = self.file_stream }; return self; } diff --git a/lib/std/io/fixed_buffer_stream.zig b/lib/std/io/fixed_buffer_stream.zig index b36949e538..1711b6da1b 100644 --- a/lib/std/io/fixed_buffer_stream.zig +++ b/lib/std/io/fixed_buffer_stream.zig @@ -45,7 +45,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type { return .{ .context = self }; } - /// Deprecated: use `inStream` + /// Deprecated: use `reader` pub fn inStream(self: *Self) InStream { return .{ .context = self }; } diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index 85357ae58a..9fdef0de1d 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -30,8 +30,8 @@ test "write a file, read it, then delete it" { var file = try tmp.dir.createFile(tmp_file_name, .{}); defer file.close(); - var buf_stream = io.bufferedOutStream(file.outStream()); - const st = buf_stream.outStream(); + var buf_stream = io.bufferedWriter(file.writer()); + const st = buf_stream.writer(); try st.print("begin", .{}); try st.writeAll(data[0..]); try st.print("end", .{}); @@ -72,7 +72,7 @@ test "BitStreams with File Stream" { var file = try tmp.dir.createFile(tmp_file_name, .{}); defer file.close(); - var bit_stream = io.bitOutStream(builtin.endian, file.outStream()); + var bit_stream = io.bitWriter(builtin.endian, file.writer()); try bit_stream.writeBits(@as(u2, 1), 1); try bit_stream.writeBits(@as(u5, 2), 2); diff --git a/lib/std/json.zig b/lib/std/json.zig index 87808a7350..5cbdb4319e 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1323,31 +1323,31 @@ test "Value.jsonStringify" { { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); - try @as(Value, .Null).jsonStringify(.{}, fbs.outStream()); + try @as(Value, .Null).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "null"); } { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); - try (Value{ .Bool = true }).jsonStringify(.{}, fbs.outStream()); + try (Value{ .Bool = true }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "true"); } { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); - try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.outStream()); + try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "42"); } { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); - try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.outStream()); + try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01"); } { var buffer: [10]u8 = undefined; var fbs = std.io.fixedBufferStream(&buffer); - try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.outStream()); + try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\""); } { @@ -1360,7 +1360,7 @@ test "Value.jsonStringify" { }; try (Value{ .Array = Array.fromOwnedSlice(undefined, &vals), - }).jsonStringify(.{}, fbs.outStream()); + }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]"); } { @@ -1369,7 +1369,7 @@ test "Value.jsonStringify" { var obj = ObjectMap.init(testing.allocator); defer obj.deinit(); try obj.putNoClobber("a", .{ .String = "b" }); - try (Value{ .Object = obj }).jsonStringify(.{}, fbs.outStream()); + try (Value{ .Object = obj }).jsonStringify(.{}, fbs.writer()); testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}"); } } @@ -2223,7 +2223,7 @@ test "write json then parse it" { var out_buffer: [1000]u8 = undefined; var fixed_buffer_stream = std.io.fixedBufferStream(&out_buffer); - const out_stream = fixed_buffer_stream.outStream(); + const out_stream = fixed_buffer_stream.writer(); var jw = writeStream(out_stream, 4); try jw.beginObject(); diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index 9322ca5429..b4a8aed84c 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -238,7 +238,7 @@ pub fn writeStream( test "json write stream" { var out_buf: [1024]u8 = undefined; var slice_stream = std.io.fixedBufferStream(&out_buf); - const out = slice_stream.outStream(); + const out = slice_stream.writer(); var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_allocator.deinit(); diff --git a/lib/std/net.zig b/lib/std/net.zig index da35bd88b0..037df76907 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -1106,7 +1106,7 @@ fn linuxLookupNameFromHosts( }; defer file.close(); - const stream = std.io.bufferedInStream(file.inStream()).inStream(); + const stream = std.io.bufferedReader(file.reader()).reader(); var line_buf: [512]u8 = undefined; while (stream.readUntilDelimiterOrEof(&line_buf, '\n') catch |err| switch (err) { error.StreamTooLong => blk: { @@ -1304,7 +1304,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void { }; defer file.close(); - const stream = std.io.bufferedInStream(file.inStream()).inStream(); + const stream = std.io.bufferedReader(file.reader()).reader(); var line_buf: [512]u8 = undefined; while (stream.readUntilDelimiterOrEof(&line_buf, '\n') catch |err| switch (err) { error.StreamTooLong => blk: { diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 110c6ec9c0..74ae1ddf4f 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -249,6 +249,6 @@ fn testServer(server: *net.StreamServer) anyerror!void { var client = try server.accept(); - const stream = client.file.outStream(); + const stream = client.file.writer(); try stream.print("hello from server\n", .{}); } diff --git a/lib/std/os.zig b/lib/std/os.zig index e9bf6379cc..42bdf486d7 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -191,7 +191,7 @@ fn getRandomBytesDevURandom(buf: []u8) !void { .capable_io_mode = .blocking, .intended_io_mode = .blocking, }; - const stream = file.inStream(); + const stream = file.reader(); stream.readNoEof(buf) catch return error.Unexpected; } diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 65dee90e62..0904a8585f 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -475,7 +475,7 @@ test "mmap" { const file = try tmp.dir.createFile(test_out_file, .{}); defer file.close(); - const stream = file.outStream(); + const stream = file.writer(); var i: u32 = 0; while (i < alloc_size / @sizeOf(u32)) : (i += 1) { @@ -499,7 +499,7 @@ test "mmap" { defer os.munmap(data); var mem_stream = io.fixedBufferStream(data); - const stream = mem_stream.inStream(); + const stream = mem_stream.reader(); var i: u32 = 0; while (i < alloc_size / @sizeOf(u32)) : (i += 1) { @@ -523,7 +523,7 @@ test "mmap" { defer os.munmap(data); var mem_stream = io.fixedBufferStream(data); - const stream = mem_stream.inStream(); + const stream = mem_stream.reader(); var i: u32 = alloc_size / 2 / @sizeOf(u32); while (i < alloc_size / @sizeOf(u32)) : (i += 1) { diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index f2fa2dc3b8..0b7baf0fc1 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -57,8 +57,8 @@ pub fn main() !void { var targets = ArrayList([]const u8).init(allocator); - const stderr_stream = io.getStdErr().outStream(); - const stdout_stream = io.getStdOut().outStream(); + const stderr_stream = io.getStdErr().writer(); + const stdout_stream = io.getStdOut().writer(); while (nextArg(args, &arg_idx)) |arg| { if (mem.startsWith(u8, arg, "-D")) { diff --git a/lib/std/unicode/throughput_test.zig b/lib/std/unicode/throughput_test.zig index 2676a30cb2..8f9f9d9cb7 100644 --- a/lib/std/unicode/throughput_test.zig +++ b/lib/std/unicode/throughput_test.zig @@ -45,7 +45,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount { } pub fn main() !void { - const stdout = std.io.getStdOut().outStream(); + const stdout = std.io.getStdOut().writer(); const args = try std.process.argsAlloc(std.heap.page_allocator); diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 060dd83caf..f0849f9a03 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -519,29 +519,29 @@ pub const CrossTarget = struct { var result = std.ArrayList(u8).init(allocator); defer result.deinit(); - try result.outStream().print("{s}-{s}", .{ arch_name, os_name }); + try result.writer().print("{s}-{s}", .{ arch_name, os_name }); // The zig target syntax does not allow specifying a max os version with no min, so // if either are present, we need the min. if (self.os_version_min != null or self.os_version_max != null) { switch (self.getOsVersionMin()) { .none => {}, - .semver => |v| try result.outStream().print(".{}", .{v}), - .windows => |v| try result.outStream().print("{s}", .{v}), + .semver => |v| try result.writer().print(".{}", .{v}), + .windows => |v| try result.writer().print("{s}", .{v}), } } if (self.os_version_max) |max| { switch (max) { .none => {}, - .semver => |v| try result.outStream().print("...{}", .{v}), - .windows => |v| try result.outStream().print("..{s}", .{v}), + .semver => |v| try result.writer().print("...{}", .{v}), + .windows => |v| try result.writer().print("..{s}", .{v}), } } if (self.glibc_version) |v| { - try result.outStream().print("-{s}.{}", .{ @tagName(self.getAbi()), v }); + try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v }); } else if (self.abi) |abi| { - try result.outStream().print("-{s}", .{@tagName(abi)}); + try result.writer().print("-{s}", .{@tagName(abi)}); } return result.toOwnedSlice(); diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 63d04f9a80..d7cc1208a2 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -3734,7 +3734,7 @@ const maxInt = std.math.maxInt; var fixed_buffer_mem: [100 * 1024]u8 = undefined; fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 { - const stderr = io.getStdErr().outStream(); + const stderr = io.getStdErr().writer(); const tree = try std.zig.parse(allocator, source); defer tree.deinit(); @@ -3767,8 +3767,8 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b var buffer = std.ArrayList(u8).init(allocator); errdefer buffer.deinit(); - const outStream = buffer.outStream(); - anything_changed.* = try std.zig.render(allocator, outStream, tree); + const writer = buffer.writer(); + anything_changed.* = try std.zig.render(allocator, writer, tree); return buffer.toOwnedSlice(); } fn testTransform(source: []const u8, expected_source: []const u8) !void { diff --git a/lib/std/zig/perf_test.zig b/lib/std/zig/perf_test.zig index e1c58c1469..b111170902 100644 --- a/lib/std/zig/perf_test.zig +++ b/lib/std/zig/perf_test.zig @@ -29,7 +29,7 @@ pub fn main() !void { const mb_per_sec = bytes_per_sec / (1024 * 1024); var stdout_file = std.io.getStdOut(); - const stdout = stdout_file.outStream(); + const stdout = stdout_file.writer(); try stdout.print("{:.3} MiB/s, {} KiB used \n", .{ mb_per_sec, memory_used / 1024 }); } diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 6931b19250..b882d71cfd 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -790,7 +790,7 @@ fn renderExpression( const section_exprs = row_exprs[0..section_end]; // Null stream for counting the printed length of each expression - var line_find_stream = std.io.findByteOutStream('\n', std.io.null_out_stream); + var line_find_stream = std.io.findByteOutStream('\n', std.io.null_writer); var counting_stream = std.io.countingOutStream(line_find_stream.writer()); var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, counting_stream.writer()); @@ -954,7 +954,7 @@ fn renderExpression( const expr_outputs_one_line = blk: { // render field expressions until a LF is found for (field_inits) |field_init| { - var find_stream = std.io.findByteOutStream('\n', std.io.null_out_stream); + var find_stream = std.io.findByteOutStream('\n', std.io.null_writer); var auto_indenting_stream = std.io.autoIndentingStream(indent_delta, find_stream.writer()); try renderExpression(allocator, &auto_indenting_stream, tree, field_init, Space.None); diff --git a/src/Cache.zig b/src/Cache.zig index 9f8beaabc7..f5ffb34dbe 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -285,7 +285,7 @@ pub const Manifest = struct { }; } - const file_contents = try self.manifest_file.?.inStream().readAllAlloc(self.cache.gpa, manifest_file_size_max); + const file_contents = try self.manifest_file.?.reader().readAllAlloc(self.cache.gpa, manifest_file_size_max); defer self.cache.gpa.free(file_contents); const input_file_count = self.files.items.len; diff --git a/src/Compilation.zig b/src/Compilation.zig index 95c9435aa7..a81926bf19 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1820,7 +1820,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { var out_zig_file = try o_dir.createFile(cimport_zig_basename, .{}); defer out_zig_file.close(); - var bos = std.io.bufferedOutStream(out_zig_file.writer()); + var bos = std.io.bufferedWriter(out_zig_file.writer()); _ = try std.zig.render(comp.gpa, bos.writer(), tree); try bos.flush(); @@ -2750,7 +2750,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 switch (target.os.getVersionRange()) { .none => try buffer.appendSlice(" .none = {} }\n"), - .semver => |semver| try buffer.outStream().print( + .semver => |semver| try buffer.writer().print( \\ .semver = .{{ \\ .min = .{{ \\ .major = {}, @@ -2773,7 +2773,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 semver.max.minor, semver.max.patch, }), - .linux => |linux| try buffer.outStream().print( + .linux => |linux| try buffer.writer().print( \\ .linux = .{{ \\ .range = .{{ \\ .min = .{{ @@ -2807,7 +2807,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 linux.glibc.minor, linux.glibc.patch, }), - .windows => |windows| try buffer.outStream().print( + .windows => |windows| try buffer.writer().print( \\ .windows = .{{ \\ .min = {s}, \\ .max = {s}, diff --git a/src/DepTokenizer.zig b/src/DepTokenizer.zig index 0fe1310cd8..b246a22bd0 100644 --- a/src/DepTokenizer.zig +++ b/src/DepTokenizer.zig @@ -910,7 +910,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { }, else => { try buffer.appendSlice("ERROR: "); - try token.printError(buffer.outStream()); + try token.printError(buffer.writer()); break; }, } diff --git a/src/Module.zig b/src/Module.zig index 603c97ffee..9707e79e2a 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1649,7 +1649,7 @@ pub fn getAstTree(self: *Module, root_scope: *Scope.File) !*ast.Tree { var msg = std.ArrayList(u8).init(self.gpa); defer msg.deinit(); - try parse_err.render(tree.token_ids, msg.outStream()); + try parse_err.render(tree.token_ids, msg.writer()); const err_msg = try self.gpa.create(Compilation.ErrorMsg); err_msg.* = .{ .msg = msg.toOwnedSlice(), diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index df97f7e0ef..9b35c42c6e 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -200,7 +200,7 @@ pub const LLVMIRModule = struct { if (llvm.Target.getFromTriple(llvm_target_triple.ptr, &target, &error_message)) { defer llvm.disposeMessage(error_message); - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); try stderr.print( \\Zig is expecting LLVM to understand this target: '{s}' \\However LLVM responded with: "{s}" @@ -268,7 +268,7 @@ pub const LLVMIRModule = struct { const dump = self.llvm_module.printToString(); defer llvm.disposeMessage(dump); - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); try stderr.writeAll(std.mem.spanZ(dump)); } @@ -278,7 +278,7 @@ pub const LLVMIRModule = struct { defer llvm.disposeMessage(error_message); if (self.llvm_module.verify(.ReturnStatus, &error_message)) { - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); try stderr.print("broken LLVM module found: {s}\nThis is a bug in the Zig compiler.", .{error_message}); return error.BrokenLLVMModule; } @@ -296,7 +296,7 @@ pub const LLVMIRModule = struct { )) { defer llvm.disposeMessage(error_message); - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); try stderr.print("LLVM failed to emit file: {s}\n", .{error_message}); return error.FailedToEmit; } diff --git a/src/libc_installation.zig b/src/libc_installation.zig index bc317869e8..05c85578ea 100644 --- a/src/libc_installation.zig +++ b/src/libc_installation.zig @@ -338,7 +338,7 @@ pub const LibCInstallation = struct { for (searches) |search| { result_buf.shrinkAndFree(0); - try result_buf.outStream().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version }); + try result_buf.writer().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { error.FileNotFound, @@ -384,7 +384,7 @@ pub const LibCInstallation = struct { for (searches) |search| { result_buf.shrinkAndFree(0); - try result_buf.outStream().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir }); + try result_buf.writer().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { error.FileNotFound, @@ -438,7 +438,7 @@ pub const LibCInstallation = struct { for (searches) |search| { result_buf.shrinkAndFree(0); - const stream = result_buf.outStream(); + const stream = result_buf.writer(); try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ search.path, search.version, arch_sub_dir }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { diff --git a/src/main.zig b/src/main.zig index cd89f269d0..7829901acc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -196,7 +196,7 @@ pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v return cmdInit(gpa, arena, cmd_args, .Lib); } else if (mem.eql(u8, cmd, "targets")) { const info = try detectNativeTargetInfo(arena, .{}); - const stdout = io.getStdOut().outStream(); + const stdout = io.getStdOut().writer(); return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target); } else if (mem.eql(u8, cmd, "version")) { try std.io.getStdOut().writeAll(build_options.version ++ "\n"); @@ -1944,8 +1944,8 @@ fn buildOutputType( } } - const stdin = std.io.getStdIn().inStream(); - const stderr = std.io.getStdErr().outStream(); + const stdin = std.io.getStdIn().reader(); + const stderr = std.io.getStdErr().writer(); var repl_buf: [1024]u8 = undefined; while (watch) { @@ -2114,9 +2114,9 @@ fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !voi var zig_file = try o_dir.createFile(translated_zig_basename, .{}); defer zig_file.close(); - var bos = io.bufferedOutStream(zig_file.writer()); - _ = try std.zig.render(comp.gpa, bos.writer(), tree); - try bos.flush(); + var bw = io.bufferedWriter(zig_file.writer()); + _ = try std.zig.render(comp.gpa, bw.writer(), tree); + try bw.flush(); man.writeManifest() catch |err| warn("failed to write cache manifest: {s}", .{@errorName(err)}); @@ -2187,9 +2187,9 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void { }; defer libc.deinit(gpa); - var bos = io.bufferedOutStream(io.getStdOut().writer()); - try libc.render(bos.writer()); - try bos.flush(); + var bw = io.bufferedWriter(io.getStdOut().writer()); + try libc.render(bw.writer()); + try bw.flush(); } } @@ -2570,7 +2570,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void { const arg = args[i]; if (mem.startsWith(u8, arg, "-")) { if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { - const stdout = io.getStdOut().outStream(); + const stdout = io.getStdOut().writer(); try stdout.writeAll(usage_fmt); return cleanExit(); } else if (mem.eql(u8, arg, "--color")) { @@ -2600,7 +2600,7 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void { fatal("cannot use --stdin with positional arguments", .{}); } - const stdin = io.getStdIn().inStream(); + const stdin = io.getStdIn().reader(); const source_code = try stdin.readAllAlloc(gpa, max_src_size); defer gpa.free(source_code); @@ -2617,14 +2617,14 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void { process.exit(1); } if (check_flag) { - const anything_changed = try std.zig.render(gpa, io.null_out_stream, tree); + const anything_changed = try std.zig.render(gpa, io.null_writer, tree); const code = if (anything_changed) @as(u8, 1) else @as(u8, 0); process.exit(code); } - var bos = io.bufferedOutStream(io.getStdOut().writer()); - _ = try std.zig.render(gpa, bos.writer(), tree); - try bos.flush(); + var bw = io.bufferedWriter(io.getStdOut().writer()); + _ = try std.zig.render(gpa, bw.writer(), tree); + try bw.flush(); return; } @@ -2774,7 +2774,7 @@ fn fmtPathFile( } if (check_mode) { - const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree); + const anything_changed = try std.zig.render(fmt.gpa, io.null_writer, tree); if (anything_changed) { const stdout = io.getStdOut().writer(); try stdout.print("{s}\n", .{file_path}); @@ -2823,11 +2823,11 @@ fn printErrMsgToFile( var text_buf = std.ArrayList(u8).init(gpa); defer text_buf.deinit(); - const out_stream = text_buf.outStream(); - try parse_error.render(tree.token_ids, out_stream); + const writer = text_buf.writer(); + try parse_error.render(tree.token_ids, writer); const text = text_buf.items; - const stream = file.outStream(); + const stream = file.writer(); try stream.print("{s}:{d}:{d}: error: {s}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text }); if (!color_on) return; diff --git a/src/print_env.zig b/src/print_env.zig index bcf4a983ab..d62e1f62fd 100644 --- a/src/print_env.zig +++ b/src/print_env.zig @@ -20,10 +20,10 @@ pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Wri const global_cache_dir = try introspect.resolveGlobalCacheDir(gpa); defer gpa.free(global_cache_dir); - var bos = std.io.bufferedOutStream(stdout); - const bos_stream = bos.outStream(); + var bw = std.io.bufferedWriter(stdout); + const w = bw.writer(); - var jws = std.json.WriteStream(@TypeOf(bos_stream), 6).init(bos_stream); + var jws = std.json.WriteStream(@TypeOf(w), 6).init(w); try jws.beginObject(); try jws.objectField("zig_exe"); @@ -42,6 +42,6 @@ pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Wri try jws.emitString(build_options.version); try jws.endObject(); - try bos_stream.writeByte('\n'); - try bos.flush(); + try w.writeByte('\n'); + try bw.flush(); } diff --git a/src/print_targets.zig b/src/print_targets.zig index cf55eee516..e24a2294a1 100644 --- a/src/print_targets.zig +++ b/src/print_targets.zig @@ -26,9 +26,9 @@ pub fn cmdTargets( const glibc_abi = try glibc.loadMetaData(allocator, zig_lib_directory.handle); defer glibc_abi.destroy(allocator); - var bos = io.bufferedOutStream(stdout); - const bos_stream = bos.outStream(); - var jws = std.json.WriteStream(@TypeOf(bos_stream), 6).init(bos_stream); + var bw = io.bufferedWriter(stdout); + const w = bw.writer(); + var jws = std.json.WriteStream(@TypeOf(w), 6).init(w); try jws.beginObject(); @@ -156,6 +156,6 @@ pub fn cmdTargets( try jws.endObject(); - try bos_stream.writeByte('\n'); - return bos.flush(); + try w.writeByte('\n'); + return bw.flush(); } diff --git a/src/test.zig b/src/test.zig index 682fb5078f..2553e57ff4 100644 --- a/src/test.zig +++ b/src/test.zig @@ -738,7 +738,7 @@ pub const TestContext = struct { write_node.activate(); var out_zir = std.ArrayList(u8).init(allocator); defer out_zir.deinit(); - try new_zir_module.writeToStream(allocator, out_zir.outStream()); + try new_zir_module.writeToStream(allocator, out_zir.writer()); write_node.end(); var test_node = update_node.start("assert", 0); diff --git a/src/translate_c.zig b/src/translate_c.zig index 9369c6d4b8..8df7963267 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -5268,7 +5268,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, try c.token_locs.ensureCapacity(c.gpa, c.token_locs.items.len + 1); const start_index = c.source_buffer.items.len; - try c.source_buffer.outStream().print(format ++ " ", args); + try c.source_buffer.writer().print(format ++ " ", args); c.token_ids.appendAssumeCapacity(token_id); c.token_locs.appendAssumeCapacity(.{ diff --git a/src/zir.zig b/src/zir.zig index 63850d67db..b3d004f1dc 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -1116,7 +1116,7 @@ pub const Module = struct { /// This is a debugging utility for rendering the tree to stderr. pub fn dump(self: Module) void { - self.writeToStream(std.heap.page_allocator, std.io.getStdErr().outStream()) catch {}; + self.writeToStream(std.heap.page_allocator, std.io.getStdErr().writer()) catch {}; } const DeclAndIndex = struct { @@ -3254,7 +3254,7 @@ pub fn dumpZir(allocator: *Allocator, kind: []const u8, decl_name: [*:0]const u8 try write.inst_table.ensureCapacity(@intCast(u32, instructions.len)); - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); try stderr.print("{s} {s} {{ // unanalyzed\n", .{ kind, decl_name }); for (instructions) |inst| { diff --git a/test/compare_output.zig b/test/compare_output.zig index 9dc80f202d..a6e9835ea1 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -22,7 +22,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() void { \\ privateFunction(); - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK 2\n", .{}) catch unreachable; \\} \\ @@ -37,7 +37,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\// purposefully conflicting function with main.zig \\// but it's private so it should be OK \\fn privateFunction() void { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK 1\n", .{}) catch unreachable; \\} \\ @@ -63,7 +63,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { tc.addSourceFile("foo.zig", \\usingnamespace @import("std").io; \\pub fn foo_function() void { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\} ); @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn bar_function() void { \\ if (foo_function()) { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\ } \\} @@ -106,7 +106,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\pub const a_text = "OK\n"; \\ \\pub fn ok() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print(b_text, .{}) catch unreachable; \\} ); @@ -124,7 +124,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\ \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable; \\} , "Hello, world!\n 12 12 a\n"); @@ -267,7 +267,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ var x_local : i32 = print_ok(x); \\} \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\ return 0; \\} @@ -349,7 +349,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\pub fn main() void { \\ const bar = Bar {.field2 = 13,}; \\ const foo = Foo {.field1 = bar,}; - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ if (!foo.method()) { \\ stdout.print("BAD\n", .{}) catch unreachable; \\ } @@ -363,7 +363,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.add("defer with only fallthrough", \\const io = @import("std").io; \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ defer stdout.print("defer2\n", .{}) catch unreachable; @@ -376,7 +376,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\const os = @import("std").os; \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ defer stdout.print("defer2\n", .{}) catch unreachable; @@ -393,7 +393,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ do_test() catch return; \\} \\fn do_test() !void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable; @@ -412,7 +412,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ do_test() catch return; \\} \\fn do_test() !void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable; @@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\ \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print(foo_txt, .{}) catch unreachable; \\} , "1234\nabcd\n"); @@ -448,7 +448,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() !void { \\ var args_it = std.process.args(); - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ var index: usize = 0; \\ _ = args_it.skip(); \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { @@ -487,7 +487,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() !void { \\ var args_it = std.process.args(); - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ var index: usize = 0; \\ _ = args_it.skip(); \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { diff --git a/test/stage1/behavior/bugs/5487.zig b/test/stage1/behavior/bugs/5487.zig index 02fa677a44..bf530a8a02 100644 --- a/test/stage1/behavior/bugs/5487.zig +++ b/test/stage1/behavior/bugs/5487.zig @@ -3,10 +3,10 @@ const io = @import("std").io; pub fn write(_: void, bytes: []const u8) !usize { return 0; } -pub fn outStream() io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) { - return io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} }; +pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) { + return io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} }; } test "crash" { - _ = io.multiOutStream(.{outStream()}); + _ = io.multiWriter(.{writer()}); } diff --git a/test/tests.zig b/test/tests.zig index 5ee381e5c2..ec6d9e1df8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -652,9 +652,9 @@ pub const StackTracesContext = struct { } child.spawn() catch |err| debug.panic("Unable to spawn {s}: {s}\n", .{ full_exe_path, @errorName(err) }); - const stdout = child.stdout.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; + const stdout = child.stdout.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; defer b.allocator.free(stdout); - const stderrFull = child.stderr.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; + const stderrFull = child.stderr.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; defer b.allocator.free(stderrFull); var stderr = stderrFull; @@ -875,8 +875,8 @@ pub const CompileErrorContext = struct { var stdout_buf = ArrayList(u8).init(b.allocator); var stderr_buf = ArrayList(u8).init(b.allocator); - child.stdout.?.inStream().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable; - child.stderr.?.inStream().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable; + child.stdout.?.reader().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable; + child.stderr.?.reader().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable; const term = child.wait() catch |err| { debug.panic("Unable to spawn {s}: {s}\n", .{ zig_args.items[0], @errorName(err) }); diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index fd64bb062a..ad380e0139 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -388,8 +388,8 @@ pub fn main() anyerror!void { // "W" and "Wl,". So we sort this list in order of descending priority. std.sort.sort(*json.ObjectMap, all_objects.items, {}, objectLessThan); - var stdout_bos = std.io.bufferedOutStream(std.io.getStdOut().outStream()); - const stdout = stdout_bos.outStream(); + var buffered_stdout = std.io.bufferedWriter(std.io.getStdOut().writer()); + const stdout = buffered_stdout.writer(); try stdout.writeAll( \\// This file is generated by tools/update_clang_options.zig. \\// zig fmt: off @@ -469,7 +469,7 @@ pub fn main() anyerror!void { \\ ); - try stdout_bos.flush(); + try buffered_stdout.flush(); } // TODO we should be able to import clang_options.zig but currently this is problematic because it will @@ -611,7 +611,7 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool { } fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn { - file.outStream().print( + file.writer().print( \\Usage: {} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project \\ diff --git a/tools/update_glibc.zig b/tools/update_glibc.zig index 03b746f0ab..1e23bf0ff8 100644 --- a/tools/update_glibc.zig +++ b/tools/update_glibc.zig @@ -239,7 +239,7 @@ pub fn main() !void { const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{}); defer vers_txt_file.close(); - var buffered = std.io.bufferedOutStream(vers_txt_file.writer()); + var buffered = std.io.bufferedWriter(vers_txt_file.writer()); const vers_txt = buffered.writer(); for (global_ver_list) |name, i| { _ = global_ver_set.put(name, i) catch unreachable; @@ -251,7 +251,7 @@ pub fn main() !void { const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" }); const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{}); defer fns_txt_file.close(); - var buffered = std.io.bufferedOutStream(fns_txt_file.writer()); + var buffered = std.io.bufferedWriter(fns_txt_file.writer()); const fns_txt = buffered.writer(); for (global_fn_list) |name, i| { const entry = global_fn_set.getEntry(name).?; @@ -282,7 +282,7 @@ pub fn main() !void { const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" }); const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{}); defer abilist_txt_file.close(); - var buffered = std.io.bufferedOutStream(abilist_txt_file.writer()); + var buffered = std.io.bufferedWriter(abilist_txt_file.writer()); const abilist_txt = buffered.writer(); // first iterate over the abi lists