authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-27 21:20:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-29 17:14:26-07:00
log79f267f6b9e7f80a6fed3b1019f9de942841c3be
tree29a243d4aa85d8295cc06608bde59333ebdb843c
parent558bea2a76179fcc00779fdd326e5a866956fc9b

std.Io: delete GenericReader

and delete deprecated alias std.io

156 files changed, 973 insertions(+), 1853 deletions(-)

lib/compiler/aro/aro/Attribute/names.zig+2-3
......@@ -117,8 +117,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
117117
118118 var node_index: u16 = 0;
119119 var count: u16 = index;
120 var fbs = std.io.fixedBufferStream(buf);
121 const w = fbs.writer();
120 var w: std.Io.Writer = .fixed(buf);
122121
123122 while (true) {
124123 var sibling_index = dafsa[node_index].child_index;
......@@ -140,7 +139,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 {
140139 if (count == 0) break;
141140 }
142141
143 return fbs.getWritten();
142 return w.buffered();
144143}
145144
146145const Node = packed struct(u32) {
lib/compiler/aro/aro/Compilation.zig+4-4
......@@ -1645,8 +1645,8 @@ test "addSourceFromReader" {
16451645 var comp = Compilation.init(std.testing.allocator, std.fs.cwd());
16461646 defer comp.deinit();
16471647
1648 var buf_reader = std.io.fixedBufferStream(str);
1649 const source = try comp.addSourceFromReader(buf_reader.reader(), "path", .user);
1648 var buf_reader: std.Io.Reader = .fixed(str);
1649 const source = try comp.addSourceFromReader(&buf_reader, "path", .user);
16501650
16511651 try std.testing.expectEqualStrings(expected, source.buf);
16521652 try std.testing.expectEqual(warning_count, @as(u32, @intCast(comp.diagnostics.list.items.len)));
......@@ -1727,8 +1727,8 @@ test "ignore BOM at beginning of file" {
17271727 var comp = Compilation.init(std.testing.allocator, std.fs.cwd());
17281728 defer comp.deinit();
17291729
1730 var buf_reader = std.io.fixedBufferStream(buf);
1731 const source = try comp.addSourceFromReader(buf_reader.reader(), "file.c", .user);
1730 var buf_reader: std.Io.Reader = .fixed(buf);
1731 const source = try comp.addSourceFromReader(&buf_reader, "file.c", .user);
17321732 const expected_output = if (mem.startsWith(u8, buf, BOM)) buf[BOM.len..] else buf;
17331733 try std.testing.expectEqualStrings(expected_output, source.buf);
17341734 }
lib/compiler/aro/aro/Diagnostics.zig+7-7
......@@ -322,14 +322,14 @@ pub fn addExtra(
322322 return error.FatalError;
323323}
324324
325pub fn render(comp: *Compilation, config: std.io.tty.Config) void {
325pub fn render(comp: *Compilation, config: std.Io.tty.Config) void {
326326 if (comp.diagnostics.list.items.len == 0) return;
327327 var buffer: [1000]u8 = undefined;
328328 var m = defaultMsgWriter(config, &buffer);
329329 defer m.deinit();
330330 renderMessages(comp, &m);
331331}
332pub fn defaultMsgWriter(config: std.io.tty.Config, buffer: []u8) MsgWriter {
332pub fn defaultMsgWriter(config: std.Io.tty.Config, buffer: []u8) MsgWriter {
333333 return MsgWriter.init(config, buffer);
334334}
335335
......@@ -451,7 +451,7 @@ pub fn renderMessage(comp: *Compilation, m: anytype, msg: Message) void {
451451 },
452452 .normalized => {
453453 const f = struct {
454 pub fn f(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
454 pub fn f(bytes: []const u8, writer: *std.Io.Writer) std.Io.Writer.Error!void {
455455 var it: std.unicode.Utf8Iterator = .{
456456 .bytes = bytes,
457457 .i = 0,
......@@ -526,10 +526,10 @@ fn tagKind(d: *Diagnostics, tag: Tag, langopts: LangOpts) Kind {
526526}
527527
528528const MsgWriter = struct {
529 writer: *std.io.Writer,
530 config: std.io.tty.Config,
529 writer: *std.Io.Writer,
530 config: std.Io.tty.Config,
531531
532 fn init(config: std.io.tty.Config, buffer: []u8) MsgWriter {
532 fn init(config: std.Io.tty.Config, buffer: []u8) MsgWriter {
533533 return .{
534534 .writer = std.debug.lockStderrWriter(buffer),
535535 .config = config,
......@@ -549,7 +549,7 @@ const MsgWriter = struct {
549549 m.writer.writeAll(msg) catch {};
550550 }
551551
552 fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {
552 fn setColor(m: *MsgWriter, color: std.Io.tty.Color) void {
553553 m.config.setColor(m.writer, color) catch {};
554554 }
555555
lib/compiler/aro/aro/Driver.zig+1-1
......@@ -544,7 +544,7 @@ pub fn renderErrors(d: *Driver) void {
544544 Diagnostics.render(d.comp, d.detectConfig(std.fs.File.stderr()));
545545}
546546
547pub fn detectConfig(d: *Driver, file: std.fs.File) std.io.tty.Config {
547pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config {
548548 if (d.color == true) return .escape_codes;
549549 if (d.color == false) return .no_color;
550550
lib/compiler/aro/aro/Tree.zig+8-8
......@@ -800,7 +800,7 @@ pub fn nodeLoc(tree: *const Tree, node: NodeIndex) ?Source.Location {
800800 return tree.tokens.items(.loc)[@intFromEnum(tok_i)];
801801}
802802
803pub fn dump(tree: *const Tree, config: std.io.tty.Config, writer: anytype) !void {
803pub fn dump(tree: *const Tree, config: std.Io.tty.Config, writer: anytype) !void {
804804 const mapper = tree.comp.string_interner.getFastTypeMapper(tree.comp.gpa) catch tree.comp.string_interner.getSlowTypeMapper();
805805 defer mapper.deinit(tree.comp.gpa);
806806
......@@ -855,17 +855,17 @@ fn dumpNode(
855855 node: NodeIndex,
856856 level: u32,
857857 mapper: StringInterner.TypeMapper,
858 config: std.io.tty.Config,
858 config: std.Io.tty.Config,
859859 w: anytype,
860860) !void {
861861 const delta = 2;
862862 const half = delta / 2;
863 const TYPE = std.io.tty.Color.bright_magenta;
864 const TAG = std.io.tty.Color.bright_cyan;
865 const IMPLICIT = std.io.tty.Color.bright_blue;
866 const NAME = std.io.tty.Color.bright_red;
867 const LITERAL = std.io.tty.Color.bright_green;
868 const ATTRIBUTE = std.io.tty.Color.bright_yellow;
863 const TYPE = std.Io.tty.Color.bright_magenta;
864 const TAG = std.Io.tty.Color.bright_cyan;
865 const IMPLICIT = std.Io.tty.Color.bright_blue;
866 const NAME = std.Io.tty.Color.bright_red;
867 const LITERAL = std.Io.tty.Color.bright_green;
868 const ATTRIBUTE = std.Io.tty.Color.bright_yellow;
869869 std.debug.assert(node != .none);
870870
871871 const tag = tree.nodes.items(.tag)[@intFromEnum(node)];
lib/compiler/aro/aro/target.zig+2-3
......@@ -578,8 +578,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
578578 // 64 bytes is assumed to be large enough to hold any target triple; increase if necessary
579579 std.debug.assert(buf.len >= 64);
580580
581 var stream = std.io.fixedBufferStream(buf);
582 const writer = stream.writer();
581 var writer: std.Io.Writer = .fixed(buf);
583582
584583 const llvm_arch = switch (target.cpu.arch) {
585584 .arm => "arm",
......@@ -718,7 +717,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
718717 .ohoseabi => "ohoseabi",
719718 };
720719 writer.writeAll(llvm_abi) catch unreachable;
721 return stream.getWritten();
720 return writer.buffered();
722721}
723722
724723test "alignment functions - smoke test" {
lib/compiler/aro/backend/Ir.zig+12-12
......@@ -374,21 +374,21 @@ pub fn deinit(ir: *Ir, gpa: std.mem.Allocator) void {
374374 ir.* = undefined;
375375}
376376
377const TYPE = std.io.tty.Color.bright_magenta;
378const INST = std.io.tty.Color.bright_cyan;
379const REF = std.io.tty.Color.bright_blue;
380const LITERAL = std.io.tty.Color.bright_green;
381const ATTRIBUTE = std.io.tty.Color.bright_yellow;
377const TYPE = std.Io.tty.Color.bright_magenta;
378const INST = std.Io.tty.Color.bright_cyan;
379const REF = std.Io.tty.Color.bright_blue;
380const LITERAL = std.Io.tty.Color.bright_green;
381const ATTRIBUTE = std.Io.tty.Color.bright_yellow;
382382
383383const RefMap = std.AutoArrayHashMap(Ref, void);
384384
385pub fn dump(ir: *const Ir, gpa: Allocator, config: std.io.tty.Config, w: anytype) !void {
385pub fn dump(ir: *const Ir, gpa: Allocator, config: std.Io.tty.Config, w: anytype) !void {
386386 for (ir.decls.keys(), ir.decls.values()) |name, *decl| {
387387 try ir.dumpDecl(decl, gpa, name, config, w);
388388 }
389389}
390390
391fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.io.tty.Config, w: anytype) !void {
391fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.Io.tty.Config, w: anytype) !void {
392392 const tags = decl.instructions.items(.tag);
393393 const data = decl.instructions.items(.data);
394394
......@@ -609,7 +609,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8,
609609 try w.writeAll("}\n\n");
610610}
611611
612fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype) !void {
612fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void {
613613 const ty = ir.interner.get(ty_ref);
614614 try config.setColor(w, TYPE);
615615 switch (ty) {
......@@ -639,7 +639,7 @@ fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype
639639 }
640640}
641641
642fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype) !void {
642fn writeValue(ir: Ir, val: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void {
643643 try config.setColor(w, LITERAL);
644644 const key = ir.interner.get(val);
645645 switch (key) {
......@@ -655,7 +655,7 @@ fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype)
655655 }
656656}
657657
658fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
658fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
659659 assert(ref != .none);
660660 const index = @intFromEnum(ref);
661661 const ty_ref = decl.instructions.items(.ty)[index];
......@@ -678,7 +678,7 @@ fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.i
678678 try w.print(" %{d}", .{ref_index});
679679}
680680
681fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
681fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
682682 try ref_map.put(ref, {});
683683 try w.writeAll(" ");
684684 try ir.writeRef(decl, ref_map, ref, config, w);
......@@ -687,7 +687,7 @@ fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: st
687687 try config.setColor(w, INST);
688688}
689689
690fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void {
690fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void {
691691 assert(ref != .none);
692692 const index = @intFromEnum(ref);
693693 const label = decl.instructions.items(.data)[index].label;
lib/compiler/aro_translate_c.zig+1-1
......@@ -1783,7 +1783,7 @@ fn renderErrorsAndExit(comp: *aro.Compilation) noreturn {
17831783 defer std.process.exit(1);
17841784
17851785 var buffer: [1000]u8 = undefined;
1786 var writer = aro.Diagnostics.defaultMsgWriter(std.io.tty.detectConfig(std.fs.File.stderr()), &buffer);
1786 var writer = aro.Diagnostics.defaultMsgWriter(std.Io.tty.detectConfig(std.fs.File.stderr()), &buffer);
17871787 defer writer.deinit(); // writer deinit must run *before* exit so that stderr is flushed
17881788
17891789 var saw_error = false;
lib/compiler/build_runner.zig+10-10
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const io = std.io;
54const fmt = std.fmt;
65const mem = std.mem;
76const process = std.process;
......@@ -11,8 +10,9 @@ const Watch = std.Build.Watch;
1110const WebServer = std.Build.WebServer;
1211const Allocator = std.mem.Allocator;
1312const fatal = std.process.fatal;
14const Writer = std.io.Writer;
13const Writer = std.Io.Writer;
1514const runner = @This();
15const tty = std.Io.tty;
1616
1717pub const root = @import("@build");
1818pub const dependencies = @import("@dependencies");
......@@ -576,7 +576,7 @@ const Run = struct {
576576
577577 claimed_rss: usize,
578578 summary: Summary,
579 ttyconf: std.io.tty.Config,
579 ttyconf: tty.Config,
580580 stderr: File,
581581
582582 fn cleanExit(run: Run) void {
......@@ -819,7 +819,7 @@ const PrintNode = struct {
819819 last: bool = false,
820820};
821821
822fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !void {
822fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: tty.Config) !void {
823823 const parent = node.parent orelse return;
824824 if (parent.parent == null) return;
825825 try printPrefix(parent, stderr, ttyconf);
......@@ -833,7 +833,7 @@ fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !v
833833 }
834834}
835835
836fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void {
836fn printChildNodePrefix(stderr: *Writer, ttyconf: tty.Config) !void {
837837 try stderr.writeAll(switch (ttyconf) {
838838 .no_color, .windows_api => "+- ",
839839 .escape_codes => "\x1B\x28\x30\x6d\x71\x1B\x28\x42 ", // └─
......@@ -843,7 +843,7 @@ fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void {
843843fn printStepStatus(
844844 s: *Step,
845845 stderr: *Writer,
846 ttyconf: std.io.tty.Config,
846 ttyconf: tty.Config,
847847 run: *const Run,
848848) !void {
849849 switch (s.state) {
......@@ -923,7 +923,7 @@ fn printStepStatus(
923923fn printStepFailure(
924924 s: *Step,
925925 stderr: *Writer,
926 ttyconf: std.io.tty.Config,
926 ttyconf: tty.Config,
927927) !void {
928928 if (s.result_error_bundle.errorMessageCount() > 0) {
929929 try ttyconf.setColor(stderr, .red);
......@@ -977,7 +977,7 @@ fn printTreeStep(
977977 s: *Step,
978978 run: *const Run,
979979 stderr: *Writer,
980 ttyconf: std.io.tty.Config,
980 ttyconf: tty.Config,
981981 parent_node: *PrintNode,
982982 step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),
983983) !void {
......@@ -1494,9 +1494,9 @@ fn uncleanExit() error{UncleanExit} {
14941494const Color = std.zig.Color;
14951495const Summary = enum { all, new, failures, none };
14961496
1497fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {
1497fn get_tty_conf(color: Color, stderr: File) tty.Config {
14981498 return switch (color) {
1499 .auto => std.io.tty.detectConfig(stderr),
1499 .auto => tty.detectConfig(stderr),
15001500 .on => .escape_codes,
15011501 .off => .no_color,
15021502 };
lib/compiler/libc.zig-1
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const mem = std.mem;
3const io = std.io;
43const LibCInstallation = std.zig.LibCInstallation;
54
65const usage_libc =
lib/compiler/reduce.zig+1-1
......@@ -381,7 +381,7 @@ fn transformationsToFixups(
381381 }
382382 }
383383
384 var other_source: std.io.Writer.Allocating = .init(gpa);
384 var other_source: std.Io.Writer.Allocating = .init(gpa);
385385 defer other_source.deinit();
386386 try other_source.writer.writeAll("struct {\n");
387387 try other_file_ast.render(gpa, &other_source.writer, inlined_fixups);
lib/compiler/resinator/ast.zig+3-3
......@@ -22,7 +22,7 @@ pub const Tree = struct {
2222 return @alignCast(@fieldParentPtr("base", self.node));
2323 }
2424
25 pub fn dump(self: *Tree, writer: *std.io.Writer) !void {
25 pub fn dump(self: *Tree, writer: *std.Io.Writer) !void {
2626 try self.node.dump(self, writer, 0);
2727 }
2828};
......@@ -726,9 +726,9 @@ pub const Node = struct {
726726 pub fn dump(
727727 node: *const Node,
728728 tree: *const Tree,
729 writer: *std.io.Writer,
729 writer: *std.Io.Writer,
730730 indent: usize,
731 ) std.io.Writer.Error!void {
731 ) std.Io.Writer.Error!void {
732732 try writer.splatByteAll(' ', indent);
733733 try writer.writeAll(@tagName(node.id));
734734 switch (node.id) {
lib/compiler/resinator/cli.zig+4-4
......@@ -124,13 +124,13 @@ pub const Diagnostics = struct {
124124 try self.errors.append(self.allocator, error_details);
125125 }
126126
127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {
127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.Io.tty.Config) void {
128128 const stderr = std.debug.lockStderrWriter(&.{});
129129 defer std.debug.unlockStderrWriter();
130130 self.renderToWriter(args, stderr, config) catch return;
131131 }
132132
133 pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: *std.io.Writer, 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 {
134134 for (self.errors.items) |err_details| {
135135 try renderErrorMessage(writer, config, err_details, args);
136136 }
......@@ -1343,7 +1343,7 @@ test parsePercent {
13431343 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));
13441344}
13451345
1346pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
1346pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
13471347 try config.setColor(writer, .dim);
13481348 try writer.writeAll("<cli>");
13491349 try config.setColor(writer, .reset);
......@@ -1470,7 +1470,7 @@ fn testParseOutput(args: []const []const u8, expected_output: []const u8) !?Opti
14701470 var diagnostics = Diagnostics.init(std.testing.allocator);
14711471 defer diagnostics.deinit();
14721472
1473 var output: std.io.Writer.Allocating = .init(std.testing.allocator);
1473 var output: std.Io.Writer.Allocating = .init(std.testing.allocator);
14741474 defer output.deinit();
14751475
14761476 var options = parse(std.testing.allocator, args, &diagnostics) catch |err| switch (err) {
lib/compiler/resinator/errors.zig+4-4
......@@ -61,7 +61,7 @@ pub const Diagnostics = struct {
6161 return @intCast(index);
6262 }
6363
64 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {
64 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.Io.tty.Config, source_mappings: ?SourceMappings) void {
6565 const stderr = std.debug.lockStderrWriter(&.{});
6666 defer std.debug.unlockStderrWriter();
6767 for (self.errors.items) |err_details| {
......@@ -70,7 +70,7 @@ pub const Diagnostics = struct {
7070 }
7171
7272 pub fn renderToStdErrDetectTTY(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, source_mappings: ?SourceMappings) void {
73 const tty_config = std.io.tty.detectConfig(std.fs.File.stderr());
73 const tty_config = std.Io.tty.detectConfig(std.fs.File.stderr());
7474 return self.renderToStdErr(cwd, source, tty_config, source_mappings);
7575 }
7676
......@@ -409,7 +409,7 @@ pub const ErrorDetails = struct {
409409 failed_to_open_cwd,
410410 };
411411
412 fn formatToken(ctx: TokenFormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
412 fn formatToken(ctx: TokenFormatContext, writer: *std.Io.Writer) std.Io.Writer.Error!void {
413413 switch (ctx.token.id) {
414414 .eof => return writer.writeAll(ctx.token.id.nameForErrorDisplay()),
415415 else => {},
......@@ -894,7 +894,7 @@ fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usiz
894894
895895const truncated_str = "<...truncated...>";
896896
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 {
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 {
898898 if (err_details.type == .hint) return;
899899
900900 const source_line_start = err_details.token.getLineStartForErrorDisplay(source);
lib/compiler/resinator/main.zig+3-3
......@@ -24,7 +24,7 @@ pub fn main() !void {
2424 const arena = arena_state.allocator();
2525
2626 const stderr = std.fs.File.stderr();
27 const stderr_config = std.io.tty.detectConfig(stderr);
27 const stderr_config = std.Io.tty.detectConfig(stderr);
2828
2929 const args = try std.process.argsAlloc(allocator);
3030 defer std.process.argsFree(allocator, args);
......@@ -621,7 +621,7 @@ const SourceMappings = @import("source_mapping.zig").SourceMappings;
621621
622622const ErrorHandler = union(enum) {
623623 server: std.zig.Server,
624 tty: std.io.tty.Config,
624 tty: std.Io.tty.Config,
625625
626626 pub fn emitCliDiagnostics(
627627 self: *ErrorHandler,
......@@ -984,7 +984,7 @@ const MsgWriter = struct {
984984 m.buf.appendSlice(msg) catch {};
985985 }
986986
987 pub fn setColor(m: *MsgWriter, color: std.io.tty.Color) void {
987 pub fn setColor(m: *MsgWriter, color: std.Io.tty.Color) void {
988988 _ = m;
989989 _ = color;
990990 }
lib/compiler/resinator/res.zig+3-3
......@@ -164,7 +164,7 @@ pub const Language = packed struct(u16) {
164164 return @bitCast(self);
165165 }
166166
167 pub fn format(language: Language, w: *std.io.Writer) std.io.Writer.Error!void {
167 pub fn format(language: Language, w: *std.Io.Writer) std.Io.Writer.Error!void {
168168 const language_id = language.asInt();
169169 const language_name = language_name: {
170170 if (std.enums.fromInt(lang.LanguageId, language_id)) |lang_enum_val| {
......@@ -439,7 +439,7 @@ pub const NameOrOrdinal = union(enum) {
439439 }
440440 }
441441
442 pub fn format(self: NameOrOrdinal, w: *std.io.Writer) !void {
442 pub fn format(self: NameOrOrdinal, w: *std.Io.Writer) !void {
443443 switch (self) {
444444 .name => |name| {
445445 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
......@@ -450,7 +450,7 @@ pub const NameOrOrdinal = union(enum) {
450450 }
451451 }
452452
453 fn formatResourceType(self: NameOrOrdinal, w: *std.io.Writer) std.io.Writer.Error!void {
453 fn formatResourceType(self: NameOrOrdinal, w: *std.Io.Writer) std.Io.Writer.Error!void {
454454 switch (self) {
455455 .name => |name| {
456456 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
lib/compiler/resinator/utils.zig+1-2
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4/// Like std.io.FixedBufferStream but does no bounds checking
54pub const UncheckedSliceWriter = struct {
65 const Self = @This();
76
......@@ -86,7 +85,7 @@ pub const ErrorMessageType = enum { err, warning, note };
8685
8786/// Used for generic colored errors/warnings/notes, more context-specific error messages
8887/// are handled elsewhere.
89pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
88pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
9089 switch (msg_type) {
9190 .err => {
9291 try config.setColor(writer, .bold);
lib/compiler/std-docs.zig+1-2
......@@ -1,7 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("std");
33const mem = std.mem;
4const io = std.io;
54const Allocator = std.mem.Allocator;
65const assert = std.debug.assert;
76const Cache = std.Build.Cache;
......@@ -318,7 +317,7 @@ fn buildWasmBinary(
318317 child.stderr_behavior = .Pipe;
319318 try child.spawn();
320319
321 var poller = std.io.poll(gpa, enum { stdout, stderr }, .{
320 var poller = std.Io.poll(gpa, enum { stdout, stderr }, .{
322321 .stdout = child.stdout.?,
323322 .stderr = child.stderr.?,
324323 });
lib/std/Build.zig+5-5
......@@ -1,6 +1,5 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
3const io = std.io;
43const fs = std.fs;
54const mem = std.mem;
65const debug = std.debug;
......@@ -1830,7 +1829,8 @@ pub fn runAllowFail(
18301829 try Step.handleVerbose2(b, null, child.env_map, argv);
18311830 try child.spawn();
18321831
1833 const stdout = child.stdout.?.deprecatedReader().readAllAlloc(b.allocator, max_output_size) catch {
1832 var stdout_reader = child.stdout.?.readerStreaming(&.{});
1833 const stdout = stdout_reader.interface.allocRemaining(b.allocator, .limited(max_output_size)) catch {
18341834 return error.ReadFailure;
18351835 };
18361836 errdefer b.allocator.free(stdout);
......@@ -2540,7 +2540,7 @@ fn dumpBadDirnameHelp(
25402540
25412541 try w.print(msg, args);
25422542
2543 const tty_config = std.io.tty.detectConfig(.stderr());
2543 const tty_config = std.Io.tty.detectConfig(.stderr());
25442544
25452545 if (fail_step) |s| {
25462546 tty_config.setColor(w, .red) catch {};
......@@ -2566,8 +2566,8 @@ fn dumpBadDirnameHelp(
25662566/// In this function the stderr mutex has already been locked.
25672567pub fn dumpBadGetPathHelp(
25682568 s: *Step,
2569 w: *std.io.Writer,
2570 tty_config: std.io.tty.Config,
2569 w: *std.Io.Writer,
2570 tty_config: std.Io.tty.Config,
25712571 src_builder: *Build,
25722572 asking_step: ?*Step,
25732573) anyerror!void {
lib/std/Build/Cache.zig+2-2
......@@ -286,7 +286,7 @@ pub const HashHelper = struct {
286286
287287pub fn binToHex(bin_digest: BinDigest) HexDigest {
288288 var out_digest: HexDigest = undefined;
289 var w: std.io.Writer = .fixed(&out_digest);
289 var w: std.Io.Writer = .fixed(&out_digest);
290290 w.printHex(&bin_digest, .lower) catch unreachable;
291291 return out_digest;
292292}
......@@ -664,7 +664,7 @@ pub const Manifest = struct {
664664 const input_file_count = self.files.entries.len;
665665 var tiny_buffer: [1]u8 = undefined; // allows allocRemaining to detect limit exceeded
666666 var manifest_reader = self.manifest_file.?.reader(&tiny_buffer); // Reads positionally from zero.
667 const limit: std.io.Limit = .limited(manifest_file_size_max);
667 const limit: std.Io.Limit = .limited(manifest_file_size_max);
668668 const file_contents = manifest_reader.interface.allocRemaining(gpa, limit) catch |err| switch (err) {
669669 error.OutOfMemory => return error.OutOfMemory,
670670 error.StreamTooLong => return error.OutOfMemory,
lib/std/Build/Cache/Directory.zig+1-1
......@@ -56,7 +56,7 @@ pub fn closeAndFree(self: *Directory, gpa: Allocator) void {
5656 self.* = undefined;
5757}
5858
59pub fn format(self: Directory, writer: *std.io.Writer) std.io.Writer.Error!void {
59pub fn format(self: Directory, writer: *std.Io.Writer) std.Io.Writer.Error!void {
6060 if (self.path) |p| {
6161 try writer.writeAll(p);
6262 try writer.writeAll(fs.path.sep_str);
lib/std/Build/Cache/Path.zig+3-3
......@@ -151,7 +151,7 @@ pub fn fmtEscapeString(path: Path) std.fmt.Formatter(Path, formatEscapeString) {
151151 return .{ .data = path };
152152}
153153
154pub fn formatEscapeString(path: Path, writer: *std.io.Writer) std.io.Writer.Error!void {
154pub fn formatEscapeString(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void {
155155 if (path.root_dir.path) |p| {
156156 try std.zig.stringEscape(p, writer);
157157 if (path.sub_path.len > 0) try std.zig.stringEscape(fs.path.sep_str, writer);
......@@ -167,7 +167,7 @@ pub fn fmtEscapeChar(path: Path) std.fmt.Formatter(Path, formatEscapeChar) {
167167}
168168
169169/// Deprecated, use double quoted escape to print paths.
170pub fn formatEscapeChar(path: Path, writer: *std.io.Writer) std.io.Writer.Error!void {
170pub fn formatEscapeChar(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void {
171171 if (path.root_dir.path) |p| {
172172 for (p) |byte| try std.zig.charEscape(byte, writer);
173173 if (path.sub_path.len > 0) try writer.writeByte(fs.path.sep);
......@@ -177,7 +177,7 @@ pub fn formatEscapeChar(path: Path, writer: *std.io.Writer) std.io.Writer.Error!
177177 }
178178}
179179
180pub fn format(self: Path, writer: *std.io.Writer) std.io.Writer.Error!void {
180pub fn format(self: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void {
181181 if (std.fs.path.isAbsolute(self.sub_path)) {
182182 try writer.writeAll(self.sub_path);
183183 return;
lib/std/Build/Fuzz.zig+2-2
......@@ -127,7 +127,7 @@ pub fn deinit(fuzz: *Fuzz) void {
127127 gpa.free(fuzz.run_steps);
128128}
129129
130fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.io.tty.Config, parent_prog_node: std.Progress.Node) void {
130fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) void {
131131 rebuildTestsWorkerRunFallible(run, gpa, ttyconf, parent_prog_node) catch |err| {
132132 const compile = run.producer.?;
133133 log.err("step '{s}': failed to rebuild in fuzz mode: {s}", .{
......@@ -136,7 +136,7 @@ fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.io.tty.Con
136136 };
137137}
138138
139fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.io.tty.Config, parent_prog_node: std.Progress.Node) !void {
139fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) !void {
140140 const compile = run.producer.?;
141141 const prog_node = parent_prog_node.start(compile.step.name, 0);
142142 defer prog_node.end();
lib/std/Build/Step/CheckObject.zig+117-127
......@@ -6,7 +6,7 @@ const macho = std.macho;
66const math = std.math;
77const mem = std.mem;
88const testing = std.testing;
9const Writer = std.io.Writer;
9const Writer = std.Io.Writer;
1010
1111const CheckObject = @This();
1212
......@@ -1462,7 +1462,7 @@ const MachODumper = struct {
14621462 const TrieIterator = struct {
14631463 stream: std.Io.Reader,
14641464
1465 fn readUleb128(it: *TrieIterator) !u64 {
1465 fn takeLeb128(it: *TrieIterator) !u64 {
14661466 return it.stream.takeLeb128(u64);
14671467 }
14681468
......@@ -1470,7 +1470,7 @@ const MachODumper = struct {
14701470 return it.stream.takeSentinel(0);
14711471 }
14721472
1473 fn readByte(it: *TrieIterator) !u8 {
1473 fn takeByte(it: *TrieIterator) !u8 {
14741474 return it.stream.takeByte();
14751475 }
14761476 };
......@@ -1518,12 +1518,12 @@ const MachODumper = struct {
15181518 prefix: []const u8,
15191519 exports: *std.array_list.Managed(Export),
15201520 ) !void {
1521 const size = try it.readUleb128();
1521 const size = try it.takeLeb128();
15221522 if (size > 0) {
1523 const flags = try it.readUleb128();
1523 const flags = try it.takeLeb128();
15241524 switch (flags) {
15251525 macho.EXPORT_SYMBOL_FLAGS_REEXPORT => {
1526 const ord = try it.readUleb128();
1526 const ord = try it.takeLeb128();
15271527 const name = try arena.dupe(u8, try it.readString());
15281528 try exports.append(.{
15291529 .name = if (name.len > 0) name else prefix,
......@@ -1532,8 +1532,8 @@ const MachODumper = struct {
15321532 });
15331533 },
15341534 macho.EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER => {
1535 const stub_offset = try it.readUleb128();
1536 const resolver_offset = try it.readUleb128();
1535 const stub_offset = try it.takeLeb128();
1536 const resolver_offset = try it.takeLeb128();
15371537 try exports.append(.{
15381538 .name = prefix,
15391539 .tag = .stub_resolver,
......@@ -1544,7 +1544,7 @@ const MachODumper = struct {
15441544 });
15451545 },
15461546 else => {
1547 const vmoff = try it.readUleb128();
1547 const vmoff = try it.takeLeb128();
15481548 try exports.append(.{
15491549 .name = prefix,
15501550 .tag = .@"export",
......@@ -1563,10 +1563,10 @@ const MachODumper = struct {
15631563 }
15641564 }
15651565
1566 const nedges = try it.readByte();
1566 const nedges = try it.takeByte();
15671567 for (0..nedges) |_| {
15681568 const label = try it.readString();
1569 const off = try it.readUleb128();
1569 const off = try it.takeLeb128();
15701570 const prefix_label = try std.fmt.allocPrint(arena, "{s}{s}", .{ prefix, label });
15711571 const curr = it.stream.seek;
15721572 it.stream.seek = off;
......@@ -1701,10 +1701,9 @@ const ElfDumper = struct {
17011701
17021702 fn parseAndDumpArchive(step: *Step, check: Check, bytes: []const u8) ![]const u8 {
17031703 const gpa = step.owner.allocator;
1704 var stream = std.io.fixedBufferStream(bytes);
1705 const reader = stream.reader();
1704 var reader: std.Io.Reader = .fixed(bytes);
17061705
1707 const magic = try reader.readBytesNoEof(elf.ARMAG.len);
1706 const magic = try reader.takeArray(elf.ARMAG.len);
17081707 if (!mem.eql(u8, &magic, elf.ARMAG)) {
17091708 return error.InvalidArchiveMagicNumber;
17101709 }
......@@ -1722,28 +1721,26 @@ const ElfDumper = struct {
17221721 }
17231722
17241723 while (true) {
1725 if (stream.pos >= ctx.data.len) break;
1726 if (!mem.isAligned(stream.pos, 2)) stream.pos += 1;
1724 if (reader.seek >= ctx.data.len) break;
1725 if (!mem.isAligned(reader.seek, 2)) reader.seek += 1;
17271726
1728 const hdr = try reader.readStruct(elf.ar_hdr);
1727 const hdr = try reader.takeStruct(elf.ar_hdr, .little);
17291728
17301729 if (!mem.eql(u8, &hdr.ar_fmag, elf.ARFMAG)) return error.InvalidArchiveHeaderMagicNumber;
17311730
17321731 const size = try hdr.size();
1733 defer {
1734 _ = stream.seekBy(size) catch {};
1735 }
1732 defer reader.seek += size;
17361733
17371734 if (hdr.isSymtab()) {
1738 try ctx.parseSymtab(ctx.data[stream.pos..][0..size], .p32);
1735 try ctx.parseSymtab(ctx.data[reader.seek..][0..size], .p32);
17391736 continue;
17401737 }
17411738 if (hdr.isSymtab64()) {
1742 try ctx.parseSymtab(ctx.data[stream.pos..][0..size], .p64);
1739 try ctx.parseSymtab(ctx.data[reader.seek..][0..size], .p64);
17431740 continue;
17441741 }
17451742 if (hdr.isStrtab()) {
1746 ctx.strtab = ctx.data[stream.pos..][0..size];
1743 ctx.strtab = ctx.data[reader.seek..][0..size];
17471744 continue;
17481745 }
17491746 if (hdr.isSymdef() or hdr.isSymdefSorted()) continue;
......@@ -1755,7 +1752,7 @@ const ElfDumper = struct {
17551752 else
17561753 unreachable;
17571754
1758 try ctx.objects.append(gpa, .{ .name = name, .off = stream.pos, .len = size });
1755 try ctx.objects.append(gpa, .{ .name = name, .off = reader.seek, .len = size });
17591756 }
17601757
17611758 var output: std.Io.Writer.Allocating = .init(gpa);
......@@ -1783,11 +1780,10 @@ const ElfDumper = struct {
17831780 objects: std.ArrayListUnmanaged(struct { name: []const u8, off: usize, len: usize }) = .empty,
17841781
17851782 fn parseSymtab(ctx: *ArchiveContext, raw: []const u8, ptr_width: enum { p32, p64 }) !void {
1786 var stream = std.io.fixedBufferStream(raw);
1787 const reader = stream.reader();
1783 var reader: std.Io.Reader = .fixed(raw);
17881784 const num = switch (ptr_width) {
1789 .p32 => try reader.readInt(u32, .big),
1790 .p64 => try reader.readInt(u64, .big),
1785 .p32 => try reader.takeInt(u32, .big),
1786 .p64 => try reader.takeInt(u64, .big),
17911787 };
17921788 const ptr_size: usize = switch (ptr_width) {
17931789 .p32 => @sizeOf(u32),
......@@ -1802,8 +1798,8 @@ const ElfDumper = struct {
18021798 var stroff: usize = 0;
18031799 for (0..num) |_| {
18041800 const off = switch (ptr_width) {
1805 .p32 => try reader.readInt(u32, .big),
1806 .p64 => try reader.readInt(u64, .big),
1801 .p32 => try reader.takeInt(u32, .big),
1802 .p64 => try reader.takeInt(u64, .big),
18071803 };
18081804 const name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + stroff)), 0);
18091805 stroff += name.len + 1;
......@@ -1868,10 +1864,9 @@ const ElfDumper = struct {
18681864
18691865 fn parseAndDumpObject(step: *Step, check: Check, bytes: []const u8) ![]const u8 {
18701866 const gpa = step.owner.allocator;
1871 var stream = std.io.fixedBufferStream(bytes);
1872 const reader = stream.reader();
1867 var reader: std.Io.Reader = .fixed(bytes);
18731868
1874 const hdr = try reader.readStruct(elf.Elf64_Ehdr);
1869 const hdr = try reader.takeStruct(elf.Elf64_Ehdr, .little);
18751870 if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) {
18761871 return error.InvalidMagicNumber;
18771872 }
......@@ -2360,10 +2355,9 @@ const WasmDumper = struct {
23602355
23612356 fn parseAndDump(step: *Step, check: Check, bytes: []const u8) ![]const u8 {
23622357 const gpa = step.owner.allocator;
2363 var fbs = std.io.fixedBufferStream(bytes);
2364 const reader = fbs.reader();
2358 var reader: std.Io.Reader = .fixed(bytes);
23652359
2366 const buf = try reader.readBytesNoEof(8);
2360 const buf = try reader.takeArray(8);
23672361 if (!mem.eql(u8, buf[0..4], &std.wasm.magic)) {
23682362 return error.InvalidMagicByte;
23692363 }
......@@ -2373,7 +2367,7 @@ const WasmDumper = struct {
23732367
23742368 var output: std.Io.Writer.Allocating = .init(gpa);
23752369 defer output.deinit();
2376 parseAndDumpInner(step, check, bytes, &fbs, &output.writer) catch |err| switch (err) {
2370 parseAndDumpInner(step, check, bytes, &reader, &output.writer) catch |err| switch (err) {
23772371 error.EndOfStream => try output.writer.writeAll("\n<UnexpectedEndOfStream>"),
23782372 else => |e| return e,
23792373 };
......@@ -2384,21 +2378,19 @@ const WasmDumper = struct {
23842378 step: *Step,
23852379 check: Check,
23862380 bytes: []const u8,
2387 fbs: *std.io.FixedBufferStream([]const u8),
2381 reader: *std.Io.Reader,
23882382 writer: *std.Io.Writer,
23892383 ) !void {
2390 const reader = fbs.reader();
2391
23922384 switch (check.kind) {
23932385 .headers => {
2394 while (reader.readByte()) |current_byte| {
2386 while (reader.takeByte()) |current_byte| {
23952387 const section = std.enums.fromInt(std.wasm.Section, current_byte) orelse {
23962388 return step.fail("Found invalid section id '{d}'", .{current_byte});
23972389 };
23982390
2399 const section_length = try std.leb.readUleb128(u32, reader);
2400 try parseAndDumpSection(step, section, bytes[fbs.pos..][0..section_length], writer);
2401 fbs.pos += section_length;
2391 const section_length = try reader.takeLeb128(u32);
2392 try parseAndDumpSection(step, section, bytes[reader.seek..][0..section_length], writer);
2393 reader.seek += section_length;
24022394 } else |_| {} // reached end of stream
24032395 },
24042396
......@@ -2410,10 +2402,9 @@ const WasmDumper = struct {
24102402 step: *Step,
24112403 section: std.wasm.Section,
24122404 data: []const u8,
2413 writer: anytype,
2405 writer: *std.Io.Writer,
24142406 ) !void {
2415 var fbs = std.io.fixedBufferStream(data);
2416 const reader = fbs.reader();
2407 var reader: std.Io.Reader = .fixed(data);
24172408
24182409 try writer.print(
24192410 \\Section {s}
......@@ -2432,31 +2423,31 @@ const WasmDumper = struct {
24322423 .code,
24332424 .data,
24342425 => {
2435 const entries = try std.leb.readUleb128(u32, reader);
2426 const entries = try reader.takeLeb128(u32);
24362427 try writer.print("\nentries {d}\n", .{entries});
2437 try parseSection(step, section, data[fbs.pos..], entries, writer);
2428 try parseSection(step, section, data[reader.seek..], entries, writer);
24382429 },
24392430 .custom => {
2440 const name_length = try std.leb.readUleb128(u32, reader);
2441 const name = data[fbs.pos..][0..name_length];
2442 fbs.pos += name_length;
2431 const name_length = try reader.takeLeb128(u32);
2432 const name = data[reader.seek..][0..name_length];
2433 reader.seek += name_length;
24432434 try writer.print("\nname {s}\n", .{name});
24442435
24452436 if (mem.eql(u8, name, "name")) {
2446 try parseDumpNames(step, reader, writer, data);
2437 try parseDumpNames(step, &reader, writer, data);
24472438 } else if (mem.eql(u8, name, "producers")) {
2448 try parseDumpProducers(reader, writer, data);
2439 try parseDumpProducers(&reader, writer, data);
24492440 } else if (mem.eql(u8, name, "target_features")) {
2450 try parseDumpFeatures(reader, writer, data);
2441 try parseDumpFeatures(&reader, writer, data);
24512442 }
24522443 // TODO: Implement parsing and dumping other custom sections (such as relocations)
24532444 },
24542445 .start => {
2455 const start = try std.leb.readUleb128(u32, reader);
2446 const start = try reader.takeLeb128(u32);
24562447 try writer.print("\nstart {d}\n", .{start});
24572448 },
24582449 .data_count => {
2459 const count = try std.leb.readUleb128(u32, reader);
2450 const count = try reader.takeLeb128(u32);
24602451 try writer.print("\ncount {d}\n", .{count});
24612452 },
24622453 else => {}, // skip unknown sections
......@@ -2464,41 +2455,40 @@ const WasmDumper = struct {
24642455 }
24652456
24662457 fn parseSection(step: *Step, section: std.wasm.Section, data: []const u8, entries: u32, writer: anytype) !void {
2467 var fbs = std.io.fixedBufferStream(data);
2468 const reader = fbs.reader();
2458 var reader: std.Io.Reader = .fixed(data);
24692459
24702460 switch (section) {
24712461 .type => {
24722462 var i: u32 = 0;
24732463 while (i < entries) : (i += 1) {
2474 const func_type = try reader.readByte();
2464 const func_type = try reader.takeByte();
24752465 if (func_type != std.wasm.function_type) {
24762466 return step.fail("expected function type, found byte '{d}'", .{func_type});
24772467 }
2478 const params = try std.leb.readUleb128(u32, reader);
2468 const params = try reader.takeLeb128(u32);
24792469 try writer.print("params {d}\n", .{params});
24802470 var index: u32 = 0;
24812471 while (index < params) : (index += 1) {
2482 _ = try parseDumpType(step, std.wasm.Valtype, reader, writer);
2472 _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer);
24832473 } else index = 0;
2484 const returns = try std.leb.readUleb128(u32, reader);
2474 const returns = try reader.takeLeb128(u32);
24852475 try writer.print("returns {d}\n", .{returns});
24862476 while (index < returns) : (index += 1) {
2487 _ = try parseDumpType(step, std.wasm.Valtype, reader, writer);
2477 _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer);
24882478 }
24892479 }
24902480 },
24912481 .import => {
24922482 var i: u32 = 0;
24932483 while (i < entries) : (i += 1) {
2494 const module_name_len = try std.leb.readUleb128(u32, reader);
2495 const module_name = data[fbs.pos..][0..module_name_len];
2496 fbs.pos += module_name_len;
2497 const name_len = try std.leb.readUleb128(u32, reader);
2498 const name = data[fbs.pos..][0..name_len];
2499 fbs.pos += name_len;
2500
2501 const kind = std.enums.fromInt(std.wasm.ExternalKind, try reader.readByte()) orelse {
2484 const module_name_len = try reader.takeLeb128(u32);
2485 const module_name = data[reader.seek..][0..module_name_len];
2486 reader.seek += module_name_len;
2487 const name_len = try reader.takeLeb128(u32);
2488 const name = data[reader.seek..][0..name_len];
2489 reader.seek += name_len;
2490
2491 const kind = std.enums.fromInt(std.wasm.ExternalKind, try reader.takeByte()) orelse {
25022492 return step.fail("invalid import kind", .{});
25032493 };
25042494
......@@ -2510,18 +2500,18 @@ const WasmDumper = struct {
25102500 try writer.writeByte('\n');
25112501 switch (kind) {
25122502 .function => {
2513 try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)});
2503 try writer.print("index {d}\n", .{try reader.takeLeb128(u32)});
25142504 },
25152505 .memory => {
2516 try parseDumpLimits(reader, writer);
2506 try parseDumpLimits(&reader, writer);
25172507 },
25182508 .global => {
2519 _ = try parseDumpType(step, std.wasm.Valtype, reader, writer);
2520 try writer.print("mutable {}\n", .{0x01 == try std.leb.readUleb128(u32, reader)});
2509 _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer);
2510 try writer.print("mutable {}\n", .{0x01 == try reader.takeLeb128(u32)});
25212511 },
25222512 .table => {
2523 _ = try parseDumpType(step, std.wasm.RefType, reader, writer);
2524 try parseDumpLimits(reader, writer);
2513 _ = try parseDumpType(step, std.wasm.RefType, &reader, writer);
2514 try parseDumpLimits(&reader, writer);
25252515 },
25262516 }
25272517 }
......@@ -2529,41 +2519,41 @@ const WasmDumper = struct {
25292519 .function => {
25302520 var i: u32 = 0;
25312521 while (i < entries) : (i += 1) {
2532 try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)});
2522 try writer.print("index {d}\n", .{try reader.takeLeb128(u32)});
25332523 }
25342524 },
25352525 .table => {
25362526 var i: u32 = 0;
25372527 while (i < entries) : (i += 1) {
2538 _ = try parseDumpType(step, std.wasm.RefType, reader, writer);
2539 try parseDumpLimits(reader, writer);
2528 _ = try parseDumpType(step, std.wasm.RefType, &reader, writer);
2529 try parseDumpLimits(&reader, writer);
25402530 }
25412531 },
25422532 .memory => {
25432533 var i: u32 = 0;
25442534 while (i < entries) : (i += 1) {
2545 try parseDumpLimits(reader, writer);
2535 try parseDumpLimits(&reader, writer);
25462536 }
25472537 },
25482538 .global => {
25492539 var i: u32 = 0;
25502540 while (i < entries) : (i += 1) {
2551 _ = try parseDumpType(step, std.wasm.Valtype, reader, writer);
2552 try writer.print("mutable {}\n", .{0x01 == try std.leb.readUleb128(u1, reader)});
2553 try parseDumpInit(step, reader, writer);
2541 _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer);
2542 try writer.print("mutable {}\n", .{0x01 == try reader.takeLeb128(u1)});
2543 try parseDumpInit(step, &reader, writer);
25542544 }
25552545 },
25562546 .@"export" => {
25572547 var i: u32 = 0;
25582548 while (i < entries) : (i += 1) {
2559 const name_len = try std.leb.readUleb128(u32, reader);
2560 const name = data[fbs.pos..][0..name_len];
2561 fbs.pos += name_len;
2562 const kind_byte = try std.leb.readUleb128(u8, reader);
2549 const name_len = try reader.takeLeb128(u32);
2550 const name = data[reader.seek..][0..name_len];
2551 reader.seek += name_len;
2552 const kind_byte = try reader.takeLeb128(u8);
25632553 const kind = std.enums.fromInt(std.wasm.ExternalKind, kind_byte) orelse {
25642554 return step.fail("invalid export kind value '{d}'", .{kind_byte});
25652555 };
2566 const index = try std.leb.readUleb128(u32, reader);
2556 const index = try reader.takeLeb128(u32);
25672557 try writer.print(
25682558 \\name {s}
25692559 \\kind {s}
......@@ -2575,14 +2565,14 @@ const WasmDumper = struct {
25752565 .element => {
25762566 var i: u32 = 0;
25772567 while (i < entries) : (i += 1) {
2578 try writer.print("table index {d}\n", .{try std.leb.readUleb128(u32, reader)});
2579 try parseDumpInit(step, reader, writer);
2568 try writer.print("table index {d}\n", .{try reader.takeLeb128(u32)});
2569 try parseDumpInit(step, &reader, writer);
25802570
2581 const function_indexes = try std.leb.readUleb128(u32, reader);
2571 const function_indexes = try reader.takeLeb128(u32);
25822572 var function_index: u32 = 0;
25832573 try writer.print("indexes {d}\n", .{function_indexes});
25842574 while (function_index < function_indexes) : (function_index += 1) {
2585 try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)});
2575 try writer.print("index {d}\n", .{try reader.takeLeb128(u32)});
25862576 }
25872577 }
25882578 },
......@@ -2590,27 +2580,27 @@ const WasmDumper = struct {
25902580 .data => {
25912581 var i: u32 = 0;
25922582 while (i < entries) : (i += 1) {
2593 const flags = try std.leb.readUleb128(u32, reader);
2583 const flags = try reader.takeLeb128(u32);
25942584 const index = if (flags & 0x02 != 0)
2595 try std.leb.readUleb128(u32, reader)
2585 try reader.takeLeb128(u32)
25962586 else
25972587 0;
25982588 try writer.print("memory index 0x{x}\n", .{index});
25992589 if (flags == 0) {
2600 try parseDumpInit(step, reader, writer);
2590 try parseDumpInit(step, &reader, writer);
26012591 }
26022592
2603 const size = try std.leb.readUleb128(u32, reader);
2593 const size = try reader.takeLeb128(u32);
26042594 try writer.print("size {d}\n", .{size});
2605 try reader.skipBytes(size, .{}); // we do not care about the content of the segments
2595 try reader.discardAll(size); // we do not care about the content of the segments
26062596 }
26072597 },
26082598 else => unreachable,
26092599 }
26102600 }
26112601
2612 fn parseDumpType(step: *Step, comptime E: type, reader: anytype, writer: anytype) !E {
2613 const byte = try reader.readByte();
2602 fn parseDumpType(step: *Step, comptime E: type, reader: *std.Io.Reader, writer: *std.Io.Writer) !E {
2603 const byte = try reader.takeByte();
26142604 const tag = std.enums.fromInt(E, byte) orelse {
26152605 return step.fail("invalid wasm type value '{d}'", .{byte});
26162606 };
......@@ -2619,43 +2609,43 @@ const WasmDumper = struct {
26192609 }
26202610
26212611 fn parseDumpLimits(reader: anytype, writer: anytype) !void {
2622 const flags = try std.leb.readUleb128(u8, reader);
2623 const min = try std.leb.readUleb128(u32, reader);
2612 const flags = try reader.takeLeb128(u8);
2613 const min = try reader.takeLeb128(u32);
26242614
26252615 try writer.print("min {x}\n", .{min});
26262616 if (flags != 0) {
2627 try writer.print("max {x}\n", .{try std.leb.readUleb128(u32, reader)});
2617 try writer.print("max {x}\n", .{try reader.takeLeb128(u32)});
26282618 }
26292619 }
26302620
2631 fn parseDumpInit(step: *Step, reader: anytype, writer: anytype) !void {
2632 const byte = try reader.readByte();
2621 fn parseDumpInit(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer) !void {
2622 const byte = try reader.takeByte();
26332623 const opcode = std.enums.fromInt(std.wasm.Opcode, byte) orelse {
26342624 return step.fail("invalid wasm opcode '{d}'", .{byte});
26352625 };
26362626 switch (opcode) {
2637 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readIleb128(i32, reader)}),
2638 .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readIleb128(i64, reader)}),
2627 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readIleb128(i32)}),
2628 .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readIleb128(i64)}),
26392629 .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}),
26402630 .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}),
2641 .global_get => try writer.print("global.get {x}\n", .{try std.leb.readUleb128(u32, reader)}),
2631 .global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}),
26422632 else => unreachable,
26432633 }
2644 const end_opcode = try std.leb.readUleb128(u8, reader);
2634 const end_opcode = try reader.takeLeb128(u8);
26452635 if (end_opcode != @intFromEnum(std.wasm.Opcode.end)) {
26462636 return step.fail("expected 'end' opcode in init expression", .{});
26472637 }
26482638 }
26492639
26502640 /// https://webassembly.github.io/spec/core/appendix/custom.html
2651 fn parseDumpNames(step: *Step, reader: anytype, writer: anytype, data: []const u8) !void {
2641 fn parseDumpNames(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void {
26522642 while (reader.context.pos < data.len) {
26532643 switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) {
26542644 // The module name subsection ... consists of a single name
26552645 // that is assigned to the module itself.
26562646 .module => {
2657 const size = try std.leb.readUleb128(u32, reader);
2658 const name_len = try std.leb.readUleb128(u32, reader);
2647 const size = try reader.takeLeb128(u32);
2648 const name_len = try reader.takeLeb128(u32);
26592649 if (size != name_len + 1) return error.BadSubsectionSize;
26602650 if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream;
26612651 try writer.print("name {s}\n", .{data[reader.context.pos..][0..name_len]});
......@@ -2665,16 +2655,16 @@ const WasmDumper = struct {
26652655 // The function name subsection ... consists of a name map
26662656 // assigning function names to function indices.
26672657 .function, .global, .data_segment => {
2668 const size = try std.leb.readUleb128(u32, reader);
2669 const entries = try std.leb.readUleb128(u32, reader);
2658 const size = try reader.takeLeb128(u32);
2659 const entries = try reader.takeLeb128(u32);
26702660 try writer.print(
26712661 \\size {d}
26722662 \\names {d}
26732663 \\
26742664 , .{ size, entries });
26752665 for (0..entries) |_| {
2676 const index = try std.leb.readUleb128(u32, reader);
2677 const name_len = try std.leb.readUleb128(u32, reader);
2666 const index = try reader.takeLeb128(u32);
2667 const name_len = try reader.takeLeb128(u32);
26782668 if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream;
26792669 const name = data[reader.context.pos..][0..name_len];
26802670 reader.context.pos += name.len;
......@@ -2699,16 +2689,16 @@ const WasmDumper = struct {
26992689 }
27002690 }
27012691
2702 fn parseDumpProducers(reader: anytype, writer: anytype, data: []const u8) !void {
2703 const field_count = try std.leb.readUleb128(u32, reader);
2692 fn parseDumpProducers(reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void {
2693 const field_count = try reader.takeLeb128(u32);
27042694 try writer.print("fields {d}\n", .{field_count});
27052695 var current_field: u32 = 0;
27062696 while (current_field < field_count) : (current_field += 1) {
2707 const field_name_length = try std.leb.readUleb128(u32, reader);
2697 const field_name_length = try reader.takeLeb128(u32);
27082698 const field_name = data[reader.context.pos..][0..field_name_length];
27092699 reader.context.pos += field_name_length;
27102700
2711 const value_count = try std.leb.readUleb128(u32, reader);
2701 const value_count = try reader.takeLeb128(u32);
27122702 try writer.print(
27132703 \\field_name {s}
27142704 \\values {d}
......@@ -2716,11 +2706,11 @@ const WasmDumper = struct {
27162706 try writer.writeByte('\n');
27172707 var current_value: u32 = 0;
27182708 while (current_value < value_count) : (current_value += 1) {
2719 const value_length = try std.leb.readUleb128(u32, reader);
2709 const value_length = try reader.takeLeb128(u32);
27202710 const value = data[reader.context.pos..][0..value_length];
27212711 reader.context.pos += value_length;
27222712
2723 const version_length = try std.leb.readUleb128(u32, reader);
2713 const version_length = try reader.takeLeb128(u32);
27242714 const version = data[reader.context.pos..][0..version_length];
27252715 reader.context.pos += version_length;
27262716
......@@ -2733,14 +2723,14 @@ const WasmDumper = struct {
27332723 }
27342724 }
27352725
2736 fn parseDumpFeatures(reader: anytype, writer: anytype, data: []const u8) !void {
2737 const feature_count = try std.leb.readUleb128(u32, reader);
2726 fn parseDumpFeatures(reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void {
2727 const feature_count = try reader.takeLeb128(u32);
27382728 try writer.print("features {d}\n", .{feature_count});
27392729
27402730 var index: u32 = 0;
27412731 while (index < feature_count) : (index += 1) {
2742 const prefix_byte = try std.leb.readUleb128(u8, reader);
2743 const name_length = try std.leb.readUleb128(u32, reader);
2732 const prefix_byte = try reader.takeLeb128(u8);
2733 const name_length = try reader.takeLeb128(u32);
27442734 const feature_name = data[reader.context.pos..][0..name_length];
27452735 reader.context.pos += name_length;
27462736
lib/std/Build/Step/Compile.zig+1-1
......@@ -2021,7 +2021,7 @@ fn checkCompileErrors(compile: *Compile) !void {
20212021 const arena = compile.step.owner.allocator;
20222022
20232023 const actual_errors = ae: {
2024 var aw: std.io.Writer.Allocating = .init(arena);
2024 var aw: std.Io.Writer.Allocating = .init(arena);
20252025 defer aw.deinit();
20262026 try actual_eb.renderToWriter(.{
20272027 .ttyconf = .no_color,
lib/std/Build/Step/ConfigHeader.zig+4-4
......@@ -2,7 +2,7 @@ const std = @import("std");
22const ConfigHeader = @This();
33const Step = std.Build.Step;
44const Allocator = std.mem.Allocator;
5const Writer = std.io.Writer;
5const Writer = std.Io.Writer;
66
77pub const Style = union(enum) {
88 /// A configure format supported by autotools that uses `#undef foo` to
......@@ -196,7 +196,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
196196 man.hash.addBytes(config_header.include_path);
197197 man.hash.addOptionalBytes(config_header.include_guard_override);
198198
199 var aw: std.io.Writer.Allocating = .init(gpa);
199 var aw: Writer.Allocating = .init(gpa);
200200 defer aw.deinit();
201201 const bw = &aw.writer;
202202
......@@ -329,7 +329,7 @@ fn render_autoconf_undef(
329329fn render_autoconf_at(
330330 step: *Step,
331331 contents: []const u8,
332 aw: *std.io.Writer.Allocating,
332 aw: *Writer.Allocating,
333333 values: std.StringArrayHashMap(Value),
334334 src_path: []const u8,
335335) !void {
......@@ -753,7 +753,7 @@ fn testReplaceVariablesAutoconfAt(
753753 expected: []const u8,
754754 values: std.StringArrayHashMap(Value),
755755) !void {
756 var aw: std.io.Writer.Allocating = .init(allocator);
756 var aw: Writer.Allocating = .init(allocator);
757757 defer aw.deinit();
758758
759759 const used = try allocator.alloc(bool, values.count());
lib/std/Build/Step/ObjCopy.zig-1
......@@ -9,7 +9,6 @@ const InstallDir = std.Build.InstallDir;
99const Step = std.Build.Step;
1010const elf = std.elf;
1111const fs = std.fs;
12const io = std.io;
1312const sort = std.sort;
1413
1514pub const base_id: Step.Id = .objcopy;
lib/std/Build/WebServer.zig+3-3
......@@ -3,7 +3,7 @@ thread_pool: *std.Thread.Pool,
33graph: *const Build.Graph,
44all_steps: []const *Build.Step,
55listen_address: std.net.Address,
6ttyconf: std.io.tty.Config,
6ttyconf: std.Io.tty.Config,
77root_prog_node: std.Progress.Node,
88watch: bool,
99
......@@ -53,7 +53,7 @@ pub const Options = struct {
5353 thread_pool: *std.Thread.Pool,
5454 graph: *const std.Build.Graph,
5555 all_steps: []const *Build.Step,
56 ttyconf: std.io.tty.Config,
56 ttyconf: std.Io.tty.Config,
5757 root_prog_node: std.Progress.Node,
5858 watch: bool,
5959 listen_address: std.net.Address,
......@@ -557,7 +557,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
557557 child.stderr_behavior = .Pipe;
558558 try child.spawn();
559559
560 var poller = std.io.poll(gpa, enum { stdout, stderr }, .{
560 var poller = std.Io.poll(gpa, enum { stdout, stderr }, .{
561561 .stdout = child.stdout.?,
562562 .stderr = child.stderr.?,
563563 });
lib/std/Io.zig-197
......@@ -82,202 +82,6 @@ pub const Limit = enum(usize) {
8282pub const Reader = @import("Io/Reader.zig");
8383pub const Writer = @import("Io/Writer.zig");
8484
85/// Deprecated in favor of `Reader`.
86pub fn GenericReader(
87 comptime Context: type,
88 comptime ReadError: type,
89 /// Returns the number of bytes read. It may be less than buffer.len.
90 /// If the number of bytes read is 0, it means end of stream.
91 /// End of stream is not an error condition.
92 comptime readFn: fn (context: Context, buffer: []u8) ReadError!usize,
93) type {
94 return struct {
95 context: Context,
96
97 pub const Error = ReadError;
98 pub const NoEofError = ReadError || error{
99 EndOfStream,
100 };
101
102 pub inline fn read(self: Self, buffer: []u8) Error!usize {
103 return readFn(self.context, buffer);
104 }
105
106 pub inline fn readAll(self: Self, buffer: []u8) Error!usize {
107 return @errorCast(self.any().readAll(buffer));
108 }
109
110 pub inline fn readAtLeast(self: Self, buffer: []u8, len: usize) Error!usize {
111 return @errorCast(self.any().readAtLeast(buffer, len));
112 }
113
114 pub inline fn readNoEof(self: Self, buf: []u8) NoEofError!void {
115 return @errorCast(self.any().readNoEof(buf));
116 }
117
118 pub inline fn readAllArrayList(
119 self: Self,
120 array_list: *std.array_list.Managed(u8),
121 max_append_size: usize,
122 ) (error{StreamTooLong} || Allocator.Error || Error)!void {
123 return @errorCast(self.any().readAllArrayList(array_list, max_append_size));
124 }
125
126 pub inline fn readAllArrayListAligned(
127 self: Self,
128 comptime alignment: ?Alignment,
129 array_list: *std.array_list.AlignedManaged(u8, alignment),
130 max_append_size: usize,
131 ) (error{StreamTooLong} || Allocator.Error || Error)!void {
132 return @errorCast(self.any().readAllArrayListAligned(
133 alignment,
134 array_list,
135 max_append_size,
136 ));
137 }
138
139 pub inline fn readAllAlloc(
140 self: Self,
141 allocator: Allocator,
142 max_size: usize,
143 ) (Error || Allocator.Error || error{StreamTooLong})![]u8 {
144 return @errorCast(self.any().readAllAlloc(allocator, max_size));
145 }
146
147 pub inline fn streamUntilDelimiter(
148 self: Self,
149 writer: anytype,
150 delimiter: u8,
151 optional_max_size: ?usize,
152 ) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void {
153 return @errorCast(self.any().streamUntilDelimiter(
154 writer,
155 delimiter,
156 optional_max_size,
157 ));
158 }
159
160 pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {
161 return @errorCast(self.any().skipUntilDelimiterOrEof(delimiter));
162 }
163
164 pub inline fn readByte(self: Self) NoEofError!u8 {
165 return @errorCast(self.any().readByte());
166 }
167
168 pub inline fn readByteSigned(self: Self) NoEofError!i8 {
169 return @errorCast(self.any().readByteSigned());
170 }
171
172 pub inline fn readBytesNoEof(
173 self: Self,
174 comptime num_bytes: usize,
175 ) NoEofError![num_bytes]u8 {
176 return @errorCast(self.any().readBytesNoEof(num_bytes));
177 }
178
179 pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
180 return @errorCast(self.any().readInt(T, endian));
181 }
182
183 pub inline fn readVarInt(
184 self: Self,
185 comptime ReturnType: type,
186 endian: std.builtin.Endian,
187 size: usize,
188 ) NoEofError!ReturnType {
189 return @errorCast(self.any().readVarInt(ReturnType, endian, size));
190 }
191
192 pub const SkipBytesOptions = AnyReader.SkipBytesOptions;
193
194 pub inline fn skipBytes(
195 self: Self,
196 num_bytes: u64,
197 comptime options: SkipBytesOptions,
198 ) NoEofError!void {
199 return @errorCast(self.any().skipBytes(num_bytes, options));
200 }
201
202 pub inline fn isBytes(self: Self, slice: []const u8) NoEofError!bool {
203 return @errorCast(self.any().isBytes(slice));
204 }
205
206 pub inline fn readStruct(self: Self, comptime T: type) NoEofError!T {
207 return @errorCast(self.any().readStruct(T));
208 }
209
210 pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
211 return @errorCast(self.any().readStructEndian(T, endian));
212 }
213
214 pub const ReadEnumError = NoEofError || error{
215 /// An integer was read, but it did not match any of the tags in the supplied enum.
216 InvalidValue,
217 };
218
219 pub inline fn readEnum(
220 self: Self,
221 comptime Enum: type,
222 endian: std.builtin.Endian,
223 ) ReadEnumError!Enum {
224 return @errorCast(self.any().readEnum(Enum, endian));
225 }
226
227 pub inline fn any(self: *const Self) AnyReader {
228 return .{
229 .context = @ptrCast(&self.context),
230 .readFn = typeErasedReadFn,
231 };
232 }
233
234 const Self = @This();
235
236 fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize {
237 const ptr: *const Context = @ptrCast(@alignCast(context));
238 return readFn(ptr.*, buffer);
239 }
240
241 /// Helper for bridging to the new `Reader` API while upgrading.
242 pub fn adaptToNewApi(self: *const Self, buffer: []u8) Adapter {
243 return .{
244 .derp_reader = self.*,
245 .new_interface = .{
246 .buffer = buffer,
247 .vtable = &.{ .stream = Adapter.stream },
248 .seek = 0,
249 .end = 0,
250 },
251 };
252 }
253
254 pub const Adapter = struct {
255 derp_reader: Self,
256 new_interface: Reader,
257 err: ?Error = null,
258
259 fn stream(r: *Reader, w: *Writer, limit: Limit) Reader.StreamError!usize {
260 const a: *@This() = @alignCast(@fieldParentPtr("new_interface", r));
261 const buf = limit.slice(try w.writableSliceGreedy(1));
262 const n = a.derp_reader.read(buf) catch |err| {
263 a.err = err;
264 return error.ReadFailed;
265 };
266 if (n == 0) return error.EndOfStream;
267 w.advance(n);
268 return n;
269 }
270 };
271 };
272}
273
274/// Deprecated in favor of `Reader`.
275pub const AnyReader = @import("Io/DeprecatedReader.zig");
276/// Deprecated in favor of `Reader`.
277pub const FixedBufferStream = @import("Io/fixed_buffer_stream.zig").FixedBufferStream;
278/// Deprecated in favor of `Reader`.
279pub const fixedBufferStream = @import("Io/fixed_buffer_stream.zig").fixedBufferStream;
280
28185pub const tty = @import("Io/tty.zig");
28286
28387pub fn poll(
......@@ -746,7 +550,6 @@ pub fn PollFiles(comptime StreamEnum: type) type {
746550test {
747551 _ = Reader;
748552 _ = Writer;
749 _ = FixedBufferStream;
750553 _ = tty;
751554 _ = @import("Io/test.zig");
752555}
lib/std/Io/DeprecatedReader.zig deleted-292
......@@ -1,292 +0,0 @@
1context: *const anyopaque,
2readFn: *const fn (context: *const anyopaque, buffer: []u8) anyerror!usize,
3
4pub const Error = anyerror;
5
6/// Returns the number of bytes read. It may be less than buffer.len.
7/// If the number of bytes read is 0, it means end of stream.
8/// End of stream is not an error condition.
9pub fn read(self: Self, buffer: []u8) anyerror!usize {
10 return self.readFn(self.context, buffer);
11}
12
13/// Returns the number of bytes read. If the number read is smaller than `buffer.len`, it
14/// means the stream reached the end. Reaching the end of a stream is not an error
15/// condition.
16pub fn readAll(self: Self, buffer: []u8) anyerror!usize {
17 return readAtLeast(self, buffer, buffer.len);
18}
19
20/// Returns the number of bytes read, calling the underlying read
21/// function the minimal number of times until the buffer has at least
22/// `len` bytes filled. If the number read is less than `len` it means
23/// the stream reached the end. Reaching the end of the stream is not
24/// an error condition.
25pub fn readAtLeast(self: Self, buffer: []u8, len: usize) anyerror!usize {
26 assert(len <= buffer.len);
27 var index: usize = 0;
28 while (index < len) {
29 const amt = try self.read(buffer[index..]);
30 if (amt == 0) break;
31 index += amt;
32 }
33 return index;
34}
35
36/// If the number read would be smaller than `buf.len`, `error.EndOfStream` is returned instead.
37pub fn readNoEof(self: Self, buf: []u8) anyerror!void {
38 const amt_read = try self.readAll(buf);
39 if (amt_read < buf.len) return error.EndOfStream;
40}
41
42/// Appends to the `std.array_list.Managed` contents by reading from the stream
43/// until end of stream is found.
44/// If the number of bytes appended would exceed `max_append_size`,
45/// `error.StreamTooLong` is returned
46/// and the `std.array_list.Managed` has exactly `max_append_size` bytes appended.
47pub fn readAllArrayList(
48 self: Self,
49 array_list: *std.array_list.Managed(u8),
50 max_append_size: usize,
51) anyerror!void {
52 return self.readAllArrayListAligned(null, array_list, max_append_size);
53}
54
55pub fn readAllArrayListAligned(
56 self: Self,
57 comptime alignment: ?Alignment,
58 array_list: *std.array_list.AlignedManaged(u8, alignment),
59 max_append_size: usize,
60) anyerror!void {
61 try array_list.ensureTotalCapacity(@min(max_append_size, 4096));
62 const original_len = array_list.items.len;
63 var start_index: usize = original_len;
64 while (true) {
65 array_list.expandToCapacity();
66 const dest_slice = array_list.items[start_index..];
67 const bytes_read = try self.readAll(dest_slice);
68 start_index += bytes_read;
69
70 if (start_index - original_len > max_append_size) {
71 array_list.shrinkAndFree(original_len + max_append_size);
72 return error.StreamTooLong;
73 }
74
75 if (bytes_read != dest_slice.len) {
76 array_list.shrinkAndFree(start_index);
77 return;
78 }
79
80 // This will trigger ArrayList to expand superlinearly at whatever its growth rate is.
81 try array_list.ensureTotalCapacity(start_index + 1);
82 }
83}
84
85/// Allocates enough memory to hold all the contents of the stream. If the allocated
86/// memory would be greater than `max_size`, returns `error.StreamTooLong`.
87/// Caller owns returned memory.
88/// If this function returns an error, the contents from the stream read so far are lost.
89pub fn readAllAlloc(self: Self, allocator: mem.Allocator, max_size: usize) anyerror![]u8 {
90 var array_list = std.array_list.Managed(u8).init(allocator);
91 defer array_list.deinit();
92 try self.readAllArrayList(&array_list, max_size);
93 return try array_list.toOwnedSlice();
94}
95
96/// Appends to the `writer` contents by reading from the stream until `delimiter` is found.
97/// Does not write the delimiter itself.
98/// If `optional_max_size` is not null and amount of written bytes exceeds `optional_max_size`,
99/// returns `error.StreamTooLong` and finishes appending.
100/// If `optional_max_size` is null, appending is unbounded.
101pub fn streamUntilDelimiter(
102 self: Self,
103 writer: anytype,
104 delimiter: u8,
105 optional_max_size: ?usize,
106) anyerror!void {
107 if (optional_max_size) |max_size| {
108 for (0..max_size) |_| {
109 const byte: u8 = try self.readByte();
110 if (byte == delimiter) return;
111 try writer.writeByte(byte);
112 }
113 return error.StreamTooLong;
114 } else {
115 while (true) {
116 const byte: u8 = try self.readByte();
117 if (byte == delimiter) return;
118 try writer.writeByte(byte);
119 }
120 // Can not throw `error.StreamTooLong` since there are no boundary.
121 }
122}
123
124/// Reads from the stream until specified byte is found, discarding all data,
125/// including the delimiter.
126/// If end-of-stream is found, this function succeeds.
127pub fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) anyerror!void {
128 while (true) {
129 const byte = self.readByte() catch |err| switch (err) {
130 error.EndOfStream => return,
131 else => |e| return e,
132 };
133 if (byte == delimiter) return;
134 }
135}
136
137/// Reads 1 byte from the stream or returns `error.EndOfStream`.
138pub fn readByte(self: Self) anyerror!u8 {
139 var result: [1]u8 = undefined;
140 const amt_read = try self.read(result[0..]);
141 if (amt_read < 1) return error.EndOfStream;
142 return result[0];
143}
144
145/// Same as `readByte` except the returned byte is signed.
146pub fn readByteSigned(self: Self) anyerror!i8 {
147 return @as(i8, @bitCast(try self.readByte()));
148}
149
150/// Reads exactly `num_bytes` bytes and returns as an array.
151/// `num_bytes` must be comptime-known
152pub fn readBytesNoEof(self: Self, comptime num_bytes: usize) anyerror![num_bytes]u8 {
153 var bytes: [num_bytes]u8 = undefined;
154 try self.readNoEof(&bytes);
155 return bytes;
156}
157
158pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) anyerror!T {
159 const bytes = try self.readBytesNoEof(@divExact(@typeInfo(T).int.bits, 8));
160 return mem.readInt(T, &bytes, endian);
161}
162
163pub fn readVarInt(
164 self: Self,
165 comptime ReturnType: type,
166 endian: std.builtin.Endian,
167 size: usize,
168) anyerror!ReturnType {
169 assert(size <= @sizeOf(ReturnType));
170 var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined;
171 const bytes = bytes_buf[0..size];
172 try self.readNoEof(bytes);
173 return mem.readVarInt(ReturnType, bytes, endian);
174}
175
176/// Optional parameters for `skipBytes`
177pub const SkipBytesOptions = struct {
178 buf_size: usize = 512,
179};
180
181// `num_bytes` is a `u64` to match `off_t`
182/// Reads `num_bytes` bytes from the stream and discards them
183pub fn skipBytes(self: Self, num_bytes: u64, comptime options: SkipBytesOptions) anyerror!void {
184 var buf: [options.buf_size]u8 = undefined;
185 var remaining = num_bytes;
186
187 while (remaining > 0) {
188 const amt = @min(remaining, options.buf_size);
189 try self.readNoEof(buf[0..amt]);
190 remaining -= amt;
191 }
192}
193
194/// Reads `slice.len` bytes from the stream and returns if they are the same as the passed slice
195pub fn isBytes(self: Self, slice: []const u8) anyerror!bool {
196 var i: usize = 0;
197 var matches = true;
198 while (i < slice.len) : (i += 1) {
199 if (slice[i] != try self.readByte()) {
200 matches = false;
201 }
202 }
203 return matches;
204}
205
206pub fn readStruct(self: Self, comptime T: type) anyerror!T {
207 // Only extern and packed structs have defined in-memory layout.
208 comptime assert(@typeInfo(T).@"struct".layout != .auto);
209 var res: [1]T = undefined;
210 try self.readNoEof(mem.sliceAsBytes(res[0..]));
211 return res[0];
212}
213
214pub fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) anyerror!T {
215 var res = try self.readStruct(T);
216 if (native_endian != endian) {
217 mem.byteSwapAllFields(T, &res);
218 }
219 return res;
220}
221
222/// Reads an integer with the same size as the given enum's tag type. If the integer matches
223/// an enum tag, casts the integer to the enum tag and returns it. Otherwise, returns an `error.InvalidValue`.
224/// TODO optimization taking advantage of most fields being in order
225pub fn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) anyerror!Enum {
226 const E = error{
227 /// An integer was read, but it did not match any of the tags in the supplied enum.
228 InvalidValue,
229 };
230 const type_info = @typeInfo(Enum).@"enum";
231 const tag = try self.readInt(type_info.tag_type, endian);
232
233 inline for (std.meta.fields(Enum)) |field| {
234 if (tag == field.value) {
235 return @field(Enum, field.name);
236 }
237 }
238
239 return E.InvalidValue;
240}
241
242/// Reads the stream until the end, ignoring all the data.
243/// Returns the number of bytes discarded.
244pub fn discard(self: Self) anyerror!u64 {
245 var trash: [4096]u8 = undefined;
246 var index: u64 = 0;
247 while (true) {
248 const n = try self.read(&trash);
249 if (n == 0) return index;
250 index += n;
251 }
252}
253
254/// Helper for bridging to the new `Reader` API while upgrading.
255pub fn adaptToNewApi(self: *const Self, buffer: []u8) Adapter {
256 return .{
257 .derp_reader = self.*,
258 .new_interface = .{
259 .buffer = buffer,
260 .vtable = &.{ .stream = Adapter.stream },
261 .seek = 0,
262 .end = 0,
263 },
264 };
265}
266
267pub const Adapter = struct {
268 derp_reader: Self,
269 new_interface: std.io.Reader,
270 err: ?Error = null,
271
272 fn stream(r: *std.io.Reader, w: *std.io.Writer, limit: std.io.Limit) std.io.Reader.StreamError!usize {
273 const a: *@This() = @alignCast(@fieldParentPtr("new_interface", r));
274 const buf = limit.slice(try w.writableSliceGreedy(1));
275 const n = a.derp_reader.read(buf) catch |err| {
276 a.err = err;
277 return error.ReadFailed;
278 };
279 if (n == 0) return error.EndOfStream;
280 w.advance(n);
281 return n;
282 }
283};
284
285const std = @import("../std.zig");
286const Self = @This();
287const math = std.math;
288const assert = std.debug.assert;
289const mem = std.mem;
290const testing = std.testing;
291const native_endian = @import("builtin").target.cpu.arch.endian();
292const Alignment = std.mem.Alignment;
lib/std/Io/Reader.zig+91-12
......@@ -4,12 +4,12 @@ const builtin = @import("builtin");
44const native_endian = builtin.target.cpu.arch.endian();
55
66const std = @import("../std.zig");
7const Writer = std.io.Writer;
7const Writer = std.Io.Writer;
8const Limit = std.Io.Limit;
89const assert = std.debug.assert;
910const testing = std.testing;
1011const Allocator = std.mem.Allocator;
1112const ArrayList = std.ArrayList;
12const Limit = std.io.Limit;
1313
1414pub const Limited = @import("Reader/Limited.zig");
1515
......@@ -1592,7 +1592,7 @@ test readVec {
15921592test "expected error.EndOfStream" {
15931593 // Unit test inspired by https://github.com/ziglang/zig/issues/17733
15941594 var buffer: [3]u8 = undefined;
1595 var r: std.io.Reader = .fixed(&buffer);
1595 var r: std.Io.Reader = .fixed(&buffer);
15961596 r.end = 0; // capacity 3, but empty
15971597 try std.testing.expectError(error.EndOfStream, r.takeEnum(enum(u8) { a, b }, .little));
15981598 try std.testing.expectError(error.EndOfStream, r.take(3));
......@@ -1647,15 +1647,6 @@ fn failingDiscard(r: *Reader, limit: Limit) Error!usize {
16471647 return error.ReadFailed;
16481648}
16491649
1650pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader {
1651 return .{ .context = r, .readFn = derpRead };
1652}
1653
1654fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize {
1655 const r: *Reader = @ptrCast(@alignCast(@constCast(context)));
1656 return r.readSliceShort(buffer);
1657}
1658
16591650test "readAlloc when the backing reader provides one byte at a time" {
16601651 const str = "This is a test";
16611652 var tiny_buffer: [1]u8 = undefined;
......@@ -1878,6 +1869,94 @@ pub fn writableVector(r: *Reader, buffer: [][]u8, data: []const []u8) Error!stru
18781869 return .{ i, n };
18791870}
18801871
1872test "deserialize signed LEB128" {
1873 // Truncated
1874 try testing.expectError(error.EndOfStream, testLeb128(i64, "\x80"));
1875
1876 // Overflow
1877 try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x80\x40"));
1878 try testing.expectError(error.Overflow, testLeb128(i16, "\x80\x80\x80\x40"));
1879 try testing.expectError(error.Overflow, testLeb128(i32, "\x80\x80\x80\x80\x40"));
1880 try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
1881 try testing.expectError(error.Overflow, testLeb128(i8, "\xff\x7e"));
1882 try testing.expectError(error.Overflow, testLeb128(i32, "\x80\x80\x80\x80\x08"));
1883 try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"));
1884
1885 // Decode SLEB128
1886 try testing.expect((try testLeb128(i64, "\x00")) == 0);
1887 try testing.expect((try testLeb128(i64, "\x01")) == 1);
1888 try testing.expect((try testLeb128(i64, "\x3f")) == 63);
1889 try testing.expect((try testLeb128(i64, "\x40")) == -64);
1890 try testing.expect((try testLeb128(i64, "\x41")) == -63);
1891 try testing.expect((try testLeb128(i64, "\x7f")) == -1);
1892 try testing.expect((try testLeb128(i64, "\x80\x01")) == 128);
1893 try testing.expect((try testLeb128(i64, "\x81\x01")) == 129);
1894 try testing.expect((try testLeb128(i64, "\xff\x7e")) == -129);
1895 try testing.expect((try testLeb128(i64, "\x80\x7f")) == -128);
1896 try testing.expect((try testLeb128(i64, "\x81\x7f")) == -127);
1897 try testing.expect((try testLeb128(i64, "\xc0\x00")) == 64);
1898 try testing.expect((try testLeb128(i64, "\xc7\x9f\x7f")) == -12345);
1899 try testing.expect((try testLeb128(i8, "\xff\x7f")) == -1);
1900 try testing.expect((try testLeb128(i16, "\xff\xff\x7f")) == -1);
1901 try testing.expect((try testLeb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
1902 try testing.expect((try testLeb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000);
1903 try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))));
1904 try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
1905 try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
1906
1907 // Decode unnormalized SLEB128 with extra padding bytes.
1908 try testing.expect((try testLeb128(i64, "\x80\x00")) == 0);
1909 try testing.expect((try testLeb128(i64, "\x80\x80\x00")) == 0);
1910 try testing.expect((try testLeb128(i64, "\xff\x00")) == 0x7f);
1911 try testing.expect((try testLeb128(i64, "\xff\x80\x00")) == 0x7f);
1912 try testing.expect((try testLeb128(i64, "\x80\x81\x00")) == 0x80);
1913 try testing.expect((try testLeb128(i64, "\x80\x81\x80\x00")) == 0x80);
1914}
1915
1916test "deserialize unsigned LEB128" {
1917 // Truncated
1918 try testing.expectError(error.EndOfStream, testLeb128(u64, "\x80"));
1919 try testing.expectError(error.EndOfStream, testLeb128(u16, "\x80\x80\x84"));
1920 try testing.expectError(error.EndOfStream, testLeb128(u32, "\x80\x80\x80\x80\x90"));
1921
1922 // Overflow
1923 try testing.expectError(error.Overflow, testLeb128(u8, "\x80\x02"));
1924 try testing.expectError(error.Overflow, testLeb128(u8, "\x80\x80\x40"));
1925 try testing.expectError(error.Overflow, testLeb128(u16, "\x80\x80\x80\x40"));
1926 try testing.expectError(error.Overflow, testLeb128(u32, "\x80\x80\x80\x80\x40"));
1927 try testing.expectError(error.Overflow, testLeb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
1928
1929 // Decode ULEB128
1930 try testing.expect((try testLeb128(u64, "\x00")) == 0);
1931 try testing.expect((try testLeb128(u64, "\x01")) == 1);
1932 try testing.expect((try testLeb128(u64, "\x3f")) == 63);
1933 try testing.expect((try testLeb128(u64, "\x40")) == 64);
1934 try testing.expect((try testLeb128(u64, "\x7f")) == 0x7f);
1935 try testing.expect((try testLeb128(u64, "\x80\x01")) == 0x80);
1936 try testing.expect((try testLeb128(u64, "\x81\x01")) == 0x81);
1937 try testing.expect((try testLeb128(u64, "\x90\x01")) == 0x90);
1938 try testing.expect((try testLeb128(u64, "\xff\x01")) == 0xff);
1939 try testing.expect((try testLeb128(u64, "\x80\x02")) == 0x100);
1940 try testing.expect((try testLeb128(u64, "\x81\x02")) == 0x101);
1941 try testing.expect((try testLeb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
1942 try testing.expect((try testLeb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
1943
1944 // Decode ULEB128 with extra padding bytes
1945 try testing.expect((try testLeb128(u64, "\x80\x00")) == 0);
1946 try testing.expect((try testLeb128(u64, "\x80\x80\x00")) == 0);
1947 try testing.expect((try testLeb128(u64, "\xff\x00")) == 0x7f);
1948 try testing.expect((try testLeb128(u64, "\xff\x80\x00")) == 0x7f);
1949 try testing.expect((try testLeb128(u64, "\x80\x81\x00")) == 0x80);
1950 try testing.expect((try testLeb128(u64, "\x80\x81\x80\x00")) == 0x80);
1951}
1952
1953fn testLeb128(comptime T: type, encoded: []const u8) !T {
1954 var reader: std.Io.Reader = .fixed(encoded);
1955 const result = try reader.takeLeb128(T);
1956 try testing.expect(reader.seek == reader.end);
1957 return result;
1958}
1959
18811960test {
18821961 _ = Limited;
18831962}
lib/std/Io/Reader/Limited.zig+3-3
......@@ -1,9 +1,9 @@
11const Limited = @This();
22
33const std = @import("../../std.zig");
4const Reader = std.io.Reader;
5const Writer = std.io.Writer;
6const Limit = std.io.Limit;
4const Reader = std.Io.Reader;
5const Writer = std.Io.Writer;
6const Limit = std.Io.Limit;
77
88unlimited: *Reader,
99remaining: Limit,
lib/std/Io/fixed_buffer_stream.zig deleted-114
......@@ -1,114 +0,0 @@
1const std = @import("../std.zig");
2const io = std.io;
3const testing = std.testing;
4const mem = std.mem;
5const assert = std.debug.assert;
6
7/// Deprecated in favor of `std.Io.Reader.fixed` and `std.Io.Writer.fixed`.
8pub fn FixedBufferStream(comptime Buffer: type) type {
9 return struct {
10 /// `Buffer` is either a `[]u8` or `[]const u8`.
11 buffer: Buffer,
12 pos: usize,
13
14 pub const ReadError = error{};
15 pub const WriteError = error{NoSpaceLeft};
16 pub const SeekError = error{};
17 pub const GetSeekPosError = error{};
18
19 pub const Reader = io.GenericReader(*Self, ReadError, read);
20
21 const Self = @This();
22
23 pub fn reader(self: *Self) Reader {
24 return .{ .context = self };
25 }
26
27 pub fn read(self: *Self, dest: []u8) ReadError!usize {
28 const size = @min(dest.len, self.buffer.len - self.pos);
29 const end = self.pos + size;
30
31 @memcpy(dest[0..size], self.buffer[self.pos..end]);
32 self.pos = end;
33
34 return size;
35 }
36
37 pub fn seekTo(self: *Self, pos: u64) SeekError!void {
38 self.pos = @min(std.math.lossyCast(usize, pos), self.buffer.len);
39 }
40
41 pub fn seekBy(self: *Self, amt: i64) SeekError!void {
42 if (amt < 0) {
43 const abs_amt = @abs(amt);
44 const abs_amt_usize = std.math.cast(usize, abs_amt) orelse std.math.maxInt(usize);
45 if (abs_amt_usize > self.pos) {
46 self.pos = 0;
47 } else {
48 self.pos -= abs_amt_usize;
49 }
50 } else {
51 const amt_usize = std.math.cast(usize, amt) orelse std.math.maxInt(usize);
52 const new_pos = std.math.add(usize, self.pos, amt_usize) catch std.math.maxInt(usize);
53 self.pos = @min(self.buffer.len, new_pos);
54 }
55 }
56
57 pub fn getEndPos(self: *Self) GetSeekPosError!u64 {
58 return self.buffer.len;
59 }
60
61 pub fn getPos(self: *Self) GetSeekPosError!u64 {
62 return self.pos;
63 }
64
65 pub fn reset(self: *Self) void {
66 self.pos = 0;
67 }
68 };
69}
70
71pub fn fixedBufferStream(buffer: anytype) FixedBufferStream(Slice(@TypeOf(buffer))) {
72 return .{ .buffer = buffer, .pos = 0 };
73}
74
75fn Slice(comptime T: type) type {
76 switch (@typeInfo(T)) {
77 .pointer => |ptr_info| {
78 var new_ptr_info = ptr_info;
79 switch (ptr_info.size) {
80 .slice => {},
81 .one => switch (@typeInfo(ptr_info.child)) {
82 .array => |info| new_ptr_info.child = info.child,
83 else => @compileError("invalid type given to fixedBufferStream"),
84 },
85 else => @compileError("invalid type given to fixedBufferStream"),
86 }
87 new_ptr_info.size = .slice;
88 return @Type(.{ .pointer = new_ptr_info });
89 },
90 else => @compileError("invalid type given to fixedBufferStream"),
91 }
92}
93
94test "input" {
95 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
96 var fbs = fixedBufferStream(&bytes);
97
98 var dest: [4]u8 = undefined;
99
100 var read = try fbs.reader().read(&dest);
101 try testing.expect(read == 4);
102 try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4]));
103
104 read = try fbs.reader().read(&dest);
105 try testing.expect(read == 3);
106 try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7]));
107
108 read = try fbs.reader().read(&dest);
109 try testing.expect(read == 0);
110
111 try fbs.seekTo((try fbs.getEndPos()) + 1);
112 read = try fbs.reader().read(&dest);
113 try testing.expect(read == 0);
114}
lib/std/Io/test.zig-22
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const io = std.io;
32const DefaultPrng = std.Random.DefaultPrng;
43const expect = std.testing.expect;
54const expectEqual = std.testing.expectEqual;
......@@ -122,24 +121,3 @@ test "updateTimes" {
122121 try expect(stat_new.atime < stat_old.atime);
123122 try expect(stat_new.mtime < stat_old.mtime);
124123}
125
126test "GenericReader methods can return error.EndOfStream" {
127 // https://github.com/ziglang/zig/issues/17733
128 var fbs = std.io.fixedBufferStream("");
129 try std.testing.expectError(
130 error.EndOfStream,
131 fbs.reader().readEnum(enum(u8) { a, b }, .little),
132 );
133 try std.testing.expectError(
134 error.EndOfStream,
135 fbs.reader().isBytes("foo"),
136 );
137}
138
139test "Adapted DeprecatedReader EndOfStream" {
140 var fbs: io.FixedBufferStream([]const u8) = .{ .buffer = &.{}, .pos = 0 };
141 const reader = fbs.reader();
142 var buf: [1]u8 = undefined;
143 var adapted = reader.adaptToNewApi(&buf);
144 try std.testing.expectError(error.EndOfStream, adapted.new_interface.takeByte());
145}
lib/std/Io/tty.zig+2-2
......@@ -76,9 +76,9 @@ pub const Config = union(enum) {
7676 reset_attributes: u16,
7777 };
7878
79 pub const SetColorError = std.os.windows.SetConsoleTextAttributeError || std.io.Writer.Error;
79 pub const SetColorError = std.os.windows.SetConsoleTextAttributeError || std.Io.Writer.Error;
8080
81 pub fn setColor(conf: Config, w: *std.io.Writer, color: Color) SetColorError!void {
81 pub fn setColor(conf: Config, w: *std.Io.Writer, color: Color) SetColorError!void {
8282 nosuspend switch (conf) {
8383 .no_color => return,
8484 .escape_codes => {
lib/std/Progress.zig+1-1
......@@ -9,7 +9,7 @@ const Progress = @This();
99const posix = std.posix;
1010const is_big_endian = builtin.cpu.arch.endian() == .big;
1111const is_windows = builtin.os.tag == .windows;
12const Writer = std.io.Writer;
12const Writer = std.Io.Writer;
1313
1414/// `null` if the current node (and its children) should
1515/// not print on update()
lib/std/SemanticVersion.zig+1-1
......@@ -150,7 +150,7 @@ fn parseNum(text: []const u8) error{ InvalidVersion, Overflow }!usize {
150150 };
151151}
152152
153pub fn format(self: Version, w: *std.io.Writer) std.io.Writer.Error!void {
153pub fn format(self: Version, w: *std.Io.Writer) std.Io.Writer.Error!void {
154154 try w.print("{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
155155 if (self.pre) |pre| try w.print("-{s}", .{pre});
156156 if (self.build) |build| try w.print("+{s}", .{build});
lib/std/Target.zig+1-1
......@@ -308,7 +308,7 @@ pub const Os = struct {
308308
309309 /// This function is defined to serialize a Zig source code representation of this
310310 /// type, that, when parsed, will deserialize into the same data.
311 pub fn format(wv: WindowsVersion, w: *std.io.Writer) std.io.Writer.Error!void {
311 pub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!void {
312312 if (std.enums.tagName(WindowsVersion, wv)) |name| {
313313 var vecs: [2][]const u8 = .{ ".", name };
314314 return w.writeVecAll(&vecs);
lib/std/Thread.zig+4-2
......@@ -281,8 +281,10 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
281281 const file = try std.fs.cwd().openFile(path, .{});
282282 defer file.close();
283283
284 const data_len = try file.deprecatedReader().readAll(buffer_ptr[0 .. max_name_len + 1]);
285
284 var file_reader = file.readerStreaming(&.{});
285 const data_len = file_reader.readSliceShort(buffer_ptr[0 .. max_name_len + 1]) catch |err| switch (err) {
286 error.ReadFailed => return file_reader.err.?,
287 };
286288 return if (data_len >= 1) buffer[0 .. data_len - 1] else null;
287289 },
288290 .windows => {
lib/std/array_list.zig+2-2
......@@ -1038,14 +1038,14 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
10381038
10391039 pub fn printAssumeCapacity(self: *Self, comptime fmt: []const u8, args: anytype) void {
10401040 comptime assert(T == u8);
1041 var w: std.io.Writer = .fixed(self.unusedCapacitySlice());
1041 var w: std.Io.Writer = .fixed(self.unusedCapacitySlice());
10421042 w.print(fmt, args) catch unreachable;
10431043 self.items.len += w.end;
10441044 }
10451045
10461046 pub fn printBounded(self: *Self, comptime fmt: []const u8, args: anytype) error{OutOfMemory}!void {
10471047 comptime assert(T == u8);
1048 var w: std.io.Writer = .fixed(self.unusedCapacitySlice());
1048 var w: std.Io.Writer = .fixed(self.unusedCapacitySlice());
10491049 w.print(fmt, args) catch return error.OutOfMemory;
10501050 self.items.len += w.end;
10511051 }
lib/std/ascii.zig+1-1
......@@ -444,7 +444,7 @@ pub const HexEscape = struct {
444444 pub const upper_charset = "0123456789ABCDEF";
445445 pub const lower_charset = "0123456789abcdef";
446446
447 pub fn format(se: HexEscape, w: *std.io.Writer) std.io.Writer.Error!void {
447 pub fn format(se: HexEscape, w: *std.Io.Writer) std.Io.Writer.Error!void {
448448 const charset = se.charset;
449449
450450 var buf: [4]u8 = undefined;
lib/std/builtin.zig+2-2
......@@ -38,7 +38,7 @@ pub const StackTrace = struct {
3838 index: usize,
3939 instruction_addresses: []usize,
4040
41 pub fn format(self: StackTrace, writer: *std.io.Writer) std.io.Writer.Error!void {
41 pub fn format(self: StackTrace, writer: *std.Io.Writer) std.Io.Writer.Error!void {
4242 // TODO: re-evaluate whether to use format() methods at all.
4343 // Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly
4444 // where it tries to call detectTTYConfig here.
......@@ -47,7 +47,7 @@ pub const StackTrace = struct {
4747 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
4848 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
4949 };
50 const tty_config = std.io.tty.detectConfig(std.fs.File.stderr());
50 const tty_config = std.Io.tty.detectConfig(std.fs.File.stderr());
5151 try writer.writeAll("\n");
5252 std.debug.writeStackTrace(self, writer, debug_info, tty_config) catch |err| {
5353 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
lib/std/coff.zig+15-20
......@@ -1087,14 +1087,11 @@ pub const Coff = struct {
10871087 const pe_pointer_offset = 0x3C;
10881088 const pe_magic = "PE\x00\x00";
10891089
1090 var stream = std.io.fixedBufferStream(data);
1091 const reader = stream.reader();
1092 try stream.seekTo(pe_pointer_offset);
1093 const coff_header_offset = try reader.readInt(u32, .little);
1094 try stream.seekTo(coff_header_offset);
1095 var buf: [4]u8 = undefined;
1096 try reader.readNoEof(&buf);
1097 const is_image = mem.eql(u8, pe_magic, &buf);
1090 var reader: std.Io.Reader = .fixed(data);
1091 reader.seek = pe_pointer_offset;
1092 const coff_header_offset = try reader.takeInt(u32, .little);
1093 reader.seek = coff_header_offset;
1094 const is_image = mem.eql(u8, pe_magic, try reader.takeArray(4));
10981095
10991096 var coff = @This(){
11001097 .data = data,
......@@ -1123,16 +1120,15 @@ pub const Coff = struct {
11231120 if (@intFromEnum(DirectoryEntry.DEBUG) >= data_dirs.len) return null;
11241121
11251122 const debug_dir = data_dirs[@intFromEnum(DirectoryEntry.DEBUG)];
1126 var stream = std.io.fixedBufferStream(self.data);
1127 const reader = stream.reader();
1123 var reader: std.Io.Reader = .fixed(self.data);
11281124
11291125 if (self.is_loaded) {
1130 try stream.seekTo(debug_dir.virtual_address);
1126 reader.seek = debug_dir.virtual_address;
11311127 } else {
11321128 // Find what section the debug_dir is in, in order to convert the RVA to a file offset
11331129 for (self.getSectionHeaders()) |*sect| {
11341130 if (debug_dir.virtual_address >= sect.virtual_address and debug_dir.virtual_address < sect.virtual_address + sect.virtual_size) {
1135 try stream.seekTo(sect.pointer_to_raw_data + (debug_dir.virtual_address - sect.virtual_address));
1131 reader.seek = sect.pointer_to_raw_data + (debug_dir.virtual_address - sect.virtual_address);
11361132 break;
11371133 }
11381134 } else return error.InvalidDebugDirectory;
......@@ -1143,24 +1139,23 @@ pub const Coff = struct {
11431139 const debug_dir_entry_count = debug_dir.size / @sizeOf(DebugDirectoryEntry);
11441140 var i: u32 = 0;
11451141 while (i < debug_dir_entry_count) : (i += 1) {
1146 const debug_dir_entry = try reader.readStruct(DebugDirectoryEntry);
1142 const debug_dir_entry = try reader.takeStruct(DebugDirectoryEntry, .little);
11471143 if (debug_dir_entry.type == .CODEVIEW) {
11481144 const dir_offset = if (self.is_loaded) debug_dir_entry.address_of_raw_data else debug_dir_entry.pointer_to_raw_data;
1149 try stream.seekTo(dir_offset);
1145 reader.seek = dir_offset;
11501146 break;
11511147 }
11521148 } else return null;
11531149
1154 var cv_signature: [4]u8 = undefined; // CodeView signature
1155 try reader.readNoEof(cv_signature[0..]);
1150 const code_view_signature = try reader.takeArray(4);
11561151 // 'RSDS' indicates PDB70 format, used by lld.
1157 if (!mem.eql(u8, &cv_signature, "RSDS"))
1152 if (!mem.eql(u8, code_view_signature, "RSDS"))
11581153 return error.InvalidPEMagic;
1159 try reader.readNoEof(self.guid[0..]);
1160 self.age = try reader.readInt(u32, .little);
1154 try reader.readSliceAll(self.guid[0..]);
1155 self.age = try reader.takeInt(u32, .little);
11611156
11621157 // Finally read the null-terminated string.
1163 const start = reader.context.pos;
1158 const start = reader.seek;
11641159 const len = std.mem.indexOfScalar(u8, self.data[start..], 0) orelse return null;
11651160 return self.data[start .. start + len];
11661161 }
lib/std/compress/flate/BlockWriter.zig+1-2
......@@ -1,9 +1,8 @@
11//! Accepts list of tokens, decides what is best block type to write. What block
22//! type will provide best compression. Writes header and body of the block.
33const std = @import("std");
4const io = std.io;
54const assert = std.debug.assert;
6const Writer = std.io.Writer;
5const Writer = std.Io.Writer;
76
87const BlockWriter = @This();
98const flate = @import("../flate.zig");
lib/std/compress/zstd/Decompress.zig+3-3
......@@ -1,10 +1,10 @@
11const Decompress = @This();
22const std = @import("std");
33const assert = std.debug.assert;
4const Reader = std.io.Reader;
5const Limit = std.io.Limit;
4const Reader = std.Io.Reader;
5const Limit = std.Io.Limit;
66const zstd = @import("../zstd.zig");
7const Writer = std.io.Writer;
7const Writer = std.Io.Writer;
88
99input: *Reader,
1010reader: Reader,
lib/std/crypto/Certificate/Bundle/macos.zig+11-12
......@@ -23,30 +23,29 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
2323 const bytes = try file.readToEndAlloc(gpa, std.math.maxInt(u32));
2424 defer gpa.free(bytes);
2525
26 var stream = std.io.fixedBufferStream(bytes);
27 const reader = stream.reader();
26 var reader: std.Io.Reader = .fixed(bytes);
2827
29 const db_header = try reader.readStructEndian(ApplDbHeader, .big);
28 const db_header = try reader.takeStruct(ApplDbHeader, .big);
3029 assert(mem.eql(u8, &db_header.signature, "kych"));
3130
32 try stream.seekTo(db_header.schema_offset);
31 reader.seek = db_header.schema_offset;
3332
34 const db_schema = try reader.readStructEndian(ApplDbSchema, .big);
33 const db_schema = try reader.takeStruct(ApplDbSchema, .big);
3534
3635 var table_list = try gpa.alloc(u32, db_schema.table_count);
3736 defer gpa.free(table_list);
3837
3938 var table_idx: u32 = 0;
4039 while (table_idx < table_list.len) : (table_idx += 1) {
41 table_list[table_idx] = try reader.readInt(u32, .big);
40 table_list[table_idx] = try reader.takeInt(u32, .big);
4241 }
4342
4443 const now_sec = std.time.timestamp();
4544
4645 for (table_list) |table_offset| {
47 try stream.seekTo(db_header.schema_offset + table_offset);
46 reader.seek = db_header.schema_offset + table_offset;
4847
49 const table_header = try reader.readStructEndian(TableHeader, .big);
48 const table_header = try reader.takeStruct(TableHeader, .big);
5049
5150 if (@as(std.c.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
5251 continue;
......@@ -57,7 +56,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
5756
5857 var record_idx: u32 = 0;
5958 while (record_idx < record_list.len) : (record_idx += 1) {
60 record_list[record_idx] = try reader.readInt(u32, .big);
59 record_list[record_idx] = try reader.takeInt(u32, .big);
6160 }
6261
6362 for (record_list) |record_offset| {
......@@ -65,15 +64,15 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
6564 // An offset that is not 4-byte-aligned is invalid.
6665 if (record_offset == 0 or record_offset % 4 != 0) continue;
6766
68 try stream.seekTo(db_header.schema_offset + table_offset + record_offset);
67 reader.seek = db_header.schema_offset + table_offset + record_offset;
6968
70 const cert_header = try reader.readStructEndian(X509CertHeader, .big);
69 const cert_header = try reader.takeStruct(X509CertHeader, .big);
7170
7271 if (cert_header.cert_size == 0) continue;
7372
7473 const cert_start = @as(u32, @intCast(cb.bytes.items.len));
7574 const dest_buf = try cb.bytes.addManyAsSlice(gpa, cert_header.cert_size);
76 try reader.readNoEof(dest_buf);
75 try reader.readSliceAll(dest_buf);
7776
7877 try cb.parseCert(gpa, cert_start, now_sec);
7978 }
lib/std/crypto/codecs/asn1.zig+13-15
......@@ -69,15 +69,15 @@ pub const Tag = struct {
6969 return .{ .number = number, .constructed = constructed, .class = .universal };
7070 }
7171
72 pub fn decode(reader: anytype) !Tag {
73 const tag1: FirstTag = @bitCast(try reader.readByte());
72 pub fn decode(reader: *std.Io.Reader) !Tag {
73 const tag1: FirstTag = @bitCast(try reader.takeByte());
7474 var number: u14 = tag1.number;
7575
7676 if (tag1.number == 15) {
77 const tag2: NextTag = @bitCast(try reader.readByte());
77 const tag2: NextTag = @bitCast(try reader.takeByte());
7878 number = tag2.number;
7979 if (tag2.continues) {
80 const tag3: NextTag = @bitCast(try reader.readByte());
80 const tag3: NextTag = @bitCast(try reader.takeByte());
8181 number = (number << 7) + tag3.number;
8282 if (tag3.continues) return error.InvalidLength;
8383 }
......@@ -90,7 +90,7 @@ pub const Tag = struct {
9090 };
9191 }
9292
93 pub fn encode(self: Tag, writer: anytype) @TypeOf(writer).Error!void {
93 pub fn encode(self: Tag, writer: *std.Io.Writer) @TypeOf(writer).Error!void {
9494 var tag1 = FirstTag{
9595 .number = undefined,
9696 .constructed = self.constructed,
......@@ -98,8 +98,7 @@ pub const Tag = struct {
9898 };
9999
100100 var buffer: [3]u8 = undefined;
101 var stream = std.io.fixedBufferStream(&buffer);
102 var writer2 = stream.writer();
101 var writer2: std.Io.Writer = .init(&buffer);
103102
104103 switch (@intFromEnum(self.number)) {
105104 0...std.math.maxInt(u5) => |n| {
......@@ -122,7 +121,7 @@ pub const Tag = struct {
122121 },
123122 }
124123
125 _ = try writer.write(stream.getWritten());
124 _ = try writer.write(writer2.buffered());
126125 }
127126
128127 const FirstTag = packed struct(u8) { number: u5, constructed: bool, class: Tag.Class };
......@@ -161,8 +160,8 @@ pub const Tag = struct {
161160
162161test Tag {
163162 const buf = [_]u8{0xa3};
164 var stream = std.io.fixedBufferStream(&buf);
165 const t = Tag.decode(stream.reader());
163 var reader: std.Io.Reader = .fixed(&buf);
164 const t = Tag.decode(&reader);
166165 try std.testing.expectEqual(Tag.init(@enumFromInt(3), true, .context_specific), t);
167166}
168167
......@@ -191,11 +190,10 @@ pub const Element = struct {
191190 /// - Ensures length is within `bytes`
192191 /// - Ensures length is less than `std.math.maxInt(Index)`
193192 pub fn decode(bytes: []const u8, index: Index) DecodeError!Element {
194 var stream = std.io.fixedBufferStream(bytes[index..]);
195 var reader = stream.reader();
193 var reader: std.Io.Reader = .fixed(bytes[index..]);
196194
197 const tag = try Tag.decode(reader);
198 const size_or_len_size = try reader.readByte();
195 const tag = try Tag.decode(&reader);
196 const size_or_len_size = try reader.takeByte();
199197
200198 var start = index + 2;
201199 var end = start + size_or_len_size;
......@@ -208,7 +206,7 @@ pub const Element = struct {
208206 start += len_size;
209207 if (len_size > @sizeOf(Index)) return error.InvalidLength;
210208
211 const len = try reader.readVarInt(Index, .big, len_size);
209 const len = try reader.takeVarInt(Index, .big, len_size);
212210 if (len < 128) return error.InvalidLength; // should have used short form
213211
214212 end = std.math.add(Index, start, len) catch return error.InvalidLength;
lib/std/crypto/codecs/asn1/Oid.zig+6-7
......@@ -4,7 +4,7 @@
44//! organizations, or policy documents.
55encoded: []const u8,
66
7pub const InitError = std.fmt.ParseIntError || error{MissingPrefix} || std.io.FixedBufferStream(u8).WriteError;
7pub const InitError = std.fmt.ParseIntError || error{MissingPrefix} || std.Io.Writer.Error;
88
99pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid {
1010 var split = std.mem.splitScalar(u8, dot_notation, '.');
......@@ -14,8 +14,7 @@ pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid {
1414 const first = try std.fmt.parseInt(u8, first_str, 10);
1515 const second = try std.fmt.parseInt(u8, second_str, 10);
1616
17 var stream = std.io.fixedBufferStream(out);
18 var writer = stream.writer();
17 var writer: std.Io.Writer = .fixed(out);
1918
2019 try writer.writeByte(first * 40 + second);
2120
......@@ -37,7 +36,7 @@ pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid {
3736 i += 1;
3837 }
3938
40 return .{ .encoded = stream.getWritten() };
39 return .{ .encoded = writer.buffered() };
4140}
4241
4342test fromDot {
......@@ -80,9 +79,9 @@ test toDot {
8079 var buf: [256]u8 = undefined;
8180
8281 for (test_cases) |t| {
83 var stream = std.io.fixedBufferStream(&buf);
84 try toDot(Oid{ .encoded = t.encoded }, stream.writer());
85 try std.testing.expectEqualStrings(t.dot_notation, stream.getWritten());
82 var stream: std.Io.Writer = .fixed(&buf);
83 try toDot(Oid{ .encoded = t.encoded }, &stream);
84 try std.testing.expectEqualStrings(t.dot_notation, stream.written());
8685 }
8786}
8887
lib/std/crypto/ecdsa.zig+12-17
......@@ -2,7 +2,6 @@ const builtin = @import("builtin");
22const std = @import("std");
33const crypto = std.crypto;
44const fmt = std.fmt;
5const io = std.io;
65const mem = std.mem;
76const sha3 = crypto.hash.sha3;
87const testing = std.testing;
......@@ -135,8 +134,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
135134 /// The maximum length of the DER encoding is der_encoded_length_max.
136135 /// The function returns a slice, that can be shorter than der_encoded_length_max.
137136 pub fn toDer(sig: Signature, buf: *[der_encoded_length_max]u8) []u8 {
138 var fb = io.fixedBufferStream(buf);
139 const w = fb.writer();
137 var w: std.Io.Writer = .fixed(buf);
140138 const r_len = @as(u8, @intCast(sig.r.len + (sig.r[0] >> 7)));
141139 const s_len = @as(u8, @intCast(sig.s.len + (sig.s[0] >> 7)));
142140 const seq_len = @as(u8, @intCast(2 + r_len + 2 + s_len));
......@@ -151,24 +149,23 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
151149 w.writeByte(0x00) catch unreachable;
152150 }
153151 w.writeAll(&sig.s) catch unreachable;
154 return fb.getWritten();
152 return w.buffered();
155153 }
156154
157155 // Read a DER-encoded integer.
158 fn readDerInt(out: []u8, reader: anytype) EncodingError!void {
159 var buf: [2]u8 = undefined;
160 _ = reader.readNoEof(&buf) catch return error.InvalidEncoding;
156 fn readDerInt(out: []u8, reader: *std.Io.Reader) EncodingError!void {
157 const buf = reader.takeArray(2) catch return error.InvalidEncoding;
161158 if (buf[0] != 0x02) return error.InvalidEncoding;
162 var expected_len = @as(usize, buf[1]);
159 var expected_len: usize = buf[1];
163160 if (expected_len == 0 or expected_len > 1 + out.len) return error.InvalidEncoding;
164161 var has_top_bit = false;
165162 if (expected_len == 1 + out.len) {
166 if ((reader.readByte() catch return error.InvalidEncoding) != 0) return error.InvalidEncoding;
163 if ((reader.takeByte() catch return error.InvalidEncoding) != 0) return error.InvalidEncoding;
167164 expected_len -= 1;
168165 has_top_bit = true;
169166 }
170167 const out_slice = out[out.len - expected_len ..];
171 reader.readNoEof(out_slice) catch return error.InvalidEncoding;
168 reader.readSliceAll(out_slice) catch return error.InvalidEncoding;
172169 if (@intFromBool(has_top_bit) != out[0] >> 7) return error.InvalidEncoding;
173170 }
174171
......@@ -176,16 +173,14 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
176173 /// Returns InvalidEncoding if the DER encoding is invalid.
177174 pub fn fromDer(der: []const u8) EncodingError!Signature {
178175 var sig: Signature = mem.zeroInit(Signature, .{});
179 var fb = io.fixedBufferStream(der);
180 const reader = fb.reader();
181 var buf: [2]u8 = undefined;
182 _ = reader.readNoEof(&buf) catch return error.InvalidEncoding;
176 var reader: std.Io.Reader = .fixed(der);
177 const buf = reader.takeArray(2) catch return error.InvalidEncoding;
183178 if (buf[0] != 0x30 or @as(usize, buf[1]) + 2 != der.len) {
184179 return error.InvalidEncoding;
185180 }
186 try readDerInt(&sig.r, reader);
187 try readDerInt(&sig.s, reader);
188 if (fb.getPos() catch unreachable != der.len) return error.InvalidEncoding;
181 try readDerInt(&sig.r, &reader);
182 try readDerInt(&sig.s, &reader);
183 if (reader.seek != der.len) return error.InvalidEncoding;
189184
190185 return sig;
191186 }
lib/std/crypto/phc_encoding.zig-1
......@@ -2,7 +2,6 @@
22
33const std = @import("std");
44const fmt = std.fmt;
5const io = std.io;
65const mem = std.mem;
76const meta = std.meta;
87const Writer = std.Io.Writer;
lib/std/crypto/scrypt.zig-1
......@@ -5,7 +5,6 @@
55const std = @import("std");
66const crypto = std.crypto;
77const fmt = std.fmt;
8const io = std.io;
98const math = std.math;
109const mem = std.mem;
1110const meta = std.meta;
lib/std/crypto/tls.zig+2-2
......@@ -655,7 +655,7 @@ pub const Decoder = struct {
655655 }
656656
657657 /// Use this function to increase `their_end`.
658 pub fn readAtLeast(d: *Decoder, stream: *std.io.Reader, their_amt: usize) !void {
658 pub fn readAtLeast(d: *Decoder, stream: *std.Io.Reader, their_amt: usize) !void {
659659 assert(!d.disable_reads);
660660 const existing_amt = d.cap - d.idx;
661661 d.their_end = d.idx + their_amt;
......@@ -672,7 +672,7 @@ pub const Decoder = struct {
672672
673673 /// Same as `readAtLeast` but also increases `our_end` by exactly `our_amt`.
674674 /// Use when `our_amt` is calculated by us, not by them.
675 pub fn readAtLeastOurAmt(d: *Decoder, stream: *std.io.Reader, our_amt: usize) !void {
675 pub fn readAtLeastOurAmt(d: *Decoder, stream: *std.Io.Reader, our_amt: usize) !void {
676676 assert(!d.disable_reads);
677677 try readAtLeast(d, stream, our_amt);
678678 d.our_end = d.idx + our_amt;
lib/std/debug.zig+19-19
......@@ -2,7 +2,6 @@ const builtin = @import("builtin");
22const std = @import("std.zig");
33const math = std.math;
44const mem = std.mem;
5const io = std.io;
65const posix = std.posix;
76const fs = std.fs;
87const testing = std.testing;
......@@ -12,7 +11,8 @@ const windows = std.os.windows;
1211const native_arch = builtin.cpu.arch;
1312const native_os = builtin.os.tag;
1413const native_endian = native_arch.endian();
15const Writer = std.io.Writer;
14const Writer = std.Io.Writer;
15const tty = std.Io.tty;
1616
1717pub const Dwarf = @import("debug/Dwarf.zig");
1818pub const Pdb = @import("debug/Pdb.zig");
......@@ -246,12 +246,12 @@ pub fn getSelfDebugInfo() !*SelfInfo {
246246pub fn dumpHex(bytes: []const u8) void {
247247 const bw = lockStderrWriter(&.{});
248248 defer unlockStderrWriter();
249 const ttyconf = std.io.tty.detectConfig(.stderr());
249 const ttyconf = tty.detectConfig(.stderr());
250250 dumpHexFallible(bw, ttyconf, bytes) catch {};
251251}
252252
253253/// Prints a hexadecimal view of the bytes, returning any error that occurs.
254pub fn dumpHexFallible(bw: *Writer, ttyconf: std.io.tty.Config, bytes: []const u8) !void {
254pub fn dumpHexFallible(bw: *Writer, ttyconf: tty.Config, bytes: []const u8) !void {
255255 var chunks = mem.window(u8, bytes, 16, 16);
256256 while (chunks.next()) |window| {
257257 // 1. Print the address.
......@@ -302,7 +302,7 @@ pub fn dumpHexFallible(bw: *Writer, ttyconf: std.io.tty.Config, bytes: []const u
302302
303303test dumpHexFallible {
304304 const bytes: []const u8 = &.{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x12, 0x13 };
305 var aw: std.io.Writer.Allocating = .init(std.testing.allocator);
305 var aw: Writer.Allocating = .init(std.testing.allocator);
306306 defer aw.deinit();
307307
308308 try dumpHexFallible(&aw.writer, .no_color, bytes);
......@@ -342,7 +342,7 @@ pub fn dumpCurrentStackTraceToWriter(start_addr: ?usize, writer: *Writer) !void
342342 try writer.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
343343 return;
344344 };
345 writeCurrentStackTrace(writer, debug_info, io.tty.detectConfig(.stderr()), start_addr) catch |err| {
345 writeCurrentStackTrace(writer, debug_info, tty.detectConfig(.stderr()), start_addr) catch |err| {
346346 try writer.print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
347347 return;
348348 };
......@@ -427,7 +427,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext, stderr: *Writer) void {
427427 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
428428 return;
429429 };
430 const tty_config = io.tty.detectConfig(.stderr());
430 const tty_config = tty.detectConfig(.stderr());
431431 if (native_os == .windows) {
432432 // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context
433433 // provided by the exception handler. On x86, RtlVirtualUnwind doesn't exist. Instead, a new backtrace
......@@ -533,7 +533,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
533533 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
534534 return;
535535 };
536 writeStackTrace(stack_trace, stderr, debug_info, io.tty.detectConfig(.stderr())) catch |err| {
536 writeStackTrace(stack_trace, stderr, debug_info, tty.detectConfig(.stderr())) catch |err| {
537537 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
538538 return;
539539 };
......@@ -738,7 +738,7 @@ pub fn writeStackTrace(
738738 stack_trace: std.builtin.StackTrace,
739739 writer: *Writer,
740740 debug_info: *SelfInfo,
741 tty_config: io.tty.Config,
741 tty_config: tty.Config,
742742) !void {
743743 if (builtin.strip_debug_info) return error.MissingDebugInfo;
744744 var frame_index: usize = 0;
......@@ -959,7 +959,7 @@ pub const StackIterator = struct {
959959pub fn writeCurrentStackTrace(
960960 writer: *Writer,
961961 debug_info: *SelfInfo,
962 tty_config: io.tty.Config,
962 tty_config: tty.Config,
963963 start_addr: ?usize,
964964) !void {
965965 if (native_os == .windows) {
......@@ -1047,7 +1047,7 @@ pub noinline fn walkStackWindows(addresses: []usize, existing_context: ?*const w
10471047pub fn writeStackTraceWindows(
10481048 writer: *Writer,
10491049 debug_info: *SelfInfo,
1050 tty_config: io.tty.Config,
1050 tty_config: tty.Config,
10511051 context: *const windows.CONTEXT,
10521052 start_addr: ?usize,
10531053) !void {
......@@ -1065,7 +1065,7 @@ pub fn writeStackTraceWindows(
10651065 }
10661066}
10671067
1068fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: io.tty.Config) !void {
1068fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: tty.Config) !void {
10691069 const module_name = debug_info.getModuleNameForAddress(address);
10701070 return printLineInfo(
10711071 writer,
......@@ -1078,14 +1078,14 @@ fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tt
10781078 );
10791079}
10801080
1081fn printLastUnwindError(it: *StackIterator, debug_info: *SelfInfo, writer: *Writer, tty_config: io.tty.Config) void {
1081fn printLastUnwindError(it: *StackIterator, debug_info: *SelfInfo, writer: *Writer, tty_config: tty.Config) void {
10821082 if (!have_ucontext) return;
10831083 if (it.getLastError()) |unwind_error| {
10841084 printUnwindError(debug_info, writer, unwind_error.address, unwind_error.err, tty_config) catch {};
10851085 }
10861086}
10871087
1088fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err: UnwindError, tty_config: io.tty.Config) !void {
1088fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err: UnwindError, tty_config: tty.Config) !void {
10891089 const module_name = debug_info.getModuleNameForAddress(address) orelse "???";
10901090 try tty_config.setColor(writer, .dim);
10911091 if (err == error.MissingDebugInfo) {
......@@ -1096,7 +1096,7 @@ fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err:
10961096 try tty_config.setColor(writer, .reset);
10971097}
10981098
1099pub fn printSourceAtAddress(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: io.tty.Config) !void {
1099pub fn printSourceAtAddress(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: tty.Config) !void {
11001100 const module = debug_info.getModuleForAddress(address) catch |err| switch (err) {
11011101 error.MissingDebugInfo, error.InvalidDebugInfo => return printUnknownSource(debug_info, writer, address, tty_config),
11021102 else => return err,
......@@ -1125,7 +1125,7 @@ fn printLineInfo(
11251125 address: usize,
11261126 symbol_name: []const u8,
11271127 compile_unit_name: []const u8,
1128 tty_config: io.tty.Config,
1128 tty_config: tty.Config,
11291129 comptime printLineFromFile: anytype,
11301130) !void {
11311131 nosuspend {
......@@ -1597,10 +1597,10 @@ test "manage resources correctly" {
15971597 // self-hosted debug info is still too buggy
15981598 if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest;
15991599
1600 var discarding: std.io.Writer.Discarding = .init(&.{});
1600 var discarding: Writer.Discarding = .init(&.{});
16011601 var di = try SelfInfo.open(testing.allocator);
16021602 defer di.deinit();
1603 try printSourceAtAddress(&di, &discarding.writer, showMyTrace(), io.tty.detectConfig(.stderr()));
1603 try printSourceAtAddress(&di, &discarding.writer, showMyTrace(), tty.detectConfig(.stderr()));
16041604}
16051605
16061606noinline fn showMyTrace() usize {
......@@ -1666,7 +1666,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
16661666 pub fn dump(t: @This()) void {
16671667 if (!enabled) return;
16681668
1669 const tty_config = io.tty.detectConfig(.stderr());
1669 const tty_config = tty.detectConfig(.stderr());
16701670 const stderr = lockStderrWriter(&.{});
16711671 defer unlockStderrWriter();
16721672 const end = @min(t.index, size);
lib/std/debug/Dwarf/call_frame.zig+37-44
......@@ -51,15 +51,9 @@ const Opcode = enum(u8) {
5151 pub const hi_user = 0x3f;
5252};
5353
54fn readBlock(stream: *std.io.FixedBufferStream([]const u8)) ![]const u8 {
55 const reader = stream.reader();
56 const block_len = try leb.readUleb128(usize, reader);
57 if (stream.pos + block_len > stream.buffer.len) return error.InvalidOperand;
58
59 const block = stream.buffer[stream.pos..][0..block_len];
60 reader.context.pos += block_len;
61
62 return block;
54fn readBlock(reader: *std.Io.Reader) ![]const u8 {
55 const block_len = try reader.takeLeb128(usize);
56 return reader.take(block_len);
6357}
6458
6559pub const Instruction = union(Opcode) {
......@@ -147,12 +141,11 @@ pub const Instruction = union(Opcode) {
147141 },
148142
149143 pub fn read(
150 stream: *std.io.FixedBufferStream([]const u8),
144 reader: *std.Io.Reader,
151145 addr_size_bytes: u8,
152146 endian: std.builtin.Endian,
153147 ) !Instruction {
154 const reader = stream.reader();
155 switch (try reader.readByte()) {
148 switch (try reader.takeByte()) {
156149 Opcode.lo_inline...Opcode.hi_inline => |opcode| {
157150 const e: Opcode = @enumFromInt(opcode & 0b11000000);
158151 const value: u6 = @intCast(opcode & 0b111111);
......@@ -163,7 +156,7 @@ pub const Instruction = union(Opcode) {
163156 .offset => .{
164157 .offset = .{
165158 .register = value,
166 .offset = try leb.readUleb128(u64, reader),
159 .offset = try reader.takeLeb128(u64),
167160 },
168161 },
169162 .restore => .{
......@@ -183,111 +176,111 @@ pub const Instruction = union(Opcode) {
183176 .set_loc => .{
184177 .set_loc = .{
185178 .address = switch (addr_size_bytes) {
186 2 => try reader.readInt(u16, endian),
187 4 => try reader.readInt(u32, endian),
188 8 => try reader.readInt(u64, endian),
179 2 => try reader.takeInt(u16, endian),
180 4 => try reader.takeInt(u32, endian),
181 8 => try reader.takeInt(u64, endian),
189182 else => return error.InvalidAddrSize,
190183 },
191184 },
192185 },
193186 .advance_loc1 => .{
194 .advance_loc1 = .{ .delta = try reader.readByte() },
187 .advance_loc1 = .{ .delta = try reader.takeByte() },
195188 },
196189 .advance_loc2 => .{
197 .advance_loc2 = .{ .delta = try reader.readInt(u16, endian) },
190 .advance_loc2 = .{ .delta = try reader.takeInt(u16, endian) },
198191 },
199192 .advance_loc4 => .{
200 .advance_loc4 = .{ .delta = try reader.readInt(u32, endian) },
193 .advance_loc4 = .{ .delta = try reader.takeInt(u32, endian) },
201194 },
202195 .offset_extended => .{
203196 .offset_extended = .{
204 .register = try leb.readUleb128(u8, reader),
205 .offset = try leb.readUleb128(u64, reader),
197 .register = try reader.takeLeb128(u8),
198 .offset = try reader.takeLeb128(u64),
206199 },
207200 },
208201 .restore_extended => .{
209202 .restore_extended = .{
210 .register = try leb.readUleb128(u8, reader),
203 .register = try reader.takeLeb128(u8),
211204 },
212205 },
213206 .undefined => .{
214207 .undefined = .{
215 .register = try leb.readUleb128(u8, reader),
208 .register = try reader.takeLeb128(u8),
216209 },
217210 },
218211 .same_value => .{
219212 .same_value = .{
220 .register = try leb.readUleb128(u8, reader),
213 .register = try reader.takeLeb128(u8),
221214 },
222215 },
223216 .register => .{
224217 .register = .{
225 .register = try leb.readUleb128(u8, reader),
226 .target_register = try leb.readUleb128(u8, reader),
218 .register = try reader.takeLeb128(u8),
219 .target_register = try reader.takeLeb128(u8),
227220 },
228221 },
229222 .remember_state => .{ .remember_state = {} },
230223 .restore_state => .{ .restore_state = {} },
231224 .def_cfa => .{
232225 .def_cfa = .{
233 .register = try leb.readUleb128(u8, reader),
234 .offset = try leb.readUleb128(u64, reader),
226 .register = try reader.takeLeb128(u8),
227 .offset = try reader.takeLeb128(u64),
235228 },
236229 },
237230 .def_cfa_register => .{
238231 .def_cfa_register = .{
239 .register = try leb.readUleb128(u8, reader),
232 .register = try reader.takeLeb128(u8),
240233 },
241234 },
242235 .def_cfa_offset => .{
243236 .def_cfa_offset = .{
244 .offset = try leb.readUleb128(u64, reader),
237 .offset = try reader.takeLeb128(u64),
245238 },
246239 },
247240 .def_cfa_expression => .{
248241 .def_cfa_expression = .{
249 .block = try readBlock(stream),
242 .block = try readBlock(reader),
250243 },
251244 },
252245 .expression => .{
253246 .expression = .{
254 .register = try leb.readUleb128(u8, reader),
255 .block = try readBlock(stream),
247 .register = try reader.takeLeb128(u8),
248 .block = try readBlock(reader),
256249 },
257250 },
258251 .offset_extended_sf => .{
259252 .offset_extended_sf = .{
260 .register = try leb.readUleb128(u8, reader),
261 .offset = try leb.readIleb128(i64, reader),
253 .register = try reader.takeLeb128(u8),
254 .offset = try reader.takeLeb128(i64),
262255 },
263256 },
264257 .def_cfa_sf => .{
265258 .def_cfa_sf = .{
266 .register = try leb.readUleb128(u8, reader),
267 .offset = try leb.readIleb128(i64, reader),
259 .register = try reader.takeLeb128(u8),
260 .offset = try reader.takeLeb128(i64),
268261 },
269262 },
270263 .def_cfa_offset_sf => .{
271264 .def_cfa_offset_sf = .{
272 .offset = try leb.readIleb128(i64, reader),
265 .offset = try reader.takeLeb128(i64),
273266 },
274267 },
275268 .val_offset => .{
276269 .val_offset = .{
277 .register = try leb.readUleb128(u8, reader),
278 .offset = try leb.readUleb128(u64, reader),
270 .register = try reader.takeLeb128(u8),
271 .offset = try reader.takeLeb128(u64),
279272 },
280273 },
281274 .val_offset_sf => .{
282275 .val_offset_sf = .{
283 .register = try leb.readUleb128(u8, reader),
284 .offset = try leb.readIleb128(i64, reader),
276 .register = try reader.takeLeb128(u8),
277 .offset = try reader.takeLeb128(i64),
285278 },
286279 },
287280 .val_expression => .{
288281 .val_expression = .{
289 .register = try leb.readUleb128(u8, reader),
290 .block = try readBlock(stream),
282 .register = try reader.takeLeb128(u8),
283 .block = try readBlock(reader),
291284 },
292285 },
293286 };
lib/std/debug/Dwarf/expression.zig+42-49
......@@ -62,7 +62,7 @@ pub const Error = error{
6262 InvalidTypeLength,
6363
6464 TruncatedIntegralType,
65} || abi.RegBytesError || error{ EndOfStream, Overflow, OutOfMemory, DivisionByZero };
65} || abi.RegBytesError || error{ EndOfStream, Overflow, OutOfMemory, DivisionByZero, ReadFailed };
6666
6767/// A stack machine that can decode and run DWARF expressions.
6868/// Expressions can be decoded for non-native address size and endianness,
......@@ -178,61 +178,60 @@ pub fn StackMachine(comptime options: Options) type {
178178 }
179179 }
180180
181 pub fn readOperand(stream: *std.io.FixedBufferStream([]const u8), opcode: u8, context: Context) !?Operand {
182 const reader = stream.reader();
181 pub fn readOperand(reader: *std.Io.Reader, opcode: u8, context: Context) !?Operand {
183182 return switch (opcode) {
184 OP.addr => generic(try reader.readInt(addr_type, options.endian)),
183 OP.addr => generic(try reader.takeInt(addr_type, options.endian)),
185184 OP.call_ref => switch (context.format) {
186 .@"32" => generic(try reader.readInt(u32, options.endian)),
187 .@"64" => generic(try reader.readInt(u64, options.endian)),
185 .@"32" => generic(try reader.takeInt(u32, options.endian)),
186 .@"64" => generic(try reader.takeInt(u64, options.endian)),
188187 },
189188 OP.const1u,
190189 OP.pick,
191 => generic(try reader.readByte()),
190 => generic(try reader.takeByte()),
192191 OP.deref_size,
193192 OP.xderef_size,
194 => .{ .type_size = try reader.readByte() },
195 OP.const1s => generic(try reader.readByteSigned()),
193 => .{ .type_size = try reader.takeByte() },
194 OP.const1s => generic(try reader.takeByteSigned()),
196195 OP.const2u,
197196 OP.call2,
198 => generic(try reader.readInt(u16, options.endian)),
199 OP.call4 => generic(try reader.readInt(u32, options.endian)),
200 OP.const2s => generic(try reader.readInt(i16, options.endian)),
197 => generic(try reader.takeInt(u16, options.endian)),
198 OP.call4 => generic(try reader.takeInt(u32, options.endian)),
199 OP.const2s => generic(try reader.takeInt(i16, options.endian)),
201200 OP.bra,
202201 OP.skip,
203 => .{ .branch_offset = try reader.readInt(i16, options.endian) },
204 OP.const4u => generic(try reader.readInt(u32, options.endian)),
205 OP.const4s => generic(try reader.readInt(i32, options.endian)),
206 OP.const8u => generic(try reader.readInt(u64, options.endian)),
207 OP.const8s => generic(try reader.readInt(i64, options.endian)),
202 => .{ .branch_offset = try reader.takeInt(i16, options.endian) },
203 OP.const4u => generic(try reader.takeInt(u32, options.endian)),
204 OP.const4s => generic(try reader.takeInt(i32, options.endian)),
205 OP.const8u => generic(try reader.takeInt(u64, options.endian)),
206 OP.const8s => generic(try reader.takeInt(i64, options.endian)),
208207 OP.constu,
209208 OP.plus_uconst,
210209 OP.addrx,
211210 OP.constx,
212211 OP.convert,
213212 OP.reinterpret,
214 => generic(try leb.readUleb128(u64, reader)),
213 => generic(try reader.takeLeb128(u64)),
215214 OP.consts,
216215 OP.fbreg,
217 => generic(try leb.readIleb128(i64, reader)),
216 => generic(try reader.takeLeb128(i64)),
218217 OP.lit0...OP.lit31 => |n| generic(n - OP.lit0),
219218 OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 },
220219 OP.breg0...OP.breg31 => |n| .{ .base_register = .{
221220 .base_register = n - OP.breg0,
222 .offset = try leb.readIleb128(i64, reader),
221 .offset = try reader.takeLeb128(i64),
223222 } },
224 OP.regx => .{ .register = try leb.readUleb128(u8, reader) },
223 OP.regx => .{ .register = try reader.takeLeb128(u8) },
225224 OP.bregx => blk: {
226 const base_register = try leb.readUleb128(u8, reader);
227 const offset = try leb.readIleb128(i64, reader);
225 const base_register = try reader.takeLeb128(u8);
226 const offset = try reader.takeLeb128(i64);
228227 break :blk .{ .base_register = .{
229228 .base_register = base_register,
230229 .offset = offset,
231230 } };
232231 },
233232 OP.regval_type => blk: {
234 const register = try leb.readUleb128(u8, reader);
235 const type_offset = try leb.readUleb128(addr_type, reader);
233 const register = try reader.takeLeb128(u8);
234 const type_offset = try reader.takeLeb128(addr_type);
236235 break :blk .{ .register_type = .{
237236 .register = register,
238237 .type_offset = type_offset,
......@@ -240,33 +239,27 @@ pub fn StackMachine(comptime options: Options) type {
240239 },
241240 OP.piece => .{
242241 .composite_location = .{
243 .size = try leb.readUleb128(u8, reader),
242 .size = try reader.takeLeb128(u8),
244243 .offset = 0,
245244 },
246245 },
247246 OP.bit_piece => blk: {
248 const size = try leb.readUleb128(u8, reader);
249 const offset = try leb.readIleb128(i64, reader);
247 const size = try reader.takeLeb128(u8);
248 const offset = try reader.takeLeb128(i64);
250249 break :blk .{ .composite_location = .{
251250 .size = size,
252251 .offset = offset,
253252 } };
254253 },
255254 OP.implicit_value, OP.entry_value => blk: {
256 const size = try leb.readUleb128(u8, reader);
257 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
258 const block = stream.buffer[stream.pos..][0..size];
259 stream.pos += size;
260 break :blk .{
261 .block = block,
262 };
255 const size = try reader.takeLeb128(u8);
256 const block = try reader.take(size);
257 break :blk .{ .block = block };
263258 },
264259 OP.const_type => blk: {
265 const type_offset = try leb.readUleb128(addr_type, reader);
266 const size = try reader.readByte();
267 if (stream.pos + size > stream.buffer.len) return error.InvalidExpression;
268 const value_bytes = stream.buffer[stream.pos..][0..size];
269 stream.pos += size;
260 const type_offset = try reader.takeLeb128(addr_type);
261 const size = try reader.takeByte();
262 const value_bytes = try reader.take(size);
270263 break :blk .{ .const_type = .{
271264 .type_offset = type_offset,
272265 .value_bytes = value_bytes,
......@@ -276,8 +269,8 @@ pub fn StackMachine(comptime options: Options) type {
276269 OP.xderef_type,
277270 => .{
278271 .deref_type = .{
279 .size = try reader.readByte(),
280 .type_offset = try leb.readUleb128(addr_type, reader),
272 .size = try reader.takeByte(),
273 .type_offset = try reader.takeLeb128(addr_type),
281274 },
282275 },
283276 OP.lo_user...OP.hi_user => return error.UnimplementedUserOpcode,
......@@ -293,7 +286,7 @@ pub fn StackMachine(comptime options: Options) type {
293286 initial_value: ?usize,
294287 ) Error!?Value {
295288 if (initial_value) |i| try self.stack.append(allocator, .{ .generic = i });
296 var stream = std.io.fixedBufferStream(expression);
289 var stream: std.Io.Reader = .fixed(expression);
297290 while (try self.step(&stream, allocator, context)) {}
298291 if (self.stack.items.len == 0) return null;
299292 return self.stack.items[self.stack.items.len - 1];
......@@ -302,14 +295,14 @@ pub fn StackMachine(comptime options: Options) type {
302295 /// Reads an opcode and its operands from `stream`, then executes it
303296 pub fn step(
304297 self: *Self,
305 stream: *std.io.FixedBufferStream([]const u8),
298 stream: *std.Io.Reader,
306299 allocator: std.mem.Allocator,
307300 context: Context,
308301 ) Error!bool {
309302 if (@sizeOf(usize) != @sizeOf(addr_type) or options.endian != native_endian)
310303 @compileError("Execution of non-native address sizes / endianness is not supported");
311304
312 const opcode = try stream.reader().readByte();
305 const opcode = try stream.takeByte();
313306 if (options.call_frame_context and !isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode;
314307 const operand = try readOperand(stream, opcode, context);
315308 switch (opcode) {
......@@ -663,11 +656,11 @@ pub fn StackMachine(comptime options: Options) type {
663656 if (condition) {
664657 const new_pos = std.math.cast(
665658 usize,
666 try std.math.add(isize, @as(isize, @intCast(stream.pos)), branch_offset),
659 try std.math.add(isize, @as(isize, @intCast(stream.seek)), branch_offset),
667660 ) orelse return error.InvalidExpression;
668661
669662 if (new_pos < 0 or new_pos > stream.buffer.len) return error.InvalidExpression;
670 stream.pos = new_pos;
663 stream.seek = new_pos;
671664 }
672665 },
673666 OP.call2,
......@@ -746,7 +739,7 @@ pub fn StackMachine(comptime options: Options) type {
746739 if (isOpcodeRegisterLocation(block[0])) {
747740 if (context.thread_context == null) return error.IncompleteExpressionContext;
748741
749 var block_stream = std.io.fixedBufferStream(block);
742 var block_stream: std.Io.Reader = .fixed(block);
750743 const register = (try readOperand(&block_stream, block[0], context)).?.register;
751744 const value = mem.readInt(usize, (try abi.regBytes(context.thread_context.?, register, context.reg_context))[0..@sizeOf(usize)], native_endian);
752745 try self.stack.append(allocator, .{ .generic = value });
......@@ -769,7 +762,7 @@ pub fn StackMachine(comptime options: Options) type {
769762 },
770763 }
771764
772 return stream.pos < stream.buffer.len;
765 return stream.seek < stream.buffer.len;
773766 }
774767 };
775768}
lib/std/debug/SelfInfo.zig+4-7
......@@ -2017,15 +2017,12 @@ pub const VirtualMachine = struct {
20172017
20182018 var prev_row: Row = self.current_row;
20192019
2020 var cie_stream = std.io.fixedBufferStream(cie.initial_instructions);
2021 var fde_stream = std.io.fixedBufferStream(fde.instructions);
2022 var streams = [_]*std.io.FixedBufferStream([]const u8){
2023 &cie_stream,
2024 &fde_stream,
2025 };
2020 var cie_stream: std.Io.Reader = .fixed(cie.initial_instructions);
2021 var fde_stream: std.Io.Reader = .fixed(fde.instructions);
2022 const streams = [_]*std.Io.Reader{ &cie_stream, &fde_stream };
20262023
20272024 for (&streams, 0..) |stream, i| {
2028 while (stream.pos < stream.buffer.len) {
2025 while (stream.seek < stream.buffer.len) {
20292026 const instruction = try std.debug.Dwarf.call_frame.Instruction.read(stream, addr_size_bytes, endian);
20302027 prev_row = try self.step(allocator, cie, i == 0, instruction);
20312028 if (pc < fde.pc_begin + self.current_row.offset) return prev_row;
lib/std/elf.zig+1-1
......@@ -609,7 +609,7 @@ pub const ProgramHeaderBufferIterator = struct {
609609 }
610610};
611611
612fn takePhdr(reader: *std.io.Reader, elf_header: Header) !?Elf64_Phdr {
612fn takePhdr(reader: *std.Io.Reader, elf_header: Header) !?Elf64_Phdr {
613613 if (elf_header.is_64) {
614614 const phdr = try reader.takeStruct(Elf64_Phdr, elf_header.endian);
615615 return phdr;
lib/std/fmt.zig+1-2
......@@ -3,7 +3,6 @@
33const builtin = @import("builtin");
44
55const std = @import("std.zig");
6const io = std.io;
76const math = std.math;
87const assert = std.debug.assert;
98const mem = std.mem;
......@@ -12,7 +11,7 @@ const lossyCast = math.lossyCast;
1211const expectFmt = std.testing.expectFmt;
1312const testing = std.testing;
1413const Allocator = std.mem.Allocator;
15const Writer = std.io.Writer;
14const Writer = std.Io.Writer;
1615
1716pub const float = @import("fmt/float.zig");
1817
lib/std/fs/File.zig-45
......@@ -7,7 +7,6 @@ const File = @This();
77const std = @import("../std.zig");
88const Allocator = std.mem.Allocator;
99const posix = std.posix;
10const io = std.io;
1110const math = std.math;
1211const assert = std.debug.assert;
1312const linux = std.os.linux;
......@@ -805,42 +804,6 @@ pub fn updateTimes(
805804 try posix.futimens(self.handle, &times);
806805}
807806
808/// Deprecated in favor of `Reader`.
809pub fn readToEndAlloc(self: File, allocator: Allocator, max_bytes: usize) ![]u8 {
810 return self.readToEndAllocOptions(allocator, max_bytes, null, .of(u8), null);
811}
812
813/// Deprecated in favor of `Reader`.
814pub fn readToEndAllocOptions(
815 self: File,
816 allocator: Allocator,
817 max_bytes: usize,
818 size_hint: ?usize,
819 comptime alignment: Alignment,
820 comptime optional_sentinel: ?u8,
821) !(if (optional_sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) {
822 // If no size hint is provided fall back to the size=0 code path
823 const size = size_hint orelse 0;
824
825 // The file size returned by stat is used as hint to set the buffer
826 // size. If the reported size is zero, as it happens on Linux for files
827 // in /proc, a small buffer is allocated instead.
828 const initial_cap = @min((if (size > 0) size else 1024), max_bytes) + @intFromBool(optional_sentinel != null);
829 var array_list = try std.array_list.AlignedManaged(u8, alignment).initCapacity(allocator, initial_cap);
830 defer array_list.deinit();
831
832 self.deprecatedReader().readAllArrayListAligned(alignment, &array_list, max_bytes) catch |err| switch (err) {
833 error.StreamTooLong => return error.FileTooBig,
834 else => |e| return e,
835 };
836
837 if (optional_sentinel) |sentinel| {
838 return try array_list.toOwnedSliceSentinel(sentinel);
839 } else {
840 return try array_list.toOwnedSlice();
841 }
842}
843
844807pub const ReadError = posix.ReadError;
845808pub const PReadError = posix.PReadError;
846809
......@@ -1089,14 +1052,6 @@ pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u
10891052 return total_bytes_copied;
10901053}
10911054
1092/// Deprecated in favor of `Reader`.
1093pub const DeprecatedReader = io.GenericReader(File, ReadError, read);
1094
1095/// Deprecated in favor of `Reader`.
1096pub fn deprecatedReader(file: File) DeprecatedReader {
1097 return .{ .context = file };
1098}
1099
11001055/// Memoizes key information about a file handle such as:
11011056/// * The size from calling stat, or the error that occurred therein.
11021057/// * The current seek position.
lib/std/fs/path.zig+1-1
......@@ -150,7 +150,7 @@ pub fn fmtJoin(paths: []const []const u8) std.fmt.Formatter([]const []const u8,
150150 return .{ .data = paths };
151151}
152152
153fn formatJoin(paths: []const []const u8, w: *std.io.Writer) std.io.Writer.Error!void {
153fn formatJoin(paths: []const []const u8, w: *std.Io.Writer) std.Io.Writer.Error!void {
154154 const first_path_idx = for (paths, 0..) |p, idx| {
155155 if (p.len != 0) break idx;
156156 } else return;
lib/std/json.zig+2-2
......@@ -1,7 +1,7 @@
11//! JSON parsing and stringification conforming to RFC 8259. https://datatracker.ietf.org/doc/html/rfc8259
22//!
33//! The low-level `Scanner` API produces `Token`s from an input slice or successive slices of inputs,
4//! The `Reader` API connects a `std.io.GenericReader` to a `Scanner`.
4//! The `Reader` API connects a `std.Io.GenericReader` to a `Scanner`.
55//!
66//! The high-level `parseFromSlice` and `parseFromTokenSource` deserialize a JSON document into a Zig type.
77//! Parse into a dynamically-typed `Value` to load any JSON value for runtime inspection.
......@@ -42,7 +42,7 @@ test Value {
4242}
4343
4444test Stringify {
45 var out: std.io.Writer.Allocating = .init(testing.allocator);
45 var out: std.Io.Writer.Allocating = .init(testing.allocator);
4646 var write_stream: Stringify = .{
4747 .writer = &out.writer,
4848 .options = .{ .whitespace = .indent_2 },
lib/std/json/Stringify.zig+3-3
......@@ -23,7 +23,7 @@ const Allocator = std.mem.Allocator;
2323const ArrayList = std.ArrayList;
2424const BitStack = std.BitStack;
2525const Stringify = @This();
26const Writer = std.io.Writer;
26const Writer = std.Io.Writer;
2727
2828const IndentationMode = enum(u1) {
2929 object = 0,
......@@ -576,7 +576,7 @@ pub fn value(v: anytype, options: Options, writer: *Writer) Error!void {
576576}
577577
578578test value {
579 var out: std.io.Writer.Allocating = .init(std.testing.allocator);
579 var out: Writer.Allocating = .init(std.testing.allocator);
580580 const writer = &out.writer;
581581 defer out.deinit();
582582
......@@ -616,7 +616,7 @@ test value {
616616///
617617/// Caller owns returned memory.
618618pub fn valueAlloc(gpa: Allocator, v: anytype, options: Options) error{OutOfMemory}![]u8 {
619 var aw: std.io.Writer.Allocating = .init(gpa);
619 var aw: Writer.Allocating = .init(gpa);
620620 defer aw.deinit();
621621 value(v, options, &aw.writer) catch return error.OutOfMemory;
622622 return aw.toOwnedSlice();
lib/std/json/dynamic_test.zig+1-1
......@@ -4,7 +4,7 @@ const mem = std.mem;
44const testing = std.testing;
55const ArenaAllocator = std.heap.ArenaAllocator;
66const Allocator = std.mem.Allocator;
7const Writer = std.io.Writer;
7const Writer = std.Io.Writer;
88
99const ObjectMap = @import("dynamic.zig").ObjectMap;
1010const Array = @import("dynamic.zig").Array;
lib/std/leb128.zig+22-251
......@@ -2,120 +2,6 @@ const builtin = @import("builtin");
22const std = @import("std");
33const testing = std.testing;
44
5/// Read a single unsigned LEB128 value from the given reader as type T,
6/// or error.Overflow if the value cannot fit.
7pub fn readUleb128(comptime T: type, reader: anytype) !T {
8 const U = if (@typeInfo(T).int.bits < 8) u8 else T;
9 const ShiftT = std.math.Log2Int(U);
10
11 const max_group = (@typeInfo(U).int.bits + 6) / 7;
12
13 var value: U = 0;
14 var group: ShiftT = 0;
15
16 while (group < max_group) : (group += 1) {
17 const byte = try reader.readByte();
18
19 const ov = @shlWithOverflow(@as(U, byte & 0x7f), group * 7);
20 if (ov[1] != 0) return error.Overflow;
21
22 value |= ov[0];
23 if (byte & 0x80 == 0) break;
24 } else {
25 return error.Overflow;
26 }
27
28 // only applies in the case that we extended to u8
29 if (U != T) {
30 if (value > std.math.maxInt(T)) return error.Overflow;
31 }
32
33 return @as(T, @truncate(value));
34}
35
36/// Read a single signed LEB128 value from the given reader as type T,
37/// or error.Overflow if the value cannot fit.
38pub fn readIleb128(comptime T: type, reader: anytype) !T {
39 const S = if (@typeInfo(T).int.bits < 8) i8 else T;
40 const U = std.meta.Int(.unsigned, @typeInfo(S).int.bits);
41 const ShiftU = std.math.Log2Int(U);
42
43 const max_group = (@typeInfo(U).int.bits + 6) / 7;
44
45 var value = @as(U, 0);
46 var group = @as(ShiftU, 0);
47
48 while (group < max_group) : (group += 1) {
49 const byte = try reader.readByte();
50
51 const shift = group * 7;
52 const ov = @shlWithOverflow(@as(U, byte & 0x7f), shift);
53 if (ov[1] != 0) {
54 // Overflow is ok so long as the sign bit is set and this is the last byte
55 if (byte & 0x80 != 0) return error.Overflow;
56 if (@as(S, @bitCast(ov[0])) >= 0) return error.Overflow;
57
58 // and all the overflowed bits are 1
59 const remaining_shift = @as(u3, @intCast(@typeInfo(U).int.bits - @as(u16, shift)));
60 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
61 if (remaining_bits != -1) return error.Overflow;
62 } else {
63 // If we don't overflow and this is the last byte and the number being decoded
64 // is negative, check that the remaining bits are 1
65 if ((byte & 0x80 == 0) and (@as(S, @bitCast(ov[0])) < 0)) {
66 const remaining_shift = @as(u3, @intCast(@typeInfo(U).int.bits - @as(u16, shift)));
67 const remaining_bits = @as(i8, @bitCast(byte | 0x80)) >> remaining_shift;
68 if (remaining_bits != -1) return error.Overflow;
69 }
70 }
71
72 value |= ov[0];
73 if (byte & 0x80 == 0) {
74 const needs_sign_ext = group + 1 < max_group;
75 if (byte & 0x40 != 0 and needs_sign_ext) {
76 const ones = @as(S, -1);
77 value |= @as(U, @bitCast(ones)) << (shift + 7);
78 }
79 break;
80 }
81 } else {
82 return error.Overflow;
83 }
84
85 const result = @as(S, @bitCast(value));
86 // Only applies if we extended to i8
87 if (S != T) {
88 if (result > std.math.maxInt(T) or result < std.math.minInt(T)) return error.Overflow;
89 }
90
91 return @as(T, @truncate(result));
92}
93
94/// Write a single signed integer as signed LEB128 to the given writer.
95pub fn writeIleb128(writer: anytype, arg: anytype) !void {
96 const Arg = @TypeOf(arg);
97 const Int = switch (Arg) {
98 comptime_int => std.math.IntFittingRange(-@abs(arg), @abs(arg)),
99 else => Arg,
100 };
101 const Signed = if (@typeInfo(Int).int.bits < 8) i8 else Int;
102 const Unsigned = std.meta.Int(.unsigned, @typeInfo(Signed).int.bits);
103 var value: Signed = arg;
104
105 while (true) {
106 const unsigned: Unsigned = @bitCast(value);
107 const byte: u8 = @truncate(unsigned);
108 value >>= 6;
109 if (value == -1 or value == 0) {
110 try writer.writeByte(byte & 0x7F);
111 break;
112 } else {
113 value >>= 1;
114 try writer.writeByte(byte | 0x80);
115 }
116 }
117}
118
1195/// This is an "advanced" function. It allows one to use a fixed amount of memory to store a
1206/// ULEB128. This defeats the entire purpose of using this data encoding; it will no longer use
1217/// fewer bytes to store smaller numbers. The advantage of using a fixed width is that it makes
......@@ -149,22 +35,26 @@ test writeUnsignedFixed {
14935 {
15036 var buf: [4]u8 = undefined;
15137 writeUnsignedFixed(4, &buf, 0);
152 try testing.expect((try test_read_uleb128(u64, &buf)) == 0);
38 var reader: std.Io.Reader = .fixed(&buf);
39 try testing.expectEqual(0, try reader.takeLeb128(u64));
15340 }
15441 {
15542 var buf: [4]u8 = undefined;
15643 writeUnsignedFixed(4, &buf, 1);
157 try testing.expect((try test_read_uleb128(u64, &buf)) == 1);
44 var reader: std.Io.Reader = .fixed(&buf);
45 try testing.expectEqual(1, try reader.takeLeb128(u64));
15846 }
15947 {
16048 var buf: [4]u8 = undefined;
16149 writeUnsignedFixed(4, &buf, 1000);
162 try testing.expect((try test_read_uleb128(u64, &buf)) == 1000);
50 var reader: std.Io.Reader = .fixed(&buf);
51 try testing.expectEqual(1000, try reader.takeLeb128(u64));
16352 }
16453 {
16554 var buf: [4]u8 = undefined;
16655 writeUnsignedFixed(4, &buf, 10000000);
167 try testing.expect((try test_read_uleb128(u64, &buf)) == 10000000);
56 var reader: std.Io.Reader = .fixed(&buf);
57 try testing.expectEqual(10000000, try reader.takeLeb128(u64));
16858 }
16959}
17060
......@@ -193,162 +83,43 @@ test writeSignedFixed {
19383 {
19484 var buf: [4]u8 = undefined;
19585 writeSignedFixed(4, &buf, 0);
196 try testing.expect((try test_read_ileb128(i64, &buf)) == 0);
86 var reader: std.Io.Reader = .fixed(&buf);
87 try testing.expectEqual(0, try reader.takeLeb128(i64));
19788 }
19889 {
19990 var buf: [4]u8 = undefined;
20091 writeSignedFixed(4, &buf, 1);
201 try testing.expect((try test_read_ileb128(i64, &buf)) == 1);
92 var reader: std.Io.Reader = .fixed(&buf);
93 try testing.expectEqual(1, try reader.takeLeb128(i64));
20294 }
20395 {
20496 var buf: [4]u8 = undefined;
20597 writeSignedFixed(4, &buf, -1);
206 try testing.expect((try test_read_ileb128(i64, &buf)) == -1);
98 var reader: std.Io.Reader = .fixed(&buf);
99 try testing.expectEqual(-1, try reader.takeLeb128(i64));
207100 }
208101 {
209102 var buf: [4]u8 = undefined;
210103 writeSignedFixed(4, &buf, 1000);
211 try testing.expect((try test_read_ileb128(i64, &buf)) == 1000);
104 var reader: std.Io.Reader = .fixed(&buf);
105 try testing.expectEqual(1000, try reader.takeLeb128(i64));
212106 }
213107 {
214108 var buf: [4]u8 = undefined;
215109 writeSignedFixed(4, &buf, -1000);
216 try testing.expect((try test_read_ileb128(i64, &buf)) == -1000);
110 var reader: std.Io.Reader = .fixed(&buf);
111 try testing.expectEqual(-1000, try reader.takeLeb128(i64));
217112 }
218113 {
219114 var buf: [4]u8 = undefined;
220115 writeSignedFixed(4, &buf, -10000000);
221 try testing.expect((try test_read_ileb128(i64, &buf)) == -10000000);
116 var reader: std.Io.Reader = .fixed(&buf);
117 try testing.expectEqual(-10000000, try reader.takeLeb128(i64));
222118 }
223119 {
224120 var buf: [4]u8 = undefined;
225121 writeSignedFixed(4, &buf, 10000000);
226 try testing.expect((try test_read_ileb128(i64, &buf)) == 10000000);
122 var reader: std.Io.Reader = .fixed(&buf);
123 try testing.expectEqual(10000000, try reader.takeLeb128(i64));
227124 }
228125}
229
230// tests
231fn test_read_stream_ileb128(comptime T: type, encoded: []const u8) !T {
232 var reader = std.io.fixedBufferStream(encoded);
233 return try readIleb128(T, reader.reader());
234}
235
236fn test_read_stream_uleb128(comptime T: type, encoded: []const u8) !T {
237 var reader = std.io.fixedBufferStream(encoded);
238 return try readUleb128(T, reader.reader());
239}
240
241fn test_read_ileb128(comptime T: type, encoded: []const u8) !T {
242 var reader = std.io.fixedBufferStream(encoded);
243 const v1 = try readIleb128(T, reader.reader());
244 return v1;
245}
246
247fn test_read_uleb128(comptime T: type, encoded: []const u8) !T {
248 var reader = std.io.fixedBufferStream(encoded);
249 const v1 = try readUleb128(T, reader.reader());
250 return v1;
251}
252
253fn test_read_ileb128_seq(comptime T: type, comptime N: usize, encoded: []const u8) !void {
254 var reader = std.io.fixedBufferStream(encoded);
255 var i: usize = 0;
256 while (i < N) : (i += 1) {
257 _ = try readIleb128(T, reader.reader());
258 }
259}
260
261fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u8) !void {
262 var reader = std.io.fixedBufferStream(encoded);
263 var i: usize = 0;
264 while (i < N) : (i += 1) {
265 _ = try readUleb128(T, reader.reader());
266 }
267}
268
269test "deserialize signed LEB128" {
270 // Truncated
271 try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80"));
272
273 // Overflow
274 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40"));
275 try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40"));
276 try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
277 try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
278 try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
279 try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x08"));
280 try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"));
281
282 // Decode SLEB128
283 try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
284 try testing.expect((try test_read_ileb128(i64, "\x01")) == 1);
285 try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63);
286 try testing.expect((try test_read_ileb128(i64, "\x40")) == -64);
287 try testing.expect((try test_read_ileb128(i64, "\x41")) == -63);
288 try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1);
289 try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128);
290 try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129);
291 try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129);
292 try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128);
293 try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127);
294 try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64);
295 try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345);
296 try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
297 try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
298 try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
299 try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000);
300 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000)))));
301 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
302 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);
303
304 // Decode unnormalized SLEB128 with extra padding bytes.
305 try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0);
306 try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0);
307 try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f);
308 try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f);
309 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80);
310 try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80);
311
312 // Decode sequence of SLEB128 values
313 try test_read_ileb128_seq(i64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
314}
315
316test "deserialize unsigned LEB128" {
317 // Truncated
318 try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80"));
319
320 // Overflow
321 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02"));
322 try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40"));
323 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84"));
324 try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40"));
325 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90"));
326 try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40"));
327 try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
328
329 // Decode ULEB128
330 try testing.expect((try test_read_uleb128(u64, "\x00")) == 0);
331 try testing.expect((try test_read_uleb128(u64, "\x01")) == 1);
332 try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63);
333 try testing.expect((try test_read_uleb128(u64, "\x40")) == 64);
334 try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f);
335 try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80);
336 try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81);
337 try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90);
338 try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff);
339 try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100);
340 try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101);
341 try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616);
342 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000);
343
344 // Decode ULEB128 with extra padding bytes
345 try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0);
346 try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0);
347 try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f);
348 try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f);
349 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80);
350 try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80);
351
352 // Decode sequence of ULEB128 values
353 try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
354}
lib/std/macho.zig-1
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const io = std.io;
54const mem = std.mem;
65const meta = std.meta;
76const testing = std.testing;
lib/std/math/big/int.zig+5-5
......@@ -2029,11 +2029,11 @@ pub const Mutable = struct {
20292029 r.len = llnormalize(r.limbs[0..length]);
20302030 }
20312031
2032 pub fn format(self: Mutable, w: *std.io.Writer) std.io.Writer.Error!void {
2032 pub fn format(self: Mutable, w: *std.Io.Writer) std.Io.Writer.Error!void {
20332033 return formatNumber(self, w, .{});
20342034 }
20352035
2036 pub fn formatNumber(self: Const, w: *std.io.Writer, n: std.fmt.Number) std.io.Writer.Error!void {
2036 pub fn formatNumber(self: Const, w: *std.Io.Writer, n: std.fmt.Number) std.Io.Writer.Error!void {
20372037 return self.toConst().formatNumber(w, n);
20382038 }
20392039};
......@@ -2326,7 +2326,7 @@ pub const Const = struct {
23262326 /// this function will fail to print the string, printing "(BigInt)" instead of a number.
23272327 /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory.
23282328 /// See `toString` and `toStringAlloc` for a way to print big integers without failure.
2329 pub fn formatNumber(self: Const, w: *std.io.Writer, number: std.fmt.Number) std.io.Writer.Error!void {
2329 pub fn formatNumber(self: Const, w: *std.Io.Writer, number: std.fmt.Number) std.Io.Writer.Error!void {
23302330 const available_len = 64;
23312331 if (self.limbs.len > available_len)
23322332 return w.writeAll("(BigInt)");
......@@ -2907,7 +2907,7 @@ pub const Managed = struct {
29072907 }
29082908
29092909 /// To allow `std.fmt.format` to work with `Managed`.
2910 pub fn format(self: Managed, w: *std.io.Writer) std.io.Writer.Error!void {
2910 pub fn format(self: Managed, w: *std.Io.Writer) std.Io.Writer.Error!void {
29112911 return formatNumber(self, w, .{});
29122912 }
29132913
......@@ -2915,7 +2915,7 @@ pub const Managed = struct {
29152915 /// this function will fail to print the string, printing "(BigInt)" instead of a number.
29162916 /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory.
29172917 /// See `toString` and `toStringAlloc` for a way to print big integers without failure.
2918 pub fn formatNumber(self: Managed, w: *std.io.Writer, n: std.fmt.Number) std.io.Writer.Error!void {
2918 pub fn formatNumber(self: Managed, w: *std.Io.Writer, n: std.fmt.Number) std.Io.Writer.Error!void {
29192919 return self.toConst().formatNumber(w, n);
29202920 }
29212921
lib/std/os/uefi.zig+1-1
......@@ -106,7 +106,7 @@ pub const Guid = extern struct {
106106 node: [6]u8,
107107
108108 /// Format GUID into hexadecimal lowercase xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format
109 pub fn format(self: Guid, writer: *std.io.Writer) std.io.Writer.Error!void {
109 pub fn format(self: Guid, writer: *std.Io.Writer) std.Io.Writer.Error!void {
110110 const time_low = @byteSwap(self.time_low);
111111 const time_mid = @byteSwap(self.time_mid);
112112 const time_high_and_version = @byteSwap(self.time_high_and_version);
lib/std/os/uefi/protocol/file.zig-1
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const uefi = std.os.uefi;
3const io = std.io;
43const Guid = uefi.Guid;
54const Time = uefi.Time;
65const Status = uefi.Status;
lib/std/os/uefi/tables.zig+1-1
......@@ -90,7 +90,7 @@ pub const MemoryType = enum(u32) {
9090 return @truncate(as_int - vendor_start);
9191 }
9292
93 pub fn format(self: MemoryType, w: *std.io.Writer) std.io.Writer.Error!void {
93 pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void {
9494 if (self.toOem()) |oemval|
9595 try w.print("OEM({X})", .{oemval})
9696 else if (self.toVendor()) |vendorval|
lib/std/pdb.zig-1
......@@ -8,7 +8,6 @@
88//! documentation and/or contributors.
99
1010const std = @import("std.zig");
11const io = std.io;
1211const math = std.math;
1312const mem = std.mem;
1413const coff = std.coff;
lib/std/posix.zig+2-2
......@@ -671,8 +671,8 @@ fn getRandomBytesDevURandom(buf: []u8) !void {
671671 }
672672
673673 const file: fs.File = .{ .handle = fd };
674 const stream = file.deprecatedReader();
675 stream.readNoEof(buf) catch return error.Unexpected;
674 var file_reader = file.readerStreaming(&.{});
675 file_reader.readSliceAll(buf) catch return error.Unexpected;
676676}
677677
678678/// Causes abnormal process termination.
lib/std/posix/test.zig+4-7
......@@ -4,7 +4,6 @@ const testing = std.testing;
44const expect = testing.expect;
55const expectEqual = testing.expectEqual;
66const expectError = testing.expectError;
7const io = std.io;
87const fs = std.fs;
98const mem = std.mem;
109const elf = std.elf;
......@@ -706,12 +705,11 @@ test "mmap" {
706705 );
707706 defer posix.munmap(data);
708707
709 var mem_stream = io.fixedBufferStream(data);
710 const stream = mem_stream.reader();
708 var stream: std.Io.Reader = .fixed(data);
711709
712710 var i: u32 = 0;
713711 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
714 try testing.expectEqual(i, try stream.readInt(u32, .little));
712 try testing.expectEqual(i, try stream.takeInt(u32, .little));
715713 }
716714 }
717715
......@@ -730,12 +728,11 @@ test "mmap" {
730728 );
731729 defer posix.munmap(data);
732730
733 var mem_stream = io.fixedBufferStream(data);
734 const stream = mem_stream.reader();
731 var stream: std.Io.Reader = .fixed(data);
735732
736733 var i: u32 = alloc_size / 2 / @sizeOf(u32);
737734 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
738 try testing.expectEqual(i, try stream.readInt(u32, .little));
735 try testing.expectEqual(i, try stream.takeInt(u32, .little));
739736 }
740737 }
741738}
lib/std/process.zig+93-88
......@@ -1552,103 +1552,108 @@ pub fn getUserInfo(name: []const u8) !UserInfo {
15521552pub fn posixGetUserInfo(name: []const u8) !UserInfo {
15531553 const file = try std.fs.openFileAbsolute("/etc/passwd", .{});
15541554 defer file.close();
1555 var buffer: [4096]u8 = undefined;
1556 var file_reader = file.reader(&buffer);
1557 return posixGetUserInfoPasswdStream(name, &file_reader.interface) catch |err| switch (err) {
1558 error.ReadFailed => return file_reader.err.?,
1559 error.EndOfStream => return error.UserNotFound,
1560 error.CorruptPasswordFile => return error.CorruptPasswordFile,
1561 };
1562}
15551563
1556 const reader = file.deprecatedReader();
1557
1564fn posixGetUserInfoPasswdStream(name: []const u8, reader: *std.Io.Reader) !UserInfo {
15581565 const State = enum {
1559 Start,
1560 WaitForNextLine,
1561 SkipPassword,
1562 ReadUserId,
1563 ReadGroupId,
1566 start,
1567 wait_for_next_line,
1568 skip_password,
1569 read_user_id,
1570 read_group_id,
15641571 };
15651572
1566 var buf: [std.heap.page_size_min]u8 = undefined;
15671573 var name_index: usize = 0;
1568 var state = State.Start;
15691574 var uid: posix.uid_t = 0;
15701575 var gid: posix.gid_t = 0;
15711576
1572 while (true) {
1573 const amt_read = try reader.read(buf[0..]);
1574 for (buf[0..amt_read]) |byte| {
1575 switch (state) {
1576 .Start => switch (byte) {
1577 ':' => {
1578 state = if (name_index == name.len) State.SkipPassword else State.WaitForNextLine;
1579 },
1580 '\n' => return error.CorruptPasswordFile,
1581 else => {
1582 if (name_index == name.len or name[name_index] != byte) {
1583 state = .WaitForNextLine;
1584 }
1585 name_index += 1;
1586 },
1587 },
1588 .WaitForNextLine => switch (byte) {
1589 '\n' => {
1590 name_index = 0;
1591 state = .Start;
1592 },
1593 else => continue,
1594 },
1595 .SkipPassword => switch (byte) {
1596 '\n' => return error.CorruptPasswordFile,
1597 ':' => {
1598 state = .ReadUserId;
1599 },
1600 else => continue,
1601 },
1602 .ReadUserId => switch (byte) {
1603 ':' => {
1604 state = .ReadGroupId;
1605 },
1606 '\n' => return error.CorruptPasswordFile,
1607 else => {
1608 const digit = switch (byte) {
1609 '0'...'9' => byte - '0',
1610 else => return error.CorruptPasswordFile,
1611 };
1612 {
1613 const ov = @mulWithOverflow(uid, 10);
1614 if (ov[1] != 0) return error.CorruptPasswordFile;
1615 uid = ov[0];
1616 }
1617 {
1618 const ov = @addWithOverflow(uid, digit);
1619 if (ov[1] != 0) return error.CorruptPasswordFile;
1620 uid = ov[0];
1621 }
1622 },
1623 },
1624 .ReadGroupId => switch (byte) {
1625 '\n', ':' => {
1626 return UserInfo{
1627 .uid = uid,
1628 .gid = gid,
1629 };
1630 },
1631 else => {
1632 const digit = switch (byte) {
1633 '0'...'9' => byte - '0',
1634 else => return error.CorruptPasswordFile,
1635 };
1636 {
1637 const ov = @mulWithOverflow(gid, 10);
1638 if (ov[1] != 0) return error.CorruptPasswordFile;
1639 gid = ov[0];
1640 }
1641 {
1642 const ov = @addWithOverflow(gid, digit);
1643 if (ov[1] != 0) return error.CorruptPasswordFile;
1644 gid = ov[0];
1645 }
1646 },
1647 },
1648 }
1649 }
1650 if (amt_read < buf.len) return error.UserNotFound;
1577 sw: switch (State.start) {
1578 .start => switch (try reader.takeByte()) {
1579 ':' => {
1580 if (name_index == name.len) {
1581 continue :sw .skip_password;
1582 } else {
1583 continue :sw .wait_for_next_line;
1584 }
1585 },
1586 '\n' => return error.CorruptPasswordFile,
1587 else => |byte| {
1588 if (name_index == name.len or name[name_index] != byte) {
1589 continue :sw .wait_for_next_line;
1590 }
1591 name_index += 1;
1592 continue :sw .start;
1593 },
1594 },
1595 .wait_for_next_line => switch (try reader.takeByte()) {
1596 '\n' => {
1597 name_index = 0;
1598 continue :sw .start;
1599 },
1600 else => continue :sw .wait_for_next_line,
1601 },
1602 .skip_password => switch (try reader.takeByte()) {
1603 '\n' => return error.CorruptPasswordFile,
1604 ':' => {
1605 continue :sw .read_user_id;
1606 },
1607 else => continue :sw .skip_password,
1608 },
1609 .read_user_id => switch (try reader.takeByte()) {
1610 ':' => {
1611 continue :sw .read_group_id;
1612 },
1613 '\n' => return error.CorruptPasswordFile,
1614 else => |byte| {
1615 const digit = switch (byte) {
1616 '0'...'9' => byte - '0',
1617 else => return error.CorruptPasswordFile,
1618 };
1619 {
1620 const ov = @mulWithOverflow(uid, 10);
1621 if (ov[1] != 0) return error.CorruptPasswordFile;
1622 uid = ov[0];
1623 }
1624 {
1625 const ov = @addWithOverflow(uid, digit);
1626 if (ov[1] != 0) return error.CorruptPasswordFile;
1627 uid = ov[0];
1628 }
1629 continue :sw .read_user_id;
1630 },
1631 },
1632 .read_group_id => switch (try reader.takeByte()) {
1633 '\n', ':' => return .{
1634 .uid = uid,
1635 .gid = gid,
1636 },
1637 else => |byte| {
1638 const digit = switch (byte) {
1639 '0'...'9' => byte - '0',
1640 else => return error.CorruptPasswordFile,
1641 };
1642 {
1643 const ov = @mulWithOverflow(gid, 10);
1644 if (ov[1] != 0) return error.CorruptPasswordFile;
1645 gid = ov[0];
1646 }
1647 {
1648 const ov = @addWithOverflow(gid, digit);
1649 if (ov[1] != 0) return error.CorruptPasswordFile;
1650 gid = ov[0];
1651 }
1652 continue :sw .read_group_id;
1653 },
1654 },
16511655 }
1656 comptime unreachable;
16521657}
16531658
16541659pub fn getBaseAddress() usize {
lib/std/std.zig-2
......@@ -78,8 +78,6 @@ pub const hash = @import("hash.zig");
7878pub const hash_map = @import("hash_map.zig");
7979pub const heap = @import("heap.zig");
8080pub const http = @import("http.zig");
81/// Deprecated
82pub const io = Io;
8381pub const json = @import("json.zig");
8482pub const leb = @import("leb128.zig");
8583pub const log = @import("log.zig");
lib/std/tar/test.zig+5-5
......@@ -336,7 +336,7 @@ fn testCase(case: Case) !void {
336336 var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined;
337337 var link_name_buffer: [std.fs.max_path_bytes]u8 = undefined;
338338
339 var br: std.io.Reader = .fixed(case.data);
339 var br: std.Io.Reader = .fixed(case.data);
340340 var it: tar.Iterator = .init(&br, .{
341341 .file_name_buffer = &file_name_buffer,
342342 .link_name_buffer = &link_name_buffer,
......@@ -387,7 +387,7 @@ fn testLongNameCase(case: Case) !void {
387387 var min_file_name_buffer: [256]u8 = undefined;
388388 var min_link_name_buffer: [100]u8 = undefined;
389389
390 var br: std.io.Reader = .fixed(case.data);
390 var br: std.Io.Reader = .fixed(case.data);
391391 var iter: tar.Iterator = .init(&br, .{
392392 .file_name_buffer = &min_file_name_buffer,
393393 .link_name_buffer = &min_link_name_buffer,
......@@ -407,7 +407,7 @@ test "insufficient buffer in Header name filed" {
407407 var min_file_name_buffer: [9]u8 = undefined;
408408 var min_link_name_buffer: [100]u8 = undefined;
409409
410 var br: std.io.Reader = .fixed(gnu_case.data);
410 var br: std.Io.Reader = .fixed(gnu_case.data);
411411 var iter: tar.Iterator = .init(&br, .{
412412 .file_name_buffer = &min_file_name_buffer,
413413 .link_name_buffer = &min_link_name_buffer,
......@@ -462,7 +462,7 @@ test "should not overwrite existing file" {
462462 // This ensures that file is not overwritten.
463463 //
464464 const data = @embedFile("testdata/overwrite_file.tar");
465 var r: std.io.Reader = .fixed(data);
465 var r: std.Io.Reader = .fixed(data);
466466
467467 // Unpack with strip_components = 1 should fail
468468 var root = std.testing.tmpDir(.{});
......@@ -490,7 +490,7 @@ test "case sensitivity" {
490490 // 18089/alacritty/Darkermatrix.yml
491491 //
492492 const data = @embedFile("testdata/18089.tar");
493 var r: std.io.Reader = .fixed(data);
493 var r: std.Io.Reader = .fixed(data);
494494
495495 var root = std.testing.tmpDir(.{});
496496 defer root.cleanup();
lib/std/testing.zig+8-8
......@@ -358,7 +358,7 @@ test expectApproxEqRel {
358358/// This function is intended to be used only in tests. When the two slices are not
359359/// equal, prints diagnostics to stderr to show exactly how they are not equal (with
360360/// the differences highlighted in red), then returns a test failure error.
361/// The colorized output is optional and controlled by the return of `std.io.tty.detectConfig()`.
361/// The colorized output is optional and controlled by the return of `std.Io.tty.detectConfig()`.
362362/// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead.
363363pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void {
364364 const diff_index: usize = diff_index: {
......@@ -381,7 +381,7 @@ fn failEqualSlices(
381381 expected: []const T,
382382 actual: []const T,
383383 diff_index: usize,
384 w: *std.io.Writer,
384 w: *std.Io.Writer,
385385) !void {
386386 try w.print("slices differ. first difference occurs at index {d} (0x{X})\n", .{ diff_index, diff_index });
387387
......@@ -401,7 +401,7 @@ fn failEqualSlices(
401401 const actual_window = actual[window_start..@min(actual.len, window_start + max_window_size)];
402402 const actual_truncated = window_start + actual_window.len < actual.len;
403403
404 const ttyconf = std.io.tty.detectConfig(.stderr());
404 const ttyconf = std.Io.tty.detectConfig(.stderr());
405405 var differ = if (T == u8) BytesDiffer{
406406 .expected = expected_window,
407407 .actual = actual_window,
......@@ -467,11 +467,11 @@ fn SliceDiffer(comptime T: type) type {
467467 start_index: usize,
468468 expected: []const T,
469469 actual: []const T,
470 ttyconf: std.io.tty.Config,
470 ttyconf: std.Io.tty.Config,
471471
472472 const Self = @This();
473473
474 pub fn write(self: Self, writer: *std.io.Writer) !void {
474 pub fn write(self: Self, writer: *std.Io.Writer) !void {
475475 for (self.expected, 0..) |value, i| {
476476 const full_index = self.start_index + i;
477477 const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true;
......@@ -490,9 +490,9 @@ fn SliceDiffer(comptime T: type) type {
490490const BytesDiffer = struct {
491491 expected: []const u8,
492492 actual: []const u8,
493 ttyconf: std.io.tty.Config,
493 ttyconf: std.Io.tty.Config,
494494
495 pub fn write(self: BytesDiffer, writer: *std.io.Writer) !void {
495 pub fn write(self: BytesDiffer, writer: *std.Io.Writer) !void {
496496 var expected_iterator = std.mem.window(u8, self.expected, 16, 16);
497497 var row: usize = 0;
498498 while (expected_iterator.next()) |chunk| {
......@@ -538,7 +538,7 @@ const BytesDiffer = struct {
538538 }
539539 }
540540
541 fn writeDiff(self: BytesDiffer, writer: *std.io.Writer, comptime fmt: []const u8, args: anytype, diff: bool) !void {
541 fn writeDiff(self: BytesDiffer, writer: *std.Io.Writer, comptime fmt: []const u8, args: anytype, diff: bool) !void {
542542 if (diff) try self.ttyconf.setColor(writer, .red);
543543 try writer.print(fmt, args);
544544 if (diff) try self.ttyconf.setColor(writer, .reset);
lib/std/unicode.zig+2-2
......@@ -804,7 +804,7 @@ fn testDecode(bytes: []const u8) !u21 {
804804/// Ill-formed UTF-8 byte sequences are replaced by the replacement character (U+FFFD)
805805/// according to "U+FFFD Substitution of Maximal Subparts" from Chapter 3 of
806806/// the Unicode standard, and as specified by https://encoding.spec.whatwg.org/#utf-8-decoder
807fn formatUtf8(utf8: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
807fn formatUtf8(utf8: []const u8, writer: *std.Io.Writer) std.Io.Writer.Error!void {
808808 var buf: [300]u8 = undefined; // just an arbitrary size
809809 var u8len: usize = 0;
810810
......@@ -1464,7 +1464,7 @@ test calcWtf16LeLen {
14641464
14651465/// Print the given `utf16le` string, encoded as UTF-8 bytes.
14661466/// Unpaired surrogates are replaced by the replacement character (U+FFFD).
1467fn formatUtf16Le(utf16le: []const u16, writer: *std.io.Writer) std.io.Writer.Error!void {
1467fn formatUtf16Le(utf16le: []const u16, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14681468 var buf: [300]u8 = undefined; // just an arbitrary size
14691469 var it = Utf16LeIterator.init(utf16le);
14701470 var u8len: usize = 0;
lib/std/zig.zig+3-3
......@@ -51,9 +51,9 @@ pub const Color = enum {
5151 /// Assume stderr is a terminal.
5252 on,
5353
54 pub fn get_tty_conf(color: Color) std.io.tty.Config {
54 pub fn get_tty_conf(color: Color) std.Io.tty.Config {
5555 return switch (color) {
56 .auto => std.io.tty.detectConfig(std.fs.File.stderr()),
56 .auto => std.Io.tty.detectConfig(std.fs.File.stderr()),
5757 .on => .escape_codes,
5858 .off => .no_color,
5959 };
......@@ -322,7 +322,7 @@ pub const BuildId = union(enum) {
322322 try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx"));
323323 }
324324
325 pub fn format(id: BuildId, writer: *std.io.Writer) std.io.Writer.Error!void {
325 pub fn format(id: BuildId, writer: *std.Io.Writer) std.Io.Writer.Error!void {
326326 switch (id) {
327327 .none, .fast, .uuid, .sha1, .md5 => {
328328 try writer.writeAll(@tagName(id));
lib/std/zig/Ast.zig+1-1
......@@ -204,7 +204,7 @@ pub fn parse(gpa: Allocator, source: [:0]const u8, mode: Mode) Allocator.Error!A
204204/// `gpa` is used for allocating the resulting formatted source code.
205205/// Caller owns the returned slice of bytes, allocated with `gpa`.
206206pub fn renderAlloc(tree: Ast, gpa: Allocator) error{OutOfMemory}![]u8 {
207 var aw: std.io.Writer.Allocating = .init(gpa);
207 var aw: std.Io.Writer.Allocating = .init(gpa);
208208 defer aw.deinit();
209209 render(tree, gpa, &aw.writer, .{}) catch |err| switch (err) {
210210 error.WriteFailed, error.OutOfMemory => return error.OutOfMemory,
lib/std/zig/Ast/Render.zig+2-2
......@@ -6,7 +6,7 @@ const meta = std.meta;
66const Ast = std.zig.Ast;
77const Token = std.zig.Token;
88const primitives = std.zig.primitives;
9const Writer = std.io.Writer;
9const Writer = std.Io.Writer;
1010
1111const Render = @This();
1212
......@@ -2169,7 +2169,7 @@ fn renderArrayInit(
21692169
21702170 const section_exprs = row_exprs[0..section_end];
21712171
2172 var sub_expr_buffer: std.io.Writer.Allocating = .init(gpa);
2172 var sub_expr_buffer: Writer.Allocating = .init(gpa);
21732173 defer sub_expr_buffer.deinit();
21742174
21752175 const sub_expr_buffer_starts = try gpa.alloc(usize, section_exprs.len + 1);
lib/std/zig/AstGen.zig+2-2
......@@ -11339,7 +11339,7 @@ fn parseStrLit(
1133911339) InnerError!void {
1134011340 const raw_string = bytes[offset..];
1134111341 const result = r: {
11342 var aw: std.io.Writer.Allocating = .fromArrayList(astgen.gpa, buf);
11342 var aw: std.Io.Writer.Allocating = .fromArrayList(astgen.gpa, buf);
1134311343 defer buf.* = aw.toArrayList();
1134411344 break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) {
1134511345 error.WriteFailed => return error.OutOfMemory,
......@@ -13785,7 +13785,7 @@ fn lowerAstErrors(astgen: *AstGen) error{OutOfMemory}!void {
1378513785 const tree = astgen.tree;
1378613786 assert(tree.errors.len > 0);
1378713787
13788 var msg: std.io.Writer.Allocating = .init(gpa);
13788 var msg: std.Io.Writer.Allocating = .init(gpa);
1378913789 defer msg.deinit();
1379013790 const msg_w = &msg.writer;
1379113791
lib/std/zig/ErrorBundle.zig+7-7
......@@ -11,7 +11,7 @@ const std = @import("std");
1111const ErrorBundle = @This();
1212const Allocator = std.mem.Allocator;
1313const assert = std.debug.assert;
14const Writer = std.io.Writer;
14const Writer = std.Io.Writer;
1515
1616string_bytes: []const u8,
1717/// The first thing in this array is an `ErrorMessageList`.
......@@ -156,7 +156,7 @@ pub fn nullTerminatedString(eb: ErrorBundle, index: String) [:0]const u8 {
156156}
157157
158158pub const RenderOptions = struct {
159 ttyconf: std.io.tty.Config,
159 ttyconf: std.Io.tty.Config,
160160 include_reference_trace: bool = true,
161161 include_source_line: bool = true,
162162 include_log_text: bool = true,
......@@ -190,14 +190,14 @@ fn renderErrorMessageToWriter(
190190 err_msg_index: MessageIndex,
191191 w: *Writer,
192192 kind: []const u8,
193 color: std.io.tty.Color,
193 color: std.Io.tty.Color,
194194 indent: usize,
195195) (Writer.Error || std.posix.UnexpectedError)!void {
196196 const ttyconf = options.ttyconf;
197197 const err_msg = eb.getErrorMessage(err_msg_index);
198198 if (err_msg.src_loc != .none) {
199199 const src = eb.extraData(SourceLocation, @intFromEnum(err_msg.src_loc));
200 var prefix: std.io.Writer.Discarding = .init(&.{});
200 var prefix: Writer.Discarding = .init(&.{});
201201 try w.splatByteAll(' ', indent);
202202 prefix.count += indent;
203203 try ttyconf.setColor(w, .bold);
......@@ -794,9 +794,9 @@ pub const Wip = struct {
794794 };
795795 defer bundle.deinit(std.testing.allocator);
796796
797 const ttyconf: std.io.tty.Config = .no_color;
797 const ttyconf: std.Io.tty.Config = .no_color;
798798
799 var bundle_buf: std.io.Writer.Allocating = .init(std.testing.allocator);
799 var bundle_buf: Writer.Allocating = .init(std.testing.allocator);
800800 const bundle_bw = &bundle_buf.interface;
801801 defer bundle_buf.deinit();
802802 try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_bw);
......@@ -812,7 +812,7 @@ pub const Wip = struct {
812812 };
813813 defer copy.deinit(std.testing.allocator);
814814
815 var copy_buf: std.io.Writer.Allocating = .init(std.testing.allocator);
815 var copy_buf: Writer.Allocating = .init(std.testing.allocator);
816816 const copy_bw = &copy_buf.interface;
817817 defer copy_buf.deinit();
818818 try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_bw);
lib/std/zig/ZonGen.zig+4-4
......@@ -9,7 +9,7 @@ const StringIndexContext = std.hash_map.StringIndexContext;
99const ZonGen = @This();
1010const Zoir = @import("Zoir.zig");
1111const Ast = @import("Ast.zig");
12const Writer = std.io.Writer;
12const Writer = std.Io.Writer;
1313
1414gpa: Allocator,
1515tree: Ast,
......@@ -472,7 +472,7 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory,
472472 const raw_string = zg.tree.tokenSlice(ident_token)[offset..];
473473 try zg.string_bytes.ensureUnusedCapacity(gpa, raw_string.len);
474474 const result = r: {
475 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, &zg.string_bytes);
475 var aw: Writer.Allocating = .fromArrayList(gpa, &zg.string_bytes);
476476 defer zg.string_bytes = aw.toArrayList();
477477 break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) {
478478 error.WriteFailed => return error.OutOfMemory,
......@@ -570,7 +570,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad
570570 const size_hint = strLitSizeHint(zg.tree, str_node);
571571 try string_bytes.ensureUnusedCapacity(gpa, size_hint);
572572 const result = r: {
573 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, &zg.string_bytes);
573 var aw: Writer.Allocating = .fromArrayList(gpa, &zg.string_bytes);
574574 defer zg.string_bytes = aw.toArrayList();
575575 break :r parseStrLit(zg.tree, str_node, &aw.writer) catch |err| switch (err) {
576576 error.WriteFailed => return error.OutOfMemory,
......@@ -885,7 +885,7 @@ fn lowerAstErrors(zg: *ZonGen) Allocator.Error!void {
885885 const tree = zg.tree;
886886 assert(tree.errors.len > 0);
887887
888 var msg: std.io.Writer.Allocating = .init(gpa);
888 var msg: Writer.Allocating = .init(gpa);
889889 defer msg.deinit();
890890 const msg_bw = &msg.writer;
891891
lib/std/zig/llvm/Builder.zig+1-1
......@@ -7,7 +7,7 @@ const builtin = @import("builtin");
77const DW = std.dwarf;
88const ir = @import("ir.zig");
99const log = std.log.scoped(.llvm);
10const Writer = std.io.Writer;
10const Writer = std.Io.Writer;
1111
1212gpa: Allocator,
1313strip: bool,
lib/std/zig/parser_test.zig-1
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const mem = std.mem;
33const print = std.debug.print;
4const io = std.io;
54const maxInt = std.math.maxInt;
65
76test "zig fmt: remove extra whitespace at start and end of file with comment between" {
lib/std/zig/string_literal.zig+3-3
......@@ -1,7 +1,7 @@
11const std = @import("../std.zig");
22const assert = std.debug.assert;
33const utf8Encode = std.unicode.utf8Encode;
4const Writer = std.io.Writer;
4const Writer = std.Io.Writer;
55
66pub const ParseError = error{
77 OutOfMemory,
......@@ -45,7 +45,7 @@ pub const Error = union(enum) {
4545 raw_string: []const u8,
4646 };
4747
48 fn formatMessage(self: FormatMessage, writer: *std.io.Writer) std.io.Writer.Error!void {
48 fn formatMessage(self: FormatMessage, writer: *Writer) Writer.Error!void {
4949 switch (self.err) {
5050 .invalid_escape_character => |bad_index| try writer.print(
5151 "invalid escape character: '{c}'",
......@@ -358,7 +358,7 @@ pub fn parseWrite(writer: *Writer, bytes: []const u8) Writer.Error!Result {
358358/// Higher level API. Does not return extra info about parse errors.
359359/// Caller owns returned memory.
360360pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]u8 {
361 var aw: std.io.Writer.Allocating = .init(allocator);
361 var aw: Writer.Allocating = .init(allocator);
362362 defer aw.deinit();
363363 const result = parseWrite(&aw.writer, bytes) catch |err| switch (err) {
364364 error.WriteFailed => return error.OutOfMemory,
lib/std/zip.zig+2-2
......@@ -195,12 +195,12 @@ pub const Decompress = struct {
195195 };
196196 }
197197
198 fn streamStore(r: *Reader, w: *Writer, limit: std.io.Limit) Reader.StreamError!usize {
198 fn streamStore(r: *Reader, w: *Writer, limit: std.Io.Limit) Reader.StreamError!usize {
199199 const d: *Decompress = @fieldParentPtr("interface", r);
200200 return d.store.read(w, limit);
201201 }
202202
203 fn streamDeflate(r: *Reader, w: *Writer, limit: std.io.Limit) Reader.StreamError!usize {
203 fn streamDeflate(r: *Reader, w: *Writer, limit: std.Io.Limit) Reader.StreamError!usize {
204204 const d: *Decompress = @fieldParentPtr("interface", r);
205205 return flate.Decompress.read(&d.inflate, w, limit);
206206 }
lib/ubsan_rt.zig+1-1
......@@ -119,7 +119,7 @@ const Value = extern struct {
119119 }
120120 }
121121
122 pub fn format(value: Value, writer: *std.io.Writer) std.io.Writer.Error!void {
122 pub fn format(value: Value, writer: *std.Io.Writer) std.Io.Writer.Error!void {
123123 // Work around x86_64 backend limitation.
124124 if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) {
125125 try writer.writeAll("(unknown)");
src/Air.zig+1-1
......@@ -961,7 +961,7 @@ pub const Inst = struct {
961961 return index.unwrap().target;
962962 }
963963
964 pub fn format(index: Index, w: *std.io.Writer) std.io.Writer.Error!void {
964 pub fn format(index: Index, w: *std.Io.Writer) std.Io.Writer.Error!void {
965965 try w.writeByte('%');
966966 switch (index.unwrap()) {
967967 .ref => {},
src/Air/Liveness.zig+3-2
......@@ -10,6 +10,7 @@ const log = std.log.scoped(.liveness);
1010const assert = std.debug.assert;
1111const Allocator = std.mem.Allocator;
1212const Log2Int = std.math.Log2Int;
13const Writer = std.Io.Writer;
1314
1415const Liveness = @This();
1516const trace = @import("../tracy.zig").trace;
......@@ -2037,7 +2038,7 @@ fn fmtInstSet(set: *const std.AutoHashMapUnmanaged(Air.Inst.Index, void)) FmtIns
20372038const FmtInstSet = struct {
20382039 set: *const std.AutoHashMapUnmanaged(Air.Inst.Index, void),
20392040
2040 pub fn format(val: FmtInstSet, w: *std.io.Writer) std.io.Writer.Error!void {
2041 pub fn format(val: FmtInstSet, w: *Writer) Writer.Error!void {
20412042 if (val.set.count() == 0) {
20422043 try w.writeAll("[no instructions]");
20432044 return;
......@@ -2057,7 +2058,7 @@ fn fmtInstList(list: []const Air.Inst.Index) FmtInstList {
20572058const FmtInstList = struct {
20582059 list: []const Air.Inst.Index,
20592060
2060 pub fn format(val: FmtInstList, w: *std.io.Writer) std.io.Writer.Error!void {
2061 pub fn format(val: FmtInstList, w: *Writer) Writer.Error!void {
20612062 if (val.list.len == 0) {
20622063 try w.writeAll("[no instructions]");
20632064 return;
src/Air/print.zig+48-48
......@@ -9,7 +9,7 @@ const Type = @import("../Type.zig");
99const Air = @import("../Air.zig");
1010const InternPool = @import("../InternPool.zig");
1111
12pub fn write(air: Air, stream: *std.io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
12pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
1313 comptime assert(build_options.enable_debug_extensions);
1414 const instruction_bytes = air.instructions.len *
1515 // Here we don't use @sizeOf(Air.Inst.Data) because it would include
......@@ -55,7 +55,7 @@ pub fn write(air: Air, stream: *std.io.Writer, pt: Zcu.PerThread, liveness: ?Air
5555
5656pub fn writeInst(
5757 air: Air,
58 stream: *std.io.Writer,
58 stream: *std.Io.Writer,
5959 inst: Air.Inst.Index,
6060 pt: Zcu.PerThread,
6161 liveness: ?Air.Liveness,
......@@ -92,16 +92,16 @@ const Writer = struct {
9292 indent: usize,
9393 skip_body: bool,
9494
95 const Error = std.io.Writer.Error;
95 const Error = std.Io.Writer.Error;
9696
97 fn writeBody(w: *Writer, s: *std.io.Writer, body: []const Air.Inst.Index) Error!void {
97 fn writeBody(w: *Writer, s: *std.Io.Writer, body: []const Air.Inst.Index) Error!void {
9898 for (body) |inst| {
9999 try w.writeInst(s, inst);
100100 try s.writeByte('\n');
101101 }
102102 }
103103
104 fn writeInst(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
104 fn writeInst(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
105105 const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)];
106106 try s.splatByteAll(' ', w.indent);
107107 try s.print("{f}{c}= {s}(", .{
......@@ -341,48 +341,48 @@ const Writer = struct {
341341 try s.writeByte(')');
342342 }
343343
344 fn writeBinOp(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
344 fn writeBinOp(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
345345 const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
346346 try w.writeOperand(s, inst, 0, bin_op.lhs);
347347 try s.writeAll(", ");
348348 try w.writeOperand(s, inst, 1, bin_op.rhs);
349349 }
350350
351 fn writeUnOp(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
351 fn writeUnOp(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
352352 const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
353353 try w.writeOperand(s, inst, 0, un_op);
354354 }
355355
356 fn writeNoOp(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
356 fn writeNoOp(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
357357 _ = w;
358358 _ = s;
359359 _ = inst;
360360 // no-op, no argument to write
361361 }
362362
363 fn writeType(w: *Writer, s: *std.io.Writer, ty: Type) !void {
363 fn writeType(w: *Writer, s: *std.Io.Writer, ty: Type) !void {
364364 return ty.print(s, w.pt);
365365 }
366366
367 fn writeTy(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
367 fn writeTy(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
368368 const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty;
369369 try w.writeType(s, ty);
370370 }
371371
372 fn writeArg(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
372 fn writeArg(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
373373 const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg;
374374 try w.writeType(s, arg.ty.toType());
375375 try s.print(", {d}", .{arg.zir_param_index});
376376 }
377377
378 fn writeTyOp(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
378 fn writeTyOp(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
379379 const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
380380 try w.writeType(s, ty_op.ty.toType());
381381 try s.writeAll(", ");
382382 try w.writeOperand(s, inst, 0, ty_op.operand);
383383 }
384384
385 fn writeBlock(w: *Writer, s: *std.io.Writer, tag: Air.Inst.Tag, inst: Air.Inst.Index) Error!void {
385 fn writeBlock(w: *Writer, s: *std.Io.Writer, tag: Air.Inst.Tag, inst: Air.Inst.Index) Error!void {
386386 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
387387 try w.writeType(s, ty_pl.ty.toType());
388388 const body: []const Air.Inst.Index = @ptrCast(switch (tag) {
......@@ -423,7 +423,7 @@ const Writer = struct {
423423 }
424424 }
425425
426 fn writeLoop(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
426 fn writeLoop(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
427427 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
428428 const extra = w.air.extraData(Air.Block, ty_pl.payload);
429429 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
......@@ -439,7 +439,7 @@ const Writer = struct {
439439 try s.writeAll("}");
440440 }
441441
442 fn writeAggregateInit(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
442 fn writeAggregateInit(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
443443 const zcu = w.pt.zcu;
444444 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
445445 const vector_ty = ty_pl.ty.toType();
......@@ -455,7 +455,7 @@ const Writer = struct {
455455 try s.writeAll("]");
456456 }
457457
458 fn writeUnionInit(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
458 fn writeUnionInit(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
459459 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
460460 const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data;
461461
......@@ -463,7 +463,7 @@ const Writer = struct {
463463 try w.writeOperand(s, inst, 0, extra.init);
464464 }
465465
466 fn writeStructField(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
466 fn writeStructField(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
467467 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
468468 const extra = w.air.extraData(Air.StructField, ty_pl.payload).data;
469469
......@@ -471,7 +471,7 @@ const Writer = struct {
471471 try s.print(", {d}", .{extra.field_index});
472472 }
473473
474 fn writeTyPlBin(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
474 fn writeTyPlBin(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
475475 const data = w.air.instructions.items(.data);
476476 const ty_pl = data[@intFromEnum(inst)].ty_pl;
477477 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -484,7 +484,7 @@ const Writer = struct {
484484 try w.writeOperand(s, inst, 1, extra.rhs);
485485 }
486486
487 fn writeCmpxchg(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
487 fn writeCmpxchg(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
488488 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
489489 const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
490490
......@@ -498,7 +498,7 @@ const Writer = struct {
498498 });
499499 }
500500
501 fn writeMulAdd(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
501 fn writeMulAdd(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
502502 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
503503 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
504504
......@@ -509,7 +509,7 @@ const Writer = struct {
509509 try w.writeOperand(s, inst, 2, pl_op.operand);
510510 }
511511
512 fn writeShuffleOne(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
512 fn writeShuffleOne(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
513513 const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst);
514514 try w.writeType(s, unwrapped.result_ty);
515515 try s.writeAll(", ");
......@@ -525,7 +525,7 @@ const Writer = struct {
525525 try s.writeByte(']');
526526 }
527527
528 fn writeShuffleTwo(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
528 fn writeShuffleTwo(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
529529 const unwrapped = w.air.unwrapShuffleTwo(w.pt.zcu, inst);
530530 try w.writeType(s, unwrapped.result_ty);
531531 try s.writeAll(", ");
......@@ -544,7 +544,7 @@ const Writer = struct {
544544 try s.writeByte(']');
545545 }
546546
547 fn writeSelect(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
547 fn writeSelect(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
548548 const zcu = w.pt.zcu;
549549 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
550550 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
......@@ -559,14 +559,14 @@ const Writer = struct {
559559 try w.writeOperand(s, inst, 2, extra.rhs);
560560 }
561561
562 fn writeReduce(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
562 fn writeReduce(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
563563 const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
564564
565565 try w.writeOperand(s, inst, 0, reduce.operand);
566566 try s.print(", {s}", .{@tagName(reduce.operation)});
567567 }
568568
569 fn writeCmpVector(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
569 fn writeCmpVector(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
570570 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
571571 const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data;
572572
......@@ -576,7 +576,7 @@ const Writer = struct {
576576 try w.writeOperand(s, inst, 1, extra.rhs);
577577 }
578578
579 fn writeVectorStoreElem(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
579 fn writeVectorStoreElem(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
580580 const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
581581 const extra = w.air.extraData(Air.VectorCmp, data.payload).data;
582582
......@@ -587,21 +587,21 @@ const Writer = struct {
587587 try w.writeOperand(s, inst, 2, extra.rhs);
588588 }
589589
590 fn writeRuntimeNavPtr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
590 fn writeRuntimeNavPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
591591 const ip = &w.pt.zcu.intern_pool;
592592 const ty_nav = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav;
593593 try w.writeType(s, .fromInterned(ty_nav.ty));
594594 try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});
595595 }
596596
597 fn writeAtomicLoad(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
597 fn writeAtomicLoad(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
598598 const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
599599
600600 try w.writeOperand(s, inst, 0, atomic_load.ptr);
601601 try s.print(", {s}", .{@tagName(atomic_load.order)});
602602 }
603603
604 fn writePrefetch(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
604 fn writePrefetch(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
605605 const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch;
606606
607607 try w.writeOperand(s, inst, 0, prefetch.ptr);
......@@ -612,7 +612,7 @@ const Writer = struct {
612612
613613 fn writeAtomicStore(
614614 w: *Writer,
615 s: *std.io.Writer,
615 s: *std.Io.Writer,
616616 inst: Air.Inst.Index,
617617 order: std.builtin.AtomicOrder,
618618 ) Error!void {
......@@ -623,7 +623,7 @@ const Writer = struct {
623623 try s.print(", {s}", .{@tagName(order)});
624624 }
625625
626 fn writeAtomicRmw(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
626 fn writeAtomicRmw(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
627627 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
628628 const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data;
629629
......@@ -633,7 +633,7 @@ const Writer = struct {
633633 try s.print(", {s}, {s}", .{ @tagName(extra.op()), @tagName(extra.ordering()) });
634634 }
635635
636 fn writeFieldParentPtr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
636 fn writeFieldParentPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
637637 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
638638 const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
639639
......@@ -641,7 +641,7 @@ const Writer = struct {
641641 try s.print(", {d}", .{extra.field_index});
642642 }
643643
644 fn writeAssembly(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
644 fn writeAssembly(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
645645 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
646646 const extra = w.air.extraData(Air.Asm, ty_pl.payload);
647647 const is_volatile = extra.data.flags.is_volatile;
......@@ -730,19 +730,19 @@ const Writer = struct {
730730 try s.print(", \"{f}\"", .{std.zig.fmtString(asm_source)});
731731 }
732732
733 fn writeDbgStmt(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
733 fn writeDbgStmt(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
734734 const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
735735 try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 });
736736 }
737737
738 fn writeDbgVar(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
738 fn writeDbgVar(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
739739 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
740740 try w.writeOperand(s, inst, 0, pl_op.operand);
741741 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
742742 try s.print(", \"{f}\"", .{std.zig.fmtString(name.toSlice(w.air))});
743743 }
744744
745 fn writeCall(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
745 fn writeCall(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
746746 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
747747 const extra = w.air.extraData(Air.Call, pl_op.payload);
748748 const args = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra.items[extra.end..][0..extra.data.args_len]));
......@@ -755,19 +755,19 @@ const Writer = struct {
755755 try s.writeAll("]");
756756 }
757757
758 fn writeBr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
758 fn writeBr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
759759 const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br;
760760 try w.writeInstIndex(s, br.block_inst, false);
761761 try s.writeAll(", ");
762762 try w.writeOperand(s, inst, 0, br.operand);
763763 }
764764
765 fn writeRepeat(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
765 fn writeRepeat(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
766766 const repeat = w.air.instructions.items(.data)[@intFromEnum(inst)].repeat;
767767 try w.writeInstIndex(s, repeat.loop_inst, false);
768768 }
769769
770 fn writeTry(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
770 fn writeTry(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
771771 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
772772 const extra = w.air.extraData(Air.Try, pl_op.payload);
773773 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
......@@ -801,7 +801,7 @@ const Writer = struct {
801801 }
802802 }
803803
804 fn writeTryPtr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
804 fn writeTryPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
805805 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
806806 const extra = w.air.extraData(Air.TryPtr, ty_pl.payload);
807807 const body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.body_len]);
......@@ -838,7 +838,7 @@ const Writer = struct {
838838 }
839839 }
840840
841 fn writeCondBr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
841 fn writeCondBr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
842842 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
843843 const extra = w.air.extraData(Air.CondBr, pl_op.payload);
844844 const then_body: []const Air.Inst.Index = @ptrCast(w.air.extra.items[extra.end..][0..extra.data.then_body_len]);
......@@ -897,7 +897,7 @@ const Writer = struct {
897897 try s.writeAll("}");
898898 }
899899
900 fn writeSwitchBr(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
900 fn writeSwitchBr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
901901 const switch_br = w.air.unwrapSwitch(inst);
902902
903903 const liveness: Air.Liveness.SwitchBrTable = if (w.liveness) |liveness|
......@@ -983,25 +983,25 @@ const Writer = struct {
983983 try s.splatByteAll(' ', old_indent);
984984 }
985985
986 fn writeWasmMemorySize(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
986 fn writeWasmMemorySize(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
987987 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
988988 try s.print("{d}", .{pl_op.payload});
989989 }
990990
991 fn writeWasmMemoryGrow(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
991 fn writeWasmMemoryGrow(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
992992 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
993993 try s.print("{d}, ", .{pl_op.payload});
994994 try w.writeOperand(s, inst, 0, pl_op.operand);
995995 }
996996
997 fn writeWorkDimension(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
997 fn writeWorkDimension(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
998998 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
999999 try s.print("{d}", .{pl_op.payload});
10001000 }
10011001
10021002 fn writeOperand(
10031003 w: *Writer,
1004 s: *std.io.Writer,
1004 s: *std.Io.Writer,
10051005 inst: Air.Inst.Index,
10061006 op_index: usize,
10071007 operand: Air.Inst.Ref,
......@@ -1027,7 +1027,7 @@ const Writer = struct {
10271027
10281028 fn writeInstRef(
10291029 w: *Writer,
1030 s: *std.io.Writer,
1030 s: *std.Io.Writer,
10311031 operand: Air.Inst.Ref,
10321032 dies: bool,
10331033 ) Error!void {
......@@ -1047,7 +1047,7 @@ const Writer = struct {
10471047
10481048 fn writeInstIndex(
10491049 w: *Writer,
1050 s: *std.io.Writer,
1050 s: *std.Io.Writer,
10511051 inst: Air.Inst.Index,
10521052 dies: bool,
10531053 ) Error!void {
src/Compilation.zig+4-4
......@@ -12,7 +12,7 @@ const ThreadPool = std.Thread.Pool;
1212const WaitGroup = std.Thread.WaitGroup;
1313const ErrorBundle = std.zig.ErrorBundle;
1414const fatal = std.process.fatal;
15const Writer = std.io.Writer;
15const Writer = std.Io.Writer;
1616
1717const Value = @import("Value.zig");
1818const Type = @import("Type.zig");
......@@ -468,7 +468,7 @@ pub const Path = struct {
468468 const Formatter = struct {
469469 p: Path,
470470 comp: *Compilation,
471 pub fn format(f: Formatter, w: *std.io.Writer) std.io.Writer.Error!void {
471 pub fn format(f: Formatter, w: *Writer) Writer.Error!void {
472472 const root_path: []const u8 = switch (f.p.root) {
473473 .zig_lib => f.comp.dirs.zig_lib.path orelse ".",
474474 .global_cache => f.comp.dirs.global_cache.path orelse ".",
......@@ -1883,7 +1883,7 @@ pub const CreateDiagnostic = union(enum) {
18831883 sub: []const u8,
18841884 err: (fs.Dir.MakeError || fs.Dir.OpenError || fs.Dir.StatFileError),
18851885 };
1886 pub fn format(diag: CreateDiagnostic, w: *std.Io.Writer) std.Io.Writer.Error!void {
1886 pub fn format(diag: CreateDiagnostic, w: *Writer) Writer.Error!void {
18871887 switch (diag) {
18881888 .export_table_import_table_conflict => try w.writeAll("'--import-table' and '--export-table' cannot be used together"),
18891889 .emit_h_without_zcu => try w.writeAll("cannot emit C header with no Zig source files"),
......@@ -6457,7 +6457,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
64576457
64586458 // In .rc files, a " within a quoted string is escaped as ""
64596459 const fmtRcEscape = struct {
6460 fn formatRcEscape(bytes: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void {
6460 fn formatRcEscape(bytes: []const u8, writer: *Writer) Writer.Error!void {
64616461 for (bytes) |byte| switch (byte) {
64626462 '"' => try writer.writeAll("\"\""),
64636463 '\\' => try writer.writeAll("\\\\"),
src/InternPool.zig+15-15
......@@ -1,6 +1,20 @@
11//! All interned objects have both a value and a type.
22//! This data structure is self-contained.
33
4const builtin = @import("builtin");
5const std = @import("std");
6const Allocator = std.mem.Allocator;
7const assert = std.debug.assert;
8const BigIntConst = std.math.big.int.Const;
9const BigIntMutable = std.math.big.int.Mutable;
10const Cache = std.Build.Cache;
11const Limb = std.math.big.Limb;
12const Hash = std.hash.Wyhash;
13
14const InternPool = @This();
15const Zcu = @import("Zcu.zig");
16const Zir = std.zig.Zir;
17
418/// One item per thread, indexed by `tid`, which is dense and unique per thread.
519locals: []Local,
620/// Length must be a power of two and represents the number of simultaneous
......@@ -1606,20 +1620,6 @@ fn getIndexMask(ip: *const InternPool, comptime BackingInt: type) u32 {
16061620
16071621const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), false);
16081622
1609const builtin = @import("builtin");
1610const std = @import("std");
1611const Allocator = std.mem.Allocator;
1612const assert = std.debug.assert;
1613const BigIntConst = std.math.big.int.Const;
1614const BigIntMutable = std.math.big.int.Mutable;
1615const Cache = std.Build.Cache;
1616const Limb = std.math.big.Limb;
1617const Hash = std.hash.Wyhash;
1618
1619const InternPool = @This();
1620const Zcu = @import("Zcu.zig");
1621const Zir = std.zig.Zir;
1622
16231623/// An index into `maps` which might be `none`.
16241624pub const OptionalMapIndex = enum(u32) {
16251625 none = std.math.maxInt(u32),
......@@ -1895,7 +1895,7 @@ pub const NullTerminatedString = enum(u32) {
18951895 ip: *const InternPool,
18961896 id: bool,
18971897 };
1898 fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
1898 fn format(data: FormatData, writer: *std.Io.Writer) std.Io.Writer.Error!void {
18991899 const slice = data.string.toSlice(data.ip);
19001900 if (!data.id) {
19011901 try writer.writeAll(slice);
src/Package/Fetch.zig+2-2
......@@ -2020,7 +2020,7 @@ const UnpackResult = struct {
20202020 // output errors to string
20212021 var errors = try fetch.error_bundle.toOwnedBundle("");
20222022 defer errors.deinit(gpa);
2023 var aw: std.io.Writer.Allocating = .init(gpa);
2023 var aw: std.Io.Writer.Allocating = .init(gpa);
20242024 defer aw.deinit();
20252025 try errors.renderToWriter(.{ .ttyconf = .no_color }, &aw.writer);
20262026 try std.testing.expectEqualStrings(
......@@ -2329,7 +2329,7 @@ const TestFetchBuilder = struct {
23292329 if (notes_len > 0) {
23302330 try std.testing.expectEqual(notes_len, em.notes_len);
23312331 }
2332 var aw: std.io.Writer.Allocating = .init(std.testing.allocator);
2332 var aw: std.Io.Writer.Allocating = .init(std.testing.allocator);
23332333 defer aw.deinit();
23342334 try errors.renderToWriter(.{ .ttyconf = .no_color }, &aw.writer);
23352335 try std.testing.expectEqualStrings(msg, aw.written());
src/Package/Fetch/git.zig+1-1
......@@ -146,7 +146,7 @@ pub const Oid = union(Format) {
146146 } else error.InvalidOid;
147147 }
148148
149 pub fn format(oid: Oid, writer: *std.io.Writer) std.io.Writer.Error!void {
149 pub fn format(oid: Oid, writer: *std.Io.Writer) std.Io.Writer.Error!void {
150150 try writer.print("{x}", .{oid.slice()});
151151 }
152152
src/Package/Manifest.zig+1-1
......@@ -472,7 +472,7 @@ const Parse = struct {
472472 ) InnerError!void {
473473 const raw_string = bytes[offset..];
474474 const result = r: {
475 var aw: std.io.Writer.Allocating = .fromArrayList(p.gpa, buf);
475 var aw: std.Io.Writer.Allocating = .fromArrayList(p.gpa, buf);
476476 defer buf.* = aw.toArrayList();
477477 break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) {
478478 error.WriteFailed => return error.OutOfMemory,
src/Sema.zig+5-5
......@@ -3080,7 +3080,7 @@ pub fn createTypeName(
30803080 const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip) orelse return error.AnalysisFail);
30813081 const zir_tags = sema.code.instructions.items(.tag);
30823082
3083 var aw: std.io.Writer.Allocating = .init(gpa);
3083 var aw: std.Io.Writer.Allocating = .init(gpa);
30843084 defer aw.deinit();
30853085 const w = &aw.writer;
30863086 w.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory;
......@@ -5508,7 +5508,7 @@ fn zirCompileLog(
55085508 const zcu = pt.zcu;
55095509 const gpa = zcu.gpa;
55105510
5511 var aw: std.io.Writer.Allocating = .init(gpa);
5511 var aw: std.Io.Writer.Allocating = .init(gpa);
55125512 defer aw.deinit();
55135513 const writer = &aw.writer;
55145514
......@@ -9080,7 +9080,7 @@ fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool {
90809080fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void {
90819081 const CallingConventionsSupportingVarArgsList = struct {
90829082 arch: std.Target.Cpu.Arch,
9083 pub fn format(ctx: @This(), w: *std.io.Writer) std.io.Writer.Error!void {
9083 pub fn format(ctx: @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
90849084 var first = true;
90859085 for (calling_conventions_supporting_var_args) |cc_inner| {
90869086 for (std.Target.Cpu.Arch.fromCallingConvention(cc_inner)) |supported_arch| {
......@@ -9521,7 +9521,7 @@ fn finishFunc(
95219521 .bad_arch => |allowed_archs| {
95229522 const ArchListFormatter = struct {
95239523 archs: []const std.Target.Cpu.Arch,
9524 pub fn format(formatter: @This(), w: *std.io.Writer) std.io.Writer.Error!void {
9524 pub fn format(formatter: @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
95259525 for (formatter.archs, 0..) |arch, i| {
95269526 if (i != 0)
95279527 try w.writeAll(", ");
......@@ -36962,7 +36962,7 @@ fn notePathToComptimeAllocPtr(
3696236962 error.AnalysisFail => unreachable,
3696336963 };
3696436964
36965 var second_path_aw: std.io.Writer.Allocating = .init(arena);
36965 var second_path_aw: std.Io.Writer.Allocating = .init(arena);
3696636966 defer second_path_aw.deinit();
3696736967 const inter_name = try std.fmt.allocPrint(arena, "v{d}", .{intermediate_value_count});
3696836968 const deriv_start = @import("print_value.zig").printPtrDerivation(
src/Type.zig+4-4
......@@ -121,7 +121,7 @@ pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
121121 return a.toIntern() == b.toIntern();
122122}
123123
124pub fn format(ty: Type, writer: *std.io.Writer) !void {
124pub fn format(ty: Type, writer: *std.Io.Writer) !void {
125125 _ = ty;
126126 _ = writer;
127127 @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
......@@ -140,7 +140,7 @@ const Format = struct {
140140 ty: Type,
141141 pt: Zcu.PerThread,
142142
143 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
143 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
144144 return print(f.ty, writer, f.pt);
145145 }
146146};
......@@ -151,13 +151,13 @@ pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) {
151151
152152/// This is a debug function. In order to print types in a meaningful way
153153/// we also need access to the module.
154pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void {
154pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void {
155155 return writer.print("{any}", .{start_type.ip_index});
156156}
157157
158158/// Prints a name suitable for `@typeName`.
159159/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
160pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer.Error!void {
160pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread) std.Io.Writer.Error!void {
161161 const zcu = pt.zcu;
162162 const ip = &zcu.intern_pool;
163163 switch (ip.indexToKey(ty.toIntern())) {
src/Value.zig+2-2
......@@ -15,7 +15,7 @@ const Value = @This();
1515
1616ip_index: InternPool.Index,
1717
18pub fn format(val: Value, writer: *std.io.Writer) !void {
18pub fn format(val: Value, writer: *std.Io.Writer) !void {
1919 _ = val;
2020 _ = writer;
2121 @compileError("do not use format values directly; use either fmtDebug or fmtValue");
......@@ -23,7 +23,7 @@ pub fn format(val: Value, writer: *std.io.Writer) !void {
2323
2424/// This is a debug function. In order to print values in a meaningful way
2525/// we also need access to the type.
26pub fn dump(start_val: Value, w: std.io.Writer) std.io.Writer.Error!void {
26pub fn dump(start_val: Value, w: std.Io.Writer) std.Io.Writer.Error!void {
2727 try w.print("(interned: {})", .{start_val.toIntern()});
2828}
2929
src/Zcu.zig+5-5
......@@ -15,7 +15,7 @@ const BigIntConst = std.math.big.int.Const;
1515const BigIntMutable = std.math.big.int.Mutable;
1616const Target = std.Target;
1717const Ast = std.zig.Ast;
18const Writer = std.io.Writer;
18const Writer = std.Io.Writer;
1919
2020const Zcu = @This();
2121const Compilation = @import("Compilation.zig");
......@@ -2872,7 +2872,7 @@ pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir {
28722872 };
28732873}
28742874
2875pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *std.io.Reader) !Zir {
2875pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *std.Io.Reader) !Zir {
28762876 var instructions: std.MultiArrayList(Zir.Inst) = .{};
28772877 errdefer instructions.deinit(gpa);
28782878
......@@ -2989,7 +2989,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir
29892989 };
29902990}
29912991
2992pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_br: *std.io.Reader) !Zoir {
2992pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_br: *std.Io.Reader) !Zoir {
29932993 var zoir: Zoir = .{
29942994 .nodes = .empty,
29952995 .extra = &.{},
......@@ -4318,7 +4318,7 @@ const FormatAnalUnit = struct {
43184318 zcu: *Zcu,
43194319};
43204320
4321fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Error!void {
4321fn formatAnalUnit(data: FormatAnalUnit, writer: *std.Io.Writer) std.Io.Writer.Error!void {
43224322 const zcu = data.zcu;
43234323 const ip = &zcu.intern_pool;
43244324 switch (data.unit.unwrap()) {
......@@ -4344,7 +4344,7 @@ fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Er
43444344
43454345const FormatDependee = struct { dependee: InternPool.Dependee, zcu: *Zcu };
43464346
4347fn formatDependee(data: FormatDependee, writer: *std.io.Writer) std.io.Writer.Error!void {
4347fn formatDependee(data: FormatDependee, writer: *std.Io.Writer) std.Io.Writer.Error!void {
43484348 const zcu = data.zcu;
43494349 const ip = &zcu.intern_pool;
43504350 switch (data.dependee) {
src/arch/riscv64/CodeGen.zig+5-5
......@@ -566,7 +566,7 @@ const InstTracking = struct {
566566 }
567567 }
568568
569 pub fn format(inst_tracking: InstTracking, writer: *std.io.Writer) std.io.Writer.Error!void {
569 pub fn format(inst_tracking: InstTracking, writer: *std.Io.Writer) std.Io.Writer.Error!void {
570570 if (!std.meta.eql(inst_tracking.long, inst_tracking.short)) try writer.print("|{}| ", .{inst_tracking.long});
571571 try writer.print("{}", .{inst_tracking.short});
572572 }
......@@ -932,7 +932,7 @@ const FormatWipMirData = struct {
932932 func: *Func,
933933 inst: Mir.Inst.Index,
934934};
935fn formatWipMir(data: FormatWipMirData, writer: *std.io.Writer) std.io.Writer.Error!void {
935fn formatWipMir(data: FormatWipMirData, writer: *std.Io.Writer) std.Io.Writer.Error!void {
936936 const pt = data.func.pt;
937937 const comp = pt.zcu.comp;
938938 var lower: Lower = .{
......@@ -980,7 +980,7 @@ const FormatNavData = struct {
980980 ip: *const InternPool,
981981 nav_index: InternPool.Nav.Index,
982982};
983fn formatNav(data: FormatNavData, writer: *std.io.Writer) std.io.Writer.Error!void {
983fn formatNav(data: FormatNavData, writer: *std.Io.Writer) std.Io.Writer.Error!void {
984984 try writer.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)});
985985}
986986fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) {
......@@ -994,7 +994,7 @@ const FormatAirData = struct {
994994 func: *Func,
995995 inst: Air.Inst.Index,
996996};
997fn formatAir(data: FormatAirData, writer: *std.io.Writer) std.io.Writer.Error!void {
997fn formatAir(data: FormatAirData, writer: *std.Io.Writer) std.Io.Writer.Error!void {
998998 // Not acceptable implementation because it ignores `writer`:
999999 //data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness);
10001000 _ = data;
......@@ -1008,7 +1008,7 @@ fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, fo
10081008const FormatTrackingData = struct {
10091009 func: *Func,
10101010};
1011fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void {
1011fn formatTracking(data: FormatTrackingData, writer: *std.Io.Writer) std.Io.Writer.Error!void {
10121012 var it = data.func.inst_tracking.iterator();
10131013 while (it.next()) |entry| try writer.print("\n%{d} = {f}", .{ entry.key_ptr.*, entry.value_ptr.* });
10141014}
src/arch/riscv64/Mir.zig+1-1
......@@ -92,7 +92,7 @@ pub const Inst = struct {
9292 },
9393 };
9494
95 pub fn format(inst: Inst, writer: *std.io.Writer) std.io.Writer.Error!void {
95 pub fn format(inst: Inst, writer: *std.Io.Writer) std.Io.Writer.Error!void {
9696 try writer.print("Tag: {s}, Data: {s}", .{ @tagName(inst.tag), @tagName(inst.data) });
9797 }
9898};
src/arch/x86_64/CodeGen.zig+2-2
......@@ -6,7 +6,7 @@ const log = std.log.scoped(.codegen);
66const tracking_log = std.log.scoped(.tracking);
77const verbose_tracking_log = std.log.scoped(.verbose_tracking);
88const wip_mir_log = std.log.scoped(.wip_mir);
9const Writer = std.io.Writer;
9const Writer = std.Io.Writer;
1010
1111const Air = @import("../../Air.zig");
1212const Allocator = std.mem.Allocator;
......@@ -1102,7 +1102,7 @@ const FormatAirData = struct {
11021102 self: *CodeGen,
11031103 inst: Air.Inst.Index,
11041104};
1105fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void {
1105fn formatAir(data: FormatAirData, w: *Writer) Writer.Error!void {
11061106 data.self.air.writeInst(w, data.inst, data.self.pt, data.self.liveness);
11071107}
11081108fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
src/arch/x86_64/Disassembler.zig+9-11
......@@ -287,13 +287,12 @@ const Prefixes = struct {
287287
288288fn parsePrefixes(dis: *Disassembler) !Prefixes {
289289 const rex_prefix_mask: u4 = 0b0100;
290 var stream = std.io.fixedBufferStream(dis.code[dis.pos..]);
291 const reader = stream.reader();
290 var reader: std.Io.Reader = .fixed(dis.code[dis.pos..]);
292291
293292 var res: Prefixes = .{};
294293
295294 while (true) {
296 const next_byte = try reader.readByte();
295 const next_byte = try reader.takeByte();
297296 dis.pos += 1;
298297
299298 switch (next_byte) {
......@@ -341,12 +340,11 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding {
341340 const o_mask: u8 = 0b1111_1000;
342341
343342 var opcode: [3]u8 = .{ 0, 0, 0 };
344 var stream = std.io.fixedBufferStream(dis.code[dis.pos..]);
345 const reader = stream.reader();
343 var reader: std.Io.Reader = .fixed(dis.code[dis.pos..]);
346344
347345 comptime var opc_count = 0;
348346 inline while (opc_count < 3) : (opc_count += 1) {
349 const byte = try reader.readByte();
347 const byte = try reader.takeByte();
350348 opcode[opc_count] = byte;
351349 dis.pos += 1;
352350
......@@ -410,11 +408,11 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate {
410408}
411409
412410fn parseOffset(dis: *Disassembler) !u64 {
413 var stream = std.io.fixedBufferStream(dis.code[dis.pos..]);
414 const reader = stream.reader();
415 const offset = try reader.readInt(u64, .little);
416 dis.pos += 8;
417 return offset;
411 var reader: std.Io.Reader = .fixed(dis.code);
412 reader.seek = dis.pos;
413 defer dis.pos = reader.seek;
414
415 return reader.takeInt(u64, .little);
418416}
419417
420418const ModRm = packed struct {
src/arch/x86_64/Emit.zig+1-1
......@@ -698,7 +698,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
698698 const gpa = comp.gpa;
699699 const start_offset: u32 = @intCast(emit.code.items.len);
700700 {
701 var aw: std.io.Writer.Allocating = .fromArrayList(gpa, emit.code);
701 var aw: std.Io.Writer.Allocating = .fromArrayList(gpa, emit.code);
702702 defer emit.code.* = aw.toArrayList();
703703 lowered_inst.encode(&aw.writer, .{}) catch |err| switch (err) {
704704 error.WriteFailed => return error.OutOfMemory,
src/arch/x86_64/Encoding.zig+2-2
......@@ -158,7 +158,7 @@ pub fn modRmExt(encoding: Encoding) u3 {
158158 };
159159}
160160
161pub fn format(encoding: Encoding, writer: *std.io.Writer) std.io.Writer.Error!void {
161pub fn format(encoding: Encoding, writer: *std.Io.Writer) std.Io.Writer.Error!void {
162162 var opc = encoding.opcode();
163163 if (encoding.data.mode.isVex()) {
164164 try writer.writeAll("VEX.");
......@@ -1016,7 +1016,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
10161016 // By using a buffer with maximum length of encoded instruction, we can use
10171017 // the `end` field of the Writer for the count.
10181018 var buf: [16]u8 = undefined;
1019 var trash: std.io.Writer.Discarding = .init(&buf);
1019 var trash: std.Io.Writer.Discarding = .init(&buf);
10201020 inst.encode(&trash.writer, .{
10211021 .allow_frame_locs = true,
10221022 .allow_symbols = true,
src/arch/x86_64/bits.zig+2-2
......@@ -827,7 +827,7 @@ pub const Memory = struct {
827827 };
828828 }
829829
830 pub fn format(s: Size, writer: *std.io.Writer) std.io.Writer.Error!void {
830 pub fn format(s: Size, writer: *std.Io.Writer) std.Io.Writer.Error!void {
831831 if (s == .none) return;
832832 try writer.writeAll(@tagName(s));
833833 switch (s) {
......@@ -892,7 +892,7 @@ pub const Immediate = union(enum) {
892892 return .{ .signed = x };
893893 }
894894
895 pub fn format(imm: Immediate, writer: *std.io.Writer) std.io.Writer.Error!void {
895 pub fn format(imm: Immediate, writer: *std.Io.Writer) std.Io.Writer.Error!void {
896896 switch (imm) {
897897 inline else => |int| try writer.print("{d}", .{int}),
898898 .nav => |nav_off| try writer.print("Nav({d}) + {d}", .{ @intFromEnum(nav_off.nav), nav_off.off }),
src/arch/x86_64/encoder.zig+1-1
......@@ -3,7 +3,7 @@ const assert = std.debug.assert;
33const log = std.log.scoped(.x86_64_encoder);
44const math = std.math;
55const testing = std.testing;
6const Writer = std.io.Writer;
6const Writer = std.Io.Writer;
77
88const bits = @import("bits.zig");
99const Encoding = @import("Encoding.zig");
src/codegen/c.zig+10-10
......@@ -4,7 +4,7 @@ const assert = std.debug.assert;
44const mem = std.mem;
55const log = std.log.scoped(.c);
66const Allocator = mem.Allocator;
7const Writer = std.io.Writer;
7const Writer = std.Io.Writer;
88
99const dev = @import("../dev.zig");
1010const link = @import("../link.zig");
......@@ -345,15 +345,15 @@ fn isReservedIdent(ident: []const u8) bool {
345345 } else return reserved_idents.has(ident);
346346}
347347
348fn formatIdentSolo(ident: []const u8, w: *std.io.Writer) std.io.Writer.Error!void {
348fn formatIdentSolo(ident: []const u8, w: *Writer) Writer.Error!void {
349349 return formatIdentOptions(ident, w, true);
350350}
351351
352fn formatIdentUnsolo(ident: []const u8, w: *std.io.Writer) std.io.Writer.Error!void {
352fn formatIdentUnsolo(ident: []const u8, w: *Writer) Writer.Error!void {
353353 return formatIdentOptions(ident, w, false);
354354}
355355
356fn formatIdentOptions(ident: []const u8, w: *std.io.Writer, solo: bool) std.io.Writer.Error!void {
356fn formatIdentOptions(ident: []const u8, w: *Writer, solo: bool) Writer.Error!void {
357357 if (solo and isReservedIdent(ident)) {
358358 try w.writeAll("zig_e_");
359359 }
......@@ -384,7 +384,7 @@ const CTypePoolStringFormatData = struct {
384384 ctype_pool: *const CType.Pool,
385385 solo: bool,
386386};
387fn formatCTypePoolString(data: CTypePoolStringFormatData, w: *std.io.Writer) std.io.Writer.Error!void {
387fn formatCTypePoolString(data: CTypePoolStringFormatData, w: *Writer) Writer.Error!void {
388388 if (data.ctype_pool_string.toSlice(data.ctype_pool)) |slice|
389389 try formatIdentOptions(slice, w, data.solo)
390390 else
......@@ -711,8 +711,8 @@ pub const Function = struct {
711711/// It is not available when generating .h file.
712712pub const Object = struct {
713713 dg: DeclGen,
714 code_header: std.io.Writer.Allocating,
715 code: std.io.Writer.Allocating,
714 code_header: Writer.Allocating,
715 code: Writer.Allocating,
716716 indent_counter: usize,
717717
718718 const indent_width = 1;
......@@ -748,7 +748,7 @@ pub const DeclGen = struct {
748748 pass: Pass,
749749 is_naked_fn: bool,
750750 expected_block: ?u32,
751 fwd_decl: std.io.Writer.Allocating,
751 fwd_decl: Writer.Allocating,
752752 error_msg: ?*Zcu.ErrorMsg,
753753 ctype_pool: CType.Pool,
754754 scratch: std.ArrayListUnmanaged(u32),
......@@ -8287,7 +8287,7 @@ const FormatStringContext = struct {
82878287 sentinel: ?u8,
82888288};
82898289
8290fn formatStringLiteral(data: FormatStringContext, w: *std.io.Writer) std.io.Writer.Error!void {
8290fn formatStringLiteral(data: FormatStringContext, w: *Writer) Writer.Error!void {
82918291 var literal: StringLiteral = .init(w, data.str.len + @intFromBool(data.sentinel != null));
82928292 try literal.start();
82938293 for (data.str) |c| try literal.writeChar(c);
......@@ -8314,7 +8314,7 @@ const FormatIntLiteralContext = struct {
83148314 base: u8,
83158315 case: std.fmt.Case,
83168316};
8317fn formatIntLiteral(data: FormatIntLiteralContext, w: *std.io.Writer) std.io.Writer.Error!void {
8317fn formatIntLiteral(data: FormatIntLiteralContext, w: *Writer) Writer.Error!void {
83188318 const pt = data.dg.pt;
83198319 const zcu = pt.zcu;
83208320 const target = &data.dg.mod.resolved_target.result;
src/codegen/c/Type.zig+1-1
......@@ -3396,7 +3396,7 @@ pub const AlignAs = packed struct {
33963396
33973397const std = @import("std");
33983398const assert = std.debug.assert;
3399const Writer = std.io.Writer;
3399const Writer = std.Io.Writer;
34003400
34013401const CType = @This();
34023402const InternPool = @import("../../InternPool.zig");
src/codegen/llvm.zig+1-1
......@@ -2683,7 +2683,7 @@ pub const Object = struct {
26832683 }
26842684
26852685 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {
2686 var aw: std.io.Writer.Allocating = .init(o.gpa);
2686 var aw: std.Io.Writer.Allocating = .init(o.gpa);
26872687 defer aw.deinit();
26882688 ty.print(&aw.writer, pt) catch |err| switch (err) {
26892689 error.WriteFailed => return error.OutOfMemory,
src/codegen/spirv/CodeGen.zig+1-1
......@@ -1211,7 +1211,7 @@ fn constantNavRef(cg: *CodeGen, ty: Type, nav_index: InternPool.Nav.Index) !Id {
12111211// Turn a Zig type's name into a cache reference.
12121212fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 {
12131213 const gpa = cg.module.gpa;
1214 var aw: std.io.Writer.Allocating = .init(gpa);
1214 var aw: std.Io.Writer.Allocating = .init(gpa);
12151215 defer aw.deinit();
12161216 ty.print(&aw.writer, cg.pt) catch |err| switch (err) {
12171217 error.WriteFailed => return error.OutOfMemory,
src/codegen/spirv/spec.zig+1-1
......@@ -18,7 +18,7 @@ pub const Id = enum(Word) {
1818 none,
1919 _,
2020
21 pub fn format(self: Id, writer: *std.io.Writer) std.io.Writer.Error!void {
21 pub fn format(self: Id, writer: *std.Io.Writer) std.Io.Writer.Error!void {
2222 switch (self) {
2323 .none => try writer.writeAll("(none)"),
2424 else => try writer.print("%{d}", .{@intFromEnum(self)}),
src/crash_report.zig-1
......@@ -2,7 +2,6 @@ const std = @import("std");
22const builtin = @import("builtin");
33const build_options = @import("build_options");
44const debug = std.debug;
5const io = std.io;
65const print_zir = @import("print_zir.zig");
76const windows = std.os.windows;
87const posix = std.posix;
src/libs/mingw.zig+1-1
......@@ -325,7 +325,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
325325
326326 for (aro_comp.diagnostics.list.items) |diagnostic| {
327327 if (diagnostic.kind == .@"fatal error" or diagnostic.kind == .@"error") {
328 aro.Diagnostics.render(&aro_comp, std.io.tty.detectConfig(std.fs.File.stderr()));
328 aro.Diagnostics.render(&aro_comp, std.Io.tty.detectConfig(std.fs.File.stderr()));
329329 return error.AroPreprocessorFailed;
330330 }
331331 }
src/link/C.zig+4-4
......@@ -348,7 +348,7 @@ pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedIn
348348 _ = ti_id;
349349}
350350
351fn abiDefines(w: *std.io.Writer, target: *const std.Target) !void {
351fn abiDefines(w: *std.Io.Writer, target: *const std.Target) !void {
352352 switch (target.abi) {
353353 .msvc, .itanium => try w.writeAll("#define ZIG_TARGET_ABI_MSVC\n"),
354354 else => {},
......@@ -400,7 +400,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
400400 };
401401 defer f.deinit(gpa);
402402
403 var abi_defines_aw: std.io.Writer.Allocating = .init(gpa);
403 var abi_defines_aw: std.Io.Writer.Allocating = .init(gpa);
404404 defer abi_defines_aw.deinit();
405405 abiDefines(&abi_defines_aw.writer, zcu.getTarget()) catch |err| switch (err) {
406406 error.WriteFailed => return error.OutOfMemory,
......@@ -415,7 +415,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
415415 const ctypes_index = f.all_buffers.items.len;
416416 f.all_buffers.items.len += 1;
417417
418 var asm_aw: std.io.Writer.Allocating = .init(gpa);
418 var asm_aw: std.Io.Writer.Allocating = .init(gpa);
419419 defer asm_aw.deinit();
420420 codegen.genGlobalAsm(zcu, &asm_aw.writer) catch |err| switch (err) {
421421 error.WriteFailed => return error.OutOfMemory,
......@@ -582,7 +582,7 @@ fn flushCTypes(
582582 try global_from_decl_map.ensureTotalCapacity(gpa, decl_ctype_pool.items.len);
583583 defer global_from_decl_map.clearRetainingCapacity();
584584
585 var ctypes_aw: std.io.Writer.Allocating = .fromArrayList(gpa, &f.ctypes);
585 var ctypes_aw: std.Io.Writer.Allocating = .fromArrayList(gpa, &f.ctypes);
586586 const ctypes_bw = &ctypes_aw.writer;
587587 defer f.ctypes = ctypes_aw.toArrayList();
588588
src/link/Coff.zig+1-1
......@@ -3039,7 +3039,7 @@ const ImportTable = struct {
30393039 itab: ImportTable,
30403040 ctx: Context,
30413041
3042 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
3042 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
30433043 const lib_name = f.ctx.coff.temp_strtab.getAssumeExists(f.ctx.name_off);
30443044 const base_vaddr = getBaseAddress(f.ctx);
30453045 try writer.print("IAT({s}.dll) @{x}:", .{ lib_name, base_vaddr });
src/link/Elf.zig+5-5
......@@ -3869,7 +3869,7 @@ fn fmtShdr(self: *Elf, shdr: elf.Elf64_Shdr) std.fmt.Formatter(FormatShdr, forma
38693869 } };
38703870}
38713871
3872fn formatShdr(ctx: FormatShdr, writer: *std.io.Writer) std.io.Writer.Error!void {
3872fn formatShdr(ctx: FormatShdr, writer: *std.Io.Writer) std.Io.Writer.Error!void {
38733873 const shdr = ctx.shdr;
38743874 try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({f})", .{
38753875 ctx.elf_file.getShString(shdr.sh_name), shdr.sh_offset,
......@@ -3883,7 +3883,7 @@ pub fn fmtShdrFlags(sh_flags: u64) std.fmt.Formatter(u64, formatShdrFlags) {
38833883 return .{ .data = sh_flags };
38843884}
38853885
3886fn formatShdrFlags(sh_flags: u64, writer: *std.io.Writer) std.io.Writer.Error!void {
3886fn formatShdrFlags(sh_flags: u64, writer: *std.Io.Writer) std.Io.Writer.Error!void {
38873887 if (elf.SHF_WRITE & sh_flags != 0) {
38883888 try writer.writeAll("W");
38893889 }
......@@ -3940,7 +3940,7 @@ fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(FormatPhdr, forma
39403940 } };
39413941}
39423942
3943fn formatPhdr(ctx: FormatPhdr, writer: *std.io.Writer) std.io.Writer.Error!void {
3943fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void {
39443944 const phdr = ctx.phdr;
39453945 const write = phdr.p_flags & elf.PF_W != 0;
39463946 const read = phdr.p_flags & elf.PF_R != 0;
......@@ -3971,7 +3971,7 @@ pub fn dumpState(self: *Elf) std.fmt.Formatter(*Elf, fmtDumpState) {
39713971 return .{ .data = self };
39723972}
39733973
3974fn fmtDumpState(self: *Elf, writer: *std.io.Writer) std.io.Writer.Error!void {
3974fn fmtDumpState(self: *Elf, writer: *std.Io.Writer) std.Io.Writer.Error!void {
39753975 const shared_objects = self.shared_objects.values();
39763976
39773977 if (self.zigObjectPtr()) |zig_object| {
......@@ -4189,7 +4189,7 @@ pub const Ref = struct {
41894189 return ref.index == other.index and ref.file == other.file;
41904190 }
41914191
4192 pub fn format(ref: Ref, writer: *std.io.Writer) std.io.Writer.Error!void {
4192 pub fn format(ref: Ref, writer: *std.Io.Writer) std.Io.Writer.Error!void {
41934193 try writer.print("ref({d},{d})", .{ ref.index, ref.file });
41944194 }
41954195};
src/link/Elf/Archive.zig+2-2
......@@ -204,7 +204,7 @@ pub const ArSymtab = struct {
204204 ar: ArSymtab,
205205 elf_file: *Elf,
206206
207 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
207 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
208208 const ar = f.ar;
209209 const elf_file = f.elf_file;
210210 for (ar.symtab.items, 0..) |entry, i| {
......@@ -259,7 +259,7 @@ pub const ArStrtab = struct {
259259 try writer.writeAll(ar.buffer.items);
260260 }
261261
262 pub fn format(ar: ArStrtab, writer: *std.io.Writer) std.io.Writer.Error!void {
262 pub fn format(ar: ArStrtab, writer: *std.Io.Writer) std.Io.Writer.Error!void {
263263 try writer.print("{f}", .{std.ascii.hexEscape(ar.buffer.items, .lower)});
264264 }
265265};
src/link/Elf/AtomList.zig+1-1
......@@ -170,7 +170,7 @@ const Format = struct {
170170 atom_list: AtomList,
171171 elf_file: *Elf,
172172
173 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
173 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
174174 const list = f.atom_list;
175175 try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{
176176 list.address(f.elf_file),
src/link/Elf/LinkerDefined.zig+1-1
......@@ -448,7 +448,7 @@ const Format = struct {
448448 self: *LinkerDefined,
449449 elf_file: *Elf,
450450
451 fn symtab(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
451 fn symtab(ctx: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
452452 const self = ctx.self;
453453 const elf_file = ctx.elf_file;
454454 try writer.writeAll(" globals\n");
src/link/Elf/Merge.zig+2-2
......@@ -168,7 +168,7 @@ pub const Section = struct {
168168 msec: Section,
169169 elf_file: *Elf,
170170
171 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
171 pub fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
172172 const msec = f.msec;
173173 const elf_file = f.elf_file;
174174 try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{
......@@ -222,7 +222,7 @@ pub const Subsection = struct {
222222 msub: Subsection,
223223 elf_file: *Elf,
224224
225 pub fn default(ctx: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
225 pub fn default(ctx: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
226226 const msub = ctx.msub;
227227 const elf_file = ctx.elf_file;
228228 try writer.print("@{x} : align({x}) : size({x})", .{
src/link/Elf/Object.zig+6-6
......@@ -1442,7 +1442,7 @@ const Format = struct {
14421442 object: *Object,
14431443 elf_file: *Elf,
14441444
1445 fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1445 fn symtab(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14461446 const object = f.object;
14471447 const elf_file = f.elf_file;
14481448 try writer.writeAll(" locals\n");
......@@ -1461,7 +1461,7 @@ const Format = struct {
14611461 }
14621462 }
14631463
1464 fn atoms(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1464 fn atoms(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14651465 const object = f.object;
14661466 try writer.writeAll(" atoms\n");
14671467 for (object.atoms_indexes.items) |atom_index| {
......@@ -1470,7 +1470,7 @@ const Format = struct {
14701470 }
14711471 }
14721472
1473 fn cies(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1473 fn cies(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14741474 const object = f.object;
14751475 try writer.writeAll(" cies\n");
14761476 for (object.cies.items, 0..) |cie, i| {
......@@ -1478,7 +1478,7 @@ const Format = struct {
14781478 }
14791479 }
14801480
1481 fn fdes(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1481 fn fdes(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14821482 const object = f.object;
14831483 try writer.writeAll(" fdes\n");
14841484 for (object.fdes.items, 0..) |fde, i| {
......@@ -1486,7 +1486,7 @@ const Format = struct {
14861486 }
14871487 }
14881488
1489 fn groups(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
1489 fn groups(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
14901490 const object = f.object;
14911491 const elf_file = f.elf_file;
14921492 try writer.writeAll(" groups\n");
......@@ -1536,7 +1536,7 @@ pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
15361536 return .{ .data = self };
15371537}
15381538
1539fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
1539fn formatPath(object: Object, writer: *std.Io.Writer) std.Io.Writer.Error!void {
15401540 if (object.archive) |ar| {
15411541 try writer.print("{f}({f})", .{ ar.path, object.path });
15421542 } else {
src/link/Elf/SharedObject.zig+1-1
......@@ -520,7 +520,7 @@ const Format = struct {
520520 shared: SharedObject,
521521 elf_file: *Elf,
522522
523 fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
523 fn symtab(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
524524 const shared = f.shared;
525525 const elf_file = f.elf_file;
526526 try writer.writeAll(" globals\n");
src/link/Elf/Symbol.zig+2-2
......@@ -320,7 +320,7 @@ const Format = struct {
320320 symbol: Symbol,
321321 elf_file: *Elf,
322322
323 fn name(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
323 fn name(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
324324 const elf_file = f.elf_file;
325325 const symbol = f.symbol;
326326 try writer.writeAll(symbol.name(elf_file));
......@@ -335,7 +335,7 @@ const Format = struct {
335335 }
336336 }
337337
338 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
338 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
339339 const symbol = f.symbol;
340340 const elf_file = f.elf_file;
341341 try writer.print("%{d} : {f} : @{x}", .{
src/link/Elf/Thunk.zig+1-1
......@@ -76,7 +76,7 @@ const Format = struct {
7676 thunk: Thunk,
7777 elf_file: *Elf,
7878
79 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
79 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
8080 const thunk = f.thunk;
8181 const elf_file = f.elf_file;
8282 try writer.print("@{x} : size({x})\n", .{ thunk.value, thunk.size(elf_file) });
src/link/Elf/ZigObject.zig+2-2
......@@ -2201,7 +2201,7 @@ const Format = struct {
22012201 self: *ZigObject,
22022202 elf_file: *Elf,
22032203
2204 fn symtab(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
2204 fn symtab(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
22052205 const self = f.self;
22062206 const elf_file = f.elf_file;
22072207 try writer.writeAll(" locals\n");
......@@ -2216,7 +2216,7 @@ const Format = struct {
22162216 }
22172217 }
22182218
2219 fn atoms(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
2219 fn atoms(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
22202220 try writer.writeAll(" atoms\n");
22212221 for (f.self.atoms_indexes.items) |atom_index| {
22222222 const atom_ptr = f.self.atom(atom_index) orelse continue;
src/link/Elf/eh_frame.zig+6-7
......@@ -58,7 +58,7 @@ pub const Fde = struct {
5858 fde: Fde,
5959 elf_file: *Elf,
6060
61 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
61 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
6262 const fde = f.fde;
6363 const elf_file = f.elf_file;
6464 const base_addr = fde.address(elf_file);
......@@ -141,7 +141,7 @@ pub const Cie = struct {
141141 cie: Cie,
142142 elf_file: *Elf,
143143
144 fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
144 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
145145 const cie = f.cie;
146146 const elf_file = f.elf_file;
147147 const base_addr = cie.address(elf_file);
......@@ -167,15 +167,14 @@ pub const Iterator = struct {
167167 pub fn next(it: *Iterator) !?Record {
168168 if (it.pos >= it.data.len) return null;
169169
170 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
171 const reader = stream.reader();
170 var reader: std.Io.Reader = .fixed(it.data[it.pos..]);
172171
173 const size = try reader.readInt(u32, .little);
172 const size = try reader.takeInt(u32, .little);
174173 if (size == 0) return null;
175174 if (size == 0xFFFFFFFF) @panic("TODO");
176175
177 const id = try reader.readInt(u32, .little);
178 const record = Record{
176 const id = try reader.takeInt(u32, .little);
177 const record: Record = .{
179178 .tag = if (id == 0) .cie else .fde,
180179 .offset = it.pos,
181180 .size = size,
src/link/Elf/file.zig+1-1
......@@ -14,7 +14,7 @@ pub const File = union(enum) {
1414 return .{ .data = file };
1515 }
1616
17 fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
17 fn formatPath(file: File, writer: *std.Io.Writer) std.Io.Writer.Error!void {
1818 switch (file) {
1919 .zig_object => |zo| try writer.writeAll(zo.basename),
2020 .linker_defined => try writer.writeAll("(linker defined)"),
src/link/Elf/gc.zig+1-1
......@@ -169,7 +169,7 @@ const Level = struct {
169169 self.value += 1;
170170 }
171171
172 pub fn format(self: *const @This(), w: *std.io.Writer) std.io.Writer.Error!void {
172 pub fn format(self: *const @This(), w: *std.Io.Writer) std.Io.Writer.Error!void {
173173 try w.splatByteAll(' ', self.value);
174174 }
175175};
src/link/Elf/relocation.zig+1-1
......@@ -160,7 +160,7 @@ pub fn fmtRelocType(r_type: u32, cpu_arch: std.Target.Cpu.Arch) std.fmt.Formatte
160160 } };
161161}
162162
163fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.io.Writer) std.io.Writer.Error!void {
163fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.Io.Writer) std.Io.Writer.Error!void {
164164 const r_type = ctx.r_type;
165165 switch (ctx.cpu_arch) {
166166 .x86_64 => try writer.print("R_X86_64_{s}", .{@tagName(@as(elf.R_X86_64, @enumFromInt(r_type)))}),
src/link/Elf/synthetic_sections.zig+2-2
......@@ -605,7 +605,7 @@ pub const GotSection = struct {
605605 got: GotSection,
606606 elf_file: *Elf,
607607
608 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
608 pub fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
609609 const got = f.got;
610610 const elf_file = f.elf_file;
611611 try writer.writeAll("GOT\n");
......@@ -741,7 +741,7 @@ pub const PltSection = struct {
741741 plt: PltSection,
742742 elf_file: *Elf,
743743
744 pub fn default(f: Format, writer: *std.io.Writer) std.io.Writer.Error!void {
744 pub fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
745745 const plt = f.plt;
746746 const elf_file = f.elf_file;
747747 try writer.writeAll("PLT\n");
src/link/Lld.zig+4-2
......@@ -1650,7 +1650,8 @@ fn spawnLld(
16501650 child.stderr_behavior = .Pipe;
16511651
16521652 child.spawn() catch |err| break :term err;
1653 stderr = try child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
1653 var stderr_reader = child.stderr.?.readerStreaming(&.{});
1654 stderr = try stderr_reader.interface.allocRemaining(comp.gpa, .unlimited);
16541655 break :term child.wait();
16551656 }) catch |first_err| term: {
16561657 const err = switch (first_err) {
......@@ -1699,7 +1700,8 @@ fn spawnLld(
16991700 rsp_child.stderr_behavior = .Pipe;
17001701
17011702 rsp_child.spawn() catch |err| break :err err;
1702 stderr = try rsp_child.stderr.?.deprecatedReader().readAllAlloc(comp.gpa, std.math.maxInt(usize));
1703 var stderr_reader = rsp_child.stderr.?.readerStreaming(&.{});
1704 stderr = try stderr_reader.interface.allocRemaining(comp.gpa, .unlimited);
17031705 break :term rsp_child.wait() catch |err| break :err err;
17041706 }
17051707 },
src/link/MachO/Dylib.zig+1-1
......@@ -914,7 +914,7 @@ const math = std.math;
914914const mem = std.mem;
915915const Allocator = mem.Allocator;
916916const Path = std.Build.Cache.Path;
917const Writer = std.io.Writer;
917const Writer = std.Io.Writer;
918918
919919const Dylib = @This();
920920const File = @import("file.zig").File;
src/link/MachO/InternalObject.zig+1-1
......@@ -894,7 +894,7 @@ const macho = std.macho;
894894const mem = std.mem;
895895const std = @import("std");
896896const trace = @import("../../tracy.zig").trace;
897const Writer = std.io.Writer;
897const Writer = std.Io.Writer;
898898
899899const Allocator = std.mem.Allocator;
900900const Atom = @import("Atom.zig");
src/link/MachO/Object.zig+1-1
......@@ -3094,7 +3094,7 @@ const math = std.math;
30943094const mem = std.mem;
30953095const Path = std.Build.Cache.Path;
30963096const Allocator = std.mem.Allocator;
3097const Writer = std.io.Writer;
3097const Writer = std.Io.Writer;
30983098
30993099const eh_frame = @import("eh_frame.zig");
31003100const trace = @import("../../tracy.zig").trace;
src/link/MachO/Relocation.zig+1-1
......@@ -162,7 +162,7 @@ const std = @import("std");
162162const assert = std.debug.assert;
163163const macho = std.macho;
164164const math = std.math;
165const Writer = std.io.Writer;
165const Writer = std.Io.Writer;
166166
167167const Atom = @import("Atom.zig");
168168const MachO = @import("../MachO.zig");
src/link/MachO/Symbol.zig+1-1
......@@ -417,7 +417,7 @@ pub const Index = u32;
417417const assert = std.debug.assert;
418418const macho = std.macho;
419419const std = @import("std");
420const Writer = std.io.Writer;
420const Writer = std.Io.Writer;
421421
422422const Atom = @import("Atom.zig");
423423const File = @import("file.zig").File;
src/link/MachO/Thunk.zig+1-1
......@@ -97,7 +97,7 @@ const math = std.math;
9797const mem = std.mem;
9898const std = @import("std");
9999const trace = @import("../../tracy.zig").trace;
100const Writer = std.io.Writer;
100const Writer = std.Io.Writer;
101101
102102const Allocator = mem.Allocator;
103103const Atom = @import("Atom.zig");
src/link/MachO/ZigObject.zig+1-1
......@@ -1785,7 +1785,7 @@ const mem = std.mem;
17851785const target_util = @import("../../target.zig");
17861786const trace = @import("../../tracy.zig").trace;
17871787const std = @import("std");
1788const Writer = std.io.Writer;
1788const Writer = std.Io.Writer;
17891789
17901790const Allocator = std.mem.Allocator;
17911791const Archive = @import("Archive.zig");
src/link/MachO/dead_strip.zig+1-1
......@@ -212,7 +212,7 @@ const mem = std.mem;
212212const trace = @import("../../tracy.zig").trace;
213213const track_live_log = std.log.scoped(.dead_strip_track_live);
214214const std = @import("std");
215const Writer = std.io.Writer;
215const Writer = std.Io.Writer;
216216
217217const Allocator = mem.Allocator;
218218const Atom = @import("Atom.zig");
src/link/MachO/dyld_info/Rebase.zig+1-1
......@@ -656,7 +656,7 @@ const macho = std.macho;
656656const mem = std.mem;
657657const testing = std.testing;
658658const Allocator = mem.Allocator;
659const Writer = std.io.Writer;
659const Writer = std.Io.Writer;
660660
661661const trace = @import("../../../tracy.zig").trace;
662662const File = @import("../file.zig").File;
src/link/MachO/eh_frame.zig+4-5
......@@ -248,13 +248,12 @@ pub const Iterator = struct {
248248 pub fn next(it: *Iterator) !?Record {
249249 if (it.pos >= it.data.len) return null;
250250
251 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
252 const reader = stream.reader();
251 var reader: std.Io.Reader = .fixed(it.data[it.pos..]);
253252
254 const size = try reader.readInt(u32, .little);
253 const size = try reader.takeInt(u32, .little);
255254 if (size == 0xFFFFFFFF) @panic("DWARF CFI is 32bit on macOS");
256255
257 const id = try reader.readInt(u32, .little);
256 const id = try reader.takeInt(u32, .little);
258257 const record = Record{
259258 .tag = if (id == 0) .cie else .fde,
260259 .offset = it.pos,
......@@ -502,7 +501,7 @@ const math = std.math;
502501const mem = std.mem;
503502const std = @import("std");
504503const trace = @import("../../tracy.zig").trace;
505const Writer = std.io.Writer;
504const Writer = std.Io.Writer;
506505
507506const Allocator = std.mem.Allocator;
508507const Atom = @import("Atom.zig");
src/link/MachO/file.zig+1-1
......@@ -364,7 +364,7 @@ const log = std.log.scoped(.link);
364364const macho = std.macho;
365365const Allocator = std.mem.Allocator;
366366const Path = std.Build.Cache.Path;
367const Writer = std.io.Writer;
367const Writer = std.Io.Writer;
368368
369369const trace = @import("../../tracy.zig").trace;
370370const Archive = @import("Archive.zig");
src/link/MachO/relocatable.zig+1-1
......@@ -780,7 +780,7 @@ const macho = std.macho;
780780const math = std.math;
781781const mem = std.mem;
782782const state_log = std.log.scoped(.link_state);
783const Writer = std.io.Writer;
783const Writer = std.Io.Writer;
784784
785785const Archive = @import("Archive.zig");
786786const Atom = @import("Atom.zig");
src/link/SpirV.zig+1-1
......@@ -249,7 +249,7 @@ pub fn flush(
249249 // We need to export the list of error names somewhere so that we can pretty-print them in the
250250 // executor. This is not really an important thing though, so we can just dump it in any old
251251 // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name.
252 var error_info: std.io.Writer.Allocating = .init(linker.module.gpa);
252 var error_info: std.Io.Writer.Allocating = .init(linker.module.gpa);
253253 defer error_info.deinit();
254254
255255 error_info.writer.writeAll("zig_errors:") catch return error.OutOfMemory;
src/link/Wasm.zig+2-2
......@@ -2126,7 +2126,7 @@ pub const FunctionType = extern struct {
21262126 wasm: *const Wasm,
21272127 ft: FunctionType,
21282128
2129 pub fn format(self: Formatter, writer: *std.io.Writer) std.io.Writer.Error!void {
2129 pub fn format(self: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void {
21302130 const params = self.ft.params.slice(self.wasm);
21312131 const returns = self.ft.returns.slice(self.wasm);
21322132
......@@ -2905,7 +2905,7 @@ pub const Feature = packed struct(u8) {
29052905 @"=",
29062906 };
29072907
2908 pub fn format(feature: Feature, writer: *std.io.Writer) std.io.Writer.Error!void {
2908 pub fn format(feature: Feature, writer: *std.Io.Writer) std.Io.Writer.Error!void {
29092909 try writer.print("{s} {s}", .{ @tagName(feature.prefix), @tagName(feature.tag) });
29102910 }
29112911
src/link/Wasm/Object.zig+3-6
......@@ -1460,13 +1460,10 @@ fn parseFeatures(
14601460}
14611461
14621462fn readLeb(comptime T: type, bytes: []const u8, pos: usize) struct { T, usize } {
1463 var fbr = std.io.fixedBufferStream(bytes[pos..]);
1463 var reader: std.Io.Reader = .fixed(bytes[pos..]);
14641464 return .{
1465 switch (@typeInfo(T).int.signedness) {
1466 .signed => std.leb.readIleb128(T, fbr.reader()) catch unreachable,
1467 .unsigned => std.leb.readUleb128(T, fbr.reader()) catch unreachable,
1468 },
1469 pos + fbr.pos,
1465 reader.takeLeb128(T) catch unreachable,
1466 pos + reader.seek,
14701467 };
14711468}
14721469
src/link/table_section.zig+1-1
......@@ -39,7 +39,7 @@ pub fn TableSection(comptime Entry: type) type {
3939 return self.entries.items.len;
4040 }
4141
42 pub fn format(self: Self, writer: *std.io.Writer) std.io.Writer.Error!void {
42 pub fn format(self: Self, writer: *std.Io.Writer) std.Io.Writer.Error!void {
4343 try writer.writeAll("TableSection:\n");
4444 for (self.entries.items, 0..) |entry, i| {
4545 try writer.print(" {d} => {}\n", .{ i, entry });
src/link/tapi/parse.zig+5-5
......@@ -57,7 +57,7 @@ pub const Node = struct {
5757 }
5858 }
5959
60 pub fn format(self: *const Node, writer: *std.io.Writer) std.io.Writer.Error!void {
60 pub fn format(self: *const Node, writer: *std.Io.Writer) std.Io.Writer.Error!void {
6161 switch (self.tag) {
6262 inline else => |tag| return @as(*tag.Type(), @fieldParentPtr("base", self)).format(writer),
6363 }
......@@ -81,7 +81,7 @@ pub const Node = struct {
8181 }
8282 }
8383
84 pub fn format(self: *const Doc, writer: *std.io.Writer) std.io.Writer.Error!void {
84 pub fn format(self: *const Doc, writer: *std.Io.Writer) std.Io.Writer.Error!void {
8585 if (self.directive) |id| {
8686 try writer.print("{{ ", .{});
8787 const directive = self.base.tree.getRaw(id, id);
......@@ -121,7 +121,7 @@ pub const Node = struct {
121121 self.values.deinit(allocator);
122122 }
123123
124 pub fn format(self: *const Map, writer: *std.io.Writer) std.io.Writer.Error!void {
124 pub fn format(self: *const Map, writer: *std.Io.Writer) std.Io.Writer.Error!void {
125125 try std.fmt.format(writer, "{{ ", .{});
126126 for (self.values.items) |entry| {
127127 const key = self.base.tree.getRaw(entry.key, entry.key);
......@@ -153,7 +153,7 @@ pub const Node = struct {
153153 self.values.deinit(allocator);
154154 }
155155
156 pub fn format(self: *const List, writer: *std.io.Writer) std.io.Writer.Error!void {
156 pub fn format(self: *const List, writer: *std.Io.Writer) std.Io.Writer.Error!void {
157157 try std.fmt.format(writer, "[ ", .{});
158158 for (self.values.items) |node| {
159159 try std.fmt.format(writer, "{}, ", .{node});
......@@ -177,7 +177,7 @@ pub const Node = struct {
177177 self.string_value.deinit(allocator);
178178 }
179179
180 pub fn format(self: *const Value, writer: *std.io.Writer) std.io.Writer.Error!void {
180 pub fn format(self: *const Value, writer: *std.Io.Writer) std.Io.Writer.Error!void {
181181 const raw = self.base.tree.getRaw(self.base.start, self.base.end);
182182 return std.fmt.format(writer, "{s}", .{raw});
183183 }
src/main.zig-1
......@@ -1,7 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const assert = std.debug.assert;
4const io = std.io;
54const fs = std.fs;
65const mem = std.mem;
76const process = std.process;
src/print_targets.zig-1
......@@ -1,6 +1,5 @@
11const std = @import("std");
22const fs = std.fs;
3const io = std.io;
43const mem = std.mem;
54const meta = std.meta;
65const fatal = std.process.fatal;
src/print_value.zig+10-9
......@@ -9,6 +9,7 @@ const Sema = @import("Sema.zig");
99const InternPool = @import("InternPool.zig");
1010const Allocator = std.mem.Allocator;
1111const Target = std.Target;
12const Writer = std.Io.Writer;
1213
1314const max_aggregate_items = 100;
1415const max_string_len = 256;
......@@ -20,7 +21,7 @@ pub const FormatContext = struct {
2021 depth: u8,
2122};
2223
23pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
24pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {
2425 const sema = ctx.opt_sema.?;
2526 return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {
2627 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
......@@ -30,7 +31,7 @@ pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Erro
3031 };
3132}
3233
33pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void {
34pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {
3435 std.debug.assert(ctx.opt_sema == null);
3536 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
3637 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
......@@ -41,11 +42,11 @@ pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!vo
4142
4243pub fn print(
4344 val: Value,
44 writer: *std.io.Writer,
45 writer: *Writer,
4546 level: u8,
4647 pt: Zcu.PerThread,
4748 opt_sema: ?*Sema,
48) (std.io.Writer.Error || Zcu.CompileError)!void {
49) (Writer.Error || Zcu.CompileError)!void {
4950 const zcu = pt.zcu;
5051 const ip = &zcu.intern_pool;
5152 switch (ip.indexToKey(val.toIntern())) {
......@@ -184,11 +185,11 @@ fn printAggregate(
184185 val: Value,
185186 aggregate: InternPool.Key.Aggregate,
186187 is_ref: bool,
187 writer: *std.io.Writer,
188 writer: *Writer,
188189 level: u8,
189190 pt: Zcu.PerThread,
190191 opt_sema: ?*Sema,
191) (std.io.Writer.Error || Zcu.CompileError)!void {
192) (Writer.Error || Zcu.CompileError)!void {
192193 if (level == 0) {
193194 if (is_ref) try writer.writeByte('&');
194195 return writer.writeAll(".{ ... }");
......@@ -270,11 +271,11 @@ fn printPtr(
270271 ptr_val: Value,
271272 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
272273 want_kind: ?PrintPtrKind,
273 writer: *std.io.Writer,
274 writer: *Writer,
274275 level: u8,
275276 pt: Zcu.PerThread,
276277 opt_sema: ?*Sema,
277) (std.io.Writer.Error || Zcu.CompileError)!void {
278) (Writer.Error || Zcu.CompileError)!void {
278279 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
279280 .undef => return writer.writeAll("undefined"),
280281 .ptr => |ptr| ptr,
......@@ -316,7 +317,7 @@ const PrintPtrKind = enum { lvalue, rvalue };
316317/// Returns the root derivation, which may be ignored.
317318pub fn printPtrDerivation(
318319 derivation: Value.PointerDeriveStep,
319 writer: *std.io.Writer,
320 writer: *Writer,
320321 pt: Zcu.PerThread,
321322 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
322323 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as
src/print_zir.zig+106-106
......@@ -10,7 +10,7 @@ const Zcu = @import("Zcu.zig");
1010const LazySrcLoc = Zcu.LazySrcLoc;
1111
1212/// Write human-readable, debug formatted ZIR code.
13pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.io.Writer) !void {
13pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.Io.Writer) !void {
1414 var arena = std.heap.ArenaAllocator.init(gpa);
1515 defer arena.deinit();
1616
......@@ -57,7 +57,7 @@ pub fn renderInstructionContext(
5757 scope_file: *Zcu.File,
5858 parent_decl_node: Ast.Node.Index,
5959 indent: u32,
60 bw: *std.io.Writer,
60 bw: *std.Io.Writer,
6161) !void {
6262 var arena = std.heap.ArenaAllocator.init(gpa);
6363 defer arena.deinit();
......@@ -89,7 +89,7 @@ pub fn renderSingleInstruction(
8989 scope_file: *Zcu.File,
9090 parent_decl_node: Ast.Node.Index,
9191 indent: u32,
92 bw: *std.io.Writer,
92 bw: *std.Io.Writer,
9393) !void {
9494 var arena = std.heap.ArenaAllocator.init(gpa);
9595 defer arena.deinit();
......@@ -176,11 +176,11 @@ const Writer = struct {
176176 }
177177 } = .{},
178178
179 const Error = std.io.Writer.Error || Allocator.Error;
179 const Error = std.Io.Writer.Error || Allocator.Error;
180180
181181 fn writeInstToStream(
182182 self: *Writer,
183 stream: *std.io.Writer,
183 stream: *std.Io.Writer,
184184 inst: Zir.Inst.Index,
185185 ) Error!void {
186186 const tags = self.code.instructions.items(.tag);
......@@ -508,7 +508,7 @@ const Writer = struct {
508508 }
509509 }
510510
511 fn writeExtended(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
511 fn writeExtended(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
512512 const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;
513513 try stream.print("{s}(", .{@tagName(extended.opcode)});
514514 switch (extended.opcode) {
......@@ -616,13 +616,13 @@ const Writer = struct {
616616 }
617617 }
618618
619 fn writeExtNode(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
619 fn writeExtNode(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
620620 try stream.writeAll(")) ");
621621 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
622622 try self.writeSrcNode(stream, src_node);
623623 }
624624
625 fn writeArrayInitElemType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
625 fn writeArrayInitElemType(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
626626 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
627627 try self.writeInstRef(stream, inst_data.lhs);
628628 try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});
......@@ -630,7 +630,7 @@ const Writer = struct {
630630
631631 fn writeUnNode(
632632 self: *Writer,
633 stream: *std.io.Writer,
633 stream: *std.Io.Writer,
634634 inst: Zir.Inst.Index,
635635 ) Error!void {
636636 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
......@@ -641,7 +641,7 @@ const Writer = struct {
641641
642642 fn writeUnTok(
643643 self: *Writer,
644 stream: *std.io.Writer,
644 stream: *std.Io.Writer,
645645 inst: Zir.Inst.Index,
646646 ) Error!void {
647647 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
......@@ -652,7 +652,7 @@ const Writer = struct {
652652
653653 fn writeValidateDestructure(
654654 self: *Writer,
655 stream: *std.io.Writer,
655 stream: *std.Io.Writer,
656656 inst: Zir.Inst.Index,
657657 ) Error!void {
658658 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -666,7 +666,7 @@ const Writer = struct {
666666
667667 fn writeValidateArrayInitTy(
668668 self: *Writer,
669 stream: *std.io.Writer,
669 stream: *std.Io.Writer,
670670 inst: Zir.Inst.Index,
671671 ) Error!void {
672672 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -678,7 +678,7 @@ const Writer = struct {
678678
679679 fn writeArrayTypeSentinel(
680680 self: *Writer,
681 stream: *std.io.Writer,
681 stream: *std.Io.Writer,
682682 inst: Zir.Inst.Index,
683683 ) Error!void {
684684 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -694,7 +694,7 @@ const Writer = struct {
694694
695695 fn writePtrType(
696696 self: *Writer,
697 stream: *std.io.Writer,
697 stream: *std.Io.Writer,
698698 inst: Zir.Inst.Index,
699699 ) Error!void {
700700 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
......@@ -737,12 +737,12 @@ const Writer = struct {
737737 try self.writeSrcNode(stream, extra.data.src_node);
738738 }
739739
740 fn writeInt(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
740 fn writeInt(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
741741 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;
742742 try stream.print("{d})", .{inst_data});
743743 }
744744
745 fn writeIntBig(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
745 fn writeIntBig(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
746746 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
747747 const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);
748748 const limb_bytes = self.code.string_bytes[@intFromEnum(inst_data.start)..][0..byte_count];
......@@ -761,12 +761,12 @@ const Writer = struct {
761761 try stream.print("{s})", .{as_string});
762762 }
763763
764 fn writeFloat(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
764 fn writeFloat(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
765765 const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;
766766 try stream.print("{d})", .{number});
767767 }
768768
769 fn writeFloat128(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
769 fn writeFloat128(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
770770 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
771771 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
772772 const number = extra.get();
......@@ -777,7 +777,7 @@ const Writer = struct {
777777
778778 fn writeStr(
779779 self: *Writer,
780 stream: *std.io.Writer,
780 stream: *std.Io.Writer,
781781 inst: Zir.Inst.Index,
782782 ) Error!void {
783783 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
......@@ -785,7 +785,7 @@ const Writer = struct {
785785 try stream.print("\"{f}\")", .{std.zig.fmtString(str)});
786786 }
787787
788 fn writeSliceStart(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
788 fn writeSliceStart(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
789789 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
790790 const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
791791 try self.writeInstRef(stream, extra.lhs);
......@@ -795,7 +795,7 @@ const Writer = struct {
795795 try self.writeSrcNode(stream, inst_data.src_node);
796796 }
797797
798 fn writeSliceEnd(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
798 fn writeSliceEnd(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
799799 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
800800 const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
801801 try self.writeInstRef(stream, extra.lhs);
......@@ -807,7 +807,7 @@ const Writer = struct {
807807 try self.writeSrcNode(stream, inst_data.src_node);
808808 }
809809
810 fn writeSliceSentinel(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
810 fn writeSliceSentinel(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
811811 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
812812 const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
813813 try self.writeInstRef(stream, extra.lhs);
......@@ -821,7 +821,7 @@ const Writer = struct {
821821 try self.writeSrcNode(stream, inst_data.src_node);
822822 }
823823
824 fn writeSliceLength(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
824 fn writeSliceLength(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
825825 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
826826 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
827827 try self.writeInstRef(stream, extra.lhs);
......@@ -837,7 +837,7 @@ const Writer = struct {
837837 try self.writeSrcNode(stream, inst_data.src_node);
838838 }
839839
840 fn writeUnionInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
840 fn writeUnionInit(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
841841 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
842842 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
843843 try self.writeInstRef(stream, extra.union_type);
......@@ -849,7 +849,7 @@ const Writer = struct {
849849 try self.writeSrcNode(stream, inst_data.src_node);
850850 }
851851
852 fn writeShuffle(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
852 fn writeShuffle(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
853853 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
854854 const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
855855 try self.writeInstRef(stream, extra.elem_type);
......@@ -863,7 +863,7 @@ const Writer = struct {
863863 try self.writeSrcNode(stream, inst_data.src_node);
864864 }
865865
866 fn writeSelect(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
866 fn writeSelect(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
867867 const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data;
868868 try self.writeInstRef(stream, extra.elem_type);
869869 try stream.writeAll(", ");
......@@ -876,7 +876,7 @@ const Writer = struct {
876876 try self.writeSrcNode(stream, extra.node);
877877 }
878878
879 fn writeMulAdd(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
879 fn writeMulAdd(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
880880 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
881881 const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
882882 try self.writeInstRef(stream, extra.mulend1);
......@@ -888,7 +888,7 @@ const Writer = struct {
888888 try self.writeSrcNode(stream, inst_data.src_node);
889889 }
890890
891 fn writeBuiltinCall(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
891 fn writeBuiltinCall(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
892892 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
893893 const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
894894
......@@ -904,7 +904,7 @@ const Writer = struct {
904904 try self.writeSrcNode(stream, inst_data.src_node);
905905 }
906906
907 fn writeFieldParentPtr(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
907 fn writeFieldParentPtr(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
908908 const extra = self.code.extraData(Zir.Inst.FieldParentPtr, extended.operand).data;
909909 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
910910 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
......@@ -921,7 +921,7 @@ const Writer = struct {
921921 try self.writeSrcNode(stream, extra.src_node);
922922 }
923923
924 fn writeParam(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
924 fn writeParam(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
925925 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
926926 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
927927 const body = self.code.bodySlice(extra.end, extra.data.type.body_len);
......@@ -936,7 +936,7 @@ const Writer = struct {
936936 try self.writeSrcTok(stream, inst_data.src_tok);
937937 }
938938
939 fn writePlNodeBin(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
939 fn writePlNodeBin(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
940940 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
941941 const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
942942 try self.writeInstRef(stream, extra.lhs);
......@@ -946,7 +946,7 @@ const Writer = struct {
946946 try self.writeSrcNode(stream, inst_data.src_node);
947947 }
948948
949 fn writePlNodeMultiOp(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
949 fn writePlNodeMultiOp(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
950950 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
951951 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
952952 const args = self.code.refSlice(extra.end, extra.data.operands_len);
......@@ -959,7 +959,7 @@ const Writer = struct {
959959 try self.writeSrcNode(stream, inst_data.src_node);
960960 }
961961
962 fn writeArrayMul(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
962 fn writeArrayMul(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
963963 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
964964 const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
965965 try self.writeInstRef(stream, extra.res_ty);
......@@ -971,13 +971,13 @@ const Writer = struct {
971971 try self.writeSrcNode(stream, inst_data.src_node);
972972 }
973973
974 fn writeElemValImm(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
974 fn writeElemValImm(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
975975 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
976976 try self.writeInstRef(stream, inst_data.operand);
977977 try stream.print(", {d})", .{inst_data.idx});
978978 }
979979
980 fn writeArrayInitElemPtr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
980 fn writeArrayInitElemPtr(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
981981 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
982982 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
983983
......@@ -986,7 +986,7 @@ const Writer = struct {
986986 try self.writeSrcNode(stream, inst_data.src_node);
987987 }
988988
989 fn writePlNodeExport(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
989 fn writePlNodeExport(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
990990 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
991991 const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
992992
......@@ -997,7 +997,7 @@ const Writer = struct {
997997 try self.writeSrcNode(stream, inst_data.src_node);
998998 }
999999
1000 fn writeValidateArrayInitRefTy(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1000 fn writeValidateArrayInitRefTy(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
10011001 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10021002 const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;
10031003
......@@ -1007,7 +1007,7 @@ const Writer = struct {
10071007 try self.writeSrcNode(stream, inst_data.src_node);
10081008 }
10091009
1010 fn writeStructInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1010 fn writeStructInit(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
10111011 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10121012 const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
10131013 var field_i: u32 = 0;
......@@ -1031,7 +1031,7 @@ const Writer = struct {
10311031 try self.writeSrcNode(stream, inst_data.src_node);
10321032 }
10331033
1034 fn writeCmpxchg(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1034 fn writeCmpxchg(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10351035 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
10361036
10371037 try self.writeInstRef(stream, extra.ptr);
......@@ -1047,7 +1047,7 @@ const Writer = struct {
10471047 try self.writeSrcNode(stream, extra.node);
10481048 }
10491049
1050 fn writePtrCastFull(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1050 fn writePtrCastFull(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10511051 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
10521052 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10531053 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
......@@ -1063,7 +1063,7 @@ const Writer = struct {
10631063 try self.writeSrcNode(stream, extra.node);
10641064 }
10651065
1066 fn writePtrCastNoDest(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1066 fn writePtrCastNoDest(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10671067 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
10681068 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10691069 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
......@@ -1074,7 +1074,7 @@ const Writer = struct {
10741074 try self.writeSrcNode(stream, extra.node);
10751075 }
10761076
1077 fn writeAtomicLoad(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1077 fn writeAtomicLoad(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
10781078 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10791079 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
10801080
......@@ -1087,7 +1087,7 @@ const Writer = struct {
10871087 try self.writeSrcNode(stream, inst_data.src_node);
10881088 }
10891089
1090 fn writeAtomicStore(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1090 fn writeAtomicStore(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
10911091 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10921092 const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
10931093
......@@ -1100,7 +1100,7 @@ const Writer = struct {
11001100 try self.writeSrcNode(stream, inst_data.src_node);
11011101 }
11021102
1103 fn writeAtomicRmw(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1103 fn writeAtomicRmw(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
11041104 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11051105 const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
11061106
......@@ -1115,7 +1115,7 @@ const Writer = struct {
11151115 try self.writeSrcNode(stream, inst_data.src_node);
11161116 }
11171117
1118 fn writeStructInitAnon(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1118 fn writeStructInitAnon(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
11191119 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11201120 const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
11211121 var field_i: u32 = 0;
......@@ -1136,7 +1136,7 @@ const Writer = struct {
11361136 try self.writeSrcNode(stream, inst_data.src_node);
11371137 }
11381138
1139 fn writeStructInitFieldType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1139 fn writeStructInitFieldType(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
11401140 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11411141 const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
11421142 try self.writeInstRef(stream, extra.container_type);
......@@ -1145,7 +1145,7 @@ const Writer = struct {
11451145 try self.writeSrcNode(stream, inst_data.src_node);
11461146 }
11471147
1148 fn writeFieldTypeRef(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1148 fn writeFieldTypeRef(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
11491149 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11501150 const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
11511151 try self.writeInstRef(stream, extra.container_type);
......@@ -1155,7 +1155,7 @@ const Writer = struct {
11551155 try self.writeSrcNode(stream, inst_data.src_node);
11561156 }
11571157
1158 fn writeNodeMultiOp(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1158 fn writeNodeMultiOp(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
11591159 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
11601160 const operands = self.code.refSlice(extra.end, extended.small);
11611161
......@@ -1169,7 +1169,7 @@ const Writer = struct {
11691169
11701170 fn writeInstNode(
11711171 self: *Writer,
1172 stream: *std.io.Writer,
1172 stream: *std.Io.Writer,
11731173 inst: Zir.Inst.Index,
11741174 ) Error!void {
11751175 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
......@@ -1180,7 +1180,7 @@ const Writer = struct {
11801180
11811181 fn writeAsm(
11821182 self: *Writer,
1183 stream: *std.io.Writer,
1183 stream: *std.Io.Writer,
11841184 extended: Zir.Inst.Extended.InstData,
11851185 tmpl_is_expr: bool,
11861186 ) !void {
......@@ -1258,7 +1258,7 @@ const Writer = struct {
12581258 try self.writeSrcNode(stream, extra.data.src_node);
12591259 }
12601260
1261 fn writeOverflowArithmetic(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1261 fn writeOverflowArithmetic(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
12621262 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
12631263
12641264 try self.writeInstRef(stream, extra.lhs);
......@@ -1270,7 +1270,7 @@ const Writer = struct {
12701270
12711271 fn writeCall(
12721272 self: *Writer,
1273 stream: *std.io.Writer,
1273 stream: *std.Io.Writer,
12741274 inst: Zir.Inst.Index,
12751275 comptime kind: enum { direct, field },
12761276 ) !void {
......@@ -1321,7 +1321,7 @@ const Writer = struct {
13211321 try self.writeSrcNode(stream, inst_data.src_node);
13221322 }
13231323
1324 fn writeBlock(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1324 fn writeBlock(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
13251325 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13261326 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
13271327 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1330,7 +1330,7 @@ const Writer = struct {
13301330 try self.writeSrcNode(stream, inst_data.src_node);
13311331 }
13321332
1333 fn writeBlockComptime(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1333 fn writeBlockComptime(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
13341334 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13351335 const extra = self.code.extraData(Zir.Inst.BlockComptime, inst_data.payload_index);
13361336 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1340,7 +1340,7 @@ const Writer = struct {
13401340 try self.writeSrcNode(stream, inst_data.src_node);
13411341 }
13421342
1343 fn writeCondBr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1343 fn writeCondBr(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
13441344 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13451345 const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
13461346 const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);
......@@ -1354,7 +1354,7 @@ const Writer = struct {
13541354 try self.writeSrcNode(stream, inst_data.src_node);
13551355 }
13561356
1357 fn writeTry(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1357 fn writeTry(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
13581358 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13591359 const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);
13601360 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1365,7 +1365,7 @@ const Writer = struct {
13651365 try self.writeSrcNode(stream, inst_data.src_node);
13661366 }
13671367
1368 fn writeStructDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1368 fn writeStructDecl(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
13691369 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
13701370
13711371 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);
......@@ -1557,7 +1557,7 @@ const Writer = struct {
15571557 try self.writeSrcNode(stream, .zero);
15581558 }
15591559
1560 fn writeUnionDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1560 fn writeUnionDecl(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
15611561 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
15621562
15631563 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);
......@@ -1708,7 +1708,7 @@ const Writer = struct {
17081708 try self.writeSrcNode(stream, .zero);
17091709 }
17101710
1711 fn writeEnumDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1711 fn writeEnumDecl(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
17121712 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17131713
17141714 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);
......@@ -1829,7 +1829,7 @@ const Writer = struct {
18291829
18301830 fn writeOpaqueDecl(
18311831 self: *Writer,
1832 stream: *std.io.Writer,
1832 stream: *std.Io.Writer,
18331833 extended: Zir.Inst.Extended.InstData,
18341834 ) !void {
18351835 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
......@@ -1871,7 +1871,7 @@ const Writer = struct {
18711871 try self.writeSrcNode(stream, .zero);
18721872 }
18731873
1874 fn writeTupleDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
1874 fn writeTupleDecl(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
18751875 const fields_len = extended.small;
18761876 assert(fields_len != 0);
18771877 const extra = self.code.extraData(Zir.Inst.TupleDecl, extended.operand);
......@@ -1899,7 +1899,7 @@ const Writer = struct {
18991899
19001900 fn writeErrorSetDecl(
19011901 self: *Writer,
1902 stream: *std.io.Writer,
1902 stream: *std.Io.Writer,
19031903 inst: Zir.Inst.Index,
19041904 ) !void {
19051905 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -1924,7 +1924,7 @@ const Writer = struct {
19241924 try self.writeSrcNode(stream, inst_data.src_node);
19251925 }
19261926
1927 fn writeSwitchBlockErrUnion(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
1927 fn writeSwitchBlockErrUnion(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
19281928 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19291929 const extra = self.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
19301930
......@@ -2061,7 +2061,7 @@ const Writer = struct {
20612061 try self.writeSrcNode(stream, inst_data.src_node);
20622062 }
20632063
2064 fn writeSwitchBlock(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2064 fn writeSwitchBlock(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
20652065 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20662066 const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
20672067
......@@ -2242,7 +2242,7 @@ const Writer = struct {
22422242 try self.writeSrcNode(stream, inst_data.src_node);
22432243 }
22442244
2245 fn writePlNodeField(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2245 fn writePlNodeField(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
22462246 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22472247 const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
22482248 const name = self.code.nullTerminatedString(extra.field_name_start);
......@@ -2251,7 +2251,7 @@ const Writer = struct {
22512251 try self.writeSrcNode(stream, inst_data.src_node);
22522252 }
22532253
2254 fn writePlNodeFieldNamed(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2254 fn writePlNodeFieldNamed(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
22552255 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22562256 const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
22572257 try self.writeInstRef(stream, extra.lhs);
......@@ -2261,7 +2261,7 @@ const Writer = struct {
22612261 try self.writeSrcNode(stream, inst_data.src_node);
22622262 }
22632263
2264 fn writeAs(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2264 fn writeAs(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
22652265 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22662266 const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
22672267 try self.writeInstRef(stream, extra.dest_type);
......@@ -2273,7 +2273,7 @@ const Writer = struct {
22732273
22742274 fn writeNode(
22752275 self: *Writer,
2276 stream: *std.io.Writer,
2276 stream: *std.Io.Writer,
22772277 inst: Zir.Inst.Index,
22782278 ) Error!void {
22792279 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
......@@ -2283,7 +2283,7 @@ const Writer = struct {
22832283
22842284 fn writeStrTok(
22852285 self: *Writer,
2286 stream: *std.io.Writer,
2286 stream: *std.Io.Writer,
22872287 inst: Zir.Inst.Index,
22882288 ) Error!void {
22892289 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
......@@ -2292,7 +2292,7 @@ const Writer = struct {
22922292 try self.writeSrcTok(stream, inst_data.src_tok);
22932293 }
22942294
2295 fn writeStrOp(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2295 fn writeStrOp(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
22962296 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
22972297 const str = inst_data.getStr(self.code);
22982298 try self.writeInstRef(stream, inst_data.operand);
......@@ -2301,7 +2301,7 @@ const Writer = struct {
23012301
23022302 fn writeFunc(
23032303 self: *Writer,
2304 stream: *std.io.Writer,
2304 stream: *std.Io.Writer,
23052305 inst: Zir.Inst.Index,
23062306 inferred_error_set: bool,
23072307 ) !void {
......@@ -2352,7 +2352,7 @@ const Writer = struct {
23522352 );
23532353 }
23542354
2355 fn writeFuncFancy(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2355 fn writeFuncFancy(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
23562356 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23572357 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
23582358
......@@ -2411,7 +2411,7 @@ const Writer = struct {
24112411 );
24122412 }
24132413
2414 fn writeAllocExtended(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2414 fn writeAllocExtended(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
24152415 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
24162416 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
24172417
......@@ -2434,7 +2434,7 @@ const Writer = struct {
24342434 try self.writeSrcNode(stream, extra.data.src_node);
24352435 }
24362436
2437 fn writeTypeofPeer(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2437 fn writeTypeofPeer(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
24382438 const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
24392439 const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);
24402440 try self.writeBracedBody(stream, body);
......@@ -2447,7 +2447,7 @@ const Writer = struct {
24472447 try stream.writeAll("])");
24482448 }
24492449
2450 fn writeBoolBr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2450 fn writeBoolBr(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
24512451 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24522452 const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);
24532453 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -2458,7 +2458,7 @@ const Writer = struct {
24582458 try self.writeSrcNode(stream, inst_data.src_node);
24592459 }
24602460
2461 fn writeIntType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2461 fn writeIntType(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
24622462 const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
24632463 const prefix: u8 = switch (int_type.signedness) {
24642464 .signed => 'i',
......@@ -2468,7 +2468,7 @@ const Writer = struct {
24682468 try self.writeSrcNode(stream, int_type.src_node);
24692469 }
24702470
2471 fn writeSaveErrRetIndex(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2471 fn writeSaveErrRetIndex(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
24722472 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24732473
24742474 try self.writeInstRef(stream, inst_data.operand);
......@@ -2476,7 +2476,7 @@ const Writer = struct {
24762476 try stream.writeAll(")");
24772477 }
24782478
2479 fn writeRestoreErrRetIndex(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2479 fn writeRestoreErrRetIndex(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
24802480 const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
24812481
24822482 try self.writeInstRef(stream, extra.block);
......@@ -2486,7 +2486,7 @@ const Writer = struct {
24862486 try self.writeSrcNode(stream, extra.src_node);
24872487 }
24882488
2489 fn writeBreak(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2489 fn writeBreak(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
24902490 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
24912491 const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
24922492
......@@ -2496,7 +2496,7 @@ const Writer = struct {
24962496 try stream.writeAll(")");
24972497 }
24982498
2499 fn writeArrayInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2499 fn writeArrayInit(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
25002500 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25012501
25022502 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2512,7 +2512,7 @@ const Writer = struct {
25122512 try self.writeSrcNode(stream, inst_data.src_node);
25132513 }
25142514
2515 fn writeArrayInitAnon(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2515 fn writeArrayInitAnon(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
25162516 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25172517
25182518 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2527,7 +2527,7 @@ const Writer = struct {
25272527 try self.writeSrcNode(stream, inst_data.src_node);
25282528 }
25292529
2530 fn writeArrayInitSent(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2530 fn writeArrayInitSent(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
25312531 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25322532
25332533 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2547,7 +2547,7 @@ const Writer = struct {
25472547 try self.writeSrcNode(stream, inst_data.src_node);
25482548 }
25492549
2550 fn writeUnreachable(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2550 fn writeUnreachable(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
25512551 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
25522552 try stream.writeAll(") ");
25532553 try self.writeSrcNode(stream, inst_data.src_node);
......@@ -2555,7 +2555,7 @@ const Writer = struct {
25552555
25562556 fn writeFuncCommon(
25572557 self: *Writer,
2558 stream: *std.io.Writer,
2558 stream: *std.Io.Writer,
25592559 inferred_error_set: bool,
25602560 var_args: bool,
25612561 is_noinline: bool,
......@@ -2592,19 +2592,19 @@ const Writer = struct {
25922592 try self.writeSrcNode(stream, src_node);
25932593 }
25942594
2595 fn writeDbgStmt(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2595 fn writeDbgStmt(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
25962596 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
25972597 try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });
25982598 }
25992599
2600 fn writeDefer(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2600 fn writeDefer(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
26012601 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
26022602 const body = self.code.bodySlice(inst_data.index, inst_data.len);
26032603 try self.writeBracedBody(stream, body);
26042604 try stream.writeByte(')');
26052605 }
26062606
2607 fn writeDeferErrCode(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2607 fn writeDeferErrCode(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
26082608 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
26092609 const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
26102610
......@@ -2617,7 +2617,7 @@ const Writer = struct {
26172617 try stream.writeByte(')');
26182618 }
26192619
2620 fn writeDeclaration(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2620 fn writeDeclaration(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
26212621 const decl = self.code.getDeclaration(inst);
26222622
26232623 const prev_parent_decl_node = self.parent_decl_node;
......@@ -2673,26 +2673,26 @@ const Writer = struct {
26732673 try self.writeSrcNode(stream, .zero);
26742674 }
26752675
2676 fn writeClosureGet(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2676 fn writeClosureGet(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26772677 try stream.print("{d})) ", .{extended.small});
26782678 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
26792679 try self.writeSrcNode(stream, src_node);
26802680 }
26812681
2682 fn writeBuiltinValue(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2682 fn writeBuiltinValue(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26832683 const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);
26842684 try stream.print("{s})) ", .{@tagName(val)});
26852685 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
26862686 try self.writeSrcNode(stream, src_node);
26872687 }
26882688
2689 fn writeInplaceArithResultTy(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
2689 fn writeInplaceArithResultTy(self: *Writer, stream: *std.Io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26902690 const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small);
26912691 try self.writeInstRef(stream, @enumFromInt(extended.operand));
26922692 try stream.print(", {s}))", .{@tagName(op)});
26932693 }
26942694
2695 fn writeInstRef(self: *Writer, stream: *std.io.Writer, ref: Zir.Inst.Ref) !void {
2695 fn writeInstRef(self: *Writer, stream: *std.Io.Writer, ref: Zir.Inst.Ref) !void {
26962696 if (ref == .none) {
26972697 return stream.writeAll(".none");
26982698 } else if (ref.toIndex()) |i| {
......@@ -2703,12 +2703,12 @@ const Writer = struct {
27032703 }
27042704 }
27052705
2706 fn writeInstIndex(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2706 fn writeInstIndex(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
27072707 _ = self;
27082708 return stream.print("%{d}", .{@intFromEnum(inst)});
27092709 }
27102710
2711 fn writeCaptures(self: *Writer, stream: *std.io.Writer, extra_index: usize, captures_len: u32) !usize {
2711 fn writeCaptures(self: *Writer, stream: *std.Io.Writer, extra_index: usize, captures_len: u32) !usize {
27122712 if (captures_len == 0) {
27132713 try stream.writeAll("{}");
27142714 return extra_index;
......@@ -2728,7 +2728,7 @@ const Writer = struct {
27282728 return extra_index + 2 * captures_len;
27292729 }
27302730
2731 fn writeCapture(self: *Writer, stream: *std.io.Writer, capture: Zir.Inst.Capture) !void {
2731 fn writeCapture(self: *Writer, stream: *std.Io.Writer, capture: Zir.Inst.Capture) !void {
27322732 switch (capture.unwrap()) {
27332733 .nested => |i| return stream.print("[{d}]", .{i}),
27342734 .instruction => |inst| return self.writeInstIndex(stream, inst),
......@@ -2747,7 +2747,7 @@ const Writer = struct {
27472747
27482748 fn writeOptionalInstRef(
27492749 self: *Writer,
2750 stream: *std.io.Writer,
2750 stream: *std.Io.Writer,
27512751 prefix: []const u8,
27522752 inst: Zir.Inst.Ref,
27532753 ) !void {
......@@ -2758,7 +2758,7 @@ const Writer = struct {
27582758
27592759 fn writeOptionalInstRefOrBody(
27602760 self: *Writer,
2761 stream: *std.io.Writer,
2761 stream: *std.Io.Writer,
27622762 prefix: []const u8,
27632763 ref: Zir.Inst.Ref,
27642764 body: []const Zir.Inst.Index,
......@@ -2776,7 +2776,7 @@ const Writer = struct {
27762776
27772777 fn writeFlag(
27782778 self: *Writer,
2779 stream: *std.io.Writer,
2779 stream: *std.Io.Writer,
27802780 name: []const u8,
27812781 flag: bool,
27822782 ) !void {
......@@ -2785,7 +2785,7 @@ const Writer = struct {
27852785 try stream.writeAll(name);
27862786 }
27872787
2788 fn writeSrcNode(self: *Writer, stream: *std.io.Writer, src_node: Ast.Node.Offset) !void {
2788 fn writeSrcNode(self: *Writer, stream: *std.Io.Writer, src_node: Ast.Node.Offset) !void {
27892789 const tree = self.tree orelse return;
27902790 const abs_node = src_node.toAbsolute(self.parent_decl_node);
27912791 const src_span = tree.nodeToSpan(abs_node);
......@@ -2797,7 +2797,7 @@ const Writer = struct {
27972797 });
27982798 }
27992799
2800 fn writeSrcTok(self: *Writer, stream: *std.io.Writer, src_tok: Ast.TokenOffset) !void {
2800 fn writeSrcTok(self: *Writer, stream: *std.Io.Writer, src_tok: Ast.TokenOffset) !void {
28012801 const tree = self.tree orelse return;
28022802 const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));
28032803 const span_start = tree.tokenStart(abs_tok);
......@@ -2810,7 +2810,7 @@ const Writer = struct {
28102810 });
28112811 }
28122812
2813 fn writeSrcTokAbs(self: *Writer, stream: *std.io.Writer, src_tok: Ast.TokenIndex) !void {
2813 fn writeSrcTokAbs(self: *Writer, stream: *std.Io.Writer, src_tok: Ast.TokenIndex) !void {
28142814 const tree = self.tree orelse return;
28152815 const span_start = tree.tokenStart(src_tok);
28162816 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
......@@ -2822,15 +2822,15 @@ const Writer = struct {
28222822 });
28232823 }
28242824
2825 fn writeBracedDecl(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
2825 fn writeBracedDecl(self: *Writer, stream: *std.Io.Writer, body: []const Zir.Inst.Index) !void {
28262826 try self.writeBracedBodyConditional(stream, body, self.recurse_decls);
28272827 }
28282828
2829 fn writeBracedBody(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
2829 fn writeBracedBody(self: *Writer, stream: *std.Io.Writer, body: []const Zir.Inst.Index) !void {
28302830 try self.writeBracedBodyConditional(stream, body, self.recurse_blocks);
28312831 }
28322832
2833 fn writeBracedBodyConditional(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index, enabled: bool) !void {
2833 fn writeBracedBodyConditional(self: *Writer, stream: *std.Io.Writer, body: []const Zir.Inst.Index, enabled: bool) !void {
28342834 if (body.len == 0) {
28352835 try stream.writeAll("{}");
28362836 } else if (enabled) {
......@@ -2859,7 +2859,7 @@ const Writer = struct {
28592859 }
28602860 }
28612861
2862 fn writeBody(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
2862 fn writeBody(self: *Writer, stream: *std.Io.Writer, body: []const Zir.Inst.Index) !void {
28632863 for (body) |inst| {
28642864 try stream.splatByteAll(' ', self.indent);
28652865 try stream.print("%{d} ", .{@intFromEnum(inst)});
......@@ -2868,7 +2868,7 @@ const Writer = struct {
28682868 }
28692869 }
28702870
2871 fn writeImport(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
2871 fn writeImport(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void {
28722872 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
28732873 const extra = self.code.extraData(Zir.Inst.Import, inst_data.payload_index).data;
28742874 try self.writeInstRef(stream, extra.res_ty);
src/print_zoir.zig+1-1
......@@ -113,4 +113,4 @@ const std = @import("std");
113113const assert = std.debug.assert;
114114const Allocator = std.mem.Allocator;
115115const Zoir = std.zig.Zoir;
116const Writer = std.io.Writer;
116const Writer = std.Io.Writer;
test/standalone/simple/cat/main.zig+1-2
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const io = std.io;
32const fs = std.fs;
43const mem = std.mem;
54const warn = std.log.warn;
......@@ -16,7 +15,7 @@ pub fn main() !void {
1615 var catted_anything = false;
1716 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
1817 const stdout = &stdout_writer.interface;
19 var stdin_reader = std.fs.File.stdin().reader(&.{});
18 var stdin_reader = std.fs.File.stdin().readerStreaming(&.{});
2019
2120 const cwd = fs.cwd();
2221