authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 10:52:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:52-07:00
logf71d97e4cbb0e56213cb76657ad6c9edf6134868
treed920c6526826ab214b8c653e9a4a39dd6f3fb5a3
parentfac5fe57beb3ee34d5687da4258be22f0ed2f2f3

update compiler source to new APIs


18 files changed, 383 insertions(+), 379 deletions(-)

lib/std/fs/File.zig+2-1
......@@ -1921,9 +1921,10 @@ pub fn reader(file: File, buffer: []u8) Reader {
19211921/// Positional is more threadsafe, since the global seek position is not
19221922/// affected, but when such syscalls are not available, preemptively choosing
19231923/// `Reader.Mode.streaming` will skip a failed syscall.
1924pub fn readerStreaming(file: File) Reader {
1924pub fn readerStreaming(file: File, buffer: []u8) Reader {
19251925 return .{
19261926 .file = file,
1927 .interface = Reader.initInterface(buffer),
19271928 .mode = .streaming,
19281929 .seek_err = error.Unseekable,
19291930 };
lib/std/io/Writer.zig+12-7
......@@ -126,8 +126,8 @@ pub fn fixed(buffer: []u8) Writer {
126126 };
127127}
128128
129pub fn hashed(w: *Writer, hasher: anytype) Hashed(@TypeOf(hasher)) {
130 return .{ .out = w, .hasher = hasher };
129pub fn hashed(w: *Writer, hasher: anytype, buffer: []u8) Hashed(@TypeOf(hasher)) {
130 return .initHasher(w, hasher, buffer);
131131}
132132
133133pub const failing: Writer = .{
......@@ -1969,20 +1969,25 @@ pub fn Hashed(comptime Hasher: type) type {
19691969 return struct {
19701970 out: *Writer,
19711971 hasher: Hasher,
1972 interface: Writer,
1972 writer: Writer,
19731973
1974 pub fn init(out: *Writer) @This() {
1974 pub fn init(out: *Writer, buffer: []u8) @This() {
1975 return .initHasher(out, .{}, buffer);
1976 }
1977
1978 pub fn initHasher(out: *Writer, hasher: Hasher, buffer: []u8) @This() {
19751979 return .{
19761980 .out = out,
1977 .hasher = .{},
1978 .interface = .{
1981 .hasher = hasher,
1982 .writer = .{
1983 .buffer = buffer,
19791984 .vtable = &.{@This().drain},
19801985 },
19811986 };
19821987 }
19831988
19841989 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
1985 const this: *@This() = @alignCast(@fieldParentPtr("interface", w));
1990 const this: *@This() = @alignCast(@fieldParentPtr("writer", w));
19861991 if (data.len == 0) {
19871992 const buf = w.buffered();
19881993 try this.out.writeAll(buf);
src/Compilation.zig+1-1
......@@ -2689,7 +2689,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
26892689 const is_hit = man.hit() catch |err| switch (err) {
26902690 error.CacheCheckFailed => switch (man.diagnostic) {
26912691 .none => unreachable,
2692 .manifest_create, .manifest_read, .manifest_lock, .manifest_seek => |e| return comp.setMiscFailure(
2692 .manifest_create, .manifest_read, .manifest_lock => |e| return comp.setMiscFailure(
26932693 .check_whole_cache,
26942694 "failed to check cache: {s} {s}",
26952695 .{ @tagName(man.diagnostic), @errorName(e) },
src/InternPool.zig+29-30
......@@ -1881,23 +1881,23 @@ pub const NullTerminatedString = enum(u32) {
18811881 const FormatData = struct {
18821882 string: NullTerminatedString,
18831883 ip: *const InternPool,
1884 id: bool,
18841885 };
1885 fn format(
1886 data: FormatData,
1887 comptime specifier: []const u8,
1888 _: std.fmt.FormatOptions,
1889 writer: anytype,
1890 ) @TypeOf(writer).Error!void {
1886 fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
18911887 const slice = data.string.toSlice(data.ip);
1892 if (comptime std.mem.eql(u8, specifier, "")) {
1888 if (!data.id) {
18931889 try writer.writeAll(slice);
1894 } else if (comptime std.mem.eql(u8, specifier, "i")) {
1890 } else {
18951891 try writer.print("{f}", .{std.zig.fmtIdP(slice)});
1896 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
1892 }
1893 }
1894
1895 pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(FormatData, format) {
1896 return .{ .data = .{ .string = string, .ip = ip, .id = false } };
18971897 }
18981898
1899 pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(format) {
1900 return .{ .data = .{ .string = string, .ip = ip } };
1899 pub fn fmtId(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(FormatData, format) {
1900 return .{ .data = .{ .string = string, .ip = ip, .id = true } };
19011901 }
19021902
19031903 const debug_state = InternPool.debug_state;
......@@ -9750,7 +9750,7 @@ fn finishFuncInstance(
97509750 const fn_namespace = fn_owner_nav.analysis.?.namespace;
97519751
97529752 // TODO: improve this name
9753 const nav_name = try ip.getOrPutStringFmt(gpa, tid, "{}__anon_{d}", .{
9753 const nav_name = try ip.getOrPutStringFmt(gpa, tid, "{f}__anon_{d}", .{
97549754 fn_owner_nav.name.fmt(ip), @intFromEnum(func_index),
97559755 }, .no_embedded_nulls);
97569756 const nav_index = try ip.createNav(gpa, tid, .{
......@@ -11259,8 +11259,9 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
1125911259}
1126011260
1126111261fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11262 var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());
11263 const w = bw.writer();
11262 var buffer: [4096]u8 = undefined;
11263 const stderr_bw = std.debug.lockStderrWriter(&buffer);
11264 defer std.debug.unlockStderrWriter();
1126411265 for (ip.locals, 0..) |*local, tid| {
1126511266 const items = local.shared.items.view();
1126611267 for (
......@@ -11269,12 +11270,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
1126911270 0..,
1127011271 ) |tag, data, index| {
1127111272 const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip);
11272 try w.print("${d} = {s}(", .{ i, @tagName(tag) });
11273 try stderr_bw.print("${d} = {s}(", .{ i, @tagName(tag) });
1127311274 switch (tag) {
1127411275 .removed => {},
1127511276
11276 .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
11277 .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
11277 .simple_type => try stderr_bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
11278 .simple_value => try stderr_bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
1127811279
1127911280 .type_int_signed,
1128011281 .type_int_unsigned,
......@@ -11347,17 +11348,16 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
1134711348 .func_coerced,
1134811349 .union_value,
1134911350 .memoized_call,
11350 => try w.print("{d}", .{data}),
11351 => try stderr_bw.print("{d}", .{data}),
1135111352
1135211353 .opt_null,
1135311354 .type_slice,
1135411355 .only_possible_value,
11355 => try w.print("${d}", .{data}),
11356 => try stderr_bw.print("${d}", .{data}),
1135611357 }
11357 try w.writeAll(")\n");
11358 try stderr_bw.writeAll(")\n");
1135811359 }
1135911360 }
11360 try bw.flush();
1136111361}
1136211362
1136311363pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void {
......@@ -11369,9 +11369,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1136911369 defer arena_allocator.deinit();
1137011370 const arena = arena_allocator.allocator();
1137111371
11372 var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());
11373 const w = bw.writer();
11374
1137511372 var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;
1137611373 for (ip.locals, 0..) |*local, tid| {
1137711374 const items = local.shared.items.view().slice();
......@@ -11394,6 +11391,10 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1139411391 }
1139511392 }
1139611393
11394 var buffer: [4096]u8 = undefined;
11395 const stderr_bw = std.debug.lockStderrWriter(&buffer);
11396 defer std.debug.unlockStderrWriter();
11397
1139711398 const SortContext = struct {
1139811399 values: []std.ArrayListUnmanaged(Index),
1139911400 pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
......@@ -11405,23 +11406,21 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1140511406 var it = instances.iterator();
1140611407 while (it.next()) |entry| {
1140711408 const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav);
11408 try w.print("{} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
11409 try stderr_bw.print("{f} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
1140911410 for (entry.value_ptr.items) |index| {
1141011411 const unwrapped_index = index.unwrap(ip);
1141111412 const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip));
1141211413 const owner_nav = ip.getNav(func.owner_nav);
11413 try w.print(" {}: (", .{owner_nav.name.fmt(ip)});
11414 try stderr_bw.print(" {f}: (", .{owner_nav.name.fmt(ip)});
1141411415 for (func.comptime_args.get(ip)) |arg| {
1141511416 if (arg != .none) {
1141611417 const key = ip.indexToKey(arg);
11417 try w.print(" {} ", .{key});
11418 try stderr_bw.print(" {} ", .{key});
1141811419 }
1141911420 }
11420 try w.writeAll(")\n");
11421 try stderr_bw.writeAll(")\n");
1142111422 }
1142211423 }
11423
11424 try bw.flush();
1142511424}
1142611425
1142711426pub fn getNav(ip: *const InternPool, index: Nav.Index) Nav {
src/Package/Fetch/git.zig+5-5
......@@ -1320,7 +1320,7 @@ fn indexPackFirstPass(
13201320 index_entries: *std.AutoHashMapUnmanaged(Oid, IndexEntry),
13211321 pending_deltas: *std.ArrayListUnmanaged(IndexEntry),
13221322) !Oid {
1323 var pack_buffered_reader = std.io.bufferedReader(pack.reader());
1323 var pack_buffered_reader = std.io.bufferedReader(pack.deprecatedReader());
13241324 var pack_counting_reader = std.io.countingReader(pack_buffered_reader.reader());
13251325 var pack_hashed_reader = std.compress.hashedReader(pack_counting_reader.reader(), Oid.Hasher.init(format));
13261326 const pack_reader = pack_hashed_reader.reader();
......@@ -1400,7 +1400,7 @@ fn indexPackHashDelta(
14001400 if (cache.get(base_offset)) |base_object| break base_object;
14011401
14021402 try pack.seekTo(base_offset);
1403 base_header = try EntryHeader.read(format, pack.reader());
1403 base_header = try EntryHeader.read(format, pack.deprecatedReader());
14041404 switch (base_header) {
14051405 .ofs_delta => |ofs_delta| {
14061406 try delta_offsets.append(allocator, base_offset);
......@@ -1411,7 +1411,7 @@ fn indexPackHashDelta(
14111411 base_offset = (index_entries.get(ref_delta.base_object) orelse return null).offset;
14121412 },
14131413 else => {
1414 const base_data = try readObjectRaw(allocator, pack.reader(), base_header.uncompressedLength());
1414 const base_data = try readObjectRaw(allocator, pack.deprecatedReader(), base_header.uncompressedLength());
14151415 errdefer allocator.free(base_data);
14161416 const base_object: Object = .{ .type = base_header.objectType(), .data = base_data };
14171417 try cache.put(allocator, base_offset, base_object);
......@@ -1448,8 +1448,8 @@ fn resolveDeltaChain(
14481448
14491449 const delta_offset = delta_offsets[i];
14501450 try pack.seekTo(delta_offset);
1451 const delta_header = try EntryHeader.read(format, pack.reader());
1452 const delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength());
1451 const delta_header = try EntryHeader.read(format, pack.deprecatedReader());
1452 const delta_data = try readObjectRaw(allocator, pack.deprecatedReader(), delta_header.uncompressedLength());
14531453 defer allocator.free(delta_data);
14541454 var delta_stream = std.io.fixedBufferStream(delta_data);
14551455 const delta_reader = delta_stream.reader();
src/Zcu.zig+12-6
......@@ -4307,15 +4307,19 @@ pub fn navFileScope(zcu: *Zcu, nav: InternPool.Nav.Index) *File {
43074307 return zcu.fileByIndex(zcu.navFileScopeIndex(nav));
43084308}
43094309
4310pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(formatAnalUnit) {
4310pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(FormatAnalUnit, formatAnalUnit) {
43114311 return .{ .data = .{ .unit = unit, .zcu = zcu } };
43124312}
4313pub fn fmtDependee(zcu: *Zcu, d: InternPool.Dependee) std.fmt.Formatter(formatDependee) {
4313pub fn fmtDependee(zcu: *Zcu, d: InternPool.Dependee) std.fmt.Formatter(FormatDependee, formatDependee) {
43144314 return .{ .data = .{ .dependee = d, .zcu = zcu } };
43154315}
43164316
4317fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
4318 _ = .{ fmt, options };
4317const FormatAnalUnit = struct {
4318 unit: AnalUnit,
4319 zcu: *Zcu,
4320};
4321
4322fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Error!void {
43194323 const zcu = data.zcu;
43204324 const ip = &zcu.intern_pool;
43214325 switch (data.unit.unwrap()) {
......@@ -4338,8 +4342,10 @@ fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, comptime fmt: []co
43384342 .memoized_state => return writer.writeAll("memoized_state"),
43394343 }
43404344}
4341fn formatDependee(data: struct { dependee: InternPool.Dependee, zcu: *Zcu }, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
4342 _ = .{ fmt, options };
4345
4346const FormatDependee = struct { dependee: InternPool.Dependee, zcu: *Zcu };
4347
4348fn formatDependee(data: FormatDependee, writer: *std.io.Writer) std.io.Writer.Error!void {
43434349 const zcu = data.zcu;
43444350 const ip = &zcu.intern_pool;
43454351 switch (data.dependee) {
src/crash_report.zig+22-15
......@@ -80,18 +80,19 @@ fn dumpStatusReport() !void {
8080 var fba = std.heap.FixedBufferAllocator.init(&crash_heap);
8181 const allocator = fba.allocator();
8282
83 const stderr = std.fs.File.stderr().deprecatedWriter();
83 var stderr_fw = std.fs.File.stderr().writer(&.{});
84 const stderr = &stderr_fw.interface;
8485 const block: *Sema.Block = anal.block;
8586 const zcu = anal.sema.pt.zcu;
8687
8788 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse {
8889 const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool));
89 try stderr.print("Analyzing lost instruction in file '{}'. This should not happen!\n\n", .{file.path.fmt(zcu.comp)});
90 try stderr.print("Analyzing lost instruction in file '{f}'. This should not happen!\n\n", .{file.path.fmt(zcu.comp)});
9091 return;
9192 };
9293
9394 try stderr.writeAll("Analyzing ");
94 try stderr.print("Analyzing '{}'\n", .{file.path.fmt(zcu.comp)});
95 try stderr.print("Analyzing '{f}'\n", .{file.path.fmt(zcu.comp)});
9596
9697 print_zir.renderInstructionContext(
9798 allocator,
......@@ -107,7 +108,7 @@ fn dumpStatusReport() !void {
107108 };
108109 try stderr.print(
109110 \\ For full context, use the command
110 \\ zig ast-check -t {}
111 \\ zig ast-check -t {f}
111112 \\
112113 \\
113114 , .{file.path.fmt(zcu.comp)});
......@@ -116,7 +117,7 @@ fn dumpStatusReport() !void {
116117 while (parent) |curr| {
117118 fba.reset();
118119 const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool));
119 try stderr.print(" in {}\n", .{cur_block_file.path.fmt(zcu.comp)});
120 try stderr.print(" in {f}\n", .{cur_block_file.path.fmt(zcu.comp)});
120121 _, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse {
121122 try stderr.writeAll(" > [lost instruction; this should not happen]\n");
122123 parent = curr.parent;
......@@ -139,7 +140,7 @@ fn dumpStatusReport() !void {
139140 parent = curr.parent;
140141 }
141142
142 try stderr.writeAll("\n");
143 try stderr.writeByte('\n');
143144}
144145
145146var crash_heap: [16 * 4096]u8 = undefined;
......@@ -268,11 +269,12 @@ const StackContext = union(enum) {
268269 debug.dumpCurrentStackTrace(ct.ret_addr);
269270 },
270271 .exception => |context| {
271 debug.dumpStackTraceFromBase(context);
272 var stderr_fw = std.fs.File.stderr().writer(&.{});
273 const stderr = &stderr_fw.interface;
274 debug.dumpStackTraceFromBase(context, stderr);
272275 },
273276 .not_supported => {
274 const stderr = std.fs.File.stderr().deprecatedWriter();
275 stderr.writeAll("Stack trace not supported on this platform.\n") catch {};
277 std.fs.File.stderr().writeAll("Stack trace not supported on this platform.\n") catch {};
276278 },
277279 }
278280 }
......@@ -379,7 +381,8 @@ const PanicSwitch = struct {
379381
380382 state.recover_stage = .release_mutex;
381383
382 const stderr = std.fs.File.stderr().deprecatedWriter();
384 var stderr_fw = std.fs.File.stderr().writer(&.{});
385 const stderr = &stderr_fw.interface;
383386 if (builtin.single_threaded) {
384387 stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state});
385388 } else {
......@@ -406,7 +409,8 @@ const PanicSwitch = struct {
406409 recover(state, trace, stack, msg);
407410
408411 state.recover_stage = .release_mutex;
409 const stderr = std.fs.File.stderr().deprecatedWriter();
412 var stderr_fw = std.fs.File.stderr().writer(&.{});
413 const stderr = &stderr_fw.interface;
410414 stderr.writeAll("\nOriginal Error:\n") catch {};
411415 goTo(reportStack, .{state});
412416 }
......@@ -477,7 +481,8 @@ const PanicSwitch = struct {
477481 recover(state, trace, stack, msg);
478482
479483 state.recover_stage = .silent_abort;
480 const stderr = std.fs.File.stderr().deprecatedWriter();
484 var stderr_fw = std.fs.File.stderr().writer(&.{});
485 const stderr = &stderr_fw.interface;
481486 stderr.writeAll("Aborting...\n") catch {};
482487 goTo(abort, .{});
483488 }
......@@ -505,7 +510,8 @@ const PanicSwitch = struct {
505510 // lower the verbosity, and restore it at the end if we don't panic.
506511 state.recover_verbosity = .message_only;
507512
508 const stderr = std.fs.File.stderr().deprecatedWriter();
513 var stderr_fw = std.fs.File.stderr().writer(&.{});
514 const stderr = &stderr_fw.interface;
509515 stderr.writeAll("\nPanicked during a panic: ") catch {};
510516 stderr.writeAll(msg) catch {};
511517 stderr.writeAll("\nInner panic stack:\n") catch {};
......@@ -519,10 +525,11 @@ const PanicSwitch = struct {
519525 .message_only => {
520526 state.recover_verbosity = .silent;
521527
522 const stderr = std.fs.File.stderr().deprecatedWriter();
528 var stderr_fw = std.fs.File.stderr().writer(&.{});
529 const stderr = &stderr_fw.interface;
523530 stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {};
524531 stderr.writeAll(msg) catch {};
525 stderr.writeAll("\n") catch {};
532 stderr.writeByte('\n') catch {};
526533
527534 // If we succeed, restore all the way to dumping the stack.
528535 state.recover_verbosity = .message_and_stack;
src/dev.zig+4
......@@ -78,6 +78,7 @@ pub const Env = enum {
7878 .ast_gen,
7979 .sema,
8080 .legalize,
81 .c_compiler,
8182 .llvm_backend,
8283 .c_backend,
8384 .wasm_backend,
......@@ -127,6 +128,7 @@ pub const Env = enum {
127128 .clang_command,
128129 .cc_command,
129130 .translate_c_command,
131 .c_compiler,
130132 => true,
131133 else => false,
132134 },
......@@ -248,6 +250,8 @@ pub const Feature = enum {
248250 sema,
249251 legalize,
250252
253 c_compiler,
254
251255 llvm_backend,
252256 c_backend,
253257 wasm_backend,
src/link/MachO/Object.zig+4-11
......@@ -2660,24 +2660,17 @@ fn formatSymtab(
26602660 }
26612661}
26622662
2663pub fn fmtPath(self: Object) std.fmt.Formatter(formatPath) {
2663pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
26642664 return .{ .data = self };
26652665}
26662666
2667fn formatPath(
2668 object: Object,
2669 comptime unused_fmt_string: []const u8,
2670 options: std.fmt.FormatOptions,
2671 writer: anytype,
2672) !void {
2673 _ = unused_fmt_string;
2674 _ = options;
2667fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
26752668 if (object.in_archive) |ar| {
2676 try writer.print("{}({s})", .{
2669 try writer.print("{f}({s})", .{
26772670 @as(Path, ar.path), object.path.basename(),
26782671 });
26792672 } else {
2680 try writer.print("{}", .{@as(Path, object.path)});
2673 try writer.print("{f}", .{@as(Path, object.path)});
26812674 }
26822675}
26832676
src/link/MachO/file.zig+2-9
......@@ -10,18 +10,11 @@ pub const File = union(enum) {
1010 };
1111 }
1212
13 pub fn fmtPath(file: File) std.fmt.Formatter(formatPath) {
13 pub fn fmtPath(file: File) std.fmt.Formatter(File, formatPath) {
1414 return .{ .data = file };
1515 }
1616
17 fn formatPath(
18 file: File,
19 comptime unused_fmt_string: []const u8,
20 options: std.fmt.FormatOptions,
21 writer: anytype,
22 ) !void {
23 _ = unused_fmt_string;
24 _ = options;
17 fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
2518 switch (file) {
2619 .zig_object => |zo| try writer.writeAll(zo.basename),
2720 .internal => try writer.writeAll("internal"),
src/link/SpirV.zig+8-8
......@@ -117,7 +117,7 @@ pub fn updateNav(self: *SpirV, pt: Zcu.PerThread, nav: InternPool.Nav.Index) lin
117117 }
118118
119119 const ip = &pt.zcu.intern_pool;
120 log.debug("lowering nav {}({d})", .{ ip.getNav(nav).fqn.fmt(ip), nav });
120 log.debug("lowering nav {f}({d})", .{ ip.getNav(nav).fqn.fmt(ip), nav });
121121
122122 try self.object.updateNav(pt, nav);
123123}
......@@ -203,10 +203,10 @@ pub fn flush(
203203 // We need to export the list of error names somewhere so that we can pretty-print them in the
204204 // executor. This is not really an important thing though, so we can just dump it in any old
205205 // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name.
206 var error_info = std.ArrayList(u8).init(self.object.gpa);
206 var error_info: std.io.Writer.Allocating = .init(self.object.gpa);
207207 defer error_info.deinit();
208208
209 try error_info.appendSlice("zig_errors:");
209 error_info.writer.writeAll("zig_errors:") catch return error.OutOfMemory;
210210 const ip = &self.base.comp.zcu.?.intern_pool;
211211 for (ip.global_error_set.getNamesFromMainThread()) |name| {
212212 // Errors can contain pretty much any character - to encode them in a string we must escape
......@@ -214,9 +214,9 @@ pub fn flush(
214214 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
215215 // We're using : as separator, which is a reserved character.
216216
217 try error_info.append(':');
218 try std.Uri.Component.percentEncode(
219 error_info.writer(),
217 error_info.writer.writeByte(':') catch return error.OutOfMemory;
218 std.Uri.Component.percentEncode(
219 &error_info.writer,
220220 name.toSlice(ip),
221221 struct {
222222 fn isValidChar(c: u8) bool {
......@@ -226,10 +226,10 @@ pub fn flush(
226226 };
227227 }
228228 }.isValidChar,
229 );
229 ) catch return error.OutOfMemory;
230230 }
231231 try spv.sections.debug_strings.emit(gpa, .OpSourceExtension, .{
232 .extension = error_info.items,
232 .extension = error_info.getWritten(),
233233 });
234234
235235 const module = try spv.finalize(arena);
src/link/SpirV/deduplicate.zig+1-1
......@@ -110,7 +110,7 @@ const ModuleInfo = struct {
110110 .TypeDeclaration, .ConstantCreation => {
111111 const entry = try entities.getOrPut(result_id);
112112 if (entry.found_existing) {
113 log.err("type or constant {} has duplicate definition", .{result_id});
113 log.err("type or constant {f} has duplicate definition", .{result_id});
114114 return error.DuplicateId;
115115 }
116116 entry.value_ptr.* = entity;
src/link/SpirV/lower_invocation_globals.zig+9-9
......@@ -92,7 +92,7 @@ const ModuleInfo = struct {
9292 const entry_point: ResultId = @enumFromInt(inst.operands[1]);
9393 const entry = try entry_points.getOrPut(entry_point);
9494 if (entry.found_existing) {
95 log.err("Entry point type {} has duplicate definition", .{entry_point});
95 log.err("Entry point type {f} has duplicate definition", .{entry_point});
9696 return error.DuplicateId;
9797 }
9898 },
......@@ -103,7 +103,7 @@ const ModuleInfo = struct {
103103
104104 const entry = try fn_types.getOrPut(fn_type);
105105 if (entry.found_existing) {
106 log.err("Function type {} has duplicate definition", .{fn_type});
106 log.err("Function type {f} has duplicate definition", .{fn_type});
107107 return error.DuplicateId;
108108 }
109109
......@@ -135,7 +135,7 @@ const ModuleInfo = struct {
135135 },
136136 .OpFunction => {
137137 if (maybe_current_function) |current_function| {
138 log.err("OpFunction {} does not have an OpFunctionEnd", .{current_function});
138 log.err("OpFunction {f} does not have an OpFunctionEnd", .{current_function});
139139 return error.InvalidPhysicalFormat;
140140 }
141141
......@@ -154,7 +154,7 @@ const ModuleInfo = struct {
154154 };
155155 const entry = try functions.getOrPut(current_function);
156156 if (entry.found_existing) {
157 log.err("Function {} has duplicate definition", .{current_function});
157 log.err("Function {f} has duplicate definition", .{current_function});
158158 return error.DuplicateId;
159159 }
160160
......@@ -162,7 +162,7 @@ const ModuleInfo = struct {
162162 try callee_store.appendSlice(calls.keys());
163163
164164 const fn_type = fn_types.get(fn_ty_id) orelse {
165 log.err("Function {} has invalid OpFunction type", .{current_function});
165 log.err("Function {f} has invalid OpFunction type", .{current_function});
166166 return error.InvalidId;
167167 };
168168
......@@ -187,7 +187,7 @@ const ModuleInfo = struct {
187187 }
188188
189189 if (maybe_current_function) |current_function| {
190 log.err("OpFunction {} does not have an OpFunctionEnd", .{current_function});
190 log.err("OpFunction {f} does not have an OpFunctionEnd", .{current_function});
191191 return error.InvalidPhysicalFormat;
192192 }
193193
......@@ -222,7 +222,7 @@ const ModuleInfo = struct {
222222 seen: *std.DynamicBitSetUnmanaged,
223223 ) !void {
224224 const index = self.functions.getIndex(id) orelse {
225 log.err("function calls invalid function {}", .{id});
225 log.err("function calls invalid function {f}", .{id});
226226 return error.InvalidId;
227227 };
228228
......@@ -261,7 +261,7 @@ const ModuleInfo = struct {
261261 seen: *std.DynamicBitSetUnmanaged,
262262 ) !void {
263263 const index = self.invocation_globals.getIndex(id) orelse {
264 log.err("invalid invocation global {}", .{id});
264 log.err("invalid invocation global {f}", .{id});
265265 return error.InvalidId;
266266 };
267267
......@@ -276,7 +276,7 @@ const ModuleInfo = struct {
276276 }
277277
278278 const initializer = self.functions.get(info.initializer) orelse {
279 log.err("invocation global {} has invalid initializer {}", .{ id, info.initializer });
279 log.err("invocation global {f} has invalid initializer {f}", .{ id, info.initializer });
280280 return error.InvalidId;
281281 };
282282
src/link/SpirV/prune_unused.zig+4-4
......@@ -128,7 +128,7 @@ const ModuleInfo = struct {
128128 switch (inst.opcode) {
129129 .OpFunction => {
130130 if (maybe_current_function) |current_function| {
131 log.err("OpFunction {} does not have an OpFunctionEnd", .{current_function});
131 log.err("OpFunction {f} does not have an OpFunctionEnd", .{current_function});
132132 return error.InvalidPhysicalFormat;
133133 }
134134
......@@ -145,7 +145,7 @@ const ModuleInfo = struct {
145145 };
146146 const entry = try functions.getOrPut(current_function);
147147 if (entry.found_existing) {
148 log.err("Function {} has duplicate definition", .{current_function});
148 log.err("Function {f} has duplicate definition", .{current_function});
149149 return error.DuplicateId;
150150 }
151151
......@@ -163,7 +163,7 @@ const ModuleInfo = struct {
163163 }
164164
165165 if (maybe_current_function) |current_function| {
166 log.err("OpFunction {} does not have an OpFunctionEnd", .{current_function});
166 log.err("OpFunction {f} does not have an OpFunctionEnd", .{current_function});
167167 return error.InvalidPhysicalFormat;
168168 }
169169
......@@ -184,7 +184,7 @@ const AliveMarker = struct {
184184
185185 fn markAlive(self: *AliveMarker, result_id: ResultId) BinaryModule.ParseError!void {
186186 const index = self.info.result_id_to_code_offset.getIndex(result_id) orelse {
187 log.err("undefined result-id {}", .{result_id});
187 log.err("undefined result-id {f}", .{result_id});
188188 return error.InvalidId;
189189 };
190190
src/main.zig+78-70
......@@ -65,6 +65,9 @@ pub fn wasi_cwd() std.os.wasi.fd_t {
6565
6666const fatal = std.process.fatal;
6767
68/// This can be global since stdout is a singleton.
69var stdio_buffer: [4096]u8 = undefined;
70
6871/// Shaming all the locations that inappropriately use an O(N) search algorithm.
6972/// Please delete this and fix the compilation errors!
7073pub const @"bad O(N)" = void;
......@@ -352,7 +355,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
352355 } else if (mem.eql(u8, cmd, "env")) {
353356 dev.check(.env_command);
354357 verifyLibcxxCorrectlyLinked();
355 return @import("print_env.zig").cmdEnv(arena, cmd_args, fs.File.stdout().deprecatedWriter());
358 return @import("print_env.zig").cmdEnv(arena, cmd_args);
356359 } else if (mem.eql(u8, cmd, "reduce")) {
357360 return jitCmd(gpa, arena, cmd_args, .{
358361 .cmd_name = "reduce",
......@@ -1806,6 +1809,7 @@ fn buildOutputType(
18061809 } else manifest_file = arg;
18071810 },
18081811 .assembly, .assembly_with_cpp, .c, .cpp, .h, .hpp, .hm, .hmm, .ll, .bc, .m, .mm => {
1812 dev.check(.c_compiler);
18091813 try create_module.c_source_files.append(arena, .{
18101814 // Populated after module creation.
18111815 .owner = undefined,
......@@ -1816,6 +1820,7 @@ fn buildOutputType(
18161820 });
18171821 },
18181822 .rc => {
1823 dev.check(.win32_resource);
18191824 try create_module.rc_source_files.append(arena, .{
18201825 // Populated after module creation.
18211826 .owner = undefined,
......@@ -3301,6 +3306,7 @@ fn buildOutputType(
33013306 defer thread_pool.deinit();
33023307
33033308 for (create_module.c_source_files.items) |*src| {
3309 dev.check(.c_compiler);
33043310 if (!mem.eql(u8, src.src_path, "-")) continue;
33053311
33063312 const ext = src.ext orelse
......@@ -3325,13 +3331,17 @@ fn buildOutputType(
33253331 // for the hashing algorithm here and in the cache are the same.
33263332 // We are providing our own cache key, because this file has nothing
33273333 // to do with the cache manifest.
3328 var hasher = Cache.Hasher.init("0123456789abcdef");
3329 var w = io.multiWriter(.{ f.writer(), hasher.writer() });
3330 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();
3331 try fifo.pump(fs.File.stdin().reader(), w.writer());
3334 var file_writer = f.writer(&.{});
3335 var buffer: [1000]u8 = undefined;
3336 var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
3337 var stdin_reader = fs.File.stdin().readerStreaming(&.{});
3338 _ = hasher.writer.sendFileAll(&stdin_reader, .unlimited) catch |err| switch (err) {
3339 error.WriteFailed => fatal("failed to write {s}: {s}", .{ dump_path, file_writer.err.? }),
3340 else => fatal("failed to pipe stdin to {s}: {s}", .{ dump_path, err }),
3341 };
3342 try hasher.writer.flush();
33323343
3333 var bin_digest: Cache.BinDigest = undefined;
3334 hasher.final(&bin_digest);
3344 const bin_digest: Cache.BinDigest = hasher.hasher.finalResult();
33353345
33363346 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{
33373347 &bin_digest, ext.canonicalName(target),
......@@ -3505,7 +3515,7 @@ fn buildOutputType(
35053515 if (t.arch == target.cpu.arch and t.os == target.os.tag) {
35063516 // If there's a `glibc_min`, there's also an `os_ver`.
35073517 if (t.glibc_min) |glibc_min| {
3508 std.log.info("zig can provide libc for related target {s}-{s}.{}-{s}.{d}.{d}", .{
3518 std.log.info("zig can provide libc for related target {s}-{s}.{f}-{s}.{d}.{d}", .{
35093519 @tagName(t.arch),
35103520 @tagName(t.os),
35113521 t.os_ver.?,
......@@ -3514,7 +3524,7 @@ fn buildOutputType(
35143524 glibc_min.minor,
35153525 });
35163526 } else if (t.os_ver) |os_ver| {
3517 std.log.info("zig can provide libc for related target {s}-{s}.{}-{s}", .{
3527 std.log.info("zig can provide libc for related target {s}-{s}.{f}-{s}", .{
35183528 @tagName(t.arch),
35193529 @tagName(t.os),
35203530 os_ver,
......@@ -5480,7 +5490,7 @@ fn jitCmd(
54805490 defer comp.destroy();
54815491
54825492 if (options.server) {
5483 var server = std.zig.Server{
5493 var server: std.zig.Server = .{
54845494 .out = fs.File.stdout(),
54855495 .in = undefined, // won't be receiving messages
54865496 .receive_fifo = undefined, // won't be receiving messages
......@@ -6064,6 +6074,8 @@ fn cmdAstCheck(
60646074
60656075 const tree = try Ast.parse(arena, source, mode);
60666076
6077 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6078 const stdout_bw = &stdout_writer.interface;
60676079 switch (mode) {
60686080 .zig => {
60696081 const zir = try AstGen.generate(arena, tree);
......@@ -6106,31 +6118,30 @@ fn cmdAstCheck(
61066118 const extra_bytes = zir.extra.len * @sizeOf(u32);
61076119 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
61086120 zir.string_bytes.len * @sizeOf(u8);
6109 const stdout = fs.File.stdout();
6110 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
61116121 // zig fmt: off
6112 try stdout.deprecatedWriter().print(
6113 \\# Source bytes: {}
6114 \\# Tokens: {} ({})
6115 \\# AST Nodes: {} ({})
6116 \\# Total ZIR bytes: {}
6117 \\# Instructions: {d} ({})
6122 try stdout_bw.print(
6123 \\# Source bytes: {Bi}
6124 \\# Tokens: {} ({Bi})
6125 \\# AST Nodes: {} ({Bi})
6126 \\# Total ZIR bytes: {Bi}
6127 \\# Instructions: {d} ({Bi})
61186128 \\# String Table Bytes: {}
6119 \\# Extra Data Items: {d} ({})
6129 \\# Extra Data Items: {d} ({Bi})
61206130 \\
61216131 , .{
6122 fmtIntSizeBin(source.len),
6123 tree.tokens.len, fmtIntSizeBin(token_bytes),
6124 tree.nodes.len, fmtIntSizeBin(tree_bytes),
6125 fmtIntSizeBin(total_bytes),
6126 zir.instructions.len, fmtIntSizeBin(instruction_bytes),
6127 fmtIntSizeBin(zir.string_bytes.len),
6128 zir.extra.len, fmtIntSizeBin(extra_bytes),
6132 source.len,
6133 tree.tokens.len, token_bytes,
6134 tree.nodes.len, tree_bytes,
6135 total_bytes,
6136 zir.instructions.len, instruction_bytes,
6137 zir.string_bytes.len,
6138 zir.extra.len, extra_bytes,
61296139 });
61306140 // zig fmt: on
61316141 }
61326142
6133 try @import("print_zir.zig").renderAsTextToFile(arena, tree, zir, fs.File.stdout());
6143 try @import("print_zir.zig").renderAsText(arena, tree, zir, stdout_bw);
6144 try stdout_bw.flush();
61346145
61356146 if (zir.hasCompileErrors()) {
61366147 process.exit(1);
......@@ -6157,7 +6168,8 @@ fn cmdAstCheck(
61576168 fatal("-t option only available in builds of zig with debug extensions", .{});
61586169 }
61596170
6160 try @import("print_zoir.zig").renderToFile(zoir, arena, fs.File.stdout());
6171 try @import("print_zoir.zig").renderToWriter(zoir, arena, stdout_bw);
6172 try stdout_bw.flush();
61616173 return cleanExit();
61626174 },
61636175 }
......@@ -6185,8 +6197,7 @@ fn cmdDetectCpu(args: []const []const u8) !void {
61856197 const arg = args[i];
61866198 if (mem.startsWith(u8, arg, "-")) {
61876199 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6188 const stdout = fs.File.stdout().deprecatedWriter();
6189 try stdout.writeAll(detect_cpu_usage);
6200 try fs.File.stdout().writeAll(detect_cpu_usage);
61906201 return cleanExit();
61916202 } else if (mem.eql(u8, arg, "--llvm")) {
61926203 use_llvm = true;
......@@ -6278,11 +6289,11 @@ fn detectNativeCpuWithLLVM(
62786289}
62796290
62806291fn printCpu(cpu: std.Target.Cpu) !void {
6281 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());
6282 const stdout = bw.writer();
6292 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6293 const stdout_bw = &stdout_writer.interface;
62836294
62846295 if (cpu.model.llvm_name) |llvm_name| {
6285 try stdout.print("{s}\n", .{llvm_name});
6296 try stdout_bw.print("{s}\n", .{llvm_name});
62866297 }
62876298
62886299 const all_features = cpu.arch.allFeaturesList();
......@@ -6291,10 +6302,10 @@ fn printCpu(cpu: std.Target.Cpu) !void {
62916302 const index: std.Target.Cpu.Feature.Set.Index = @intCast(index_usize);
62926303 const is_enabled = cpu.features.isEnabled(index);
62936304 const plus_or_minus = "-+"[@intFromBool(is_enabled)];
6294 try stdout.print("{c}{s}\n", .{ plus_or_minus, llvm_name });
6305 try stdout_bw.print("{c}{s}\n", .{ plus_or_minus, llvm_name });
62956306 }
62966307
6297 try bw.flush();
6308 try stdout_bw.flush();
62986309}
62996310
63006311fn cmdDumpLlvmInts(
......@@ -6327,16 +6338,14 @@ fn cmdDumpLlvmInts(
63276338 const dl = tm.createTargetDataLayout();
63286339 const context = llvm.Context.create();
63296340
6330 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());
6331 const stdout = bw.writer();
6332
6341 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6342 const stdout_bw = &stdout_writer.interface;
63336343 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
63346344 const int_type = context.intType(bits);
63356345 const alignment = dl.abiAlignmentOfType(int_type);
6336 try stdout.print("LLVMABIAlignmentOfType(i{d}) == {d}\n", .{ bits, alignment });
6346 try stdout_bw.print("LLVMABIAlignmentOfType(i{d}) == {d}\n", .{ bits, alignment });
63376347 }
6338
6339 try bw.flush();
6348 try stdout_bw.flush();
63406349
63416350 return cleanExit();
63426351}
......@@ -6358,6 +6367,8 @@ fn cmdDumpZir(
63586367 defer f.close();
63596368
63606369 const zir = try Zcu.loadZirCache(arena, f);
6370 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6371 const stdout_bw = &stdout_writer.interface;
63616372
63626373 {
63636374 const instruction_bytes = zir.instructions.len *
......@@ -6367,25 +6378,24 @@ fn cmdDumpZir(
63676378 const extra_bytes = zir.extra.len * @sizeOf(u32);
63686379 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
63696380 zir.string_bytes.len * @sizeOf(u8);
6370 const stdout = fs.File.stdout();
6371 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
63726381 // zig fmt: off
6373 try stdout.deprecatedWriter().print(
6374 \\# Total ZIR bytes: {}
6375 \\# Instructions: {d} ({})
6376 \\# String Table Bytes: {}
6377 \\# Extra Data Items: {d} ({})
6382 try stdout_bw.print(
6383 \\# Total ZIR bytes: {Bi}
6384 \\# Instructions: {d} ({Bi})
6385 \\# String Table Bytes: {Bi}
6386 \\# Extra Data Items: {d} ({Bi})
63786387 \\
63796388 , .{
6380 fmtIntSizeBin(total_bytes),
6381 zir.instructions.len, fmtIntSizeBin(instruction_bytes),
6382 fmtIntSizeBin(zir.string_bytes.len),
6383 zir.extra.len, fmtIntSizeBin(extra_bytes),
6389 total_bytes,
6390 zir.instructions.len, instruction_bytes,
6391 zir.string_bytes.len,
6392 zir.extra.len, extra_bytes,
63846393 });
63856394 // zig fmt: on
63866395 }
63876396
6388 return @import("print_zir.zig").renderAsTextToFile(arena, null, zir, fs.File.stdout());
6397 try @import("print_zir.zig").renderAsText(arena, null, zir, stdout_bw);
6398 try stdout_bw.flush();
63896399}
63906400
63916401/// This is only enabled for debug builds.
......@@ -6443,19 +6453,19 @@ fn cmdChangelist(
64436453 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
64446454 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64456455
6446 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());
6447 const stdout = bw.writer();
6456 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6457 const stdout_bw = &stdout_writer.interface;
64486458 {
6449 try stdout.print("Instruction mappings:\n", .{});
6459 try stdout_bw.print("Instruction mappings:\n", .{});
64506460 var it = inst_map.iterator();
64516461 while (it.next()) |entry| {
6452 try stdout.print(" %{d} => %{d}\n", .{
6462 try stdout_bw.print(" %{d} => %{d}\n", .{
64536463 @intFromEnum(entry.key_ptr.*),
64546464 @intFromEnum(entry.value_ptr.*),
64556465 });
64566466 }
64576467 }
6458 try bw.flush();
6468 try stdout_bw.flush();
64596469}
64606470
64616471fn eatIntPrefix(arg: []const u8, base: u8) []const u8 {
......@@ -6717,13 +6727,10 @@ fn accessFrameworkPath(
67176727
67186728 for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| {
67196729 test_path.clearRetainingCapacity();
6720 try test_path.writer().print("{s}" ++ sep ++ "{s}.framework" ++ sep ++ "{s}{s}", .{
6721 framework_dir_path,
6722 framework_name,
6723 framework_name,
6724 ext,
6730 try test_path.print("{s}" ++ sep ++ "{s}.framework" ++ sep ++ "{s}{s}", .{
6731 framework_dir_path, framework_name, framework_name, ext,
67256732 });
6726 try checked_paths.writer().print("\n {s}", .{test_path.items});
6733 try checked_paths.print("\n {s}", .{test_path.items});
67276734 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
67286735 error.FileNotFound => continue,
67296736 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
......@@ -6793,8 +6800,7 @@ fn cmdFetch(
67936800 const arg = args[i];
67946801 if (mem.startsWith(u8, arg, "-")) {
67956802 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6796 const stdout = fs.File.stdout().deprecatedWriter();
6797 try stdout.writeAll(usage_fetch);
6803 try fs.File.stdout().writeAll(usage_fetch);
67986804 return cleanExit();
67996805 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
68006806 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
......@@ -6907,7 +6913,9 @@ fn cmdFetch(
69076913
69086914 const name = switch (save) {
69096915 .no => {
6910 try fs.File.stdout().deprecatedWriter().print("{s}\n", .{package_hash_slice});
6916 var stdout = fs.File.stdout().writer(&stdio_buffer);
6917 try stdout.interface.print("{s}\n", .{package_hash_slice});
6918 try stdout.interface.flush();
69116919 return cleanExit();
69126920 },
69136921 .yes, .exact => |name| name: {
......@@ -6943,7 +6951,7 @@ fn cmdFetch(
69436951 var saved_path_or_url = path_or_url;
69446952
69456953 if (fetch.latest_commit) |latest_commit| resolved: {
6946 const latest_commit_hex = try std.fmt.allocPrint(arena, "{}", .{latest_commit});
6954 const latest_commit_hex = try std.fmt.allocPrint(arena, "{f}", .{latest_commit});
69476955
69486956 var uri = try std.Uri.parse(path_or_url);
69496957
......@@ -6956,7 +6964,7 @@ fn cmdFetch(
69566964 std.log.info("resolved ref '{s}' to commit {s}", .{ target_ref, latest_commit_hex });
69576965
69586966 // include the original refspec in a query parameter, could be used to check for updates
6959 uri.query = .{ .percent_encoded = try std.fmt.allocPrint(arena, "ref={%}", .{fragment}) };
6967 uri.query = .{ .percent_encoded = try std.fmt.allocPrint(arena, "ref={f%}", .{fragment}) };
69606968 } else {
69616969 std.log.info("resolved to commit {s}", .{latest_commit_hex});
69626970 }
......@@ -6965,7 +6973,7 @@ fn cmdFetch(
69656973 uri.fragment = .{ .raw = latest_commit_hex };
69666974
69676975 switch (save) {
6968 .yes => saved_path_or_url = try std.fmt.allocPrint(arena, "{}", .{uri}),
6976 .yes => saved_path_or_url = try std.fmt.allocPrint(arena, "{f}", .{uri}),
69696977 .no, .exact => {}, // keep the original URL
69706978 }
69716979 }
src/print_env.zig+2-2
......@@ -4,7 +4,7 @@ const introspect = @import("introspect.zig");
44const Allocator = std.mem.Allocator;
55const fatal = std.process.fatal;
66
7pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
7pub fn cmdEnv(arena: Allocator, args: []const []const u8) !void {
88 _ = args;
99 const cwd_path = try introspect.getResolvedCwd(arena);
1010 const self_exe_path = try std.fs.selfExePathAlloc(arena);
......@@ -21,7 +21,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Wr
2121 const host = try std.zig.system.resolveTargetQuery(.{});
2222 const triple = try host.zigTriple(arena);
2323
24 var bw = std.io.bufferedWriter(stdout);
24 var bw = std.io.bufferedWriter(std.fs.File.stdout().deprecatedWriter());
2525 const w = bw.writer();
2626
2727 var jws = std.json.writeStream(w, .{ .whitespace = .indent_1 });
src/print_zir.zig+169-175
......@@ -9,13 +9,8 @@ const Zir = std.zig.Zir;
99const Zcu = @import("Zcu.zig");
1010const LazySrcLoc = Zcu.LazySrcLoc;
1111
12/// Write human-readable, debug formatted ZIR code to a file.
13pub fn renderAsTextToFile(
14 gpa: Allocator,
15 tree: ?Ast,
16 zir: Zir,
17 fs_file: std.fs.File,
18) !void {
12/// Write human-readable, debug formatted ZIR code.
13pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.io.Writer) !void {
1914 var arena = std.heap.ArenaAllocator.init(gpa);
2015 defer arena.deinit();
2116
......@@ -30,16 +25,13 @@ pub fn renderAsTextToFile(
3025 .recurse_blocks = true,
3126 };
3227
33 var raw_stream = std.io.bufferedWriter(fs_file.deprecatedWriter());
34 const stream = raw_stream.writer();
35
3628 const main_struct_inst: Zir.Inst.Index = .main_struct_inst;
37 try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)});
38 try writer.writeInstToStream(stream, main_struct_inst);
39 try stream.writeAll("\n");
29 try bw.print("%{d} ", .{@intFromEnum(main_struct_inst)});
30 try writer.writeInstToStream(bw, main_struct_inst);
31 try bw.writeAll("\n");
4032 const imports_index = zir.extra[@intFromEnum(Zir.ExtraIndex.imports)];
4133 if (imports_index != 0) {
42 try stream.writeAll("Imports:\n");
34 try bw.writeAll("Imports:\n");
4335
4436 const extra = zir.extraData(Zir.Inst.Imports, imports_index);
4537 var extra_index = extra.end;
......@@ -49,15 +41,13 @@ pub fn renderAsTextToFile(
4941 extra_index = item.end;
5042
5143 const import_path = zir.nullTerminatedString(item.data.name);
52 try stream.print(" @import(\"{f}\") ", .{
44 try bw.print(" @import(\"{f}\") ", .{
5345 std.zig.fmtString(import_path),
5446 });
55 try writer.writeSrcTokAbs(stream, item.data.token);
56 try stream.writeAll("\n");
47 try writer.writeSrcTokAbs(bw, item.data.token);
48 try bw.writeAll("\n");
5749 }
5850 }
59
60 try raw_stream.flush();
6151}
6252
6353pub fn renderInstructionContext(
......@@ -67,7 +57,7 @@ pub fn renderInstructionContext(
6757 scope_file: *Zcu.File,
6858 parent_decl_node: Ast.Node.Index,
6959 indent: u32,
70 stream: anytype,
60 bw: *std.io.Writer,
7161) !void {
7262 var arena = std.heap.ArenaAllocator.init(gpa);
7363 defer arena.deinit();
......@@ -83,13 +73,13 @@ pub fn renderInstructionContext(
8373 .recurse_blocks = true,
8474 };
8575
86 try writer.writeBody(stream, block[0..block_index]);
87 try stream.writeByteNTimes(' ', writer.indent - 2);
88 try stream.print("> %{d} ", .{@intFromEnum(block[block_index])});
89 try writer.writeInstToStream(stream, block[block_index]);
90 try stream.writeByte('\n');
76 try writer.writeBody(bw, block[0..block_index]);
77 try bw.splatByteAll(' ', writer.indent - 2);
78 try bw.print("> %{d} ", .{@intFromEnum(block[block_index])});
79 try writer.writeInstToStream(bw, block[block_index]);
80 try bw.writeByte('\n');
9181 if (block_index + 1 < block.len) {
92 try writer.writeBody(stream, block[block_index + 1 ..]);
82 try writer.writeBody(bw, block[block_index + 1 ..]);
9383 }
9484}
9585
......@@ -99,7 +89,7 @@ pub fn renderSingleInstruction(
9989 scope_file: *Zcu.File,
10090 parent_decl_node: Ast.Node.Index,
10191 indent: u32,
102 stream: anytype,
92 bw: *std.io.Writer,
10393) !void {
10494 var arena = std.heap.ArenaAllocator.init(gpa);
10595 defer arena.deinit();
......@@ -115,8 +105,8 @@ pub fn renderSingleInstruction(
115105 .recurse_blocks = false,
116106 };
117107
118 try stream.print("%{d} ", .{@intFromEnum(inst)});
119 try writer.writeInstToStream(stream, inst);
108 try bw.print("%{d} ", .{@intFromEnum(inst)});
109 try writer.writeInstToStream(bw, inst);
120110}
121111
122112const Writer = struct {
......@@ -186,11 +176,13 @@ const Writer = struct {
186176 }
187177 } = .{},
188178
179 const Error = std.io.Writer.Error || Allocator.Error;
180
189181 fn writeInstToStream(
190182 self: *Writer,
191 stream: anytype,
183 stream: *std.io.Writer,
192184 inst: Zir.Inst.Index,
193 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
185 ) Error!void {
194186 const tags = self.code.instructions.items(.tag);
195187 const tag = tags[@intFromEnum(inst)];
196188 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});
......@@ -516,7 +508,7 @@ const Writer = struct {
516508 }
517509 }
518510
519 fn writeExtended(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
511 fn writeExtended(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
520512 const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;
521513 try stream.print("{s}(", .{@tagName(extended.opcode)});
522514 switch (extended.opcode) {
......@@ -623,13 +615,13 @@ const Writer = struct {
623615 }
624616 }
625617
626 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
618 fn writeExtNode(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
627619 try stream.writeAll(")) ");
628620 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
629621 try self.writeSrcNode(stream, src_node);
630622 }
631623
632 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
624 fn writeArrayInitElemType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
633625 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
634626 try self.writeInstRef(stream, inst_data.lhs);
635627 try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});
......@@ -637,9 +629,9 @@ const Writer = struct {
637629
638630 fn writeUnNode(
639631 self: *Writer,
640 stream: anytype,
632 stream: *std.io.Writer,
641633 inst: Zir.Inst.Index,
642 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
634 ) Error!void {
643635 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
644636 try self.writeInstRef(stream, inst_data.operand);
645637 try stream.writeAll(") ");
......@@ -648,9 +640,9 @@ const Writer = struct {
648640
649641 fn writeUnTok(
650642 self: *Writer,
651 stream: anytype,
643 stream: *std.io.Writer,
652644 inst: Zir.Inst.Index,
653 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
645 ) Error!void {
654646 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
655647 try self.writeInstRef(stream, inst_data.operand);
656648 try stream.writeAll(") ");
......@@ -659,9 +651,9 @@ const Writer = struct {
659651
660652 fn writeValidateDestructure(
661653 self: *Writer,
662 stream: anytype,
654 stream: *std.io.Writer,
663655 inst: Zir.Inst.Index,
664 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
656 ) Error!void {
665657 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
666658 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
667659 try self.writeInstRef(stream, extra.operand);
......@@ -673,9 +665,9 @@ const Writer = struct {
673665
674666 fn writeValidateArrayInitTy(
675667 self: *Writer,
676 stream: anytype,
668 stream: *std.io.Writer,
677669 inst: Zir.Inst.Index,
678 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
670 ) Error!void {
679671 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
680672 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
681673 try self.writeInstRef(stream, extra.ty);
......@@ -685,9 +677,9 @@ const Writer = struct {
685677
686678 fn writeArrayTypeSentinel(
687679 self: *Writer,
688 stream: anytype,
680 stream: *std.io.Writer,
689681 inst: Zir.Inst.Index,
690 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
682 ) Error!void {
691683 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
692684 const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
693685 try self.writeInstRef(stream, extra.len);
......@@ -701,9 +693,9 @@ const Writer = struct {
701693
702694 fn writePtrType(
703695 self: *Writer,
704 stream: anytype,
696 stream: *std.io.Writer,
705697 inst: Zir.Inst.Index,
706 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
698 ) Error!void {
707699 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
708700 const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else "";
709701 const str_const = if (!inst_data.flags.is_mutable) "const, " else "";
......@@ -744,12 +736,12 @@ const Writer = struct {
744736 try self.writeSrcNode(stream, extra.data.src_node);
745737 }
746738
747 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
739 fn writeInt(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
748740 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;
749741 try stream.print("{d})", .{inst_data});
750742 }
751743
752 fn writeIntBig(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
744 fn writeIntBig(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
753745 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
754746 const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);
755747 const limb_bytes = self.code.string_bytes[@intFromEnum(inst_data.start)..][0..byte_count];
......@@ -768,12 +760,12 @@ const Writer = struct {
768760 try stream.print("{s})", .{as_string});
769761 }
770762
771 fn writeFloat(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
763 fn writeFloat(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
772764 const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;
773765 try stream.print("{d})", .{number});
774766 }
775767
776 fn writeFloat128(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
768 fn writeFloat128(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
777769 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
778770 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
779771 const number = extra.get();
......@@ -784,15 +776,15 @@ const Writer = struct {
784776
785777 fn writeStr(
786778 self: *Writer,
787 stream: anytype,
779 stream: *std.io.Writer,
788780 inst: Zir.Inst.Index,
789 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
781 ) Error!void {
790782 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
791783 const str = inst_data.get(self.code);
792784 try stream.print("\"{f}\")", .{std.zig.fmtString(str)});
793785 }
794786
795 fn writeSliceStart(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
787 fn writeSliceStart(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
796788 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
797789 const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
798790 try self.writeInstRef(stream, extra.lhs);
......@@ -802,7 +794,7 @@ const Writer = struct {
802794 try self.writeSrcNode(stream, inst_data.src_node);
803795 }
804796
805 fn writeSliceEnd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
797 fn writeSliceEnd(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
806798 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
807799 const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
808800 try self.writeInstRef(stream, extra.lhs);
......@@ -814,7 +806,7 @@ const Writer = struct {
814806 try self.writeSrcNode(stream, inst_data.src_node);
815807 }
816808
817 fn writeSliceSentinel(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
809 fn writeSliceSentinel(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
818810 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
819811 const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
820812 try self.writeInstRef(stream, extra.lhs);
......@@ -828,7 +820,7 @@ const Writer = struct {
828820 try self.writeSrcNode(stream, inst_data.src_node);
829821 }
830822
831 fn writeSliceLength(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
823 fn writeSliceLength(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
832824 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
833825 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
834826 try self.writeInstRef(stream, extra.lhs);
......@@ -844,7 +836,7 @@ const Writer = struct {
844836 try self.writeSrcNode(stream, inst_data.src_node);
845837 }
846838
847 fn writeUnionInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
839 fn writeUnionInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
848840 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
849841 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
850842 try self.writeInstRef(stream, extra.union_type);
......@@ -856,7 +848,7 @@ const Writer = struct {
856848 try self.writeSrcNode(stream, inst_data.src_node);
857849 }
858850
859 fn writeShuffle(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
851 fn writeShuffle(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
860852 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
861853 const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
862854 try self.writeInstRef(stream, extra.elem_type);
......@@ -870,7 +862,7 @@ const Writer = struct {
870862 try self.writeSrcNode(stream, inst_data.src_node);
871863 }
872864
873 fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
865 fn writeSelect(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
874866 const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data;
875867 try self.writeInstRef(stream, extra.elem_type);
876868 try stream.writeAll(", ");
......@@ -883,7 +875,7 @@ const Writer = struct {
883875 try self.writeSrcNode(stream, extra.node);
884876 }
885877
886 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
878 fn writeMulAdd(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
887879 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
888880 const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
889881 try self.writeInstRef(stream, extra.mulend1);
......@@ -895,7 +887,7 @@ const Writer = struct {
895887 try self.writeSrcNode(stream, inst_data.src_node);
896888 }
897889
898 fn writeBuiltinCall(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
890 fn writeBuiltinCall(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
899891 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
900892 const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
901893
......@@ -911,7 +903,7 @@ const Writer = struct {
911903 try self.writeSrcNode(stream, inst_data.src_node);
912904 }
913905
914 fn writeFieldParentPtr(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
906 fn writeFieldParentPtr(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
915907 const extra = self.code.extraData(Zir.Inst.FieldParentPtr, extended.operand).data;
916908 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
917909 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
......@@ -928,7 +920,7 @@ const Writer = struct {
928920 try self.writeSrcNode(stream, extra.src_node);
929921 }
930922
931 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
923 fn writeParam(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
932924 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
933925 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
934926 const body = self.code.bodySlice(extra.end, extra.data.type.body_len);
......@@ -943,7 +935,7 @@ const Writer = struct {
943935 try self.writeSrcTok(stream, inst_data.src_tok);
944936 }
945937
946 fn writePlNodeBin(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
938 fn writePlNodeBin(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
947939 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
948940 const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
949941 try self.writeInstRef(stream, extra.lhs);
......@@ -953,7 +945,7 @@ const Writer = struct {
953945 try self.writeSrcNode(stream, inst_data.src_node);
954946 }
955947
956 fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
948 fn writePlNodeMultiOp(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
957949 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
958950 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
959951 const args = self.code.refSlice(extra.end, extra.data.operands_len);
......@@ -966,7 +958,7 @@ const Writer = struct {
966958 try self.writeSrcNode(stream, inst_data.src_node);
967959 }
968960
969 fn writeArrayMul(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
961 fn writeArrayMul(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
970962 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
971963 const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
972964 try self.writeInstRef(stream, extra.res_ty);
......@@ -978,13 +970,13 @@ const Writer = struct {
978970 try self.writeSrcNode(stream, inst_data.src_node);
979971 }
980972
981 fn writeElemValImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
973 fn writeElemValImm(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
982974 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
983975 try self.writeInstRef(stream, inst_data.operand);
984976 try stream.print(", {d})", .{inst_data.idx});
985977 }
986978
987 fn writeArrayInitElemPtr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
979 fn writeArrayInitElemPtr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
988980 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
989981 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
990982
......@@ -993,7 +985,7 @@ const Writer = struct {
993985 try self.writeSrcNode(stream, inst_data.src_node);
994986 }
995987
996 fn writePlNodeExport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
988 fn writePlNodeExport(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
997989 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
998990 const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
999991
......@@ -1004,7 +996,7 @@ const Writer = struct {
1004996 try self.writeSrcNode(stream, inst_data.src_node);
1005997 }
1006998
1007 fn writeValidateArrayInitRefTy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
999 fn writeValidateArrayInitRefTy(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
10081000 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10091001 const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;
10101002
......@@ -1014,7 +1006,7 @@ const Writer = struct {
10141006 try self.writeSrcNode(stream, inst_data.src_node);
10151007 }
10161008
1017 fn writeStructInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1009 fn writeStructInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
10181010 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10191011 const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
10201012 var field_i: u32 = 0;
......@@ -1038,7 +1030,7 @@ const Writer = struct {
10381030 try self.writeSrcNode(stream, inst_data.src_node);
10391031 }
10401032
1041 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1033 fn writeCmpxchg(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10421034 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
10431035
10441036 try self.writeInstRef(stream, extra.ptr);
......@@ -1054,7 +1046,7 @@ const Writer = struct {
10541046 try self.writeSrcNode(stream, extra.node);
10551047 }
10561048
1057 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1049 fn writePtrCastFull(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10581050 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
10591051 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10601052 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
......@@ -1070,7 +1062,7 @@ const Writer = struct {
10701062 try self.writeSrcNode(stream, extra.node);
10711063 }
10721064
1073 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1065 fn writePtrCastNoDest(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
10741066 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
10751067 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10761068 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
......@@ -1081,7 +1073,7 @@ const Writer = struct {
10811073 try self.writeSrcNode(stream, extra.node);
10821074 }
10831075
1084 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1076 fn writeAtomicLoad(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
10851077 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10861078 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
10871079
......@@ -1094,7 +1086,7 @@ const Writer = struct {
10941086 try self.writeSrcNode(stream, inst_data.src_node);
10951087 }
10961088
1097 fn writeAtomicStore(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1089 fn writeAtomicStore(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
10981090 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10991091 const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
11001092
......@@ -1107,7 +1099,7 @@ const Writer = struct {
11071099 try self.writeSrcNode(stream, inst_data.src_node);
11081100 }
11091101
1110 fn writeAtomicRmw(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1102 fn writeAtomicRmw(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
11111103 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11121104 const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
11131105
......@@ -1122,7 +1114,7 @@ const Writer = struct {
11221114 try self.writeSrcNode(stream, inst_data.src_node);
11231115 }
11241116
1125 fn writeStructInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1117 fn writeStructInitAnon(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
11261118 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11271119 const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
11281120 var field_i: u32 = 0;
......@@ -1143,7 +1135,7 @@ const Writer = struct {
11431135 try self.writeSrcNode(stream, inst_data.src_node);
11441136 }
11451137
1146 fn writeStructInitFieldType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1138 fn writeStructInitFieldType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
11471139 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11481140 const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
11491141 try self.writeInstRef(stream, extra.container_type);
......@@ -1152,7 +1144,7 @@ const Writer = struct {
11521144 try self.writeSrcNode(stream, inst_data.src_node);
11531145 }
11541146
1155 fn writeFieldTypeRef(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1147 fn writeFieldTypeRef(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
11561148 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11571149 const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
11581150 try self.writeInstRef(stream, extra.container_type);
......@@ -1162,7 +1154,7 @@ const Writer = struct {
11621154 try self.writeSrcNode(stream, inst_data.src_node);
11631155 }
11641156
1165 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1157 fn writeNodeMultiOp(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
11661158 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
11671159 const operands = self.code.refSlice(extra.end, extended.small);
11681160
......@@ -1176,9 +1168,9 @@ const Writer = struct {
11761168
11771169 fn writeInstNode(
11781170 self: *Writer,
1179 stream: anytype,
1171 stream: *std.io.Writer,
11801172 inst: Zir.Inst.Index,
1181 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
1173 ) Error!void {
11821174 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
11831175 try self.writeInstIndex(stream, inst_data.inst);
11841176 try stream.writeAll(") ");
......@@ -1187,7 +1179,7 @@ const Writer = struct {
11871179
11881180 fn writeAsm(
11891181 self: *Writer,
1190 stream: anytype,
1182 stream: *std.io.Writer,
11911183 extended: Zir.Inst.Extended.InstData,
11921184 tmpl_is_expr: bool,
11931185 ) !void {
......@@ -1220,8 +1212,8 @@ const Writer = struct {
12201212
12211213 const name = self.code.nullTerminatedString(output.data.name);
12221214 const constraint = self.code.nullTerminatedString(output.data.constraint);
1223 try stream.print("output({f}, \"{f}\", ", .{
1224 std.zig.fmtIdFlags(name, .{ .allow_primitive = true }), std.zig.fmtString(constraint),
1215 try stream.print("output({fp}, \"{f}\", ", .{
1216 std.zig.fmtId(name), std.zig.fmtString(constraint),
12251217 });
12261218 try self.writeFlag(stream, "->", is_type);
12271219 try self.writeInstRef(stream, output.data.operand);
......@@ -1239,8 +1231,8 @@ const Writer = struct {
12391231
12401232 const name = self.code.nullTerminatedString(input.data.name);
12411233 const constraint = self.code.nullTerminatedString(input.data.constraint);
1242 try stream.print("input({f}, \"{f}\", ", .{
1243 std.zig.fmtIdFlags(name, .{ .allow_primitive = true }), std.zig.fmtString(constraint),
1234 try stream.print("input({fp}, \"{f}\", ", .{
1235 std.zig.fmtId(name), std.zig.fmtString(constraint),
12441236 });
12451237 try self.writeInstRef(stream, input.data.operand);
12461238 try stream.writeAll(")");
......@@ -1255,7 +1247,7 @@ const Writer = struct {
12551247 const str_index = self.code.extra[extra_i];
12561248 extra_i += 1;
12571249 const clobber = self.code.nullTerminatedString(@enumFromInt(str_index));
1258 try stream.print("{f}", .{std.zig.fmtIdFlags(clobber, .{ .allow_primitive = true })});
1250 try stream.print("{fp}", .{std.zig.fmtId(clobber)});
12591251 if (i + 1 < clobbers_len) {
12601252 try stream.writeAll(", ");
12611253 }
......@@ -1265,7 +1257,7 @@ const Writer = struct {
12651257 try self.writeSrcNode(stream, extra.data.src_node);
12661258 }
12671259
1268 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1260 fn writeOverflowArithmetic(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
12691261 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
12701262
12711263 try self.writeInstRef(stream, extra.lhs);
......@@ -1277,7 +1269,7 @@ const Writer = struct {
12771269
12781270 fn writeCall(
12791271 self: *Writer,
1280 stream: anytype,
1272 stream: *std.io.Writer,
12811273 inst: Zir.Inst.Index,
12821274 comptime kind: enum { direct, field },
12831275 ) !void {
......@@ -1311,7 +1303,7 @@ const Writer = struct {
13111303 var i: usize = 0;
13121304 var arg_start: u32 = args_len;
13131305 while (i < args_len) : (i += 1) {
1314 try stream.writeByteNTimes(' ', self.indent);
1306 try stream.splatByteAll(' ', self.indent);
13151307 const arg_end = self.code.extra[extra.end + i];
13161308 defer arg_start = arg_end;
13171309 const arg_body = body[arg_start..arg_end];
......@@ -1321,14 +1313,14 @@ const Writer = struct {
13211313 }
13221314 self.indent -= 2;
13231315 if (args_len != 0) {
1324 try stream.writeByteNTimes(' ', self.indent);
1316 try stream.splatByteAll(' ', self.indent);
13251317 }
13261318
13271319 try stream.writeAll("]) ");
13281320 try self.writeSrcNode(stream, inst_data.src_node);
13291321 }
13301322
1331 fn writeBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1323 fn writeBlock(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
13321324 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13331325 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
13341326 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1337,7 +1329,7 @@ const Writer = struct {
13371329 try self.writeSrcNode(stream, inst_data.src_node);
13381330 }
13391331
1340 fn writeBlockComptime(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1332 fn writeBlockComptime(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
13411333 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13421334 const extra = self.code.extraData(Zir.Inst.BlockComptime, inst_data.payload_index);
13431335 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1347,7 +1339,7 @@ const Writer = struct {
13471339 try self.writeSrcNode(stream, inst_data.src_node);
13481340 }
13491341
1350 fn writeCondBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1342 fn writeCondBr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
13511343 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13521344 const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
13531345 const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);
......@@ -1361,7 +1353,7 @@ const Writer = struct {
13611353 try self.writeSrcNode(stream, inst_data.src_node);
13621354 }
13631355
1364 fn writeTry(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1356 fn writeTry(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
13651357 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13661358 const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);
13671359 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -1372,7 +1364,7 @@ const Writer = struct {
13721364 try self.writeSrcNode(stream, inst_data.src_node);
13731365 }
13741366
1375 fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1367 fn writeStructDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
13761368 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
13771369
13781370 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);
......@@ -1446,7 +1438,7 @@ const Writer = struct {
14461438 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
14471439 self.indent -= 2;
14481440 extra_index += decls_len;
1449 try stream.writeByteNTimes(' ', self.indent);
1441 try stream.splatByteAll(' ', self.indent);
14501442 try stream.writeAll("}, ");
14511443 }
14521444
......@@ -1515,11 +1507,11 @@ const Writer = struct {
15151507 self.indent += 2;
15161508
15171509 for (fields, 0..) |field, i| {
1518 try stream.writeByteNTimes(' ', self.indent);
1510 try stream.splatByteAll(' ', self.indent);
15191511 try self.writeFlag(stream, "comptime ", field.is_comptime);
15201512 if (field.name != .empty) {
15211513 const field_name = self.code.nullTerminatedString(field.name);
1522 try stream.print("{f}: ", .{std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true })});
1514 try stream.print("{fp}: ", .{std.zig.fmtId(field_name)});
15231515 } else {
15241516 try stream.print("@\"{d}\": ", .{i});
15251517 }
......@@ -1558,13 +1550,13 @@ const Writer = struct {
15581550 }
15591551
15601552 self.indent -= 2;
1561 try stream.writeByteNTimes(' ', self.indent);
1553 try stream.splatByteAll(' ', self.indent);
15621554 try stream.writeAll("}) ");
15631555 }
15641556 try self.writeSrcNode(stream, .zero);
15651557 }
15661558
1567 fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1559 fn writeUnionDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
15681560 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
15691561
15701562 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);
......@@ -1630,7 +1622,7 @@ const Writer = struct {
16301622 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
16311623 self.indent -= 2;
16321624 extra_index += decls_len;
1633 try stream.writeByteNTimes(' ', self.indent);
1625 try stream.splatByteAll(' ', self.indent);
16341626 try stream.writeAll("}");
16351627 }
16361628
......@@ -1681,8 +1673,8 @@ const Writer = struct {
16811673 const field_name = self.code.nullTerminatedString(field_name_index);
16821674 extra_index += 1;
16831675
1684 try stream.writeByteNTimes(' ', self.indent);
1685 try stream.print("{f}", .{std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true })});
1676 try stream.splatByteAll(' ', self.indent);
1677 try stream.print("{fp}", .{std.zig.fmtId(field_name)});
16861678
16871679 if (has_type) {
16881680 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -1710,12 +1702,12 @@ const Writer = struct {
17101702 }
17111703
17121704 self.indent -= 2;
1713 try stream.writeByteNTimes(' ', self.indent);
1705 try stream.splatByteAll(' ', self.indent);
17141706 try stream.writeAll("}) ");
17151707 try self.writeSrcNode(stream, .zero);
17161708 }
17171709
1718 fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1710 fn writeEnumDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
17191711 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17201712
17211713 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);
......@@ -1779,7 +1771,7 @@ const Writer = struct {
17791771 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
17801772 self.indent -= 2;
17811773 extra_index += decls_len;
1782 try stream.writeByteNTimes(' ', self.indent);
1774 try stream.splatByteAll(' ', self.indent);
17831775 try stream.writeAll("}, ");
17841776 }
17851777
......@@ -1815,8 +1807,8 @@ const Writer = struct {
18151807 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));
18161808 extra_index += 1;
18171809
1818 try stream.writeByteNTimes(' ', self.indent);
1819 try stream.print("{f}", .{std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true })});
1810 try stream.splatByteAll(' ', self.indent);
1811 try stream.print("{fp}", .{std.zig.fmtId(field_name)});
18201812
18211813 if (has_tag_value) {
18221814 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
......@@ -1828,7 +1820,7 @@ const Writer = struct {
18281820 try stream.writeAll(",\n");
18291821 }
18301822 self.indent -= 2;
1831 try stream.writeByteNTimes(' ', self.indent);
1823 try stream.splatByteAll(' ', self.indent);
18321824 try stream.writeAll("}) ");
18331825 }
18341826 try self.writeSrcNode(stream, .zero);
......@@ -1836,7 +1828,7 @@ const Writer = struct {
18361828
18371829 fn writeOpaqueDecl(
18381830 self: *Writer,
1839 stream: anytype,
1831 stream: *std.io.Writer,
18401832 extended: Zir.Inst.Extended.InstData,
18411833 ) !void {
18421834 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
......@@ -1872,13 +1864,13 @@ const Writer = struct {
18721864 self.indent += 2;
18731865 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
18741866 self.indent -= 2;
1875 try stream.writeByteNTimes(' ', self.indent);
1867 try stream.splatByteAll(' ', self.indent);
18761868 try stream.writeAll("}) ");
18771869 }
18781870 try self.writeSrcNode(stream, .zero);
18791871 }
18801872
1881 fn writeTupleDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1873 fn writeTupleDecl(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
18821874 const fields_len = extended.small;
18831875 assert(fields_len != 0);
18841876 const extra = self.code.extraData(Zir.Inst.TupleDecl, extended.operand);
......@@ -1906,7 +1898,7 @@ const Writer = struct {
19061898
19071899 fn writeErrorSetDecl(
19081900 self: *Writer,
1909 stream: anytype,
1901 stream: *std.io.Writer,
19101902 inst: Zir.Inst.Index,
19111903 ) !void {
19121904 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
......@@ -1920,18 +1912,18 @@ const Writer = struct {
19201912 while (extra_index < extra_index_end) : (extra_index += 1) {
19211913 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
19221914 const name = self.code.nullTerminatedString(name_index);
1923 try stream.writeByteNTimes(' ', self.indent);
1924 try stream.print("{f},\n", .{std.zig.fmtIdFlags(name, .{ .allow_primitive = true })});
1915 try stream.splatByteAll(' ', self.indent);
1916 try stream.print("{fp},\n", .{std.zig.fmtId(name)});
19251917 }
19261918
19271919 self.indent -= 2;
1928 try stream.writeByteNTimes(' ', self.indent);
1920 try stream.splatByteAll(' ', self.indent);
19291921 try stream.writeAll("}) ");
19301922
19311923 try self.writeSrcNode(stream, inst_data.src_node);
19321924 }
19331925
1934 fn writeSwitchBlockErrUnion(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
1926 fn writeSwitchBlockErrUnion(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
19351927 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19361928 const extra = self.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
19371929
......@@ -1967,7 +1959,7 @@ const Writer = struct {
19671959 extra_index += body.len;
19681960
19691961 try stream.writeAll(",\n");
1970 try stream.writeByteNTimes(' ', self.indent);
1962 try stream.splatByteAll(' ', self.indent);
19711963 try stream.writeAll("non_err => ");
19721964 try self.writeBracedBody(stream, body);
19731965 }
......@@ -1985,7 +1977,7 @@ const Writer = struct {
19851977 extra_index += body.len;
19861978
19871979 try stream.writeAll(",\n");
1988 try stream.writeByteNTimes(' ', self.indent);
1980 try stream.splatByteAll(' ', self.indent);
19891981 try stream.print("{s}{s}else => ", .{ capture_text, inline_text });
19901982 try self.writeBracedBody(stream, body);
19911983 }
......@@ -2002,7 +1994,7 @@ const Writer = struct {
20021994 extra_index += info.body_len;
20031995
20041996 try stream.writeAll(",\n");
2005 try stream.writeByteNTimes(' ', self.indent);
1997 try stream.splatByteAll(' ', self.indent);
20061998 switch (info.capture) {
20071999 .none => {},
20082000 .by_val => try stream.writeAll("by_val "),
......@@ -2027,7 +2019,7 @@ const Writer = struct {
20272019 extra_index += items_len;
20282020
20292021 try stream.writeAll(",\n");
2030 try stream.writeByteNTimes(' ', self.indent);
2022 try stream.splatByteAll(' ', self.indent);
20312023 switch (info.capture) {
20322024 .none => {},
20332025 .by_val => try stream.writeAll("by_val "),
......@@ -2068,7 +2060,7 @@ const Writer = struct {
20682060 try self.writeSrcNode(stream, inst_data.src_node);
20692061 }
20702062
2071 fn writeSwitchBlock(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2063 fn writeSwitchBlock(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
20722064 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20732065 const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
20742066
......@@ -2115,7 +2107,7 @@ const Writer = struct {
21152107 extra_index += body.len;
21162108
21172109 try stream.writeAll(",\n");
2118 try stream.writeByteNTimes(' ', self.indent);
2110 try stream.splatByteAll(' ', self.indent);
21192111 try stream.print("{s}{s}{s} => ", .{ capture_text, inline_text, prong_name });
21202112 try self.writeBracedBody(stream, body);
21212113 }
......@@ -2132,7 +2124,7 @@ const Writer = struct {
21322124 extra_index += info.body_len;
21332125
21342126 try stream.writeAll(",\n");
2135 try stream.writeByteNTimes(' ', self.indent);
2127 try stream.splatByteAll(' ', self.indent);
21362128 switch (info.capture) {
21372129 .none => {},
21382130 .by_val => try stream.writeAll("by_val "),
......@@ -2157,7 +2149,7 @@ const Writer = struct {
21572149 extra_index += items_len;
21582150
21592151 try stream.writeAll(",\n");
2160 try stream.writeByteNTimes(' ', self.indent);
2152 try stream.splatByteAll(' ', self.indent);
21612153 switch (info.capture) {
21622154 .none => {},
21632155 .by_val => try stream.writeAll("by_val "),
......@@ -2198,7 +2190,7 @@ const Writer = struct {
21982190 try self.writeSrcNode(stream, inst_data.src_node);
21992191 }
22002192
2201 fn writePlNodeField(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2193 fn writePlNodeField(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
22022194 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22032195 const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
22042196 const name = self.code.nullTerminatedString(extra.field_name_start);
......@@ -2207,7 +2199,7 @@ const Writer = struct {
22072199 try self.writeSrcNode(stream, inst_data.src_node);
22082200 }
22092201
2210 fn writePlNodeFieldNamed(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2202 fn writePlNodeFieldNamed(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
22112203 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22122204 const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
22132205 try self.writeInstRef(stream, extra.lhs);
......@@ -2217,7 +2209,7 @@ const Writer = struct {
22172209 try self.writeSrcNode(stream, inst_data.src_node);
22182210 }
22192211
2220 fn writeAs(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2212 fn writeAs(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
22212213 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22222214 const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
22232215 try self.writeInstRef(stream, extra.dest_type);
......@@ -2229,9 +2221,9 @@ const Writer = struct {
22292221
22302222 fn writeNode(
22312223 self: *Writer,
2232 stream: anytype,
2224 stream: *std.io.Writer,
22332225 inst: Zir.Inst.Index,
2234 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2226 ) Error!void {
22352227 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
22362228 try stream.writeAll(") ");
22372229 try self.writeSrcNode(stream, src_node);
......@@ -2239,16 +2231,16 @@ const Writer = struct {
22392231
22402232 fn writeStrTok(
22412233 self: *Writer,
2242 stream: anytype,
2234 stream: *std.io.Writer,
22432235 inst: Zir.Inst.Index,
2244 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2236 ) Error!void {
22452237 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
22462238 const str = inst_data.get(self.code);
22472239 try stream.print("\"{f}\") ", .{std.zig.fmtString(str)});
22482240 try self.writeSrcTok(stream, inst_data.src_tok);
22492241 }
22502242
2251 fn writeStrOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2243 fn writeStrOp(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
22522244 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
22532245 const str = inst_data.getStr(self.code);
22542246 try self.writeInstRef(stream, inst_data.operand);
......@@ -2257,7 +2249,7 @@ const Writer = struct {
22572249
22582250 fn writeFunc(
22592251 self: *Writer,
2260 stream: anytype,
2252 stream: *std.io.Writer,
22612253 inst: Zir.Inst.Index,
22622254 inferred_error_set: bool,
22632255 ) !void {
......@@ -2308,7 +2300,7 @@ const Writer = struct {
23082300 );
23092301 }
23102302
2311 fn writeFuncFancy(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2303 fn writeFuncFancy(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
23122304 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23132305 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
23142306
......@@ -2367,7 +2359,7 @@ const Writer = struct {
23672359 );
23682360 }
23692361
2370 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2362 fn writeAllocExtended(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
23712363 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
23722364 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
23732365
......@@ -2390,7 +2382,7 @@ const Writer = struct {
23902382 try self.writeSrcNode(stream, extra.data.src_node);
23912383 }
23922384
2393 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2385 fn writeTypeofPeer(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
23942386 const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
23952387 const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);
23962388 try self.writeBracedBody(stream, body);
......@@ -2403,7 +2395,7 @@ const Writer = struct {
24032395 try stream.writeAll("])");
24042396 }
24052397
2406 fn writeBoolBr(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2398 fn writeBoolBr(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24072399 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24082400 const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);
24092401 const body = self.code.bodySlice(extra.end, extra.data.body_len);
......@@ -2414,7 +2406,7 @@ const Writer = struct {
24142406 try self.writeSrcNode(stream, inst_data.src_node);
24152407 }
24162408
2417 fn writeIntType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2409 fn writeIntType(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24182410 const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
24192411 const prefix: u8 = switch (int_type.signedness) {
24202412 .signed => 'i',
......@@ -2424,7 +2416,7 @@ const Writer = struct {
24242416 try self.writeSrcNode(stream, int_type.src_node);
24252417 }
24262418
2427 fn writeSaveErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2419 fn writeSaveErrRetIndex(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24282420 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24292421
24302422 try self.writeInstRef(stream, inst_data.operand);
......@@ -2432,7 +2424,7 @@ const Writer = struct {
24322424 try stream.writeAll(")");
24332425 }
24342426
2435 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2427 fn writeRestoreErrRetIndex(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
24362428 const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
24372429
24382430 try self.writeInstRef(stream, extra.block);
......@@ -2442,7 +2434,7 @@ const Writer = struct {
24422434 try self.writeSrcNode(stream, extra.src_node);
24432435 }
24442436
2445 fn writeBreak(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2437 fn writeBreak(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24462438 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
24472439 const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
24482440
......@@ -2452,7 +2444,7 @@ const Writer = struct {
24522444 try stream.writeAll(")");
24532445 }
24542446
2455 fn writeArrayInit(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2447 fn writeArrayInit(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24562448 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24572449
24582450 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2468,7 +2460,7 @@ const Writer = struct {
24682460 try self.writeSrcNode(stream, inst_data.src_node);
24692461 }
24702462
2471 fn writeArrayInitAnon(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2463 fn writeArrayInitAnon(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24722464 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24732465
24742466 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2483,7 +2475,7 @@ const Writer = struct {
24832475 try self.writeSrcNode(stream, inst_data.src_node);
24842476 }
24852477
2486 fn writeArrayInitSent(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2478 fn writeArrayInitSent(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
24872479 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24882480
24892481 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
......@@ -2503,7 +2495,7 @@ const Writer = struct {
25032495 try self.writeSrcNode(stream, inst_data.src_node);
25042496 }
25052497
2506 fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2498 fn writeUnreachable(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
25072499 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
25082500 try stream.writeAll(") ");
25092501 try self.writeSrcNode(stream, inst_data.src_node);
......@@ -2511,7 +2503,7 @@ const Writer = struct {
25112503
25122504 fn writeFuncCommon(
25132505 self: *Writer,
2514 stream: anytype,
2506 stream: *std.io.Writer,
25152507 inferred_error_set: bool,
25162508 var_args: bool,
25172509 is_noinline: bool,
......@@ -2548,19 +2540,19 @@ const Writer = struct {
25482540 try self.writeSrcNode(stream, src_node);
25492541 }
25502542
2551 fn writeDbgStmt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2543 fn writeDbgStmt(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
25522544 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
25532545 try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });
25542546 }
25552547
2556 fn writeDefer(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2548 fn writeDefer(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
25572549 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
25582550 const body = self.code.bodySlice(inst_data.index, inst_data.len);
25592551 try self.writeBracedBody(stream, body);
25602552 try stream.writeByte(')');
25612553 }
25622554
2563 fn writeDeferErrCode(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2555 fn writeDeferErrCode(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
25642556 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
25652557 const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
25662558
......@@ -2573,7 +2565,7 @@ const Writer = struct {
25732565 try stream.writeByte(')');
25742566 }
25752567
2576 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2568 fn writeDeclaration(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
25772569 const decl = self.code.getDeclaration(inst);
25782570
25792571 const prev_parent_decl_node = self.parent_decl_node;
......@@ -2594,7 +2586,9 @@ const Writer = struct {
25942586 },
25952587 }
25962588 const src_hash = self.code.getAssociatedSrcHash(inst).?;
2597 try stream.print(" line({d}) column({d}) hash({x})", .{ decl.src_line, decl.src_column, &src_hash });
2589 try stream.print(" line({d}) column({d}) hash({x})", .{
2590 decl.src_line, decl.src_column, &src_hash,
2591 });
25982592
25992593 {
26002594 if (decl.type_body) |b| {
......@@ -2627,26 +2621,26 @@ const Writer = struct {
26272621 try self.writeSrcNode(stream, .zero);
26282622 }
26292623
2630 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2624 fn writeClosureGet(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26312625 try stream.print("{d})) ", .{extended.small});
26322626 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
26332627 try self.writeSrcNode(stream, src_node);
26342628 }
26352629
2636 fn writeBuiltinValue(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2630 fn writeBuiltinValue(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26372631 const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);
26382632 try stream.print("{s})) ", .{@tagName(val)});
26392633 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
26402634 try self.writeSrcNode(stream, src_node);
26412635 }
26422636
2643 fn writeInplaceArithResultTy(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2637 fn writeInplaceArithResultTy(self: *Writer, stream: *std.io.Writer, extended: Zir.Inst.Extended.InstData) !void {
26442638 const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small);
26452639 try self.writeInstRef(stream, @enumFromInt(extended.operand));
26462640 try stream.print(", {s}))", .{@tagName(op)});
26472641 }
26482642
2649 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2643 fn writeInstRef(self: *Writer, stream: *std.io.Writer, ref: Zir.Inst.Ref) !void {
26502644 if (ref == .none) {
26512645 return stream.writeAll(".none");
26522646 } else if (ref.toIndex()) |i| {
......@@ -2657,12 +2651,12 @@ const Writer = struct {
26572651 }
26582652 }
26592653
2660 fn writeInstIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2654 fn writeInstIndex(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
26612655 _ = self;
26622656 return stream.print("%{d}", .{@intFromEnum(inst)});
26632657 }
26642658
2665 fn writeCaptures(self: *Writer, stream: anytype, extra_index: usize, captures_len: u32) !usize {
2659 fn writeCaptures(self: *Writer, stream: *std.io.Writer, extra_index: usize, captures_len: u32) !usize {
26662660 if (captures_len == 0) {
26672661 try stream.writeAll("{}");
26682662 return extra_index;
......@@ -2682,7 +2676,7 @@ const Writer = struct {
26822676 return extra_index + 2 * captures_len;
26832677 }
26842678
2685 fn writeCapture(self: *Writer, stream: anytype, capture: Zir.Inst.Capture) !void {
2679 fn writeCapture(self: *Writer, stream: *std.io.Writer, capture: Zir.Inst.Capture) !void {
26862680 switch (capture.unwrap()) {
26872681 .nested => |i| return stream.print("[{d}]", .{i}),
26882682 .instruction => |inst| return self.writeInstIndex(stream, inst),
......@@ -2701,7 +2695,7 @@ const Writer = struct {
27012695
27022696 fn writeOptionalInstRef(
27032697 self: *Writer,
2704 stream: anytype,
2698 stream: *std.io.Writer,
27052699 prefix: []const u8,
27062700 inst: Zir.Inst.Ref,
27072701 ) !void {
......@@ -2712,7 +2706,7 @@ const Writer = struct {
27122706
27132707 fn writeOptionalInstRefOrBody(
27142708 self: *Writer,
2715 stream: anytype,
2709 stream: *std.io.Writer,
27162710 prefix: []const u8,
27172711 ref: Zir.Inst.Ref,
27182712 body: []const Zir.Inst.Index,
......@@ -2730,7 +2724,7 @@ const Writer = struct {
27302724
27312725 fn writeFlag(
27322726 self: *Writer,
2733 stream: anytype,
2727 stream: *std.io.Writer,
27342728 name: []const u8,
27352729 flag: bool,
27362730 ) !void {
......@@ -2739,7 +2733,7 @@ const Writer = struct {
27392733 try stream.writeAll(name);
27402734 }
27412735
2742 fn writeSrcNode(self: *Writer, stream: anytype, src_node: Ast.Node.Offset) !void {
2736 fn writeSrcNode(self: *Writer, stream: *std.io.Writer, src_node: Ast.Node.Offset) !void {
27432737 const tree = self.tree orelse return;
27442738 const abs_node = src_node.toAbsolute(self.parent_decl_node);
27452739 const src_span = tree.nodeToSpan(abs_node);
......@@ -2751,7 +2745,7 @@ const Writer = struct {
27512745 });
27522746 }
27532747
2754 fn writeSrcTok(self: *Writer, stream: anytype, src_tok: Ast.TokenOffset) !void {
2748 fn writeSrcTok(self: *Writer, stream: *std.io.Writer, src_tok: Ast.TokenOffset) !void {
27552749 const tree = self.tree orelse return;
27562750 const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));
27572751 const span_start = tree.tokenStart(abs_tok);
......@@ -2764,7 +2758,7 @@ const Writer = struct {
27642758 });
27652759 }
27662760
2767 fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: Ast.TokenIndex) !void {
2761 fn writeSrcTokAbs(self: *Writer, stream: *std.io.Writer, src_tok: Ast.TokenIndex) !void {
27682762 const tree = self.tree orelse return;
27692763 const span_start = tree.tokenStart(src_tok);
27702764 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
......@@ -2776,15 +2770,15 @@ const Writer = struct {
27762770 });
27772771 }
27782772
2779 fn writeBracedDecl(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
2773 fn writeBracedDecl(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
27802774 try self.writeBracedBodyConditional(stream, body, self.recurse_decls);
27812775 }
27822776
2783 fn writeBracedBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
2777 fn writeBracedBody(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
27842778 try self.writeBracedBodyConditional(stream, body, self.recurse_blocks);
27852779 }
27862780
2787 fn writeBracedBodyConditional(self: *Writer, stream: anytype, body: []const Zir.Inst.Index, enabled: bool) !void {
2781 fn writeBracedBodyConditional(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index, enabled: bool) !void {
27882782 if (body.len == 0) {
27892783 try stream.writeAll("{}");
27902784 } else if (enabled) {
......@@ -2792,7 +2786,7 @@ const Writer = struct {
27922786 self.indent += 2;
27932787 try self.writeBody(stream, body);
27942788 self.indent -= 2;
2795 try stream.writeByteNTimes(' ', self.indent);
2789 try stream.splatByteAll(' ', self.indent);
27962790 try stream.writeAll("}");
27972791 } else if (body.len == 1) {
27982792 try stream.writeByte('{');
......@@ -2813,16 +2807,16 @@ const Writer = struct {
28132807 }
28142808 }
28152809
2816 fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
2810 fn writeBody(self: *Writer, stream: *std.io.Writer, body: []const Zir.Inst.Index) !void {
28172811 for (body) |inst| {
2818 try stream.writeByteNTimes(' ', self.indent);
2812 try stream.splatByteAll(' ', self.indent);
28192813 try stream.print("%{d} ", .{@intFromEnum(inst)});
28202814 try self.writeInstToStream(stream, inst);
28212815 try stream.writeByte('\n');
28222816 }
28232817 }
28242818
2825 fn writeImport(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2819 fn writeImport(self: *Writer, stream: *std.io.Writer, inst: Zir.Inst.Index) !void {
28262820 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
28272821 const extra = self.code.extraData(Zir.Inst.Import, inst_data.payload_index).data;
28282822 try self.writeInstRef(stream, extra.res_ty);
src/print_zoir.zig+19-25
......@@ -1,13 +1,8 @@
1pub fn renderToFile(zoir: Zoir, arena: Allocator, f: std.fs.File) (std.fs.File.WriteError || Allocator.Error)!void {
2 var bw = std.io.bufferedWriter(f.writer());
3 try renderToWriter(zoir, arena, bw.writer());
4 try bw.flush();
5}
1pub const Error = error{ WriteFailed, OutOfMemory };
62
7pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: anytype) (@TypeOf(w).Error || Allocator.Error)!void {
3pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: *Writer) Error!void {
84 assert(!zoir.hasCompileErrors());
95
10 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
116 const bytes_per_node = comptime n: {
127 var n: usize = 0;
138 for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| {
......@@ -23,42 +18,42 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: anytype) (@TypeOf(w).Erro
2318
2419 // zig fmt: off
2520 try w.print(
26 \\# Nodes: {} ({})
27 \\# Extra Data Items: {} ({})
28 \\# BigInt Limbs: {} ({})
29 \\# String Table Bytes: {}
30 \\# Total ZON Bytes: {}
21 \\# Nodes: {} ({Bi})
22 \\# Extra Data Items: {} ({Bi})
23 \\# BigInt Limbs: {} ({Bi})
24 \\# String Table Bytes: {Bi}
25 \\# Total ZON Bytes: {Bi}
3126 \\
3227 , .{
33 zoir.nodes.len, fmtIntSizeBin(node_bytes),
34 zoir.extra.len, fmtIntSizeBin(extra_bytes),
35 zoir.limbs.len, fmtIntSizeBin(limb_bytes),
36 fmtIntSizeBin(string_bytes),
37 fmtIntSizeBin(node_bytes + extra_bytes + limb_bytes + string_bytes),
28 zoir.nodes.len, node_bytes,
29 zoir.extra.len, extra_bytes,
30 zoir.limbs.len, limb_bytes,
31 string_bytes,
32 node_bytes + extra_bytes + limb_bytes + string_bytes,
3833 });
3934 // zig fmt: on
4035 var pz: PrintZon = .{
41 .w = w.any(),
36 .w = w,
4237 .arena = arena,
4338 .zoir = zoir,
4439 .indent = 0,
4540 };
4641
47 return @errorCast(pz.renderRoot());
42 return pz.renderRoot();
4843}
4944
5045const PrintZon = struct {
51 w: std.io.AnyWriter,
46 w: *Writer,
5247 arena: Allocator,
5348 zoir: Zoir,
5449 indent: u32,
5550
56 fn renderRoot(pz: *PrintZon) anyerror!void {
51 fn renderRoot(pz: *PrintZon) Error!void {
5752 try pz.renderNode(.root);
5853 try pz.w.writeByte('\n');
5954 }
6055
61 fn renderNode(pz: *PrintZon, node: Zoir.Node.Index) anyerror!void {
56 fn renderNode(pz: *PrintZon, node: Zoir.Node.Index) Error!void {
6257 const zoir = pz.zoir;
6358 try pz.w.print("%{d} = ", .{@intFromEnum(node)});
6459 switch (node.get(zoir)) {
......@@ -110,9 +105,7 @@ const PrintZon = struct {
110105
111106 fn newline(pz: *PrintZon) !void {
112107 try pz.w.writeByte('\n');
113 for (0..pz.indent) |_| {
114 try pz.w.writeByteNTimes(' ', 2);
115 }
108 try pz.w.splatByteAll(' ', 2 * pz.indent);
116109 }
117110};
118111
......@@ -120,3 +113,4 @@ const std = @import("std");
120113const assert = std.debug.assert;
121114const Allocator = std.mem.Allocator;
122115const Zoir = std.zig.Zoir;
116const Writer = std.io.Writer;