| author | |
| committer | |
| log | b7104231af68c26b850325748a64f15119a2dd69 |
| tree | c83483ec36ae96af5cf429cf8129336fa09ef256 |
| parent | 151314346d7c4ed4da13a0a0146e1016c9ca5dd7 |
| parent | 31a0c2a36a09fd3cd82f061b090fc12c3239dfb1 |
| signature |
std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage187 files changed, 1379 insertions(+), 2136 deletions(-)
build.zig+1-1| ... | ... | @@ -304,7 +304,7 @@ pub fn build(b: *std.Build) !void { |
| 304 | 304 | if (enable_llvm) { |
| 305 | 305 | const cmake_cfg = if (static_llvm) null else blk: { |
| 306 | 306 | if (findConfigH(b, config_h_path_option)) |config_h_path| { |
| 307 | const file_contents = fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable; | |
| 307 | const file_contents = fs.cwd().readFileAlloc(config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable; | |
| 308 | 308 | break :blk parseConfigH(b, file_contents); |
| 309 | 309 | } else { |
| 310 | 310 | std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{}); |
lib/compiler/aro/aro/Attribute/names.zig+2-3| ... | ... | @@ -117,8 +117,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 { |
| 117 | 117 | |
| 118 | 118 | var node_index: u16 = 0; |
| 119 | 119 | var count: u16 = index; |
| 120 | var fbs = std.io.fixedBufferStream(buf); | |
| 121 | const w = fbs.writer(); | |
| 120 | var w: std.Io.Writer = .fixed(buf); | |
| 122 | 121 | |
| 123 | 122 | while (true) { |
| 124 | 123 | var sibling_index = dafsa[node_index].child_index; |
| ... | ... | @@ -140,7 +139,7 @@ pub fn nameFromUniqueIndex(index: u16, buf: []u8) []u8 { |
| 140 | 139 | if (count == 0) break; |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | return fbs.getWritten(); | |
| 142 | return w.buffered(); | |
| 144 | 143 | } |
| 145 | 144 | |
| 146 | 145 | const Node = packed struct(u32) { |
lib/compiler/aro/aro/Compilation.zig+6-24| ... | ... | @@ -1308,13 +1308,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin |
| 1308 | 1308 | return error.FileNotFound; |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | const file = try comp.cwd.openFile(path, .{}); | |
| 1312 | defer file.close(); | |
| 1313 | ||
| 1314 | const contents = file.readToEndAlloc(comp.gpa, std.math.maxInt(u32)) catch |err| switch (err) { | |
| 1315 | error.FileTooBig => return error.StreamTooLong, | |
| 1316 | else => |e| return e, | |
| 1317 | }; | |
| 1311 | const contents = try comp.cwd.readFileAlloc(path, comp.gpa, .limited(std.math.maxInt(u32))); | |
| 1318 | 1312 | errdefer comp.gpa.free(contents); |
| 1319 | 1313 | |
| 1320 | 1314 | return comp.addSourceFromOwnedBuffer(contents, path, kind); |
| ... | ... | @@ -1433,19 +1427,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u |
| 1433 | 1427 | return error.FileNotFound; |
| 1434 | 1428 | } |
| 1435 | 1429 | |
| 1436 | const file = try comp.cwd.openFile(path, .{}); | |
| 1437 | defer file.close(); | |
| 1438 | ||
| 1439 | var buf = std.array_list.Managed(u8).init(comp.gpa); | |
| 1440 | defer buf.deinit(); | |
| 1441 | ||
| 1442 | const max = limit orelse std.math.maxInt(u32); | |
| 1443 | file.deprecatedReader().readAllArrayList(&buf, max) catch |e| switch (e) { | |
| 1444 | error.StreamTooLong => if (limit == null) return e, | |
| 1445 | else => return e, | |
| 1446 | }; | |
| 1447 | ||
| 1448 | return buf.toOwnedSlice(); | |
| 1430 | return comp.cwd.readFileAlloc(path, comp.gpa, .limited(limit orelse std.math.maxInt(u32))); | |
| 1449 | 1431 | } |
| 1450 | 1432 | |
| 1451 | 1433 | pub fn findEmbed( |
| ... | ... | @@ -1645,8 +1627,8 @@ test "addSourceFromReader" { |
| 1645 | 1627 | var comp = Compilation.init(std.testing.allocator, std.fs.cwd()); |
| 1646 | 1628 | defer comp.deinit(); |
| 1647 | 1629 | |
| 1648 | var buf_reader = std.io.fixedBufferStream(str); | |
| 1649 | const source = try comp.addSourceFromReader(buf_reader.reader(), "path", .user); | |
| 1630 | var buf_reader: std.Io.Reader = .fixed(str); | |
| 1631 | const source = try comp.addSourceFromReader(&buf_reader, "path", .user); | |
| 1650 | 1632 | |
| 1651 | 1633 | try std.testing.expectEqualStrings(expected, source.buf); |
| 1652 | 1634 | try std.testing.expectEqual(warning_count, @as(u32, @intCast(comp.diagnostics.list.items.len))); |
| ... | ... | @@ -1727,8 +1709,8 @@ test "ignore BOM at beginning of file" { |
| 1727 | 1709 | var comp = Compilation.init(std.testing.allocator, std.fs.cwd()); |
| 1728 | 1710 | defer comp.deinit(); |
| 1729 | 1711 | |
| 1730 | var buf_reader = std.io.fixedBufferStream(buf); | |
| 1731 | const source = try comp.addSourceFromReader(buf_reader.reader(), "file.c", .user); | |
| 1712 | var buf_reader: std.Io.Reader = .fixed(buf); | |
| 1713 | const source = try comp.addSourceFromReader(&buf_reader, "file.c", .user); | |
| 1732 | 1714 | const expected_output = if (mem.startsWith(u8, buf, BOM)) buf[BOM.len..] else buf; |
| 1733 | 1715 | try std.testing.expectEqualStrings(expected_output, source.buf); |
| 1734 | 1716 | } |
lib/compiler/aro/aro/Diagnostics.zig+7-7| ... | ... | @@ -322,14 +322,14 @@ pub fn addExtra( |
| 322 | 322 | return error.FatalError; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | pub fn render(comp: *Compilation, config: std.io.tty.Config) void { | |
| 325 | pub fn render(comp: *Compilation, config: std.Io.tty.Config) void { | |
| 326 | 326 | if (comp.diagnostics.list.items.len == 0) return; |
| 327 | 327 | var buffer: [1000]u8 = undefined; |
| 328 | 328 | var m = defaultMsgWriter(config, &buffer); |
| 329 | 329 | defer m.deinit(); |
| 330 | 330 | renderMessages(comp, &m); |
| 331 | 331 | } |
| 332 | pub fn defaultMsgWriter(config: std.io.tty.Config, buffer: []u8) MsgWriter { | |
| 332 | pub fn defaultMsgWriter(config: std.Io.tty.Config, buffer: []u8) MsgWriter { | |
| 333 | 333 | return MsgWriter.init(config, buffer); |
| 334 | 334 | } |
| 335 | 335 | |
| ... | ... | @@ -451,7 +451,7 @@ pub fn renderMessage(comp: *Compilation, m: anytype, msg: Message) void { |
| 451 | 451 | }, |
| 452 | 452 | .normalized => { |
| 453 | 453 | 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 { | |
| 455 | 455 | var it: std.unicode.Utf8Iterator = .{ |
| 456 | 456 | .bytes = bytes, |
| 457 | 457 | .i = 0, |
| ... | ... | @@ -526,10 +526,10 @@ fn tagKind(d: *Diagnostics, tag: Tag, langopts: LangOpts) Kind { |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | const MsgWriter = struct { |
| 529 | writer: *std.io.Writer, | |
| 530 | config: std.io.tty.Config, | |
| 529 | writer: *std.Io.Writer, | |
| 530 | config: std.Io.tty.Config, | |
| 531 | 531 | |
| 532 | fn init(config: std.io.tty.Config, buffer: []u8) MsgWriter { | |
| 532 | fn init(config: std.Io.tty.Config, buffer: []u8) MsgWriter { | |
| 533 | 533 | return .{ |
| 534 | 534 | .writer = std.debug.lockStderrWriter(buffer), |
| 535 | 535 | .config = config, |
| ... | ... | @@ -549,7 +549,7 @@ const MsgWriter = struct { |
| 549 | 549 | m.writer.writeAll(msg) catch {}; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | fn setColor(m: *MsgWriter, color: std.io.tty.Color) void { | |
| 552 | fn setColor(m: *MsgWriter, color: std.Io.tty.Color) void { | |
| 553 | 553 | m.config.setColor(m.writer, color) catch {}; |
| 554 | 554 | } |
| 555 | 555 |
lib/compiler/aro/aro/Driver.zig+3-3| ... | ... | @@ -519,8 +519,8 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 { |
| 519 | 519 | |
| 520 | 520 | fn addSource(d: *Driver, path: []const u8) !Source { |
| 521 | 521 | if (mem.eql(u8, "-", path)) { |
| 522 | const stdin = std.fs.File.stdin().deprecatedReader(); | |
| 523 | const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32)); | |
| 522 | var stdin_reader: std.fs.File.Reader = .initStreaming(.stdin(), &.{}); | |
| 523 | const input = try stdin_reader.interface.allocRemaining(d.comp.gpa, .limited(std.math.maxInt(u32))); | |
| 524 | 524 | defer d.comp.gpa.free(input); |
| 525 | 525 | return d.comp.addSourceFromBuffer("<stdin>", input); |
| 526 | 526 | } |
| ... | ... | @@ -544,7 +544,7 @@ pub fn renderErrors(d: *Driver) void { |
| 544 | 544 | Diagnostics.render(d.comp, d.detectConfig(std.fs.File.stderr())); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | pub fn detectConfig(d: *Driver, file: std.fs.File) std.io.tty.Config { | |
| 547 | pub fn detectConfig(d: *Driver, file: std.fs.File) std.Io.tty.Config { | |
| 548 | 548 | if (d.color == true) return .escape_codes; |
| 549 | 549 | if (d.color == false) return .no_color; |
| 550 | 550 |
lib/compiler/aro/aro/Tree.zig+8-8| ... | ... | @@ -800,7 +800,7 @@ pub fn nodeLoc(tree: *const Tree, node: NodeIndex) ?Source.Location { |
| 800 | 800 | return tree.tokens.items(.loc)[@intFromEnum(tok_i)]; |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | pub fn dump(tree: *const Tree, config: std.io.tty.Config, writer: anytype) !void { | |
| 803 | pub fn dump(tree: *const Tree, config: std.Io.tty.Config, writer: anytype) !void { | |
| 804 | 804 | const mapper = tree.comp.string_interner.getFastTypeMapper(tree.comp.gpa) catch tree.comp.string_interner.getSlowTypeMapper(); |
| 805 | 805 | defer mapper.deinit(tree.comp.gpa); |
| 806 | 806 | |
| ... | ... | @@ -855,17 +855,17 @@ fn dumpNode( |
| 855 | 855 | node: NodeIndex, |
| 856 | 856 | level: u32, |
| 857 | 857 | mapper: StringInterner.TypeMapper, |
| 858 | config: std.io.tty.Config, | |
| 858 | config: std.Io.tty.Config, | |
| 859 | 859 | w: anytype, |
| 860 | 860 | ) !void { |
| 861 | 861 | const delta = 2; |
| 862 | 862 | 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; | |
| 869 | 869 | std.debug.assert(node != .none); |
| 870 | 870 | |
| 871 | 871 | 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 { |
| 578 | 578 | // 64 bytes is assumed to be large enough to hold any target triple; increase if necessary |
| 579 | 579 | std.debug.assert(buf.len >= 64); |
| 580 | 580 | |
| 581 | var stream = std.io.fixedBufferStream(buf); | |
| 582 | const writer = stream.writer(); | |
| 581 | var writer: std.Io.Writer = .fixed(buf); | |
| 583 | 582 | |
| 584 | 583 | const llvm_arch = switch (target.cpu.arch) { |
| 585 | 584 | .arm => "arm", |
| ... | ... | @@ -719,7 +718,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 { |
| 719 | 718 | .ohoseabi => "ohoseabi", |
| 720 | 719 | }; |
| 721 | 720 | writer.writeAll(llvm_abi) catch unreachable; |
| 722 | return stream.getWritten(); | |
| 721 | return writer.buffered(); | |
| 723 | 722 | } |
| 724 | 723 | |
| 725 | 724 | test "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 { |
| 374 | 374 | ir.* = undefined; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | const TYPE = std.io.tty.Color.bright_magenta; | |
| 378 | const INST = std.io.tty.Color.bright_cyan; | |
| 379 | const REF = std.io.tty.Color.bright_blue; | |
| 380 | const LITERAL = std.io.tty.Color.bright_green; | |
| 381 | const ATTRIBUTE = std.io.tty.Color.bright_yellow; | |
| 377 | const TYPE = std.Io.tty.Color.bright_magenta; | |
| 378 | const INST = std.Io.tty.Color.bright_cyan; | |
| 379 | const REF = std.Io.tty.Color.bright_blue; | |
| 380 | const LITERAL = std.Io.tty.Color.bright_green; | |
| 381 | const ATTRIBUTE = std.Io.tty.Color.bright_yellow; | |
| 382 | 382 | |
| 383 | 383 | const RefMap = std.AutoArrayHashMap(Ref, void); |
| 384 | 384 | |
| 385 | pub fn dump(ir: *const Ir, gpa: Allocator, config: std.io.tty.Config, w: anytype) !void { | |
| 385 | pub fn dump(ir: *const Ir, gpa: Allocator, config: std.Io.tty.Config, w: anytype) !void { | |
| 386 | 386 | for (ir.decls.keys(), ir.decls.values()) |name, *decl| { |
| 387 | 387 | try ir.dumpDecl(decl, gpa, name, config, w); |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.io.tty.Config, w: anytype) !void { | |
| 391 | fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, config: std.Io.tty.Config, w: anytype) !void { | |
| 392 | 392 | const tags = decl.instructions.items(.tag); |
| 393 | 393 | const data = decl.instructions.items(.data); |
| 394 | 394 | |
| ... | ... | @@ -609,7 +609,7 @@ fn dumpDecl(ir: *const Ir, decl: *const Decl, gpa: Allocator, name: []const u8, |
| 609 | 609 | try w.writeAll("}\n\n"); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype) !void { | |
| 612 | fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void { | |
| 613 | 613 | const ty = ir.interner.get(ty_ref); |
| 614 | 614 | try config.setColor(w, TYPE); |
| 615 | 615 | switch (ty) { |
| ... | ... | @@ -639,7 +639,7 @@ fn writeType(ir: Ir, ty_ref: Interner.Ref, config: std.io.tty.Config, w: anytype |
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype) !void { | |
| 642 | fn writeValue(ir: Ir, val: Interner.Ref, config: std.Io.tty.Config, w: anytype) !void { | |
| 643 | 643 | try config.setColor(w, LITERAL); |
| 644 | 644 | const key = ir.interner.get(val); |
| 645 | 645 | switch (key) { |
| ... | ... | @@ -655,7 +655,7 @@ fn writeValue(ir: Ir, val: Interner.Ref, config: std.io.tty.Config, w: anytype) |
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void { | |
| 658 | fn writeRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void { | |
| 659 | 659 | assert(ref != .none); |
| 660 | 660 | const index = @intFromEnum(ref); |
| 661 | 661 | 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 |
| 678 | 678 | try w.print(" %{d}", .{ref_index}); |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void { | |
| 681 | fn writeNewRef(ir: Ir, decl: *const Decl, ref_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void { | |
| 682 | 682 | try ref_map.put(ref, {}); |
| 683 | 683 | try w.writeAll(" "); |
| 684 | 684 | 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 |
| 687 | 687 | try config.setColor(w, INST); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.io.tty.Config, w: anytype) !void { | |
| 690 | fn writeLabel(decl: *const Decl, label_map: *RefMap, ref: Ref, config: std.Io.tty.Config, w: anytype) !void { | |
| 691 | 691 | assert(ref != .none); |
| 692 | 692 | const index = @intFromEnum(ref); |
| 693 | 693 | 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 { |
| 1783 | 1783 | defer std.process.exit(1); |
| 1784 | 1784 | |
| 1785 | 1785 | 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); | |
| 1787 | 1787 | defer writer.deinit(); // writer deinit must run *before* exit so that stderr is flushed |
| 1788 | 1788 | |
| 1789 | 1789 | var saw_error = false; |
lib/compiler/build_runner.zig+10-10| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const io = std.io; | |
| 5 | 4 | const fmt = std.fmt; |
| 6 | 5 | const mem = std.mem; |
| 7 | 6 | const process = std.process; |
| ... | ... | @@ -11,8 +10,9 @@ const Watch = std.Build.Watch; |
| 11 | 10 | const WebServer = std.Build.WebServer; |
| 12 | 11 | const Allocator = std.mem.Allocator; |
| 13 | 12 | const fatal = std.process.fatal; |
| 14 | const Writer = std.io.Writer; | |
| 13 | const Writer = std.Io.Writer; | |
| 15 | 14 | const runner = @This(); |
| 15 | const tty = std.Io.tty; | |
| 16 | 16 | |
| 17 | 17 | pub const root = @import("@build"); |
| 18 | 18 | pub const dependencies = @import("@dependencies"); |
| ... | ... | @@ -576,7 +576,7 @@ const Run = struct { |
| 576 | 576 | |
| 577 | 577 | claimed_rss: usize, |
| 578 | 578 | summary: Summary, |
| 579 | ttyconf: std.io.tty.Config, | |
| 579 | ttyconf: tty.Config, | |
| 580 | 580 | stderr: File, |
| 581 | 581 | |
| 582 | 582 | fn cleanExit(run: Run) void { |
| ... | ... | @@ -819,7 +819,7 @@ const PrintNode = struct { |
| 819 | 819 | last: bool = false, |
| 820 | 820 | }; |
| 821 | 821 | |
| 822 | fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !void { | |
| 822 | fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: tty.Config) !void { | |
| 823 | 823 | const parent = node.parent orelse return; |
| 824 | 824 | if (parent.parent == null) return; |
| 825 | 825 | try printPrefix(parent, stderr, ttyconf); |
| ... | ... | @@ -833,7 +833,7 @@ fn printPrefix(node: *PrintNode, stderr: *Writer, ttyconf: std.io.tty.Config) !v |
| 833 | 833 | } |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void { | |
| 836 | fn printChildNodePrefix(stderr: *Writer, ttyconf: tty.Config) !void { | |
| 837 | 837 | try stderr.writeAll(switch (ttyconf) { |
| 838 | 838 | .no_color, .windows_api => "+- ", |
| 839 | 839 | .escape_codes => "\x1B\x28\x30\x6d\x71\x1B\x28\x42 ", // └─ |
| ... | ... | @@ -843,7 +843,7 @@ fn printChildNodePrefix(stderr: *Writer, ttyconf: std.io.tty.Config) !void { |
| 843 | 843 | fn printStepStatus( |
| 844 | 844 | s: *Step, |
| 845 | 845 | stderr: *Writer, |
| 846 | ttyconf: std.io.tty.Config, | |
| 846 | ttyconf: tty.Config, | |
| 847 | 847 | run: *const Run, |
| 848 | 848 | ) !void { |
| 849 | 849 | switch (s.state) { |
| ... | ... | @@ -923,7 +923,7 @@ fn printStepStatus( |
| 923 | 923 | fn printStepFailure( |
| 924 | 924 | s: *Step, |
| 925 | 925 | stderr: *Writer, |
| 926 | ttyconf: std.io.tty.Config, | |
| 926 | ttyconf: tty.Config, | |
| 927 | 927 | ) !void { |
| 928 | 928 | if (s.result_error_bundle.errorMessageCount() > 0) { |
| 929 | 929 | try ttyconf.setColor(stderr, .red); |
| ... | ... | @@ -977,7 +977,7 @@ fn printTreeStep( |
| 977 | 977 | s: *Step, |
| 978 | 978 | run: *const Run, |
| 979 | 979 | stderr: *Writer, |
| 980 | ttyconf: std.io.tty.Config, | |
| 980 | ttyconf: tty.Config, | |
| 981 | 981 | parent_node: *PrintNode, |
| 982 | 982 | step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void), |
| 983 | 983 | ) !void { |
| ... | ... | @@ -1494,9 +1494,9 @@ fn uncleanExit() error{UncleanExit} { |
| 1494 | 1494 | const Color = std.zig.Color; |
| 1495 | 1495 | const Summary = enum { all, new, failures, none }; |
| 1496 | 1496 | |
| 1497 | fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config { | |
| 1497 | fn get_tty_conf(color: Color, stderr: File) tty.Config { | |
| 1498 | 1498 | return switch (color) { |
| 1499 | .auto => std.io.tty.detectConfig(stderr), | |
| 1499 | .auto => tty.detectConfig(stderr), | |
| 1500 | 1500 | .on => .escape_codes, |
| 1501 | 1501 | .off => .no_color, |
| 1502 | 1502 | }; |
lib/compiler/libc.zig-1| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | const io = std.io; | |
| 4 | 3 | const LibCInstallation = std.zig.LibCInstallation; |
| 5 | 4 | |
| 6 | 5 | const usage_libc = |
lib/compiler/reduce.zig+3-4| ... | ... | @@ -381,7 +381,7 @@ fn transformationsToFixups( |
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | var other_source: std.io.Writer.Allocating = .init(gpa); | |
| 384 | var other_source: std.Io.Writer.Allocating = .init(gpa); | |
| 385 | 385 | defer other_source.deinit(); |
| 386 | 386 | try other_source.writer.writeAll("struct {\n"); |
| 387 | 387 | try other_file_ast.render(gpa, &other_source.writer, inlined_fixups); |
| ... | ... | @@ -398,10 +398,9 @@ fn transformationsToFixups( |
| 398 | 398 | |
| 399 | 399 | fn parse(gpa: Allocator, file_path: []const u8) !Ast { |
| 400 | 400 | const source_code = std.fs.cwd().readFileAllocOptions( |
| 401 | gpa, | |
| 402 | 401 | file_path, |
| 403 | std.math.maxInt(u32), | |
| 404 | null, | |
| 402 | gpa, | |
| 403 | .limited(std.math.maxInt(u32)), | |
| 405 | 404 | .fromByteUnits(1), |
| 406 | 405 | 0, |
| 407 | 406 | ) catch |err| { |
lib/compiler/resinator/ast.zig+3-3| ... | ... | @@ -22,7 +22,7 @@ pub const Tree = struct { |
| 22 | 22 | return @alignCast(@fieldParentPtr("base", self.node)); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | pub fn dump(self: *Tree, writer: *std.io.Writer) !void { | |
| 25 | pub fn dump(self: *Tree, writer: *std.Io.Writer) !void { | |
| 26 | 26 | try self.node.dump(self, writer, 0); |
| 27 | 27 | } |
| 28 | 28 | }; |
| ... | ... | @@ -726,9 +726,9 @@ pub const Node = struct { |
| 726 | 726 | pub fn dump( |
| 727 | 727 | node: *const Node, |
| 728 | 728 | tree: *const Tree, |
| 729 | writer: *std.io.Writer, | |
| 729 | writer: *std.Io.Writer, | |
| 730 | 730 | indent: usize, |
| 731 | ) std.io.Writer.Error!void { | |
| 731 | ) std.Io.Writer.Error!void { | |
| 732 | 732 | try writer.splatByteAll(' ', indent); |
| 733 | 733 | try writer.writeAll(@tagName(node.id)); |
| 734 | 734 | switch (node.id) { |
lib/compiler/resinator/cli.zig+4-4| ... | ... | @@ -124,13 +124,13 @@ pub const Diagnostics = struct { |
| 124 | 124 | try self.errors.append(self.allocator, error_details); |
| 125 | 125 | } |
| 126 | 126 | |
| 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 { | |
| 128 | 128 | const stderr = std.debug.lockStderrWriter(&.{}); |
| 129 | 129 | defer std.debug.unlockStderrWriter(); |
| 130 | 130 | self.renderToWriter(args, stderr, config) catch return; |
| 131 | 131 | } |
| 132 | 132 | |
| 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 { | |
| 134 | 134 | for (self.errors.items) |err_details| { |
| 135 | 135 | try renderErrorMessage(writer, config, err_details, args); |
| 136 | 136 | } |
| ... | ... | @@ -1343,7 +1343,7 @@ test parsePercent { |
| 1343 | 1343 | try std.testing.expectError(error.InvalidFormat, parsePercent("~1")); |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void { | |
| 1346 | pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void { | |
| 1347 | 1347 | try config.setColor(writer, .dim); |
| 1348 | 1348 | try writer.writeAll("<cli>"); |
| 1349 | 1349 | try config.setColor(writer, .reset); |
| ... | ... | @@ -1470,7 +1470,7 @@ fn testParseOutput(args: []const []const u8, expected_output: []const u8) !?Opti |
| 1470 | 1470 | var diagnostics = Diagnostics.init(std.testing.allocator); |
| 1471 | 1471 | defer diagnostics.deinit(); |
| 1472 | 1472 | |
| 1473 | var output: std.io.Writer.Allocating = .init(std.testing.allocator); | |
| 1473 | var output: std.Io.Writer.Allocating = .init(std.testing.allocator); | |
| 1474 | 1474 | defer output.deinit(); |
| 1475 | 1475 | |
| 1476 | 1476 | 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 { |
| 61 | 61 | return @intCast(index); |
| 62 | 62 | } |
| 63 | 63 | |
| 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 { | |
| 65 | 65 | const stderr = std.debug.lockStderrWriter(&.{}); |
| 66 | 66 | defer std.debug.unlockStderrWriter(); |
| 67 | 67 | for (self.errors.items) |err_details| { |
| ... | ... | @@ -70,7 +70,7 @@ pub const Diagnostics = struct { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | 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()); | |
| 74 | 74 | return self.renderToStdErr(cwd, source, tty_config, source_mappings); |
| 75 | 75 | } |
| 76 | 76 | |
| ... | ... | @@ -409,7 +409,7 @@ pub const ErrorDetails = struct { |
| 409 | 409 | failed_to_open_cwd, |
| 410 | 410 | }; |
| 411 | 411 | |
| 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 { | |
| 413 | 413 | switch (ctx.token.id) { |
| 414 | 414 | .eof => return writer.writeAll(ctx.token.id.nameForErrorDisplay()), |
| 415 | 415 | else => {}, |
| ... | ... | @@ -894,7 +894,7 @@ fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usiz |
| 894 | 894 | |
| 895 | 895 | const truncated_str = "<...truncated...>"; |
| 896 | 896 | |
| 897 | pub 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 { | |
| 897 | pub 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 { | |
| 898 | 898 | if (err_details.type == .hint) return; |
| 899 | 899 | |
| 900 | 900 | const source_line_start = err_details.token.getLineStartForErrorDisplay(source); |
lib/compiler/resinator/main.zig+10-6| ... | ... | @@ -24,7 +24,7 @@ pub fn main() !void { |
| 24 | 24 | const arena = arena_state.allocator(); |
| 25 | 25 | |
| 26 | 26 | const stderr = std.fs.File.stderr(); |
| 27 | const stderr_config = std.io.tty.detectConfig(stderr); | |
| 27 | const stderr_config = std.Io.tty.detectConfig(stderr); | |
| 28 | 28 | |
| 29 | 29 | const args = try std.process.argsAlloc(allocator); |
| 30 | 30 | defer std.process.argsFree(allocator, args); |
| ... | ... | @@ -164,13 +164,14 @@ pub fn main() !void { |
| 164 | 164 | } else { |
| 165 | 165 | switch (options.input_source) { |
| 166 | 166 | .stdio => |file| { |
| 167 | break :full_input file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch |err| { | |
| 167 | var file_reader = file.reader(&.{}); | |
| 168 | break :full_input file_reader.interface.allocRemaining(allocator, .unlimited) catch |err| { | |
| 168 | 169 | try error_handler.emitMessage(allocator, .err, "unable to read input from stdin: {s}", .{@errorName(err)}); |
| 169 | 170 | std.process.exit(1); |
| 170 | 171 | }; |
| 171 | 172 | }, |
| 172 | 173 | .filename => |input_filename| { |
| 173 | break :full_input std.fs.cwd().readFileAlloc(allocator, input_filename, std.math.maxInt(usize)) catch |err| { | |
| 174 | break :full_input std.fs.cwd().readFileAlloc(input_filename, allocator, .unlimited) catch |err| { | |
| 174 | 175 | try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) }); |
| 175 | 176 | std.process.exit(1); |
| 176 | 177 | }; |
| ... | ... | @@ -462,7 +463,10 @@ const IoStream = struct { |
| 462 | 463 | pub fn readAll(self: Source, allocator: std.mem.Allocator) !Data { |
| 463 | 464 | return switch (self) { |
| 464 | 465 | inline .file, .stdio => |file| .{ |
| 465 | .bytes = try file.readToEndAlloc(allocator, std.math.maxInt(usize)), | |
| 466 | .bytes = b: { | |
| 467 | var file_reader = file.reader(&.{}); | |
| 468 | break :b try file_reader.interface.allocRemaining(allocator, .unlimited); | |
| 469 | }, | |
| 466 | 470 | .needs_free = true, |
| 467 | 471 | }, |
| 468 | 472 | .memory => |list| .{ .bytes = list.items, .needs_free = false }, |
| ... | ... | @@ -621,7 +625,7 @@ const SourceMappings = @import("source_mapping.zig").SourceMappings; |
| 621 | 625 | |
| 622 | 626 | const ErrorHandler = union(enum) { |
| 623 | 627 | server: std.zig.Server, |
| 624 | tty: std.io.tty.Config, | |
| 628 | tty: std.Io.tty.Config, | |
| 625 | 629 | |
| 626 | 630 | pub fn emitCliDiagnostics( |
| 627 | 631 | self: *ErrorHandler, |
| ... | ... | @@ -984,7 +988,7 @@ const MsgWriter = struct { |
| 984 | 988 | m.buf.appendSlice(msg) catch {}; |
| 985 | 989 | } |
| 986 | 990 | |
| 987 | pub fn setColor(m: *MsgWriter, color: std.io.tty.Color) void { | |
| 991 | pub fn setColor(m: *MsgWriter, color: std.Io.tty.Color) void { | |
| 988 | 992 | _ = m; |
| 989 | 993 | _ = color; |
| 990 | 994 | } |
lib/compiler/resinator/res.zig+3-3| ... | ... | @@ -164,7 +164,7 @@ pub const Language = packed struct(u16) { |
| 164 | 164 | return @bitCast(self); |
| 165 | 165 | } |
| 166 | 166 | |
| 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 { | |
| 168 | 168 | const language_id = language.asInt(); |
| 169 | 169 | const language_name = language_name: { |
| 170 | 170 | if (std.enums.fromInt(lang.LanguageId, language_id)) |lang_enum_val| { |
| ... | ... | @@ -439,7 +439,7 @@ pub const NameOrOrdinal = union(enum) { |
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | pub fn format(self: NameOrOrdinal, w: *std.io.Writer) !void { | |
| 442 | pub fn format(self: NameOrOrdinal, w: *std.Io.Writer) !void { | |
| 443 | 443 | switch (self) { |
| 444 | 444 | .name => |name| { |
| 445 | 445 | try w.print("{f}", .{std.unicode.fmtUtf16Le(name)}); |
| ... | ... | @@ -450,7 +450,7 @@ pub const NameOrOrdinal = union(enum) { |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | |
| 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 { | |
| 454 | 454 | switch (self) { |
| 455 | 455 | .name => |name| { |
| 456 | 456 | try w.print("{f}", .{std.unicode.fmtUtf16Le(name)}); |
lib/compiler/resinator/utils.zig+1-2| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | /// Like std.io.FixedBufferStream but does no bounds checking | |
| 5 | 4 | pub const UncheckedSliceWriter = struct { |
| 6 | 5 | const Self = @This(); |
| 7 | 6 | |
| ... | ... | @@ -86,7 +85,7 @@ pub const ErrorMessageType = enum { err, warning, note }; |
| 86 | 85 | |
| 87 | 86 | /// Used for generic colored errors/warnings/notes, more context-specific error messages |
| 88 | 87 | /// are handled elsewhere. |
| 89 | pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void { | |
| 88 | pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void { | |
| 90 | 89 | switch (msg_type) { |
| 91 | 90 | .err => { |
| 92 | 91 | try config.setColor(writer, .bold); |
lib/compiler/std-docs.zig+3-4| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const mem = std.mem; |
| 4 | const io = std.io; | |
| 5 | 4 | const Allocator = std.mem.Allocator; |
| 6 | 5 | const assert = std.debug.assert; |
| 7 | 6 | const Cache = std.Build.Cache; |
| ... | ... | @@ -174,7 +173,7 @@ fn serveDocsFile( |
| 174 | 173 | // The desired API is actually sendfile, which will require enhancing std.http.Server. |
| 175 | 174 | // We load the file with every request so that the user can make changes to the file |
| 176 | 175 | // and refresh the HTML page without restarting this server. |
| 177 | const file_contents = try context.lib_dir.readFileAlloc(gpa, name, 10 * 1024 * 1024); | |
| 176 | const file_contents = try context.lib_dir.readFileAlloc(name, gpa, .limited(10 * 1024 * 1024)); | |
| 178 | 177 | defer gpa.free(file_contents); |
| 179 | 178 | try request.respond(file_contents, .{ |
| 180 | 179 | .extra_headers = &.{ |
| ... | ... | @@ -264,7 +263,7 @@ fn serveWasm( |
| 264 | 263 | }); |
| 265 | 264 | // std.http.Server does not have a sendfile API yet. |
| 266 | 265 | const bin_path = try wasm_base_path.join(arena, bin_name); |
| 267 | const file_contents = try bin_path.root_dir.handle.readFileAlloc(gpa, bin_path.sub_path, 10 * 1024 * 1024); | |
| 266 | const file_contents = try bin_path.root_dir.handle.readFileAlloc(bin_path.sub_path, gpa, .limited(10 * 1024 * 1024)); | |
| 268 | 267 | defer gpa.free(file_contents); |
| 269 | 268 | try request.respond(file_contents, .{ |
| 270 | 269 | .extra_headers = &.{ |
| ... | ... | @@ -318,7 +317,7 @@ fn buildWasmBinary( |
| 318 | 317 | child.stderr_behavior = .Pipe; |
| 319 | 318 | try child.spawn(); |
| 320 | 319 | |
| 321 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ | |
| 320 | var poller = std.Io.poll(gpa, enum { stdout, stderr }, .{ | |
| 322 | 321 | .stdout = child.stdout.?, |
| 323 | 322 | .stderr = child.stderr.?, |
| 324 | 323 | }); |
lib/fuzzer.zig+1-1| ... | ... | @@ -220,7 +220,7 @@ const Fuzzer = struct { |
| 220 | 220 | const i = f.corpus.items.len; |
| 221 | 221 | var buf: [30]u8 = undefined; |
| 222 | 222 | const input_sub_path = std.fmt.bufPrint(&buf, "{d}", .{i}) catch unreachable; |
| 223 | const input = f.corpus_directory.handle.readFileAlloc(gpa, input_sub_path, 1 << 31) catch |err| switch (err) { | |
| 223 | const input = f.corpus_directory.handle.readFileAlloc(input_sub_path, gpa, .limited(1 << 31)) catch |err| switch (err) { | |
| 224 | 224 | error.FileNotFound => { |
| 225 | 225 | // Make this one the next input. |
| 226 | 226 | const input_file = f.corpus_directory.handle.createFile(input_sub_path, .{ |
lib/std/Build.zig+5-5| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const io = std.io; | |
| 4 | 3 | const fs = std.fs; |
| 5 | 4 | const mem = std.mem; |
| 6 | 5 | const debug = std.debug; |
| ... | ... | @@ -1830,7 +1829,8 @@ pub fn runAllowFail( |
| 1830 | 1829 | try Step.handleVerbose2(b, null, child.env_map, argv); |
| 1831 | 1830 | try child.spawn(); |
| 1832 | 1831 | |
| 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 { | |
| 1834 | 1834 | return error.ReadFailure; |
| 1835 | 1835 | }; |
| 1836 | 1836 | errdefer b.allocator.free(stdout); |
| ... | ... | @@ -2540,7 +2540,7 @@ fn dumpBadDirnameHelp( |
| 2540 | 2540 | |
| 2541 | 2541 | try w.print(msg, args); |
| 2542 | 2542 | |
| 2543 | const tty_config = std.io.tty.detectConfig(.stderr()); | |
| 2543 | const tty_config = std.Io.tty.detectConfig(.stderr()); | |
| 2544 | 2544 | |
| 2545 | 2545 | if (fail_step) |s| { |
| 2546 | 2546 | tty_config.setColor(w, .red) catch {}; |
| ... | ... | @@ -2566,8 +2566,8 @@ fn dumpBadDirnameHelp( |
| 2566 | 2566 | /// In this function the stderr mutex has already been locked. |
| 2567 | 2567 | pub fn dumpBadGetPathHelp( |
| 2568 | 2568 | 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, | |
| 2571 | 2571 | src_builder: *Build, |
| 2572 | 2572 | asking_step: ?*Step, |
| 2573 | 2573 | ) anyerror!void { |
lib/std/Build/Cache.zig+3-3| ... | ... | @@ -286,7 +286,7 @@ pub const HashHelper = struct { |
| 286 | 286 | |
| 287 | 287 | pub fn binToHex(bin_digest: BinDigest) HexDigest { |
| 288 | 288 | var out_digest: HexDigest = undefined; |
| 289 | var w: std.io.Writer = .fixed(&out_digest); | |
| 289 | var w: std.Io.Writer = .fixed(&out_digest); | |
| 290 | 290 | w.printHex(&bin_digest, .lower) catch unreachable; |
| 291 | 291 | return out_digest; |
| 292 | 292 | } |
| ... | ... | @@ -664,7 +664,7 @@ pub const Manifest = struct { |
| 664 | 664 | const input_file_count = self.files.entries.len; |
| 665 | 665 | var tiny_buffer: [1]u8 = undefined; // allows allocRemaining to detect limit exceeded |
| 666 | 666 | 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); | |
| 668 | 668 | const file_contents = manifest_reader.interface.allocRemaining(gpa, limit) catch |err| switch (err) { |
| 669 | 669 | error.OutOfMemory => return error.OutOfMemory, |
| 670 | 670 | error.StreamTooLong => return error.OutOfMemory, |
| ... | ... | @@ -1056,7 +1056,7 @@ pub const Manifest = struct { |
| 1056 | 1056 | |
| 1057 | 1057 | fn addDepFileMaybePost(self: *Manifest, dir: fs.Dir, dep_file_basename: []const u8) !void { |
| 1058 | 1058 | const gpa = self.cache.gpa; |
| 1059 | const dep_file_contents = try dir.readFileAlloc(gpa, dep_file_basename, manifest_file_size_max); | |
| 1059 | const dep_file_contents = try dir.readFileAlloc(dep_file_basename, gpa, .limited(manifest_file_size_max)); | |
| 1060 | 1060 | defer gpa.free(dep_file_contents); |
| 1061 | 1061 | |
| 1062 | 1062 | var error_buf: std.ArrayListUnmanaged(u8) = .empty; |
lib/std/Build/Cache/Directory.zig+1-1| ... | ... | @@ -56,7 +56,7 @@ pub fn closeAndFree(self: *Directory, gpa: Allocator) void { |
| 56 | 56 | self.* = undefined; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | pub fn format(self: Directory, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 59 | pub fn format(self: Directory, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 60 | 60 | if (self.path) |p| { |
| 61 | 61 | try writer.writeAll(p); |
| 62 | 62 | 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) { |
| 151 | 151 | return .{ .data = path }; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | pub fn formatEscapeString(path: Path, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 154 | pub fn formatEscapeString(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 155 | 155 | if (path.root_dir.path) |p| { |
| 156 | 156 | try std.zig.stringEscape(p, writer); |
| 157 | 157 | 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) { |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /// Deprecated, use double quoted escape to print paths. |
| 170 | pub fn formatEscapeChar(path: Path, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 170 | pub fn formatEscapeChar(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 171 | 171 | if (path.root_dir.path) |p| { |
| 172 | 172 | for (p) |byte| try std.zig.charEscape(byte, writer); |
| 173 | 173 | 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! |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | pub fn format(self: Path, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 180 | pub fn format(self: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 181 | 181 | if (std.fs.path.isAbsolute(self.sub_path)) { |
| 182 | 182 | try writer.writeAll(self.sub_path); |
| 183 | 183 | return; |
lib/std/Build/Fuzz.zig+2-2| ... | ... | @@ -127,7 +127,7 @@ pub fn deinit(fuzz: *Fuzz) void { |
| 127 | 127 | gpa.free(fuzz.run_steps); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.io.tty.Config, parent_prog_node: std.Progress.Node) void { | |
| 130 | fn rebuildTestsWorkerRun(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) void { | |
| 131 | 131 | rebuildTestsWorkerRunFallible(run, gpa, ttyconf, parent_prog_node) catch |err| { |
| 132 | 132 | const compile = run.producer.?; |
| 133 | 133 | 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 |
| 136 | 136 | }; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.io.tty.Config, parent_prog_node: std.Progress.Node) !void { | |
| 139 | fn rebuildTestsWorkerRunFallible(run: *Step.Run, gpa: Allocator, ttyconf: std.Io.tty.Config, parent_prog_node: std.Progress.Node) !void { | |
| 140 | 140 | const compile = run.producer.?; |
| 141 | 141 | const prog_node = parent_prog_node.start(compile.step.name, 0); |
| 142 | 142 | defer prog_node.end(); |
lib/std/Build/Step/CheckFile.zig+1-1| ... | ... | @@ -53,7 +53,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 53 | 53 | try step.singleUnchangingWatchInput(check_file.source); |
| 54 | 54 | |
| 55 | 55 | const src_path = check_file.source.getPath2(b, step); |
| 56 | const contents = fs.cwd().readFileAlloc(b.allocator, src_path, check_file.max_bytes) catch |err| { | |
| 56 | const contents = fs.cwd().readFileAlloc(src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| { | |
| 57 | 57 | return step.fail("unable to read '{s}': {s}", .{ |
| 58 | 58 | src_path, @errorName(err), |
| 59 | 59 | }); |
lib/std/Build/Step/CheckObject.zig+139-150| ... | ... | @@ -6,7 +6,7 @@ const macho = std.macho; |
| 6 | 6 | const math = std.math; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const testing = std.testing; |
| 9 | const Writer = std.io.Writer; | |
| 9 | const Writer = std.Io.Writer; | |
| 10 | 10 | |
| 11 | 11 | const CheckObject = @This(); |
| 12 | 12 | |
| ... | ... | @@ -553,14 +553,13 @@ fn make(step: *Step, make_options: Step.MakeOptions) !void { |
| 553 | 553 | |
| 554 | 554 | const src_path = check_object.source.getPath3(b, step); |
| 555 | 555 | const contents = src_path.root_dir.handle.readFileAllocOptions( |
| 556 | gpa, | |
| 557 | 556 | src_path.sub_path, |
| 558 | check_object.max_bytes, | |
| 559 | null, | |
| 557 | gpa, | |
| 558 | .limited(check_object.max_bytes), | |
| 560 | 559 | .of(u64), |
| 561 | 560 | null, |
| 562 | ) catch |err| return step.fail("unable to read '{f}': {s}", .{ | |
| 563 | std.fmt.alt(src_path, .formatEscapeChar), @errorName(err), | |
| 561 | ) catch |err| return step.fail("unable to read '{f}': {t}", .{ | |
| 562 | std.fmt.alt(src_path, .formatEscapeChar), err, | |
| 564 | 563 | }); |
| 565 | 564 | |
| 566 | 565 | var vars: std.StringHashMap(u64) = .init(gpa); |
| ... | ... | @@ -1462,7 +1461,7 @@ const MachODumper = struct { |
| 1462 | 1461 | const TrieIterator = struct { |
| 1463 | 1462 | stream: std.Io.Reader, |
| 1464 | 1463 | |
| 1465 | fn readUleb128(it: *TrieIterator) !u64 { | |
| 1464 | fn takeLeb128(it: *TrieIterator) !u64 { | |
| 1466 | 1465 | return it.stream.takeLeb128(u64); |
| 1467 | 1466 | } |
| 1468 | 1467 | |
| ... | ... | @@ -1470,7 +1469,7 @@ const MachODumper = struct { |
| 1470 | 1469 | return it.stream.takeSentinel(0); |
| 1471 | 1470 | } |
| 1472 | 1471 | |
| 1473 | fn readByte(it: *TrieIterator) !u8 { | |
| 1472 | fn takeByte(it: *TrieIterator) !u8 { | |
| 1474 | 1473 | return it.stream.takeByte(); |
| 1475 | 1474 | } |
| 1476 | 1475 | }; |
| ... | ... | @@ -1518,12 +1517,12 @@ const MachODumper = struct { |
| 1518 | 1517 | prefix: []const u8, |
| 1519 | 1518 | exports: *std.array_list.Managed(Export), |
| 1520 | 1519 | ) !void { |
| 1521 | const size = try it.readUleb128(); | |
| 1520 | const size = try it.takeLeb128(); | |
| 1522 | 1521 | if (size > 0) { |
| 1523 | const flags = try it.readUleb128(); | |
| 1522 | const flags = try it.takeLeb128(); | |
| 1524 | 1523 | switch (flags) { |
| 1525 | 1524 | macho.EXPORT_SYMBOL_FLAGS_REEXPORT => { |
| 1526 | const ord = try it.readUleb128(); | |
| 1525 | const ord = try it.takeLeb128(); | |
| 1527 | 1526 | const name = try arena.dupe(u8, try it.readString()); |
| 1528 | 1527 | try exports.append(.{ |
| 1529 | 1528 | .name = if (name.len > 0) name else prefix, |
| ... | ... | @@ -1532,8 +1531,8 @@ const MachODumper = struct { |
| 1532 | 1531 | }); |
| 1533 | 1532 | }, |
| 1534 | 1533 | macho.EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER => { |
| 1535 | const stub_offset = try it.readUleb128(); | |
| 1536 | const resolver_offset = try it.readUleb128(); | |
| 1534 | const stub_offset = try it.takeLeb128(); | |
| 1535 | const resolver_offset = try it.takeLeb128(); | |
| 1537 | 1536 | try exports.append(.{ |
| 1538 | 1537 | .name = prefix, |
| 1539 | 1538 | .tag = .stub_resolver, |
| ... | ... | @@ -1544,7 +1543,7 @@ const MachODumper = struct { |
| 1544 | 1543 | }); |
| 1545 | 1544 | }, |
| 1546 | 1545 | else => { |
| 1547 | const vmoff = try it.readUleb128(); | |
| 1546 | const vmoff = try it.takeLeb128(); | |
| 1548 | 1547 | try exports.append(.{ |
| 1549 | 1548 | .name = prefix, |
| 1550 | 1549 | .tag = .@"export", |
| ... | ... | @@ -1563,10 +1562,10 @@ const MachODumper = struct { |
| 1563 | 1562 | } |
| 1564 | 1563 | } |
| 1565 | 1564 | |
| 1566 | const nedges = try it.readByte(); | |
| 1565 | const nedges = try it.takeByte(); | |
| 1567 | 1566 | for (0..nedges) |_| { |
| 1568 | 1567 | const label = try it.readString(); |
| 1569 | const off = try it.readUleb128(); | |
| 1568 | const off = try it.takeLeb128(); | |
| 1570 | 1569 | const prefix_label = try std.fmt.allocPrint(arena, "{s}{s}", .{ prefix, label }); |
| 1571 | 1570 | const curr = it.stream.seek; |
| 1572 | 1571 | it.stream.seek = off; |
| ... | ... | @@ -1701,11 +1700,10 @@ const ElfDumper = struct { |
| 1701 | 1700 | |
| 1702 | 1701 | fn parseAndDumpArchive(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 1703 | 1702 | const gpa = step.owner.allocator; |
| 1704 | var stream = std.io.fixedBufferStream(bytes); | |
| 1705 | const reader = stream.reader(); | |
| 1703 | var reader: std.Io.Reader = .fixed(bytes); | |
| 1706 | 1704 | |
| 1707 | const magic = try reader.readBytesNoEof(elf.ARMAG.len); | |
| 1708 | if (!mem.eql(u8, &magic, elf.ARMAG)) { | |
| 1705 | const magic = try reader.takeArray(elf.ARMAG.len); | |
| 1706 | if (!mem.eql(u8, magic, elf.ARMAG)) { | |
| 1709 | 1707 | return error.InvalidArchiveMagicNumber; |
| 1710 | 1708 | } |
| 1711 | 1709 | |
| ... | ... | @@ -1722,28 +1720,26 @@ const ElfDumper = struct { |
| 1722 | 1720 | } |
| 1723 | 1721 | |
| 1724 | 1722 | while (true) { |
| 1725 | if (stream.pos >= ctx.data.len) break; | |
| 1726 | if (!mem.isAligned(stream.pos, 2)) stream.pos += 1; | |
| 1723 | if (reader.seek >= ctx.data.len) break; | |
| 1724 | if (!mem.isAligned(reader.seek, 2)) reader.seek += 1; | |
| 1727 | 1725 | |
| 1728 | const hdr = try reader.readStruct(elf.ar_hdr); | |
| 1726 | const hdr = try reader.takeStruct(elf.ar_hdr, .little); | |
| 1729 | 1727 | |
| 1730 | 1728 | if (!mem.eql(u8, &hdr.ar_fmag, elf.ARFMAG)) return error.InvalidArchiveHeaderMagicNumber; |
| 1731 | 1729 | |
| 1732 | 1730 | const size = try hdr.size(); |
| 1733 | defer { | |
| 1734 | _ = stream.seekBy(size) catch {}; | |
| 1735 | } | |
| 1731 | defer reader.seek += size; | |
| 1736 | 1732 | |
| 1737 | 1733 | if (hdr.isSymtab()) { |
| 1738 | try ctx.parseSymtab(ctx.data[stream.pos..][0..size], .p32); | |
| 1734 | try ctx.parseSymtab(ctx.data[reader.seek..][0..size], .p32); | |
| 1739 | 1735 | continue; |
| 1740 | 1736 | } |
| 1741 | 1737 | if (hdr.isSymtab64()) { |
| 1742 | try ctx.parseSymtab(ctx.data[stream.pos..][0..size], .p64); | |
| 1738 | try ctx.parseSymtab(ctx.data[reader.seek..][0..size], .p64); | |
| 1743 | 1739 | continue; |
| 1744 | 1740 | } |
| 1745 | 1741 | if (hdr.isStrtab()) { |
| 1746 | ctx.strtab = ctx.data[stream.pos..][0..size]; | |
| 1742 | ctx.strtab = ctx.data[reader.seek..][0..size]; | |
| 1747 | 1743 | continue; |
| 1748 | 1744 | } |
| 1749 | 1745 | if (hdr.isSymdef() or hdr.isSymdefSorted()) continue; |
| ... | ... | @@ -1755,7 +1751,7 @@ const ElfDumper = struct { |
| 1755 | 1751 | else |
| 1756 | 1752 | unreachable; |
| 1757 | 1753 | |
| 1758 | try ctx.objects.append(gpa, .{ .name = name, .off = stream.pos, .len = size }); | |
| 1754 | try ctx.objects.append(gpa, .{ .name = name, .off = reader.seek, .len = size }); | |
| 1759 | 1755 | } |
| 1760 | 1756 | |
| 1761 | 1757 | var output: std.Io.Writer.Allocating = .init(gpa); |
| ... | ... | @@ -1783,11 +1779,10 @@ const ElfDumper = struct { |
| 1783 | 1779 | objects: std.ArrayListUnmanaged(struct { name: []const u8, off: usize, len: usize }) = .empty, |
| 1784 | 1780 | |
| 1785 | 1781 | 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(); | |
| 1782 | var reader: std.Io.Reader = .fixed(raw); | |
| 1788 | 1783 | const num = switch (ptr_width) { |
| 1789 | .p32 => try reader.readInt(u32, .big), | |
| 1790 | .p64 => try reader.readInt(u64, .big), | |
| 1784 | .p32 => try reader.takeInt(u32, .big), | |
| 1785 | .p64 => try reader.takeInt(u64, .big), | |
| 1791 | 1786 | }; |
| 1792 | 1787 | const ptr_size: usize = switch (ptr_width) { |
| 1793 | 1788 | .p32 => @sizeOf(u32), |
| ... | ... | @@ -1802,8 +1797,8 @@ const ElfDumper = struct { |
| 1802 | 1797 | var stroff: usize = 0; |
| 1803 | 1798 | for (0..num) |_| { |
| 1804 | 1799 | const off = switch (ptr_width) { |
| 1805 | .p32 => try reader.readInt(u32, .big), | |
| 1806 | .p64 => try reader.readInt(u64, .big), | |
| 1800 | .p32 => try reader.takeInt(u32, .big), | |
| 1801 | .p64 => try reader.takeInt(u64, .big), | |
| 1807 | 1802 | }; |
| 1808 | 1803 | const name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + stroff)), 0); |
| 1809 | 1804 | stroff += name.len + 1; |
| ... | ... | @@ -1868,10 +1863,9 @@ const ElfDumper = struct { |
| 1868 | 1863 | |
| 1869 | 1864 | fn parseAndDumpObject(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 1870 | 1865 | const gpa = step.owner.allocator; |
| 1871 | var stream = std.io.fixedBufferStream(bytes); | |
| 1872 | const reader = stream.reader(); | |
| 1866 | var reader: std.Io.Reader = .fixed(bytes); | |
| 1873 | 1867 | |
| 1874 | const hdr = try reader.readStruct(elf.Elf64_Ehdr); | |
| 1868 | const hdr = try reader.takeStruct(elf.Elf64_Ehdr, .little); | |
| 1875 | 1869 | if (!mem.eql(u8, hdr.e_ident[0..4], "\x7fELF")) { |
| 1876 | 1870 | return error.InvalidMagicNumber; |
| 1877 | 1871 | } |
| ... | ... | @@ -2360,10 +2354,9 @@ const WasmDumper = struct { |
| 2360 | 2354 | |
| 2361 | 2355 | fn parseAndDump(step: *Step, check: Check, bytes: []const u8) ![]const u8 { |
| 2362 | 2356 | const gpa = step.owner.allocator; |
| 2363 | var fbs = std.io.fixedBufferStream(bytes); | |
| 2364 | const reader = fbs.reader(); | |
| 2357 | var reader: std.Io.Reader = .fixed(bytes); | |
| 2365 | 2358 | |
| 2366 | const buf = try reader.readBytesNoEof(8); | |
| 2359 | const buf = try reader.takeArray(8); | |
| 2367 | 2360 | if (!mem.eql(u8, buf[0..4], &std.wasm.magic)) { |
| 2368 | 2361 | return error.InvalidMagicByte; |
| 2369 | 2362 | } |
| ... | ... | @@ -2373,7 +2366,7 @@ const WasmDumper = struct { |
| 2373 | 2366 | |
| 2374 | 2367 | var output: std.Io.Writer.Allocating = .init(gpa); |
| 2375 | 2368 | defer output.deinit(); |
| 2376 | parseAndDumpInner(step, check, bytes, &fbs, &output.writer) catch |err| switch (err) { | |
| 2369 | parseAndDumpInner(step, check, bytes, &reader, &output.writer) catch |err| switch (err) { | |
| 2377 | 2370 | error.EndOfStream => try output.writer.writeAll("\n<UnexpectedEndOfStream>"), |
| 2378 | 2371 | else => |e| return e, |
| 2379 | 2372 | }; |
| ... | ... | @@ -2384,21 +2377,19 @@ const WasmDumper = struct { |
| 2384 | 2377 | step: *Step, |
| 2385 | 2378 | check: Check, |
| 2386 | 2379 | bytes: []const u8, |
| 2387 | fbs: *std.io.FixedBufferStream([]const u8), | |
| 2380 | reader: *std.Io.Reader, | |
| 2388 | 2381 | writer: *std.Io.Writer, |
| 2389 | 2382 | ) !void { |
| 2390 | const reader = fbs.reader(); | |
| 2391 | ||
| 2392 | 2383 | switch (check.kind) { |
| 2393 | 2384 | .headers => { |
| 2394 | while (reader.readByte()) |current_byte| { | |
| 2385 | while (reader.takeByte()) |current_byte| { | |
| 2395 | 2386 | const section = std.enums.fromInt(std.wasm.Section, current_byte) orelse { |
| 2396 | 2387 | return step.fail("Found invalid section id '{d}'", .{current_byte}); |
| 2397 | 2388 | }; |
| 2398 | 2389 | |
| 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; | |
| 2390 | const section_length = try reader.takeLeb128(u32); | |
| 2391 | try parseAndDumpSection(step, section, bytes[reader.seek..][0..section_length], writer); | |
| 2392 | reader.seek += section_length; | |
| 2402 | 2393 | } else |_| {} // reached end of stream |
| 2403 | 2394 | }, |
| 2404 | 2395 | |
| ... | ... | @@ -2410,10 +2401,9 @@ const WasmDumper = struct { |
| 2410 | 2401 | step: *Step, |
| 2411 | 2402 | section: std.wasm.Section, |
| 2412 | 2403 | data: []const u8, |
| 2413 | writer: anytype, | |
| 2404 | writer: *std.Io.Writer, | |
| 2414 | 2405 | ) !void { |
| 2415 | var fbs = std.io.fixedBufferStream(data); | |
| 2416 | const reader = fbs.reader(); | |
| 2406 | var reader: std.Io.Reader = .fixed(data); | |
| 2417 | 2407 | |
| 2418 | 2408 | try writer.print( |
| 2419 | 2409 | \\Section {s} |
| ... | ... | @@ -2432,31 +2422,31 @@ const WasmDumper = struct { |
| 2432 | 2422 | .code, |
| 2433 | 2423 | .data, |
| 2434 | 2424 | => { |
| 2435 | const entries = try std.leb.readUleb128(u32, reader); | |
| 2425 | const entries = try reader.takeLeb128(u32); | |
| 2436 | 2426 | try writer.print("\nentries {d}\n", .{entries}); |
| 2437 | try parseSection(step, section, data[fbs.pos..], entries, writer); | |
| 2427 | try parseSection(step, section, data[reader.seek..], entries, writer); | |
| 2438 | 2428 | }, |
| 2439 | 2429 | .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; | |
| 2430 | const name_length = try reader.takeLeb128(u32); | |
| 2431 | const name = data[reader.seek..][0..name_length]; | |
| 2432 | reader.seek += name_length; | |
| 2443 | 2433 | try writer.print("\nname {s}\n", .{name}); |
| 2444 | 2434 | |
| 2445 | 2435 | if (mem.eql(u8, name, "name")) { |
| 2446 | try parseDumpNames(step, reader, writer, data); | |
| 2436 | try parseDumpNames(step, &reader, writer, data); | |
| 2447 | 2437 | } else if (mem.eql(u8, name, "producers")) { |
| 2448 | try parseDumpProducers(reader, writer, data); | |
| 2438 | try parseDumpProducers(&reader, writer, data); | |
| 2449 | 2439 | } else if (mem.eql(u8, name, "target_features")) { |
| 2450 | try parseDumpFeatures(reader, writer, data); | |
| 2440 | try parseDumpFeatures(&reader, writer, data); | |
| 2451 | 2441 | } |
| 2452 | 2442 | // TODO: Implement parsing and dumping other custom sections (such as relocations) |
| 2453 | 2443 | }, |
| 2454 | 2444 | .start => { |
| 2455 | const start = try std.leb.readUleb128(u32, reader); | |
| 2445 | const start = try reader.takeLeb128(u32); | |
| 2456 | 2446 | try writer.print("\nstart {d}\n", .{start}); |
| 2457 | 2447 | }, |
| 2458 | 2448 | .data_count => { |
| 2459 | const count = try std.leb.readUleb128(u32, reader); | |
| 2449 | const count = try reader.takeLeb128(u32); | |
| 2460 | 2450 | try writer.print("\ncount {d}\n", .{count}); |
| 2461 | 2451 | }, |
| 2462 | 2452 | else => {}, // skip unknown sections |
| ... | ... | @@ -2464,41 +2454,40 @@ const WasmDumper = struct { |
| 2464 | 2454 | } |
| 2465 | 2455 | |
| 2466 | 2456 | 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(); | |
| 2457 | var reader: std.Io.Reader = .fixed(data); | |
| 2469 | 2458 | |
| 2470 | 2459 | switch (section) { |
| 2471 | 2460 | .type => { |
| 2472 | 2461 | var i: u32 = 0; |
| 2473 | 2462 | while (i < entries) : (i += 1) { |
| 2474 | const func_type = try reader.readByte(); | |
| 2463 | const func_type = try reader.takeByte(); | |
| 2475 | 2464 | if (func_type != std.wasm.function_type) { |
| 2476 | 2465 | return step.fail("expected function type, found byte '{d}'", .{func_type}); |
| 2477 | 2466 | } |
| 2478 | const params = try std.leb.readUleb128(u32, reader); | |
| 2467 | const params = try reader.takeLeb128(u32); | |
| 2479 | 2468 | try writer.print("params {d}\n", .{params}); |
| 2480 | 2469 | var index: u32 = 0; |
| 2481 | 2470 | while (index < params) : (index += 1) { |
| 2482 | _ = try parseDumpType(step, std.wasm.Valtype, reader, writer); | |
| 2471 | _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer); | |
| 2483 | 2472 | } else index = 0; |
| 2484 | const returns = try std.leb.readUleb128(u32, reader); | |
| 2473 | const returns = try reader.takeLeb128(u32); | |
| 2485 | 2474 | try writer.print("returns {d}\n", .{returns}); |
| 2486 | 2475 | while (index < returns) : (index += 1) { |
| 2487 | _ = try parseDumpType(step, std.wasm.Valtype, reader, writer); | |
| 2476 | _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer); | |
| 2488 | 2477 | } |
| 2489 | 2478 | } |
| 2490 | 2479 | }, |
| 2491 | 2480 | .import => { |
| 2492 | 2481 | var i: u32 = 0; |
| 2493 | 2482 | 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 { | |
| 2483 | const module_name_len = try reader.takeLeb128(u32); | |
| 2484 | const module_name = data[reader.seek..][0..module_name_len]; | |
| 2485 | reader.seek += module_name_len; | |
| 2486 | const name_len = try reader.takeLeb128(u32); | |
| 2487 | const name = data[reader.seek..][0..name_len]; | |
| 2488 | reader.seek += name_len; | |
| 2489 | ||
| 2490 | const kind = std.enums.fromInt(std.wasm.ExternalKind, try reader.takeByte()) orelse { | |
| 2502 | 2491 | return step.fail("invalid import kind", .{}); |
| 2503 | 2492 | }; |
| 2504 | 2493 | |
| ... | ... | @@ -2510,18 +2499,18 @@ const WasmDumper = struct { |
| 2510 | 2499 | try writer.writeByte('\n'); |
| 2511 | 2500 | switch (kind) { |
| 2512 | 2501 | .function => { |
| 2513 | try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)}); | |
| 2502 | try writer.print("index {d}\n", .{try reader.takeLeb128(u32)}); | |
| 2514 | 2503 | }, |
| 2515 | 2504 | .memory => { |
| 2516 | try parseDumpLimits(reader, writer); | |
| 2505 | try parseDumpLimits(&reader, writer); | |
| 2517 | 2506 | }, |
| 2518 | 2507 | .global => { |
| 2519 | _ = try parseDumpType(step, std.wasm.Valtype, reader, writer); | |
| 2520 | try writer.print("mutable {}\n", .{0x01 == try std.leb.readUleb128(u32, reader)}); | |
| 2508 | _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer); | |
| 2509 | try writer.print("mutable {}\n", .{0x01 == try reader.takeLeb128(u32)}); | |
| 2521 | 2510 | }, |
| 2522 | 2511 | .table => { |
| 2523 | _ = try parseDumpType(step, std.wasm.RefType, reader, writer); | |
| 2524 | try parseDumpLimits(reader, writer); | |
| 2512 | _ = try parseDumpType(step, std.wasm.RefType, &reader, writer); | |
| 2513 | try parseDumpLimits(&reader, writer); | |
| 2525 | 2514 | }, |
| 2526 | 2515 | } |
| 2527 | 2516 | } |
| ... | ... | @@ -2529,41 +2518,41 @@ const WasmDumper = struct { |
| 2529 | 2518 | .function => { |
| 2530 | 2519 | var i: u32 = 0; |
| 2531 | 2520 | while (i < entries) : (i += 1) { |
| 2532 | try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)}); | |
| 2521 | try writer.print("index {d}\n", .{try reader.takeLeb128(u32)}); | |
| 2533 | 2522 | } |
| 2534 | 2523 | }, |
| 2535 | 2524 | .table => { |
| 2536 | 2525 | var i: u32 = 0; |
| 2537 | 2526 | while (i < entries) : (i += 1) { |
| 2538 | _ = try parseDumpType(step, std.wasm.RefType, reader, writer); | |
| 2539 | try parseDumpLimits(reader, writer); | |
| 2527 | _ = try parseDumpType(step, std.wasm.RefType, &reader, writer); | |
| 2528 | try parseDumpLimits(&reader, writer); | |
| 2540 | 2529 | } |
| 2541 | 2530 | }, |
| 2542 | 2531 | .memory => { |
| 2543 | 2532 | var i: u32 = 0; |
| 2544 | 2533 | while (i < entries) : (i += 1) { |
| 2545 | try parseDumpLimits(reader, writer); | |
| 2534 | try parseDumpLimits(&reader, writer); | |
| 2546 | 2535 | } |
| 2547 | 2536 | }, |
| 2548 | 2537 | .global => { |
| 2549 | 2538 | var i: u32 = 0; |
| 2550 | 2539 | 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); | |
| 2540 | _ = try parseDumpType(step, std.wasm.Valtype, &reader, writer); | |
| 2541 | try writer.print("mutable {}\n", .{0x01 == try reader.takeLeb128(u1)}); | |
| 2542 | try parseDumpInit(step, &reader, writer); | |
| 2554 | 2543 | } |
| 2555 | 2544 | }, |
| 2556 | 2545 | .@"export" => { |
| 2557 | 2546 | var i: u32 = 0; |
| 2558 | 2547 | 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); | |
| 2548 | const name_len = try reader.takeLeb128(u32); | |
| 2549 | const name = data[reader.seek..][0..name_len]; | |
| 2550 | reader.seek += name_len; | |
| 2551 | const kind_byte = try reader.takeLeb128(u8); | |
| 2563 | 2552 | const kind = std.enums.fromInt(std.wasm.ExternalKind, kind_byte) orelse { |
| 2564 | 2553 | return step.fail("invalid export kind value '{d}'", .{kind_byte}); |
| 2565 | 2554 | }; |
| 2566 | const index = try std.leb.readUleb128(u32, reader); | |
| 2555 | const index = try reader.takeLeb128(u32); | |
| 2567 | 2556 | try writer.print( |
| 2568 | 2557 | \\name {s} |
| 2569 | 2558 | \\kind {s} |
| ... | ... | @@ -2575,14 +2564,14 @@ const WasmDumper = struct { |
| 2575 | 2564 | .element => { |
| 2576 | 2565 | var i: u32 = 0; |
| 2577 | 2566 | 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); | |
| 2567 | try writer.print("table index {d}\n", .{try reader.takeLeb128(u32)}); | |
| 2568 | try parseDumpInit(step, &reader, writer); | |
| 2580 | 2569 | |
| 2581 | const function_indexes = try std.leb.readUleb128(u32, reader); | |
| 2570 | const function_indexes = try reader.takeLeb128(u32); | |
| 2582 | 2571 | var function_index: u32 = 0; |
| 2583 | 2572 | try writer.print("indexes {d}\n", .{function_indexes}); |
| 2584 | 2573 | while (function_index < function_indexes) : (function_index += 1) { |
| 2585 | try writer.print("index {d}\n", .{try std.leb.readUleb128(u32, reader)}); | |
| 2574 | try writer.print("index {d}\n", .{try reader.takeLeb128(u32)}); | |
| 2586 | 2575 | } |
| 2587 | 2576 | } |
| 2588 | 2577 | }, |
| ... | ... | @@ -2590,27 +2579,27 @@ const WasmDumper = struct { |
| 2590 | 2579 | .data => { |
| 2591 | 2580 | var i: u32 = 0; |
| 2592 | 2581 | while (i < entries) : (i += 1) { |
| 2593 | const flags = try std.leb.readUleb128(u32, reader); | |
| 2582 | const flags = try reader.takeLeb128(u32); | |
| 2594 | 2583 | const index = if (flags & 0x02 != 0) |
| 2595 | try std.leb.readUleb128(u32, reader) | |
| 2584 | try reader.takeLeb128(u32) | |
| 2596 | 2585 | else |
| 2597 | 2586 | 0; |
| 2598 | 2587 | try writer.print("memory index 0x{x}\n", .{index}); |
| 2599 | 2588 | if (flags == 0) { |
| 2600 | try parseDumpInit(step, reader, writer); | |
| 2589 | try parseDumpInit(step, &reader, writer); | |
| 2601 | 2590 | } |
| 2602 | 2591 | |
| 2603 | const size = try std.leb.readUleb128(u32, reader); | |
| 2592 | const size = try reader.takeLeb128(u32); | |
| 2604 | 2593 | try writer.print("size {d}\n", .{size}); |
| 2605 | try reader.skipBytes(size, .{}); // we do not care about the content of the segments | |
| 2594 | try reader.discardAll(size); // we do not care about the content of the segments | |
| 2606 | 2595 | } |
| 2607 | 2596 | }, |
| 2608 | 2597 | else => unreachable, |
| 2609 | 2598 | } |
| 2610 | 2599 | } |
| 2611 | 2600 | |
| 2612 | fn parseDumpType(step: *Step, comptime E: type, reader: anytype, writer: anytype) !E { | |
| 2613 | const byte = try reader.readByte(); | |
| 2601 | fn parseDumpType(step: *Step, comptime E: type, reader: *std.Io.Reader, writer: *std.Io.Writer) !E { | |
| 2602 | const byte = try reader.takeByte(); | |
| 2614 | 2603 | const tag = std.enums.fromInt(E, byte) orelse { |
| 2615 | 2604 | return step.fail("invalid wasm type value '{d}'", .{byte}); |
| 2616 | 2605 | }; |
| ... | ... | @@ -2619,65 +2608,65 @@ const WasmDumper = struct { |
| 2619 | 2608 | } |
| 2620 | 2609 | |
| 2621 | 2610 | 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); | |
| 2611 | const flags = try reader.takeLeb128(u8); | |
| 2612 | const min = try reader.takeLeb128(u32); | |
| 2624 | 2613 | |
| 2625 | 2614 | try writer.print("min {x}\n", .{min}); |
| 2626 | 2615 | if (flags != 0) { |
| 2627 | try writer.print("max {x}\n", .{try std.leb.readUleb128(u32, reader)}); | |
| 2616 | try writer.print("max {x}\n", .{try reader.takeLeb128(u32)}); | |
| 2628 | 2617 | } |
| 2629 | 2618 | } |
| 2630 | 2619 | |
| 2631 | fn parseDumpInit(step: *Step, reader: anytype, writer: anytype) !void { | |
| 2632 | const byte = try reader.readByte(); | |
| 2620 | fn parseDumpInit(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer) !void { | |
| 2621 | const byte = try reader.takeByte(); | |
| 2633 | 2622 | const opcode = std.enums.fromInt(std.wasm.Opcode, byte) orelse { |
| 2634 | 2623 | return step.fail("invalid wasm opcode '{d}'", .{byte}); |
| 2635 | 2624 | }; |
| 2636 | 2625 | 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)}), | |
| 2639 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}), | |
| 2640 | .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)}), | |
| 2626 | .i32_const => try writer.print("i32.const {x}\n", .{try reader.takeLeb128(i32)}), | |
| 2627 | .i64_const => try writer.print("i64.const {x}\n", .{try reader.takeLeb128(i64)}), | |
| 2628 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.takeInt(u32, .little)))}), | |
| 2629 | .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.takeInt(u64, .little)))}), | |
| 2630 | .global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}), | |
| 2642 | 2631 | else => unreachable, |
| 2643 | 2632 | } |
| 2644 | const end_opcode = try std.leb.readUleb128(u8, reader); | |
| 2633 | const end_opcode = try reader.takeLeb128(u8); | |
| 2645 | 2634 | if (end_opcode != @intFromEnum(std.wasm.Opcode.end)) { |
| 2646 | 2635 | return step.fail("expected 'end' opcode in init expression", .{}); |
| 2647 | 2636 | } |
| 2648 | 2637 | } |
| 2649 | 2638 | |
| 2650 | 2639 | /// https://webassembly.github.io/spec/core/appendix/custom.html |
| 2651 | fn parseDumpNames(step: *Step, reader: anytype, writer: anytype, data: []const u8) !void { | |
| 2652 | while (reader.context.pos < data.len) { | |
| 2640 | fn parseDumpNames(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { | |
| 2641 | while (reader.seek < data.len) { | |
| 2653 | 2642 | switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) { |
| 2654 | 2643 | // The module name subsection ... consists of a single name |
| 2655 | 2644 | // that is assigned to the module itself. |
| 2656 | 2645 | .module => { |
| 2657 | const size = try std.leb.readUleb128(u32, reader); | |
| 2658 | const name_len = try std.leb.readUleb128(u32, reader); | |
| 2646 | const size = try reader.takeLeb128(u32); | |
| 2647 | const name_len = try reader.takeLeb128(u32); | |
| 2659 | 2648 | if (size != name_len + 1) return error.BadSubsectionSize; |
| 2660 | if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; | |
| 2661 | try writer.print("name {s}\n", .{data[reader.context.pos..][0..name_len]}); | |
| 2662 | reader.context.pos += name_len; | |
| 2649 | if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; | |
| 2650 | try writer.print("name {s}\n", .{data[reader.seek..][0..name_len]}); | |
| 2651 | reader.seek += name_len; | |
| 2663 | 2652 | }, |
| 2664 | 2653 | |
| 2665 | 2654 | // The function name subsection ... consists of a name map |
| 2666 | 2655 | // assigning function names to function indices. |
| 2667 | 2656 | .function, .global, .data_segment => { |
| 2668 | const size = try std.leb.readUleb128(u32, reader); | |
| 2669 | const entries = try std.leb.readUleb128(u32, reader); | |
| 2657 | const size = try reader.takeLeb128(u32); | |
| 2658 | const entries = try reader.takeLeb128(u32); | |
| 2670 | 2659 | try writer.print( |
| 2671 | 2660 | \\size {d} |
| 2672 | 2661 | \\names {d} |
| 2673 | 2662 | \\ |
| 2674 | 2663 | , .{ size, entries }); |
| 2675 | 2664 | for (0..entries) |_| { |
| 2676 | const index = try std.leb.readUleb128(u32, reader); | |
| 2677 | const name_len = try std.leb.readUleb128(u32, reader); | |
| 2678 | if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; | |
| 2679 | const name = data[reader.context.pos..][0..name_len]; | |
| 2680 | reader.context.pos += name.len; | |
| 2665 | const index = try reader.takeLeb128(u32); | |
| 2666 | const name_len = try reader.takeLeb128(u32); | |
| 2667 | if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; | |
| 2668 | const name = data[reader.seek..][0..name_len]; | |
| 2669 | reader.seek += name.len; | |
| 2681 | 2670 | |
| 2682 | 2671 | try writer.print( |
| 2683 | 2672 | \\index {d} |
| ... | ... | @@ -2699,16 +2688,16 @@ const WasmDumper = struct { |
| 2699 | 2688 | } |
| 2700 | 2689 | } |
| 2701 | 2690 | |
| 2702 | fn parseDumpProducers(reader: anytype, writer: anytype, data: []const u8) !void { | |
| 2703 | const field_count = try std.leb.readUleb128(u32, reader); | |
| 2691 | fn parseDumpProducers(reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { | |
| 2692 | const field_count = try reader.takeLeb128(u32); | |
| 2704 | 2693 | try writer.print("fields {d}\n", .{field_count}); |
| 2705 | 2694 | var current_field: u32 = 0; |
| 2706 | 2695 | while (current_field < field_count) : (current_field += 1) { |
| 2707 | const field_name_length = try std.leb.readUleb128(u32, reader); | |
| 2708 | const field_name = data[reader.context.pos..][0..field_name_length]; | |
| 2709 | reader.context.pos += field_name_length; | |
| 2696 | const field_name_length = try reader.takeLeb128(u32); | |
| 2697 | const field_name = data[reader.seek..][0..field_name_length]; | |
| 2698 | reader.seek += field_name_length; | |
| 2710 | 2699 | |
| 2711 | const value_count = try std.leb.readUleb128(u32, reader); | |
| 2700 | const value_count = try reader.takeLeb128(u32); | |
| 2712 | 2701 | try writer.print( |
| 2713 | 2702 | \\field_name {s} |
| 2714 | 2703 | \\values {d} |
| ... | ... | @@ -2716,13 +2705,13 @@ const WasmDumper = struct { |
| 2716 | 2705 | try writer.writeByte('\n'); |
| 2717 | 2706 | var current_value: u32 = 0; |
| 2718 | 2707 | while (current_value < value_count) : (current_value += 1) { |
| 2719 | const value_length = try std.leb.readUleb128(u32, reader); | |
| 2720 | const value = data[reader.context.pos..][0..value_length]; | |
| 2721 | reader.context.pos += value_length; | |
| 2708 | const value_length = try reader.takeLeb128(u32); | |
| 2709 | const value = data[reader.seek..][0..value_length]; | |
| 2710 | reader.seek += value_length; | |
| 2722 | 2711 | |
| 2723 | const version_length = try std.leb.readUleb128(u32, reader); | |
| 2724 | const version = data[reader.context.pos..][0..version_length]; | |
| 2725 | reader.context.pos += version_length; | |
| 2712 | const version_length = try reader.takeLeb128(u32); | |
| 2713 | const version = data[reader.seek..][0..version_length]; | |
| 2714 | reader.seek += version_length; | |
| 2726 | 2715 | |
| 2727 | 2716 | try writer.print( |
| 2728 | 2717 | \\value_name {s} |
| ... | ... | @@ -2733,16 +2722,16 @@ const WasmDumper = struct { |
| 2733 | 2722 | } |
| 2734 | 2723 | } |
| 2735 | 2724 | |
| 2736 | fn parseDumpFeatures(reader: anytype, writer: anytype, data: []const u8) !void { | |
| 2737 | const feature_count = try std.leb.readUleb128(u32, reader); | |
| 2725 | fn parseDumpFeatures(reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { | |
| 2726 | const feature_count = try reader.takeLeb128(u32); | |
| 2738 | 2727 | try writer.print("features {d}\n", .{feature_count}); |
| 2739 | 2728 | |
| 2740 | 2729 | var index: u32 = 0; |
| 2741 | 2730 | 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); | |
| 2744 | const feature_name = data[reader.context.pos..][0..name_length]; | |
| 2745 | reader.context.pos += name_length; | |
| 2731 | const prefix_byte = try reader.takeLeb128(u8); | |
| 2732 | const name_length = try reader.takeLeb128(u32); | |
| 2733 | const feature_name = data[reader.seek..][0..name_length]; | |
| 2734 | reader.seek += name_length; | |
| 2746 | 2735 | |
| 2747 | 2736 | try writer.print("{c} {s}\n", .{ prefix_byte, feature_name }); |
| 2748 | 2737 | } |
lib/std/Build/Step/Compile.zig+1-1| ... | ... | @@ -2021,7 +2021,7 @@ fn checkCompileErrors(compile: *Compile) !void { |
| 2021 | 2021 | const arena = compile.step.owner.allocator; |
| 2022 | 2022 | |
| 2023 | 2023 | const actual_errors = ae: { |
| 2024 | var aw: std.io.Writer.Allocating = .init(arena); | |
| 2024 | var aw: std.Io.Writer.Allocating = .init(arena); | |
| 2025 | 2025 | defer aw.deinit(); |
| 2026 | 2026 | try actual_eb.renderToWriter(.{ |
| 2027 | 2027 | .ttyconf = .no_color, |
lib/std/Build/Step/ConfigHeader.zig+6-6| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const ConfigHeader = @This(); |
| 3 | 3 | const Step = std.Build.Step; |
| 4 | 4 | const Allocator = std.mem.Allocator; |
| 5 | const Writer = std.io.Writer; | |
| 5 | const Writer = std.Io.Writer; | |
| 6 | 6 | |
| 7 | 7 | pub const Style = union(enum) { |
| 8 | 8 | /// A configure format supported by autotools that uses `#undef foo` to |
| ... | ... | @@ -196,7 +196,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 196 | 196 | man.hash.addBytes(config_header.include_path); |
| 197 | 197 | man.hash.addOptionalBytes(config_header.include_guard_override); |
| 198 | 198 | |
| 199 | var aw: std.io.Writer.Allocating = .init(gpa); | |
| 199 | var aw: Writer.Allocating = .init(gpa); | |
| 200 | 200 | defer aw.deinit(); |
| 201 | 201 | const bw = &aw.writer; |
| 202 | 202 | |
| ... | ... | @@ -208,7 +208,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 208 | 208 | .autoconf_undef, .autoconf_at => |file_source| { |
| 209 | 209 | try bw.writeAll(c_generated_line); |
| 210 | 210 | const src_path = file_source.getPath2(b, step); |
| 211 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, config_header.max_bytes) catch |err| { | |
| 211 | const contents = std.fs.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| { | |
| 212 | 212 | return step.fail("unable to read autoconf input file '{s}': {s}", .{ |
| 213 | 213 | src_path, @errorName(err), |
| 214 | 214 | }); |
| ... | ... | @@ -222,7 +222,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 222 | 222 | .cmake => |file_source| { |
| 223 | 223 | try bw.writeAll(c_generated_line); |
| 224 | 224 | const src_path = file_source.getPath2(b, step); |
| 225 | const contents = std.fs.cwd().readFileAlloc(arena, src_path, config_header.max_bytes) catch |err| { | |
| 225 | const contents = std.fs.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| { | |
| 226 | 226 | return step.fail("unable to read cmake input file '{s}': {s}", .{ |
| 227 | 227 | src_path, @errorName(err), |
| 228 | 228 | }); |
| ... | ... | @@ -329,7 +329,7 @@ fn render_autoconf_undef( |
| 329 | 329 | fn render_autoconf_at( |
| 330 | 330 | step: *Step, |
| 331 | 331 | contents: []const u8, |
| 332 | aw: *std.io.Writer.Allocating, | |
| 332 | aw: *Writer.Allocating, | |
| 333 | 333 | values: std.StringArrayHashMap(Value), |
| 334 | 334 | src_path: []const u8, |
| 335 | 335 | ) !void { |
| ... | ... | @@ -753,7 +753,7 @@ fn testReplaceVariablesAutoconfAt( |
| 753 | 753 | expected: []const u8, |
| 754 | 754 | values: std.StringArrayHashMap(Value), |
| 755 | 755 | ) !void { |
| 756 | var aw: std.io.Writer.Allocating = .init(allocator); | |
| 756 | var aw: Writer.Allocating = .init(allocator); | |
| 757 | 757 | defer aw.deinit(); |
| 758 | 758 | |
| 759 | 759 | const used = try allocator.alloc(bool, values.count()); |
lib/std/Build/Step/ObjCopy.zig-1| ... | ... | @@ -9,7 +9,6 @@ const InstallDir = std.Build.InstallDir; |
| 9 | 9 | const Step = std.Build.Step; |
| 10 | 10 | const elf = std.elf; |
| 11 | 11 | const fs = std.fs; |
| 12 | const io = std.io; | |
| 13 | 12 | const sort = std.sort; |
| 14 | 13 | |
| 15 | 14 | pub const base_id: Step.Id = .objcopy; |
lib/std/Build/WebServer.zig+4-4| ... | ... | @@ -3,7 +3,7 @@ thread_pool: *std.Thread.Pool, |
| 3 | 3 | graph: *const Build.Graph, |
| 4 | 4 | all_steps: []const *Build.Step, |
| 5 | 5 | listen_address: std.net.Address, |
| 6 | ttyconf: std.io.tty.Config, | |
| 6 | ttyconf: std.Io.tty.Config, | |
| 7 | 7 | root_prog_node: std.Progress.Node, |
| 8 | 8 | watch: bool, |
| 9 | 9 | |
| ... | ... | @@ -53,7 +53,7 @@ pub const Options = struct { |
| 53 | 53 | thread_pool: *std.Thread.Pool, |
| 54 | 54 | graph: *const std.Build.Graph, |
| 55 | 55 | all_steps: []const *Build.Step, |
| 56 | ttyconf: std.io.tty.Config, | |
| 56 | ttyconf: std.Io.tty.Config, | |
| 57 | 57 | root_prog_node: std.Progress.Node, |
| 58 | 58 | watch: bool, |
| 59 | 59 | listen_address: std.net.Address, |
| ... | ... | @@ -446,7 +446,7 @@ pub fn serveFile( |
| 446 | 446 | // The desired API is actually sendfile, which will require enhancing http.Server. |
| 447 | 447 | // We load the file with every request so that the user can make changes to the file |
| 448 | 448 | // and refresh the HTML page without restarting this server. |
| 449 | const file_contents = path.root_dir.handle.readFileAlloc(gpa, path.sub_path, 10 * 1024 * 1024) catch |err| { | |
| 449 | const file_contents = path.root_dir.handle.readFileAlloc(path.sub_path, gpa, .limited(10 * 1024 * 1024)) catch |err| { | |
| 450 | 450 | log.err("failed to read '{f}': {s}", .{ path, @errorName(err) }); |
| 451 | 451 | return error.AlreadyReported; |
| 452 | 452 | }; |
| ... | ... | @@ -557,7 +557,7 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim |
| 557 | 557 | child.stderr_behavior = .Pipe; |
| 558 | 558 | try child.spawn(); |
| 559 | 559 | |
| 560 | var poller = std.io.poll(gpa, enum { stdout, stderr }, .{ | |
| 560 | var poller = std.Io.poll(gpa, enum { stdout, stderr }, .{ | |
| 561 | 561 | .stdout = child.stdout.?, |
| 562 | 562 | .stderr = child.stderr.?, |
| 563 | 563 | }); |
lib/std/Io.zig-197| ... | ... | @@ -82,202 +82,6 @@ pub const Limit = enum(usize) { |
| 82 | 82 | pub const Reader = @import("Io/Reader.zig"); |
| 83 | 83 | pub const Writer = @import("Io/Writer.zig"); |
| 84 | 84 | |
| 85 | /// Deprecated in favor of `Reader`. | |
| 86 | pub 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`. | |
| 275 | pub const AnyReader = @import("Io/DeprecatedReader.zig"); | |
| 276 | /// Deprecated in favor of `Reader`. | |
| 277 | pub const FixedBufferStream = @import("Io/fixed_buffer_stream.zig").FixedBufferStream; | |
| 278 | /// Deprecated in favor of `Reader`. | |
| 279 | pub const fixedBufferStream = @import("Io/fixed_buffer_stream.zig").fixedBufferStream; | |
| 280 | ||
| 281 | 85 | pub const tty = @import("Io/tty.zig"); |
| 282 | 86 | |
| 283 | 87 | pub fn poll( |
| ... | ... | @@ -746,7 +550,6 @@ pub fn PollFiles(comptime StreamEnum: type) type { |
| 746 | 550 | test { |
| 747 | 551 | _ = Reader; |
| 748 | 552 | _ = Writer; |
| 749 | _ = FixedBufferStream; | |
| 750 | 553 | _ = tty; |
| 751 | 554 | _ = @import("Io/test.zig"); |
| 752 | 555 | } |
lib/std/Io/DeprecatedReader.zig deleted-292| ... | ... | @@ -1,292 +0,0 @@ |
| 1 | context: *const anyopaque, | |
| 2 | readFn: *const fn (context: *const anyopaque, buffer: []u8) anyerror!usize, | |
| 3 | ||
| 4 | pub 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. | |
| 9 | pub 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. | |
| 16 | pub 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. | |
| 25 | pub 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. | |
| 37 | pub 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. | |
| 47 | pub 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 | ||
| 55 | pub 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. | |
| 89 | pub 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. | |
| 101 | pub 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. | |
| 127 | pub 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`. | |
| 138 | pub 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. | |
| 146 | pub 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 | |
| 152 | pub 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 | ||
| 158 | pub 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 | ||
| 163 | pub 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` | |
| 177 | pub 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 | |
| 183 | pub 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 | |
| 195 | pub 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 | ||
| 206 | pub 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 | ||
| 214 | pub 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 | |
| 225 | pub 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. | |
| 244 | pub 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. | |
| 255 | pub 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 | ||
| 267 | pub 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 | ||
| 285 | const std = @import("../std.zig"); | |
| 286 | const Self = @This(); | |
| 287 | const math = std.math; | |
| 288 | const assert = std.debug.assert; | |
| 289 | const mem = std.mem; | |
| 290 | const testing = std.testing; | |
| 291 | const native_endian = @import("builtin").target.cpu.arch.endian(); | |
| 292 | const Alignment = std.mem.Alignment; |
lib/std/Io/Reader.zig+132-21| ... | ... | @@ -4,12 +4,12 @@ const builtin = @import("builtin"); |
| 4 | 4 | const native_endian = builtin.target.cpu.arch.endian(); |
| 5 | 5 | |
| 6 | 6 | const std = @import("../std.zig"); |
| 7 | const Writer = std.io.Writer; | |
| 7 | const Writer = std.Io.Writer; | |
| 8 | const Limit = std.Io.Limit; | |
| 8 | 9 | const assert = std.debug.assert; |
| 9 | 10 | const testing = std.testing; |
| 10 | 11 | const Allocator = std.mem.Allocator; |
| 11 | 12 | const ArrayList = std.ArrayList; |
| 12 | const Limit = std.io.Limit; | |
| 13 | 13 | |
| 14 | 14 | pub const Limited = @import("Reader/Limited.zig"); |
| 15 | 15 | |
| ... | ... | @@ -292,6 +292,23 @@ pub fn allocRemaining(r: *Reader, gpa: Allocator, limit: Limit) LimitedAllocErro |
| 292 | 292 | return buffer.toOwnedSlice(gpa); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | pub fn allocRemainingAlignedSentinel( | |
| 296 | r: *Reader, | |
| 297 | gpa: Allocator, | |
| 298 | limit: Limit, | |
| 299 | comptime alignment: std.mem.Alignment, | |
| 300 | comptime sentinel: ?u8, | |
| 301 | ) LimitedAllocError!(if (sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) { | |
| 302 | var buffer: std.array_list.Aligned(u8, alignment) = .empty; | |
| 303 | defer buffer.deinit(gpa); | |
| 304 | try appendRemainingAligned(r, gpa, alignment, &buffer, limit); | |
| 305 | if (sentinel) |s| { | |
| 306 | return buffer.toOwnedSliceSentinel(gpa, s); | |
| 307 | } else { | |
| 308 | return buffer.toOwnedSlice(gpa); | |
| 309 | } | |
| 310 | } | |
| 311 | ||
| 295 | 312 | /// Transfers all bytes from the current position to the end of the stream, up |
| 296 | 313 | /// to `limit`, appending them to `list`. |
| 297 | 314 | /// |
| ... | ... | @@ -308,15 +325,30 @@ pub fn appendRemaining( |
| 308 | 325 | list: *ArrayList(u8), |
| 309 | 326 | limit: Limit, |
| 310 | 327 | ) LimitedAllocError!void { |
| 311 | var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.allocatedSlice()); | |
| 312 | a.writer.end = list.items.len; | |
| 313 | list.* = .empty; | |
| 314 | defer { | |
| 315 | list.* = .{ | |
| 316 | .items = a.writer.buffer[0..a.writer.end], | |
| 317 | .capacity = a.writer.buffer.len, | |
| 318 | }; | |
| 319 | } | |
| 328 | return appendRemainingAligned(r, gpa, .of(u8), list, limit); | |
| 329 | } | |
| 330 | ||
| 331 | /// Transfers all bytes from the current position to the end of the stream, up | |
| 332 | /// to `limit`, appending them to `list`. | |
| 333 | /// | |
| 334 | /// If `limit` is reached or exceeded, `error.StreamTooLong` is returned | |
| 335 | /// instead. In such case, the next byte that would be read will be the first | |
| 336 | /// one to exceed `limit`, and all preceeding bytes have been appended to | |
| 337 | /// `list`. | |
| 338 | /// | |
| 339 | /// See also: | |
| 340 | /// * `appendRemaining` | |
| 341 | /// * `allocRemainingAligned` | |
| 342 | pub fn appendRemainingAligned( | |
| 343 | r: *Reader, | |
| 344 | gpa: Allocator, | |
| 345 | comptime alignment: std.mem.Alignment, | |
| 346 | list: *std.array_list.Aligned(u8, alignment), | |
| 347 | limit: Limit, | |
| 348 | ) LimitedAllocError!void { | |
| 349 | var a = std.Io.Writer.Allocating.fromArrayListAligned(gpa, alignment, list); | |
| 350 | defer list.* = a.toArrayListAligned(alignment); | |
| 351 | ||
| 320 | 352 | var remaining = limit; |
| 321 | 353 | while (remaining.nonzero()) { |
| 322 | 354 | const n = stream(r, &a.writer, remaining) catch |err| switch (err) { |
| ... | ... | @@ -1584,7 +1616,7 @@ test readVec { |
| 1584 | 1616 | test "expected error.EndOfStream" { |
| 1585 | 1617 | // Unit test inspired by https://github.com/ziglang/zig/issues/17733 |
| 1586 | 1618 | var buffer: [3]u8 = undefined; |
| 1587 | var r: std.io.Reader = .fixed(&buffer); | |
| 1619 | var r: std.Io.Reader = .fixed(&buffer); | |
| 1588 | 1620 | r.end = 0; // capacity 3, but empty |
| 1589 | 1621 | try std.testing.expectError(error.EndOfStream, r.takeEnum(enum(u8) { a, b }, .little)); |
| 1590 | 1622 | try std.testing.expectError(error.EndOfStream, r.take(3)); |
| ... | ... | @@ -1639,15 +1671,6 @@ fn failingDiscard(r: *Reader, limit: Limit) Error!usize { |
| 1639 | 1671 | return error.ReadFailed; |
| 1640 | 1672 | } |
| 1641 | 1673 | |
| 1642 | pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader { | |
| 1643 | return .{ .context = r, .readFn = derpRead }; | |
| 1644 | } | |
| 1645 | ||
| 1646 | fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize { | |
| 1647 | const r: *Reader = @ptrCast(@alignCast(@constCast(context))); | |
| 1648 | return r.readSliceShort(buffer); | |
| 1649 | } | |
| 1650 | ||
| 1651 | 1674 | test "readAlloc when the backing reader provides one byte at a time" { |
| 1652 | 1675 | const str = "This is a test"; |
| 1653 | 1676 | var tiny_buffer: [1]u8 = undefined; |
| ... | ... | @@ -1870,6 +1893,94 @@ pub fn writableVector(r: *Reader, buffer: [][]u8, data: []const []u8) Error!stru |
| 1870 | 1893 | return .{ i, n }; |
| 1871 | 1894 | } |
| 1872 | 1895 | |
| 1896 | test "deserialize signed LEB128" { | |
| 1897 | // Truncated | |
| 1898 | try testing.expectError(error.EndOfStream, testLeb128(i64, "\x80")); | |
| 1899 | ||
| 1900 | // Overflow | |
| 1901 | try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x80\x40")); | |
| 1902 | try testing.expectError(error.Overflow, testLeb128(i16, "\x80\x80\x80\x40")); | |
| 1903 | try testing.expectError(error.Overflow, testLeb128(i32, "\x80\x80\x80\x80\x40")); | |
| 1904 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 1905 | try testing.expectError(error.Overflow, testLeb128(i8, "\xff\x7e")); | |
| 1906 | try testing.expectError(error.Overflow, testLeb128(i32, "\x80\x80\x80\x80\x08")); | |
| 1907 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")); | |
| 1908 | ||
| 1909 | // Decode SLEB128 | |
| 1910 | try testing.expect((try testLeb128(i64, "\x00")) == 0); | |
| 1911 | try testing.expect((try testLeb128(i64, "\x01")) == 1); | |
| 1912 | try testing.expect((try testLeb128(i64, "\x3f")) == 63); | |
| 1913 | try testing.expect((try testLeb128(i64, "\x40")) == -64); | |
| 1914 | try testing.expect((try testLeb128(i64, "\x41")) == -63); | |
| 1915 | try testing.expect((try testLeb128(i64, "\x7f")) == -1); | |
| 1916 | try testing.expect((try testLeb128(i64, "\x80\x01")) == 128); | |
| 1917 | try testing.expect((try testLeb128(i64, "\x81\x01")) == 129); | |
| 1918 | try testing.expect((try testLeb128(i64, "\xff\x7e")) == -129); | |
| 1919 | try testing.expect((try testLeb128(i64, "\x80\x7f")) == -128); | |
| 1920 | try testing.expect((try testLeb128(i64, "\x81\x7f")) == -127); | |
| 1921 | try testing.expect((try testLeb128(i64, "\xc0\x00")) == 64); | |
| 1922 | try testing.expect((try testLeb128(i64, "\xc7\x9f\x7f")) == -12345); | |
| 1923 | try testing.expect((try testLeb128(i8, "\xff\x7f")) == -1); | |
| 1924 | try testing.expect((try testLeb128(i16, "\xff\xff\x7f")) == -1); | |
| 1925 | try testing.expect((try testLeb128(i32, "\xff\xff\xff\xff\x7f")) == -1); | |
| 1926 | try testing.expect((try testLeb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000); | |
| 1927 | try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @as(i64, @bitCast(@as(u64, @intCast(0x8000000000000000))))); | |
| 1928 | try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000); | |
| 1929 | try testing.expect((try testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000); | |
| 1930 | ||
| 1931 | // Decode unnormalized SLEB128 with extra padding bytes. | |
| 1932 | try testing.expect((try testLeb128(i64, "\x80\x00")) == 0); | |
| 1933 | try testing.expect((try testLeb128(i64, "\x80\x80\x00")) == 0); | |
| 1934 | try testing.expect((try testLeb128(i64, "\xff\x00")) == 0x7f); | |
| 1935 | try testing.expect((try testLeb128(i64, "\xff\x80\x00")) == 0x7f); | |
| 1936 | try testing.expect((try testLeb128(i64, "\x80\x81\x00")) == 0x80); | |
| 1937 | try testing.expect((try testLeb128(i64, "\x80\x81\x80\x00")) == 0x80); | |
| 1938 | } | |
| 1939 | ||
| 1940 | test "deserialize unsigned LEB128" { | |
| 1941 | // Truncated | |
| 1942 | try testing.expectError(error.EndOfStream, testLeb128(u64, "\x80")); | |
| 1943 | try testing.expectError(error.EndOfStream, testLeb128(u16, "\x80\x80\x84")); | |
| 1944 | try testing.expectError(error.EndOfStream, testLeb128(u32, "\x80\x80\x80\x80\x90")); | |
| 1945 | ||
| 1946 | // Overflow | |
| 1947 | try testing.expectError(error.Overflow, testLeb128(u8, "\x80\x02")); | |
| 1948 | try testing.expectError(error.Overflow, testLeb128(u8, "\x80\x80\x40")); | |
| 1949 | try testing.expectError(error.Overflow, testLeb128(u16, "\x80\x80\x80\x40")); | |
| 1950 | try testing.expectError(error.Overflow, testLeb128(u32, "\x80\x80\x80\x80\x40")); | |
| 1951 | try testing.expectError(error.Overflow, testLeb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 1952 | ||
| 1953 | // Decode ULEB128 | |
| 1954 | try testing.expect((try testLeb128(u64, "\x00")) == 0); | |
| 1955 | try testing.expect((try testLeb128(u64, "\x01")) == 1); | |
| 1956 | try testing.expect((try testLeb128(u64, "\x3f")) == 63); | |
| 1957 | try testing.expect((try testLeb128(u64, "\x40")) == 64); | |
| 1958 | try testing.expect((try testLeb128(u64, "\x7f")) == 0x7f); | |
| 1959 | try testing.expect((try testLeb128(u64, "\x80\x01")) == 0x80); | |
| 1960 | try testing.expect((try testLeb128(u64, "\x81\x01")) == 0x81); | |
| 1961 | try testing.expect((try testLeb128(u64, "\x90\x01")) == 0x90); | |
| 1962 | try testing.expect((try testLeb128(u64, "\xff\x01")) == 0xff); | |
| 1963 | try testing.expect((try testLeb128(u64, "\x80\x02")) == 0x100); | |
| 1964 | try testing.expect((try testLeb128(u64, "\x81\x02")) == 0x101); | |
| 1965 | try testing.expect((try testLeb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616); | |
| 1966 | try testing.expect((try testLeb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000); | |
| 1967 | ||
| 1968 | // Decode ULEB128 with extra padding bytes | |
| 1969 | try testing.expect((try testLeb128(u64, "\x80\x00")) == 0); | |
| 1970 | try testing.expect((try testLeb128(u64, "\x80\x80\x00")) == 0); | |
| 1971 | try testing.expect((try testLeb128(u64, "\xff\x00")) == 0x7f); | |
| 1972 | try testing.expect((try testLeb128(u64, "\xff\x80\x00")) == 0x7f); | |
| 1973 | try testing.expect((try testLeb128(u64, "\x80\x81\x00")) == 0x80); | |
| 1974 | try testing.expect((try testLeb128(u64, "\x80\x81\x80\x00")) == 0x80); | |
| 1975 | } | |
| 1976 | ||
| 1977 | fn testLeb128(comptime T: type, encoded: []const u8) !T { | |
| 1978 | var reader: std.Io.Reader = .fixed(encoded); | |
| 1979 | const result = try reader.takeLeb128(T); | |
| 1980 | try testing.expect(reader.seek == reader.end); | |
| 1981 | return result; | |
| 1982 | } | |
| 1983 | ||
| 1873 | 1984 | test { |
| 1874 | 1985 | _ = Limited; |
| 1875 | 1986 | } |
lib/std/Io/Reader/Limited.zig+3-3| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | 1 | const Limited = @This(); |
| 2 | 2 | |
| 3 | 3 | const std = @import("../../std.zig"); |
| 4 | const Reader = std.io.Reader; | |
| 5 | const Writer = std.io.Writer; | |
| 6 | const Limit = std.io.Limit; | |
| 4 | const Reader = std.Io.Reader; | |
| 5 | const Writer = std.Io.Writer; | |
| 6 | const Limit = std.Io.Limit; | |
| 7 | 7 | |
| 8 | 8 | unlimited: *Reader, |
| 9 | 9 | remaining: Limit, |
lib/std/Io/Writer.zig+123-47| ... | ... | @@ -2531,13 +2531,14 @@ pub fn Hashing(comptime Hasher: type) type { |
| 2531 | 2531 | /// Maintains `Writer` state such that it writes to the unused capacity of an |
| 2532 | 2532 | /// array list, filling it up completely before making a call through the |
| 2533 | 2533 | /// vtable, causing a resize. Consequently, the same, optimized, non-generic |
| 2534 | /// machine code that uses `std.Io.Reader`, such as formatted printing, takes | |
| 2534 | /// machine code that uses `Writer`, such as formatted printing, takes | |
| 2535 | 2535 | /// the hot paths when using this API. |
| 2536 | 2536 | /// |
| 2537 | 2537 | /// When using this API, it is not necessary to call `flush`. |
| 2538 | 2538 | pub const Allocating = struct { |
| 2539 | 2539 | allocator: Allocator, |
| 2540 | 2540 | writer: Writer, |
| 2541 | alignment: std.mem.Alignment, | |
| 2541 | 2542 | |
| 2542 | 2543 | pub fn init(allocator: Allocator) Allocating { |
| 2543 | 2544 | return .{ |
| ... | ... | @@ -2546,6 +2547,7 @@ pub const Allocating = struct { |
| 2546 | 2547 | .buffer = &.{}, |
| 2547 | 2548 | .vtable = &vtable, |
| 2548 | 2549 | }, |
| 2550 | .alignment = .of(u8), | |
| 2549 | 2551 | }; |
| 2550 | 2552 | } |
| 2551 | 2553 | |
| ... | ... | @@ -2553,24 +2555,47 @@ pub const Allocating = struct { |
| 2553 | 2555 | return .{ |
| 2554 | 2556 | .allocator = allocator, |
| 2555 | 2557 | .writer = .{ |
| 2556 | .buffer = try allocator.alloc(u8, capacity), | |
| 2558 | .buffer = if (capacity == 0) | |
| 2559 | &.{} | |
| 2560 | else | |
| 2561 | (allocator.rawAlloc(capacity, .of(u8), @returnAddress()) orelse | |
| 2562 | return error.OutOfMemory)[0..capacity], | |
| 2557 | 2563 | .vtable = &vtable, |
| 2558 | 2564 | }, |
| 2565 | .alignment = .of(u8), | |
| 2559 | 2566 | }; |
| 2560 | 2567 | } |
| 2561 | 2568 | |
| 2562 | 2569 | pub fn initOwnedSlice(allocator: Allocator, slice: []u8) Allocating { |
| 2570 | return initOwnedSliceAligned(allocator, .of(u8), slice); | |
| 2571 | } | |
| 2572 | ||
| 2573 | pub fn initOwnedSliceAligned( | |
| 2574 | allocator: Allocator, | |
| 2575 | comptime alignment: std.mem.Alignment, | |
| 2576 | slice: []align(alignment.toByteUnits()) u8, | |
| 2577 | ) Allocating { | |
| 2563 | 2578 | return .{ |
| 2564 | 2579 | .allocator = allocator, |
| 2565 | 2580 | .writer = .{ |
| 2566 | 2581 | .buffer = slice, |
| 2567 | 2582 | .vtable = &vtable, |
| 2568 | 2583 | }, |
| 2584 | .alignment = alignment, | |
| 2569 | 2585 | }; |
| 2570 | 2586 | } |
| 2571 | 2587 | |
| 2572 | 2588 | /// Replaces `array_list` with empty, taking ownership of the memory. |
| 2573 | 2589 | pub fn fromArrayList(allocator: Allocator, array_list: *ArrayList(u8)) Allocating { |
| 2590 | return fromArrayListAligned(allocator, .of(u8), array_list); | |
| 2591 | } | |
| 2592 | ||
| 2593 | /// Replaces `array_list` with empty, taking ownership of the memory. | |
| 2594 | pub fn fromArrayListAligned( | |
| 2595 | allocator: Allocator, | |
| 2596 | comptime alignment: std.mem.Alignment, | |
| 2597 | array_list: *std.array_list.Aligned(u8, alignment), | |
| 2598 | ) Allocating { | |
| 2574 | 2599 | defer array_list.* = .empty; |
| 2575 | 2600 | return .{ |
| 2576 | 2601 | .allocator = allocator, |
| ... | ... | @@ -2579,6 +2604,7 @@ pub const Allocating = struct { |
| 2579 | 2604 | .buffer = array_list.allocatedSlice(), |
| 2580 | 2605 | .end = array_list.items.len, |
| 2581 | 2606 | }, |
| 2607 | .alignment = alignment, | |
| 2582 | 2608 | }; |
| 2583 | 2609 | } |
| 2584 | 2610 | |
| ... | ... | @@ -2590,16 +2616,27 @@ pub const Allocating = struct { |
| 2590 | 2616 | }; |
| 2591 | 2617 | |
| 2592 | 2618 | pub fn deinit(a: *Allocating) void { |
| 2593 | a.allocator.free(a.writer.buffer); | |
| 2619 | if (a.writer.buffer.len == 0) return; | |
| 2620 | a.allocator.rawFree(a.writer.buffer, a.alignment, @returnAddress()); | |
| 2594 | 2621 | a.* = undefined; |
| 2595 | 2622 | } |
| 2596 | 2623 | |
| 2597 | 2624 | /// Returns an array list that takes ownership of the allocated memory. |
| 2598 | 2625 | /// Resets the `Allocating` to an empty state. |
| 2599 | 2626 | pub fn toArrayList(a: *Allocating) ArrayList(u8) { |
| 2627 | return toArrayListAligned(a, .of(u8)); | |
| 2628 | } | |
| 2629 | ||
| 2630 | /// Returns an array list that takes ownership of the allocated memory. | |
| 2631 | /// Resets the `Allocating` to an empty state. | |
| 2632 | pub fn toArrayListAligned( | |
| 2633 | a: *Allocating, | |
| 2634 | comptime alignment: std.mem.Alignment, | |
| 2635 | ) std.array_list.Aligned(u8, alignment) { | |
| 2636 | assert(a.alignment == alignment); // Required for Allocator correctness. | |
| 2600 | 2637 | const w = &a.writer; |
| 2601 | const result: ArrayList(u8) = .{ | |
| 2602 | .items = w.buffer[0..w.end], | |
| 2638 | const result: std.array_list.Aligned(u8, alignment) = .{ | |
| 2639 | .items = @alignCast(w.buffer[0..w.end]), | |
| 2603 | 2640 | .capacity = w.buffer.len, |
| 2604 | 2641 | }; |
| 2605 | 2642 | w.buffer = &.{}; |
| ... | ... | @@ -2608,28 +2645,74 @@ pub const Allocating = struct { |
| 2608 | 2645 | } |
| 2609 | 2646 | |
| 2610 | 2647 | pub fn ensureUnusedCapacity(a: *Allocating, additional_count: usize) Allocator.Error!void { |
| 2611 | var list = a.toArrayList(); | |
| 2612 | defer a.setArrayList(list); | |
| 2613 | return list.ensureUnusedCapacity(a.allocator, additional_count); | |
| 2648 | const new_capacity = std.math.add(usize, a.writer.end, additional_count) catch return error.OutOfMemory; | |
| 2649 | return ensureTotalCapacity(a, new_capacity); | |
| 2614 | 2650 | } |
| 2615 | 2651 | |
| 2616 | 2652 | pub fn ensureTotalCapacity(a: *Allocating, new_capacity: usize) Allocator.Error!void { |
| 2617 | var list = a.toArrayList(); | |
| 2618 | defer a.setArrayList(list); | |
| 2619 | return list.ensureTotalCapacity(a.allocator, new_capacity); | |
| 2620 | } | |
| 2653 | // Protects growing unnecessarily since better_capacity will be larger. | |
| 2654 | if (a.writer.buffer.len >= new_capacity) return; | |
| 2655 | const better_capacity = ArrayList(u8).growCapacity(a.writer.buffer.len, new_capacity); | |
| 2656 | return ensureTotalCapacityPrecise(a, better_capacity); | |
| 2657 | } | |
| 2658 | ||
| 2659 | pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void { | |
| 2660 | const old_memory = a.writer.buffer; | |
| 2661 | if (old_memory.len >= new_capacity) return; | |
| 2662 | assert(new_capacity != 0); | |
| 2663 | const alignment = a.alignment; | |
| 2664 | if (old_memory.len > 0) { | |
| 2665 | if (a.allocator.rawRemap(old_memory, alignment, new_capacity, @returnAddress())) |new| { | |
| 2666 | a.writer.buffer = new[0..new_capacity]; | |
| 2667 | return; | |
| 2668 | } | |
| 2669 | } | |
| 2670 | const new_memory = (a.allocator.rawAlloc(new_capacity, alignment, @returnAddress()) orelse | |
| 2671 | return error.OutOfMemory)[0..new_capacity]; | |
| 2672 | const saved = old_memory[0..a.writer.end]; | |
| 2673 | @memcpy(new_memory[0..saved.len], saved); | |
| 2674 | if (old_memory.len != 0) a.allocator.rawFree(old_memory, alignment, @returnAddress()); | |
| 2675 | a.writer.buffer = new_memory; | |
| 2676 | } | |
| 2677 | ||
| 2678 | pub fn toOwnedSlice(a: *Allocating) Allocator.Error![]u8 { | |
| 2679 | const old_memory = a.writer.buffer; | |
| 2680 | const alignment = a.alignment; | |
| 2681 | const buffered_len = a.writer.end; | |
| 2682 | ||
| 2683 | if (old_memory.len > 0) { | |
| 2684 | if (buffered_len == 0) { | |
| 2685 | a.allocator.rawFree(old_memory, alignment, @returnAddress()); | |
| 2686 | a.writer.buffer = &.{}; | |
| 2687 | a.writer.end = 0; | |
| 2688 | return old_memory[0..0]; | |
| 2689 | } else if (a.allocator.rawRemap(old_memory, alignment, buffered_len, @returnAddress())) |new| { | |
| 2690 | a.writer.buffer = &.{}; | |
| 2691 | a.writer.end = 0; | |
| 2692 | return new[0..buffered_len]; | |
| 2693 | } | |
| 2694 | } | |
| 2621 | 2695 | |
| 2622 | pub fn toOwnedSlice(a: *Allocating) error{OutOfMemory}![]u8 { | |
| 2623 | var list = a.toArrayList(); | |
| 2624 | defer a.setArrayList(list); | |
| 2625 | return list.toOwnedSlice(a.allocator); | |
| 2696 | if (buffered_len == 0) | |
| 2697 | return a.writer.buffer[0..0]; | |
| 2698 | ||
| 2699 | const new_memory = (a.allocator.rawAlloc(buffered_len, alignment, @returnAddress()) orelse | |
| 2700 | return error.OutOfMemory)[0..buffered_len]; | |
| 2701 | @memcpy(new_memory, old_memory[0..buffered_len]); | |
| 2702 | if (old_memory.len != 0) a.allocator.rawFree(old_memory, alignment, @returnAddress()); | |
| 2703 | a.writer.buffer = &.{}; | |
| 2704 | a.writer.end = 0; | |
| 2705 | return new_memory; | |
| 2626 | 2706 | } |
| 2627 | 2707 | |
| 2628 | pub fn toOwnedSliceSentinel(a: *Allocating, comptime sentinel: u8) error{OutOfMemory}![:sentinel]u8 { | |
| 2629 | const gpa = a.allocator; | |
| 2630 | var list = @This().toArrayList(a); | |
| 2631 | defer a.setArrayList(list); | |
| 2632 | return list.toOwnedSliceSentinel(gpa, sentinel); | |
| 2708 | pub fn toOwnedSliceSentinel(a: *Allocating, comptime sentinel: u8) Allocator.Error![:sentinel]u8 { | |
| 2709 | // This addition can never overflow because `a.writer.buffer` can never occupy the whole address space. | |
| 2710 | try ensureTotalCapacityPrecise(a, a.writer.end + 1); | |
| 2711 | a.writer.buffer[a.writer.end] = sentinel; | |
| 2712 | a.writer.end += 1; | |
| 2713 | errdefer a.writer.end -= 1; | |
| 2714 | const result = try toOwnedSlice(a); | |
| 2715 | return result[0 .. result.len - 1 :sentinel]; | |
| 2633 | 2716 | } |
| 2634 | 2717 | |
| 2635 | 2718 | pub fn written(a: *Allocating) []u8 { |
| ... | ... | @@ -2646,57 +2729,50 @@ pub const Allocating = struct { |
| 2646 | 2729 | |
| 2647 | 2730 | fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize { |
| 2648 | 2731 | const a: *Allocating = @fieldParentPtr("writer", w); |
| 2649 | const gpa = a.allocator; | |
| 2650 | 2732 | const pattern = data[data.len - 1]; |
| 2651 | 2733 | const splat_len = pattern.len * splat; |
| 2652 | var list = a.toArrayList(); | |
| 2653 | defer setArrayList(a, list); | |
| 2654 | const start_len = list.items.len; | |
| 2734 | const start_len = a.writer.end; | |
| 2655 | 2735 | assert(data.len != 0); |
| 2656 | 2736 | for (data) |bytes| { |
| 2657 | list.ensureUnusedCapacity(gpa, bytes.len + splat_len + 1) catch return error.WriteFailed; | |
| 2658 | list.appendSliceAssumeCapacity(bytes); | |
| 2737 | a.ensureUnusedCapacity(bytes.len + splat_len + 1) catch return error.WriteFailed; | |
| 2738 | @memcpy(a.writer.buffer[a.writer.end..][0..bytes.len], bytes); | |
| 2739 | a.writer.end += bytes.len; | |
| 2659 | 2740 | } |
| 2660 | 2741 | if (splat == 0) { |
| 2661 | list.items.len -= pattern.len; | |
| 2742 | a.writer.end -= pattern.len; | |
| 2662 | 2743 | } else switch (pattern.len) { |
| 2663 | 2744 | 0 => {}, |
| 2664 | 1 => list.appendNTimesAssumeCapacity(pattern[0], splat - 1), | |
| 2665 | else => for (0..splat - 1) |_| list.appendSliceAssumeCapacity(pattern), | |
| 2745 | 1 => { | |
| 2746 | @memset(a.writer.buffer[a.writer.end..][0 .. splat - 1], pattern[0]); | |
| 2747 | a.writer.end += splat - 1; | |
| 2748 | }, | |
| 2749 | else => for (0..splat - 1) |_| { | |
| 2750 | @memcpy(a.writer.buffer[a.writer.end..][0..pattern.len], pattern); | |
| 2751 | a.writer.end += pattern.len; | |
| 2752 | }, | |
| 2666 | 2753 | } |
| 2667 | return list.items.len - start_len; | |
| 2754 | return a.writer.end - start_len; | |
| 2668 | 2755 | } |
| 2669 | 2756 | |
| 2670 | 2757 | fn sendFile(w: *Writer, file_reader: *File.Reader, limit: Limit) FileError!usize { |
| 2671 | 2758 | if (File.Handle == void) return error.Unimplemented; |
| 2672 | 2759 | if (limit == .nothing) return 0; |
| 2673 | 2760 | const a: *Allocating = @fieldParentPtr("writer", w); |
| 2674 | const gpa = a.allocator; | |
| 2675 | var list = a.toArrayList(); | |
| 2676 | defer setArrayList(a, list); | |
| 2677 | 2761 | const pos = file_reader.logicalPos(); |
| 2678 | 2762 | const additional = if (file_reader.getSize()) |size| size - pos else |_| std.atomic.cache_line; |
| 2679 | 2763 | if (additional == 0) return error.EndOfStream; |
| 2680 | list.ensureUnusedCapacity(gpa, limit.minInt64(additional)) catch return error.WriteFailed; | |
| 2681 | const dest = limit.slice(list.unusedCapacitySlice()); | |
| 2764 | a.ensureUnusedCapacity(limit.minInt64(additional)) catch return error.WriteFailed; | |
| 2765 | const dest = limit.slice(a.writer.buffer[a.writer.end..]); | |
| 2682 | 2766 | const n = try file_reader.read(dest); |
| 2683 | list.items.len += n; | |
| 2767 | a.writer.end += n; | |
| 2684 | 2768 | return n; |
| 2685 | 2769 | } |
| 2686 | 2770 | |
| 2687 | 2771 | fn growingRebase(w: *Writer, preserve: usize, minimum_len: usize) Error!void { |
| 2688 | 2772 | const a: *Allocating = @fieldParentPtr("writer", w); |
| 2689 | const gpa = a.allocator; | |
| 2690 | var list = a.toArrayList(); | |
| 2691 | defer setArrayList(a, list); | |
| 2692 | 2773 | const total = std.math.add(usize, preserve, minimum_len) catch return error.WriteFailed; |
| 2693 | list.ensureTotalCapacity(gpa, total) catch return error.WriteFailed; | |
| 2694 | list.ensureUnusedCapacity(gpa, minimum_len) catch return error.WriteFailed; | |
| 2695 | } | |
| 2696 | ||
| 2697 | fn setArrayList(a: *Allocating, list: ArrayList(u8)) void { | |
| 2698 | a.writer.buffer = list.allocatedSlice(); | |
| 2699 | a.writer.end = list.items.len; | |
| 2774 | a.ensureTotalCapacity(total) catch return error.WriteFailed; | |
| 2775 | a.ensureUnusedCapacity(minimum_len) catch return error.WriteFailed; | |
| 2700 | 2776 | } |
| 2701 | 2777 | |
| 2702 | 2778 | test Allocating { |
lib/std/Io/fixed_buffer_stream.zig deleted-114| ... | ... | @@ -1,114 +0,0 @@ |
| 1 | const std = @import("../std.zig"); | |
| 2 | const io = std.io; | |
| 3 | const testing = std.testing; | |
| 4 | const mem = std.mem; | |
| 5 | const assert = std.debug.assert; | |
| 6 | ||
| 7 | /// Deprecated in favor of `std.Io.Reader.fixed` and `std.Io.Writer.fixed`. | |
| 8 | pub 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 | ||
| 71 | pub fn fixedBufferStream(buffer: anytype) FixedBufferStream(Slice(@TypeOf(buffer))) { | |
| 72 | return .{ .buffer = buffer, .pos = 0 }; | |
| 73 | } | |
| 74 | ||
| 75 | fn 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 | ||
| 94 | test "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 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const io = std.io; | |
| 3 | 2 | const DefaultPrng = std.Random.DefaultPrng; |
| 4 | 3 | const expect = std.testing.expect; |
| 5 | 4 | const expectEqual = std.testing.expectEqual; |
| ... | ... | @@ -122,24 +121,3 @@ test "updateTimes" { |
| 122 | 121 | try expect(stat_new.atime < stat_old.atime); |
| 123 | 122 | try expect(stat_new.mtime < stat_old.mtime); |
| 124 | 123 | } |
| 125 | ||
| 126 | test "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 | ||
| 139 | test "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) { |
| 76 | 76 | reset_attributes: u16, |
| 77 | 77 | }; |
| 78 | 78 | |
| 79 | pub const SetColorError = std.os.windows.SetConsoleTextAttributeError || std.io.Writer.Error; | |
| 79 | pub const SetColorError = std.os.windows.SetConsoleTextAttributeError || std.Io.Writer.Error; | |
| 80 | 80 | |
| 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 { | |
| 82 | 82 | nosuspend switch (conf) { |
| 83 | 83 | .no_color => return, |
| 84 | 84 | .escape_codes => { |
lib/std/Progress.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ const Progress = @This(); |
| 9 | 9 | const posix = std.posix; |
| 10 | 10 | const is_big_endian = builtin.cpu.arch.endian() == .big; |
| 11 | 11 | const is_windows = builtin.os.tag == .windows; |
| 12 | const Writer = std.io.Writer; | |
| 12 | const Writer = std.Io.Writer; | |
| 13 | 13 | |
| 14 | 14 | /// `null` if the current node (and its children) should |
| 15 | 15 | /// not print on update() |
lib/std/SemanticVersion.zig+1-1| ... | ... | @@ -150,7 +150,7 @@ fn parseNum(text: []const u8) error{ InvalidVersion, Overflow }!usize { |
| 150 | 150 | }; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | pub fn format(self: Version, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 153 | pub fn format(self: Version, w: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 154 | 154 | try w.print("{d}.{d}.{d}", .{ self.major, self.minor, self.patch }); |
| 155 | 155 | if (self.pre) |pre| try w.print("-{s}", .{pre}); |
| 156 | 156 | if (self.build) |build| try w.print("+{s}", .{build}); |
lib/std/Target.zig+1-1| ... | ... | @@ -311,7 +311,7 @@ pub const Os = struct { |
| 311 | 311 | |
| 312 | 312 | /// This function is defined to serialize a Zig source code representation of this |
| 313 | 313 | /// type, that, when parsed, will deserialize into the same data. |
| 314 | pub fn format(wv: WindowsVersion, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 314 | pub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 315 | 315 | if (std.enums.tagName(WindowsVersion, wv)) |name| { |
| 316 | 316 | var vecs: [2][]const u8 = .{ ".", name }; |
| 317 | 317 | return w.writeVecAll(&vecs); |
lib/std/Thread.zig+4-2| ... | ... | @@ -280,8 +280,10 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 280 | 280 | const file = try std.fs.cwd().openFile(path, .{}); |
| 281 | 281 | defer file.close(); |
| 282 | 282 | |
| 283 | const data_len = try file.deprecatedReader().readAll(buffer_ptr[0 .. max_name_len + 1]); | |
| 284 | ||
| 283 | var file_reader = file.readerStreaming(&.{}); | |
| 284 | const data_len = file_reader.interface.readSliceShort(buffer_ptr[0 .. max_name_len + 1]) catch |err| switch (err) { | |
| 285 | error.ReadFailed => return file_reader.err.?, | |
| 286 | }; | |
| 285 | 287 | return if (data_len >= 1) buffer[0 .. data_len - 1] else null; |
| 286 | 288 | }, |
| 287 | 289 | .windows => { |
lib/std/array_list.zig+6-4| ... | ... | @@ -405,6 +405,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type |
| 405 | 405 | return; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | // Protects growing unnecessarily since better_capacity will be larger. | |
| 408 | 409 | if (self.capacity >= new_capacity) return; |
| 409 | 410 | |
| 410 | 411 | const better_capacity = Aligned(T, alignment).growCapacity(self.capacity, new_capacity); |
| ... | ... | @@ -664,9 +665,10 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 664 | 665 | |
| 665 | 666 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 666 | 667 | pub fn toOwnedSliceSentinel(self: *Self, gpa: Allocator, comptime sentinel: T) Allocator.Error!SentinelSlice(sentinel) { |
| 667 | // This addition can never overflow because `self.items` can never occupy the whole address space | |
| 668 | // This addition can never overflow because `self.items` can never occupy the whole address space. | |
| 668 | 669 | try self.ensureTotalCapacityPrecise(gpa, self.items.len + 1); |
| 669 | 670 | self.appendAssumeCapacity(sentinel); |
| 671 | errdefer self.items.len -= 1; | |
| 670 | 672 | const result = try self.toOwnedSlice(gpa); |
| 671 | 673 | return result[0 .. result.len - 1 :sentinel]; |
| 672 | 674 | } |
| ... | ... | @@ -1038,14 +1040,14 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 1038 | 1040 | |
| 1039 | 1041 | pub fn printAssumeCapacity(self: *Self, comptime fmt: []const u8, args: anytype) void { |
| 1040 | 1042 | comptime assert(T == u8); |
| 1041 | var w: std.io.Writer = .fixed(self.unusedCapacitySlice()); | |
| 1043 | var w: std.Io.Writer = .fixed(self.unusedCapacitySlice()); | |
| 1042 | 1044 | w.print(fmt, args) catch unreachable; |
| 1043 | 1045 | self.items.len += w.end; |
| 1044 | 1046 | } |
| 1045 | 1047 | |
| 1046 | 1048 | pub fn printBounded(self: *Self, comptime fmt: []const u8, args: anytype) error{OutOfMemory}!void { |
| 1047 | 1049 | comptime assert(T == u8); |
| 1048 | var w: std.io.Writer = .fixed(self.unusedCapacitySlice()); | |
| 1050 | var w: std.Io.Writer = .fixed(self.unusedCapacitySlice()); | |
| 1049 | 1051 | w.print(fmt, args) catch return error.OutOfMemory; |
| 1050 | 1052 | self.items.len += w.end; |
| 1051 | 1053 | } |
| ... | ... | @@ -1361,7 +1363,7 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type { |
| 1361 | 1363 | |
| 1362 | 1364 | /// Called when memory growth is necessary. Returns a capacity larger than |
| 1363 | 1365 | /// minimum that grows super-linearly. |
| 1364 | fn growCapacity(current: usize, minimum: usize) usize { | |
| 1366 | pub fn growCapacity(current: usize, minimum: usize) usize { | |
| 1365 | 1367 | var new = current; |
| 1366 | 1368 | while (true) { |
| 1367 | 1369 | new +|= new / 2 + init_capacity; |
lib/std/ascii.zig+1-1| ... | ... | @@ -444,7 +444,7 @@ pub const HexEscape = struct { |
| 444 | 444 | pub const upper_charset = "0123456789ABCDEF"; |
| 445 | 445 | pub const lower_charset = "0123456789abcdef"; |
| 446 | 446 | |
| 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 { | |
| 448 | 448 | const charset = se.charset; |
| 449 | 449 | |
| 450 | 450 | var buf: [4]u8 = undefined; |
lib/std/builtin.zig+2-2| ... | ... | @@ -38,7 +38,7 @@ pub const StackTrace = struct { |
| 38 | 38 | index: usize, |
| 39 | 39 | instruction_addresses: []usize, |
| 40 | 40 | |
| 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 { | |
| 42 | 42 | // TODO: re-evaluate whether to use format() methods at all. |
| 43 | 43 | // Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly |
| 44 | 44 | // where it tries to call detectTTYConfig here. |
| ... | ... | @@ -47,7 +47,7 @@ pub const StackTrace = struct { |
| 47 | 47 | const debug_info = std.debug.getSelfDebugInfo() catch |err| { |
| 48 | 48 | return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}); |
| 49 | 49 | }; |
| 50 | const tty_config = std.io.tty.detectConfig(std.fs.File.stderr()); | |
| 50 | const tty_config = std.Io.tty.detectConfig(std.fs.File.stderr()); | |
| 51 | 51 | try writer.writeAll("\n"); |
| 52 | 52 | std.debug.writeStackTrace(self, writer, debug_info, tty_config) catch |err| { |
| 53 | 53 | 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 { |
| 1087 | 1087 | const pe_pointer_offset = 0x3C; |
| 1088 | 1088 | const pe_magic = "PE\x00\x00"; |
| 1089 | 1089 | |
| 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)); | |
| 1098 | 1095 | |
| 1099 | 1096 | var coff = @This(){ |
| 1100 | 1097 | .data = data, |
| ... | ... | @@ -1123,16 +1120,15 @@ pub const Coff = struct { |
| 1123 | 1120 | if (@intFromEnum(DirectoryEntry.DEBUG) >= data_dirs.len) return null; |
| 1124 | 1121 | |
| 1125 | 1122 | 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); | |
| 1128 | 1124 | |
| 1129 | 1125 | if (self.is_loaded) { |
| 1130 | try stream.seekTo(debug_dir.virtual_address); | |
| 1126 | reader.seek = debug_dir.virtual_address; | |
| 1131 | 1127 | } else { |
| 1132 | 1128 | // Find what section the debug_dir is in, in order to convert the RVA to a file offset |
| 1133 | 1129 | for (self.getSectionHeaders()) |*sect| { |
| 1134 | 1130 | 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); | |
| 1136 | 1132 | break; |
| 1137 | 1133 | } |
| 1138 | 1134 | } else return error.InvalidDebugDirectory; |
| ... | ... | @@ -1143,24 +1139,23 @@ pub const Coff = struct { |
| 1143 | 1139 | const debug_dir_entry_count = debug_dir.size / @sizeOf(DebugDirectoryEntry); |
| 1144 | 1140 | var i: u32 = 0; |
| 1145 | 1141 | 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); | |
| 1147 | 1143 | if (debug_dir_entry.type == .CODEVIEW) { |
| 1148 | 1144 | 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; | |
| 1150 | 1146 | break; |
| 1151 | 1147 | } |
| 1152 | 1148 | } else return null; |
| 1153 | 1149 | |
| 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); | |
| 1156 | 1151 | // 'RSDS' indicates PDB70 format, used by lld. |
| 1157 | if (!mem.eql(u8, &cv_signature, "RSDS")) | |
| 1152 | if (!mem.eql(u8, code_view_signature, "RSDS")) | |
| 1158 | 1153 | 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); | |
| 1161 | 1156 | |
| 1162 | 1157 | // Finally read the null-terminated string. |
| 1163 | const start = reader.context.pos; | |
| 1158 | const start = reader.seek; | |
| 1164 | 1159 | const len = std.mem.indexOfScalar(u8, self.data[start..], 0) orelse return null; |
| 1165 | 1160 | return self.data[start .. start + len]; |
| 1166 | 1161 | } |
lib/std/compress/flate/BlockWriter.zig+1-2| ... | ... | @@ -1,9 +1,8 @@ |
| 1 | 1 | //! Accepts list of tokens, decides what is best block type to write. What block |
| 2 | 2 | //! type will provide best compression. Writes header and body of the block. |
| 3 | 3 | const std = @import("std"); |
| 4 | const io = std.io; | |
| 5 | 4 | const assert = std.debug.assert; |
| 6 | const Writer = std.io.Writer; | |
| 5 | const Writer = std.Io.Writer; | |
| 7 | 6 | |
| 8 | 7 | const BlockWriter = @This(); |
| 9 | 8 | const flate = @import("../flate.zig"); |
lib/std/compress/zstd/Decompress.zig+3-3| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | 1 | const Decompress = @This(); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const Reader = std.io.Reader; | |
| 5 | const Limit = std.io.Limit; | |
| 4 | const Reader = std.Io.Reader; | |
| 5 | const Limit = std.Io.Limit; | |
| 6 | 6 | const zstd = @import("../zstd.zig"); |
| 7 | const Writer = std.io.Writer; | |
| 7 | const Writer = std.Io.Writer; | |
| 8 | 8 | |
| 9 | 9 | input: *Reader, |
| 10 | 10 | reader: Reader, |
lib/std/crypto/Certificate/Bundle/macos.zig+50-45| ... | ... | @@ -11,76 +11,81 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 11 | 11 | cb.bytes.clearRetainingCapacity(); |
| 12 | 12 | cb.map.clearRetainingCapacity(); |
| 13 | 13 | |
| 14 | const keychainPaths = [2][]const u8{ | |
| 14 | const keychain_paths = [2][]const u8{ | |
| 15 | 15 | "/System/Library/Keychains/SystemRootCertificates.keychain", |
| 16 | 16 | "/Library/Keychains/System.keychain", |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | for (keychainPaths) |keychainPath| { | |
| 20 | const file = try fs.openFileAbsolute(keychainPath, .{}); | |
| 21 | defer file.close(); | |
| 22 | ||
| 23 | const bytes = try file.readToEndAlloc(gpa, std.math.maxInt(u32)); | |
| 19 | for (keychain_paths) |keychain_path| { | |
| 20 | const bytes = std.fs.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) { | |
| 21 | error.StreamTooLong => return error.FileTooBig, | |
| 22 | else => |e| return e, | |
| 23 | }; | |
| 24 | 24 | defer gpa.free(bytes); |
| 25 | 25 | |
| 26 | var stream = std.io.fixedBufferStream(bytes); | |
| 27 | const reader = stream.reader(); | |
| 26 | var reader: std.Io.Reader = .fixed(bytes); | |
| 27 | scanReader(cb, gpa, &reader) catch |err| switch (err) { | |
| 28 | error.ReadFailed => unreachable, // prebuffered | |
| 29 | else => |e| return e, | |
| 30 | }; | |
| 31 | } | |
| 28 | 32 | |
| 29 | const db_header = try reader.readStructEndian(ApplDbHeader, .big); | |
| 30 | assert(mem.eql(u8, &db_header.signature, "kych")); | |
| 33 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); | |
| 34 | } | |
| 31 | 35 | |
| 32 | try stream.seekTo(db_header.schema_offset); | |
| 36 | fn scanReader(cb: *Bundle, gpa: Allocator, reader: *std.Io.Reader) !void { | |
| 37 | const db_header = try reader.takeStruct(ApplDbHeader, .big); | |
| 38 | assert(mem.eql(u8, &db_header.signature, "kych")); | |
| 33 | 39 | |
| 34 | const db_schema = try reader.readStructEndian(ApplDbSchema, .big); | |
| 40 | reader.seek = db_header.schema_offset; | |
| 35 | 41 | |
| 36 | var table_list = try gpa.alloc(u32, db_schema.table_count); | |
| 37 | defer gpa.free(table_list); | |
| 42 | const db_schema = try reader.takeStruct(ApplDbSchema, .big); | |
| 38 | 43 | |
| 39 | var table_idx: u32 = 0; | |
| 40 | while (table_idx < table_list.len) : (table_idx += 1) { | |
| 41 | table_list[table_idx] = try reader.readInt(u32, .big); | |
| 42 | } | |
| 44 | var table_list = try gpa.alloc(u32, db_schema.table_count); | |
| 45 | defer gpa.free(table_list); | |
| 43 | 46 | |
| 44 | const now_sec = std.time.timestamp(); | |
| 47 | var table_idx: u32 = 0; | |
| 48 | while (table_idx < table_list.len) : (table_idx += 1) { | |
| 49 | table_list[table_idx] = try reader.takeInt(u32, .big); | |
| 50 | } | |
| 45 | 51 | |
| 46 | for (table_list) |table_offset| { | |
| 47 | try stream.seekTo(db_header.schema_offset + table_offset); | |
| 52 | const now_sec = std.time.timestamp(); | |
| 48 | 53 | |
| 49 | const table_header = try reader.readStructEndian(TableHeader, .big); | |
| 54 | for (table_list) |table_offset| { | |
| 55 | reader.seek = db_header.schema_offset + table_offset; | |
| 50 | 56 | |
| 51 | if (@as(std.c.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) { | |
| 52 | continue; | |
| 53 | } | |
| 57 | const table_header = try reader.takeStruct(TableHeader, .big); | |
| 54 | 58 | |
| 55 | var record_list = try gpa.alloc(u32, table_header.record_count); | |
| 56 | defer gpa.free(record_list); | |
| 59 | if (@as(std.c.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) { | |
| 60 | continue; | |
| 61 | } | |
| 62 | ||
| 63 | var record_list = try gpa.alloc(u32, table_header.record_count); | |
| 64 | defer gpa.free(record_list); | |
| 57 | 65 | |
| 58 | var record_idx: u32 = 0; | |
| 59 | while (record_idx < record_list.len) : (record_idx += 1) { | |
| 60 | record_list[record_idx] = try reader.readInt(u32, .big); | |
| 61 | } | |
| 66 | var record_idx: u32 = 0; | |
| 67 | while (record_idx < record_list.len) : (record_idx += 1) { | |
| 68 | record_list[record_idx] = try reader.takeInt(u32, .big); | |
| 69 | } | |
| 62 | 70 | |
| 63 | for (record_list) |record_offset| { | |
| 64 | // An offset of zero means that the record is not present. | |
| 65 | // An offset that is not 4-byte-aligned is invalid. | |
| 66 | if (record_offset == 0 or record_offset % 4 != 0) continue; | |
| 71 | for (record_list) |record_offset| { | |
| 72 | // An offset of zero means that the record is not present. | |
| 73 | // An offset that is not 4-byte-aligned is invalid. | |
| 74 | if (record_offset == 0 or record_offset % 4 != 0) continue; | |
| 67 | 75 | |
| 68 | try stream.seekTo(db_header.schema_offset + table_offset + record_offset); | |
| 76 | reader.seek = db_header.schema_offset + table_offset + record_offset; | |
| 69 | 77 | |
| 70 | const cert_header = try reader.readStructEndian(X509CertHeader, .big); | |
| 78 | const cert_header = try reader.takeStruct(X509CertHeader, .big); | |
| 71 | 79 | |
| 72 | if (cert_header.cert_size == 0) continue; | |
| 80 | if (cert_header.cert_size == 0) continue; | |
| 73 | 81 | |
| 74 | const cert_start = @as(u32, @intCast(cb.bytes.items.len)); | |
| 75 | const dest_buf = try cb.bytes.addManyAsSlice(gpa, cert_header.cert_size); | |
| 76 | try reader.readNoEof(dest_buf); | |
| 82 | const cert_start: u32 = @intCast(cb.bytes.items.len); | |
| 83 | const dest_buf = try cb.bytes.addManyAsSlice(gpa, cert_header.cert_size); | |
| 84 | try reader.readSliceAll(dest_buf); | |
| 77 | 85 | |
| 78 | try cb.parseCert(gpa, cert_start, now_sec); | |
| 79 | } | |
| 86 | try cb.parseCert(gpa, cert_start, now_sec); | |
| 80 | 87 | } |
| 81 | 88 | } |
| 82 | ||
| 83 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); | |
| 84 | 89 | } |
| 85 | 90 | |
| 86 | 91 | const ApplDbHeader = extern struct { |
lib/std/crypto/codecs/asn1.zig+13-15| ... | ... | @@ -69,15 +69,15 @@ pub const Tag = struct { |
| 69 | 69 | return .{ .number = number, .constructed = constructed, .class = .universal }; |
| 70 | 70 | } |
| 71 | 71 | |
| 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()); | |
| 74 | 74 | var number: u14 = tag1.number; |
| 75 | 75 | |
| 76 | 76 | if (tag1.number == 15) { |
| 77 | const tag2: NextTag = @bitCast(try reader.readByte()); | |
| 77 | const tag2: NextTag = @bitCast(try reader.takeByte()); | |
| 78 | 78 | number = tag2.number; |
| 79 | 79 | if (tag2.continues) { |
| 80 | const tag3: NextTag = @bitCast(try reader.readByte()); | |
| 80 | const tag3: NextTag = @bitCast(try reader.takeByte()); | |
| 81 | 81 | number = (number << 7) + tag3.number; |
| 82 | 82 | if (tag3.continues) return error.InvalidLength; |
| 83 | 83 | } |
| ... | ... | @@ -90,7 +90,7 @@ pub const Tag = struct { |
| 90 | 90 | }; |
| 91 | 91 | } |
| 92 | 92 | |
| 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 { | |
| 94 | 94 | var tag1 = FirstTag{ |
| 95 | 95 | .number = undefined, |
| 96 | 96 | .constructed = self.constructed, |
| ... | ... | @@ -98,8 +98,7 @@ pub const Tag = struct { |
| 98 | 98 | }; |
| 99 | 99 | |
| 100 | 100 | 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); | |
| 103 | 102 | |
| 104 | 103 | switch (@intFromEnum(self.number)) { |
| 105 | 104 | 0...std.math.maxInt(u5) => |n| { |
| ... | ... | @@ -122,7 +121,7 @@ pub const Tag = struct { |
| 122 | 121 | }, |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | _ = try writer.write(stream.getWritten()); | |
| 124 | _ = try writer.write(writer2.buffered()); | |
| 126 | 125 | } |
| 127 | 126 | |
| 128 | 127 | const FirstTag = packed struct(u8) { number: u5, constructed: bool, class: Tag.Class }; |
| ... | ... | @@ -161,8 +160,8 @@ pub const Tag = struct { |
| 161 | 160 | |
| 162 | 161 | test Tag { |
| 163 | 162 | 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); | |
| 166 | 165 | try std.testing.expectEqual(Tag.init(@enumFromInt(3), true, .context_specific), t); |
| 167 | 166 | } |
| 168 | 167 | |
| ... | ... | @@ -191,11 +190,10 @@ pub const Element = struct { |
| 191 | 190 | /// - Ensures length is within `bytes` |
| 192 | 191 | /// - Ensures length is less than `std.math.maxInt(Index)` |
| 193 | 192 | 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..]); | |
| 196 | 194 | |
| 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(); | |
| 199 | 197 | |
| 200 | 198 | var start = index + 2; |
| 201 | 199 | var end = start + size_or_len_size; |
| ... | ... | @@ -208,7 +206,7 @@ pub const Element = struct { |
| 208 | 206 | start += len_size; |
| 209 | 207 | if (len_size > @sizeOf(Index)) return error.InvalidLength; |
| 210 | 208 | |
| 211 | const len = try reader.readVarInt(Index, .big, len_size); | |
| 209 | const len = try reader.takeVarInt(Index, .big, len_size); | |
| 212 | 210 | if (len < 128) return error.InvalidLength; // should have used short form |
| 213 | 211 | |
| 214 | 212 | end = std.math.add(Index, start, len) catch return error.InvalidLength; |
lib/std/crypto/codecs/asn1/Oid.zig+6-7| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | //! organizations, or policy documents. |
| 5 | 5 | encoded: []const u8, |
| 6 | 6 | |
| 7 | pub const InitError = std.fmt.ParseIntError || error{MissingPrefix} || std.io.FixedBufferStream(u8).WriteError; | |
| 7 | pub const InitError = std.fmt.ParseIntError || error{MissingPrefix} || std.Io.Writer.Error; | |
| 8 | 8 | |
| 9 | 9 | pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid { |
| 10 | 10 | var split = std.mem.splitScalar(u8, dot_notation, '.'); |
| ... | ... | @@ -14,8 +14,7 @@ pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid { |
| 14 | 14 | const first = try std.fmt.parseInt(u8, first_str, 10); |
| 15 | 15 | const second = try std.fmt.parseInt(u8, second_str, 10); |
| 16 | 16 | |
| 17 | var stream = std.io.fixedBufferStream(out); | |
| 18 | var writer = stream.writer(); | |
| 17 | var writer: std.Io.Writer = .fixed(out); | |
| 19 | 18 | |
| 20 | 19 | try writer.writeByte(first * 40 + second); |
| 21 | 20 | |
| ... | ... | @@ -37,7 +36,7 @@ pub fn fromDot(dot_notation: []const u8, out: []u8) InitError!Oid { |
| 37 | 36 | i += 1; |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | return .{ .encoded = stream.getWritten() }; | |
| 39 | return .{ .encoded = writer.buffered() }; | |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | test fromDot { |
| ... | ... | @@ -80,9 +79,9 @@ test toDot { |
| 80 | 79 | var buf: [256]u8 = undefined; |
| 81 | 80 | |
| 82 | 81 | 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()); | |
| 86 | 85 | } |
| 87 | 86 | } |
| 88 | 87 |
lib/std/crypto/ecdsa.zig+12-17| ... | ... | @@ -2,7 +2,6 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const crypto = std.crypto; |
| 4 | 4 | const fmt = std.fmt; |
| 5 | const io = std.io; | |
| 6 | 5 | const mem = std.mem; |
| 7 | 6 | const sha3 = crypto.hash.sha3; |
| 8 | 7 | const testing = std.testing; |
| ... | ... | @@ -135,8 +134,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 135 | 134 | /// The maximum length of the DER encoding is der_encoded_length_max. |
| 136 | 135 | /// The function returns a slice, that can be shorter than der_encoded_length_max. |
| 137 | 136 | 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); | |
| 140 | 138 | const r_len = @as(u8, @intCast(sig.r.len + (sig.r[0] >> 7))); |
| 141 | 139 | const s_len = @as(u8, @intCast(sig.s.len + (sig.s[0] >> 7))); |
| 142 | 140 | 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 { |
| 151 | 149 | w.writeByte(0x00) catch unreachable; |
| 152 | 150 | } |
| 153 | 151 | w.writeAll(&sig.s) catch unreachable; |
| 154 | return fb.getWritten(); | |
| 152 | return w.buffered(); | |
| 155 | 153 | } |
| 156 | 154 | |
| 157 | 155 | // 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; | |
| 161 | 158 | if (buf[0] != 0x02) return error.InvalidEncoding; |
| 162 | var expected_len = @as(usize, buf[1]); | |
| 159 | var expected_len: usize = buf[1]; | |
| 163 | 160 | if (expected_len == 0 or expected_len > 1 + out.len) return error.InvalidEncoding; |
| 164 | 161 | var has_top_bit = false; |
| 165 | 162 | 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; | |
| 167 | 164 | expected_len -= 1; |
| 168 | 165 | has_top_bit = true; |
| 169 | 166 | } |
| 170 | 167 | 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; | |
| 172 | 169 | if (@intFromBool(has_top_bit) != out[0] >> 7) return error.InvalidEncoding; |
| 173 | 170 | } |
| 174 | 171 | |
| ... | ... | @@ -176,16 +173,14 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 176 | 173 | /// Returns InvalidEncoding if the DER encoding is invalid. |
| 177 | 174 | pub fn fromDer(der: []const u8) EncodingError!Signature { |
| 178 | 175 | 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; | |
| 183 | 178 | if (buf[0] != 0x30 or @as(usize, buf[1]) + 2 != der.len) { |
| 184 | 179 | return error.InvalidEncoding; |
| 185 | 180 | } |
| 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; | |
| 189 | 184 | |
| 190 | 185 | return sig; |
| 191 | 186 | } |
lib/std/crypto/phc_encoding.zig-1| ... | ... | @@ -2,7 +2,6 @@ |
| 2 | 2 | |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const fmt = std.fmt; |
| 5 | const io = std.io; | |
| 6 | 5 | const mem = std.mem; |
| 7 | 6 | const meta = std.meta; |
| 8 | 7 | const Writer = std.Io.Writer; |
lib/std/crypto/scrypt.zig-1| ... | ... | @@ -5,7 +5,6 @@ |
| 5 | 5 | const std = @import("std"); |
| 6 | 6 | const crypto = std.crypto; |
| 7 | 7 | const fmt = std.fmt; |
| 8 | const io = std.io; | |
| 9 | 8 | const math = std.math; |
| 10 | 9 | const mem = std.mem; |
| 11 | 10 | const meta = std.meta; |
lib/std/crypto/tls.zig+2-2| ... | ... | @@ -655,7 +655,7 @@ pub const Decoder = struct { |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /// 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 { | |
| 659 | 659 | assert(!d.disable_reads); |
| 660 | 660 | const existing_amt = d.cap - d.idx; |
| 661 | 661 | d.their_end = d.idx + their_amt; |
| ... | ... | @@ -672,7 +672,7 @@ pub const Decoder = struct { |
| 672 | 672 | |
| 673 | 673 | /// Same as `readAtLeast` but also increases `our_end` by exactly `our_amt`. |
| 674 | 674 | /// 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 { | |
| 676 | 676 | assert(!d.disable_reads); |
| 677 | 677 | try readAtLeast(d, stream, our_amt); |
| 678 | 678 | d.our_end = d.idx + our_amt; |
lib/std/debug.zig+19-19| ... | ... | @@ -2,7 +2,6 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std.zig"); |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const mem = std.mem; |
| 5 | const io = std.io; | |
| 6 | 5 | const posix = std.posix; |
| 7 | 6 | const fs = std.fs; |
| 8 | 7 | const testing = std.testing; |
| ... | ... | @@ -12,7 +11,8 @@ const windows = std.os.windows; |
| 12 | 11 | const native_arch = builtin.cpu.arch; |
| 13 | 12 | const native_os = builtin.os.tag; |
| 14 | 13 | const native_endian = native_arch.endian(); |
| 15 | const Writer = std.io.Writer; | |
| 14 | const Writer = std.Io.Writer; | |
| 15 | const tty = std.Io.tty; | |
| 16 | 16 | |
| 17 | 17 | pub const Dwarf = @import("debug/Dwarf.zig"); |
| 18 | 18 | pub const Pdb = @import("debug/Pdb.zig"); |
| ... | ... | @@ -246,12 +246,12 @@ pub fn getSelfDebugInfo() !*SelfInfo { |
| 246 | 246 | pub fn dumpHex(bytes: []const u8) void { |
| 247 | 247 | const bw = lockStderrWriter(&.{}); |
| 248 | 248 | defer unlockStderrWriter(); |
| 249 | const ttyconf = std.io.tty.detectConfig(.stderr()); | |
| 249 | const ttyconf = tty.detectConfig(.stderr()); | |
| 250 | 250 | dumpHexFallible(bw, ttyconf, bytes) catch {}; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /// Prints a hexadecimal view of the bytes, returning any error that occurs. |
| 254 | pub fn dumpHexFallible(bw: *Writer, ttyconf: std.io.tty.Config, bytes: []const u8) !void { | |
| 254 | pub fn dumpHexFallible(bw: *Writer, ttyconf: tty.Config, bytes: []const u8) !void { | |
| 255 | 255 | var chunks = mem.window(u8, bytes, 16, 16); |
| 256 | 256 | while (chunks.next()) |window| { |
| 257 | 257 | // 1. Print the address. |
| ... | ... | @@ -302,7 +302,7 @@ pub fn dumpHexFallible(bw: *Writer, ttyconf: std.io.tty.Config, bytes: []const u |
| 302 | 302 | |
| 303 | 303 | test dumpHexFallible { |
| 304 | 304 | 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); | |
| 306 | 306 | defer aw.deinit(); |
| 307 | 307 | |
| 308 | 308 | try dumpHexFallible(&aw.writer, .no_color, bytes); |
| ... | ... | @@ -342,7 +342,7 @@ pub fn dumpCurrentStackTraceToWriter(start_addr: ?usize, writer: *Writer) !void |
| 342 | 342 | try writer.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}); |
| 343 | 343 | return; |
| 344 | 344 | }; |
| 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| { | |
| 346 | 346 | try writer.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}); |
| 347 | 347 | return; |
| 348 | 348 | }; |
| ... | ... | @@ -427,7 +427,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext, stderr: *Writer) void { |
| 427 | 427 | stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return; |
| 428 | 428 | return; |
| 429 | 429 | }; |
| 430 | const tty_config = io.tty.detectConfig(.stderr()); | |
| 430 | const tty_config = tty.detectConfig(.stderr()); | |
| 431 | 431 | if (native_os == .windows) { |
| 432 | 432 | // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context |
| 433 | 433 | // 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 { |
| 533 | 533 | stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return; |
| 534 | 534 | return; |
| 535 | 535 | }; |
| 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| { | |
| 537 | 537 | stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return; |
| 538 | 538 | return; |
| 539 | 539 | }; |
| ... | ... | @@ -738,7 +738,7 @@ pub fn writeStackTrace( |
| 738 | 738 | stack_trace: std.builtin.StackTrace, |
| 739 | 739 | writer: *Writer, |
| 740 | 740 | debug_info: *SelfInfo, |
| 741 | tty_config: io.tty.Config, | |
| 741 | tty_config: tty.Config, | |
| 742 | 742 | ) !void { |
| 743 | 743 | if (builtin.strip_debug_info) return error.MissingDebugInfo; |
| 744 | 744 | var frame_index: usize = 0; |
| ... | ... | @@ -959,7 +959,7 @@ pub const StackIterator = struct { |
| 959 | 959 | pub fn writeCurrentStackTrace( |
| 960 | 960 | writer: *Writer, |
| 961 | 961 | debug_info: *SelfInfo, |
| 962 | tty_config: io.tty.Config, | |
| 962 | tty_config: tty.Config, | |
| 963 | 963 | start_addr: ?usize, |
| 964 | 964 | ) !void { |
| 965 | 965 | if (native_os == .windows) { |
| ... | ... | @@ -1047,7 +1047,7 @@ pub noinline fn walkStackWindows(addresses: []usize, existing_context: ?*const w |
| 1047 | 1047 | pub fn writeStackTraceWindows( |
| 1048 | 1048 | writer: *Writer, |
| 1049 | 1049 | debug_info: *SelfInfo, |
| 1050 | tty_config: io.tty.Config, | |
| 1050 | tty_config: tty.Config, | |
| 1051 | 1051 | context: *const windows.CONTEXT, |
| 1052 | 1052 | start_addr: ?usize, |
| 1053 | 1053 | ) !void { |
| ... | ... | @@ -1065,7 +1065,7 @@ pub fn writeStackTraceWindows( |
| 1065 | 1065 | } |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: io.tty.Config) !void { | |
| 1068 | fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: tty.Config) !void { | |
| 1069 | 1069 | const module_name = debug_info.getModuleNameForAddress(address); |
| 1070 | 1070 | return printLineInfo( |
| 1071 | 1071 | writer, |
| ... | ... | @@ -1078,14 +1078,14 @@ fn printUnknownSource(debug_info: *SelfInfo, writer: *Writer, address: usize, tt |
| 1078 | 1078 | ); |
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | fn printLastUnwindError(it: *StackIterator, debug_info: *SelfInfo, writer: *Writer, tty_config: io.tty.Config) void { | |
| 1081 | fn printLastUnwindError(it: *StackIterator, debug_info: *SelfInfo, writer: *Writer, tty_config: tty.Config) void { | |
| 1082 | 1082 | if (!have_ucontext) return; |
| 1083 | 1083 | if (it.getLastError()) |unwind_error| { |
| 1084 | 1084 | printUnwindError(debug_info, writer, unwind_error.address, unwind_error.err, tty_config) catch {}; |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err: UnwindError, tty_config: io.tty.Config) !void { | |
| 1088 | fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err: UnwindError, tty_config: tty.Config) !void { | |
| 1089 | 1089 | const module_name = debug_info.getModuleNameForAddress(address) orelse "???"; |
| 1090 | 1090 | try tty_config.setColor(writer, .dim); |
| 1091 | 1091 | if (err == error.MissingDebugInfo) { |
| ... | ... | @@ -1096,7 +1096,7 @@ fn printUnwindError(debug_info: *SelfInfo, writer: *Writer, address: usize, err: |
| 1096 | 1096 | try tty_config.setColor(writer, .reset); |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | pub fn printSourceAtAddress(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: io.tty.Config) !void { | |
| 1099 | pub fn printSourceAtAddress(debug_info: *SelfInfo, writer: *Writer, address: usize, tty_config: tty.Config) !void { | |
| 1100 | 1100 | const module = debug_info.getModuleForAddress(address) catch |err| switch (err) { |
| 1101 | 1101 | error.MissingDebugInfo, error.InvalidDebugInfo => return printUnknownSource(debug_info, writer, address, tty_config), |
| 1102 | 1102 | else => return err, |
| ... | ... | @@ -1125,7 +1125,7 @@ fn printLineInfo( |
| 1125 | 1125 | address: usize, |
| 1126 | 1126 | symbol_name: []const u8, |
| 1127 | 1127 | compile_unit_name: []const u8, |
| 1128 | tty_config: io.tty.Config, | |
| 1128 | tty_config: tty.Config, | |
| 1129 | 1129 | comptime printLineFromFile: anytype, |
| 1130 | 1130 | ) !void { |
| 1131 | 1131 | nosuspend { |
| ... | ... | @@ -1597,10 +1597,10 @@ test "manage resources correctly" { |
| 1597 | 1597 | // self-hosted debug info is still too buggy |
| 1598 | 1598 | if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; |
| 1599 | 1599 | |
| 1600 | var discarding: std.io.Writer.Discarding = .init(&.{}); | |
| 1600 | var discarding: Writer.Discarding = .init(&.{}); | |
| 1601 | 1601 | var di = try SelfInfo.open(testing.allocator); |
| 1602 | 1602 | defer di.deinit(); |
| 1603 | try printSourceAtAddress(&di, &discarding.writer, showMyTrace(), io.tty.detectConfig(.stderr())); | |
| 1603 | try printSourceAtAddress(&di, &discarding.writer, showMyTrace(), tty.detectConfig(.stderr())); | |
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | noinline fn showMyTrace() usize { |
| ... | ... | @@ -1666,7 +1666,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize |
| 1666 | 1666 | pub fn dump(t: @This()) void { |
| 1667 | 1667 | if (!enabled) return; |
| 1668 | 1668 | |
| 1669 | const tty_config = io.tty.detectConfig(.stderr()); | |
| 1669 | const tty_config = tty.detectConfig(.stderr()); | |
| 1670 | 1670 | const stderr = lockStderrWriter(&.{}); |
| 1671 | 1671 | defer unlockStderrWriter(); |
| 1672 | 1672 | const end = @min(t.index, size); |
lib/std/debug/Dwarf/call_frame.zig+37-44| ... | ... | @@ -51,15 +51,9 @@ const Opcode = enum(u8) { |
| 51 | 51 | pub const hi_user = 0x3f; |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | fn 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; | |
| 54 | fn readBlock(reader: *std.Io.Reader) ![]const u8 { | |
| 55 | const block_len = try reader.takeLeb128(usize); | |
| 56 | return reader.take(block_len); | |
| 63 | 57 | } |
| 64 | 58 | |
| 65 | 59 | pub const Instruction = union(Opcode) { |
| ... | ... | @@ -147,12 +141,11 @@ pub const Instruction = union(Opcode) { |
| 147 | 141 | }, |
| 148 | 142 | |
| 149 | 143 | pub fn read( |
| 150 | stream: *std.io.FixedBufferStream([]const u8), | |
| 144 | reader: *std.Io.Reader, | |
| 151 | 145 | addr_size_bytes: u8, |
| 152 | 146 | endian: std.builtin.Endian, |
| 153 | 147 | ) !Instruction { |
| 154 | const reader = stream.reader(); | |
| 155 | switch (try reader.readByte()) { | |
| 148 | switch (try reader.takeByte()) { | |
| 156 | 149 | Opcode.lo_inline...Opcode.hi_inline => |opcode| { |
| 157 | 150 | const e: Opcode = @enumFromInt(opcode & 0b11000000); |
| 158 | 151 | const value: u6 = @intCast(opcode & 0b111111); |
| ... | ... | @@ -163,7 +156,7 @@ pub const Instruction = union(Opcode) { |
| 163 | 156 | .offset => .{ |
| 164 | 157 | .offset = .{ |
| 165 | 158 | .register = value, |
| 166 | .offset = try leb.readUleb128(u64, reader), | |
| 159 | .offset = try reader.takeLeb128(u64), | |
| 167 | 160 | }, |
| 168 | 161 | }, |
| 169 | 162 | .restore => .{ |
| ... | ... | @@ -183,111 +176,111 @@ pub const Instruction = union(Opcode) { |
| 183 | 176 | .set_loc => .{ |
| 184 | 177 | .set_loc = .{ |
| 185 | 178 | .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), | |
| 189 | 182 | else => return error.InvalidAddrSize, |
| 190 | 183 | }, |
| 191 | 184 | }, |
| 192 | 185 | }, |
| 193 | 186 | .advance_loc1 => .{ |
| 194 | .advance_loc1 = .{ .delta = try reader.readByte() }, | |
| 187 | .advance_loc1 = .{ .delta = try reader.takeByte() }, | |
| 195 | 188 | }, |
| 196 | 189 | .advance_loc2 => .{ |
| 197 | .advance_loc2 = .{ .delta = try reader.readInt(u16, endian) }, | |
| 190 | .advance_loc2 = .{ .delta = try reader.takeInt(u16, endian) }, | |
| 198 | 191 | }, |
| 199 | 192 | .advance_loc4 => .{ |
| 200 | .advance_loc4 = .{ .delta = try reader.readInt(u32, endian) }, | |
| 193 | .advance_loc4 = .{ .delta = try reader.takeInt(u32, endian) }, | |
| 201 | 194 | }, |
| 202 | 195 | .offset_extended => .{ |
| 203 | 196 | .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), | |
| 206 | 199 | }, |
| 207 | 200 | }, |
| 208 | 201 | .restore_extended => .{ |
| 209 | 202 | .restore_extended = .{ |
| 210 | .register = try leb.readUleb128(u8, reader), | |
| 203 | .register = try reader.takeLeb128(u8), | |
| 211 | 204 | }, |
| 212 | 205 | }, |
| 213 | 206 | .undefined => .{ |
| 214 | 207 | .undefined = .{ |
| 215 | .register = try leb.readUleb128(u8, reader), | |
| 208 | .register = try reader.takeLeb128(u8), | |
| 216 | 209 | }, |
| 217 | 210 | }, |
| 218 | 211 | .same_value => .{ |
| 219 | 212 | .same_value = .{ |
| 220 | .register = try leb.readUleb128(u8, reader), | |
| 213 | .register = try reader.takeLeb128(u8), | |
| 221 | 214 | }, |
| 222 | 215 | }, |
| 223 | 216 | .register => .{ |
| 224 | 217 | .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), | |
| 227 | 220 | }, |
| 228 | 221 | }, |
| 229 | 222 | .remember_state => .{ .remember_state = {} }, |
| 230 | 223 | .restore_state => .{ .restore_state = {} }, |
| 231 | 224 | .def_cfa => .{ |
| 232 | 225 | .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), | |
| 235 | 228 | }, |
| 236 | 229 | }, |
| 237 | 230 | .def_cfa_register => .{ |
| 238 | 231 | .def_cfa_register = .{ |
| 239 | .register = try leb.readUleb128(u8, reader), | |
| 232 | .register = try reader.takeLeb128(u8), | |
| 240 | 233 | }, |
| 241 | 234 | }, |
| 242 | 235 | .def_cfa_offset => .{ |
| 243 | 236 | .def_cfa_offset = .{ |
| 244 | .offset = try leb.readUleb128(u64, reader), | |
| 237 | .offset = try reader.takeLeb128(u64), | |
| 245 | 238 | }, |
| 246 | 239 | }, |
| 247 | 240 | .def_cfa_expression => .{ |
| 248 | 241 | .def_cfa_expression = .{ |
| 249 | .block = try readBlock(stream), | |
| 242 | .block = try readBlock(reader), | |
| 250 | 243 | }, |
| 251 | 244 | }, |
| 252 | 245 | .expression => .{ |
| 253 | 246 | .expression = .{ |
| 254 | .register = try leb.readUleb128(u8, reader), | |
| 255 | .block = try readBlock(stream), | |
| 247 | .register = try reader.takeLeb128(u8), | |
| 248 | .block = try readBlock(reader), | |
| 256 | 249 | }, |
| 257 | 250 | }, |
| 258 | 251 | .offset_extended_sf => .{ |
| 259 | 252 | .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), | |
| 262 | 255 | }, |
| 263 | 256 | }, |
| 264 | 257 | .def_cfa_sf => .{ |
| 265 | 258 | .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), | |
| 268 | 261 | }, |
| 269 | 262 | }, |
| 270 | 263 | .def_cfa_offset_sf => .{ |
| 271 | 264 | .def_cfa_offset_sf = .{ |
| 272 | .offset = try leb.readIleb128(i64, reader), | |
| 265 | .offset = try reader.takeLeb128(i64), | |
| 273 | 266 | }, |
| 274 | 267 | }, |
| 275 | 268 | .val_offset => .{ |
| 276 | 269 | .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), | |
| 279 | 272 | }, |
| 280 | 273 | }, |
| 281 | 274 | .val_offset_sf => .{ |
| 282 | 275 | .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), | |
| 285 | 278 | }, |
| 286 | 279 | }, |
| 287 | 280 | .val_expression => .{ |
| 288 | 281 | .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), | |
| 291 | 284 | }, |
| 292 | 285 | }, |
| 293 | 286 | }; |
lib/std/debug/Dwarf/expression.zig+46-53| ... | ... | @@ -62,7 +62,7 @@ pub const Error = error{ |
| 62 | 62 | InvalidTypeLength, |
| 63 | 63 | |
| 64 | 64 | TruncatedIntegralType, |
| 65 | } || abi.RegBytesError || error{ EndOfStream, Overflow, OutOfMemory, DivisionByZero }; | |
| 65 | } || abi.RegBytesError || error{ EndOfStream, Overflow, OutOfMemory, DivisionByZero, ReadFailed }; | |
| 66 | 66 | |
| 67 | 67 | /// A stack machine that can decode and run DWARF expressions. |
| 68 | 68 | /// Expressions can be decoded for non-native address size and endianness, |
| ... | ... | @@ -178,61 +178,60 @@ pub fn StackMachine(comptime options: Options) type { |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 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 { | |
| 183 | 182 | 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)), | |
| 185 | 184 | 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)), | |
| 188 | 187 | }, |
| 189 | 188 | OP.const1u, |
| 190 | 189 | OP.pick, |
| 191 | => generic(try reader.readByte()), | |
| 190 | => generic(try reader.takeByte()), | |
| 192 | 191 | OP.deref_size, |
| 193 | 192 | 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()), | |
| 196 | 195 | OP.const2u, |
| 197 | 196 | 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)), | |
| 201 | 200 | OP.bra, |
| 202 | 201 | 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)), | |
| 208 | 207 | OP.constu, |
| 209 | 208 | OP.plus_uconst, |
| 210 | 209 | OP.addrx, |
| 211 | 210 | OP.constx, |
| 212 | 211 | OP.convert, |
| 213 | 212 | OP.reinterpret, |
| 214 | => generic(try leb.readUleb128(u64, reader)), | |
| 213 | => generic(try reader.takeLeb128(u64)), | |
| 215 | 214 | OP.consts, |
| 216 | 215 | OP.fbreg, |
| 217 | => generic(try leb.readIleb128(i64, reader)), | |
| 216 | => generic(try reader.takeLeb128(i64)), | |
| 218 | 217 | OP.lit0...OP.lit31 => |n| generic(n - OP.lit0), |
| 219 | 218 | OP.reg0...OP.reg31 => |n| .{ .register = n - OP.reg0 }, |
| 220 | 219 | OP.breg0...OP.breg31 => |n| .{ .base_register = .{ |
| 221 | 220 | .base_register = n - OP.breg0, |
| 222 | .offset = try leb.readIleb128(i64, reader), | |
| 221 | .offset = try reader.takeLeb128(i64), | |
| 223 | 222 | } }, |
| 224 | OP.regx => .{ .register = try leb.readUleb128(u8, reader) }, | |
| 223 | OP.regx => .{ .register = try reader.takeLeb128(u8) }, | |
| 225 | 224 | 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); | |
| 228 | 227 | break :blk .{ .base_register = .{ |
| 229 | 228 | .base_register = base_register, |
| 230 | 229 | .offset = offset, |
| 231 | 230 | } }; |
| 232 | 231 | }, |
| 233 | 232 | 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); | |
| 236 | 235 | break :blk .{ .register_type = .{ |
| 237 | 236 | .register = register, |
| 238 | 237 | .type_offset = type_offset, |
| ... | ... | @@ -240,33 +239,27 @@ pub fn StackMachine(comptime options: Options) type { |
| 240 | 239 | }, |
| 241 | 240 | OP.piece => .{ |
| 242 | 241 | .composite_location = .{ |
| 243 | .size = try leb.readUleb128(u8, reader), | |
| 242 | .size = try reader.takeLeb128(u8), | |
| 244 | 243 | .offset = 0, |
| 245 | 244 | }, |
| 246 | 245 | }, |
| 247 | 246 | 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); | |
| 250 | 249 | break :blk .{ .composite_location = .{ |
| 251 | 250 | .size = size, |
| 252 | 251 | .offset = offset, |
| 253 | 252 | } }; |
| 254 | 253 | }, |
| 255 | 254 | 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 }; | |
| 263 | 258 | }, |
| 264 | 259 | 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); | |
| 270 | 263 | break :blk .{ .const_type = .{ |
| 271 | 264 | .type_offset = type_offset, |
| 272 | 265 | .value_bytes = value_bytes, |
| ... | ... | @@ -276,8 +269,8 @@ pub fn StackMachine(comptime options: Options) type { |
| 276 | 269 | OP.xderef_type, |
| 277 | 270 | => .{ |
| 278 | 271 | .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), | |
| 281 | 274 | }, |
| 282 | 275 | }, |
| 283 | 276 | OP.lo_user...OP.hi_user => return error.UnimplementedUserOpcode, |
| ... | ... | @@ -293,7 +286,7 @@ pub fn StackMachine(comptime options: Options) type { |
| 293 | 286 | initial_value: ?usize, |
| 294 | 287 | ) Error!?Value { |
| 295 | 288 | 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); | |
| 297 | 290 | while (try self.step(&stream, allocator, context)) {} |
| 298 | 291 | if (self.stack.items.len == 0) return null; |
| 299 | 292 | return self.stack.items[self.stack.items.len - 1]; |
| ... | ... | @@ -302,14 +295,14 @@ pub fn StackMachine(comptime options: Options) type { |
| 302 | 295 | /// Reads an opcode and its operands from `stream`, then executes it |
| 303 | 296 | pub fn step( |
| 304 | 297 | self: *Self, |
| 305 | stream: *std.io.FixedBufferStream([]const u8), | |
| 298 | stream: *std.Io.Reader, | |
| 306 | 299 | allocator: std.mem.Allocator, |
| 307 | 300 | context: Context, |
| 308 | 301 | ) Error!bool { |
| 309 | 302 | if (@sizeOf(usize) != @sizeOf(addr_type) or options.endian != native_endian) |
| 310 | 303 | @compileError("Execution of non-native address sizes / endianness is not supported"); |
| 311 | 304 | |
| 312 | const opcode = try stream.reader().readByte(); | |
| 305 | const opcode = try stream.takeByte(); | |
| 313 | 306 | if (options.call_frame_context and !isOpcodeValidInCFA(opcode)) return error.InvalidCFAOpcode; |
| 314 | 307 | const operand = try readOperand(stream, opcode, context); |
| 315 | 308 | switch (opcode) { |
| ... | ... | @@ -663,11 +656,11 @@ pub fn StackMachine(comptime options: Options) type { |
| 663 | 656 | if (condition) { |
| 664 | 657 | const new_pos = std.math.cast( |
| 665 | 658 | 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), | |
| 667 | 660 | ) orelse return error.InvalidExpression; |
| 668 | 661 | |
| 669 | 662 | if (new_pos < 0 or new_pos > stream.buffer.len) return error.InvalidExpression; |
| 670 | stream.pos = new_pos; | |
| 663 | stream.seek = new_pos; | |
| 671 | 664 | } |
| 672 | 665 | }, |
| 673 | 666 | OP.call2, |
| ... | ... | @@ -746,7 +739,7 @@ pub fn StackMachine(comptime options: Options) type { |
| 746 | 739 | if (isOpcodeRegisterLocation(block[0])) { |
| 747 | 740 | if (context.thread_context == null) return error.IncompleteExpressionContext; |
| 748 | 741 | |
| 749 | var block_stream = std.io.fixedBufferStream(block); | |
| 742 | var block_stream: std.Io.Reader = .fixed(block); | |
| 750 | 743 | const register = (try readOperand(&block_stream, block[0], context)).?.register; |
| 751 | 744 | const value = mem.readInt(usize, (try abi.regBytes(context.thread_context.?, register, context.reg_context))[0..@sizeOf(usize)], native_endian); |
| 752 | 745 | try self.stack.append(allocator, .{ .generic = value }); |
| ... | ... | @@ -769,7 +762,7 @@ pub fn StackMachine(comptime options: Options) type { |
| 769 | 762 | }, |
| 770 | 763 | } |
| 771 | 764 | |
| 772 | return stream.pos < stream.buffer.len; | |
| 765 | return stream.seek < stream.buffer.len; | |
| 773 | 766 | } |
| 774 | 767 | }; |
| 775 | 768 | } |
| ... | ... | @@ -858,7 +851,7 @@ pub fn Builder(comptime options: Options) type { |
| 858 | 851 | }, |
| 859 | 852 | .signed => { |
| 860 | 853 | try writer.writeByte(OP.consts); |
| 861 | try leb.writeIleb128(writer, value); | |
| 854 | try writer.writeLeb128(value); | |
| 862 | 855 | }, |
| 863 | 856 | }, |
| 864 | 857 | } |
| ... | ... | @@ -892,19 +885,19 @@ pub fn Builder(comptime options: Options) type { |
| 892 | 885 | // 2.5.1.2: Register Values |
| 893 | 886 | pub fn writeFbreg(writer: *Writer, offset: anytype) !void { |
| 894 | 887 | try writer.writeByte(OP.fbreg); |
| 895 | try leb.writeIleb128(writer, offset); | |
| 888 | try writer.writeSleb128(offset); | |
| 896 | 889 | } |
| 897 | 890 | |
| 898 | 891 | pub fn writeBreg(writer: *Writer, register: u8, offset: anytype) !void { |
| 899 | 892 | if (register > 31) return error.InvalidRegister; |
| 900 | 893 | try writer.writeByte(OP.breg0 + register); |
| 901 | try leb.writeIleb128(writer, offset); | |
| 894 | try writer.writeSleb128(offset); | |
| 902 | 895 | } |
| 903 | 896 | |
| 904 | 897 | pub fn writeBregx(writer: *Writer, register: anytype, offset: anytype) !void { |
| 905 | 898 | try writer.writeByte(OP.bregx); |
| 906 | 899 | try writer.writeUleb128(register); |
| 907 | try leb.writeIleb128(writer, offset); | |
| 900 | try writer.writeSleb128(offset); | |
| 908 | 901 | } |
| 909 | 902 | |
| 910 | 903 | pub fn writeRegvalType(writer: *Writer, register: anytype, offset: anytype) !void { |
lib/std/debug/SelfInfo.zig+4-7| ... | ... | @@ -2017,15 +2017,12 @@ pub const VirtualMachine = struct { |
| 2017 | 2017 | |
| 2018 | 2018 | var prev_row: Row = self.current_row; |
| 2019 | 2019 | |
| 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 }; | |
| 2026 | 2023 | |
| 2027 | 2024 | for (&streams, 0..) |stream, i| { |
| 2028 | while (stream.pos < stream.buffer.len) { | |
| 2025 | while (stream.seek < stream.buffer.len) { | |
| 2029 | 2026 | const instruction = try std.debug.Dwarf.call_frame.Instruction.read(stream, addr_size_bytes, endian); |
| 2030 | 2027 | prev_row = try self.step(allocator, cie, i == 0, instruction); |
| 2031 | 2028 | 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 { |
| 609 | 609 | } |
| 610 | 610 | }; |
| 611 | 611 | |
| 612 | fn takePhdr(reader: *std.io.Reader, elf_header: Header) !?Elf64_Phdr { | |
| 612 | fn takePhdr(reader: *std.Io.Reader, elf_header: Header) !?Elf64_Phdr { | |
| 613 | 613 | if (elf_header.is_64) { |
| 614 | 614 | const phdr = try reader.takeStruct(Elf64_Phdr, elf_header.endian); |
| 615 | 615 | return phdr; |
lib/std/fmt.zig+1-2| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | |
| 5 | 5 | const std = @import("std.zig"); |
| 6 | const io = std.io; | |
| 7 | 6 | const math = std.math; |
| 8 | 7 | const assert = std.debug.assert; |
| 9 | 8 | const mem = std.mem; |
| ... | ... | @@ -12,7 +11,7 @@ const lossyCast = math.lossyCast; |
| 12 | 11 | const expectFmt = std.testing.expectFmt; |
| 13 | 12 | const testing = std.testing; |
| 14 | 13 | const Allocator = std.mem.Allocator; |
| 15 | const Writer = std.io.Writer; | |
| 14 | const Writer = std.Io.Writer; | |
| 16 | 15 | |
| 17 | 16 | pub const float = @import("fmt/float.zig"); |
| 18 | 17 |
lib/std/fs/Dir.zig+48-30| ... | ... | @@ -1977,41 +1977,59 @@ pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8 { |
| 1977 | 1977 | return buffer[0..end_index]; |
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | /// On success, caller owns returned buffer. | |
| 1981 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. | |
| 1982 | /// On Windows, `file_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 1983 | /// On WASI, `file_path` should be encoded as valid UTF-8. | |
| 1984 | /// On other platforms, `file_path` is an opaque sequence of bytes with no particular encoding. | |
| 1985 | pub fn readFileAlloc(self: Dir, allocator: mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 { | |
| 1986 | return self.readFileAllocOptions(allocator, file_path, max_bytes, null, .of(u8), null); | |
| 1980 | pub const ReadFileAllocError = File.OpenError || File.ReadError || Allocator.Error || error{ | |
| 1981 | /// File size reached or exceeded the provided limit. | |
| 1982 | StreamTooLong, | |
| 1983 | }; | |
| 1984 | ||
| 1985 | /// Reads all the bytes from the named file. On success, caller owns returned | |
| 1986 | /// buffer. | |
| 1987 | /// | |
| 1988 | /// If the file size is already known, a better alternative is to initialize a | |
| 1989 | /// `File.Reader`. | |
| 1990 | /// | |
| 1991 | /// If the file size cannot be obtained, an error is returned. If | |
| 1992 | /// this is a realistic possibility, a better alternative is to initialize a | |
| 1993 | /// `File.Reader` which handles this seamlessly. | |
| 1994 | pub fn readFileAlloc( | |
| 1995 | dir: Dir, | |
| 1996 | /// On Windows, should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 1997 | /// On WASI, should be encoded as valid UTF-8. | |
| 1998 | /// On other platforms, an opaque sequence of bytes with no particular encoding. | |
| 1999 | sub_path: []const u8, | |
| 2000 | /// Used to allocate the result. | |
| 2001 | gpa: Allocator, | |
| 2002 | /// If reached or exceeded, `error.StreamTooLong` is returned instead. | |
| 2003 | limit: std.Io.Limit, | |
| 2004 | ) ReadFileAllocError![]u8 { | |
| 2005 | return readFileAllocOptions(dir, sub_path, gpa, limit, .of(u8), null); | |
| 1987 | 2006 | } |
| 1988 | 2007 | |
| 1989 | /// On success, caller owns returned buffer. | |
| 1990 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. | |
| 1991 | /// If `size_hint` is specified the initial buffer size is calculated using | |
| 1992 | /// that value, otherwise the effective file size is used instead. | |
| 1993 | /// Allows specifying alignment and a sentinel value. | |
| 1994 | /// On Windows, `file_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 1995 | /// On WASI, `file_path` should be encoded as valid UTF-8. | |
| 1996 | /// On other platforms, `file_path` is an opaque sequence of bytes with no particular encoding. | |
| 2008 | /// Reads all the bytes from the named file. On success, caller owns returned | |
| 2009 | /// buffer. | |
| 2010 | /// | |
| 2011 | /// If the file size is already known, a better alternative is to initialize a | |
| 2012 | /// `File.Reader`. | |
| 1997 | 2013 | pub fn readFileAllocOptions( |
| 1998 | self: Dir, | |
| 1999 | allocator: mem.Allocator, | |
| 2000 | file_path: []const u8, | |
| 2001 | max_bytes: usize, | |
| 2002 | size_hint: ?usize, | |
| 2014 | dir: Dir, | |
| 2015 | /// On Windows, should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/). | |
| 2016 | /// On WASI, should be encoded as valid UTF-8. | |
| 2017 | /// On other platforms, an opaque sequence of bytes with no particular encoding. | |
| 2018 | sub_path: []const u8, | |
| 2019 | /// Used to allocate the result. | |
| 2020 | gpa: Allocator, | |
| 2021 | /// If reached or exceeded, `error.StreamTooLong` is returned instead. | |
| 2022 | limit: std.Io.Limit, | |
| 2003 | 2023 | comptime alignment: std.mem.Alignment, |
| 2004 | comptime optional_sentinel: ?u8, | |
| 2005 | ) !(if (optional_sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) { | |
| 2006 | var file = try self.openFile(file_path, .{}); | |
| 2024 | comptime sentinel: ?u8, | |
| 2025 | ) ReadFileAllocError!(if (sentinel) |s| [:s]align(alignment.toByteUnits()) u8 else []align(alignment.toByteUnits()) u8) { | |
| 2026 | var file = try dir.openFile(sub_path, .{}); | |
| 2007 | 2027 | defer file.close(); |
| 2008 | ||
| 2009 | // If the file size doesn't fit a usize it'll be certainly greater than | |
| 2010 | // `max_bytes` | |
| 2011 | const stat_size = size_hint orelse std.math.cast(usize, try file.getEndPos()) orelse | |
| 2012 | return error.FileTooBig; | |
| 2013 | ||
| 2014 | return file.readToEndAllocOptions(allocator, max_bytes, stat_size, alignment, optional_sentinel); | |
| 2028 | var file_reader = file.reader(&.{}); | |
| 2029 | return file_reader.interface.allocRemainingAlignedSentinel(gpa, limit, alignment, sentinel) catch |err| switch (err) { | |
| 2030 | error.ReadFailed => return file_reader.err.?, | |
| 2031 | error.OutOfMemory, error.StreamTooLong => |e| return e, | |
| 2032 | }; | |
| 2015 | 2033 | } |
| 2016 | 2034 | |
| 2017 | 2035 | pub const DeleteTreeError = error{ |
lib/std/fs/File.zig-45| ... | ... | @@ -7,7 +7,6 @@ const File = @This(); |
| 7 | 7 | const std = @import("../std.zig"); |
| 8 | 8 | const Allocator = std.mem.Allocator; |
| 9 | 9 | const posix = std.posix; |
| 10 | const io = std.io; | |
| 11 | 10 | const math = std.math; |
| 12 | 11 | const assert = std.debug.assert; |
| 13 | 12 | const linux = std.os.linux; |
| ... | ... | @@ -805,42 +804,6 @@ pub fn updateTimes( |
| 805 | 804 | try posix.futimens(self.handle, &times); |
| 806 | 805 | } |
| 807 | 806 | |
| 808 | /// Deprecated in favor of `Reader`. | |
| 809 | pub 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`. | |
| 814 | pub 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 | ||
| 844 | 807 | pub const ReadError = posix.ReadError; |
| 845 | 808 | pub const PReadError = posix.PReadError; |
| 846 | 809 | |
| ... | ... | @@ -1089,14 +1052,6 @@ pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u |
| 1089 | 1052 | return total_bytes_copied; |
| 1090 | 1053 | } |
| 1091 | 1054 | |
| 1092 | /// Deprecated in favor of `Reader`. | |
| 1093 | pub const DeprecatedReader = io.GenericReader(File, ReadError, read); | |
| 1094 | ||
| 1095 | /// Deprecated in favor of `Reader`. | |
| 1096 | pub fn deprecatedReader(file: File) DeprecatedReader { | |
| 1097 | return .{ .context = file }; | |
| 1098 | } | |
| 1099 | ||
| 1100 | 1055 | /// Memoizes key information about a file handle such as: |
| 1101 | 1056 | /// * The size from calling stat, or the error that occurred therein. |
| 1102 | 1057 | /// * 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, |
| 150 | 150 | return .{ .data = paths }; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | fn formatJoin(paths: []const []const u8, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 153 | fn formatJoin(paths: []const []const u8, w: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 154 | 154 | const first_path_idx = for (paths, 0..) |p, idx| { |
| 155 | 155 | if (p.len != 0) break idx; |
| 156 | 156 | } else return; |
lib/std/fs/test.zig+35-25| ... | ... | @@ -676,37 +676,47 @@ test "Dir.realpath smoke test" { |
| 676 | 676 | }.impl); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | test "readAllAlloc" { | |
| 679 | test "readFileAlloc" { | |
| 680 | 680 | var tmp_dir = tmpDir(.{}); |
| 681 | 681 | defer tmp_dir.cleanup(); |
| 682 | 682 | |
| 683 | 683 | var file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); |
| 684 | 684 | defer file.close(); |
| 685 | 685 | |
| 686 | const buf1 = try file.readToEndAlloc(testing.allocator, 1024); | |
| 686 | const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024)); | |
| 687 | 687 | defer testing.allocator.free(buf1); |
| 688 | try testing.expectEqual(@as(usize, 0), buf1.len); | |
| 688 | try testing.expectEqualStrings("", buf1); | |
| 689 | 689 | |
| 690 | 690 | const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n"; |
| 691 | 691 | try file.writeAll(write_buf); |
| 692 | try file.seekTo(0); | |
| 693 | ||
| 694 | // max_bytes > file_size | |
| 695 | const buf2 = try file.readToEndAlloc(testing.allocator, 1024); | |
| 696 | defer testing.allocator.free(buf2); | |
| 697 | try testing.expectEqual(write_buf.len, buf2.len); | |
| 698 | try testing.expectEqualStrings(write_buf, buf2); | |
| 699 | try file.seekTo(0); | |
| 700 | ||
| 701 | // max_bytes == file_size | |
| 702 | const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len); | |
| 703 | defer testing.allocator.free(buf3); | |
| 704 | try testing.expectEqual(write_buf.len, buf3.len); | |
| 705 | try testing.expectEqualStrings(write_buf, buf3); | |
| 706 | try file.seekTo(0); | |
| 692 | ||
| 693 | { | |
| 694 | // max_bytes > file_size | |
| 695 | const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024)); | |
| 696 | defer testing.allocator.free(buf2); | |
| 697 | try testing.expectEqualStrings(write_buf, buf2); | |
| 698 | } | |
| 699 | ||
| 700 | { | |
| 701 | // max_bytes == file_size | |
| 702 | try testing.expectError( | |
| 703 | error.StreamTooLong, | |
| 704 | tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len)), | |
| 705 | ); | |
| 706 | } | |
| 707 | ||
| 708 | { | |
| 709 | // max_bytes == file_size + 1 | |
| 710 | const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len + 1)); | |
| 711 | defer testing.allocator.free(buf2); | |
| 712 | try testing.expectEqualStrings(write_buf, buf2); | |
| 713 | } | |
| 707 | 714 | |
| 708 | 715 | // max_bytes < file_size |
| 709 | try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1)); | |
| 716 | try testing.expectError( | |
| 717 | error.StreamTooLong, | |
| 718 | tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len - 1)), | |
| 719 | ); | |
| 710 | 720 | } |
| 711 | 721 | |
| 712 | 722 | test "Dir.statFile" { |
| ... | ... | @@ -778,16 +788,16 @@ test "file operations on directories" { |
| 778 | 788 | switch (native_os) { |
| 779 | 789 | .dragonfly, .netbsd => { |
| 780 | 790 | // no error when reading a directory. See https://github.com/ziglang/zig/issues/5732 |
| 781 | const buf = try ctx.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize)); | |
| 791 | const buf = try ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited); | |
| 782 | 792 | testing.allocator.free(buf); |
| 783 | 793 | }, |
| 784 | 794 | .wasi => { |
| 785 | 795 | // WASI return EBADF, which gets mapped to NotOpenForReading. |
| 786 | 796 | // See https://github.com/bytecodealliance/wasmtime/issues/1935 |
| 787 | try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize))); | |
| 797 | try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited)); | |
| 788 | 798 | }, |
| 789 | 799 | else => { |
| 790 | try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(testing.allocator, test_dir_name, std.math.maxInt(usize))); | |
| 800 | try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited)); | |
| 791 | 801 | }, |
| 792 | 802 | } |
| 793 | 803 | |
| ... | ... | @@ -1564,7 +1574,7 @@ test "copyFile" { |
| 1564 | 1574 | } |
| 1565 | 1575 | |
| 1566 | 1576 | fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { |
| 1567 | const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000); | |
| 1577 | const contents = try dir.readFileAlloc(file_path, testing.allocator, .limited(1000)); | |
| 1568 | 1578 | defer testing.allocator.free(contents); |
| 1569 | 1579 | |
| 1570 | 1580 | try testing.expectEqualSlices(u8, data, contents); |
| ... | ... | @@ -1587,7 +1597,7 @@ test "AtomicFile" { |
| 1587 | 1597 | try af.file_writer.interface.writeAll(test_content); |
| 1588 | 1598 | try af.finish(); |
| 1589 | 1599 | } |
| 1590 | const content = try ctx.dir.readFileAlloc(allocator, test_out_file, 9999); | |
| 1600 | const content = try ctx.dir.readFileAlloc(test_out_file, allocator, .limited(9999)); | |
| 1591 | 1601 | try testing.expectEqualStrings(test_content, content); |
| 1592 | 1602 | |
| 1593 | 1603 | try ctx.dir.deleteFile(test_out_file); |
| ... | ... | @@ -2004,7 +2014,7 @@ test "invalid UTF-8/WTF-8 paths" { |
| 2004 | 2014 | } |
| 2005 | 2015 | |
| 2006 | 2016 | try testing.expectError(expected_err, ctx.dir.readFile(invalid_path, &[_]u8{})); |
| 2007 | try testing.expectError(expected_err, ctx.dir.readFileAlloc(testing.allocator, invalid_path, 0)); | |
| 2017 | try testing.expectError(expected_err, ctx.dir.readFileAlloc(invalid_path, testing.allocator, .limited(0))); | |
| 2008 | 2018 | |
| 2009 | 2019 | try testing.expectError(expected_err, ctx.dir.deleteTree(invalid_path)); |
| 2010 | 2020 | try testing.expectError(expected_err, ctx.dir.deleteTreeMinStackSize(invalid_path)); |
lib/std/json.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | //! JSON parsing and stringification conforming to RFC 8259. https://datatracker.ietf.org/doc/html/rfc8259 |
| 2 | 2 | //! |
| 3 | 3 | //! 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`. | |
| 5 | 5 | //! |
| 6 | 6 | //! The high-level `parseFromSlice` and `parseFromTokenSource` deserialize a JSON document into a Zig type. |
| 7 | 7 | //! Parse into a dynamically-typed `Value` to load any JSON value for runtime inspection. |
| ... | ... | @@ -42,7 +42,7 @@ test Value { |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | test Stringify { |
| 45 | var out: std.io.Writer.Allocating = .init(testing.allocator); | |
| 45 | var out: std.Io.Writer.Allocating = .init(testing.allocator); | |
| 46 | 46 | var write_stream: Stringify = .{ |
| 47 | 47 | .writer = &out.writer, |
| 48 | 48 | .options = .{ .whitespace = .indent_2 }, |
lib/std/json/Stringify.zig+3-3| ... | ... | @@ -23,7 +23,7 @@ const Allocator = std.mem.Allocator; |
| 23 | 23 | const ArrayList = std.ArrayList; |
| 24 | 24 | const BitStack = std.BitStack; |
| 25 | 25 | const Stringify = @This(); |
| 26 | const Writer = std.io.Writer; | |
| 26 | const Writer = std.Io.Writer; | |
| 27 | 27 | |
| 28 | 28 | const IndentationMode = enum(u1) { |
| 29 | 29 | object = 0, |
| ... | ... | @@ -576,7 +576,7 @@ pub fn value(v: anytype, options: Options, writer: *Writer) Error!void { |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | test value { |
| 579 | var out: std.io.Writer.Allocating = .init(std.testing.allocator); | |
| 579 | var out: Writer.Allocating = .init(std.testing.allocator); | |
| 580 | 580 | const writer = &out.writer; |
| 581 | 581 | defer out.deinit(); |
| 582 | 582 | |
| ... | ... | @@ -616,7 +616,7 @@ test value { |
| 616 | 616 | /// |
| 617 | 617 | /// Caller owns returned memory. |
| 618 | 618 | pub 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); | |
| 620 | 620 | defer aw.deinit(); |
| 621 | 621 | value(v, options, &aw.writer) catch return error.OutOfMemory; |
| 622 | 622 | return aw.toOwnedSlice(); |
lib/std/json/dynamic_test.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const mem = std.mem; |
| 4 | 4 | const testing = std.testing; |
| 5 | 5 | const ArenaAllocator = std.heap.ArenaAllocator; |
| 6 | 6 | const Allocator = std.mem.Allocator; |
| 7 | const Writer = std.io.Writer; | |
| 7 | const Writer = std.Io.Writer; | |
| 8 | 8 | |
| 9 | 9 | const ObjectMap = @import("dynamic.zig").ObjectMap; |
| 10 | 10 | const Array = @import("dynamic.zig").Array; |
lib/std/leb128.zig+22-251| ... | ... | @@ -2,120 +2,6 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const testing = std.testing; |
| 4 | 4 | |
| 5 | /// Read a single unsigned LEB128 value from the given reader as type T, | |
| 6 | /// or error.Overflow if the value cannot fit. | |
| 7 | pub 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. | |
| 38 | pub 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. | |
| 95 | pub 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 | ||
| 119 | 5 | /// This is an "advanced" function. It allows one to use a fixed amount of memory to store a |
| 120 | 6 | /// ULEB128. This defeats the entire purpose of using this data encoding; it will no longer use |
| 121 | 7 | /// fewer bytes to store smaller numbers. The advantage of using a fixed width is that it makes |
| ... | ... | @@ -149,22 +35,26 @@ test writeUnsignedFixed { |
| 149 | 35 | { |
| 150 | 36 | var buf: [4]u8 = undefined; |
| 151 | 37 | 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)); | |
| 153 | 40 | } |
| 154 | 41 | { |
| 155 | 42 | var buf: [4]u8 = undefined; |
| 156 | 43 | 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)); | |
| 158 | 46 | } |
| 159 | 47 | { |
| 160 | 48 | var buf: [4]u8 = undefined; |
| 161 | 49 | 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)); | |
| 163 | 52 | } |
| 164 | 53 | { |
| 165 | 54 | var buf: [4]u8 = undefined; |
| 166 | 55 | 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)); | |
| 168 | 58 | } |
| 169 | 59 | } |
| 170 | 60 | |
| ... | ... | @@ -193,162 +83,43 @@ test writeSignedFixed { |
| 193 | 83 | { |
| 194 | 84 | var buf: [4]u8 = undefined; |
| 195 | 85 | 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)); | |
| 197 | 88 | } |
| 198 | 89 | { |
| 199 | 90 | var buf: [4]u8 = undefined; |
| 200 | 91 | 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)); | |
| 202 | 94 | } |
| 203 | 95 | { |
| 204 | 96 | var buf: [4]u8 = undefined; |
| 205 | 97 | 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)); | |
| 207 | 100 | } |
| 208 | 101 | { |
| 209 | 102 | var buf: [4]u8 = undefined; |
| 210 | 103 | 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)); | |
| 212 | 106 | } |
| 213 | 107 | { |
| 214 | 108 | var buf: [4]u8 = undefined; |
| 215 | 109 | 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)); | |
| 217 | 112 | } |
| 218 | 113 | { |
| 219 | 114 | var buf: [4]u8 = undefined; |
| 220 | 115 | 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)); | |
| 222 | 118 | } |
| 223 | 119 | { |
| 224 | 120 | var buf: [4]u8 = undefined; |
| 225 | 121 | 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)); | |
| 227 | 124 | } |
| 228 | 125 | } |
| 229 | ||
| 230 | // tests | |
| 231 | fn 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 | ||
| 236 | fn 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 | ||
| 241 | fn 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 | ||
| 247 | fn 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 | ||
| 253 | fn 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 | ||
| 261 | fn 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 | ||
| 269 | test "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 | ||
| 316 | test "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 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const io = std.io; | |
| 5 | 4 | const mem = std.mem; |
| 6 | 5 | const meta = std.meta; |
| 7 | 6 | const testing = std.testing; |
lib/std/math/big/int.zig+5-5| ... | ... | @@ -2029,11 +2029,11 @@ pub const Mutable = struct { |
| 2029 | 2029 | r.len = llnormalize(r.limbs[0..length]); |
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 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 { | |
| 2033 | 2033 | return formatNumber(self, w, .{}); |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 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 { | |
| 2037 | 2037 | return self.toConst().formatNumber(w, n); |
| 2038 | 2038 | } |
| 2039 | 2039 | }; |
| ... | ... | @@ -2326,7 +2326,7 @@ pub const Const = struct { |
| 2326 | 2326 | /// this function will fail to print the string, printing "(BigInt)" instead of a number. |
| 2327 | 2327 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. |
| 2328 | 2328 | /// 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 { | |
| 2330 | 2330 | const available_len = 64; |
| 2331 | 2331 | if (self.limbs.len > available_len) |
| 2332 | 2332 | return w.writeAll("(BigInt)"); |
| ... | ... | @@ -2907,7 +2907,7 @@ pub const Managed = struct { |
| 2907 | 2907 | } |
| 2908 | 2908 | |
| 2909 | 2909 | /// 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 { | |
| 2911 | 2911 | return formatNumber(self, w, .{}); |
| 2912 | 2912 | } |
| 2913 | 2913 | |
| ... | ... | @@ -2915,7 +2915,7 @@ pub const Managed = struct { |
| 2915 | 2915 | /// this function will fail to print the string, printing "(BigInt)" instead of a number. |
| 2916 | 2916 | /// This is because the rendering algorithm requires reversing a string, which requires O(N) memory. |
| 2917 | 2917 | /// 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 { | |
| 2919 | 2919 | return self.toConst().formatNumber(w, n); |
| 2920 | 2920 | } |
| 2921 | 2921 |
lib/std/os/uefi.zig+1-1| ... | ... | @@ -106,7 +106,7 @@ pub const Guid = extern struct { |
| 106 | 106 | node: [6]u8, |
| 107 | 107 | |
| 108 | 108 | /// 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 { | |
| 110 | 110 | const time_low = @byteSwap(self.time_low); |
| 111 | 111 | const time_mid = @byteSwap(self.time_mid); |
| 112 | 112 | const time_high_and_version = @byteSwap(self.time_high_and_version); |
lib/std/os/uefi/protocol/file.zig-1| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const uefi = std.os.uefi; |
| 3 | const io = std.io; | |
| 4 | 3 | const Guid = uefi.Guid; |
| 5 | 4 | const Time = uefi.Time; |
| 6 | 5 | const Status = uefi.Status; |
lib/std/os/uefi/tables.zig+1-1| ... | ... | @@ -90,7 +90,7 @@ pub const MemoryType = enum(u32) { |
| 90 | 90 | return @truncate(as_int - vendor_start); |
| 91 | 91 | } |
| 92 | 92 | |
| 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 { | |
| 94 | 94 | if (self.toOem()) |oemval| |
| 95 | 95 | try w.print("OEM({X})", .{oemval}) |
| 96 | 96 | else if (self.toVendor()) |vendorval| |
lib/std/pdb.zig-1| ... | ... | @@ -8,7 +8,6 @@ |
| 8 | 8 | //! documentation and/or contributors. |
| 9 | 9 | |
| 10 | 10 | const std = @import("std.zig"); |
| 11 | const io = std.io; | |
| 12 | 11 | const math = std.math; |
| 13 | 12 | const mem = std.mem; |
| 14 | 13 | const coff = std.coff; |
lib/std/posix.zig+2-2| ... | ... | @@ -671,8 +671,8 @@ fn getRandomBytesDevURandom(buf: []u8) !void { |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | 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; | |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /// Causes abnormal process termination. |
lib/std/posix/test.zig+4-7| ... | ... | @@ -4,7 +4,6 @@ const testing = std.testing; |
| 4 | 4 | const expect = testing.expect; |
| 5 | 5 | const expectEqual = testing.expectEqual; |
| 6 | 6 | const expectError = testing.expectError; |
| 7 | const io = std.io; | |
| 8 | 7 | const fs = std.fs; |
| 9 | 8 | const mem = std.mem; |
| 10 | 9 | const elf = std.elf; |
| ... | ... | @@ -706,12 +705,11 @@ test "mmap" { |
| 706 | 705 | ); |
| 707 | 706 | defer posix.munmap(data); |
| 708 | 707 | |
| 709 | var mem_stream = io.fixedBufferStream(data); | |
| 710 | const stream = mem_stream.reader(); | |
| 708 | var stream: std.Io.Reader = .fixed(data); | |
| 711 | 709 | |
| 712 | 710 | var i: usize = 0; |
| 713 | 711 | 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)); | |
| 715 | 713 | } |
| 716 | 714 | } |
| 717 | 715 | |
| ... | ... | @@ -730,12 +728,11 @@ test "mmap" { |
| 730 | 728 | ); |
| 731 | 729 | defer posix.munmap(data); |
| 732 | 730 | |
| 733 | var mem_stream = io.fixedBufferStream(data); | |
| 734 | const stream = mem_stream.reader(); | |
| 731 | var stream: std.Io.Reader = .fixed(data); | |
| 735 | 732 | |
| 736 | 733 | var i: usize = alloc_size / 2 / @sizeOf(u32); |
| 737 | 734 | 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)); | |
| 739 | 736 | } |
| 740 | 737 | } |
| 741 | 738 | } |
lib/std/process.zig+93-88| ... | ... | @@ -1552,103 +1552,108 @@ pub fn getUserInfo(name: []const u8) !UserInfo { |
| 1552 | 1552 | pub fn posixGetUserInfo(name: []const u8) !UserInfo { |
| 1553 | 1553 | const file = try std.fs.openFileAbsolute("/etc/passwd", .{}); |
| 1554 | 1554 | 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 | } | |
| 1555 | 1563 | |
| 1556 | const reader = file.deprecatedReader(); | |
| 1557 | ||
| 1564 | fn posixGetUserInfoPasswdStream(name: []const u8, reader: *std.Io.Reader) !UserInfo { | |
| 1558 | 1565 | 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, | |
| 1564 | 1571 | }; |
| 1565 | 1572 | |
| 1566 | var buf: [std.heap.page_size_min]u8 = undefined; | |
| 1567 | 1573 | var name_index: usize = 0; |
| 1568 | var state = State.Start; | |
| 1569 | 1574 | var uid: posix.uid_t = 0; |
| 1570 | 1575 | var gid: posix.gid_t = 0; |
| 1571 | 1576 | |
| 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 | }, | |
| 1651 | 1655 | } |
| 1656 | comptime unreachable; | |
| 1652 | 1657 | } |
| 1653 | 1658 | |
| 1654 | 1659 | pub fn getBaseAddress() usize { |
lib/std/std.zig-2| ... | ... | @@ -78,8 +78,6 @@ pub const hash = @import("hash.zig"); |
| 78 | 78 | pub const hash_map = @import("hash_map.zig"); |
| 79 | 79 | pub const heap = @import("heap.zig"); |
| 80 | 80 | pub const http = @import("http.zig"); |
| 81 | /// Deprecated | |
| 82 | pub const io = Io; | |
| 83 | 81 | pub const json = @import("json.zig"); |
| 84 | 82 | pub const leb = @import("leb128.zig"); |
| 85 | 83 | pub const log = @import("log.zig"); |
lib/std/tar/test.zig+5-5| ... | ... | @@ -336,7 +336,7 @@ fn testCase(case: Case) !void { |
| 336 | 336 | var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined; |
| 337 | 337 | var link_name_buffer: [std.fs.max_path_bytes]u8 = undefined; |
| 338 | 338 | |
| 339 | var br: std.io.Reader = .fixed(case.data); | |
| 339 | var br: std.Io.Reader = .fixed(case.data); | |
| 340 | 340 | var it: tar.Iterator = .init(&br, .{ |
| 341 | 341 | .file_name_buffer = &file_name_buffer, |
| 342 | 342 | .link_name_buffer = &link_name_buffer, |
| ... | ... | @@ -387,7 +387,7 @@ fn testLongNameCase(case: Case) !void { |
| 387 | 387 | var min_file_name_buffer: [256]u8 = undefined; |
| 388 | 388 | var min_link_name_buffer: [100]u8 = undefined; |
| 389 | 389 | |
| 390 | var br: std.io.Reader = .fixed(case.data); | |
| 390 | var br: std.Io.Reader = .fixed(case.data); | |
| 391 | 391 | var iter: tar.Iterator = .init(&br, .{ |
| 392 | 392 | .file_name_buffer = &min_file_name_buffer, |
| 393 | 393 | .link_name_buffer = &min_link_name_buffer, |
| ... | ... | @@ -407,7 +407,7 @@ test "insufficient buffer in Header name filed" { |
| 407 | 407 | var min_file_name_buffer: [9]u8 = undefined; |
| 408 | 408 | var min_link_name_buffer: [100]u8 = undefined; |
| 409 | 409 | |
| 410 | var br: std.io.Reader = .fixed(gnu_case.data); | |
| 410 | var br: std.Io.Reader = .fixed(gnu_case.data); | |
| 411 | 411 | var iter: tar.Iterator = .init(&br, .{ |
| 412 | 412 | .file_name_buffer = &min_file_name_buffer, |
| 413 | 413 | .link_name_buffer = &min_link_name_buffer, |
| ... | ... | @@ -462,7 +462,7 @@ test "should not overwrite existing file" { |
| 462 | 462 | // This ensures that file is not overwritten. |
| 463 | 463 | // |
| 464 | 464 | const data = @embedFile("testdata/overwrite_file.tar"); |
| 465 | var r: std.io.Reader = .fixed(data); | |
| 465 | var r: std.Io.Reader = .fixed(data); | |
| 466 | 466 | |
| 467 | 467 | // Unpack with strip_components = 1 should fail |
| 468 | 468 | var root = std.testing.tmpDir(.{}); |
| ... | ... | @@ -490,7 +490,7 @@ test "case sensitivity" { |
| 490 | 490 | // 18089/alacritty/Darkermatrix.yml |
| 491 | 491 | // |
| 492 | 492 | const data = @embedFile("testdata/18089.tar"); |
| 493 | var r: std.io.Reader = .fixed(data); | |
| 493 | var r: std.Io.Reader = .fixed(data); | |
| 494 | 494 | |
| 495 | 495 | var root = std.testing.tmpDir(.{}); |
| 496 | 496 | defer root.cleanup(); |
lib/std/testing.zig+8-8| ... | ... | @@ -358,7 +358,7 @@ test expectApproxEqRel { |
| 358 | 358 | /// This function is intended to be used only in tests. When the two slices are not |
| 359 | 359 | /// equal, prints diagnostics to stderr to show exactly how they are not equal (with |
| 360 | 360 | /// 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()`. | |
| 362 | 362 | /// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead. |
| 363 | 363 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { |
| 364 | 364 | const diff_index: usize = diff_index: { |
| ... | ... | @@ -381,7 +381,7 @@ fn failEqualSlices( |
| 381 | 381 | expected: []const T, |
| 382 | 382 | actual: []const T, |
| 383 | 383 | diff_index: usize, |
| 384 | w: *std.io.Writer, | |
| 384 | w: *std.Io.Writer, | |
| 385 | 385 | ) !void { |
| 386 | 386 | try w.print("slices differ. first difference occurs at index {d} (0x{X})\n", .{ diff_index, diff_index }); |
| 387 | 387 | |
| ... | ... | @@ -401,7 +401,7 @@ fn failEqualSlices( |
| 401 | 401 | const actual_window = actual[window_start..@min(actual.len, window_start + max_window_size)]; |
| 402 | 402 | const actual_truncated = window_start + actual_window.len < actual.len; |
| 403 | 403 | |
| 404 | const ttyconf = std.io.tty.detectConfig(.stderr()); | |
| 404 | const ttyconf = std.Io.tty.detectConfig(.stderr()); | |
| 405 | 405 | var differ = if (T == u8) BytesDiffer{ |
| 406 | 406 | .expected = expected_window, |
| 407 | 407 | .actual = actual_window, |
| ... | ... | @@ -467,11 +467,11 @@ fn SliceDiffer(comptime T: type) type { |
| 467 | 467 | start_index: usize, |
| 468 | 468 | expected: []const T, |
| 469 | 469 | actual: []const T, |
| 470 | ttyconf: std.io.tty.Config, | |
| 470 | ttyconf: std.Io.tty.Config, | |
| 471 | 471 | |
| 472 | 472 | const Self = @This(); |
| 473 | 473 | |
| 474 | pub fn write(self: Self, writer: *std.io.Writer) !void { | |
| 474 | pub fn write(self: Self, writer: *std.Io.Writer) !void { | |
| 475 | 475 | for (self.expected, 0..) |value, i| { |
| 476 | 476 | const full_index = self.start_index + i; |
| 477 | 477 | 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 { |
| 490 | 490 | const BytesDiffer = struct { |
| 491 | 491 | expected: []const u8, |
| 492 | 492 | actual: []const u8, |
| 493 | ttyconf: std.io.tty.Config, | |
| 493 | ttyconf: std.Io.tty.Config, | |
| 494 | 494 | |
| 495 | pub fn write(self: BytesDiffer, writer: *std.io.Writer) !void { | |
| 495 | pub fn write(self: BytesDiffer, writer: *std.Io.Writer) !void { | |
| 496 | 496 | var expected_iterator = std.mem.window(u8, self.expected, 16, 16); |
| 497 | 497 | var row: usize = 0; |
| 498 | 498 | while (expected_iterator.next()) |chunk| { |
| ... | ... | @@ -538,7 +538,7 @@ const BytesDiffer = struct { |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
| 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 { | |
| 542 | 542 | if (diff) try self.ttyconf.setColor(writer, .red); |
| 543 | 543 | try writer.print(fmt, args); |
| 544 | 544 | if (diff) try self.ttyconf.setColor(writer, .reset); |
lib/std/unicode.zig+2-2| ... | ... | @@ -804,7 +804,7 @@ fn testDecode(bytes: []const u8) !u21 { |
| 804 | 804 | /// Ill-formed UTF-8 byte sequences are replaced by the replacement character (U+FFFD) |
| 805 | 805 | /// according to "U+FFFD Substitution of Maximal Subparts" from Chapter 3 of |
| 806 | 806 | /// the Unicode standard, and as specified by https://encoding.spec.whatwg.org/#utf-8-decoder |
| 807 | fn formatUtf8(utf8: []const u8, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 807 | fn formatUtf8(utf8: []const u8, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 808 | 808 | var buf: [300]u8 = undefined; // just an arbitrary size |
| 809 | 809 | var u8len: usize = 0; |
| 810 | 810 | |
| ... | ... | @@ -1464,7 +1464,7 @@ test calcWtf16LeLen { |
| 1464 | 1464 | |
| 1465 | 1465 | /// Print the given `utf16le` string, encoded as UTF-8 bytes. |
| 1466 | 1466 | /// Unpaired surrogates are replaced by the replacement character (U+FFFD). |
| 1467 | fn formatUtf16Le(utf16le: []const u16, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 1467 | fn formatUtf16Le(utf16le: []const u16, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 1468 | 1468 | var buf: [300]u8 = undefined; // just an arbitrary size |
| 1469 | 1469 | var it = Utf16LeIterator.init(utf16le); |
| 1470 | 1470 | var u8len: usize = 0; |
lib/std/zig.zig+3-3| ... | ... | @@ -51,9 +51,9 @@ pub const Color = enum { |
| 51 | 51 | /// Assume stderr is a terminal. |
| 52 | 52 | on, |
| 53 | 53 | |
| 54 | pub fn get_tty_conf(color: Color) std.io.tty.Config { | |
| 54 | pub fn get_tty_conf(color: Color) std.Io.tty.Config { | |
| 55 | 55 | return switch (color) { |
| 56 | .auto => std.io.tty.detectConfig(std.fs.File.stderr()), | |
| 56 | .auto => std.Io.tty.detectConfig(std.fs.File.stderr()), | |
| 57 | 57 | .on => .escape_codes, |
| 58 | 58 | .off => .no_color, |
| 59 | 59 | }; |
| ... | ... | @@ -322,7 +322,7 @@ pub const BuildId = union(enum) { |
| 322 | 322 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); |
| 323 | 323 | } |
| 324 | 324 | |
| 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 { | |
| 326 | 326 | switch (id) { |
| 327 | 327 | .none, .fast, .uuid, .sha1, .md5 => { |
| 328 | 328 | 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 |
| 204 | 204 | /// `gpa` is used for allocating the resulting formatted source code. |
| 205 | 205 | /// Caller owns the returned slice of bytes, allocated with `gpa`. |
| 206 | 206 | pub 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); | |
| 208 | 208 | defer aw.deinit(); |
| 209 | 209 | render(tree, gpa, &aw.writer, .{}) catch |err| switch (err) { |
| 210 | 210 | error.WriteFailed, error.OutOfMemory => return error.OutOfMemory, |
lib/std/zig/Ast/Render.zig+2-2| ... | ... | @@ -6,7 +6,7 @@ const meta = std.meta; |
| 6 | 6 | const Ast = std.zig.Ast; |
| 7 | 7 | const Token = std.zig.Token; |
| 8 | 8 | const primitives = std.zig.primitives; |
| 9 | const Writer = std.io.Writer; | |
| 9 | const Writer = std.Io.Writer; | |
| 10 | 10 | |
| 11 | 11 | const Render = @This(); |
| 12 | 12 | |
| ... | ... | @@ -2169,7 +2169,7 @@ fn renderArrayInit( |
| 2169 | 2169 | |
| 2170 | 2170 | const section_exprs = row_exprs[0..section_end]; |
| 2171 | 2171 | |
| 2172 | var sub_expr_buffer: std.io.Writer.Allocating = .init(gpa); | |
| 2172 | var sub_expr_buffer: Writer.Allocating = .init(gpa); | |
| 2173 | 2173 | defer sub_expr_buffer.deinit(); |
| 2174 | 2174 | |
| 2175 | 2175 | 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( |
| 11339 | 11339 | ) InnerError!void { |
| 11340 | 11340 | const raw_string = bytes[offset..]; |
| 11341 | 11341 | 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); | |
| 11343 | 11343 | defer buf.* = aw.toArrayList(); |
| 11344 | 11344 | break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) { |
| 11345 | 11345 | error.WriteFailed => return error.OutOfMemory, |
| ... | ... | @@ -13785,7 +13785,7 @@ fn lowerAstErrors(astgen: *AstGen) error{OutOfMemory}!void { |
| 13785 | 13785 | const tree = astgen.tree; |
| 13786 | 13786 | assert(tree.errors.len > 0); |
| 13787 | 13787 | |
| 13788 | var msg: std.io.Writer.Allocating = .init(gpa); | |
| 13788 | var msg: std.Io.Writer.Allocating = .init(gpa); | |
| 13789 | 13789 | defer msg.deinit(); |
| 13790 | 13790 | const msg_w = &msg.writer; |
| 13791 | 13791 |
lib/std/zig/ErrorBundle.zig+7-7| ... | ... | @@ -11,7 +11,7 @@ const std = @import("std"); |
| 11 | 11 | const ErrorBundle = @This(); |
| 12 | 12 | const Allocator = std.mem.Allocator; |
| 13 | 13 | const assert = std.debug.assert; |
| 14 | const Writer = std.io.Writer; | |
| 14 | const Writer = std.Io.Writer; | |
| 15 | 15 | |
| 16 | 16 | string_bytes: []const u8, |
| 17 | 17 | /// The first thing in this array is an `ErrorMessageList`. |
| ... | ... | @@ -156,7 +156,7 @@ pub fn nullTerminatedString(eb: ErrorBundle, index: String) [:0]const u8 { |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | pub const RenderOptions = struct { |
| 159 | ttyconf: std.io.tty.Config, | |
| 159 | ttyconf: std.Io.tty.Config, | |
| 160 | 160 | include_reference_trace: bool = true, |
| 161 | 161 | include_source_line: bool = true, |
| 162 | 162 | include_log_text: bool = true, |
| ... | ... | @@ -190,14 +190,14 @@ fn renderErrorMessageToWriter( |
| 190 | 190 | err_msg_index: MessageIndex, |
| 191 | 191 | w: *Writer, |
| 192 | 192 | kind: []const u8, |
| 193 | color: std.io.tty.Color, | |
| 193 | color: std.Io.tty.Color, | |
| 194 | 194 | indent: usize, |
| 195 | 195 | ) (Writer.Error || std.posix.UnexpectedError)!void { |
| 196 | 196 | const ttyconf = options.ttyconf; |
| 197 | 197 | const err_msg = eb.getErrorMessage(err_msg_index); |
| 198 | 198 | if (err_msg.src_loc != .none) { |
| 199 | 199 | const src = eb.extraData(SourceLocation, @intFromEnum(err_msg.src_loc)); |
| 200 | var prefix: std.io.Writer.Discarding = .init(&.{}); | |
| 200 | var prefix: Writer.Discarding = .init(&.{}); | |
| 201 | 201 | try w.splatByteAll(' ', indent); |
| 202 | 202 | prefix.count += indent; |
| 203 | 203 | try ttyconf.setColor(w, .bold); |
| ... | ... | @@ -794,9 +794,9 @@ pub const Wip = struct { |
| 794 | 794 | }; |
| 795 | 795 | defer bundle.deinit(std.testing.allocator); |
| 796 | 796 | |
| 797 | const ttyconf: std.io.tty.Config = .no_color; | |
| 797 | const ttyconf: std.Io.tty.Config = .no_color; | |
| 798 | 798 | |
| 799 | var bundle_buf: std.io.Writer.Allocating = .init(std.testing.allocator); | |
| 799 | var bundle_buf: Writer.Allocating = .init(std.testing.allocator); | |
| 800 | 800 | const bundle_bw = &bundle_buf.interface; |
| 801 | 801 | defer bundle_buf.deinit(); |
| 802 | 802 | try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_bw); |
| ... | ... | @@ -812,7 +812,7 @@ pub const Wip = struct { |
| 812 | 812 | }; |
| 813 | 813 | defer copy.deinit(std.testing.allocator); |
| 814 | 814 | |
| 815 | var copy_buf: std.io.Writer.Allocating = .init(std.testing.allocator); | |
| 815 | var copy_buf: Writer.Allocating = .init(std.testing.allocator); | |
| 816 | 816 | const copy_bw = &copy_buf.interface; |
| 817 | 817 | defer copy_buf.deinit(); |
| 818 | 818 | try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_bw); |
lib/std/zig/LibCInstallation.zig+1-1| ... | ... | @@ -43,7 +43,7 @@ pub fn parse( |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | const contents = try std.fs.cwd().readFileAlloc(allocator, libc_file, std.math.maxInt(usize)); | |
| 46 | const contents = try std.fs.cwd().readFileAlloc(libc_file, allocator, .limited(std.math.maxInt(usize))); | |
| 47 | 47 | defer allocator.free(contents); |
| 48 | 48 | |
| 49 | 49 | var it = std.mem.tokenizeScalar(u8, contents, '\n'); |
lib/std/zig/WindowsSdk.zig+1-1| ... | ... | @@ -766,7 +766,7 @@ const MsvcLibDir = struct { |
| 766 | 766 | writer.writeByte(std.fs.path.sep) catch unreachable; |
| 767 | 767 | writer.writeAll("state.json") catch unreachable; |
| 768 | 768 | |
| 769 | const json_contents = instances_dir.readFileAlloc(allocator, writer.buffered(), std.math.maxInt(usize)) catch continue; | |
| 769 | const json_contents = instances_dir.readFileAlloc(writer.buffered(), allocator, .limited(std.math.maxInt(usize))) catch continue; | |
| 770 | 770 | defer allocator.free(json_contents); |
| 771 | 771 | |
| 772 | 772 | var parsed = std.json.parseFromSlice(std.json.Value, allocator, json_contents, .{}) catch continue; |
lib/std/zig/ZonGen.zig+4-4| ... | ... | @@ -9,7 +9,7 @@ const StringIndexContext = std.hash_map.StringIndexContext; |
| 9 | 9 | const ZonGen = @This(); |
| 10 | 10 | const Zoir = @import("Zoir.zig"); |
| 11 | 11 | const Ast = @import("Ast.zig"); |
| 12 | const Writer = std.io.Writer; | |
| 12 | const Writer = std.Io.Writer; | |
| 13 | 13 | |
| 14 | 14 | gpa: Allocator, |
| 15 | 15 | tree: Ast, |
| ... | ... | @@ -472,7 +472,7 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory, |
| 472 | 472 | const raw_string = zg.tree.tokenSlice(ident_token)[offset..]; |
| 473 | 473 | try zg.string_bytes.ensureUnusedCapacity(gpa, raw_string.len); |
| 474 | 474 | 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); | |
| 476 | 476 | defer zg.string_bytes = aw.toArrayList(); |
| 477 | 477 | break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) { |
| 478 | 478 | error.WriteFailed => return error.OutOfMemory, |
| ... | ... | @@ -570,7 +570,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad |
| 570 | 570 | const size_hint = strLitSizeHint(zg.tree, str_node); |
| 571 | 571 | try string_bytes.ensureUnusedCapacity(gpa, size_hint); |
| 572 | 572 | 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); | |
| 574 | 574 | defer zg.string_bytes = aw.toArrayList(); |
| 575 | 575 | break :r parseStrLit(zg.tree, str_node, &aw.writer) catch |err| switch (err) { |
| 576 | 576 | error.WriteFailed => return error.OutOfMemory, |
| ... | ... | @@ -885,7 +885,7 @@ fn lowerAstErrors(zg: *ZonGen) Allocator.Error!void { |
| 885 | 885 | const tree = zg.tree; |
| 886 | 886 | assert(tree.errors.len > 0); |
| 887 | 887 | |
| 888 | var msg: std.io.Writer.Allocating = .init(gpa); | |
| 888 | var msg: Writer.Allocating = .init(gpa); | |
| 889 | 889 | defer msg.deinit(); |
| 890 | 890 | const msg_bw = &msg.writer; |
| 891 | 891 |
lib/std/zig/llvm/Builder.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ const builtin = @import("builtin"); |
| 7 | 7 | const DW = std.dwarf; |
| 8 | 8 | const ir = @import("ir.zig"); |
| 9 | 9 | const log = std.log.scoped(.llvm); |
| 10 | const Writer = std.io.Writer; | |
| 10 | const Writer = std.Io.Writer; | |
| 11 | 11 | |
| 12 | 12 | gpa: Allocator, |
| 13 | 13 | strip: bool, |
lib/std/zig/parser_test.zig-1| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | 3 | const print = std.debug.print; |
| 4 | const io = std.io; | |
| 5 | 4 | const maxInt = std.math.maxInt; |
| 6 | 5 | |
| 7 | 6 | test "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 @@ |
| 1 | 1 | const std = @import("../std.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | 3 | const utf8Encode = std.unicode.utf8Encode; |
| 4 | const Writer = std.io.Writer; | |
| 4 | const Writer = std.Io.Writer; | |
| 5 | 5 | |
| 6 | 6 | pub const ParseError = error{ |
| 7 | 7 | OutOfMemory, |
| ... | ... | @@ -45,7 +45,7 @@ pub const Error = union(enum) { |
| 45 | 45 | raw_string: []const u8, |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | fn formatMessage(self: FormatMessage, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 48 | fn formatMessage(self: FormatMessage, writer: *Writer) Writer.Error!void { | |
| 49 | 49 | switch (self.err) { |
| 50 | 50 | .invalid_escape_character => |bad_index| try writer.print( |
| 51 | 51 | "invalid escape character: '{c}'", |
| ... | ... | @@ -358,7 +358,7 @@ pub fn parseWrite(writer: *Writer, bytes: []const u8) Writer.Error!Result { |
| 358 | 358 | /// Higher level API. Does not return extra info about parse errors. |
| 359 | 359 | /// Caller owns returned memory. |
| 360 | 360 | pub 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); | |
| 362 | 362 | defer aw.deinit(); |
| 363 | 363 | const result = parseWrite(&aw.writer, bytes) catch |err| switch (err) { |
| 364 | 364 | error.WriteFailed => return error.OutOfMemory, |
lib/std/zip.zig+2-2| ... | ... | @@ -195,12 +195,12 @@ pub const Decompress = struct { |
| 195 | 195 | }; |
| 196 | 196 | } |
| 197 | 197 | |
| 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 { | |
| 199 | 199 | const d: *Decompress = @fieldParentPtr("interface", r); |
| 200 | 200 | return d.store.read(w, limit); |
| 201 | 201 | } |
| 202 | 202 | |
| 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 { | |
| 204 | 204 | const d: *Decompress = @fieldParentPtr("interface", r); |
| 205 | 205 | return flate.Decompress.read(&d.inflate, w, limit); |
| 206 | 206 | } |
lib/ubsan_rt.zig+1-1| ... | ... | @@ -119,7 +119,7 @@ const Value = extern struct { |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 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 { | |
| 123 | 123 | // Work around x86_64 backend limitation. |
| 124 | 124 | if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) { |
| 125 | 125 | try writer.writeAll("(unknown)"); |
src/Air.zig+1-1| ... | ... | @@ -961,7 +961,7 @@ pub const Inst = struct { |
| 961 | 961 | return index.unwrap().target; |
| 962 | 962 | } |
| 963 | 963 | |
| 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 { | |
| 965 | 965 | try w.writeByte('%'); |
| 966 | 966 | switch (index.unwrap()) { |
| 967 | 967 | .ref => {}, |
src/Air/Liveness.zig+3-2| ... | ... | @@ -10,6 +10,7 @@ const log = std.log.scoped(.liveness); |
| 10 | 10 | const assert = std.debug.assert; |
| 11 | 11 | const Allocator = std.mem.Allocator; |
| 12 | 12 | const Log2Int = std.math.Log2Int; |
| 13 | const Writer = std.Io.Writer; | |
| 13 | 14 | |
| 14 | 15 | const Liveness = @This(); |
| 15 | 16 | const trace = @import("../tracy.zig").trace; |
| ... | ... | @@ -2037,7 +2038,7 @@ fn fmtInstSet(set: *const std.AutoHashMapUnmanaged(Air.Inst.Index, void)) FmtIns |
| 2037 | 2038 | const FmtInstSet = struct { |
| 2038 | 2039 | set: *const std.AutoHashMapUnmanaged(Air.Inst.Index, void), |
| 2039 | 2040 | |
| 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 { | |
| 2041 | 2042 | if (val.set.count() == 0) { |
| 2042 | 2043 | try w.writeAll("[no instructions]"); |
| 2043 | 2044 | return; |
| ... | ... | @@ -2057,7 +2058,7 @@ fn fmtInstList(list: []const Air.Inst.Index) FmtInstList { |
| 2057 | 2058 | const FmtInstList = struct { |
| 2058 | 2059 | list: []const Air.Inst.Index, |
| 2059 | 2060 | |
| 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 { | |
| 2061 | 2062 | if (val.list.len == 0) { |
| 2062 | 2063 | try w.writeAll("[no instructions]"); |
| 2063 | 2064 | return; |
src/Air/print.zig+48-48| ... | ... | @@ -9,7 +9,7 @@ const Type = @import("../Type.zig"); |
| 9 | 9 | const Air = @import("../Air.zig"); |
| 10 | 10 | const InternPool = @import("../InternPool.zig"); |
| 11 | 11 | |
| 12 | pub fn write(air: Air, stream: *std.io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { | |
| 12 | pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) void { | |
| 13 | 13 | comptime assert(build_options.enable_debug_extensions); |
| 14 | 14 | const instruction_bytes = air.instructions.len * |
| 15 | 15 | // Here we don't use @sizeOf(Air.Inst.Data) because it would include |
| ... | ... | @@ -55,7 +55,7 @@ pub fn write(air: Air, stream: *std.io.Writer, pt: Zcu.PerThread, liveness: ?Air |
| 55 | 55 | |
| 56 | 56 | pub fn writeInst( |
| 57 | 57 | air: Air, |
| 58 | stream: *std.io.Writer, | |
| 58 | stream: *std.Io.Writer, | |
| 59 | 59 | inst: Air.Inst.Index, |
| 60 | 60 | pt: Zcu.PerThread, |
| 61 | 61 | liveness: ?Air.Liveness, |
| ... | ... | @@ -92,16 +92,16 @@ const Writer = struct { |
| 92 | 92 | indent: usize, |
| 93 | 93 | skip_body: bool, |
| 94 | 94 | |
| 95 | const Error = std.io.Writer.Error; | |
| 95 | const Error = std.Io.Writer.Error; | |
| 96 | 96 | |
| 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 { | |
| 98 | 98 | for (body) |inst| { |
| 99 | 99 | try w.writeInst(s, inst); |
| 100 | 100 | try s.writeByte('\n'); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 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 { | |
| 105 | 105 | const tag = w.air.instructions.items(.tag)[@intFromEnum(inst)]; |
| 106 | 106 | try s.splatByteAll(' ', w.indent); |
| 107 | 107 | try s.print("{f}{c}= {s}(", .{ |
| ... | ... | @@ -341,48 +341,48 @@ const Writer = struct { |
| 341 | 341 | try s.writeByte(')'); |
| 342 | 342 | } |
| 343 | 343 | |
| 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 { | |
| 345 | 345 | const bin_op = w.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; |
| 346 | 346 | try w.writeOperand(s, inst, 0, bin_op.lhs); |
| 347 | 347 | try s.writeAll(", "); |
| 348 | 348 | try w.writeOperand(s, inst, 1, bin_op.rhs); |
| 349 | 349 | } |
| 350 | 350 | |
| 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 { | |
| 352 | 352 | const un_op = w.air.instructions.items(.data)[@intFromEnum(inst)].un_op; |
| 353 | 353 | try w.writeOperand(s, inst, 0, un_op); |
| 354 | 354 | } |
| 355 | 355 | |
| 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 { | |
| 357 | 357 | _ = w; |
| 358 | 358 | _ = s; |
| 359 | 359 | _ = inst; |
| 360 | 360 | // no-op, no argument to write |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | fn writeType(w: *Writer, s: *std.io.Writer, ty: Type) !void { | |
| 363 | fn writeType(w: *Writer, s: *std.Io.Writer, ty: Type) !void { | |
| 364 | 364 | return ty.print(s, w.pt); |
| 365 | 365 | } |
| 366 | 366 | |
| 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 { | |
| 368 | 368 | const ty = w.air.instructions.items(.data)[@intFromEnum(inst)].ty; |
| 369 | 369 | try w.writeType(s, ty); |
| 370 | 370 | } |
| 371 | 371 | |
| 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 { | |
| 373 | 373 | const arg = w.air.instructions.items(.data)[@intFromEnum(inst)].arg; |
| 374 | 374 | try w.writeType(s, arg.ty.toType()); |
| 375 | 375 | try s.print(", {d}", .{arg.zir_param_index}); |
| 376 | 376 | } |
| 377 | 377 | |
| 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 { | |
| 379 | 379 | const ty_op = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 380 | 380 | try w.writeType(s, ty_op.ty.toType()); |
| 381 | 381 | try s.writeAll(", "); |
| 382 | 382 | try w.writeOperand(s, inst, 0, ty_op.operand); |
| 383 | 383 | } |
| 384 | 384 | |
| 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 { | |
| 386 | 386 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 387 | 387 | try w.writeType(s, ty_pl.ty.toType()); |
| 388 | 388 | const body: []const Air.Inst.Index = @ptrCast(switch (tag) { |
| ... | ... | @@ -423,7 +423,7 @@ const Writer = struct { |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
| 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 { | |
| 427 | 427 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 428 | 428 | const extra = w.air.extraData(Air.Block, ty_pl.payload); |
| 429 | 429 | 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 { |
| 439 | 439 | try s.writeAll("}"); |
| 440 | 440 | } |
| 441 | 441 | |
| 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 { | |
| 443 | 443 | const zcu = w.pt.zcu; |
| 444 | 444 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 445 | 445 | const vector_ty = ty_pl.ty.toType(); |
| ... | ... | @@ -455,7 +455,7 @@ const Writer = struct { |
| 455 | 455 | try s.writeAll("]"); |
| 456 | 456 | } |
| 457 | 457 | |
| 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 { | |
| 459 | 459 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 460 | 460 | const extra = w.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 461 | 461 | |
| ... | ... | @@ -463,7 +463,7 @@ const Writer = struct { |
| 463 | 463 | try w.writeOperand(s, inst, 0, extra.init); |
| 464 | 464 | } |
| 465 | 465 | |
| 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 { | |
| 467 | 467 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 468 | 468 | const extra = w.air.extraData(Air.StructField, ty_pl.payload).data; |
| 469 | 469 | |
| ... | ... | @@ -471,7 +471,7 @@ const Writer = struct { |
| 471 | 471 | try s.print(", {d}", .{extra.field_index}); |
| 472 | 472 | } |
| 473 | 473 | |
| 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 { | |
| 475 | 475 | const data = w.air.instructions.items(.data); |
| 476 | 476 | const ty_pl = data[@intFromEnum(inst)].ty_pl; |
| 477 | 477 | const extra = w.air.extraData(Air.Bin, ty_pl.payload).data; |
| ... | ... | @@ -484,7 +484,7 @@ const Writer = struct { |
| 484 | 484 | try w.writeOperand(s, inst, 1, extra.rhs); |
| 485 | 485 | } |
| 486 | 486 | |
| 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 { | |
| 488 | 488 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 489 | 489 | const extra = w.air.extraData(Air.Cmpxchg, ty_pl.payload).data; |
| 490 | 490 | |
| ... | ... | @@ -498,7 +498,7 @@ const Writer = struct { |
| 498 | 498 | }); |
| 499 | 499 | } |
| 500 | 500 | |
| 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 { | |
| 502 | 502 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 503 | 503 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| 504 | 504 | |
| ... | ... | @@ -509,7 +509,7 @@ const Writer = struct { |
| 509 | 509 | try w.writeOperand(s, inst, 2, pl_op.operand); |
| 510 | 510 | } |
| 511 | 511 | |
| 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 { | |
| 513 | 513 | const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst); |
| 514 | 514 | try w.writeType(s, unwrapped.result_ty); |
| 515 | 515 | try s.writeAll(", "); |
| ... | ... | @@ -525,7 +525,7 @@ const Writer = struct { |
| 525 | 525 | try s.writeByte(']'); |
| 526 | 526 | } |
| 527 | 527 | |
| 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 { | |
| 529 | 529 | const unwrapped = w.air.unwrapShuffleTwo(w.pt.zcu, inst); |
| 530 | 530 | try w.writeType(s, unwrapped.result_ty); |
| 531 | 531 | try s.writeAll(", "); |
| ... | ... | @@ -544,7 +544,7 @@ const Writer = struct { |
| 544 | 544 | try s.writeByte(']'); |
| 545 | 545 | } |
| 546 | 546 | |
| 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 { | |
| 548 | 548 | const zcu = w.pt.zcu; |
| 549 | 549 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 550 | 550 | const extra = w.air.extraData(Air.Bin, pl_op.payload).data; |
| ... | ... | @@ -559,14 +559,14 @@ const Writer = struct { |
| 559 | 559 | try w.writeOperand(s, inst, 2, extra.rhs); |
| 560 | 560 | } |
| 561 | 561 | |
| 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 { | |
| 563 | 563 | const reduce = w.air.instructions.items(.data)[@intFromEnum(inst)].reduce; |
| 564 | 564 | |
| 565 | 565 | try w.writeOperand(s, inst, 0, reduce.operand); |
| 566 | 566 | try s.print(", {s}", .{@tagName(reduce.operation)}); |
| 567 | 567 | } |
| 568 | 568 | |
| 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 { | |
| 570 | 570 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 571 | 571 | const extra = w.air.extraData(Air.VectorCmp, ty_pl.payload).data; |
| 572 | 572 | |
| ... | ... | @@ -576,7 +576,7 @@ const Writer = struct { |
| 576 | 576 | try w.writeOperand(s, inst, 1, extra.rhs); |
| 577 | 577 | } |
| 578 | 578 | |
| 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 { | |
| 580 | 580 | const data = w.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem; |
| 581 | 581 | const extra = w.air.extraData(Air.VectorCmp, data.payload).data; |
| 582 | 582 | |
| ... | ... | @@ -587,21 +587,21 @@ const Writer = struct { |
| 587 | 587 | try w.writeOperand(s, inst, 2, extra.rhs); |
| 588 | 588 | } |
| 589 | 589 | |
| 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 { | |
| 591 | 591 | const ip = &w.pt.zcu.intern_pool; |
| 592 | 592 | const ty_nav = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_nav; |
| 593 | 593 | try w.writeType(s, .fromInterned(ty_nav.ty)); |
| 594 | 594 | try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)}); |
| 595 | 595 | } |
| 596 | 596 | |
| 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 { | |
| 598 | 598 | const atomic_load = w.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load; |
| 599 | 599 | |
| 600 | 600 | try w.writeOperand(s, inst, 0, atomic_load.ptr); |
| 601 | 601 | try s.print(", {s}", .{@tagName(atomic_load.order)}); |
| 602 | 602 | } |
| 603 | 603 | |
| 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 { | |
| 605 | 605 | const prefetch = w.air.instructions.items(.data)[@intFromEnum(inst)].prefetch; |
| 606 | 606 | |
| 607 | 607 | try w.writeOperand(s, inst, 0, prefetch.ptr); |
| ... | ... | @@ -612,7 +612,7 @@ const Writer = struct { |
| 612 | 612 | |
| 613 | 613 | fn writeAtomicStore( |
| 614 | 614 | w: *Writer, |
| 615 | s: *std.io.Writer, | |
| 615 | s: *std.Io.Writer, | |
| 616 | 616 | inst: Air.Inst.Index, |
| 617 | 617 | order: std.builtin.AtomicOrder, |
| 618 | 618 | ) Error!void { |
| ... | ... | @@ -623,7 +623,7 @@ const Writer = struct { |
| 623 | 623 | try s.print(", {s}", .{@tagName(order)}); |
| 624 | 624 | } |
| 625 | 625 | |
| 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 { | |
| 627 | 627 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 628 | 628 | const extra = w.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 629 | 629 | |
| ... | ... | @@ -633,7 +633,7 @@ const Writer = struct { |
| 633 | 633 | try s.print(", {s}, {s}", .{ @tagName(extra.op()), @tagName(extra.ordering()) }); |
| 634 | 634 | } |
| 635 | 635 | |
| 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 { | |
| 637 | 637 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 638 | 638 | const extra = w.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 639 | 639 | |
| ... | ... | @@ -641,7 +641,7 @@ const Writer = struct { |
| 641 | 641 | try s.print(", {d}", .{extra.field_index}); |
| 642 | 642 | } |
| 643 | 643 | |
| 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 { | |
| 645 | 645 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 646 | 646 | const extra = w.air.extraData(Air.Asm, ty_pl.payload); |
| 647 | 647 | const is_volatile = extra.data.flags.is_volatile; |
| ... | ... | @@ -730,19 +730,19 @@ const Writer = struct { |
| 730 | 730 | try s.print(", \"{f}\"", .{std.zig.fmtString(asm_source)}); |
| 731 | 731 | } |
| 732 | 732 | |
| 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 { | |
| 734 | 734 | const dbg_stmt = w.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 735 | 735 | try s.print("{d}:{d}", .{ dbg_stmt.line + 1, dbg_stmt.column + 1 }); |
| 736 | 736 | } |
| 737 | 737 | |
| 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 { | |
| 739 | 739 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 740 | 740 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 741 | 741 | const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload); |
| 742 | 742 | try s.print(", \"{f}\"", .{std.zig.fmtString(name.toSlice(w.air))}); |
| 743 | 743 | } |
| 744 | 744 | |
| 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 { | |
| 746 | 746 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 747 | 747 | const extra = w.air.extraData(Air.Call, pl_op.payload); |
| 748 | 748 | 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 { |
| 755 | 755 | try s.writeAll("]"); |
| 756 | 756 | } |
| 757 | 757 | |
| 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 { | |
| 759 | 759 | const br = w.air.instructions.items(.data)[@intFromEnum(inst)].br; |
| 760 | 760 | try w.writeInstIndex(s, br.block_inst, false); |
| 761 | 761 | try s.writeAll(", "); |
| 762 | 762 | try w.writeOperand(s, inst, 0, br.operand); |
| 763 | 763 | } |
| 764 | 764 | |
| 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 { | |
| 766 | 766 | const repeat = w.air.instructions.items(.data)[@intFromEnum(inst)].repeat; |
| 767 | 767 | try w.writeInstIndex(s, repeat.loop_inst, false); |
| 768 | 768 | } |
| 769 | 769 | |
| 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 { | |
| 771 | 771 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 772 | 772 | const extra = w.air.extraData(Air.Try, pl_op.payload); |
| 773 | 773 | 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 { |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | |
| 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 { | |
| 805 | 805 | const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl; |
| 806 | 806 | const extra = w.air.extraData(Air.TryPtr, ty_pl.payload); |
| 807 | 807 | 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 { |
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | |
| 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 { | |
| 842 | 842 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 843 | 843 | const extra = w.air.extraData(Air.CondBr, pl_op.payload); |
| 844 | 844 | 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 { |
| 897 | 897 | try s.writeAll("}"); |
| 898 | 898 | } |
| 899 | 899 | |
| 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 { | |
| 901 | 901 | const switch_br = w.air.unwrapSwitch(inst); |
| 902 | 902 | |
| 903 | 903 | const liveness: Air.Liveness.SwitchBrTable = if (w.liveness) |liveness| |
| ... | ... | @@ -983,25 +983,25 @@ const Writer = struct { |
| 983 | 983 | try s.splatByteAll(' ', old_indent); |
| 984 | 984 | } |
| 985 | 985 | |
| 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 { | |
| 987 | 987 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 988 | 988 | try s.print("{d}", .{pl_op.payload}); |
| 989 | 989 | } |
| 990 | 990 | |
| 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 { | |
| 992 | 992 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 993 | 993 | try s.print("{d}, ", .{pl_op.payload}); |
| 994 | 994 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 995 | 995 | } |
| 996 | 996 | |
| 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 { | |
| 998 | 998 | const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; |
| 999 | 999 | try s.print("{d}", .{pl_op.payload}); |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | fn writeOperand( |
| 1003 | 1003 | w: *Writer, |
| 1004 | s: *std.io.Writer, | |
| 1004 | s: *std.Io.Writer, | |
| 1005 | 1005 | inst: Air.Inst.Index, |
| 1006 | 1006 | op_index: usize, |
| 1007 | 1007 | operand: Air.Inst.Ref, |
| ... | ... | @@ -1027,7 +1027,7 @@ const Writer = struct { |
| 1027 | 1027 | |
| 1028 | 1028 | fn writeInstRef( |
| 1029 | 1029 | w: *Writer, |
| 1030 | s: *std.io.Writer, | |
| 1030 | s: *std.Io.Writer, | |
| 1031 | 1031 | operand: Air.Inst.Ref, |
| 1032 | 1032 | dies: bool, |
| 1033 | 1033 | ) Error!void { |
| ... | ... | @@ -1047,7 +1047,7 @@ const Writer = struct { |
| 1047 | 1047 | |
| 1048 | 1048 | fn writeInstIndex( |
| 1049 | 1049 | w: *Writer, |
| 1050 | s: *std.io.Writer, | |
| 1050 | s: *std.Io.Writer, | |
| 1051 | 1051 | inst: Air.Inst.Index, |
| 1052 | 1052 | dies: bool, |
| 1053 | 1053 | ) Error!void { |
src/Compilation.zig+5-5| ... | ... | @@ -12,7 +12,7 @@ const ThreadPool = std.Thread.Pool; |
| 12 | 12 | const WaitGroup = std.Thread.WaitGroup; |
| 13 | 13 | const ErrorBundle = std.zig.ErrorBundle; |
| 14 | 14 | const fatal = std.process.fatal; |
| 15 | const Writer = std.io.Writer; | |
| 15 | const Writer = std.Io.Writer; | |
| 16 | 16 | |
| 17 | 17 | const Value = @import("Value.zig"); |
| 18 | 18 | const Type = @import("Type.zig"); |
| ... | ... | @@ -468,7 +468,7 @@ pub const Path = struct { |
| 468 | 468 | const Formatter = struct { |
| 469 | 469 | p: Path, |
| 470 | 470 | 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 { | |
| 472 | 472 | const root_path: []const u8 = switch (f.p.root) { |
| 473 | 473 | .zig_lib => f.comp.dirs.zig_lib.path orelse ".", |
| 474 | 474 | .global_cache => f.comp.dirs.global_cache.path orelse ".", |
| ... | ... | @@ -1883,7 +1883,7 @@ pub const CreateDiagnostic = union(enum) { |
| 1883 | 1883 | sub: []const u8, |
| 1884 | 1884 | err: (fs.Dir.MakeError || fs.Dir.OpenError || fs.Dir.StatFileError), |
| 1885 | 1885 | }; |
| 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 { | |
| 1887 | 1887 | switch (diag) { |
| 1888 | 1888 | .export_table_import_table_conflict => try w.writeAll("'--import-table' and '--export-table' cannot be used together"), |
| 1889 | 1889 | .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 |
| 6457 | 6457 | |
| 6458 | 6458 | // In .rc files, a " within a quoted string is escaped as "" |
| 6459 | 6459 | 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 { | |
| 6461 | 6461 | for (bytes) |byte| switch (byte) { |
| 6462 | 6462 | '"' => try writer.writeAll("\"\""), |
| 6463 | 6463 | '\\' => try writer.writeAll("\\\\"), |
| ... | ... | @@ -6576,7 +6576,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 |
| 6576 | 6576 | // Read depfile and update cache manifest |
| 6577 | 6577 | { |
| 6578 | 6578 | const dep_basename = fs.path.basename(out_dep_path); |
| 6579 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(arena, dep_basename, 50 * 1024 * 1024); | |
| 6579 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, arena, .limited(50 * 1024 * 1024)); | |
| 6580 | 6580 | defer arena.free(dep_file_contents); |
| 6581 | 6581 | |
| 6582 | 6582 | const value = try std.json.parseFromSliceLeaky(std.json.Value, arena, dep_file_contents, .{}); |
src/InternPool.zig+15-15| ... | ... | @@ -1,6 +1,20 @@ |
| 1 | 1 | //! All interned objects have both a value and a type. |
| 2 | 2 | //! This data structure is self-contained. |
| 3 | 3 | |
| 4 | const builtin = @import("builtin"); | |
| 5 | const std = @import("std"); | |
| 6 | const Allocator = std.mem.Allocator; | |
| 7 | const assert = std.debug.assert; | |
| 8 | const BigIntConst = std.math.big.int.Const; | |
| 9 | const BigIntMutable = std.math.big.int.Mutable; | |
| 10 | const Cache = std.Build.Cache; | |
| 11 | const Limb = std.math.big.Limb; | |
| 12 | const Hash = std.hash.Wyhash; | |
| 13 | ||
| 14 | const InternPool = @This(); | |
| 15 | const Zcu = @import("Zcu.zig"); | |
| 16 | const Zir = std.zig.Zir; | |
| 17 | ||
| 4 | 18 | /// One item per thread, indexed by `tid`, which is dense and unique per thread. |
| 5 | 19 | locals: []Local, |
| 6 | 20 | /// 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 { |
| 1606 | 1620 | |
| 1607 | 1621 | const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), false); |
| 1608 | 1622 | |
| 1609 | const builtin = @import("builtin"); | |
| 1610 | const std = @import("std"); | |
| 1611 | const Allocator = std.mem.Allocator; | |
| 1612 | const assert = std.debug.assert; | |
| 1613 | const BigIntConst = std.math.big.int.Const; | |
| 1614 | const BigIntMutable = std.math.big.int.Mutable; | |
| 1615 | const Cache = std.Build.Cache; | |
| 1616 | const Limb = std.math.big.Limb; | |
| 1617 | const Hash = std.hash.Wyhash; | |
| 1618 | ||
| 1619 | const InternPool = @This(); | |
| 1620 | const Zcu = @import("Zcu.zig"); | |
| 1621 | const Zir = std.zig.Zir; | |
| 1622 | ||
| 1623 | 1623 | /// An index into `maps` which might be `none`. |
| 1624 | 1624 | pub const OptionalMapIndex = enum(u32) { |
| 1625 | 1625 | none = std.math.maxInt(u32), |
| ... | ... | @@ -1895,7 +1895,7 @@ pub const NullTerminatedString = enum(u32) { |
| 1895 | 1895 | ip: *const InternPool, |
| 1896 | 1896 | id: bool, |
| 1897 | 1897 | }; |
| 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 { | |
| 1899 | 1899 | const slice = data.string.toSlice(data.ip); |
| 1900 | 1900 | if (!data.id) { |
| 1901 | 1901 | try writer.writeAll(slice); |
src/Package/Fetch.zig+4-5| ... | ... | @@ -655,10 +655,9 @@ fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void { |
| 655 | 655 | const eb = &f.error_bundle; |
| 656 | 656 | const arena = f.arena.allocator(); |
| 657 | 657 | const manifest_bytes = pkg_root.root_dir.handle.readFileAllocOptions( |
| 658 | arena, | |
| 659 | 658 | try fs.path.join(arena, &.{ pkg_root.sub_path, Manifest.basename }), |
| 660 | Manifest.max_bytes, | |
| 661 | null, | |
| 659 | arena, | |
| 660 | .limited(Manifest.max_bytes), | |
| 662 | 661 | .@"1", |
| 663 | 662 | 0, |
| 664 | 663 | ) catch |err| switch (err) { |
| ... | ... | @@ -2020,7 +2019,7 @@ const UnpackResult = struct { |
| 2020 | 2019 | // output errors to string |
| 2021 | 2020 | var errors = try fetch.error_bundle.toOwnedBundle(""); |
| 2022 | 2021 | defer errors.deinit(gpa); |
| 2023 | var aw: std.io.Writer.Allocating = .init(gpa); | |
| 2022 | var aw: std.Io.Writer.Allocating = .init(gpa); | |
| 2024 | 2023 | defer aw.deinit(); |
| 2025 | 2024 | try errors.renderToWriter(.{ .ttyconf = .no_color }, &aw.writer); |
| 2026 | 2025 | try std.testing.expectEqualStrings( |
| ... | ... | @@ -2329,7 +2328,7 @@ const TestFetchBuilder = struct { |
| 2329 | 2328 | if (notes_len > 0) { |
| 2330 | 2329 | try std.testing.expectEqual(notes_len, em.notes_len); |
| 2331 | 2330 | } |
| 2332 | var aw: std.io.Writer.Allocating = .init(std.testing.allocator); | |
| 2331 | var aw: std.Io.Writer.Allocating = .init(std.testing.allocator); | |
| 2333 | 2332 | defer aw.deinit(); |
| 2334 | 2333 | try errors.renderToWriter(.{ .ttyconf = .no_color }, &aw.writer); |
| 2335 | 2334 | try std.testing.expectEqualStrings(msg, aw.written()); |
src/Package/Fetch/git.zig+3-3| ... | ... | @@ -146,7 +146,7 @@ pub const Oid = union(Format) { |
| 146 | 146 | } else error.InvalidOid; |
| 147 | 147 | } |
| 148 | 148 | |
| 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 { | |
| 150 | 150 | try writer.print("{x}", .{oid.slice()}); |
| 151 | 151 | } |
| 152 | 152 | |
| ... | ... | @@ -1599,7 +1599,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void |
| 1599 | 1599 | const max_file_size = 8192; |
| 1600 | 1600 | |
| 1601 | 1601 | if (!skip_checksums) { |
| 1602 | const index_file_data = try git_dir.dir.readFileAlloc(testing.allocator, "testrepo.idx", max_file_size); | |
| 1602 | const index_file_data = try git_dir.dir.readFileAlloc("testrepo.idx", testing.allocator, .limited(max_file_size)); | |
| 1603 | 1603 | defer testing.allocator.free(index_file_data); |
| 1604 | 1604 | // testrepo.idx is generated by Git. The index created by this file should |
| 1605 | 1605 | // match it exactly. Running `git verify-pack -v testrepo.pack` can verify |
| ... | ... | @@ -1675,7 +1675,7 @@ fn runRepositoryTest(comptime format: Oid.Format, head_commit: []const u8) !void |
| 1675 | 1675 | \\revision 19 |
| 1676 | 1676 | \\ |
| 1677 | 1677 | ; |
| 1678 | const actual_file_contents = try worktree.dir.readFileAlloc(testing.allocator, "file", max_file_size); | |
| 1678 | const actual_file_contents = try worktree.dir.readFileAlloc("file", testing.allocator, .limited(max_file_size)); | |
| 1679 | 1679 | defer testing.allocator.free(actual_file_contents); |
| 1680 | 1680 | try testing.expectEqualStrings(expected_file_contents, actual_file_contents); |
| 1681 | 1681 | } |
src/Package/Manifest.zig+1-1| ... | ... | @@ -472,7 +472,7 @@ const Parse = struct { |
| 472 | 472 | ) InnerError!void { |
| 473 | 473 | const raw_string = bytes[offset..]; |
| 474 | 474 | 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); | |
| 476 | 476 | defer buf.* = aw.toArrayList(); |
| 477 | 477 | break :r std.zig.string_literal.parseWrite(&aw.writer, raw_string) catch |err| switch (err) { |
| 478 | 478 | error.WriteFailed => return error.OutOfMemory, |
src/Sema.zig+5-5| ... | ... | @@ -3080,7 +3080,7 @@ pub fn createTypeName( |
| 3080 | 3080 | const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip) orelse return error.AnalysisFail); |
| 3081 | 3081 | const zir_tags = sema.code.instructions.items(.tag); |
| 3082 | 3082 | |
| 3083 | var aw: std.io.Writer.Allocating = .init(gpa); | |
| 3083 | var aw: std.Io.Writer.Allocating = .init(gpa); | |
| 3084 | 3084 | defer aw.deinit(); |
| 3085 | 3085 | const w = &aw.writer; |
| 3086 | 3086 | w.print("{f}(", .{block.type_name_ctx.fmt(ip)}) catch return error.OutOfMemory; |
| ... | ... | @@ -5508,7 +5508,7 @@ fn zirCompileLog( |
| 5508 | 5508 | const zcu = pt.zcu; |
| 5509 | 5509 | const gpa = zcu.gpa; |
| 5510 | 5510 | |
| 5511 | var aw: std.io.Writer.Allocating = .init(gpa); | |
| 5511 | var aw: std.Io.Writer.Allocating = .init(gpa); | |
| 5512 | 5512 | defer aw.deinit(); |
| 5513 | 5513 | const writer = &aw.writer; |
| 5514 | 5514 | |
| ... | ... | @@ -9080,7 +9080,7 @@ fn callConvSupportsVarArgs(cc: std.builtin.CallingConvention.Tag) bool { |
| 9080 | 9080 | fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: std.builtin.CallingConvention.Tag) CompileError!void { |
| 9081 | 9081 | const CallingConventionsSupportingVarArgsList = struct { |
| 9082 | 9082 | 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 { | |
| 9084 | 9084 | var first = true; |
| 9085 | 9085 | for (calling_conventions_supporting_var_args) |cc_inner| { |
| 9086 | 9086 | for (std.Target.Cpu.Arch.fromCallingConvention(cc_inner)) |supported_arch| { |
| ... | ... | @@ -9521,7 +9521,7 @@ fn finishFunc( |
| 9521 | 9521 | .bad_arch => |allowed_archs| { |
| 9522 | 9522 | const ArchListFormatter = struct { |
| 9523 | 9523 | 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 { | |
| 9525 | 9525 | for (formatter.archs, 0..) |arch, i| { |
| 9526 | 9526 | if (i != 0) |
| 9527 | 9527 | try w.writeAll(", "); |
| ... | ... | @@ -36962,7 +36962,7 @@ fn notePathToComptimeAllocPtr( |
| 36962 | 36962 | error.AnalysisFail => unreachable, |
| 36963 | 36963 | }; |
| 36964 | 36964 | |
| 36965 | var second_path_aw: std.io.Writer.Allocating = .init(arena); | |
| 36965 | var second_path_aw: std.Io.Writer.Allocating = .init(arena); | |
| 36966 | 36966 | defer second_path_aw.deinit(); |
| 36967 | 36967 | const inter_name = try std.fmt.allocPrint(arena, "v{d}", .{intermediate_value_count}); |
| 36968 | 36968 | 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 { |
| 121 | 121 | return a.toIntern() == b.toIntern(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | pub fn format(ty: Type, writer: *std.io.Writer) !void { | |
| 124 | pub fn format(ty: Type, writer: *std.Io.Writer) !void { | |
| 125 | 125 | _ = ty; |
| 126 | 126 | _ = writer; |
| 127 | 127 | @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()"); |
| ... | ... | @@ -140,7 +140,7 @@ const Format = struct { |
| 140 | 140 | ty: Type, |
| 141 | 141 | pt: Zcu.PerThread, |
| 142 | 142 | |
| 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 { | |
| 144 | 144 | return print(f.ty, writer, f.pt); |
| 145 | 145 | } |
| 146 | 146 | }; |
| ... | ... | @@ -151,13 +151,13 @@ pub fn fmtDebug(ty: Type) std.fmt.Formatter(Type, dump) { |
| 151 | 151 | |
| 152 | 152 | /// This is a debug function. In order to print types in a meaningful way |
| 153 | 153 | /// we also need access to the module. |
| 154 | pub fn dump(start_type: Type, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 154 | pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 155 | 155 | return writer.print("{any}", .{start_type.ip_index}); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /// Prints a name suitable for `@typeName`. |
| 159 | 159 | /// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels. |
| 160 | pub fn print(ty: Type, writer: *std.io.Writer, pt: Zcu.PerThread) std.io.Writer.Error!void { | |
| 160 | pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread) std.Io.Writer.Error!void { | |
| 161 | 161 | const zcu = pt.zcu; |
| 162 | 162 | const ip = &zcu.intern_pool; |
| 163 | 163 | switch (ip.indexToKey(ty.toIntern())) { |
src/Value.zig+2-2| ... | ... | @@ -15,7 +15,7 @@ const Value = @This(); |
| 15 | 15 | |
| 16 | 16 | ip_index: InternPool.Index, |
| 17 | 17 | |
| 18 | pub fn format(val: Value, writer: *std.io.Writer) !void { | |
| 18 | pub fn format(val: Value, writer: *std.Io.Writer) !void { | |
| 19 | 19 | _ = val; |
| 20 | 20 | _ = writer; |
| 21 | 21 | @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 { |
| 23 | 23 | |
| 24 | 24 | /// This is a debug function. In order to print values in a meaningful way |
| 25 | 25 | /// we also need access to the type. |
| 26 | pub fn dump(start_val: Value, w: std.io.Writer) std.io.Writer.Error!void { | |
| 26 | pub fn dump(start_val: Value, w: std.Io.Writer) std.Io.Writer.Error!void { | |
| 27 | 27 | try w.print("(interned: {})", .{start_val.toIntern()}); |
| 28 | 28 | } |
| 29 | 29 |
src/Zcu.zig+5-5| ... | ... | @@ -15,7 +15,7 @@ const BigIntConst = std.math.big.int.Const; |
| 15 | 15 | const BigIntMutable = std.math.big.int.Mutable; |
| 16 | 16 | const Target = std.Target; |
| 17 | 17 | const Ast = std.zig.Ast; |
| 18 | const Writer = std.io.Writer; | |
| 18 | const Writer = std.Io.Writer; | |
| 19 | 19 | |
| 20 | 20 | const Zcu = @This(); |
| 21 | 21 | const Compilation = @import("Compilation.zig"); |
| ... | ... | @@ -2872,7 +2872,7 @@ pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir { |
| 2872 | 2872 | }; |
| 2873 | 2873 | } |
| 2874 | 2874 | |
| 2875 | pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *std.io.Reader) !Zir { | |
| 2875 | pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *std.Io.Reader) !Zir { | |
| 2876 | 2876 | var instructions: std.MultiArrayList(Zir.Inst) = .{}; |
| 2877 | 2877 | errdefer instructions.deinit(gpa); |
| 2878 | 2878 | |
| ... | ... | @@ -2989,7 +2989,7 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir |
| 2989 | 2989 | }; |
| 2990 | 2990 | } |
| 2991 | 2991 | |
| 2992 | pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_br: *std.io.Reader) !Zoir { | |
| 2992 | pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_br: *std.Io.Reader) !Zoir { | |
| 2993 | 2993 | var zoir: Zoir = .{ |
| 2994 | 2994 | .nodes = .empty, |
| 2995 | 2995 | .extra = &.{}, |
| ... | ... | @@ -4318,7 +4318,7 @@ const FormatAnalUnit = struct { |
| 4318 | 4318 | zcu: *Zcu, |
| 4319 | 4319 | }; |
| 4320 | 4320 | |
| 4321 | fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 4321 | fn formatAnalUnit(data: FormatAnalUnit, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 4322 | 4322 | const zcu = data.zcu; |
| 4323 | 4323 | const ip = &zcu.intern_pool; |
| 4324 | 4324 | switch (data.unit.unwrap()) { |
| ... | ... | @@ -4344,7 +4344,7 @@ fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Er |
| 4344 | 4344 | |
| 4345 | 4345 | const FormatDependee = struct { dependee: InternPool.Dependee, zcu: *Zcu }; |
| 4346 | 4346 | |
| 4347 | fn formatDependee(data: FormatDependee, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 4347 | fn formatDependee(data: FormatDependee, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 4348 | 4348 | const zcu = data.zcu; |
| 4349 | 4349 | const ip = &zcu.intern_pool; |
| 4350 | 4350 | switch (data.dependee) { |
src/arch/riscv64/CodeGen.zig+5-5| ... | ... | @@ -566,7 +566,7 @@ const InstTracking = struct { |
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
| 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 { | |
| 570 | 570 | if (!std.meta.eql(inst_tracking.long, inst_tracking.short)) try writer.print("|{}| ", .{inst_tracking.long}); |
| 571 | 571 | try writer.print("{}", .{inst_tracking.short}); |
| 572 | 572 | } |
| ... | ... | @@ -932,7 +932,7 @@ const FormatWipMirData = struct { |
| 932 | 932 | func: *Func, |
| 933 | 933 | inst: Mir.Inst.Index, |
| 934 | 934 | }; |
| 935 | fn formatWipMir(data: FormatWipMirData, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 935 | fn formatWipMir(data: FormatWipMirData, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 936 | 936 | const pt = data.func.pt; |
| 937 | 937 | const comp = pt.zcu.comp; |
| 938 | 938 | var lower: Lower = .{ |
| ... | ... | @@ -980,7 +980,7 @@ const FormatNavData = struct { |
| 980 | 980 | ip: *const InternPool, |
| 981 | 981 | nav_index: InternPool.Nav.Index, |
| 982 | 982 | }; |
| 983 | fn formatNav(data: FormatNavData, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 983 | fn formatNav(data: FormatNavData, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 984 | 984 | try writer.print("{f}", .{data.ip.getNav(data.nav_index).fqn.fmt(data.ip)}); |
| 985 | 985 | } |
| 986 | 986 | fn fmtNav(nav_index: InternPool.Nav.Index, ip: *const InternPool) std.fmt.Formatter(FormatNavData, formatNav) { |
| ... | ... | @@ -994,7 +994,7 @@ const FormatAirData = struct { |
| 994 | 994 | func: *Func, |
| 995 | 995 | inst: Air.Inst.Index, |
| 996 | 996 | }; |
| 997 | fn formatAir(data: FormatAirData, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 997 | fn formatAir(data: FormatAirData, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 998 | 998 | // Not acceptable implementation because it ignores `writer`: |
| 999 | 999 | //data.func.air.dumpInst(data.inst, data.func.pt, data.func.liveness); |
| 1000 | 1000 | _ = data; |
| ... | ... | @@ -1008,7 +1008,7 @@ fn fmtAir(func: *Func, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, fo |
| 1008 | 1008 | const FormatTrackingData = struct { |
| 1009 | 1009 | func: *Func, |
| 1010 | 1010 | }; |
| 1011 | fn formatTracking(data: FormatTrackingData, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 1011 | fn formatTracking(data: FormatTrackingData, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 1012 | 1012 | var it = data.func.inst_tracking.iterator(); |
| 1013 | 1013 | while (it.next()) |entry| try writer.print("\n%{d} = {f}", .{ entry.key_ptr.*, entry.value_ptr.* }); |
| 1014 | 1014 | } |
src/arch/riscv64/Mir.zig+1-1| ... | ... | @@ -92,7 +92,7 @@ pub const Inst = struct { |
| 92 | 92 | }, |
| 93 | 93 | }; |
| 94 | 94 | |
| 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 { | |
| 96 | 96 | try writer.print("Tag: {s}, Data: {s}", .{ @tagName(inst.tag), @tagName(inst.data) }); |
| 97 | 97 | } |
| 98 | 98 | }; |
src/arch/x86_64/CodeGen.zig+2-2| ... | ... | @@ -6,7 +6,7 @@ const log = std.log.scoped(.codegen); |
| 6 | 6 | const tracking_log = std.log.scoped(.tracking); |
| 7 | 7 | const verbose_tracking_log = std.log.scoped(.verbose_tracking); |
| 8 | 8 | const wip_mir_log = std.log.scoped(.wip_mir); |
| 9 | const Writer = std.io.Writer; | |
| 9 | const Writer = std.Io.Writer; | |
| 10 | 10 | |
| 11 | 11 | const Air = @import("../../Air.zig"); |
| 12 | 12 | const Allocator = std.mem.Allocator; |
| ... | ... | @@ -1102,7 +1102,7 @@ const FormatAirData = struct { |
| 1102 | 1102 | self: *CodeGen, |
| 1103 | 1103 | inst: Air.Inst.Index, |
| 1104 | 1104 | }; |
| 1105 | fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void { | |
| 1105 | fn formatAir(data: FormatAirData, w: *Writer) Writer.Error!void { | |
| 1106 | 1106 | data.self.air.writeInst(w, data.inst, data.self.pt, data.self.liveness); |
| 1107 | 1107 | } |
| 1108 | 1108 | fn 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 { |
| 287 | 287 | |
| 288 | 288 | fn parsePrefixes(dis: *Disassembler) !Prefixes { |
| 289 | 289 | 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..]); | |
| 292 | 291 | |
| 293 | 292 | var res: Prefixes = .{}; |
| 294 | 293 | |
| 295 | 294 | while (true) { |
| 296 | const next_byte = try reader.readByte(); | |
| 295 | const next_byte = try reader.takeByte(); | |
| 297 | 296 | dis.pos += 1; |
| 298 | 297 | |
| 299 | 298 | switch (next_byte) { |
| ... | ... | @@ -341,12 +340,11 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding { |
| 341 | 340 | const o_mask: u8 = 0b1111_1000; |
| 342 | 341 | |
| 343 | 342 | 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..]); | |
| 346 | 344 | |
| 347 | 345 | comptime var opc_count = 0; |
| 348 | 346 | inline while (opc_count < 3) : (opc_count += 1) { |
| 349 | const byte = try reader.readByte(); | |
| 347 | const byte = try reader.takeByte(); | |
| 350 | 348 | opcode[opc_count] = byte; |
| 351 | 349 | dis.pos += 1; |
| 352 | 350 | |
| ... | ... | @@ -410,11 +408,11 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { |
| 410 | 408 | } |
| 411 | 409 | |
| 412 | 410 | fn 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); | |
| 418 | 416 | } |
| 419 | 417 | |
| 420 | 418 | const 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 |
| 698 | 698 | const gpa = comp.gpa; |
| 699 | 699 | const start_offset: u32 = @intCast(emit.code.items.len); |
| 700 | 700 | { |
| 701 | var aw: std.io.Writer.Allocating = .fromArrayList(gpa, emit.code); | |
| 701 | var aw: std.Io.Writer.Allocating = .fromArrayList(gpa, emit.code); | |
| 702 | 702 | defer emit.code.* = aw.toArrayList(); |
| 703 | 703 | lowered_inst.encode(&aw.writer, .{}) catch |err| switch (err) { |
| 704 | 704 | error.WriteFailed => return error.OutOfMemory, |
src/arch/x86_64/Encoding.zig+2-2| ... | ... | @@ -158,7 +158,7 @@ pub fn modRmExt(encoding: Encoding) u3 { |
| 158 | 158 | }; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | pub fn format(encoding: Encoding, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 161 | pub fn format(encoding: Encoding, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 162 | 162 | var opc = encoding.opcode(); |
| 163 | 163 | if (encoding.data.mode.isVex()) { |
| 164 | 164 | try writer.writeAll("VEX."); |
| ... | ... | @@ -1016,7 +1016,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op |
| 1016 | 1016 | // By using a buffer with maximum length of encoded instruction, we can use |
| 1017 | 1017 | // the `end` field of the Writer for the count. |
| 1018 | 1018 | var buf: [16]u8 = undefined; |
| 1019 | var trash: std.io.Writer.Discarding = .init(&buf); | |
| 1019 | var trash: std.Io.Writer.Discarding = .init(&buf); | |
| 1020 | 1020 | inst.encode(&trash.writer, .{ |
| 1021 | 1021 | .allow_frame_locs = true, |
| 1022 | 1022 | .allow_symbols = true, |
src/arch/x86_64/bits.zig+2-2| ... | ... | @@ -827,7 +827,7 @@ pub const Memory = struct { |
| 827 | 827 | }; |
| 828 | 828 | } |
| 829 | 829 | |
| 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 { | |
| 831 | 831 | if (s == .none) return; |
| 832 | 832 | try writer.writeAll(@tagName(s)); |
| 833 | 833 | switch (s) { |
| ... | ... | @@ -892,7 +892,7 @@ pub const Immediate = union(enum) { |
| 892 | 892 | return .{ .signed = x }; |
| 893 | 893 | } |
| 894 | 894 | |
| 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 { | |
| 896 | 896 | switch (imm) { |
| 897 | 897 | inline else => |int| try writer.print("{d}", .{int}), |
| 898 | 898 | .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; |
| 3 | 3 | const log = std.log.scoped(.x86_64_encoder); |
| 4 | 4 | const math = std.math; |
| 5 | 5 | const testing = std.testing; |
| 6 | const Writer = std.io.Writer; | |
| 6 | const Writer = std.Io.Writer; | |
| 7 | 7 | |
| 8 | 8 | const bits = @import("bits.zig"); |
| 9 | 9 | const Encoding = @import("Encoding.zig"); |
src/codegen/c.zig+10-10| ... | ... | @@ -4,7 +4,7 @@ const assert = std.debug.assert; |
| 4 | 4 | const mem = std.mem; |
| 5 | 5 | const log = std.log.scoped(.c); |
| 6 | 6 | const Allocator = mem.Allocator; |
| 7 | const Writer = std.io.Writer; | |
| 7 | const Writer = std.Io.Writer; | |
| 8 | 8 | |
| 9 | 9 | const dev = @import("../dev.zig"); |
| 10 | 10 | const link = @import("../link.zig"); |
| ... | ... | @@ -345,15 +345,15 @@ fn isReservedIdent(ident: []const u8) bool { |
| 345 | 345 | } else return reserved_idents.has(ident); |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | fn formatIdentSolo(ident: []const u8, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 348 | fn formatIdentSolo(ident: []const u8, w: *Writer) Writer.Error!void { | |
| 349 | 349 | return formatIdentOptions(ident, w, true); |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | fn formatIdentUnsolo(ident: []const u8, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 352 | fn formatIdentUnsolo(ident: []const u8, w: *Writer) Writer.Error!void { | |
| 353 | 353 | return formatIdentOptions(ident, w, false); |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | fn formatIdentOptions(ident: []const u8, w: *std.io.Writer, solo: bool) std.io.Writer.Error!void { | |
| 356 | fn formatIdentOptions(ident: []const u8, w: *Writer, solo: bool) Writer.Error!void { | |
| 357 | 357 | if (solo and isReservedIdent(ident)) { |
| 358 | 358 | try w.writeAll("zig_e_"); |
| 359 | 359 | } |
| ... | ... | @@ -384,7 +384,7 @@ const CTypePoolStringFormatData = struct { |
| 384 | 384 | ctype_pool: *const CType.Pool, |
| 385 | 385 | solo: bool, |
| 386 | 386 | }; |
| 387 | fn formatCTypePoolString(data: CTypePoolStringFormatData, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 387 | fn formatCTypePoolString(data: CTypePoolStringFormatData, w: *Writer) Writer.Error!void { | |
| 388 | 388 | if (data.ctype_pool_string.toSlice(data.ctype_pool)) |slice| |
| 389 | 389 | try formatIdentOptions(slice, w, data.solo) |
| 390 | 390 | else |
| ... | ... | @@ -711,8 +711,8 @@ pub const Function = struct { |
| 711 | 711 | /// It is not available when generating .h file. |
| 712 | 712 | pub const Object = struct { |
| 713 | 713 | dg: DeclGen, |
| 714 | code_header: std.io.Writer.Allocating, | |
| 715 | code: std.io.Writer.Allocating, | |
| 714 | code_header: Writer.Allocating, | |
| 715 | code: Writer.Allocating, | |
| 716 | 716 | indent_counter: usize, |
| 717 | 717 | |
| 718 | 718 | const indent_width = 1; |
| ... | ... | @@ -748,7 +748,7 @@ pub const DeclGen = struct { |
| 748 | 748 | pass: Pass, |
| 749 | 749 | is_naked_fn: bool, |
| 750 | 750 | expected_block: ?u32, |
| 751 | fwd_decl: std.io.Writer.Allocating, | |
| 751 | fwd_decl: Writer.Allocating, | |
| 752 | 752 | error_msg: ?*Zcu.ErrorMsg, |
| 753 | 753 | ctype_pool: CType.Pool, |
| 754 | 754 | scratch: std.ArrayListUnmanaged(u32), |
| ... | ... | @@ -8287,7 +8287,7 @@ const FormatStringContext = struct { |
| 8287 | 8287 | sentinel: ?u8, |
| 8288 | 8288 | }; |
| 8289 | 8289 | |
| 8290 | fn formatStringLiteral(data: FormatStringContext, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 8290 | fn formatStringLiteral(data: FormatStringContext, w: *Writer) Writer.Error!void { | |
| 8291 | 8291 | var literal: StringLiteral = .init(w, data.str.len + @intFromBool(data.sentinel != null)); |
| 8292 | 8292 | try literal.start(); |
| 8293 | 8293 | for (data.str) |c| try literal.writeChar(c); |
| ... | ... | @@ -8314,7 +8314,7 @@ const FormatIntLiteralContext = struct { |
| 8314 | 8314 | base: u8, |
| 8315 | 8315 | case: std.fmt.Case, |
| 8316 | 8316 | }; |
| 8317 | fn formatIntLiteral(data: FormatIntLiteralContext, w: *std.io.Writer) std.io.Writer.Error!void { | |
| 8317 | fn formatIntLiteral(data: FormatIntLiteralContext, w: *Writer) Writer.Error!void { | |
| 8318 | 8318 | const pt = data.dg.pt; |
| 8319 | 8319 | const zcu = pt.zcu; |
| 8320 | 8320 | const target = &data.dg.mod.resolved_target.result; |
src/codegen/c/Type.zig+1-1| ... | ... | @@ -3396,7 +3396,7 @@ pub const AlignAs = packed struct { |
| 3396 | 3396 | |
| 3397 | 3397 | const std = @import("std"); |
| 3398 | 3398 | const assert = std.debug.assert; |
| 3399 | const Writer = std.io.Writer; | |
| 3399 | const Writer = std.Io.Writer; | |
| 3400 | 3400 | |
| 3401 | 3401 | const CType = @This(); |
| 3402 | 3402 | const InternPool = @import("../../InternPool.zig"); |
src/codegen/llvm.zig+1-1| ... | ... | @@ -2684,7 +2684,7 @@ pub const Object = struct { |
| 2684 | 2684 | } |
| 2685 | 2685 | |
| 2686 | 2686 | fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 { |
| 2687 | var aw: std.io.Writer.Allocating = .init(o.gpa); | |
| 2687 | var aw: std.Io.Writer.Allocating = .init(o.gpa); | |
| 2688 | 2688 | defer aw.deinit(); |
| 2689 | 2689 | ty.print(&aw.writer, pt) catch |err| switch (err) { |
| 2690 | 2690 | 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 { |
| 1211 | 1211 | // Turn a Zig type's name into a cache reference. |
| 1212 | 1212 | fn resolveTypeName(cg: *CodeGen, ty: Type) ![]const u8 { |
| 1213 | 1213 | const gpa = cg.module.gpa; |
| 1214 | var aw: std.io.Writer.Allocating = .init(gpa); | |
| 1214 | var aw: std.Io.Writer.Allocating = .init(gpa); | |
| 1215 | 1215 | defer aw.deinit(); |
| 1216 | 1216 | ty.print(&aw.writer, cg.pt) catch |err| switch (err) { |
| 1217 | 1217 | error.WriteFailed => return error.OutOfMemory, |
src/codegen/spirv/spec.zig+1-1| ... | ... | @@ -18,7 +18,7 @@ pub const Id = enum(Word) { |
| 18 | 18 | none, |
| 19 | 19 | _, |
| 20 | 20 | |
| 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 { | |
| 22 | 22 | switch (self) { |
| 23 | 23 | .none => try writer.writeAll("(none)"), |
| 24 | 24 | else => try writer.print("%{d}", .{@intFromEnum(self)}), |
src/crash_report.zig-1| ... | ... | @@ -2,7 +2,6 @@ const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const build_options = @import("build_options"); |
| 4 | 4 | const debug = std.debug; |
| 5 | const io = std.io; | |
| 6 | 5 | const print_zir = @import("print_zir.zig"); |
| 7 | 6 | const windows = std.os.windows; |
| 8 | 7 | const posix = std.posix; |
src/libs/mingw.zig+1-1| ... | ... | @@ -325,7 +325,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 325 | 325 | |
| 326 | 326 | for (aro_comp.diagnostics.list.items) |diagnostic| { |
| 327 | 327 | 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())); | |
| 329 | 329 | return error.AroPreprocessorFailed; |
| 330 | 330 | } |
| 331 | 331 | } |
src/link/C.zig+4-4| ... | ... | @@ -348,7 +348,7 @@ pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedIn |
| 348 | 348 | _ = ti_id; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | fn abiDefines(w: *std.io.Writer, target: *const std.Target) !void { | |
| 351 | fn abiDefines(w: *std.Io.Writer, target: *const std.Target) !void { | |
| 352 | 352 | switch (target.abi) { |
| 353 | 353 | .msvc, .itanium => try w.writeAll("#define ZIG_TARGET_ABI_MSVC\n"), |
| 354 | 354 | else => {}, |
| ... | ... | @@ -400,7 +400,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P |
| 400 | 400 | }; |
| 401 | 401 | defer f.deinit(gpa); |
| 402 | 402 | |
| 403 | var abi_defines_aw: std.io.Writer.Allocating = .init(gpa); | |
| 403 | var abi_defines_aw: std.Io.Writer.Allocating = .init(gpa); | |
| 404 | 404 | defer abi_defines_aw.deinit(); |
| 405 | 405 | abiDefines(&abi_defines_aw.writer, zcu.getTarget()) catch |err| switch (err) { |
| 406 | 406 | error.WriteFailed => return error.OutOfMemory, |
| ... | ... | @@ -415,7 +415,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P |
| 415 | 415 | const ctypes_index = f.all_buffers.items.len; |
| 416 | 416 | f.all_buffers.items.len += 1; |
| 417 | 417 | |
| 418 | var asm_aw: std.io.Writer.Allocating = .init(gpa); | |
| 418 | var asm_aw: std.Io.Writer.Allocating = .init(gpa); | |
| 419 | 419 | defer asm_aw.deinit(); |
| 420 | 420 | codegen.genGlobalAsm(zcu, &asm_aw.writer) catch |err| switch (err) { |
| 421 | 421 | error.WriteFailed => return error.OutOfMemory, |
| ... | ... | @@ -582,7 +582,7 @@ fn flushCTypes( |
| 582 | 582 | try global_from_decl_map.ensureTotalCapacity(gpa, decl_ctype_pool.items.len); |
| 583 | 583 | defer global_from_decl_map.clearRetainingCapacity(); |
| 584 | 584 | |
| 585 | var ctypes_aw: std.io.Writer.Allocating = .fromArrayList(gpa, &f.ctypes); | |
| 585 | var ctypes_aw: std.Io.Writer.Allocating = .fromArrayList(gpa, &f.ctypes); | |
| 586 | 586 | const ctypes_bw = &ctypes_aw.writer; |
| 587 | 587 | defer f.ctypes = ctypes_aw.toArrayList(); |
| 588 | 588 |
src/link/Coff.zig+1-1| ... | ... | @@ -3039,7 +3039,7 @@ const ImportTable = struct { |
| 3039 | 3039 | itab: ImportTable, |
| 3040 | 3040 | ctx: Context, |
| 3041 | 3041 | |
| 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 { | |
| 3043 | 3043 | const lib_name = f.ctx.coff.temp_strtab.getAssumeExists(f.ctx.name_off); |
| 3044 | 3044 | const base_vaddr = getBaseAddress(f.ctx); |
| 3045 | 3045 | 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 |
| 3869 | 3869 | } }; |
| 3870 | 3870 | } |
| 3871 | 3871 | |
| 3872 | fn formatShdr(ctx: FormatShdr, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 3872 | fn formatShdr(ctx: FormatShdr, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 3873 | 3873 | const shdr = ctx.shdr; |
| 3874 | 3874 | try writer.print("{s} : @{x} ({x}) : align({x}) : size({x}) : entsize({x}) : flags({f})", .{ |
| 3875 | 3875 | 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) { |
| 3883 | 3883 | return .{ .data = sh_flags }; |
| 3884 | 3884 | } |
| 3885 | 3885 | |
| 3886 | fn formatShdrFlags(sh_flags: u64, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 3886 | fn formatShdrFlags(sh_flags: u64, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 3887 | 3887 | if (elf.SHF_WRITE & sh_flags != 0) { |
| 3888 | 3888 | try writer.writeAll("W"); |
| 3889 | 3889 | } |
| ... | ... | @@ -3940,7 +3940,7 @@ fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Formatter(FormatPhdr, forma |
| 3940 | 3940 | } }; |
| 3941 | 3941 | } |
| 3942 | 3942 | |
| 3943 | fn formatPhdr(ctx: FormatPhdr, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 3943 | fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 3944 | 3944 | const phdr = ctx.phdr; |
| 3945 | 3945 | const write = phdr.p_flags & elf.PF_W != 0; |
| 3946 | 3946 | const read = phdr.p_flags & elf.PF_R != 0; |
| ... | ... | @@ -3971,7 +3971,7 @@ pub fn dumpState(self: *Elf) std.fmt.Formatter(*Elf, fmtDumpState) { |
| 3971 | 3971 | return .{ .data = self }; |
| 3972 | 3972 | } |
| 3973 | 3973 | |
| 3974 | fn fmtDumpState(self: *Elf, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 3974 | fn fmtDumpState(self: *Elf, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 3975 | 3975 | const shared_objects = self.shared_objects.values(); |
| 3976 | 3976 | |
| 3977 | 3977 | if (self.zigObjectPtr()) |zig_object| { |
| ... | ... | @@ -4189,7 +4189,7 @@ pub const Ref = struct { |
| 4189 | 4189 | return ref.index == other.index and ref.file == other.file; |
| 4190 | 4190 | } |
| 4191 | 4191 | |
| 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 { | |
| 4193 | 4193 | try writer.print("ref({d},{d})", .{ ref.index, ref.file }); |
| 4194 | 4194 | } |
| 4195 | 4195 | }; |
src/link/Elf/Archive.zig+2-2| ... | ... | @@ -204,7 +204,7 @@ pub const ArSymtab = struct { |
| 204 | 204 | ar: ArSymtab, |
| 205 | 205 | elf_file: *Elf, |
| 206 | 206 | |
| 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 { | |
| 208 | 208 | const ar = f.ar; |
| 209 | 209 | const elf_file = f.elf_file; |
| 210 | 210 | for (ar.symtab.items, 0..) |entry, i| { |
| ... | ... | @@ -259,7 +259,7 @@ pub const ArStrtab = struct { |
| 259 | 259 | try writer.writeAll(ar.buffer.items); |
| 260 | 260 | } |
| 261 | 261 | |
| 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 { | |
| 263 | 263 | try writer.print("{f}", .{std.ascii.hexEscape(ar.buffer.items, .lower)}); |
| 264 | 264 | } |
| 265 | 265 | }; |
src/link/Elf/AtomList.zig+1-1| ... | ... | @@ -170,7 +170,7 @@ const Format = struct { |
| 170 | 170 | atom_list: AtomList, |
| 171 | 171 | elf_file: *Elf, |
| 172 | 172 | |
| 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 { | |
| 174 | 174 | const list = f.atom_list; |
| 175 | 175 | try writer.print("list : @{x} : shdr({d}) : align({x}) : size({x})", .{ |
| 176 | 176 | list.address(f.elf_file), |
src/link/Elf/LinkerDefined.zig+1-1| ... | ... | @@ -448,7 +448,7 @@ const Format = struct { |
| 448 | 448 | self: *LinkerDefined, |
| 449 | 449 | elf_file: *Elf, |
| 450 | 450 | |
| 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 { | |
| 452 | 452 | const self = ctx.self; |
| 453 | 453 | const elf_file = ctx.elf_file; |
| 454 | 454 | try writer.writeAll(" globals\n"); |
src/link/Elf/Merge.zig+2-2| ... | ... | @@ -168,7 +168,7 @@ pub const Section = struct { |
| 168 | 168 | msec: Section, |
| 169 | 169 | elf_file: *Elf, |
| 170 | 170 | |
| 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 { | |
| 172 | 172 | const msec = f.msec; |
| 173 | 173 | const elf_file = f.elf_file; |
| 174 | 174 | try writer.print("{s} : @{x} : size({x}) : align({x}) : entsize({x}) : type({x}) : flags({x})\n", .{ |
| ... | ... | @@ -222,7 +222,7 @@ pub const Subsection = struct { |
| 222 | 222 | msub: Subsection, |
| 223 | 223 | elf_file: *Elf, |
| 224 | 224 | |
| 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 { | |
| 226 | 226 | const msub = ctx.msub; |
| 227 | 227 | const elf_file = ctx.elf_file; |
| 228 | 228 | try writer.print("@{x} : align({x}) : size({x})", .{ |
src/link/Elf/Object.zig+6-6| ... | ... | @@ -1442,7 +1442,7 @@ const Format = struct { |
| 1442 | 1442 | object: *Object, |
| 1443 | 1443 | elf_file: *Elf, |
| 1444 | 1444 | |
| 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 { | |
| 1446 | 1446 | const object = f.object; |
| 1447 | 1447 | const elf_file = f.elf_file; |
| 1448 | 1448 | try writer.writeAll(" locals\n"); |
| ... | ... | @@ -1461,7 +1461,7 @@ const Format = struct { |
| 1461 | 1461 | } |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 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 { | |
| 1465 | 1465 | const object = f.object; |
| 1466 | 1466 | try writer.writeAll(" atoms\n"); |
| 1467 | 1467 | for (object.atoms_indexes.items) |atom_index| { |
| ... | ... | @@ -1470,7 +1470,7 @@ const Format = struct { |
| 1470 | 1470 | } |
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 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 { | |
| 1474 | 1474 | const object = f.object; |
| 1475 | 1475 | try writer.writeAll(" cies\n"); |
| 1476 | 1476 | for (object.cies.items, 0..) |cie, i| { |
| ... | ... | @@ -1478,7 +1478,7 @@ const Format = struct { |
| 1478 | 1478 | } |
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 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 { | |
| 1482 | 1482 | const object = f.object; |
| 1483 | 1483 | try writer.writeAll(" fdes\n"); |
| 1484 | 1484 | for (object.fdes.items, 0..) |fde, i| { |
| ... | ... | @@ -1486,7 +1486,7 @@ const Format = struct { |
| 1486 | 1486 | } |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 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 { | |
| 1490 | 1490 | const object = f.object; |
| 1491 | 1491 | const elf_file = f.elf_file; |
| 1492 | 1492 | try writer.writeAll(" groups\n"); |
| ... | ... | @@ -1536,7 +1536,7 @@ pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) { |
| 1536 | 1536 | return .{ .data = self }; |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 1539 | fn formatPath(object: Object, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 1540 | 1540 | if (object.archive) |ar| { |
| 1541 | 1541 | try writer.print("{f}({f})", .{ ar.path, object.path }); |
| 1542 | 1542 | } else { |
src/link/Elf/SharedObject.zig+1-1| ... | ... | @@ -520,7 +520,7 @@ const Format = struct { |
| 520 | 520 | shared: SharedObject, |
| 521 | 521 | elf_file: *Elf, |
| 522 | 522 | |
| 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 { | |
| 524 | 524 | const shared = f.shared; |
| 525 | 525 | const elf_file = f.elf_file; |
| 526 | 526 | try writer.writeAll(" globals\n"); |
src/link/Elf/Symbol.zig+2-2| ... | ... | @@ -320,7 +320,7 @@ const Format = struct { |
| 320 | 320 | symbol: Symbol, |
| 321 | 321 | elf_file: *Elf, |
| 322 | 322 | |
| 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 { | |
| 324 | 324 | const elf_file = f.elf_file; |
| 325 | 325 | const symbol = f.symbol; |
| 326 | 326 | try writer.writeAll(symbol.name(elf_file)); |
| ... | ... | @@ -335,7 +335,7 @@ const Format = struct { |
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
| 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 { | |
| 339 | 339 | const symbol = f.symbol; |
| 340 | 340 | const elf_file = f.elf_file; |
| 341 | 341 | try writer.print("%{d} : {f} : @{x}", .{ |
src/link/Elf/Thunk.zig+1-1| ... | ... | @@ -76,7 +76,7 @@ const Format = struct { |
| 76 | 76 | thunk: Thunk, |
| 77 | 77 | elf_file: *Elf, |
| 78 | 78 | |
| 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 { | |
| 80 | 80 | const thunk = f.thunk; |
| 81 | 81 | const elf_file = f.elf_file; |
| 82 | 82 | 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 { |
| 2201 | 2201 | self: *ZigObject, |
| 2202 | 2202 | elf_file: *Elf, |
| 2203 | 2203 | |
| 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 { | |
| 2205 | 2205 | const self = f.self; |
| 2206 | 2206 | const elf_file = f.elf_file; |
| 2207 | 2207 | try writer.writeAll(" locals\n"); |
| ... | ... | @@ -2216,7 +2216,7 @@ const Format = struct { |
| 2216 | 2216 | } |
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 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 { | |
| 2220 | 2220 | try writer.writeAll(" atoms\n"); |
| 2221 | 2221 | for (f.self.atoms_indexes.items) |atom_index| { |
| 2222 | 2222 | 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 { |
| 58 | 58 | fde: Fde, |
| 59 | 59 | elf_file: *Elf, |
| 60 | 60 | |
| 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 { | |
| 62 | 62 | const fde = f.fde; |
| 63 | 63 | const elf_file = f.elf_file; |
| 64 | 64 | const base_addr = fde.address(elf_file); |
| ... | ... | @@ -141,7 +141,7 @@ pub const Cie = struct { |
| 141 | 141 | cie: Cie, |
| 142 | 142 | elf_file: *Elf, |
| 143 | 143 | |
| 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 { | |
| 145 | 145 | const cie = f.cie; |
| 146 | 146 | const elf_file = f.elf_file; |
| 147 | 147 | const base_addr = cie.address(elf_file); |
| ... | ... | @@ -167,15 +167,14 @@ pub const Iterator = struct { |
| 167 | 167 | pub fn next(it: *Iterator) !?Record { |
| 168 | 168 | if (it.pos >= it.data.len) return null; |
| 169 | 169 | |
| 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..]); | |
| 172 | 171 | |
| 173 | const size = try reader.readInt(u32, .little); | |
| 172 | const size = try reader.takeInt(u32, .little); | |
| 174 | 173 | if (size == 0) return null; |
| 175 | 174 | if (size == 0xFFFFFFFF) @panic("TODO"); |
| 176 | 175 | |
| 177 | const id = try reader.readInt(u32, .little); | |
| 178 | const record = Record{ | |
| 176 | const id = try reader.takeInt(u32, .little); | |
| 177 | const record: Record = .{ | |
| 179 | 178 | .tag = if (id == 0) .cie else .fde, |
| 180 | 179 | .offset = it.pos, |
| 181 | 180 | .size = size, |
src/link/Elf/file.zig+1-1| ... | ... | @@ -14,7 +14,7 @@ pub const File = union(enum) { |
| 14 | 14 | return .{ .data = file }; |
| 15 | 15 | } |
| 16 | 16 | |
| 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 { | |
| 18 | 18 | switch (file) { |
| 19 | 19 | .zig_object => |zo| try writer.writeAll(zo.basename), |
| 20 | 20 | .linker_defined => try writer.writeAll("(linker defined)"), |
src/link/Elf/gc.zig+1-1| ... | ... | @@ -169,7 +169,7 @@ const Level = struct { |
| 169 | 169 | self.value += 1; |
| 170 | 170 | } |
| 171 | 171 | |
| 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 { | |
| 173 | 173 | try w.splatByteAll(' ', self.value); |
| 174 | 174 | } |
| 175 | 175 | }; |
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 |
| 160 | 160 | } }; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 163 | fn formatRelocType(ctx: FormatRelocTypeCtx, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 164 | 164 | const r_type = ctx.r_type; |
| 165 | 165 | switch (ctx.cpu_arch) { |
| 166 | 166 | .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 { |
| 605 | 605 | got: GotSection, |
| 606 | 606 | elf_file: *Elf, |
| 607 | 607 | |
| 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 { | |
| 609 | 609 | const got = f.got; |
| 610 | 610 | const elf_file = f.elf_file; |
| 611 | 611 | try writer.writeAll("GOT\n"); |
| ... | ... | @@ -741,7 +741,7 @@ pub const PltSection = struct { |
| 741 | 741 | plt: PltSection, |
| 742 | 742 | elf_file: *Elf, |
| 743 | 743 | |
| 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 { | |
| 745 | 745 | const plt = f.plt; |
| 746 | 746 | const elf_file = f.elf_file; |
| 747 | 747 | try writer.writeAll("PLT\n"); |
src/link/Lld.zig+4-2| ... | ... | @@ -1650,7 +1650,8 @@ fn spawnLld( |
| 1650 | 1650 | child.stderr_behavior = .Pipe; |
| 1651 | 1651 | |
| 1652 | 1652 | 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); | |
| 1654 | 1655 | break :term child.wait(); |
| 1655 | 1656 | }) catch |first_err| term: { |
| 1656 | 1657 | const err = switch (first_err) { |
| ... | ... | @@ -1699,7 +1700,8 @@ fn spawnLld( |
| 1699 | 1700 | rsp_child.stderr_behavior = .Pipe; |
| 1700 | 1701 | |
| 1701 | 1702 | 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); | |
| 1703 | 1705 | break :term rsp_child.wait() catch |err| break :err err; |
| 1704 | 1706 | } |
| 1705 | 1707 | }, |
src/link/MachO.zig+1-1| ... | ... | @@ -4361,7 +4361,7 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi |
| 4361 | 4361 | // The file/property is also available with vendored libc. |
| 4362 | 4362 | fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 { |
| 4363 | 4363 | const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" }); |
| 4364 | const contents = try fs.cwd().readFileAlloc(arena, sdk_path, std.math.maxInt(u16)); | |
| 4364 | const contents = try fs.cwd().readFileAlloc(sdk_path, arena, .limited(std.math.maxInt(u16))); | |
| 4365 | 4365 | const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{}); |
| 4366 | 4366 | if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string; |
| 4367 | 4367 | return error.SdkVersionFailure; |
src/link/MachO/CodeSignature.zig+1-3| ... | ... | @@ -245,9 +245,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void { |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void { |
| 248 | const file = try fs.cwd().openFile(path, .{}); | |
| 249 | defer file.close(); | |
| 250 | const inner = try file.readToEndAlloc(allocator, std.math.maxInt(u32)); | |
| 248 | const inner = try fs.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32))); | |
| 251 | 249 | self.entitlements = .{ .inner = inner }; |
| 252 | 250 | } |
| 253 | 251 |
src/link/MachO/Dylib.zig+1-1| ... | ... | @@ -914,7 +914,7 @@ const math = std.math; |
| 914 | 914 | const mem = std.mem; |
| 915 | 915 | const Allocator = mem.Allocator; |
| 916 | 916 | const Path = std.Build.Cache.Path; |
| 917 | const Writer = std.io.Writer; | |
| 917 | const Writer = std.Io.Writer; | |
| 918 | 918 | |
| 919 | 919 | const Dylib = @This(); |
| 920 | 920 | const File = @import("file.zig").File; |
src/link/MachO/InternalObject.zig+1-1| ... | ... | @@ -894,7 +894,7 @@ const macho = std.macho; |
| 894 | 894 | const mem = std.mem; |
| 895 | 895 | const std = @import("std"); |
| 896 | 896 | const trace = @import("../../tracy.zig").trace; |
| 897 | const Writer = std.io.Writer; | |
| 897 | const Writer = std.Io.Writer; | |
| 898 | 898 | |
| 899 | 899 | const Allocator = std.mem.Allocator; |
| 900 | 900 | const Atom = @import("Atom.zig"); |
src/link/MachO/Object.zig+1-1| ... | ... | @@ -3094,7 +3094,7 @@ const math = std.math; |
| 3094 | 3094 | const mem = std.mem; |
| 3095 | 3095 | const Path = std.Build.Cache.Path; |
| 3096 | 3096 | const Allocator = std.mem.Allocator; |
| 3097 | const Writer = std.io.Writer; | |
| 3097 | const Writer = std.Io.Writer; | |
| 3098 | 3098 | |
| 3099 | 3099 | const eh_frame = @import("eh_frame.zig"); |
| 3100 | 3100 | const trace = @import("../../tracy.zig").trace; |
src/link/MachO/Relocation.zig+1-1| ... | ... | @@ -162,7 +162,7 @@ const std = @import("std"); |
| 162 | 162 | const assert = std.debug.assert; |
| 163 | 163 | const macho = std.macho; |
| 164 | 164 | const math = std.math; |
| 165 | const Writer = std.io.Writer; | |
| 165 | const Writer = std.Io.Writer; | |
| 166 | 166 | |
| 167 | 167 | const Atom = @import("Atom.zig"); |
| 168 | 168 | const MachO = @import("../MachO.zig"); |
src/link/MachO/Symbol.zig+1-1| ... | ... | @@ -417,7 +417,7 @@ pub const Index = u32; |
| 417 | 417 | const assert = std.debug.assert; |
| 418 | 418 | const macho = std.macho; |
| 419 | 419 | const std = @import("std"); |
| 420 | const Writer = std.io.Writer; | |
| 420 | const Writer = std.Io.Writer; | |
| 421 | 421 | |
| 422 | 422 | const Atom = @import("Atom.zig"); |
| 423 | 423 | const File = @import("file.zig").File; |
src/link/MachO/Thunk.zig+1-1| ... | ... | @@ -97,7 +97,7 @@ const math = std.math; |
| 97 | 97 | const mem = std.mem; |
| 98 | 98 | const std = @import("std"); |
| 99 | 99 | const trace = @import("../../tracy.zig").trace; |
| 100 | const Writer = std.io.Writer; | |
| 100 | const Writer = std.Io.Writer; | |
| 101 | 101 | |
| 102 | 102 | const Allocator = mem.Allocator; |
| 103 | 103 | const Atom = @import("Atom.zig"); |
src/link/MachO/ZigObject.zig+1-1| ... | ... | @@ -1785,7 +1785,7 @@ const mem = std.mem; |
| 1785 | 1785 | const target_util = @import("../../target.zig"); |
| 1786 | 1786 | const trace = @import("../../tracy.zig").trace; |
| 1787 | 1787 | const std = @import("std"); |
| 1788 | const Writer = std.io.Writer; | |
| 1788 | const Writer = std.Io.Writer; | |
| 1789 | 1789 | |
| 1790 | 1790 | const Allocator = std.mem.Allocator; |
| 1791 | 1791 | const Archive = @import("Archive.zig"); |
src/link/MachO/dead_strip.zig+1-1| ... | ... | @@ -212,7 +212,7 @@ const mem = std.mem; |
| 212 | 212 | const trace = @import("../../tracy.zig").trace; |
| 213 | 213 | const track_live_log = std.log.scoped(.dead_strip_track_live); |
| 214 | 214 | const std = @import("std"); |
| 215 | const Writer = std.io.Writer; | |
| 215 | const Writer = std.Io.Writer; | |
| 216 | 216 | |
| 217 | 217 | const Allocator = mem.Allocator; |
| 218 | 218 | const Atom = @import("Atom.zig"); |
src/link/MachO/dyld_info/Rebase.zig+1-1| ... | ... | @@ -656,7 +656,7 @@ const macho = std.macho; |
| 656 | 656 | const mem = std.mem; |
| 657 | 657 | const testing = std.testing; |
| 658 | 658 | const Allocator = mem.Allocator; |
| 659 | const Writer = std.io.Writer; | |
| 659 | const Writer = std.Io.Writer; | |
| 660 | 660 | |
| 661 | 661 | const trace = @import("../../../tracy.zig").trace; |
| 662 | 662 | const File = @import("../file.zig").File; |
src/link/MachO/dyld_info/bind.zig+1-1| ... | ... | @@ -647,7 +647,7 @@ fn setDylibOrdinal(ordinal: i16, writer: *std.Io.Writer) !void { |
| 647 | 647 | fn setAddend(addend: i64, writer: *std.Io.Writer) !void { |
| 648 | 648 | log.debug(">>> set addend: {x}", .{addend}); |
| 649 | 649 | try writer.writeByte(macho.BIND_OPCODE_SET_ADDEND_SLEB); |
| 650 | try std.leb.writeIleb128(writer, addend); | |
| 650 | try writer.writeSleb128(addend); | |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | fn doBind(writer: *std.Io.Writer) !void { |
src/link/MachO/eh_frame.zig+4-5| ... | ... | @@ -248,13 +248,12 @@ pub const Iterator = struct { |
| 248 | 248 | pub fn next(it: *Iterator) !?Record { |
| 249 | 249 | if (it.pos >= it.data.len) return null; |
| 250 | 250 | |
| 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..]); | |
| 253 | 252 | |
| 254 | const size = try reader.readInt(u32, .little); | |
| 253 | const size = try reader.takeInt(u32, .little); | |
| 255 | 254 | if (size == 0xFFFFFFFF) @panic("DWARF CFI is 32bit on macOS"); |
| 256 | 255 | |
| 257 | const id = try reader.readInt(u32, .little); | |
| 256 | const id = try reader.takeInt(u32, .little); | |
| 258 | 257 | const record = Record{ |
| 259 | 258 | .tag = if (id == 0) .cie else .fde, |
| 260 | 259 | .offset = it.pos, |
| ... | ... | @@ -502,7 +501,7 @@ const math = std.math; |
| 502 | 501 | const mem = std.mem; |
| 503 | 502 | const std = @import("std"); |
| 504 | 503 | const trace = @import("../../tracy.zig").trace; |
| 505 | const Writer = std.io.Writer; | |
| 504 | const Writer = std.Io.Writer; | |
| 506 | 505 | |
| 507 | 506 | const Allocator = std.mem.Allocator; |
| 508 | 507 | const Atom = @import("Atom.zig"); |
src/link/MachO/file.zig+1-1| ... | ... | @@ -364,7 +364,7 @@ const log = std.log.scoped(.link); |
| 364 | 364 | const macho = std.macho; |
| 365 | 365 | const Allocator = std.mem.Allocator; |
| 366 | 366 | const Path = std.Build.Cache.Path; |
| 367 | const Writer = std.io.Writer; | |
| 367 | const Writer = std.Io.Writer; | |
| 368 | 368 | |
| 369 | 369 | const trace = @import("../../tracy.zig").trace; |
| 370 | 370 | const Archive = @import("Archive.zig"); |
src/link/MachO/relocatable.zig+1-1| ... | ... | @@ -780,7 +780,7 @@ const macho = std.macho; |
| 780 | 780 | const math = std.math; |
| 781 | 781 | const mem = std.mem; |
| 782 | 782 | const state_log = std.log.scoped(.link_state); |
| 783 | const Writer = std.io.Writer; | |
| 783 | const Writer = std.Io.Writer; | |
| 784 | 784 | |
| 785 | 785 | const Archive = @import("Archive.zig"); |
| 786 | 786 | const Atom = @import("Atom.zig"); |
src/link/SpirV.zig+1-1| ... | ... | @@ -249,7 +249,7 @@ pub fn flush( |
| 249 | 249 | // We need to export the list of error names somewhere so that we can pretty-print them in the |
| 250 | 250 | // executor. This is not really an important thing though, so we can just dump it in any old |
| 251 | 251 | // 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); | |
| 253 | 253 | defer error_info.deinit(); |
| 254 | 254 | |
| 255 | 255 | 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 { |
| 2126 | 2126 | wasm: *const Wasm, |
| 2127 | 2127 | ft: FunctionType, |
| 2128 | 2128 | |
| 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 { | |
| 2130 | 2130 | const params = self.ft.params.slice(self.wasm); |
| 2131 | 2131 | const returns = self.ft.returns.slice(self.wasm); |
| 2132 | 2132 | |
| ... | ... | @@ -2905,7 +2905,7 @@ pub const Feature = packed struct(u8) { |
| 2905 | 2905 | @"=", |
| 2906 | 2906 | }; |
| 2907 | 2907 | |
| 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 { | |
| 2909 | 2909 | try writer.print("{s} {s}", .{ @tagName(feature.prefix), @tagName(feature.tag) }); |
| 2910 | 2910 | } |
| 2911 | 2911 |
src/link/Wasm/Object.zig+3-6| ... | ... | @@ -1460,13 +1460,10 @@ fn parseFeatures( |
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | fn 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..]); | |
| 1464 | 1464 | 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, | |
| 1470 | 1467 | }; |
| 1471 | 1468 | } |
| 1472 | 1469 |
src/link/table_section.zig+1-1| ... | ... | @@ -39,7 +39,7 @@ pub fn TableSection(comptime Entry: type) type { |
| 39 | 39 | return self.entries.items.len; |
| 40 | 40 | } |
| 41 | 41 | |
| 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 { | |
| 43 | 43 | try writer.writeAll("TableSection:\n"); |
| 44 | 44 | for (self.entries.items, 0..) |entry, i| { |
| 45 | 45 | try writer.print(" {d} => {}\n", .{ i, entry }); |
src/link/tapi/parse.zig+5-5| ... | ... | @@ -57,7 +57,7 @@ pub const Node = struct { |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 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 { | |
| 61 | 61 | switch (self.tag) { |
| 62 | 62 | inline else => |tag| return @as(*tag.Type(), @fieldParentPtr("base", self)).format(writer), |
| 63 | 63 | } |
| ... | ... | @@ -81,7 +81,7 @@ pub const Node = struct { |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 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 { | |
| 85 | 85 | if (self.directive) |id| { |
| 86 | 86 | try writer.print("{{ ", .{}); |
| 87 | 87 | const directive = self.base.tree.getRaw(id, id); |
| ... | ... | @@ -121,7 +121,7 @@ pub const Node = struct { |
| 121 | 121 | self.values.deinit(allocator); |
| 122 | 122 | } |
| 123 | 123 | |
| 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 { | |
| 125 | 125 | try std.fmt.format(writer, "{{ ", .{}); |
| 126 | 126 | for (self.values.items) |entry| { |
| 127 | 127 | const key = self.base.tree.getRaw(entry.key, entry.key); |
| ... | ... | @@ -153,7 +153,7 @@ pub const Node = struct { |
| 153 | 153 | self.values.deinit(allocator); |
| 154 | 154 | } |
| 155 | 155 | |
| 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 { | |
| 157 | 157 | try std.fmt.format(writer, "[ ", .{}); |
| 158 | 158 | for (self.values.items) |node| { |
| 159 | 159 | try std.fmt.format(writer, "{}, ", .{node}); |
| ... | ... | @@ -177,7 +177,7 @@ pub const Node = struct { |
| 177 | 177 | self.string_value.deinit(allocator); |
| 178 | 178 | } |
| 179 | 179 | |
| 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 { | |
| 181 | 181 | const raw = self.base.tree.getRaw(self.base.start, self.base.end); |
| 182 | 182 | return std.fmt.format(writer, "{s}", .{raw}); |
| 183 | 183 | } |
src/main.zig+7-8| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const io = std.io; | |
| 5 | 4 | const fs = std.fs; |
| 6 | 5 | const mem = std.mem; |
| 7 | 6 | const process = std.process; |
| ... | ... | @@ -5444,7 +5443,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5444 | 5443 | // that are missing. |
| 5445 | 5444 | const s = fs.path.sep_str; |
| 5446 | 5445 | const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce; |
| 5447 | const stdout = dirs.local_cache.handle.readFileAlloc(arena, tmp_sub_path, 50 * 1024 * 1024) catch |err| { | |
| 5446 | const stdout = dirs.local_cache.handle.readFileAlloc(tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| { | |
| 5448 | 5447 | fatal("unable to read results of configure phase from '{f}{s}': {s}", .{ |
| 5449 | 5448 | dirs.local_cache, tmp_sub_path, @errorName(err), |
| 5450 | 5449 | }); |
| ... | ... | @@ -5694,7 +5693,8 @@ fn jitCmd( |
| 5694 | 5693 | try child.spawn(); |
| 5695 | 5694 | |
| 5696 | 5695 | if (options.capture) |ptr| { |
| 5697 | ptr.* = try child.stdout.?.readToEndAlloc(arena, std.math.maxInt(u32)); | |
| 5696 | var stdout_reader = child.stdout.?.readerStreaming(&.{}); | |
| 5697 | ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32))); | |
| 5698 | 5698 | } |
| 5699 | 5699 | |
| 5700 | 5700 | const term = try child.wait(); |
| ... | ... | @@ -5827,7 +5827,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, |
| 5827 | 5827 | /// Initialize the arguments from a Response File. "*.rsp" |
| 5828 | 5828 | fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile { |
| 5829 | 5829 | const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit |
| 5830 | const cmd_line = try fs.cwd().readFileAlloc(allocator, resp_file_path, max_bytes); | |
| 5830 | const cmd_line = try fs.cwd().readFileAlloc(resp_file_path, allocator, .limited(max_bytes)); | |
| 5831 | 5831 | errdefer allocator.free(cmd_line); |
| 5832 | 5832 | |
| 5833 | 5833 | return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); |
| ... | ... | @@ -7351,10 +7351,9 @@ fn loadManifest( |
| 7351 | 7351 | ) !struct { Package.Manifest, Ast } { |
| 7352 | 7352 | const manifest_bytes = while (true) { |
| 7353 | 7353 | break options.dir.readFileAllocOptions( |
| 7354 | arena, | |
| 7355 | 7354 | Package.Manifest.basename, |
| 7356 | Package.Manifest.max_bytes, | |
| 7357 | null, | |
| 7355 | arena, | |
| 7356 | .limited(Package.Manifest.max_bytes), | |
| 7358 | 7357 | .@"1", |
| 7359 | 7358 | 0, |
| 7360 | 7359 | ) catch |err| switch (err) { |
| ... | ... | @@ -7436,7 +7435,7 @@ const Templates = struct { |
| 7436 | 7435 | } |
| 7437 | 7436 | |
| 7438 | 7437 | const max_bytes = 10 * 1024 * 1024; |
| 7439 | const contents = templates.dir.readFileAlloc(arena, template_path, max_bytes) catch |err| { | |
| 7438 | const contents = templates.dir.readFileAlloc(template_path, arena, .limited(max_bytes)) catch |err| { | |
| 7440 | 7439 | fatal("unable to read template file '{s}': {s}", .{ template_path, @errorName(err) }); |
| 7441 | 7440 | }; |
| 7442 | 7441 | templates.buffer.clearRetainingCapacity(); |
src/print_targets.zig+2-3| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const fs = std.fs; |
| 3 | const io = std.io; | |
| 4 | 3 | const mem = std.mem; |
| 5 | 4 | const meta = std.meta; |
| 6 | 5 | const fatal = std.process.fatal; |
| ... | ... | @@ -25,9 +24,9 @@ pub fn cmdTargets( |
| 25 | 24 | defer allocator.free(zig_lib_directory.path.?); |
| 26 | 25 | |
| 27 | 26 | const abilists_contents = zig_lib_directory.handle.readFileAlloc( |
| 28 | allocator, | |
| 29 | 27 | glibc.abilists_path, |
| 30 | glibc.abilists_max_size, | |
| 28 | allocator, | |
| 29 | .limited(glibc.abilists_max_size), | |
| 31 | 30 | ) catch |err| switch (err) { |
| 32 | 31 | error.OutOfMemory => return error.OutOfMemory, |
| 33 | 32 | else => fatal("unable to read " ++ glibc.abilists_path ++ ": {s}", .{@errorName(err)}), |
src/print_value.zig+10-9| ... | ... | @@ -9,6 +9,7 @@ const Sema = @import("Sema.zig"); |
| 9 | 9 | const InternPool = @import("InternPool.zig"); |
| 10 | 10 | const Allocator = std.mem.Allocator; |
| 11 | 11 | const Target = std.Target; |
| 12 | const Writer = std.Io.Writer; | |
| 12 | 13 | |
| 13 | 14 | const max_aggregate_items = 100; |
| 14 | 15 | const max_string_len = 256; |
| ... | ... | @@ -20,7 +21,7 @@ pub const FormatContext = struct { |
| 20 | 21 | depth: u8, |
| 21 | 22 | }; |
| 22 | 23 | |
| 23 | pub fn formatSema(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 24 | pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void { | |
| 24 | 25 | const sema = ctx.opt_sema.?; |
| 25 | 26 | return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) { |
| 26 | 27 | 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 |
| 30 | 31 | }; |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | pub fn format(ctx: FormatContext, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 34 | pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void { | |
| 34 | 35 | std.debug.assert(ctx.opt_sema == null); |
| 35 | 36 | return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) { |
| 36 | 37 | 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 |
| 41 | 42 | |
| 42 | 43 | pub fn print( |
| 43 | 44 | val: Value, |
| 44 | writer: *std.io.Writer, | |
| 45 | writer: *Writer, | |
| 45 | 46 | level: u8, |
| 46 | 47 | pt: Zcu.PerThread, |
| 47 | 48 | opt_sema: ?*Sema, |
| 48 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 49 | ) (Writer.Error || Zcu.CompileError)!void { | |
| 49 | 50 | const zcu = pt.zcu; |
| 50 | 51 | const ip = &zcu.intern_pool; |
| 51 | 52 | switch (ip.indexToKey(val.toIntern())) { |
| ... | ... | @@ -184,11 +185,11 @@ fn printAggregate( |
| 184 | 185 | val: Value, |
| 185 | 186 | aggregate: InternPool.Key.Aggregate, |
| 186 | 187 | is_ref: bool, |
| 187 | writer: *std.io.Writer, | |
| 188 | writer: *Writer, | |
| 188 | 189 | level: u8, |
| 189 | 190 | pt: Zcu.PerThread, |
| 190 | 191 | opt_sema: ?*Sema, |
| 191 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 192 | ) (Writer.Error || Zcu.CompileError)!void { | |
| 192 | 193 | if (level == 0) { |
| 193 | 194 | if (is_ref) try writer.writeByte('&'); |
| 194 | 195 | return writer.writeAll(".{ ... }"); |
| ... | ... | @@ -270,11 +271,11 @@ fn printPtr( |
| 270 | 271 | ptr_val: Value, |
| 271 | 272 | /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen. |
| 272 | 273 | want_kind: ?PrintPtrKind, |
| 273 | writer: *std.io.Writer, | |
| 274 | writer: *Writer, | |
| 274 | 275 | level: u8, |
| 275 | 276 | pt: Zcu.PerThread, |
| 276 | 277 | opt_sema: ?*Sema, |
| 277 | ) (std.io.Writer.Error || Zcu.CompileError)!void { | |
| 278 | ) (Writer.Error || Zcu.CompileError)!void { | |
| 278 | 279 | const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 279 | 280 | .undef => return writer.writeAll("undefined"), |
| 280 | 281 | .ptr => |ptr| ptr, |
| ... | ... | @@ -316,7 +317,7 @@ const PrintPtrKind = enum { lvalue, rvalue }; |
| 316 | 317 | /// Returns the root derivation, which may be ignored. |
| 317 | 318 | pub fn printPtrDerivation( |
| 318 | 319 | derivation: Value.PointerDeriveStep, |
| 319 | writer: *std.io.Writer, | |
| 320 | writer: *Writer, | |
| 320 | 321 | pt: Zcu.PerThread, |
| 321 | 322 | /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen. |
| 322 | 323 | /// 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"); |
| 10 | 10 | const LazySrcLoc = Zcu.LazySrcLoc; |
| 11 | 11 | |
| 12 | 12 | /// Write human-readable, debug formatted ZIR code. |
| 13 | pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.io.Writer) !void { | |
| 13 | pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.Io.Writer) !void { | |
| 14 | 14 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 15 | 15 | defer arena.deinit(); |
| 16 | 16 | |
| ... | ... | @@ -57,7 +57,7 @@ pub fn renderInstructionContext( |
| 57 | 57 | scope_file: *Zcu.File, |
| 58 | 58 | parent_decl_node: Ast.Node.Index, |
| 59 | 59 | indent: u32, |
| 60 | bw: *std.io.Writer, | |
| 60 | bw: *std.Io.Writer, | |
| 61 | 61 | ) !void { |
| 62 | 62 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 63 | 63 | defer arena.deinit(); |
| ... | ... | @@ -89,7 +89,7 @@ pub fn renderSingleInstruction( |
| 89 | 89 | scope_file: *Zcu.File, |
| 90 | 90 | parent_decl_node: Ast.Node.Index, |
| 91 | 91 | indent: u32, |
| 92 | bw: *std.io.Writer, | |
| 92 | bw: *std.Io.Writer, | |
| 93 | 93 | ) !void { |
| 94 | 94 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 95 | 95 | defer arena.deinit(); |
| ... | ... | @@ -176,11 +176,11 @@ const Writer = struct { |
| 176 | 176 | } |
| 177 | 177 | } = .{}, |
| 178 | 178 | |
| 179 | const Error = std.io.Writer.Error || Allocator.Error; | |
| 179 | const Error = std.Io.Writer.Error || Allocator.Error; | |
| 180 | 180 | |
| 181 | 181 | fn writeInstToStream( |
| 182 | 182 | self: *Writer, |
| 183 | stream: *std.io.Writer, | |
| 183 | stream: *std.Io.Writer, | |
| 184 | 184 | inst: Zir.Inst.Index, |
| 185 | 185 | ) Error!void { |
| 186 | 186 | const tags = self.code.instructions.items(.tag); |
| ... | ... | @@ -508,7 +508,7 @@ const Writer = struct { |
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | |
| 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 { | |
| 512 | 512 | const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended; |
| 513 | 513 | try stream.print("{s}(", .{@tagName(extended.opcode)}); |
| 514 | 514 | switch (extended.opcode) { |
| ... | ... | @@ -616,13 +616,13 @@ const Writer = struct { |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
| 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 { | |
| 620 | 620 | try stream.writeAll(")) "); |
| 621 | 621 | const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand))); |
| 622 | 622 | try self.writeSrcNode(stream, src_node); |
| 623 | 623 | } |
| 624 | 624 | |
| 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 { | |
| 626 | 626 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin; |
| 627 | 627 | try self.writeInstRef(stream, inst_data.lhs); |
| 628 | 628 | try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)}); |
| ... | ... | @@ -630,7 +630,7 @@ const Writer = struct { |
| 630 | 630 | |
| 631 | 631 | fn writeUnNode( |
| 632 | 632 | self: *Writer, |
| 633 | stream: *std.io.Writer, | |
| 633 | stream: *std.Io.Writer, | |
| 634 | 634 | inst: Zir.Inst.Index, |
| 635 | 635 | ) Error!void { |
| 636 | 636 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| ... | ... | @@ -641,7 +641,7 @@ const Writer = struct { |
| 641 | 641 | |
| 642 | 642 | fn writeUnTok( |
| 643 | 643 | self: *Writer, |
| 644 | stream: *std.io.Writer, | |
| 644 | stream: *std.Io.Writer, | |
| 645 | 645 | inst: Zir.Inst.Index, |
| 646 | 646 | ) Error!void { |
| 647 | 647 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| ... | ... | @@ -652,7 +652,7 @@ const Writer = struct { |
| 652 | 652 | |
| 653 | 653 | fn writeValidateDestructure( |
| 654 | 654 | self: *Writer, |
| 655 | stream: *std.io.Writer, | |
| 655 | stream: *std.Io.Writer, | |
| 656 | 656 | inst: Zir.Inst.Index, |
| 657 | 657 | ) Error!void { |
| 658 | 658 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| ... | ... | @@ -666,7 +666,7 @@ const Writer = struct { |
| 666 | 666 | |
| 667 | 667 | fn writeValidateArrayInitTy( |
| 668 | 668 | self: *Writer, |
| 669 | stream: *std.io.Writer, | |
| 669 | stream: *std.Io.Writer, | |
| 670 | 670 | inst: Zir.Inst.Index, |
| 671 | 671 | ) Error!void { |
| 672 | 672 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| ... | ... | @@ -678,7 +678,7 @@ const Writer = struct { |
| 678 | 678 | |
| 679 | 679 | fn writeArrayTypeSentinel( |
| 680 | 680 | self: *Writer, |
| 681 | stream: *std.io.Writer, | |
| 681 | stream: *std.Io.Writer, | |
| 682 | 682 | inst: Zir.Inst.Index, |
| 683 | 683 | ) Error!void { |
| 684 | 684 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| ... | ... | @@ -694,7 +694,7 @@ const Writer = struct { |
| 694 | 694 | |
| 695 | 695 | fn writePtrType( |
| 696 | 696 | self: *Writer, |
| 697 | stream: *std.io.Writer, | |
| 697 | stream: *std.Io.Writer, | |
| 698 | 698 | inst: Zir.Inst.Index, |
| 699 | 699 | ) Error!void { |
| 700 | 700 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; |
| ... | ... | @@ -737,12 +737,12 @@ const Writer = struct { |
| 737 | 737 | try self.writeSrcNode(stream, extra.data.src_node); |
| 738 | 738 | } |
| 739 | 739 | |
| 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 { | |
| 741 | 741 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int; |
| 742 | 742 | try stream.print("{d})", .{inst_data}); |
| 743 | 743 | } |
| 744 | 744 | |
| 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 { | |
| 746 | 746 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str; |
| 747 | 747 | const byte_count = inst_data.len * @sizeOf(std.math.big.Limb); |
| 748 | 748 | const limb_bytes = self.code.string_bytes[@intFromEnum(inst_data.start)..][0..byte_count]; |
| ... | ... | @@ -761,12 +761,12 @@ const Writer = struct { |
| 761 | 761 | try stream.print("{s})", .{as_string}); |
| 762 | 762 | } |
| 763 | 763 | |
| 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 { | |
| 765 | 765 | const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float; |
| 766 | 766 | try stream.print("{d})", .{number}); |
| 767 | 767 | } |
| 768 | 768 | |
| 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 { | |
| 770 | 770 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 771 | 771 | const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data; |
| 772 | 772 | const number = extra.get(); |
| ... | ... | @@ -777,7 +777,7 @@ const Writer = struct { |
| 777 | 777 | |
| 778 | 778 | fn writeStr( |
| 779 | 779 | self: *Writer, |
| 780 | stream: *std.io.Writer, | |
| 780 | stream: *std.Io.Writer, | |
| 781 | 781 | inst: Zir.Inst.Index, |
| 782 | 782 | ) Error!void { |
| 783 | 783 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str; |
| ... | ... | @@ -785,7 +785,7 @@ const Writer = struct { |
| 785 | 785 | try stream.print("\"{f}\")", .{std.zig.fmtString(str)}); |
| 786 | 786 | } |
| 787 | 787 | |
| 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 { | |
| 789 | 789 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 790 | 790 | const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 791 | 791 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -795,7 +795,7 @@ const Writer = struct { |
| 795 | 795 | try self.writeSrcNode(stream, inst_data.src_node); |
| 796 | 796 | } |
| 797 | 797 | |
| 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 { | |
| 799 | 799 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 800 | 800 | const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 801 | 801 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -807,7 +807,7 @@ const Writer = struct { |
| 807 | 807 | try self.writeSrcNode(stream, inst_data.src_node); |
| 808 | 808 | } |
| 809 | 809 | |
| 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 { | |
| 811 | 811 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 812 | 812 | const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 813 | 813 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -821,7 +821,7 @@ const Writer = struct { |
| 821 | 821 | try self.writeSrcNode(stream, inst_data.src_node); |
| 822 | 822 | } |
| 823 | 823 | |
| 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 { | |
| 825 | 825 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 826 | 826 | const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 827 | 827 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -837,7 +837,7 @@ const Writer = struct { |
| 837 | 837 | try self.writeSrcNode(stream, inst_data.src_node); |
| 838 | 838 | } |
| 839 | 839 | |
| 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 { | |
| 841 | 841 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 842 | 842 | const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 843 | 843 | try self.writeInstRef(stream, extra.union_type); |
| ... | ... | @@ -849,7 +849,7 @@ const Writer = struct { |
| 849 | 849 | try self.writeSrcNode(stream, inst_data.src_node); |
| 850 | 850 | } |
| 851 | 851 | |
| 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 { | |
| 853 | 853 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 854 | 854 | const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 855 | 855 | try self.writeInstRef(stream, extra.elem_type); |
| ... | ... | @@ -863,7 +863,7 @@ const Writer = struct { |
| 863 | 863 | try self.writeSrcNode(stream, inst_data.src_node); |
| 864 | 864 | } |
| 865 | 865 | |
| 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 { | |
| 867 | 867 | const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data; |
| 868 | 868 | try self.writeInstRef(stream, extra.elem_type); |
| 869 | 869 | try stream.writeAll(", "); |
| ... | ... | @@ -876,7 +876,7 @@ const Writer = struct { |
| 876 | 876 | try self.writeSrcNode(stream, extra.node); |
| 877 | 877 | } |
| 878 | 878 | |
| 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 { | |
| 880 | 880 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 881 | 881 | const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 882 | 882 | try self.writeInstRef(stream, extra.mulend1); |
| ... | ... | @@ -888,7 +888,7 @@ const Writer = struct { |
| 888 | 888 | try self.writeSrcNode(stream, inst_data.src_node); |
| 889 | 889 | } |
| 890 | 890 | |
| 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 { | |
| 892 | 892 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 893 | 893 | const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 894 | 894 | |
| ... | ... | @@ -904,7 +904,7 @@ const Writer = struct { |
| 904 | 904 | try self.writeSrcNode(stream, inst_data.src_node); |
| 905 | 905 | } |
| 906 | 906 | |
| 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 { | |
| 908 | 908 | const extra = self.code.extraData(Zir.Inst.FieldParentPtr, extended.operand).data; |
| 909 | 909 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?; |
| 910 | 910 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| ... | ... | @@ -921,7 +921,7 @@ const Writer = struct { |
| 921 | 921 | try self.writeSrcNode(stream, extra.src_node); |
| 922 | 922 | } |
| 923 | 923 | |
| 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 { | |
| 925 | 925 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; |
| 926 | 926 | const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 927 | 927 | const body = self.code.bodySlice(extra.end, extra.data.type.body_len); |
| ... | ... | @@ -936,7 +936,7 @@ const Writer = struct { |
| 936 | 936 | try self.writeSrcTok(stream, inst_data.src_tok); |
| 937 | 937 | } |
| 938 | 938 | |
| 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 { | |
| 940 | 940 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 941 | 941 | const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 942 | 942 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -946,7 +946,7 @@ const Writer = struct { |
| 946 | 946 | try self.writeSrcNode(stream, inst_data.src_node); |
| 947 | 947 | } |
| 948 | 948 | |
| 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 { | |
| 950 | 950 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 951 | 951 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 952 | 952 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| ... | ... | @@ -959,7 +959,7 @@ const Writer = struct { |
| 959 | 959 | try self.writeSrcNode(stream, inst_data.src_node); |
| 960 | 960 | } |
| 961 | 961 | |
| 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 { | |
| 963 | 963 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 964 | 964 | const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; |
| 965 | 965 | try self.writeInstRef(stream, extra.res_ty); |
| ... | ... | @@ -971,13 +971,13 @@ const Writer = struct { |
| 971 | 971 | try self.writeSrcNode(stream, inst_data.src_node); |
| 972 | 972 | } |
| 973 | 973 | |
| 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 { | |
| 975 | 975 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 976 | 976 | try self.writeInstRef(stream, inst_data.operand); |
| 977 | 977 | try stream.print(", {d})", .{inst_data.idx}); |
| 978 | 978 | } |
| 979 | 979 | |
| 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 { | |
| 981 | 981 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 982 | 982 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 983 | 983 | |
| ... | ... | @@ -986,7 +986,7 @@ const Writer = struct { |
| 986 | 986 | try self.writeSrcNode(stream, inst_data.src_node); |
| 987 | 987 | } |
| 988 | 988 | |
| 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 { | |
| 990 | 990 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 991 | 991 | const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 992 | 992 | |
| ... | ... | @@ -997,7 +997,7 @@ const Writer = struct { |
| 997 | 997 | try self.writeSrcNode(stream, inst_data.src_node); |
| 998 | 998 | } |
| 999 | 999 | |
| 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 { | |
| 1001 | 1001 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1002 | 1002 | const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data; |
| 1003 | 1003 | |
| ... | ... | @@ -1007,7 +1007,7 @@ const Writer = struct { |
| 1007 | 1007 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 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 { | |
| 1011 | 1011 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1012 | 1012 | const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 1013 | 1013 | var field_i: u32 = 0; |
| ... | ... | @@ -1031,7 +1031,7 @@ const Writer = struct { |
| 1031 | 1031 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 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 { | |
| 1035 | 1035 | const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data; |
| 1036 | 1036 | |
| 1037 | 1037 | try self.writeInstRef(stream, extra.ptr); |
| ... | ... | @@ -1047,7 +1047,7 @@ const Writer = struct { |
| 1047 | 1047 | try self.writeSrcNode(stream, extra.node); |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 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 { | |
| 1051 | 1051 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?; |
| 1052 | 1052 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 1053 | 1053 | const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| ... | ... | @@ -1063,7 +1063,7 @@ const Writer = struct { |
| 1063 | 1063 | try self.writeSrcNode(stream, extra.node); |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 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 { | |
| 1067 | 1067 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?; |
| 1068 | 1068 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 1069 | 1069 | const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| ... | ... | @@ -1074,7 +1074,7 @@ const Writer = struct { |
| 1074 | 1074 | try self.writeSrcNode(stream, extra.node); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 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 { | |
| 1078 | 1078 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1079 | 1079 | const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 1080 | 1080 | |
| ... | ... | @@ -1087,7 +1087,7 @@ const Writer = struct { |
| 1087 | 1087 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 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 { | |
| 1091 | 1091 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1092 | 1092 | const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 1093 | 1093 | |
| ... | ... | @@ -1100,7 +1100,7 @@ const Writer = struct { |
| 1100 | 1100 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 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 { | |
| 1104 | 1104 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1105 | 1105 | const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 1106 | 1106 | |
| ... | ... | @@ -1115,7 +1115,7 @@ const Writer = struct { |
| 1115 | 1115 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 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 { | |
| 1119 | 1119 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1120 | 1120 | const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 1121 | 1121 | var field_i: u32 = 0; |
| ... | ... | @@ -1136,7 +1136,7 @@ const Writer = struct { |
| 1136 | 1136 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 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 { | |
| 1140 | 1140 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1141 | 1141 | const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 1142 | 1142 | try self.writeInstRef(stream, extra.container_type); |
| ... | ... | @@ -1145,7 +1145,7 @@ const Writer = struct { |
| 1145 | 1145 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 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 { | |
| 1149 | 1149 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1150 | 1150 | const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 1151 | 1151 | try self.writeInstRef(stream, extra.container_type); |
| ... | ... | @@ -1155,7 +1155,7 @@ const Writer = struct { |
| 1155 | 1155 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 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 { | |
| 1159 | 1159 | const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 1160 | 1160 | const operands = self.code.refSlice(extra.end, extended.small); |
| 1161 | 1161 | |
| ... | ... | @@ -1169,7 +1169,7 @@ const Writer = struct { |
| 1169 | 1169 | |
| 1170 | 1170 | fn writeInstNode( |
| 1171 | 1171 | self: *Writer, |
| 1172 | stream: *std.io.Writer, | |
| 1172 | stream: *std.Io.Writer, | |
| 1173 | 1173 | inst: Zir.Inst.Index, |
| 1174 | 1174 | ) Error!void { |
| 1175 | 1175 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node; |
| ... | ... | @@ -1180,7 +1180,7 @@ const Writer = struct { |
| 1180 | 1180 | |
| 1181 | 1181 | fn writeAsm( |
| 1182 | 1182 | self: *Writer, |
| 1183 | stream: *std.io.Writer, | |
| 1183 | stream: *std.Io.Writer, | |
| 1184 | 1184 | extended: Zir.Inst.Extended.InstData, |
| 1185 | 1185 | tmpl_is_expr: bool, |
| 1186 | 1186 | ) !void { |
| ... | ... | @@ -1258,7 +1258,7 @@ const Writer = struct { |
| 1258 | 1258 | try self.writeSrcNode(stream, extra.data.src_node); |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 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 { | |
| 1262 | 1262 | const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 1263 | 1263 | |
| 1264 | 1264 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -1270,7 +1270,7 @@ const Writer = struct { |
| 1270 | 1270 | |
| 1271 | 1271 | fn writeCall( |
| 1272 | 1272 | self: *Writer, |
| 1273 | stream: *std.io.Writer, | |
| 1273 | stream: *std.Io.Writer, | |
| 1274 | 1274 | inst: Zir.Inst.Index, |
| 1275 | 1275 | comptime kind: enum { direct, field }, |
| 1276 | 1276 | ) !void { |
| ... | ... | @@ -1321,7 +1321,7 @@ const Writer = struct { |
| 1321 | 1321 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 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 { | |
| 1325 | 1325 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1326 | 1326 | const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 1327 | 1327 | const body = self.code.bodySlice(extra.end, extra.data.body_len); |
| ... | ... | @@ -1330,7 +1330,7 @@ const Writer = struct { |
| 1330 | 1330 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 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 { | |
| 1334 | 1334 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1335 | 1335 | const extra = self.code.extraData(Zir.Inst.BlockComptime, inst_data.payload_index); |
| 1336 | 1336 | const body = self.code.bodySlice(extra.end, extra.data.body_len); |
| ... | ... | @@ -1340,7 +1340,7 @@ const Writer = struct { |
| 1340 | 1340 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 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 { | |
| 1344 | 1344 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1345 | 1345 | const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1346 | 1346 | const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len); |
| ... | ... | @@ -1354,7 +1354,7 @@ const Writer = struct { |
| 1354 | 1354 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 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 { | |
| 1358 | 1358 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1359 | 1359 | const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1360 | 1360 | const body = self.code.bodySlice(extra.end, extra.data.body_len); |
| ... | ... | @@ -1365,7 +1365,7 @@ const Writer = struct { |
| 1365 | 1365 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 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 { | |
| 1369 | 1369 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 1370 | 1370 | |
| 1371 | 1371 | const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand); |
| ... | ... | @@ -1557,7 +1557,7 @@ const Writer = struct { |
| 1557 | 1557 | try self.writeSrcNode(stream, .zero); |
| 1558 | 1558 | } |
| 1559 | 1559 | |
| 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 { | |
| 1561 | 1561 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); |
| 1562 | 1562 | |
| 1563 | 1563 | const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| ... | ... | @@ -1708,7 +1708,7 @@ const Writer = struct { |
| 1708 | 1708 | try self.writeSrcNode(stream, .zero); |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 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 { | |
| 1712 | 1712 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); |
| 1713 | 1713 | |
| 1714 | 1714 | const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| ... | ... | @@ -1829,7 +1829,7 @@ const Writer = struct { |
| 1829 | 1829 | |
| 1830 | 1830 | fn writeOpaqueDecl( |
| 1831 | 1831 | self: *Writer, |
| 1832 | stream: *std.io.Writer, | |
| 1832 | stream: *std.Io.Writer, | |
| 1833 | 1833 | extended: Zir.Inst.Extended.InstData, |
| 1834 | 1834 | ) !void { |
| 1835 | 1835 | const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small)); |
| ... | ... | @@ -1871,7 +1871,7 @@ const Writer = struct { |
| 1871 | 1871 | try self.writeSrcNode(stream, .zero); |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 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 { | |
| 1875 | 1875 | const fields_len = extended.small; |
| 1876 | 1876 | assert(fields_len != 0); |
| 1877 | 1877 | const extra = self.code.extraData(Zir.Inst.TupleDecl, extended.operand); |
| ... | ... | @@ -1899,7 +1899,7 @@ const Writer = struct { |
| 1899 | 1899 | |
| 1900 | 1900 | fn writeErrorSetDecl( |
| 1901 | 1901 | self: *Writer, |
| 1902 | stream: *std.io.Writer, | |
| 1902 | stream: *std.Io.Writer, | |
| 1903 | 1903 | inst: Zir.Inst.Index, |
| 1904 | 1904 | ) !void { |
| 1905 | 1905 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| ... | ... | @@ -1924,7 +1924,7 @@ const Writer = struct { |
| 1924 | 1924 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1925 | 1925 | } |
| 1926 | 1926 | |
| 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 { | |
| 1928 | 1928 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1929 | 1929 | const extra = self.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); |
| 1930 | 1930 | |
| ... | ... | @@ -2061,7 +2061,7 @@ const Writer = struct { |
| 2061 | 2061 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 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 { | |
| 2065 | 2065 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2066 | 2066 | const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 2067 | 2067 | |
| ... | ... | @@ -2242,7 +2242,7 @@ const Writer = struct { |
| 2242 | 2242 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 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 { | |
| 2246 | 2246 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2247 | 2247 | const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 2248 | 2248 | const name = self.code.nullTerminatedString(extra.field_name_start); |
| ... | ... | @@ -2251,7 +2251,7 @@ const Writer = struct { |
| 2251 | 2251 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 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 { | |
| 2255 | 2255 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2256 | 2256 | const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 2257 | 2257 | try self.writeInstRef(stream, extra.lhs); |
| ... | ... | @@ -2261,7 +2261,7 @@ const Writer = struct { |
| 2261 | 2261 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 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 { | |
| 2265 | 2265 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2266 | 2266 | const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 2267 | 2267 | try self.writeInstRef(stream, extra.dest_type); |
| ... | ... | @@ -2273,7 +2273,7 @@ const Writer = struct { |
| 2273 | 2273 | |
| 2274 | 2274 | fn writeNode( |
| 2275 | 2275 | self: *Writer, |
| 2276 | stream: *std.io.Writer, | |
| 2276 | stream: *std.Io.Writer, | |
| 2277 | 2277 | inst: Zir.Inst.Index, |
| 2278 | 2278 | ) Error!void { |
| 2279 | 2279 | const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node; |
| ... | ... | @@ -2283,7 +2283,7 @@ const Writer = struct { |
| 2283 | 2283 | |
| 2284 | 2284 | fn writeStrTok( |
| 2285 | 2285 | self: *Writer, |
| 2286 | stream: *std.io.Writer, | |
| 2286 | stream: *std.Io.Writer, | |
| 2287 | 2287 | inst: Zir.Inst.Index, |
| 2288 | 2288 | ) Error!void { |
| 2289 | 2289 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| ... | ... | @@ -2292,7 +2292,7 @@ const Writer = struct { |
| 2292 | 2292 | try self.writeSrcTok(stream, inst_data.src_tok); |
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 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 { | |
| 2296 | 2296 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op; |
| 2297 | 2297 | const str = inst_data.getStr(self.code); |
| 2298 | 2298 | try self.writeInstRef(stream, inst_data.operand); |
| ... | ... | @@ -2301,7 +2301,7 @@ const Writer = struct { |
| 2301 | 2301 | |
| 2302 | 2302 | fn writeFunc( |
| 2303 | 2303 | self: *Writer, |
| 2304 | stream: *std.io.Writer, | |
| 2304 | stream: *std.Io.Writer, | |
| 2305 | 2305 | inst: Zir.Inst.Index, |
| 2306 | 2306 | inferred_error_set: bool, |
| 2307 | 2307 | ) !void { |
| ... | ... | @@ -2352,7 +2352,7 @@ const Writer = struct { |
| 2352 | 2352 | ); |
| 2353 | 2353 | } |
| 2354 | 2354 | |
| 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 { | |
| 2356 | 2356 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2357 | 2357 | const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 2358 | 2358 | |
| ... | ... | @@ -2411,7 +2411,7 @@ const Writer = struct { |
| 2411 | 2411 | ); |
| 2412 | 2412 | } |
| 2413 | 2413 | |
| 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 { | |
| 2415 | 2415 | const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 2416 | 2416 | const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small)); |
| 2417 | 2417 | |
| ... | ... | @@ -2434,7 +2434,7 @@ const Writer = struct { |
| 2434 | 2434 | try self.writeSrcNode(stream, extra.data.src_node); |
| 2435 | 2435 | } |
| 2436 | 2436 | |
| 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 { | |
| 2438 | 2438 | const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); |
| 2439 | 2439 | const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len); |
| 2440 | 2440 | try self.writeBracedBody(stream, body); |
| ... | ... | @@ -2447,7 +2447,7 @@ const Writer = struct { |
| 2447 | 2447 | try stream.writeAll("])"); |
| 2448 | 2448 | } |
| 2449 | 2449 | |
| 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 { | |
| 2451 | 2451 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2452 | 2452 | const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index); |
| 2453 | 2453 | const body = self.code.bodySlice(extra.end, extra.data.body_len); |
| ... | ... | @@ -2458,7 +2458,7 @@ const Writer = struct { |
| 2458 | 2458 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2459 | 2459 | } |
| 2460 | 2460 | |
| 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 { | |
| 2462 | 2462 | const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type; |
| 2463 | 2463 | const prefix: u8 = switch (int_type.signedness) { |
| 2464 | 2464 | .signed => 'i', |
| ... | ... | @@ -2468,7 +2468,7 @@ const Writer = struct { |
| 2468 | 2468 | try self.writeSrcNode(stream, int_type.src_node); |
| 2469 | 2469 | } |
| 2470 | 2470 | |
| 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 { | |
| 2472 | 2472 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index; |
| 2473 | 2473 | |
| 2474 | 2474 | try self.writeInstRef(stream, inst_data.operand); |
| ... | ... | @@ -2476,7 +2476,7 @@ const Writer = struct { |
| 2476 | 2476 | try stream.writeAll(")"); |
| 2477 | 2477 | } |
| 2478 | 2478 | |
| 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 { | |
| 2480 | 2480 | const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data; |
| 2481 | 2481 | |
| 2482 | 2482 | try self.writeInstRef(stream, extra.block); |
| ... | ... | @@ -2486,7 +2486,7 @@ const Writer = struct { |
| 2486 | 2486 | try self.writeSrcNode(stream, extra.src_node); |
| 2487 | 2487 | } |
| 2488 | 2488 | |
| 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 { | |
| 2490 | 2490 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break"; |
| 2491 | 2491 | const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 2492 | 2492 | |
| ... | ... | @@ -2496,7 +2496,7 @@ const Writer = struct { |
| 2496 | 2496 | try stream.writeAll(")"); |
| 2497 | 2497 | } |
| 2498 | 2498 | |
| 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 { | |
| 2500 | 2500 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2501 | 2501 | |
| 2502 | 2502 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| ... | ... | @@ -2512,7 +2512,7 @@ const Writer = struct { |
| 2512 | 2512 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 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 { | |
| 2516 | 2516 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2517 | 2517 | |
| 2518 | 2518 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| ... | ... | @@ -2527,7 +2527,7 @@ const Writer = struct { |
| 2527 | 2527 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2528 | 2528 | } |
| 2529 | 2529 | |
| 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 { | |
| 2531 | 2531 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2532 | 2532 | |
| 2533 | 2533 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| ... | ... | @@ -2547,7 +2547,7 @@ const Writer = struct { |
| 2547 | 2547 | try self.writeSrcNode(stream, inst_data.src_node); |
| 2548 | 2548 | } |
| 2549 | 2549 | |
| 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 { | |
| 2551 | 2551 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; |
| 2552 | 2552 | try stream.writeAll(") "); |
| 2553 | 2553 | try self.writeSrcNode(stream, inst_data.src_node); |
| ... | ... | @@ -2555,7 +2555,7 @@ const Writer = struct { |
| 2555 | 2555 | |
| 2556 | 2556 | fn writeFuncCommon( |
| 2557 | 2557 | self: *Writer, |
| 2558 | stream: *std.io.Writer, | |
| 2558 | stream: *std.Io.Writer, | |
| 2559 | 2559 | inferred_error_set: bool, |
| 2560 | 2560 | var_args: bool, |
| 2561 | 2561 | is_noinline: bool, |
| ... | ... | @@ -2592,19 +2592,19 @@ const Writer = struct { |
| 2592 | 2592 | try self.writeSrcNode(stream, src_node); |
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 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 { | |
| 2596 | 2596 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 2597 | 2597 | try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 }); |
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 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 { | |
| 2601 | 2601 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer"; |
| 2602 | 2602 | const body = self.code.bodySlice(inst_data.index, inst_data.len); |
| 2603 | 2603 | try self.writeBracedBody(stream, body); |
| 2604 | 2604 | try stream.writeByte(')'); |
| 2605 | 2605 | } |
| 2606 | 2606 | |
| 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 { | |
| 2608 | 2608 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code; |
| 2609 | 2609 | const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; |
| 2610 | 2610 | |
| ... | ... | @@ -2617,7 +2617,7 @@ const Writer = struct { |
| 2617 | 2617 | try stream.writeByte(')'); |
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 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 { | |
| 2621 | 2621 | const decl = self.code.getDeclaration(inst); |
| 2622 | 2622 | |
| 2623 | 2623 | const prev_parent_decl_node = self.parent_decl_node; |
| ... | ... | @@ -2673,26 +2673,26 @@ const Writer = struct { |
| 2673 | 2673 | try self.writeSrcNode(stream, .zero); |
| 2674 | 2674 | } |
| 2675 | 2675 | |
| 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 { | |
| 2677 | 2677 | try stream.print("{d})) ", .{extended.small}); |
| 2678 | 2678 | const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand))); |
| 2679 | 2679 | try self.writeSrcNode(stream, src_node); |
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 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 { | |
| 2683 | 2683 | const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small); |
| 2684 | 2684 | try stream.print("{s})) ", .{@tagName(val)}); |
| 2685 | 2685 | const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand))); |
| 2686 | 2686 | try self.writeSrcNode(stream, src_node); |
| 2687 | 2687 | } |
| 2688 | 2688 | |
| 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 { | |
| 2690 | 2690 | const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small); |
| 2691 | 2691 | try self.writeInstRef(stream, @enumFromInt(extended.operand)); |
| 2692 | 2692 | try stream.print(", {s}))", .{@tagName(op)}); |
| 2693 | 2693 | } |
| 2694 | 2694 | |
| 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 { | |
| 2696 | 2696 | if (ref == .none) { |
| 2697 | 2697 | return stream.writeAll(".none"); |
| 2698 | 2698 | } else if (ref.toIndex()) |i| { |
| ... | ... | @@ -2703,12 +2703,12 @@ const Writer = struct { |
| 2703 | 2703 | } |
| 2704 | 2704 | } |
| 2705 | 2705 | |
| 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 { | |
| 2707 | 2707 | _ = self; |
| 2708 | 2708 | return stream.print("%{d}", .{@intFromEnum(inst)}); |
| 2709 | 2709 | } |
| 2710 | 2710 | |
| 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 { | |
| 2712 | 2712 | if (captures_len == 0) { |
| 2713 | 2713 | try stream.writeAll("{}"); |
| 2714 | 2714 | return extra_index; |
| ... | ... | @@ -2728,7 +2728,7 @@ const Writer = struct { |
| 2728 | 2728 | return extra_index + 2 * captures_len; |
| 2729 | 2729 | } |
| 2730 | 2730 | |
| 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 { | |
| 2732 | 2732 | switch (capture.unwrap()) { |
| 2733 | 2733 | .nested => |i| return stream.print("[{d}]", .{i}), |
| 2734 | 2734 | .instruction => |inst| return self.writeInstIndex(stream, inst), |
| ... | ... | @@ -2747,7 +2747,7 @@ const Writer = struct { |
| 2747 | 2747 | |
| 2748 | 2748 | fn writeOptionalInstRef( |
| 2749 | 2749 | self: *Writer, |
| 2750 | stream: *std.io.Writer, | |
| 2750 | stream: *std.Io.Writer, | |
| 2751 | 2751 | prefix: []const u8, |
| 2752 | 2752 | inst: Zir.Inst.Ref, |
| 2753 | 2753 | ) !void { |
| ... | ... | @@ -2758,7 +2758,7 @@ const Writer = struct { |
| 2758 | 2758 | |
| 2759 | 2759 | fn writeOptionalInstRefOrBody( |
| 2760 | 2760 | self: *Writer, |
| 2761 | stream: *std.io.Writer, | |
| 2761 | stream: *std.Io.Writer, | |
| 2762 | 2762 | prefix: []const u8, |
| 2763 | 2763 | ref: Zir.Inst.Ref, |
| 2764 | 2764 | body: []const Zir.Inst.Index, |
| ... | ... | @@ -2776,7 +2776,7 @@ const Writer = struct { |
| 2776 | 2776 | |
| 2777 | 2777 | fn writeFlag( |
| 2778 | 2778 | self: *Writer, |
| 2779 | stream: *std.io.Writer, | |
| 2779 | stream: *std.Io.Writer, | |
| 2780 | 2780 | name: []const u8, |
| 2781 | 2781 | flag: bool, |
| 2782 | 2782 | ) !void { |
| ... | ... | @@ -2785,7 +2785,7 @@ const Writer = struct { |
| 2785 | 2785 | try stream.writeAll(name); |
| 2786 | 2786 | } |
| 2787 | 2787 | |
| 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 { | |
| 2789 | 2789 | const tree = self.tree orelse return; |
| 2790 | 2790 | const abs_node = src_node.toAbsolute(self.parent_decl_node); |
| 2791 | 2791 | const src_span = tree.nodeToSpan(abs_node); |
| ... | ... | @@ -2797,7 +2797,7 @@ const Writer = struct { |
| 2797 | 2797 | }); |
| 2798 | 2798 | } |
| 2799 | 2799 | |
| 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 { | |
| 2801 | 2801 | const tree = self.tree orelse return; |
| 2802 | 2802 | const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node)); |
| 2803 | 2803 | const span_start = tree.tokenStart(abs_tok); |
| ... | ... | @@ -2810,7 +2810,7 @@ const Writer = struct { |
| 2810 | 2810 | }); |
| 2811 | 2811 | } |
| 2812 | 2812 | |
| 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 { | |
| 2814 | 2814 | const tree = self.tree orelse return; |
| 2815 | 2815 | const span_start = tree.tokenStart(src_tok); |
| 2816 | 2816 | const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len)); |
| ... | ... | @@ -2822,15 +2822,15 @@ const Writer = struct { |
| 2822 | 2822 | }); |
| 2823 | 2823 | } |
| 2824 | 2824 | |
| 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 { | |
| 2826 | 2826 | try self.writeBracedBodyConditional(stream, body, self.recurse_decls); |
| 2827 | 2827 | } |
| 2828 | 2828 | |
| 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 { | |
| 2830 | 2830 | try self.writeBracedBodyConditional(stream, body, self.recurse_blocks); |
| 2831 | 2831 | } |
| 2832 | 2832 | |
| 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 { | |
| 2834 | 2834 | if (body.len == 0) { |
| 2835 | 2835 | try stream.writeAll("{}"); |
| 2836 | 2836 | } else if (enabled) { |
| ... | ... | @@ -2859,7 +2859,7 @@ const Writer = struct { |
| 2859 | 2859 | } |
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 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 { | |
| 2863 | 2863 | for (body) |inst| { |
| 2864 | 2864 | try stream.splatByteAll(' ', self.indent); |
| 2865 | 2865 | try stream.print("%{d} ", .{@intFromEnum(inst)}); |
| ... | ... | @@ -2868,7 +2868,7 @@ const Writer = struct { |
| 2868 | 2868 | } |
| 2869 | 2869 | } |
| 2870 | 2870 | |
| 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 { | |
| 2872 | 2872 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; |
| 2873 | 2873 | const extra = self.code.extraData(Zir.Inst.Import, inst_data.payload_index).data; |
| 2874 | 2874 | try self.writeInstRef(stream, extra.res_ty); |
src/print_zoir.zig+1-1| ... | ... | @@ -113,4 +113,4 @@ const std = @import("std"); |
| 113 | 113 | const assert = std.debug.assert; |
| 114 | 114 | const Allocator = std.mem.Allocator; |
| 115 | 115 | const Zoir = std.zig.Zoir; |
| 116 | const Writer = std.io.Writer; | |
| 116 | const Writer = std.Io.Writer; |
test/src/Cases.zig+1-1| ... | ... | @@ -386,7 +386,7 @@ fn addFromDirInner( |
| 386 | 386 | current_file.* = filename; |
| 387 | 387 | |
| 388 | 388 | const max_file_size = 10 * 1024 * 1024; |
| 389 | const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, .@"1", 0); | |
| 389 | const src = try iterable_dir.readFileAllocOptions(filename, ctx.arena, .limited(max_file_size), .@"1", 0); | |
| 390 | 390 | |
| 391 | 391 | // Parse the manifest |
| 392 | 392 | var manifest = try TestManifest.parse(ctx.arena, src); |
test/src/check-stack-trace.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ pub fn main() !void { |
| 13 | 13 | const input_path = args[1]; |
| 14 | 14 | const optimize_mode_text = args[2]; |
| 15 | 15 | |
| 16 | const input_bytes = try std.fs.cwd().readFileAlloc(arena, input_path, 5 * 1024 * 1024); | |
| 16 | const input_bytes = try std.fs.cwd().readFileAlloc(input_path, arena, .limited(5 * 1024 * 1024)); | |
| 17 | 17 | const optimize_mode = std.meta.stringToEnum(std.builtin.OptimizeMode, optimize_mode_text).?; |
| 18 | 18 | |
| 19 | 19 | var stderr = input_bytes; |
test/standalone/child_process/main.zig+2-1| ... | ... | @@ -32,7 +32,8 @@ pub fn main() !void { |
| 32 | 32 | |
| 33 | 33 | const hello_stdout = "hello from stdout"; |
| 34 | 34 | var buf: [hello_stdout.len]u8 = undefined; |
| 35 | const n = try child.stdout.?.deprecatedReader().readAll(&buf); | |
| 35 | var stdout_reader = child.stdout.?.readerStreaming(&.{}); | |
| 36 | const n = try stdout_reader.interface.readSliceShort(&buf); | |
| 36 | 37 | if (!std.mem.eql(u8, buf[0..n], hello_stdout)) { |
| 37 | 38 | testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout }); |
| 38 | 39 | } |
test/standalone/cmakedefine/check.zig+2-2| ... | ... | @@ -9,8 +9,8 @@ pub fn main() !void { |
| 9 | 9 | const actual_path = args[1]; |
| 10 | 10 | const expected_path = args[2]; |
| 11 | 11 | |
| 12 | const actual = try std.fs.cwd().readFileAlloc(arena, actual_path, 1024 * 1024); | |
| 13 | const expected = try std.fs.cwd().readFileAlloc(arena, expected_path, 1024 * 1024); | |
| 12 | const actual = try std.fs.cwd().readFileAlloc(actual_path, arena, .limited(1024 * 1024)); | |
| 13 | const expected = try std.fs.cwd().readFileAlloc(expected_path, arena, .limited(1024 * 1024)); | |
| 14 | 14 | |
| 15 | 15 | // The actual output starts with a comment which we should strip out before comparing. |
| 16 | 16 | const comment_str = "/* This file was generated by ConfigHeader using the Zig Build System. */\n"; |
test/standalone/entry_point/check_differ.zig+2-2| ... | ... | @@ -6,8 +6,8 @@ pub fn main() !void { |
| 6 | 6 | const args = try std.process.argsAlloc(arena); |
| 7 | 7 | if (args.len != 3) return error.BadUsage; // usage: 'check_differ <path a> <path b>' |
| 8 | 8 | |
| 9 | const contents_1 = try std.fs.cwd().readFileAlloc(arena, args[1], 1024 * 1024 * 64); // 64 MiB ought to be plenty | |
| 10 | const contents_2 = try std.fs.cwd().readFileAlloc(arena, args[2], 1024 * 1024 * 64); // 64 MiB ought to be plenty | |
| 9 | const contents_1 = try std.fs.cwd().readFileAlloc(args[1], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty | |
| 10 | const contents_2 = try std.fs.cwd().readFileAlloc(args[2], arena, .limited(1024 * 1024 * 64)); // 64 MiB ought to be plenty | |
| 11 | 11 | |
| 12 | 12 | if (std.mem.eql(u8, contents_1, contents_2)) { |
| 13 | 13 | return error.FilesMatch; |
test/standalone/simple/cat/main.zig+1-2| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const io = std.io; | |
| 3 | 2 | const fs = std.fs; |
| 4 | 3 | const mem = std.mem; |
| 5 | 4 | const warn = std.log.warn; |
| ... | ... | @@ -16,7 +15,7 @@ pub fn main() !void { |
| 16 | 15 | var catted_anything = false; |
| 17 | 16 | var stdout_writer = std.fs.File.stdout().writerStreaming(&.{}); |
| 18 | 17 | const stdout = &stdout_writer.interface; |
| 19 | var stdin_reader = std.fs.File.stdin().reader(&.{}); | |
| 18 | var stdin_reader = std.fs.File.stdin().readerStreaming(&.{}); | |
| 20 | 19 | |
| 21 | 20 | const cwd = fs.cwd(); |
| 22 | 21 |
tools/docgen.zig+4-5| ... | ... | @@ -77,7 +77,8 @@ pub fn main() !void { |
| 77 | 77 | var code_dir = try fs.cwd().openDir(code_dir_path, .{}); |
| 78 | 78 | defer code_dir.close(); |
| 79 | 79 | |
| 80 | const input_file_bytes = try in_file.deprecatedReader().readAllAlloc(arena, max_doc_file_size); | |
| 80 | var in_file_reader = in_file.reader(&.{}); | |
| 81 | const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size)); | |
| 81 | 82 | |
| 82 | 83 | var tokenizer = Tokenizer.init(input_path, input_file_bytes); |
| 83 | 84 | var toc = try genToc(arena, &tokenizer); |
| ... | ... | @@ -1039,10 +1040,8 @@ fn genHtml( |
| 1039 | 1040 | }); |
| 1040 | 1041 | defer allocator.free(out_basename); |
| 1041 | 1042 | |
| 1042 | const contents = code_dir.readFileAlloc(allocator, out_basename, std.math.maxInt(u32)) catch |err| { | |
| 1043 | return parseError(tokenizer, code.token, "unable to open '{s}': {s}", .{ | |
| 1044 | out_basename, @errorName(err), | |
| 1045 | }); | |
| 1043 | const contents = code_dir.readFileAlloc(out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| { | |
| 1044 | return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err }); | |
| 1046 | 1045 | }; |
| 1047 | 1046 | defer allocator.free(contents); |
| 1048 | 1047 |
tools/doctest.zig+1-1| ... | ... | @@ -70,7 +70,7 @@ pub fn main() !void { |
| 70 | 70 | const zig_path = opt_zig orelse fatal("missing zig compiler path (--zig)", .{}); |
| 71 | 71 | const cache_root = opt_cache_root orelse fatal("missing cache root path (--cache-root)", .{}); |
| 72 | 72 | |
| 73 | const source_bytes = try fs.cwd().readFileAlloc(arena, input_path, std.math.maxInt(u32)); | |
| 73 | const source_bytes = try fs.cwd().readFileAlloc(input_path, arena, .limited(std.math.maxInt(u32))); | |
| 74 | 74 | const code = try parseManifest(arena, source_bytes); |
| 75 | 75 | const source = stripManifest(source_bytes); |
| 76 | 76 |
tools/dump-cov.zig+2-3| ... | ... | @@ -38,10 +38,9 @@ pub fn main() !void { |
| 38 | 38 | defer debug_info.deinit(gpa); |
| 39 | 39 | |
| 40 | 40 | const cov_bytes = cov_path.root_dir.handle.readFileAllocOptions( |
| 41 | arena, | |
| 42 | 41 | cov_path.sub_path, |
| 43 | 1 << 30, | |
| 44 | null, | |
| 42 | arena, | |
| 43 | .limited(1 << 30), | |
| 45 | 44 | .of(SeenPcsHeader), |
| 46 | 45 | null, |
| 47 | 46 | ) catch |err| { |
tools/fetch_them_macos_headers.zig+3-3| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const fs = std.fs; |
| 3 | const io = std.io; | |
| 4 | 3 | const mem = std.mem; |
| 5 | 4 | const process = std.process; |
| 6 | 5 | const assert = std.debug.assert; |
| ... | ... | @@ -93,7 +92,7 @@ pub fn main() anyerror!void { |
| 93 | 92 | |
| 94 | 93 | var sdk_dir = try std.fs.cwd().openDir(sysroot_path, .{}); |
| 95 | 94 | defer sdk_dir.close(); |
| 96 | const sdk_info = try sdk_dir.readFileAlloc(allocator, "SDKSettings.json", std.math.maxInt(u32)); | |
| 95 | const sdk_info = try sdk_dir.readFileAlloc("SDKSettings.json", allocator, .limited(std.math.maxInt(u32))); | |
| 97 | 96 | |
| 98 | 97 | const parsed_json = try std.json.parseFromSlice(struct { |
| 99 | 98 | DefaultProperties: struct { MACOSX_DEPLOYMENT_TARGET: []const u8 }, |
| ... | ... | @@ -198,7 +197,8 @@ fn fetchTarget( |
| 198 | 197 | var dirs = std.StringHashMap(fs.Dir).init(arena); |
| 199 | 198 | try dirs.putNoClobber(".", dest_dir); |
| 200 | 199 | |
| 201 | const headers_list_str = try headers_list_file.deprecatedReader().readAllAlloc(arena, std.math.maxInt(usize)); | |
| 200 | var headers_list_file_reader = headers_list_file.reader(&.{}); | |
| 201 | const headers_list_str = try headers_list_file_reader.interface.allocRemaining(arena, .unlimited); | |
| 202 | 202 | const prefix = "/usr/include"; |
| 203 | 203 | |
| 204 | 204 | var it = mem.splitScalar(u8, headers_list_str, '\n'); |
tools/gen_spirv_spec.zig+15-15| ... | ... | @@ -136,7 +136,7 @@ fn readExtRegistry(exts: *std.array_list.Managed(Extension), dir: std.fs.Dir, su |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | fn readRegistry(comptime RegistryType: type, dir: std.fs.Dir, path: []const u8) !RegistryType { |
| 139 | const spec = try dir.readFileAlloc(allocator, path, std.math.maxInt(usize)); | |
| 139 | const spec = try dir.readFileAlloc(path, allocator, .unlimited); | |
| 140 | 140 | // Required for json parsing. |
| 141 | 141 | // TODO: ALI |
| 142 | 142 | @setEvalBranchQuota(10000); |
| ... | ... | @@ -189,7 +189,7 @@ fn tagPriorityScore(tag: []const u8) usize { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | fn render( |
| 192 | writer: *std.io.Writer, | |
| 192 | writer: *std.Io.Writer, | |
| 193 | 193 | registry: CoreRegistry, |
| 194 | 194 | extensions: []const Extension, |
| 195 | 195 | ) !void { |
| ... | ... | @@ -214,7 +214,7 @@ fn render( |
| 214 | 214 | \\ none, |
| 215 | 215 | \\ _, |
| 216 | 216 | \\ |
| 217 | \\ pub fn format(self: Id, writer: *std.io.Writer) std.io.Writer.Error!void { | |
| 217 | \\ pub fn format(self: Id, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 218 | 218 | \\ switch (self) { |
| 219 | 219 | \\ .none => try writer.writeAll("(none)"), |
| 220 | 220 | \\ else => try writer.print("%{d}", .{@intFromEnum(self)}), |
| ... | ... | @@ -327,7 +327,7 @@ fn render( |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | fn renderInstructionSet( |
| 330 | writer: *std.io.Writer, | |
| 330 | writer: *std.Io.Writer, | |
| 331 | 331 | core: CoreRegistry, |
| 332 | 332 | extensions: []const Extension, |
| 333 | 333 | all_operand_kinds: OperandKindMap, |
| ... | ... | @@ -362,7 +362,7 @@ fn renderInstructionSet( |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | fn renderInstructionsCase( |
| 365 | writer: *std.io.Writer, | |
| 365 | writer: *std.Io.Writer, | |
| 366 | 366 | set_name: []const u8, |
| 367 | 367 | instructions: []const Instruction, |
| 368 | 368 | all_operand_kinds: OperandKindMap, |
| ... | ... | @@ -409,7 +409,7 @@ fn renderInstructionsCase( |
| 409 | 409 | ); |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void { | |
| 412 | fn renderClass(writer: *std.Io.Writer, instructions: []const Instruction) !void { | |
| 413 | 413 | var class_map = std.StringArrayHashMap(void).init(allocator); |
| 414 | 414 | |
| 415 | 415 | for (instructions) |inst| { |
| ... | ... | @@ -427,7 +427,7 @@ fn renderClass(writer: *std.io.Writer, instructions: []const Instruction) !void |
| 427 | 427 | const Formatter = struct { |
| 428 | 428 | data: []const u8, |
| 429 | 429 | |
| 430 | fn format(f: Formatter, writer: *std.Io.Writer) std.io.Writer.Error!void { | |
| 430 | fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void { | |
| 431 | 431 | var id_buf: [128]u8 = undefined; |
| 432 | 432 | var fw: std.Io.Writer = .fixed(&id_buf); |
| 433 | 433 | for (f.data, 0..) |c, i| { |
| ... | ... | @@ -457,7 +457,7 @@ fn formatId(identifier: []const u8) std.fmt.Alt(Formatter, Formatter.format) { |
| 457 | 457 | return .{ .data = .{ .data = identifier } }; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !void { | |
| 460 | fn renderOperandKind(writer: *std.Io.Writer, operands: []const OperandKind) !void { | |
| 461 | 461 | try writer.writeAll( |
| 462 | 462 | \\pub const OperandKind = enum { |
| 463 | 463 | \\ opcode, |
| ... | ... | @@ -513,7 +513,7 @@ fn renderOperandKind(writer: *std.io.Writer, operands: []const OperandKind) !voi |
| 513 | 513 | try writer.writeAll("};\n}\n};\n"); |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void { | |
| 516 | fn renderEnumerant(writer: *std.Io.Writer, enumerant: Enumerant) !void { | |
| 517 | 517 | try writer.print(".{{.name = \"{s}\", .value = ", .{enumerant.enumerant}); |
| 518 | 518 | switch (enumerant.value) { |
| 519 | 519 | .bitflag => |flag| try writer.writeAll(flag), |
| ... | ... | @@ -530,7 +530,7 @@ fn renderEnumerant(writer: *std.io.Writer, enumerant: Enumerant) !void { |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | fn renderOpcodes( |
| 533 | writer: *std.io.Writer, | |
| 533 | writer: *std.Io.Writer, | |
| 534 | 534 | opcode_type_name: []const u8, |
| 535 | 535 | want_operands: bool, |
| 536 | 536 | instructions: []const Instruction, |
| ... | ... | @@ -629,7 +629,7 @@ fn renderOpcodes( |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | fn renderOperandKinds( |
| 632 | writer: *std.io.Writer, | |
| 632 | writer: *std.Io.Writer, | |
| 633 | 633 | kinds: []const OperandKind, |
| 634 | 634 | extended_structs: ExtendedStructSet, |
| 635 | 635 | ) !void { |
| ... | ... | @@ -643,7 +643,7 @@ fn renderOperandKinds( |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | fn renderValueEnum( |
| 646 | writer: *std.io.Writer, | |
| 646 | writer: *std.Io.Writer, | |
| 647 | 647 | enumeration: OperandKind, |
| 648 | 648 | extended_structs: ExtendedStructSet, |
| 649 | 649 | ) !void { |
| ... | ... | @@ -721,7 +721,7 @@ fn renderValueEnum( |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | fn renderBitEnum( |
| 724 | writer: *std.io.Writer, | |
| 724 | writer: *std.Io.Writer, | |
| 725 | 725 | enumeration: OperandKind, |
| 726 | 726 | extended_structs: ExtendedStructSet, |
| 727 | 727 | ) !void { |
| ... | ... | @@ -804,7 +804,7 @@ fn renderBitEnum( |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | fn renderOperand( |
| 807 | writer: *std.io.Writer, | |
| 807 | writer: *std.Io.Writer, | |
| 808 | 808 | kind: enum { |
| 809 | 809 | @"union", |
| 810 | 810 | instruction, |
| ... | ... | @@ -888,7 +888,7 @@ fn renderOperand( |
| 888 | 888 | try writer.writeAll(",\n"); |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | fn renderFieldName(writer: *std.io.Writer, operands: []const Operand, field_index: usize) !void { | |
| 891 | fn renderFieldName(writer: *std.Io.Writer, operands: []const Operand, field_index: usize) !void { | |
| 892 | 892 | const operand = operands[field_index]; |
| 893 | 893 | |
| 894 | 894 | derive_from_kind: { |
tools/gen_stubs.zig+2-3| ... | ... | @@ -299,10 +299,9 @@ pub fn main() !void { |
| 299 | 299 | |
| 300 | 300 | // Read the ELF header. |
| 301 | 301 | const elf_bytes = build_all_dir.readFileAllocOptions( |
| 302 | arena, | |
| 303 | 302 | libc_so_path, |
| 304 | 100 * 1024 * 1024, | |
| 305 | 1 * 1024 * 1024, | |
| 303 | arena, | |
| 304 | .limited(100 * 1024 * 1024), | |
| 306 | 305 | .of(elf.Elf64_Ehdr), |
| 307 | 306 | null, |
| 308 | 307 | ) catch |err| { |
tools/generate_JSONTestSuite.zig+1-1| ... | ... | @@ -32,7 +32,7 @@ pub fn main() !void { |
| 32 | 32 | }).lessThan); |
| 33 | 33 | |
| 34 | 34 | for (names.items) |name| { |
| 35 | const contents = try std.fs.cwd().readFileAlloc(allocator, name, 250001); | |
| 35 | const contents = try std.fs.cwd().readFileAlloc(name, allocator, .limited(250001)); | |
| 36 | 36 | try output.writeAll("test "); |
| 37 | 37 | try writeString(output, name); |
| 38 | 38 | try output.writeAll(" {\n try "); |
tools/generate_linux_syscalls.zig+1-1| ... | ... | @@ -248,7 +248,7 @@ pub fn main() !void { |
| 248 | 248 | try Io.Writer.flush(stdout); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | fn usage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void { | |
| 251 | fn usage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void { | |
| 252 | 252 | try w.print( |
| 253 | 253 | \\Usage: {s} /path/to/zig /path/to/linux |
| 254 | 254 | \\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux |
tools/incr-check.zig+2-2| ... | ... | @@ -52,7 +52,7 @@ pub fn main() !void { |
| 52 | 52 | const zig_exe = opt_zig_exe orelse fatal("missing path to zig\n{s}", .{usage}); |
| 53 | 53 | const input_file_name = opt_input_file_name orelse fatal("missing input file\n{s}", .{usage}); |
| 54 | 54 | |
| 55 | const input_file_bytes = try std.fs.cwd().readFileAlloc(arena, input_file_name, std.math.maxInt(u32)); | |
| 55 | const input_file_bytes = try std.fs.cwd().readFileAlloc(input_file_name, arena, .limited(std.math.maxInt(u32))); | |
| 56 | 56 | const case = try Case.parse(arena, input_file_bytes); |
| 57 | 57 | |
| 58 | 58 | // Check now: if there are any targets using the `cbe` backend, we need the lib dir. |
| ... | ... | @@ -226,7 +226,7 @@ const Eval = struct { |
| 226 | 226 | cc_child_args: *std.ArrayListUnmanaged([]const u8), |
| 227 | 227 | |
| 228 | 228 | const StreamEnum = enum { stdout, stderr }; |
| 229 | const Poller = std.io.Poller(StreamEnum); | |
| 229 | const Poller = std.Io.Poller(StreamEnum); | |
| 230 | 230 | |
| 231 | 231 | /// Currently this function assumes the previous updates have already been written. |
| 232 | 232 | fn write(eval: *Eval, update: Case.Update) void { |
tools/migrate_langref.zig+2-2| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const io = std.io; | |
| 4 | 3 | const fs = std.fs; |
| 5 | 4 | const print = std.debug.print; |
| 6 | 5 | const mem = std.mem; |
| ... | ... | @@ -29,7 +28,8 @@ pub fn main() !void { |
| 29 | 28 | var out_dir = try fs.cwd().openDir(fs.path.dirname(output_file).?, .{}); |
| 30 | 29 | defer out_dir.close(); |
| 31 | 30 | |
| 32 | const input_file_bytes = try in_file.deprecatedReader().readAllAlloc(arena, std.math.maxInt(u32)); | |
| 31 | var in_file_reader = in_file.reader(&.{}); | |
| 32 | const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .unlimited); | |
| 33 | 33 | |
| 34 | 34 | var tokenizer = Tokenizer.init(input_file, input_file_bytes); |
| 35 | 35 |
tools/process_headers.zig+1-1| ... | ... | @@ -254,7 +254,7 @@ pub fn main() !void { |
| 254 | 254 | .file, .sym_link => { |
| 255 | 255 | const rel_path = try std.fs.path.relative(allocator, target_include_dir, full_path); |
| 256 | 256 | const max_size = 2 * 1024 * 1024 * 1024; |
| 257 | const raw_bytes = try std.fs.cwd().readFileAlloc(allocator, full_path, max_size); | |
| 257 | const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, allocator, .limited(max_size)); | |
| 258 | 258 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 259 | 259 | total_bytes += raw_bytes.len; |
| 260 | 260 | const hash = try allocator.alloc(u8, 32); |
tools/update-linux-headers.zig+1-1| ... | ... | @@ -206,7 +206,7 @@ pub fn main() !void { |
| 206 | 206 | .file => { |
| 207 | 207 | const rel_path = try std.fs.path.relative(arena, target_include_dir, full_path); |
| 208 | 208 | const max_size = 2 * 1024 * 1024 * 1024; |
| 209 | const raw_bytes = try std.fs.cwd().readFileAlloc(arena, full_path, max_size); | |
| 209 | const raw_bytes = try std.fs.cwd().readFileAlloc(full_path, arena, .limited(max_size)); | |
| 210 | 210 | const trimmed = std.mem.trim(u8, raw_bytes, " \r\n\t"); |
| 211 | 211 | total_bytes += raw_bytes.len; |
| 212 | 212 | const hash = try arena.alloc(u8, 32); |
tools/update_clang_options.zig+1-1| ... | ... | @@ -965,7 +965,7 @@ fn printUsageAndExit(arg0: []const u8) noreturn { |
| 965 | 965 | std.process.exit(1); |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void { | |
| 968 | fn printUsage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void { | |
| 969 | 969 | try w.print( |
| 970 | 970 | \\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project |
| 971 | 971 | \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project |
tools/update_crc_catalog.zig+1-1| ... | ... | @@ -194,7 +194,7 @@ fn printUsageAndExit(arg0: []const u8) noreturn { |
| 194 | 194 | std.process.exit(1); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void { | |
| 197 | fn printUsage(w: *std.Io.Writer, arg0: []const u8) std.Io.Writer.Error!void { | |
| 198 | 198 | return w.print( |
| 199 | 199 | \\Usage: {s} /path/git/zig |
| 200 | 200 | \\ |
tools/update_glibc.zig+4-4| ... | ... | @@ -116,9 +116,9 @@ pub fn main() !void { |
| 116 | 116 | const max_file_size = 10 * 1024 * 1024; |
| 117 | 117 | |
| 118 | 118 | const generic_glibc_contents = generic_glibc_dir.readFileAlloc( |
| 119 | arena, | |
| 120 | 119 | entry.path, |
| 121 | max_file_size, | |
| 120 | arena, | |
| 121 | .limited(max_file_size), | |
| 122 | 122 | ) catch |err| switch (err) { |
| 123 | 123 | error.FileNotFound => continue, |
| 124 | 124 | else => |e| fatal("unable to load '{s}/include/{s}': {s}", .{ |
| ... | ... | @@ -126,9 +126,9 @@ pub fn main() !void { |
| 126 | 126 | }), |
| 127 | 127 | }; |
| 128 | 128 | const glibc_include_contents = include_dir.readFileAlloc( |
| 129 | arena, | |
| 130 | 129 | entry.path, |
| 131 | max_file_size, | |
| 130 | arena, | |
| 131 | .limited(max_file_size), | |
| 132 | 132 | ) catch |err| { |
| 133 | 133 | fatal("unable to load '{s}/include/{s}': {s}", .{ |
| 134 | 134 | dest_dir_path, entry.path, @errorName(err), |