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 {...@@ -1921,9 +1921,10 @@ pub fn reader(file: File, buffer: []u8) Reader {
1921/// Positional is more threadsafe, since the global seek position is not1921/// Positional is more threadsafe, since the global seek position is not
1922/// affected, but when such syscalls are not available, preemptively choosing1922/// affected, but when such syscalls are not available, preemptively choosing
1923/// `Reader.Mode.streaming` will skip a failed syscall.1923/// `Reader.Mode.streaming` will skip a failed syscall.
1924pub fn readerStreaming(file: File) Reader {1924pub fn readerStreaming(file: File, buffer: []u8) Reader {
1925 return .{1925 return .{
1926 .file = file,1926 .file = file,
1927 .interface = Reader.initInterface(buffer),
1927 .mode = .streaming,1928 .mode = .streaming,
1928 .seek_err = error.Unseekable,1929 .seek_err = error.Unseekable,
1929 };1930 };
lib/std/io/Writer.zig+12-7
...@@ -126,8 +126,8 @@ pub fn fixed(buffer: []u8) Writer {...@@ -126,8 +126,8 @@ pub fn fixed(buffer: []u8) Writer {
126 };126 };
127}127}
128128
129pub fn hashed(w: *Writer, hasher: anytype) Hashed(@TypeOf(hasher)) {129pub fn hashed(w: *Writer, hasher: anytype, buffer: []u8) Hashed(@TypeOf(hasher)) {
130 return .{ .out = w, .hasher = hasher };130 return .initHasher(w, hasher, buffer);
131}131}
132132
133pub const failing: Writer = .{133pub const failing: Writer = .{
...@@ -1969,20 +1969,25 @@ pub fn Hashed(comptime Hasher: type) type {...@@ -1969,20 +1969,25 @@ pub fn Hashed(comptime Hasher: type) type {
1969 return struct {1969 return struct {
1970 out: *Writer,1970 out: *Writer,
1971 hasher: Hasher,1971 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() {
1975 return .{1979 return .{
1976 .out = out,1980 .out = out,
1977 .hasher = .{},1981 .hasher = hasher,
1978 .interface = .{1982 .writer = .{
1983 .buffer = buffer,
1979 .vtable = &.{@This().drain},1984 .vtable = &.{@This().drain},
1980 },1985 },
1981 };1986 };
1982 }1987 }
19831988
1984 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {1989 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));
1986 if (data.len == 0) {1991 if (data.len == 0) {
1987 const buf = w.buffered();1992 const buf = w.buffered();
1988 try this.out.writeAll(buf);1993 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 {...@@ -2689,7 +2689,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2689 const is_hit = man.hit() catch |err| switch (err) {2689 const is_hit = man.hit() catch |err| switch (err) {
2690 error.CacheCheckFailed => switch (man.diagnostic) {2690 error.CacheCheckFailed => switch (man.diagnostic) {
2691 .none => unreachable,2691 .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(
2693 .check_whole_cache,2693 .check_whole_cache,
2694 "failed to check cache: {s} {s}",2694 "failed to check cache: {s} {s}",
2695 .{ @tagName(man.diagnostic), @errorName(e) },2695 .{ @tagName(man.diagnostic), @errorName(e) },
src/InternPool.zig+29-30
...@@ -1881,23 +1881,23 @@ pub const NullTerminatedString = enum(u32) {...@@ -1881,23 +1881,23 @@ pub const NullTerminatedString = enum(u32) {
1881 const FormatData = struct {1881 const FormatData = struct {
1882 string: NullTerminatedString,1882 string: NullTerminatedString,
1883 ip: *const InternPool,1883 ip: *const InternPool,
1884 id: bool,
1884 };1885 };
1885 fn format(1886 fn format(data: FormatData, writer: *std.io.Writer) std.io.Writer.Error!void {
1886 data: FormatData,
1887 comptime specifier: []const u8,
1888 _: std.fmt.FormatOptions,
1889 writer: anytype,
1890 ) @TypeOf(writer).Error!void {
1891 const slice = data.string.toSlice(data.ip);1887 const slice = data.string.toSlice(data.ip);
1892 if (comptime std.mem.eql(u8, specifier, "")) {1888 if (!data.id) {
1893 try writer.writeAll(slice);1889 try writer.writeAll(slice);
1894 } else if (comptime std.mem.eql(u8, specifier, "i")) {1890 } else {
1895 try writer.print("{f}", .{std.zig.fmtIdP(slice)});1891 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 } };
1897 }1897 }
18981898
1899 pub fn fmt(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(format) {1899 pub fn fmtId(string: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(FormatData, format) {
1900 return .{ .data = .{ .string = string, .ip = ip } };1900 return .{ .data = .{ .string = string, .ip = ip, .id = true } };
1901 }1901 }
19021902
1903 const debug_state = InternPool.debug_state;1903 const debug_state = InternPool.debug_state;
...@@ -9750,7 +9750,7 @@ fn finishFuncInstance(...@@ -9750,7 +9750,7 @@ fn finishFuncInstance(
9750 const fn_namespace = fn_owner_nav.analysis.?.namespace;9750 const fn_namespace = fn_owner_nav.analysis.?.namespace;
97519751
9752 // TODO: improve this name9752 // 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}", .{
9754 fn_owner_nav.name.fmt(ip), @intFromEnum(func_index),9754 fn_owner_nav.name.fmt(ip), @intFromEnum(func_index),
9755 }, .no_embedded_nulls);9755 }, .no_embedded_nulls);
9756 const nav_index = try ip.createNav(gpa, tid, .{9756 const nav_index = try ip.createNav(gpa, tid, .{
...@@ -11259,8 +11259,9 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {...@@ -11259,8 +11259,9 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
11259}11259}
1126011260
11261fn dumpAllFallible(ip: *const InternPool) anyerror!void {11261fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11262 var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());11262 var buffer: [4096]u8 = undefined;
11263 const w = bw.writer();11263 const stderr_bw = std.debug.lockStderrWriter(&buffer);
11264 defer std.debug.unlockStderrWriter();
11264 for (ip.locals, 0..) |*local, tid| {11265 for (ip.locals, 0..) |*local, tid| {
11265 const items = local.shared.items.view();11266 const items = local.shared.items.view();
11266 for (11267 for (
...@@ -11269,12 +11270,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {...@@ -11269,12 +11270,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11269 0..,11270 0..,
11270 ) |tag, data, index| {11271 ) |tag, data, index| {
11271 const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip);11272 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) });
11273 switch (tag) {11274 switch (tag) {
11274 .removed => {},11275 .removed => {},
1127511276
11276 .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),11277 .simple_type => try stderr_bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
11277 .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),11278 .simple_value => try stderr_bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
1127811279
11279 .type_int_signed,11280 .type_int_signed,
11280 .type_int_unsigned,11281 .type_int_unsigned,
...@@ -11347,17 +11348,16 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {...@@ -11347,17 +11348,16 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11347 .func_coerced,11348 .func_coerced,
11348 .union_value,11349 .union_value,
11349 .memoized_call,11350 .memoized_call,
11350 => try w.print("{d}", .{data}),11351 => try stderr_bw.print("{d}", .{data}),
1135111352
11352 .opt_null,11353 .opt_null,
11353 .type_slice,11354 .type_slice,
11354 .only_possible_value,11355 .only_possible_value,
11355 => try w.print("${d}", .{data}),11356 => try stderr_bw.print("${d}", .{data}),
11356 }11357 }
11357 try w.writeAll(")\n");11358 try stderr_bw.writeAll(")\n");
11358 }11359 }
11359 }11360 }
11360 try bw.flush();
11361}11361}
1136211362
11363pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void {11363pub fn dumpGenericInstances(ip: *const InternPool, allocator: Allocator) void {
...@@ -11369,9 +11369,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)...@@ -11369,9 +11369,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
11369 defer arena_allocator.deinit();11369 defer arena_allocator.deinit();
11370 const arena = arena_allocator.allocator();11370 const arena = arena_allocator.allocator();
1137111371
11372 var bw = std.io.bufferedWriter(std.fs.File.stderr().deprecatedWriter());
11373 const w = bw.writer();
11374
11375 var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;11372 var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;
11376 for (ip.locals, 0..) |*local, tid| {11373 for (ip.locals, 0..) |*local, tid| {
11377 const items = local.shared.items.view().slice();11374 const items = local.shared.items.view().slice();
...@@ -11394,6 +11391,10 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)...@@ -11394,6 +11391,10 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
11394 }11391 }
11395 }11392 }
1139611393
11394 var buffer: [4096]u8 = undefined;
11395 const stderr_bw = std.debug.lockStderrWriter(&buffer);
11396 defer std.debug.unlockStderrWriter();
11397
11397 const SortContext = struct {11398 const SortContext = struct {
11398 values: []std.ArrayListUnmanaged(Index),11399 values: []std.ArrayListUnmanaged(Index),
11399 pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {11400 pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
...@@ -11405,23 +11406,21 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)...@@ -11405,23 +11406,21 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
11405 var it = instances.iterator();11406 var it = instances.iterator();
11406 while (it.next()) |entry| {11407 while (it.next()) |entry| {
11407 const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav);11408 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 });
11409 for (entry.value_ptr.items) |index| {11410 for (entry.value_ptr.items) |index| {
11410 const unwrapped_index = index.unwrap(ip);11411 const unwrapped_index = index.unwrap(ip);
11411 const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip));11412 const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip));
11412 const owner_nav = ip.getNav(func.owner_nav);11413 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)});
11414 for (func.comptime_args.get(ip)) |arg| {11415 for (func.comptime_args.get(ip)) |arg| {
11415 if (arg != .none) {11416 if (arg != .none) {
11416 const key = ip.indexToKey(arg);11417 const key = ip.indexToKey(arg);
11417 try w.print(" {} ", .{key});11418 try stderr_bw.print(" {} ", .{key});
11418 }11419 }
11419 }11420 }
11420 try w.writeAll(")\n");11421 try stderr_bw.writeAll(")\n");
11421 }11422 }
11422 }11423 }
11423
11424 try bw.flush();
11425}11424}
1142611425
11427pub fn getNav(ip: *const InternPool, index: Nav.Index) Nav {11426pub fn getNav(ip: *const InternPool, index: Nav.Index) Nav {
src/Package/Fetch/git.zig+5-5
...@@ -1320,7 +1320,7 @@ fn indexPackFirstPass(...@@ -1320,7 +1320,7 @@ fn indexPackFirstPass(
1320 index_entries: *std.AutoHashMapUnmanaged(Oid, IndexEntry),1320 index_entries: *std.AutoHashMapUnmanaged(Oid, IndexEntry),
1321 pending_deltas: *std.ArrayListUnmanaged(IndexEntry),1321 pending_deltas: *std.ArrayListUnmanaged(IndexEntry),
1322) !Oid {1322) !Oid {
1323 var pack_buffered_reader = std.io.bufferedReader(pack.reader());1323 var pack_buffered_reader = std.io.bufferedReader(pack.deprecatedReader());
1324 var pack_counting_reader = std.io.countingReader(pack_buffered_reader.reader());1324 var pack_counting_reader = std.io.countingReader(pack_buffered_reader.reader());
1325 var pack_hashed_reader = std.compress.hashedReader(pack_counting_reader.reader(), Oid.Hasher.init(format));1325 var pack_hashed_reader = std.compress.hashedReader(pack_counting_reader.reader(), Oid.Hasher.init(format));
1326 const pack_reader = pack_hashed_reader.reader();1326 const pack_reader = pack_hashed_reader.reader();
...@@ -1400,7 +1400,7 @@ fn indexPackHashDelta(...@@ -1400,7 +1400,7 @@ fn indexPackHashDelta(
1400 if (cache.get(base_offset)) |base_object| break base_object;1400 if (cache.get(base_offset)) |base_object| break base_object;
14011401
1402 try pack.seekTo(base_offset);1402 try pack.seekTo(base_offset);
1403 base_header = try EntryHeader.read(format, pack.reader());1403 base_header = try EntryHeader.read(format, pack.deprecatedReader());
1404 switch (base_header) {1404 switch (base_header) {
1405 .ofs_delta => |ofs_delta| {1405 .ofs_delta => |ofs_delta| {
1406 try delta_offsets.append(allocator, base_offset);1406 try delta_offsets.append(allocator, base_offset);
...@@ -1411,7 +1411,7 @@ fn indexPackHashDelta(...@@ -1411,7 +1411,7 @@ fn indexPackHashDelta(
1411 base_offset = (index_entries.get(ref_delta.base_object) orelse return null).offset;1411 base_offset = (index_entries.get(ref_delta.base_object) orelse return null).offset;
1412 },1412 },
1413 else => {1413 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());
1415 errdefer allocator.free(base_data);1415 errdefer allocator.free(base_data);
1416 const base_object: Object = .{ .type = base_header.objectType(), .data = base_data };1416 const base_object: Object = .{ .type = base_header.objectType(), .data = base_data };
1417 try cache.put(allocator, base_offset, base_object);1417 try cache.put(allocator, base_offset, base_object);
...@@ -1448,8 +1448,8 @@ fn resolveDeltaChain(...@@ -1448,8 +1448,8 @@ fn resolveDeltaChain(
14481448
1449 const delta_offset = delta_offsets[i];1449 const delta_offset = delta_offsets[i];
1450 try pack.seekTo(delta_offset);1450 try pack.seekTo(delta_offset);
1451 const delta_header = try EntryHeader.read(format, pack.reader());1451 const delta_header = try EntryHeader.read(format, pack.deprecatedReader());
1452 const delta_data = try readObjectRaw(allocator, pack.reader(), delta_header.uncompressedLength());1452 const delta_data = try readObjectRaw(allocator, pack.deprecatedReader(), delta_header.uncompressedLength());
1453 defer allocator.free(delta_data);1453 defer allocator.free(delta_data);
1454 var delta_stream = std.io.fixedBufferStream(delta_data);1454 var delta_stream = std.io.fixedBufferStream(delta_data);
1455 const delta_reader = delta_stream.reader();1455 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 {...@@ -4307,15 +4307,19 @@ pub fn navFileScope(zcu: *Zcu, nav: InternPool.Nav.Index) *File {
4307 return zcu.fileByIndex(zcu.navFileScopeIndex(nav));4307 return zcu.fileByIndex(zcu.navFileScopeIndex(nav));
4308}4308}
43094309
4310pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(formatAnalUnit) {4310pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(FormatAnalUnit, formatAnalUnit) {
4311 return .{ .data = .{ .unit = unit, .zcu = zcu } };4311 return .{ .data = .{ .unit = unit, .zcu = zcu } };
4312}4312}
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) {
4314 return .{ .data = .{ .dependee = d, .zcu = zcu } };4314 return .{ .data = .{ .dependee = d, .zcu = zcu } };
4315}4315}
43164316
4317fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {4317const FormatAnalUnit = struct {
4318 _ = .{ fmt, options };4318 unit: AnalUnit,
4319 zcu: *Zcu,
4320};
4321
4322fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Error!void {
4319 const zcu = data.zcu;4323 const zcu = data.zcu;
4320 const ip = &zcu.intern_pool;4324 const ip = &zcu.intern_pool;
4321 switch (data.unit.unwrap()) {4325 switch (data.unit.unwrap()) {
...@@ -4338,8 +4342,10 @@ fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, comptime fmt: []co...@@ -4338,8 +4342,10 @@ fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, comptime fmt: []co
4338 .memoized_state => return writer.writeAll("memoized_state"),4342 .memoized_state => return writer.writeAll("memoized_state"),
4339 }4343 }
4340}4344}
4341fn formatDependee(data: struct { dependee: InternPool.Dependee, zcu: *Zcu }, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {4345
4342 _ = .{ fmt, options };4346const FormatDependee = struct { dependee: InternPool.Dependee, zcu: *Zcu };
4347
4348fn formatDependee(data: FormatDependee, writer: *std.io.Writer) std.io.Writer.Error!void {
4343 const zcu = data.zcu;4349 const zcu = data.zcu;
4344 const ip = &zcu.intern_pool;4350 const ip = &zcu.intern_pool;
4345 switch (data.dependee) {4351 switch (data.dependee) {
src/crash_report.zig+22-15
...@@ -80,18 +80,19 @@ fn dumpStatusReport() !void {...@@ -80,18 +80,19 @@ fn dumpStatusReport() !void {
80 var fba = std.heap.FixedBufferAllocator.init(&crash_heap);80 var fba = std.heap.FixedBufferAllocator.init(&crash_heap);
81 const allocator = fba.allocator();81 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;
84 const block: *Sema.Block = anal.block;85 const block: *Sema.Block = anal.block;
85 const zcu = anal.sema.pt.zcu;86 const zcu = anal.sema.pt.zcu;
8687
87 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse {88 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse {
88 const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool));89 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)});
90 return;91 return;
91 };92 };
9293
93 try stderr.writeAll("Analyzing ");94 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
96 print_zir.renderInstructionContext(97 print_zir.renderInstructionContext(
97 allocator,98 allocator,
...@@ -107,7 +108,7 @@ fn dumpStatusReport() !void {...@@ -107,7 +108,7 @@ fn dumpStatusReport() !void {
107 };108 };
108 try stderr.print(109 try stderr.print(
109 \\ For full context, use the command110 \\ For full context, use the command
110 \\ zig ast-check -t {}111 \\ zig ast-check -t {f}
111 \\112 \\
112 \\113 \\
113 , .{file.path.fmt(zcu.comp)});114 , .{file.path.fmt(zcu.comp)});
...@@ -116,7 +117,7 @@ fn dumpStatusReport() !void {...@@ -116,7 +117,7 @@ fn dumpStatusReport() !void {
116 while (parent) |curr| {117 while (parent) |curr| {
117 fba.reset();118 fba.reset();
118 const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool));119 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)});
120 _, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse {121 _, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse {
121 try stderr.writeAll(" > [lost instruction; this should not happen]\n");122 try stderr.writeAll(" > [lost instruction; this should not happen]\n");
122 parent = curr.parent;123 parent = curr.parent;
...@@ -139,7 +140,7 @@ fn dumpStatusReport() !void {...@@ -139,7 +140,7 @@ fn dumpStatusReport() !void {
139 parent = curr.parent;140 parent = curr.parent;
140 }141 }
141142
142 try stderr.writeAll("\n");143 try stderr.writeByte('\n');
143}144}
144145
145var crash_heap: [16 * 4096]u8 = undefined;146var crash_heap: [16 * 4096]u8 = undefined;
...@@ -268,11 +269,12 @@ const StackContext = union(enum) {...@@ -268,11 +269,12 @@ const StackContext = union(enum) {
268 debug.dumpCurrentStackTrace(ct.ret_addr);269 debug.dumpCurrentStackTrace(ct.ret_addr);
269 },270 },
270 .exception => |context| {271 .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);
272 },275 },
273 .not_supported => {276 .not_supported => {
274 const stderr = std.fs.File.stderr().deprecatedWriter();277 std.fs.File.stderr().writeAll("Stack trace not supported on this platform.\n") catch {};
275 stderr.writeAll("Stack trace not supported on this platform.\n") catch {};
276 },278 },
277 }279 }
278 }280 }
...@@ -379,7 +381,8 @@ const PanicSwitch = struct {...@@ -379,7 +381,8 @@ const PanicSwitch = struct {
379381
380 state.recover_stage = .release_mutex;382 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;
383 if (builtin.single_threaded) {386 if (builtin.single_threaded) {
384 stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state});387 stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state});
385 } else {388 } else {
...@@ -406,7 +409,8 @@ const PanicSwitch = struct {...@@ -406,7 +409,8 @@ const PanicSwitch = struct {
406 recover(state, trace, stack, msg);409 recover(state, trace, stack, msg);
407410
408 state.recover_stage = .release_mutex;411 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;
410 stderr.writeAll("\nOriginal Error:\n") catch {};414 stderr.writeAll("\nOriginal Error:\n") catch {};
411 goTo(reportStack, .{state});415 goTo(reportStack, .{state});
412 }416 }
...@@ -477,7 +481,8 @@ const PanicSwitch = struct {...@@ -477,7 +481,8 @@ const PanicSwitch = struct {
477 recover(state, trace, stack, msg);481 recover(state, trace, stack, msg);
478482
479 state.recover_stage = .silent_abort;483 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;
481 stderr.writeAll("Aborting...\n") catch {};486 stderr.writeAll("Aborting...\n") catch {};
482 goTo(abort, .{});487 goTo(abort, .{});
483 }488 }
...@@ -505,7 +510,8 @@ const PanicSwitch = struct {...@@ -505,7 +510,8 @@ const PanicSwitch = struct {
505 // lower the verbosity, and restore it at the end if we don't panic.510 // lower the verbosity, and restore it at the end if we don't panic.
506 state.recover_verbosity = .message_only;511 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;
509 stderr.writeAll("\nPanicked during a panic: ") catch {};515 stderr.writeAll("\nPanicked during a panic: ") catch {};
510 stderr.writeAll(msg) catch {};516 stderr.writeAll(msg) catch {};
511 stderr.writeAll("\nInner panic stack:\n") catch {};517 stderr.writeAll("\nInner panic stack:\n") catch {};
...@@ -519,10 +525,11 @@ const PanicSwitch = struct {...@@ -519,10 +525,11 @@ const PanicSwitch = struct {
519 .message_only => {525 .message_only => {
520 state.recover_verbosity = .silent;526 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;
523 stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {};530 stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {};
524 stderr.writeAll(msg) catch {};531 stderr.writeAll(msg) catch {};
525 stderr.writeAll("\n") catch {};532 stderr.writeByte('\n') catch {};
526533
527 // If we succeed, restore all the way to dumping the stack.534 // If we succeed, restore all the way to dumping the stack.
528 state.recover_verbosity = .message_and_stack;535 state.recover_verbosity = .message_and_stack;
src/dev.zig+4
...@@ -78,6 +78,7 @@ pub const Env = enum {...@@ -78,6 +78,7 @@ pub const Env = enum {
78 .ast_gen,78 .ast_gen,
79 .sema,79 .sema,
80 .legalize,80 .legalize,
81 .c_compiler,
81 .llvm_backend,82 .llvm_backend,
82 .c_backend,83 .c_backend,
83 .wasm_backend,84 .wasm_backend,
...@@ -127,6 +128,7 @@ pub const Env = enum {...@@ -127,6 +128,7 @@ pub const Env = enum {
127 .clang_command,128 .clang_command,
128 .cc_command,129 .cc_command,
129 .translate_c_command,130 .translate_c_command,
131 .c_compiler,
130 => true,132 => true,
131 else => false,133 else => false,
132 },134 },
...@@ -248,6 +250,8 @@ pub const Feature = enum {...@@ -248,6 +250,8 @@ pub const Feature = enum {
248 sema,250 sema,
249 legalize,251 legalize,
250252
253 c_compiler,
254
251 llvm_backend,255 llvm_backend,
252 c_backend,256 c_backend,
253 wasm_backend,257 wasm_backend,
src/link/MachO/Object.zig+4-11
...@@ -2660,24 +2660,17 @@ fn formatSymtab(...@@ -2660,24 +2660,17 @@ fn formatSymtab(
2660 }2660 }
2661}2661}
26622662
2663pub fn fmtPath(self: Object) std.fmt.Formatter(formatPath) {2663pub fn fmtPath(self: Object) std.fmt.Formatter(Object, formatPath) {
2664 return .{ .data = self };2664 return .{ .data = self };
2665}2665}
26662666
2667fn formatPath(2667fn formatPath(object: Object, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
2675 if (object.in_archive) |ar| {2668 if (object.in_archive) |ar| {
2676 try writer.print("{}({s})", .{2669 try writer.print("{f}({s})", .{
2677 @as(Path, ar.path), object.path.basename(),2670 @as(Path, ar.path), object.path.basename(),
2678 });2671 });
2679 } else {2672 } else {
2680 try writer.print("{}", .{@as(Path, object.path)});2673 try writer.print("{f}", .{@as(Path, object.path)});
2681 }2674 }
2682}2675}
26832676
src/link/MachO/file.zig+2-9
...@@ -10,18 +10,11 @@ pub const File = union(enum) {...@@ -10,18 +10,11 @@ pub const File = union(enum) {
10 };10 };
11 }11 }
1212
13 pub fn fmtPath(file: File) std.fmt.Formatter(formatPath) {13 pub fn fmtPath(file: File) std.fmt.Formatter(File, formatPath) {
14 return .{ .data = file };14 return .{ .data = file };
15 }15 }
1616
17 fn formatPath(17 fn formatPath(file: File, writer: *std.io.Writer) std.io.Writer.Error!void {
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;
25 switch (file) {18 switch (file) {
26 .zig_object => |zo| try writer.writeAll(zo.basename),19 .zig_object => |zo| try writer.writeAll(zo.basename),
27 .internal => try writer.writeAll("internal"),20 .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...@@ -117,7 +117,7 @@ pub fn updateNav(self: *SpirV, pt: Zcu.PerThread, nav: InternPool.Nav.Index) lin
117 }117 }
118118
119 const ip = &pt.zcu.intern_pool;119 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
122 try self.object.updateNav(pt, nav);122 try self.object.updateNav(pt, nav);
123}123}
...@@ -203,10 +203,10 @@ pub fn flush(...@@ -203,10 +203,10 @@ pub fn flush(
203 // We need to export the list of error names somewhere so that we can pretty-print them in the203 // We need to export the list of error names somewhere so that we can pretty-print them in the
204 // executor. This is not really an important thing though, so we can just dump it in any old204 // executor. This is not really an important thing though, so we can just dump it in any old
205 // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name.205 // 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);
207 defer error_info.deinit();207 defer error_info.deinit();
208208
209 try error_info.appendSlice("zig_errors:");209 error_info.writer.writeAll("zig_errors:") catch return error.OutOfMemory;
210 const ip = &self.base.comp.zcu.?.intern_pool;210 const ip = &self.base.comp.zcu.?.intern_pool;
211 for (ip.global_error_set.getNamesFromMainThread()) |name| {211 for (ip.global_error_set.getNamesFromMainThread()) |name| {
212 // Errors can contain pretty much any character - to encode them in a string we must escape212 // Errors can contain pretty much any character - to encode them in a string we must escape
...@@ -214,9 +214,9 @@ pub fn flush(...@@ -214,9 +214,9 @@ pub fn flush(
214 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.214 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
215 // We're using : as separator, which is a reserved character.215 // We're using : as separator, which is a reserved character.
216216
217 try error_info.append(':');217 error_info.writer.writeByte(':') catch return error.OutOfMemory;
218 try std.Uri.Component.percentEncode(218 std.Uri.Component.percentEncode(
219 error_info.writer(),219 &error_info.writer,
220 name.toSlice(ip),220 name.toSlice(ip),
221 struct {221 struct {
222 fn isValidChar(c: u8) bool {222 fn isValidChar(c: u8) bool {
...@@ -226,10 +226,10 @@ pub fn flush(...@@ -226,10 +226,10 @@ pub fn flush(
226 };226 };
227 }227 }
228 }.isValidChar,228 }.isValidChar,
229 );229 ) catch return error.OutOfMemory;
230 }230 }
231 try spv.sections.debug_strings.emit(gpa, .OpSourceExtension, .{231 try spv.sections.debug_strings.emit(gpa, .OpSourceExtension, .{
232 .extension = error_info.items,232 .extension = error_info.getWritten(),
233 });233 });
234234
235 const module = try spv.finalize(arena);235 const module = try spv.finalize(arena);
src/link/SpirV/deduplicate.zig+1-1
...@@ -110,7 +110,7 @@ const ModuleInfo = struct {...@@ -110,7 +110,7 @@ const ModuleInfo = struct {
110 .TypeDeclaration, .ConstantCreation => {110 .TypeDeclaration, .ConstantCreation => {
111 const entry = try entities.getOrPut(result_id);111 const entry = try entities.getOrPut(result_id);
112 if (entry.found_existing) {112 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});
114 return error.DuplicateId;114 return error.DuplicateId;
115 }115 }
116 entry.value_ptr.* = entity;116 entry.value_ptr.* = entity;
src/link/SpirV/lower_invocation_globals.zig+9-9
...@@ -92,7 +92,7 @@ const ModuleInfo = struct {...@@ -92,7 +92,7 @@ const ModuleInfo = struct {
92 const entry_point: ResultId = @enumFromInt(inst.operands[1]);92 const entry_point: ResultId = @enumFromInt(inst.operands[1]);
93 const entry = try entry_points.getOrPut(entry_point);93 const entry = try entry_points.getOrPut(entry_point);
94 if (entry.found_existing) {94 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});
96 return error.DuplicateId;96 return error.DuplicateId;
97 }97 }
98 },98 },
...@@ -103,7 +103,7 @@ const ModuleInfo = struct {...@@ -103,7 +103,7 @@ const ModuleInfo = struct {
103103
104 const entry = try fn_types.getOrPut(fn_type);104 const entry = try fn_types.getOrPut(fn_type);
105 if (entry.found_existing) {105 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});
107 return error.DuplicateId;107 return error.DuplicateId;
108 }108 }
109109
...@@ -135,7 +135,7 @@ const ModuleInfo = struct {...@@ -135,7 +135,7 @@ const ModuleInfo = struct {
135 },135 },
136 .OpFunction => {136 .OpFunction => {
137 if (maybe_current_function) |current_function| {137 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});
139 return error.InvalidPhysicalFormat;139 return error.InvalidPhysicalFormat;
140 }140 }
141141
...@@ -154,7 +154,7 @@ const ModuleInfo = struct {...@@ -154,7 +154,7 @@ const ModuleInfo = struct {
154 };154 };
155 const entry = try functions.getOrPut(current_function);155 const entry = try functions.getOrPut(current_function);
156 if (entry.found_existing) {156 if (entry.found_existing) {
157 log.err("Function {} has duplicate definition", .{current_function});157 log.err("Function {f} has duplicate definition", .{current_function});
158 return error.DuplicateId;158 return error.DuplicateId;
159 }159 }
160160
...@@ -162,7 +162,7 @@ const ModuleInfo = struct {...@@ -162,7 +162,7 @@ const ModuleInfo = struct {
162 try callee_store.appendSlice(calls.keys());162 try callee_store.appendSlice(calls.keys());
163163
164 const fn_type = fn_types.get(fn_ty_id) orelse {164 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});
166 return error.InvalidId;166 return error.InvalidId;
167 };167 };
168168
...@@ -187,7 +187,7 @@ const ModuleInfo = struct {...@@ -187,7 +187,7 @@ const ModuleInfo = struct {
187 }187 }
188188
189 if (maybe_current_function) |current_function| {189 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});
191 return error.InvalidPhysicalFormat;191 return error.InvalidPhysicalFormat;
192 }192 }
193193
...@@ -222,7 +222,7 @@ const ModuleInfo = struct {...@@ -222,7 +222,7 @@ const ModuleInfo = struct {
222 seen: *std.DynamicBitSetUnmanaged,222 seen: *std.DynamicBitSetUnmanaged,
223 ) !void {223 ) !void {
224 const index = self.functions.getIndex(id) orelse {224 const index = self.functions.getIndex(id) orelse {
225 log.err("function calls invalid function {}", .{id});225 log.err("function calls invalid function {f}", .{id});
226 return error.InvalidId;226 return error.InvalidId;
227 };227 };
228228
...@@ -261,7 +261,7 @@ const ModuleInfo = struct {...@@ -261,7 +261,7 @@ const ModuleInfo = struct {
261 seen: *std.DynamicBitSetUnmanaged,261 seen: *std.DynamicBitSetUnmanaged,
262 ) !void {262 ) !void {
263 const index = self.invocation_globals.getIndex(id) orelse {263 const index = self.invocation_globals.getIndex(id) orelse {
264 log.err("invalid invocation global {}", .{id});264 log.err("invalid invocation global {f}", .{id});
265 return error.InvalidId;265 return error.InvalidId;
266 };266 };
267267
...@@ -276,7 +276,7 @@ const ModuleInfo = struct {...@@ -276,7 +276,7 @@ const ModuleInfo = struct {
276 }276 }
277277
278 const initializer = self.functions.get(info.initializer) orelse {278 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 });
280 return error.InvalidId;280 return error.InvalidId;
281 };281 };
282282
src/link/SpirV/prune_unused.zig+4-4
...@@ -128,7 +128,7 @@ const ModuleInfo = struct {...@@ -128,7 +128,7 @@ const ModuleInfo = struct {
128 switch (inst.opcode) {128 switch (inst.opcode) {
129 .OpFunction => {129 .OpFunction => {
130 if (maybe_current_function) |current_function| {130 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});
132 return error.InvalidPhysicalFormat;132 return error.InvalidPhysicalFormat;
133 }133 }
134134
...@@ -145,7 +145,7 @@ const ModuleInfo = struct {...@@ -145,7 +145,7 @@ const ModuleInfo = struct {
145 };145 };
146 const entry = try functions.getOrPut(current_function);146 const entry = try functions.getOrPut(current_function);
147 if (entry.found_existing) {147 if (entry.found_existing) {
148 log.err("Function {} has duplicate definition", .{current_function});148 log.err("Function {f} has duplicate definition", .{current_function});
149 return error.DuplicateId;149 return error.DuplicateId;
150 }150 }
151151
...@@ -163,7 +163,7 @@ const ModuleInfo = struct {...@@ -163,7 +163,7 @@ const ModuleInfo = struct {
163 }163 }
164164
165 if (maybe_current_function) |current_function| {165 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});
167 return error.InvalidPhysicalFormat;167 return error.InvalidPhysicalFormat;
168 }168 }
169169
...@@ -184,7 +184,7 @@ const AliveMarker = struct {...@@ -184,7 +184,7 @@ const AliveMarker = struct {
184184
185 fn markAlive(self: *AliveMarker, result_id: ResultId) BinaryModule.ParseError!void {185 fn markAlive(self: *AliveMarker, result_id: ResultId) BinaryModule.ParseError!void {
186 const index = self.info.result_id_to_code_offset.getIndex(result_id) orelse {186 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});
188 return error.InvalidId;188 return error.InvalidId;
189 };189 };
190190
src/main.zig+78-70
...@@ -65,6 +65,9 @@ pub fn wasi_cwd() std.os.wasi.fd_t {...@@ -65,6 +65,9 @@ pub fn wasi_cwd() std.os.wasi.fd_t {
6565
66const fatal = std.process.fatal;66const fatal = std.process.fatal;
6767
68/// This can be global since stdout is a singleton.
69var stdio_buffer: [4096]u8 = undefined;
70
68/// Shaming all the locations that inappropriately use an O(N) search algorithm.71/// Shaming all the locations that inappropriately use an O(N) search algorithm.
69/// Please delete this and fix the compilation errors!72/// Please delete this and fix the compilation errors!
70pub const @"bad O(N)" = void;73pub const @"bad O(N)" = void;
...@@ -352,7 +355,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -352,7 +355,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
352 } else if (mem.eql(u8, cmd, "env")) {355 } else if (mem.eql(u8, cmd, "env")) {
353 dev.check(.env_command);356 dev.check(.env_command);
354 verifyLibcxxCorrectlyLinked();357 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);
356 } else if (mem.eql(u8, cmd, "reduce")) {359 } else if (mem.eql(u8, cmd, "reduce")) {
357 return jitCmd(gpa, arena, cmd_args, .{360 return jitCmd(gpa, arena, cmd_args, .{
358 .cmd_name = "reduce",361 .cmd_name = "reduce",
...@@ -1806,6 +1809,7 @@ fn buildOutputType(...@@ -1806,6 +1809,7 @@ fn buildOutputType(
1806 } else manifest_file = arg;1809 } else manifest_file = arg;
1807 },1810 },
1808 .assembly, .assembly_with_cpp, .c, .cpp, .h, .hpp, .hm, .hmm, .ll, .bc, .m, .mm => {1811 .assembly, .assembly_with_cpp, .c, .cpp, .h, .hpp, .hm, .hmm, .ll, .bc, .m, .mm => {
1812 dev.check(.c_compiler);
1809 try create_module.c_source_files.append(arena, .{1813 try create_module.c_source_files.append(arena, .{
1810 // Populated after module creation.1814 // Populated after module creation.
1811 .owner = undefined,1815 .owner = undefined,
...@@ -1816,6 +1820,7 @@ fn buildOutputType(...@@ -1816,6 +1820,7 @@ fn buildOutputType(
1816 });1820 });
1817 },1821 },
1818 .rc => {1822 .rc => {
1823 dev.check(.win32_resource);
1819 try create_module.rc_source_files.append(arena, .{1824 try create_module.rc_source_files.append(arena, .{
1820 // Populated after module creation.1825 // Populated after module creation.
1821 .owner = undefined,1826 .owner = undefined,
...@@ -3301,6 +3306,7 @@ fn buildOutputType(...@@ -3301,6 +3306,7 @@ fn buildOutputType(
3301 defer thread_pool.deinit();3306 defer thread_pool.deinit();
33023307
3303 for (create_module.c_source_files.items) |*src| {3308 for (create_module.c_source_files.items) |*src| {
3309 dev.check(.c_compiler);
3304 if (!mem.eql(u8, src.src_path, "-")) continue;3310 if (!mem.eql(u8, src.src_path, "-")) continue;
33053311
3306 const ext = src.ext orelse3312 const ext = src.ext orelse
...@@ -3325,13 +3331,17 @@ fn buildOutputType(...@@ -3325,13 +3331,17 @@ fn buildOutputType(
3325 // for the hashing algorithm here and in the cache are the same.3331 // for the hashing algorithm here and in the cache are the same.
3326 // We are providing our own cache key, because this file has nothing3332 // We are providing our own cache key, because this file has nothing
3327 // to do with the cache manifest.3333 // to do with the cache manifest.
3328 var hasher = Cache.Hasher.init("0123456789abcdef");3334 var file_writer = f.writer(&.{});
3329 var w = io.multiWriter(.{ f.writer(), hasher.writer() });3335 var buffer: [1000]u8 = undefined;
3330 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();3336 var hasher = file_writer.interface.hashed(Cache.Hasher.init("0123456789abcdef"), &buffer);
3331 try fifo.pump(fs.File.stdin().reader(), w.writer());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;3344 const bin_digest: Cache.BinDigest = hasher.hasher.finalResult();
3334 hasher.final(&bin_digest);
33353345
3336 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{3346 const sub_path = try std.fmt.allocPrint(arena, "tmp" ++ sep ++ "{x}-stdin{s}", .{
3337 &bin_digest, ext.canonicalName(target),3347 &bin_digest, ext.canonicalName(target),
...@@ -3505,7 +3515,7 @@ fn buildOutputType(...@@ -3505,7 +3515,7 @@ fn buildOutputType(
3505 if (t.arch == target.cpu.arch and t.os == target.os.tag) {3515 if (t.arch == target.cpu.arch and t.os == target.os.tag) {
3506 // If there's a `glibc_min`, there's also an `os_ver`.3516 // If there's a `glibc_min`, there's also an `os_ver`.
3507 if (t.glibc_min) |glibc_min| {3517 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}", .{
3509 @tagName(t.arch),3519 @tagName(t.arch),
3510 @tagName(t.os),3520 @tagName(t.os),
3511 t.os_ver.?,3521 t.os_ver.?,
...@@ -3514,7 +3524,7 @@ fn buildOutputType(...@@ -3514,7 +3524,7 @@ fn buildOutputType(
3514 glibc_min.minor,3524 glibc_min.minor,
3515 });3525 });
3516 } else if (t.os_ver) |os_ver| {3526 } 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}", .{
3518 @tagName(t.arch),3528 @tagName(t.arch),
3519 @tagName(t.os),3529 @tagName(t.os),
3520 os_ver,3530 os_ver,
...@@ -5480,7 +5490,7 @@ fn jitCmd(...@@ -5480,7 +5490,7 @@ fn jitCmd(
5480 defer comp.destroy();5490 defer comp.destroy();
54815491
5482 if (options.server) {5492 if (options.server) {
5483 var server = std.zig.Server{5493 var server: std.zig.Server = .{
5484 .out = fs.File.stdout(),5494 .out = fs.File.stdout(),
5485 .in = undefined, // won't be receiving messages5495 .in = undefined, // won't be receiving messages
5486 .receive_fifo = undefined, // won't be receiving messages5496 .receive_fifo = undefined, // won't be receiving messages
...@@ -6064,6 +6074,8 @@ fn cmdAstCheck(...@@ -6064,6 +6074,8 @@ fn cmdAstCheck(
60646074
6065 const tree = try Ast.parse(arena, source, mode);6075 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;
6067 switch (mode) {6079 switch (mode) {
6068 .zig => {6080 .zig => {
6069 const zir = try AstGen.generate(arena, tree);6081 const zir = try AstGen.generate(arena, tree);
...@@ -6106,31 +6118,30 @@ fn cmdAstCheck(...@@ -6106,31 +6118,30 @@ fn cmdAstCheck(
6106 const extra_bytes = zir.extra.len * @sizeOf(u32);6118 const extra_bytes = zir.extra.len * @sizeOf(u32);
6107 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +6119 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
6108 zir.string_bytes.len * @sizeOf(u8);6120 zir.string_bytes.len * @sizeOf(u8);
6109 const stdout = fs.File.stdout();
6110 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
6111 // zig fmt: off6121 // zig fmt: off
6112 try stdout.deprecatedWriter().print(6122 try stdout_bw.print(
6113 \\# Source bytes: {}6123 \\# Source bytes: {Bi}
6114 \\# Tokens: {} ({})6124 \\# Tokens: {} ({Bi})
6115 \\# AST Nodes: {} ({})6125 \\# AST Nodes: {} ({Bi})
6116 \\# Total ZIR bytes: {}6126 \\# Total ZIR bytes: {Bi}
6117 \\# Instructions: {d} ({})6127 \\# Instructions: {d} ({Bi})
6118 \\# String Table Bytes: {}6128 \\# String Table Bytes: {}
6119 \\# Extra Data Items: {d} ({})6129 \\# Extra Data Items: {d} ({Bi})
6120 \\6130 \\
6121 , .{6131 , .{
6122 fmtIntSizeBin(source.len),6132 source.len,
6123 tree.tokens.len, fmtIntSizeBin(token_bytes),6133 tree.tokens.len, token_bytes,
6124 tree.nodes.len, fmtIntSizeBin(tree_bytes),6134 tree.nodes.len, tree_bytes,
6125 fmtIntSizeBin(total_bytes),6135 total_bytes,
6126 zir.instructions.len, fmtIntSizeBin(instruction_bytes),6136 zir.instructions.len, instruction_bytes,
6127 fmtIntSizeBin(zir.string_bytes.len),6137 zir.string_bytes.len,
6128 zir.extra.len, fmtIntSizeBin(extra_bytes),6138 zir.extra.len, extra_bytes,
6129 });6139 });
6130 // zig fmt: on6140 // zig fmt: on
6131 }6141 }
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
6135 if (zir.hasCompileErrors()) {6146 if (zir.hasCompileErrors()) {
6136 process.exit(1);6147 process.exit(1);
...@@ -6157,7 +6168,8 @@ fn cmdAstCheck(...@@ -6157,7 +6168,8 @@ fn cmdAstCheck(
6157 fatal("-t option only available in builds of zig with debug extensions", .{});6168 fatal("-t option only available in builds of zig with debug extensions", .{});
6158 }6169 }
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();
6161 return cleanExit();6173 return cleanExit();
6162 },6174 },
6163 }6175 }
...@@ -6185,8 +6197,7 @@ fn cmdDetectCpu(args: []const []const u8) !void {...@@ -6185,8 +6197,7 @@ fn cmdDetectCpu(args: []const []const u8) !void {
6185 const arg = args[i];6197 const arg = args[i];
6186 if (mem.startsWith(u8, arg, "-")) {6198 if (mem.startsWith(u8, arg, "-")) {
6187 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {6199 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6188 const stdout = fs.File.stdout().deprecatedWriter();6200 try fs.File.stdout().writeAll(detect_cpu_usage);
6189 try stdout.writeAll(detect_cpu_usage);
6190 return cleanExit();6201 return cleanExit();
6191 } else if (mem.eql(u8, arg, "--llvm")) {6202 } else if (mem.eql(u8, arg, "--llvm")) {
6192 use_llvm = true;6203 use_llvm = true;
...@@ -6278,11 +6289,11 @@ fn detectNativeCpuWithLLVM(...@@ -6278,11 +6289,11 @@ fn detectNativeCpuWithLLVM(
6278}6289}
62796290
6280fn printCpu(cpu: std.Target.Cpu) !void {6291fn printCpu(cpu: std.Target.Cpu) !void {
6281 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());6292 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6282 const stdout = bw.writer();6293 const stdout_bw = &stdout_writer.interface;
62836294
6284 if (cpu.model.llvm_name) |llvm_name| {6295 if (cpu.model.llvm_name) |llvm_name| {
6285 try stdout.print("{s}\n", .{llvm_name});6296 try stdout_bw.print("{s}\n", .{llvm_name});
6286 }6297 }
62876298
6288 const all_features = cpu.arch.allFeaturesList();6299 const all_features = cpu.arch.allFeaturesList();
...@@ -6291,10 +6302,10 @@ fn printCpu(cpu: std.Target.Cpu) !void {...@@ -6291,10 +6302,10 @@ fn printCpu(cpu: std.Target.Cpu) !void {
6291 const index: std.Target.Cpu.Feature.Set.Index = @intCast(index_usize);6302 const index: std.Target.Cpu.Feature.Set.Index = @intCast(index_usize);
6292 const is_enabled = cpu.features.isEnabled(index);6303 const is_enabled = cpu.features.isEnabled(index);
6293 const plus_or_minus = "-+"[@intFromBool(is_enabled)];6304 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 });
6295 }6306 }
62966307
6297 try bw.flush();6308 try stdout_bw.flush();
6298}6309}
62996310
6300fn cmdDumpLlvmInts(6311fn cmdDumpLlvmInts(
...@@ -6327,16 +6338,14 @@ fn cmdDumpLlvmInts(...@@ -6327,16 +6338,14 @@ fn cmdDumpLlvmInts(
6327 const dl = tm.createTargetDataLayout();6338 const dl = tm.createTargetDataLayout();
6328 const context = llvm.Context.create();6339 const context = llvm.Context.create();
63296340
6330 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());6341 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6331 const stdout = bw.writer();6342 const stdout_bw = &stdout_writer.interface;
6332
6333 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {6343 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
6334 const int_type = context.intType(bits);6344 const int_type = context.intType(bits);
6335 const alignment = dl.abiAlignmentOfType(int_type);6345 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 });
6337 }6347 }
63386348 try stdout_bw.flush();
6339 try bw.flush();
63406349
6341 return cleanExit();6350 return cleanExit();
6342}6351}
...@@ -6358,6 +6367,8 @@ fn cmdDumpZir(...@@ -6358,6 +6367,8 @@ fn cmdDumpZir(
6358 defer f.close();6367 defer f.close();
63596368
6360 const zir = try Zcu.loadZirCache(arena, f);6369 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
6362 {6373 {
6363 const instruction_bytes = zir.instructions.len *6374 const instruction_bytes = zir.instructions.len *
...@@ -6367,25 +6378,24 @@ fn cmdDumpZir(...@@ -6367,25 +6378,24 @@ fn cmdDumpZir(
6367 const extra_bytes = zir.extra.len * @sizeOf(u32);6378 const extra_bytes = zir.extra.len * @sizeOf(u32);
6368 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +6379 const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes +
6369 zir.string_bytes.len * @sizeOf(u8);6380 zir.string_bytes.len * @sizeOf(u8);
6370 const stdout = fs.File.stdout();
6371 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
6372 // zig fmt: off6381 // zig fmt: off
6373 try stdout.deprecatedWriter().print(6382 try stdout_bw.print(
6374 \\# Total ZIR bytes: {}6383 \\# Total ZIR bytes: {Bi}
6375 \\# Instructions: {d} ({})6384 \\# Instructions: {d} ({Bi})
6376 \\# String Table Bytes: {}6385 \\# String Table Bytes: {Bi}
6377 \\# Extra Data Items: {d} ({})6386 \\# Extra Data Items: {d} ({Bi})
6378 \\6387 \\
6379 , .{6388 , .{
6380 fmtIntSizeBin(total_bytes),6389 total_bytes,
6381 zir.instructions.len, fmtIntSizeBin(instruction_bytes),6390 zir.instructions.len, instruction_bytes,
6382 fmtIntSizeBin(zir.string_bytes.len),6391 zir.string_bytes.len,
6383 zir.extra.len, fmtIntSizeBin(extra_bytes),6392 zir.extra.len, extra_bytes,
6384 });6393 });
6385 // zig fmt: on6394 // zig fmt: on
6386 }6395 }
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();
6389}6399}
63906400
6391/// This is only enabled for debug builds.6401/// This is only enabled for debug builds.
...@@ -6443,19 +6453,19 @@ fn cmdChangelist(...@@ -6443,19 +6453,19 @@ fn cmdChangelist(
6443 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;6453 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
6444 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);6454 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64456455
6446 var bw = io.bufferedWriter(fs.File.stdout().deprecatedWriter());6456 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);
6447 const stdout = bw.writer();6457 const stdout_bw = &stdout_writer.interface;
6448 {6458 {
6449 try stdout.print("Instruction mappings:\n", .{});6459 try stdout_bw.print("Instruction mappings:\n", .{});
6450 var it = inst_map.iterator();6460 var it = inst_map.iterator();
6451 while (it.next()) |entry| {6461 while (it.next()) |entry| {
6452 try stdout.print(" %{d} => %{d}\n", .{6462 try stdout_bw.print(" %{d} => %{d}\n", .{
6453 @intFromEnum(entry.key_ptr.*),6463 @intFromEnum(entry.key_ptr.*),
6454 @intFromEnum(entry.value_ptr.*),6464 @intFromEnum(entry.value_ptr.*),
6455 });6465 });
6456 }6466 }
6457 }6467 }
6458 try bw.flush();6468 try stdout_bw.flush();
6459}6469}
64606470
6461fn eatIntPrefix(arg: []const u8, base: u8) []const u8 {6471fn eatIntPrefix(arg: []const u8, base: u8) []const u8 {
...@@ -6717,13 +6727,10 @@ fn accessFrameworkPath(...@@ -6717,13 +6727,10 @@ fn accessFrameworkPath(
67176727
6718 for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| {6728 for (&[_][]const u8{ ".tbd", ".dylib", "" }) |ext| {
6719 test_path.clearRetainingCapacity();6729 test_path.clearRetainingCapacity();
6720 try test_path.writer().print("{s}" ++ sep ++ "{s}.framework" ++ sep ++ "{s}{s}", .{6730 try test_path.print("{s}" ++ sep ++ "{s}.framework" ++ sep ++ "{s}{s}", .{
6721 framework_dir_path,6731 framework_dir_path, framework_name, framework_name, ext,
6722 framework_name,
6723 framework_name,
6724 ext,
6725 });6732 });
6726 try checked_paths.writer().print("\n {s}", .{test_path.items});6733 try checked_paths.print("\n {s}", .{test_path.items});
6727 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {6734 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
6728 error.FileNotFound => continue,6735 error.FileNotFound => continue,
6729 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{6736 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
...@@ -6793,8 +6800,7 @@ fn cmdFetch(...@@ -6793,8 +6800,7 @@ fn cmdFetch(
6793 const arg = args[i];6800 const arg = args[i];
6794 if (mem.startsWith(u8, arg, "-")) {6801 if (mem.startsWith(u8, arg, "-")) {
6795 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {6802 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6796 const stdout = fs.File.stdout().deprecatedWriter();6803 try fs.File.stdout().writeAll(usage_fetch);
6797 try stdout.writeAll(usage_fetch);
6798 return cleanExit();6804 return cleanExit();
6799 } else if (mem.eql(u8, arg, "--global-cache-dir")) {6805 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
6800 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});6806 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
...@@ -6907,7 +6913,9 @@ fn cmdFetch(...@@ -6907,7 +6913,9 @@ fn cmdFetch(
69076913
6908 const name = switch (save) {6914 const name = switch (save) {
6909 .no => {6915 .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();
6911 return cleanExit();6919 return cleanExit();
6912 },6920 },
6913 .yes, .exact => |name| name: {6921 .yes, .exact => |name| name: {
...@@ -6943,7 +6951,7 @@ fn cmdFetch(...@@ -6943,7 +6951,7 @@ fn cmdFetch(
6943 var saved_path_or_url = path_or_url;6951 var saved_path_or_url = path_or_url;
69446952
6945 if (fetch.latest_commit) |latest_commit| resolved: {6953 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
6948 var uri = try std.Uri.parse(path_or_url);6956 var uri = try std.Uri.parse(path_or_url);
69496957
...@@ -6956,7 +6964,7 @@ fn cmdFetch(...@@ -6956,7 +6964,7 @@ fn cmdFetch(
6956 std.log.info("resolved ref '{s}' to commit {s}", .{ target_ref, latest_commit_hex });6964 std.log.info("resolved ref '{s}' to commit {s}", .{ target_ref, latest_commit_hex });
69576965
6958 // include the original refspec in a query parameter, could be used to check for updates6966 // 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}) };
6960 } else {6968 } else {
6961 std.log.info("resolved to commit {s}", .{latest_commit_hex});6969 std.log.info("resolved to commit {s}", .{latest_commit_hex});
6962 }6970 }
...@@ -6965,7 +6973,7 @@ fn cmdFetch(...@@ -6965,7 +6973,7 @@ fn cmdFetch(
6965 uri.fragment = .{ .raw = latest_commit_hex };6973 uri.fragment = .{ .raw = latest_commit_hex };
69666974
6967 switch (save) {6975 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}),
6969 .no, .exact => {}, // keep the original URL6977 .no, .exact => {}, // keep the original URL
6970 }6978 }
6971 }6979 }
src/print_env.zig+2-2
...@@ -4,7 +4,7 @@ const introspect = @import("introspect.zig");...@@ -4,7 +4,7 @@ const introspect = @import("introspect.zig");
4const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
5const fatal = std.process.fatal;5const 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 {
8 _ = args;8 _ = args;
9 const cwd_path = try introspect.getResolvedCwd(arena);9 const cwd_path = try introspect.getResolvedCwd(arena);
10 const self_exe_path = try std.fs.selfExePathAlloc(arena);10 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...@@ -21,7 +21,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Wr
21 const host = try std.zig.system.resolveTargetQuery(.{});21 const host = try std.zig.system.resolveTargetQuery(.{});
22 const triple = try host.zigTriple(arena);22 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());
25 const w = bw.writer();25 const w = bw.writer();
2626
27 var jws = std.json.writeStream(w, .{ .whitespace = .indent_1 });27 var jws = std.json.writeStream(w, .{ .whitespace = .indent_1 });
src/print_zir.zig+169-175
...@@ -9,13 +9,8 @@ const Zir = std.zig.Zir;...@@ -9,13 +9,8 @@ const Zir = std.zig.Zir;
9const Zcu = @import("Zcu.zig");9const Zcu = @import("Zcu.zig");
10const LazySrcLoc = Zcu.LazySrcLoc;10const LazySrcLoc = Zcu.LazySrcLoc;
1111
12/// Write human-readable, debug formatted ZIR code to a file.12/// Write human-readable, debug formatted ZIR code.
13pub fn renderAsTextToFile(13pub fn renderAsText(gpa: Allocator, tree: ?Ast, zir: Zir, bw: *std.io.Writer) !void {
14 gpa: Allocator,
15 tree: ?Ast,
16 zir: Zir,
17 fs_file: std.fs.File,
18) !void {
19 var arena = std.heap.ArenaAllocator.init(gpa);14 var arena = std.heap.ArenaAllocator.init(gpa);
20 defer arena.deinit();15 defer arena.deinit();
2116
...@@ -30,16 +25,13 @@ pub fn renderAsTextToFile(...@@ -30,16 +25,13 @@ pub fn renderAsTextToFile(
30 .recurse_blocks = true,25 .recurse_blocks = true,
31 };26 };
3227
33 var raw_stream = std.io.bufferedWriter(fs_file.deprecatedWriter());
34 const stream = raw_stream.writer();
35
36 const main_struct_inst: Zir.Inst.Index = .main_struct_inst;28 const main_struct_inst: Zir.Inst.Index = .main_struct_inst;
37 try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)});29 try bw.print("%{d} ", .{@intFromEnum(main_struct_inst)});
38 try writer.writeInstToStream(stream, main_struct_inst);30 try writer.writeInstToStream(bw, main_struct_inst);
39 try stream.writeAll("\n");31 try bw.writeAll("\n");
40 const imports_index = zir.extra[@intFromEnum(Zir.ExtraIndex.imports)];32 const imports_index = zir.extra[@intFromEnum(Zir.ExtraIndex.imports)];
41 if (imports_index != 0) {33 if (imports_index != 0) {
42 try stream.writeAll("Imports:\n");34 try bw.writeAll("Imports:\n");
4335
44 const extra = zir.extraData(Zir.Inst.Imports, imports_index);36 const extra = zir.extraData(Zir.Inst.Imports, imports_index);
45 var extra_index = extra.end;37 var extra_index = extra.end;
...@@ -49,15 +41,13 @@ pub fn renderAsTextToFile(...@@ -49,15 +41,13 @@ pub fn renderAsTextToFile(
49 extra_index = item.end;41 extra_index = item.end;
5042
51 const import_path = zir.nullTerminatedString(item.data.name);43 const import_path = zir.nullTerminatedString(item.data.name);
52 try stream.print(" @import(\"{f}\") ", .{44 try bw.print(" @import(\"{f}\") ", .{
53 std.zig.fmtString(import_path),45 std.zig.fmtString(import_path),
54 });46 });
55 try writer.writeSrcTokAbs(stream, item.data.token);47 try writer.writeSrcTokAbs(bw, item.data.token);
56 try stream.writeAll("\n");48 try bw.writeAll("\n");
57 }49 }
58 }50 }
59
60 try raw_stream.flush();
61}51}
6252
63pub fn renderInstructionContext(53pub fn renderInstructionContext(
...@@ -67,7 +57,7 @@ pub fn renderInstructionContext(...@@ -67,7 +57,7 @@ pub fn renderInstructionContext(
67 scope_file: *Zcu.File,57 scope_file: *Zcu.File,
68 parent_decl_node: Ast.Node.Index,58 parent_decl_node: Ast.Node.Index,
69 indent: u32,59 indent: u32,
70 stream: anytype,60 bw: *std.io.Writer,
71) !void {61) !void {
72 var arena = std.heap.ArenaAllocator.init(gpa);62 var arena = std.heap.ArenaAllocator.init(gpa);
73 defer arena.deinit();63 defer arena.deinit();
...@@ -83,13 +73,13 @@ pub fn renderInstructionContext(...@@ -83,13 +73,13 @@ pub fn renderInstructionContext(
83 .recurse_blocks = true,73 .recurse_blocks = true,
84 };74 };
8575
86 try writer.writeBody(stream, block[0..block_index]);76 try writer.writeBody(bw, block[0..block_index]);
87 try stream.writeByteNTimes(' ', writer.indent - 2);77 try bw.splatByteAll(' ', writer.indent - 2);
88 try stream.print("> %{d} ", .{@intFromEnum(block[block_index])});78 try bw.print("> %{d} ", .{@intFromEnum(block[block_index])});
89 try writer.writeInstToStream(stream, block[block_index]);79 try writer.writeInstToStream(bw, block[block_index]);
90 try stream.writeByte('\n');80 try bw.writeByte('\n');
91 if (block_index + 1 < block.len) {81 if (block_index + 1 < block.len) {
92 try writer.writeBody(stream, block[block_index + 1 ..]);82 try writer.writeBody(bw, block[block_index + 1 ..]);
93 }83 }
94}84}
9585
...@@ -99,7 +89,7 @@ pub fn renderSingleInstruction(...@@ -99,7 +89,7 @@ pub fn renderSingleInstruction(
99 scope_file: *Zcu.File,89 scope_file: *Zcu.File,
100 parent_decl_node: Ast.Node.Index,90 parent_decl_node: Ast.Node.Index,
101 indent: u32,91 indent: u32,
102 stream: anytype,92 bw: *std.io.Writer,
103) !void {93) !void {
104 var arena = std.heap.ArenaAllocator.init(gpa);94 var arena = std.heap.ArenaAllocator.init(gpa);
105 defer arena.deinit();95 defer arena.deinit();
...@@ -115,8 +105,8 @@ pub fn renderSingleInstruction(...@@ -115,8 +105,8 @@ pub fn renderSingleInstruction(
115 .recurse_blocks = false,105 .recurse_blocks = false,
116 };106 };
117107
118 try stream.print("%{d} ", .{@intFromEnum(inst)});108 try bw.print("%{d} ", .{@intFromEnum(inst)});
119 try writer.writeInstToStream(stream, inst);109 try writer.writeInstToStream(bw, inst);
120}110}
121111
122const Writer = struct {112const Writer = struct {
...@@ -186,11 +176,13 @@ const Writer = struct {...@@ -186,11 +176,13 @@ const Writer = struct {
186 }176 }
187 } = .{},177 } = .{},
188178
179 const Error = std.io.Writer.Error || Allocator.Error;
180
189 fn writeInstToStream(181 fn writeInstToStream(
190 self: *Writer,182 self: *Writer,
191 stream: anytype,183 stream: *std.io.Writer,
192 inst: Zir.Inst.Index,184 inst: Zir.Inst.Index,
193 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {185 ) Error!void {
194 const tags = self.code.instructions.items(.tag);186 const tags = self.code.instructions.items(.tag);
195 const tag = tags[@intFromEnum(inst)];187 const tag = tags[@intFromEnum(inst)];
196 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});188 try stream.print("= {s}(", .{@tagName(tags[@intFromEnum(inst)])});
...@@ -516,7 +508,7 @@ const Writer = struct {...@@ -516,7 +508,7 @@ const Writer = struct {
516 }508 }
517 }509 }
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 {
520 const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;512 const extended = self.code.instructions.items(.data)[@intFromEnum(inst)].extended;
521 try stream.print("{s}(", .{@tagName(extended.opcode)});513 try stream.print("{s}(", .{@tagName(extended.opcode)});
522 switch (extended.opcode) {514 switch (extended.opcode) {
...@@ -623,13 +615,13 @@ const Writer = struct {...@@ -623,13 +615,13 @@ const Writer = struct {
623 }615 }
624 }616 }
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 {
627 try stream.writeAll(")) ");619 try stream.writeAll(")) ");
628 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));620 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
629 try self.writeSrcNode(stream, src_node);621 try self.writeSrcNode(stream, src_node);
630 }622 }
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 {
633 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;625 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].bin;
634 try self.writeInstRef(stream, inst_data.lhs);626 try self.writeInstRef(stream, inst_data.lhs);
635 try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});627 try stream.print(", {d})", .{@intFromEnum(inst_data.rhs)});
...@@ -637,9 +629,9 @@ const Writer = struct {...@@ -637,9 +629,9 @@ const Writer = struct {
637629
638 fn writeUnNode(630 fn writeUnNode(
639 self: *Writer,631 self: *Writer,
640 stream: anytype,632 stream: *std.io.Writer,
641 inst: Zir.Inst.Index,633 inst: Zir.Inst.Index,
642 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {634 ) Error!void {
643 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;635 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
644 try self.writeInstRef(stream, inst_data.operand);636 try self.writeInstRef(stream, inst_data.operand);
645 try stream.writeAll(") ");637 try stream.writeAll(") ");
...@@ -648,9 +640,9 @@ const Writer = struct {...@@ -648,9 +640,9 @@ const Writer = struct {
648640
649 fn writeUnTok(641 fn writeUnTok(
650 self: *Writer,642 self: *Writer,
651 stream: anytype,643 stream: *std.io.Writer,
652 inst: Zir.Inst.Index,644 inst: Zir.Inst.Index,
653 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {645 ) Error!void {
654 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;646 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
655 try self.writeInstRef(stream, inst_data.operand);647 try self.writeInstRef(stream, inst_data.operand);
656 try stream.writeAll(") ");648 try stream.writeAll(") ");
...@@ -659,9 +651,9 @@ const Writer = struct {...@@ -659,9 +651,9 @@ const Writer = struct {
659651
660 fn writeValidateDestructure(652 fn writeValidateDestructure(
661 self: *Writer,653 self: *Writer,
662 stream: anytype,654 stream: *std.io.Writer,
663 inst: Zir.Inst.Index,655 inst: Zir.Inst.Index,
664 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {656 ) Error!void {
665 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;657 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
666 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;658 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
667 try self.writeInstRef(stream, extra.operand);659 try self.writeInstRef(stream, extra.operand);
...@@ -673,9 +665,9 @@ const Writer = struct {...@@ -673,9 +665,9 @@ const Writer = struct {
673665
674 fn writeValidateArrayInitTy(666 fn writeValidateArrayInitTy(
675 self: *Writer,667 self: *Writer,
676 stream: anytype,668 stream: *std.io.Writer,
677 inst: Zir.Inst.Index,669 inst: Zir.Inst.Index,
678 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {670 ) Error!void {
679 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;671 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
680 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;672 const extra = self.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
681 try self.writeInstRef(stream, extra.ty);673 try self.writeInstRef(stream, extra.ty);
...@@ -685,9 +677,9 @@ const Writer = struct {...@@ -685,9 +677,9 @@ const Writer = struct {
685677
686 fn writeArrayTypeSentinel(678 fn writeArrayTypeSentinel(
687 self: *Writer,679 self: *Writer,
688 stream: anytype,680 stream: *std.io.Writer,
689 inst: Zir.Inst.Index,681 inst: Zir.Inst.Index,
690 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {682 ) Error!void {
691 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;683 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
692 const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;684 const extra = self.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
693 try self.writeInstRef(stream, extra.len);685 try self.writeInstRef(stream, extra.len);
...@@ -701,9 +693,9 @@ const Writer = struct {...@@ -701,9 +693,9 @@ const Writer = struct {
701693
702 fn writePtrType(694 fn writePtrType(
703 self: *Writer,695 self: *Writer,
704 stream: anytype,696 stream: *std.io.Writer,
705 inst: Zir.Inst.Index,697 inst: Zir.Inst.Index,
706 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {698 ) Error!void {
707 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;699 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
708 const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else "";700 const str_allowzero = if (inst_data.flags.is_allowzero) "allowzero, " else "";
709 const str_const = if (!inst_data.flags.is_mutable) "const, " else "";701 const str_const = if (!inst_data.flags.is_mutable) "const, " else "";
...@@ -744,12 +736,12 @@ const Writer = struct {...@@ -744,12 +736,12 @@ const Writer = struct {
744 try self.writeSrcNode(stream, extra.data.src_node);736 try self.writeSrcNode(stream, extra.data.src_node);
745 }737 }
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 {
748 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;740 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].int;
749 try stream.print("{d})", .{inst_data});741 try stream.print("{d})", .{inst_data});
750 }742 }
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 {
753 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;745 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
754 const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);746 const byte_count = inst_data.len * @sizeOf(std.math.big.Limb);
755 const limb_bytes = self.code.string_bytes[@intFromEnum(inst_data.start)..][0..byte_count];747 const limb_bytes = self.code.string_bytes[@intFromEnum(inst_data.start)..][0..byte_count];
...@@ -768,12 +760,12 @@ const Writer = struct {...@@ -768,12 +760,12 @@ const Writer = struct {
768 try stream.print("{s})", .{as_string});760 try stream.print("{s})", .{as_string});
769 }761 }
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 {
772 const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;764 const number = self.code.instructions.items(.data)[@intFromEnum(inst)].float;
773 try stream.print("{d})", .{number});765 try stream.print("{d})", .{number});
774 }766 }
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 {
777 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;769 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
778 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;770 const extra = self.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
779 const number = extra.get();771 const number = extra.get();
...@@ -784,15 +776,15 @@ const Writer = struct {...@@ -784,15 +776,15 @@ const Writer = struct {
784776
785 fn writeStr(777 fn writeStr(
786 self: *Writer,778 self: *Writer,
787 stream: anytype,779 stream: *std.io.Writer,
788 inst: Zir.Inst.Index,780 inst: Zir.Inst.Index,
789 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {781 ) Error!void {
790 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;782 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str;
791 const str = inst_data.get(self.code);783 const str = inst_data.get(self.code);
792 try stream.print("\"{f}\")", .{std.zig.fmtString(str)});784 try stream.print("\"{f}\")", .{std.zig.fmtString(str)});
793 }785 }
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 {
796 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;788 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
797 const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;789 const extra = self.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
798 try self.writeInstRef(stream, extra.lhs);790 try self.writeInstRef(stream, extra.lhs);
...@@ -802,7 +794,7 @@ const Writer = struct {...@@ -802,7 +794,7 @@ const Writer = struct {
802 try self.writeSrcNode(stream, inst_data.src_node);794 try self.writeSrcNode(stream, inst_data.src_node);
803 }795 }
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 {
806 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;798 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
807 const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;799 const extra = self.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data;
808 try self.writeInstRef(stream, extra.lhs);800 try self.writeInstRef(stream, extra.lhs);
...@@ -814,7 +806,7 @@ const Writer = struct {...@@ -814,7 +806,7 @@ const Writer = struct {
814 try self.writeSrcNode(stream, inst_data.src_node);806 try self.writeSrcNode(stream, inst_data.src_node);
815 }807 }
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 {
818 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;810 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
819 const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;811 const extra = self.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
820 try self.writeInstRef(stream, extra.lhs);812 try self.writeInstRef(stream, extra.lhs);
...@@ -828,7 +820,7 @@ const Writer = struct {...@@ -828,7 +820,7 @@ const Writer = struct {
828 try self.writeSrcNode(stream, inst_data.src_node);820 try self.writeSrcNode(stream, inst_data.src_node);
829 }821 }
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 {
832 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;824 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
833 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;825 const extra = self.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data;
834 try self.writeInstRef(stream, extra.lhs);826 try self.writeInstRef(stream, extra.lhs);
...@@ -844,7 +836,7 @@ const Writer = struct {...@@ -844,7 +836,7 @@ const Writer = struct {
844 try self.writeSrcNode(stream, inst_data.src_node);836 try self.writeSrcNode(stream, inst_data.src_node);
845 }837 }
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 {
848 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;840 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
849 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;841 const extra = self.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
850 try self.writeInstRef(stream, extra.union_type);842 try self.writeInstRef(stream, extra.union_type);
...@@ -856,7 +848,7 @@ const Writer = struct {...@@ -856,7 +848,7 @@ const Writer = struct {
856 try self.writeSrcNode(stream, inst_data.src_node);848 try self.writeSrcNode(stream, inst_data.src_node);
857 }849 }
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 {
860 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;852 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
861 const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;853 const extra = self.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
862 try self.writeInstRef(stream, extra.elem_type);854 try self.writeInstRef(stream, extra.elem_type);
...@@ -870,7 +862,7 @@ const Writer = struct {...@@ -870,7 +862,7 @@ const Writer = struct {
870 try self.writeSrcNode(stream, inst_data.src_node);862 try self.writeSrcNode(stream, inst_data.src_node);
871 }863 }
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 {
874 const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data;866 const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data;
875 try self.writeInstRef(stream, extra.elem_type);867 try self.writeInstRef(stream, extra.elem_type);
876 try stream.writeAll(", ");868 try stream.writeAll(", ");
...@@ -883,7 +875,7 @@ const Writer = struct {...@@ -883,7 +875,7 @@ const Writer = struct {
883 try self.writeSrcNode(stream, extra.node);875 try self.writeSrcNode(stream, extra.node);
884 }876 }
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 {
887 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;879 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
888 const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;880 const extra = self.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
889 try self.writeInstRef(stream, extra.mulend1);881 try self.writeInstRef(stream, extra.mulend1);
...@@ -895,7 +887,7 @@ const Writer = struct {...@@ -895,7 +887,7 @@ const Writer = struct {
895 try self.writeSrcNode(stream, inst_data.src_node);887 try self.writeSrcNode(stream, inst_data.src_node);
896 }888 }
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 {
899 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;891 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
900 const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;892 const extra = self.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
901893
...@@ -911,7 +903,7 @@ const Writer = struct {...@@ -911,7 +903,7 @@ const Writer = struct {
911 try self.writeSrcNode(stream, inst_data.src_node);903 try self.writeSrcNode(stream, inst_data.src_node);
912 }904 }
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 {
915 const extra = self.code.extraData(Zir.Inst.FieldParentPtr, extended.operand).data;907 const extra = self.code.extraData(Zir.Inst.FieldParentPtr, extended.operand).data;
916 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;908 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
917 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));909 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
...@@ -928,7 +920,7 @@ const Writer = struct {...@@ -928,7 +920,7 @@ const Writer = struct {
928 try self.writeSrcNode(stream, extra.src_node);920 try self.writeSrcNode(stream, extra.src_node);
929 }921 }
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 {
932 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;924 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
933 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);925 const extra = self.code.extraData(Zir.Inst.Param, inst_data.payload_index);
934 const body = self.code.bodySlice(extra.end, extra.data.type.body_len);926 const body = self.code.bodySlice(extra.end, extra.data.type.body_len);
...@@ -943,7 +935,7 @@ const Writer = struct {...@@ -943,7 +935,7 @@ const Writer = struct {
943 try self.writeSrcTok(stream, inst_data.src_tok);935 try self.writeSrcTok(stream, inst_data.src_tok);
944 }936 }
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 {
947 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;939 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
948 const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;940 const extra = self.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
949 try self.writeInstRef(stream, extra.lhs);941 try self.writeInstRef(stream, extra.lhs);
...@@ -953,7 +945,7 @@ const Writer = struct {...@@ -953,7 +945,7 @@ const Writer = struct {
953 try self.writeSrcNode(stream, inst_data.src_node);945 try self.writeSrcNode(stream, inst_data.src_node);
954 }946 }
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 {
957 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;949 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
958 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);950 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
959 const args = self.code.refSlice(extra.end, extra.data.operands_len);951 const args = self.code.refSlice(extra.end, extra.data.operands_len);
...@@ -966,7 +958,7 @@ const Writer = struct {...@@ -966,7 +958,7 @@ const Writer = struct {
966 try self.writeSrcNode(stream, inst_data.src_node);958 try self.writeSrcNode(stream, inst_data.src_node);
967 }959 }
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 {
970 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;962 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
971 const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;963 const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
972 try self.writeInstRef(stream, extra.res_ty);964 try self.writeInstRef(stream, extra.res_ty);
...@@ -978,13 +970,13 @@ const Writer = struct {...@@ -978,13 +970,13 @@ const Writer = struct {
978 try self.writeSrcNode(stream, inst_data.src_node);970 try self.writeSrcNode(stream, inst_data.src_node);
979 }971 }
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 {
982 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;974 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
983 try self.writeInstRef(stream, inst_data.operand);975 try self.writeInstRef(stream, inst_data.operand);
984 try stream.print(", {d})", .{inst_data.idx});976 try stream.print(", {d})", .{inst_data.idx});
985 }977 }
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 {
988 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;980 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
989 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;981 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
990982
...@@ -993,7 +985,7 @@ const Writer = struct {...@@ -993,7 +985,7 @@ const Writer = struct {
993 try self.writeSrcNode(stream, inst_data.src_node);985 try self.writeSrcNode(stream, inst_data.src_node);
994 }986 }
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 {
997 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;989 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
998 const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;990 const extra = self.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
999991
...@@ -1004,7 +996,7 @@ const Writer = struct {...@@ -1004,7 +996,7 @@ const Writer = struct {
1004 try self.writeSrcNode(stream, inst_data.src_node);996 try self.writeSrcNode(stream, inst_data.src_node);
1005 }997 }
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 {
1008 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1000 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1009 const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;1001 const extra = self.code.extraData(Zir.Inst.ArrayInitRefTy, inst_data.payload_index).data;
10101002
...@@ -1014,7 +1006,7 @@ const Writer = struct {...@@ -1014,7 +1006,7 @@ const Writer = struct {
1014 try self.writeSrcNode(stream, inst_data.src_node);1006 try self.writeSrcNode(stream, inst_data.src_node);
1015 }1007 }
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 {
1018 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1010 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1019 const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);1011 const extra = self.code.extraData(Zir.Inst.StructInit, inst_data.payload_index);
1020 var field_i: u32 = 0;1012 var field_i: u32 = 0;
...@@ -1038,7 +1030,7 @@ const Writer = struct {...@@ -1038,7 +1030,7 @@ const Writer = struct {
1038 try self.writeSrcNode(stream, inst_data.src_node);1030 try self.writeSrcNode(stream, inst_data.src_node);
1039 }1031 }
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 {
1042 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;1034 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
10431035
1044 try self.writeInstRef(stream, extra.ptr);1036 try self.writeInstRef(stream, extra.ptr);
...@@ -1054,7 +1046,7 @@ const Writer = struct {...@@ -1054,7 +1046,7 @@ const Writer = struct {
1054 try self.writeSrcNode(stream, extra.node);1046 try self.writeSrcNode(stream, extra.node);
1055 }1047 }
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 {
1058 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;1050 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
1059 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1051 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1060 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1052 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
...@@ -1070,7 +1062,7 @@ const Writer = struct {...@@ -1070,7 +1062,7 @@ const Writer = struct {
1070 try self.writeSrcNode(stream, extra.node);1062 try self.writeSrcNode(stream, extra.node);
1071 }1063 }
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 {
1074 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;1066 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).@"struct".backing_integer.?;
1075 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1067 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1076 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;1068 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
...@@ -1081,7 +1073,7 @@ const Writer = struct {...@@ -1081,7 +1073,7 @@ const Writer = struct {
1081 try self.writeSrcNode(stream, extra.node);1073 try self.writeSrcNode(stream, extra.node);
1082 }1074 }
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 {
1085 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1077 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1086 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;1078 const extra = self.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
10871079
...@@ -1094,7 +1086,7 @@ const Writer = struct {...@@ -1094,7 +1086,7 @@ const Writer = struct {
1094 try self.writeSrcNode(stream, inst_data.src_node);1086 try self.writeSrcNode(stream, inst_data.src_node);
1095 }1087 }
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 {
1098 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1090 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1099 const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;1091 const extra = self.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
11001092
...@@ -1107,7 +1099,7 @@ const Writer = struct {...@@ -1107,7 +1099,7 @@ const Writer = struct {
1107 try self.writeSrcNode(stream, inst_data.src_node);1099 try self.writeSrcNode(stream, inst_data.src_node);
1108 }1100 }
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 {
1111 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1103 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1112 const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;1104 const extra = self.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
11131105
...@@ -1122,7 +1114,7 @@ const Writer = struct {...@@ -1122,7 +1114,7 @@ const Writer = struct {
1122 try self.writeSrcNode(stream, inst_data.src_node);1114 try self.writeSrcNode(stream, inst_data.src_node);
1123 }1115 }
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 {
1126 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1118 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1127 const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);1119 const extra = self.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index);
1128 var field_i: u32 = 0;1120 var field_i: u32 = 0;
...@@ -1143,7 +1135,7 @@ const Writer = struct {...@@ -1143,7 +1135,7 @@ const Writer = struct {
1143 try self.writeSrcNode(stream, inst_data.src_node);1135 try self.writeSrcNode(stream, inst_data.src_node);
1144 }1136 }
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 {
1147 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1139 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1148 const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;1140 const extra = self.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
1149 try self.writeInstRef(stream, extra.container_type);1141 try self.writeInstRef(stream, extra.container_type);
...@@ -1152,7 +1144,7 @@ const Writer = struct {...@@ -1152,7 +1144,7 @@ const Writer = struct {
1152 try self.writeSrcNode(stream, inst_data.src_node);1144 try self.writeSrcNode(stream, inst_data.src_node);
1153 }1145 }
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 {
1156 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1148 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1157 const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;1149 const extra = self.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
1158 try self.writeInstRef(stream, extra.container_type);1150 try self.writeInstRef(stream, extra.container_type);
...@@ -1162,7 +1154,7 @@ const Writer = struct {...@@ -1162,7 +1154,7 @@ const Writer = struct {
1162 try self.writeSrcNode(stream, inst_data.src_node);1154 try self.writeSrcNode(stream, inst_data.src_node);
1163 }1155 }
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 {
1166 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);1158 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
1167 const operands = self.code.refSlice(extra.end, extended.small);1159 const operands = self.code.refSlice(extra.end, extended.small);
11681160
...@@ -1176,9 +1168,9 @@ const Writer = struct {...@@ -1176,9 +1168,9 @@ const Writer = struct {
11761168
1177 fn writeInstNode(1169 fn writeInstNode(
1178 self: *Writer,1170 self: *Writer,
1179 stream: anytype,1171 stream: *std.io.Writer,
1180 inst: Zir.Inst.Index,1172 inst: Zir.Inst.Index,
1181 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {1173 ) Error!void {
1182 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;1174 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].inst_node;
1183 try self.writeInstIndex(stream, inst_data.inst);1175 try self.writeInstIndex(stream, inst_data.inst);
1184 try stream.writeAll(") ");1176 try stream.writeAll(") ");
...@@ -1187,7 +1179,7 @@ const Writer = struct {...@@ -1187,7 +1179,7 @@ const Writer = struct {
11871179
1188 fn writeAsm(1180 fn writeAsm(
1189 self: *Writer,1181 self: *Writer,
1190 stream: anytype,1182 stream: *std.io.Writer,
1191 extended: Zir.Inst.Extended.InstData,1183 extended: Zir.Inst.Extended.InstData,
1192 tmpl_is_expr: bool,1184 tmpl_is_expr: bool,
1193 ) !void {1185 ) !void {
...@@ -1220,8 +1212,8 @@ const Writer = struct {...@@ -1220,8 +1212,8 @@ const Writer = struct {
12201212
1221 const name = self.code.nullTerminatedString(output.data.name);1213 const name = self.code.nullTerminatedString(output.data.name);
1222 const constraint = self.code.nullTerminatedString(output.data.constraint);1214 const constraint = self.code.nullTerminatedString(output.data.constraint);
1223 try stream.print("output({f}, \"{f}\", ", .{1215 try stream.print("output({fp}, \"{f}\", ", .{
1224 std.zig.fmtIdFlags(name, .{ .allow_primitive = true }), std.zig.fmtString(constraint),1216 std.zig.fmtId(name), std.zig.fmtString(constraint),
1225 });1217 });
1226 try self.writeFlag(stream, "->", is_type);1218 try self.writeFlag(stream, "->", is_type);
1227 try self.writeInstRef(stream, output.data.operand);1219 try self.writeInstRef(stream, output.data.operand);
...@@ -1239,8 +1231,8 @@ const Writer = struct {...@@ -1239,8 +1231,8 @@ const Writer = struct {
12391231
1240 const name = self.code.nullTerminatedString(input.data.name);1232 const name = self.code.nullTerminatedString(input.data.name);
1241 const constraint = self.code.nullTerminatedString(input.data.constraint);1233 const constraint = self.code.nullTerminatedString(input.data.constraint);
1242 try stream.print("input({f}, \"{f}\", ", .{1234 try stream.print("input({fp}, \"{f}\", ", .{
1243 std.zig.fmtIdFlags(name, .{ .allow_primitive = true }), std.zig.fmtString(constraint),1235 std.zig.fmtId(name), std.zig.fmtString(constraint),
1244 });1236 });
1245 try self.writeInstRef(stream, input.data.operand);1237 try self.writeInstRef(stream, input.data.operand);
1246 try stream.writeAll(")");1238 try stream.writeAll(")");
...@@ -1255,7 +1247,7 @@ const Writer = struct {...@@ -1255,7 +1247,7 @@ const Writer = struct {
1255 const str_index = self.code.extra[extra_i];1247 const str_index = self.code.extra[extra_i];
1256 extra_i += 1;1248 extra_i += 1;
1257 const clobber = self.code.nullTerminatedString(@enumFromInt(str_index));1249 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)});
1259 if (i + 1 < clobbers_len) {1251 if (i + 1 < clobbers_len) {
1260 try stream.writeAll(", ");1252 try stream.writeAll(", ");
1261 }1253 }
...@@ -1265,7 +1257,7 @@ const Writer = struct {...@@ -1265,7 +1257,7 @@ const Writer = struct {
1265 try self.writeSrcNode(stream, extra.data.src_node);1257 try self.writeSrcNode(stream, extra.data.src_node);
1266 }1258 }
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 {
1269 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1261 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
12701262
1271 try self.writeInstRef(stream, extra.lhs);1263 try self.writeInstRef(stream, extra.lhs);
...@@ -1277,7 +1269,7 @@ const Writer = struct {...@@ -1277,7 +1269,7 @@ const Writer = struct {
12771269
1278 fn writeCall(1270 fn writeCall(
1279 self: *Writer,1271 self: *Writer,
1280 stream: anytype,1272 stream: *std.io.Writer,
1281 inst: Zir.Inst.Index,1273 inst: Zir.Inst.Index,
1282 comptime kind: enum { direct, field },1274 comptime kind: enum { direct, field },
1283 ) !void {1275 ) !void {
...@@ -1311,7 +1303,7 @@ const Writer = struct {...@@ -1311,7 +1303,7 @@ const Writer = struct {
1311 var i: usize = 0;1303 var i: usize = 0;
1312 var arg_start: u32 = args_len;1304 var arg_start: u32 = args_len;
1313 while (i < args_len) : (i += 1) {1305 while (i < args_len) : (i += 1) {
1314 try stream.writeByteNTimes(' ', self.indent);1306 try stream.splatByteAll(' ', self.indent);
1315 const arg_end = self.code.extra[extra.end + i];1307 const arg_end = self.code.extra[extra.end + i];
1316 defer arg_start = arg_end;1308 defer arg_start = arg_end;
1317 const arg_body = body[arg_start..arg_end];1309 const arg_body = body[arg_start..arg_end];
...@@ -1321,14 +1313,14 @@ const Writer = struct {...@@ -1321,14 +1313,14 @@ const Writer = struct {
1321 }1313 }
1322 self.indent -= 2;1314 self.indent -= 2;
1323 if (args_len != 0) {1315 if (args_len != 0) {
1324 try stream.writeByteNTimes(' ', self.indent);1316 try stream.splatByteAll(' ', self.indent);
1325 }1317 }
13261318
1327 try stream.writeAll("]) ");1319 try stream.writeAll("]) ");
1328 try self.writeSrcNode(stream, inst_data.src_node);1320 try self.writeSrcNode(stream, inst_data.src_node);
1329 }1321 }
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 {
1332 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1324 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1333 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);1325 const extra = self.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1334 const body = self.code.bodySlice(extra.end, extra.data.body_len);1326 const body = self.code.bodySlice(extra.end, extra.data.body_len);
...@@ -1337,7 +1329,7 @@ const Writer = struct {...@@ -1337,7 +1329,7 @@ const Writer = struct {
1337 try self.writeSrcNode(stream, inst_data.src_node);1329 try self.writeSrcNode(stream, inst_data.src_node);
1338 }1330 }
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 {
1341 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1333 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1342 const extra = self.code.extraData(Zir.Inst.BlockComptime, inst_data.payload_index);1334 const extra = self.code.extraData(Zir.Inst.BlockComptime, inst_data.payload_index);
1343 const body = self.code.bodySlice(extra.end, extra.data.body_len);1335 const body = self.code.bodySlice(extra.end, extra.data.body_len);
...@@ -1347,7 +1339,7 @@ const Writer = struct {...@@ -1347,7 +1339,7 @@ const Writer = struct {
1347 try self.writeSrcNode(stream, inst_data.src_node);1339 try self.writeSrcNode(stream, inst_data.src_node);
1348 }1340 }
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 {
1351 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1343 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1352 const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);1344 const extra = self.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1353 const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);1345 const then_body = self.code.bodySlice(extra.end, extra.data.then_body_len);
...@@ -1361,7 +1353,7 @@ const Writer = struct {...@@ -1361,7 +1353,7 @@ const Writer = struct {
1361 try self.writeSrcNode(stream, inst_data.src_node);1353 try self.writeSrcNode(stream, inst_data.src_node);
1362 }1354 }
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 {
1365 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1357 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1366 const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);1358 const extra = self.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1367 const body = self.code.bodySlice(extra.end, extra.data.body_len);1359 const body = self.code.bodySlice(extra.end, extra.data.body_len);
...@@ -1372,7 +1364,7 @@ const Writer = struct {...@@ -1372,7 +1364,7 @@ const Writer = struct {
1372 try self.writeSrcNode(stream, inst_data.src_node);1364 try self.writeSrcNode(stream, inst_data.src_node);
1373 }1365 }
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 {
1376 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);1368 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
13771369
1378 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);1370 const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand);
...@@ -1446,7 +1438,7 @@ const Writer = struct {...@@ -1446,7 +1438,7 @@ const Writer = struct {
1446 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1438 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
1447 self.indent -= 2;1439 self.indent -= 2;
1448 extra_index += decls_len;1440 extra_index += decls_len;
1449 try stream.writeByteNTimes(' ', self.indent);1441 try stream.splatByteAll(' ', self.indent);
1450 try stream.writeAll("}, ");1442 try stream.writeAll("}, ");
1451 }1443 }
14521444
...@@ -1515,11 +1507,11 @@ const Writer = struct {...@@ -1515,11 +1507,11 @@ const Writer = struct {
1515 self.indent += 2;1507 self.indent += 2;
15161508
1517 for (fields, 0..) |field, i| {1509 for (fields, 0..) |field, i| {
1518 try stream.writeByteNTimes(' ', self.indent);1510 try stream.splatByteAll(' ', self.indent);
1519 try self.writeFlag(stream, "comptime ", field.is_comptime);1511 try self.writeFlag(stream, "comptime ", field.is_comptime);
1520 if (field.name != .empty) {1512 if (field.name != .empty) {
1521 const field_name = self.code.nullTerminatedString(field.name);1513 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)});
1523 } else {1515 } else {
1524 try stream.print("@\"{d}\": ", .{i});1516 try stream.print("@\"{d}\": ", .{i});
1525 }1517 }
...@@ -1558,13 +1550,13 @@ const Writer = struct {...@@ -1558,13 +1550,13 @@ const Writer = struct {
1558 }1550 }
15591551
1560 self.indent -= 2;1552 self.indent -= 2;
1561 try stream.writeByteNTimes(' ', self.indent);1553 try stream.splatByteAll(' ', self.indent);
1562 try stream.writeAll("}) ");1554 try stream.writeAll("}) ");
1563 }1555 }
1564 try self.writeSrcNode(stream, .zero);1556 try self.writeSrcNode(stream, .zero);
1565 }1557 }
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 {
1568 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));1560 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
15691561
1570 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);1562 const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand);
...@@ -1630,7 +1622,7 @@ const Writer = struct {...@@ -1630,7 +1622,7 @@ const Writer = struct {
1630 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1622 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
1631 self.indent -= 2;1623 self.indent -= 2;
1632 extra_index += decls_len;1624 extra_index += decls_len;
1633 try stream.writeByteNTimes(' ', self.indent);1625 try stream.splatByteAll(' ', self.indent);
1634 try stream.writeAll("}");1626 try stream.writeAll("}");
1635 }1627 }
16361628
...@@ -1681,8 +1673,8 @@ const Writer = struct {...@@ -1681,8 +1673,8 @@ const Writer = struct {
1681 const field_name = self.code.nullTerminatedString(field_name_index);1673 const field_name = self.code.nullTerminatedString(field_name_index);
1682 extra_index += 1;1674 extra_index += 1;
16831675
1684 try stream.writeByteNTimes(' ', self.indent);1676 try stream.splatByteAll(' ', self.indent);
1685 try stream.print("{f}", .{std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true })});1677 try stream.print("{fp}", .{std.zig.fmtId(field_name)});
16861678
1687 if (has_type) {1679 if (has_type) {
1688 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));1680 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
...@@ -1710,12 +1702,12 @@ const Writer = struct {...@@ -1710,12 +1702,12 @@ const Writer = struct {
1710 }1702 }
17111703
1712 self.indent -= 2;1704 self.indent -= 2;
1713 try stream.writeByteNTimes(' ', self.indent);1705 try stream.splatByteAll(' ', self.indent);
1714 try stream.writeAll("}) ");1706 try stream.writeAll("}) ");
1715 try self.writeSrcNode(stream, .zero);1707 try self.writeSrcNode(stream, .zero);
1716 }1708 }
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 {
1719 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));1711 const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small));
17201712
1721 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);1713 const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand);
...@@ -1779,7 +1771,7 @@ const Writer = struct {...@@ -1779,7 +1771,7 @@ const Writer = struct {
1779 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1771 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
1780 self.indent -= 2;1772 self.indent -= 2;
1781 extra_index += decls_len;1773 extra_index += decls_len;
1782 try stream.writeByteNTimes(' ', self.indent);1774 try stream.splatByteAll(' ', self.indent);
1783 try stream.writeAll("}, ");1775 try stream.writeAll("}, ");
1784 }1776 }
17851777
...@@ -1815,8 +1807,8 @@ const Writer = struct {...@@ -1815,8 +1807,8 @@ const Writer = struct {
1815 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));1807 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));
1816 extra_index += 1;1808 extra_index += 1;
18171809
1818 try stream.writeByteNTimes(' ', self.indent);1810 try stream.splatByteAll(' ', self.indent);
1819 try stream.print("{f}", .{std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true })});1811 try stream.print("{fp}", .{std.zig.fmtId(field_name)});
18201812
1821 if (has_tag_value) {1813 if (has_tag_value) {
1822 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));1814 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
...@@ -1828,7 +1820,7 @@ const Writer = struct {...@@ -1828,7 +1820,7 @@ const Writer = struct {
1828 try stream.writeAll(",\n");1820 try stream.writeAll(",\n");
1829 }1821 }
1830 self.indent -= 2;1822 self.indent -= 2;
1831 try stream.writeByteNTimes(' ', self.indent);1823 try stream.splatByteAll(' ', self.indent);
1832 try stream.writeAll("}) ");1824 try stream.writeAll("}) ");
1833 }1825 }
1834 try self.writeSrcNode(stream, .zero);1826 try self.writeSrcNode(stream, .zero);
...@@ -1836,7 +1828,7 @@ const Writer = struct {...@@ -1836,7 +1828,7 @@ const Writer = struct {
18361828
1837 fn writeOpaqueDecl(1829 fn writeOpaqueDecl(
1838 self: *Writer,1830 self: *Writer,
1839 stream: anytype,1831 stream: *std.io.Writer,
1840 extended: Zir.Inst.Extended.InstData,1832 extended: Zir.Inst.Extended.InstData,
1841 ) !void {1833 ) !void {
1842 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));1834 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
...@@ -1872,13 +1864,13 @@ const Writer = struct {...@@ -1872,13 +1864,13 @@ const Writer = struct {
1872 self.indent += 2;1864 self.indent += 2;
1873 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));1865 try self.writeBody(stream, self.code.bodySlice(extra_index, decls_len));
1874 self.indent -= 2;1866 self.indent -= 2;
1875 try stream.writeByteNTimes(' ', self.indent);1867 try stream.splatByteAll(' ', self.indent);
1876 try stream.writeAll("}) ");1868 try stream.writeAll("}) ");
1877 }1869 }
1878 try self.writeSrcNode(stream, .zero);1870 try self.writeSrcNode(stream, .zero);
1879 }1871 }
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 {
1882 const fields_len = extended.small;1874 const fields_len = extended.small;
1883 assert(fields_len != 0);1875 assert(fields_len != 0);
1884 const extra = self.code.extraData(Zir.Inst.TupleDecl, extended.operand);1876 const extra = self.code.extraData(Zir.Inst.TupleDecl, extended.operand);
...@@ -1906,7 +1898,7 @@ const Writer = struct {...@@ -1906,7 +1898,7 @@ const Writer = struct {
19061898
1907 fn writeErrorSetDecl(1899 fn writeErrorSetDecl(
1908 self: *Writer,1900 self: *Writer,
1909 stream: anytype,1901 stream: *std.io.Writer,
1910 inst: Zir.Inst.Index,1902 inst: Zir.Inst.Index,
1911 ) !void {1903 ) !void {
1912 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1904 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
...@@ -1920,18 +1912,18 @@ const Writer = struct {...@@ -1920,18 +1912,18 @@ const Writer = struct {
1920 while (extra_index < extra_index_end) : (extra_index += 1) {1912 while (extra_index < extra_index_end) : (extra_index += 1) {
1921 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);1913 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1922 const name = self.code.nullTerminatedString(name_index);1914 const name = self.code.nullTerminatedString(name_index);
1923 try stream.writeByteNTimes(' ', self.indent);1915 try stream.splatByteAll(' ', self.indent);
1924 try stream.print("{f},\n", .{std.zig.fmtIdFlags(name, .{ .allow_primitive = true })});1916 try stream.print("{fp},\n", .{std.zig.fmtId(name)});
1925 }1917 }
19261918
1927 self.indent -= 2;1919 self.indent -= 2;
1928 try stream.writeByteNTimes(' ', self.indent);1920 try stream.splatByteAll(' ', self.indent);
1929 try stream.writeAll("}) ");1921 try stream.writeAll("}) ");
19301922
1931 try self.writeSrcNode(stream, inst_data.src_node);1923 try self.writeSrcNode(stream, inst_data.src_node);
1932 }1924 }
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 {
1935 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1927 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1936 const extra = self.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);1928 const extra = self.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
19371929
...@@ -1967,7 +1959,7 @@ const Writer = struct {...@@ -1967,7 +1959,7 @@ const Writer = struct {
1967 extra_index += body.len;1959 extra_index += body.len;
19681960
1969 try stream.writeAll(",\n");1961 try stream.writeAll(",\n");
1970 try stream.writeByteNTimes(' ', self.indent);1962 try stream.splatByteAll(' ', self.indent);
1971 try stream.writeAll("non_err => ");1963 try stream.writeAll("non_err => ");
1972 try self.writeBracedBody(stream, body);1964 try self.writeBracedBody(stream, body);
1973 }1965 }
...@@ -1985,7 +1977,7 @@ const Writer = struct {...@@ -1985,7 +1977,7 @@ const Writer = struct {
1985 extra_index += body.len;1977 extra_index += body.len;
19861978
1987 try stream.writeAll(",\n");1979 try stream.writeAll(",\n");
1988 try stream.writeByteNTimes(' ', self.indent);1980 try stream.splatByteAll(' ', self.indent);
1989 try stream.print("{s}{s}else => ", .{ capture_text, inline_text });1981 try stream.print("{s}{s}else => ", .{ capture_text, inline_text });
1990 try self.writeBracedBody(stream, body);1982 try self.writeBracedBody(stream, body);
1991 }1983 }
...@@ -2002,7 +1994,7 @@ const Writer = struct {...@@ -2002,7 +1994,7 @@ const Writer = struct {
2002 extra_index += info.body_len;1994 extra_index += info.body_len;
20031995
2004 try stream.writeAll(",\n");1996 try stream.writeAll(",\n");
2005 try stream.writeByteNTimes(' ', self.indent);1997 try stream.splatByteAll(' ', self.indent);
2006 switch (info.capture) {1998 switch (info.capture) {
2007 .none => {},1999 .none => {},
2008 .by_val => try stream.writeAll("by_val "),2000 .by_val => try stream.writeAll("by_val "),
...@@ -2027,7 +2019,7 @@ const Writer = struct {...@@ -2027,7 +2019,7 @@ const Writer = struct {
2027 extra_index += items_len;2019 extra_index += items_len;
20282020
2029 try stream.writeAll(",\n");2021 try stream.writeAll(",\n");
2030 try stream.writeByteNTimes(' ', self.indent);2022 try stream.splatByteAll(' ', self.indent);
2031 switch (info.capture) {2023 switch (info.capture) {
2032 .none => {},2024 .none => {},
2033 .by_val => try stream.writeAll("by_val "),2025 .by_val => try stream.writeAll("by_val "),
...@@ -2068,7 +2060,7 @@ const Writer = struct {...@@ -2068,7 +2060,7 @@ const Writer = struct {
2068 try self.writeSrcNode(stream, inst_data.src_node);2060 try self.writeSrcNode(stream, inst_data.src_node);
2069 }2061 }
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 {
2072 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2064 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2073 const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);2065 const extra = self.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
20742066
...@@ -2115,7 +2107,7 @@ const Writer = struct {...@@ -2115,7 +2107,7 @@ const Writer = struct {
2115 extra_index += body.len;2107 extra_index += body.len;
21162108
2117 try stream.writeAll(",\n");2109 try stream.writeAll(",\n");
2118 try stream.writeByteNTimes(' ', self.indent);2110 try stream.splatByteAll(' ', self.indent);
2119 try stream.print("{s}{s}{s} => ", .{ capture_text, inline_text, prong_name });2111 try stream.print("{s}{s}{s} => ", .{ capture_text, inline_text, prong_name });
2120 try self.writeBracedBody(stream, body);2112 try self.writeBracedBody(stream, body);
2121 }2113 }
...@@ -2132,7 +2124,7 @@ const Writer = struct {...@@ -2132,7 +2124,7 @@ const Writer = struct {
2132 extra_index += info.body_len;2124 extra_index += info.body_len;
21332125
2134 try stream.writeAll(",\n");2126 try stream.writeAll(",\n");
2135 try stream.writeByteNTimes(' ', self.indent);2127 try stream.splatByteAll(' ', self.indent);
2136 switch (info.capture) {2128 switch (info.capture) {
2137 .none => {},2129 .none => {},
2138 .by_val => try stream.writeAll("by_val "),2130 .by_val => try stream.writeAll("by_val "),
...@@ -2157,7 +2149,7 @@ const Writer = struct {...@@ -2157,7 +2149,7 @@ const Writer = struct {
2157 extra_index += items_len;2149 extra_index += items_len;
21582150
2159 try stream.writeAll(",\n");2151 try stream.writeAll(",\n");
2160 try stream.writeByteNTimes(' ', self.indent);2152 try stream.splatByteAll(' ', self.indent);
2161 switch (info.capture) {2153 switch (info.capture) {
2162 .none => {},2154 .none => {},
2163 .by_val => try stream.writeAll("by_val "),2155 .by_val => try stream.writeAll("by_val "),
...@@ -2198,7 +2190,7 @@ const Writer = struct {...@@ -2198,7 +2190,7 @@ const Writer = struct {
2198 try self.writeSrcNode(stream, inst_data.src_node);2190 try self.writeSrcNode(stream, inst_data.src_node);
2199 }2191 }
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 {
2202 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2194 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2203 const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;2195 const extra = self.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
2204 const name = self.code.nullTerminatedString(extra.field_name_start);2196 const name = self.code.nullTerminatedString(extra.field_name_start);
...@@ -2207,7 +2199,7 @@ const Writer = struct {...@@ -2207,7 +2199,7 @@ const Writer = struct {
2207 try self.writeSrcNode(stream, inst_data.src_node);2199 try self.writeSrcNode(stream, inst_data.src_node);
2208 }2200 }
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 {
2211 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2203 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2212 const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;2204 const extra = self.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
2213 try self.writeInstRef(stream, extra.lhs);2205 try self.writeInstRef(stream, extra.lhs);
...@@ -2217,7 +2209,7 @@ const Writer = struct {...@@ -2217,7 +2209,7 @@ const Writer = struct {
2217 try self.writeSrcNode(stream, inst_data.src_node);2209 try self.writeSrcNode(stream, inst_data.src_node);
2218 }2210 }
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 {
2221 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2213 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2222 const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;2214 const extra = self.code.extraData(Zir.Inst.As, inst_data.payload_index).data;
2223 try self.writeInstRef(stream, extra.dest_type);2215 try self.writeInstRef(stream, extra.dest_type);
...@@ -2229,9 +2221,9 @@ const Writer = struct {...@@ -2229,9 +2221,9 @@ const Writer = struct {
22292221
2230 fn writeNode(2222 fn writeNode(
2231 self: *Writer,2223 self: *Writer,
2232 stream: anytype,2224 stream: *std.io.Writer,
2233 inst: Zir.Inst.Index,2225 inst: Zir.Inst.Index,
2234 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {2226 ) Error!void {
2235 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;2227 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
2236 try stream.writeAll(") ");2228 try stream.writeAll(") ");
2237 try self.writeSrcNode(stream, src_node);2229 try self.writeSrcNode(stream, src_node);
...@@ -2239,16 +2231,16 @@ const Writer = struct {...@@ -2239,16 +2231,16 @@ const Writer = struct {
22392231
2240 fn writeStrTok(2232 fn writeStrTok(
2241 self: *Writer,2233 self: *Writer,
2242 stream: anytype,2234 stream: *std.io.Writer,
2243 inst: Zir.Inst.Index,2235 inst: Zir.Inst.Index,
2244 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {2236 ) Error!void {
2245 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;2237 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
2246 const str = inst_data.get(self.code);2238 const str = inst_data.get(self.code);
2247 try stream.print("\"{f}\") ", .{std.zig.fmtString(str)});2239 try stream.print("\"{f}\") ", .{std.zig.fmtString(str)});
2248 try self.writeSrcTok(stream, inst_data.src_tok);2240 try self.writeSrcTok(stream, inst_data.src_tok);
2249 }2241 }
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 {
2252 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;2244 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].str_op;
2253 const str = inst_data.getStr(self.code);2245 const str = inst_data.getStr(self.code);
2254 try self.writeInstRef(stream, inst_data.operand);2246 try self.writeInstRef(stream, inst_data.operand);
...@@ -2257,7 +2249,7 @@ const Writer = struct {...@@ -2257,7 +2249,7 @@ const Writer = struct {
22572249
2258 fn writeFunc(2250 fn writeFunc(
2259 self: *Writer,2251 self: *Writer,
2260 stream: anytype,2252 stream: *std.io.Writer,
2261 inst: Zir.Inst.Index,2253 inst: Zir.Inst.Index,
2262 inferred_error_set: bool,2254 inferred_error_set: bool,
2263 ) !void {2255 ) !void {
...@@ -2308,7 +2300,7 @@ const Writer = struct {...@@ -2308,7 +2300,7 @@ const Writer = struct {
2308 );2300 );
2309 }2301 }
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 {
2312 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2304 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2313 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);2305 const extra = self.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
23142306
...@@ -2367,7 +2359,7 @@ const Writer = struct {...@@ -2367,7 +2359,7 @@ const Writer = struct {
2367 );2359 );
2368 }2360 }
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 {
2371 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);2363 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2372 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));2364 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
23732365
...@@ -2390,7 +2382,7 @@ const Writer = struct {...@@ -2390,7 +2382,7 @@ const Writer = struct {
2390 try self.writeSrcNode(stream, extra.data.src_node);2382 try self.writeSrcNode(stream, extra.data.src_node);
2391 }2383 }
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 {
2394 const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);2386 const extra = self.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
2395 const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);2387 const body = self.code.bodySlice(extra.data.body_index, extra.data.body_len);
2396 try self.writeBracedBody(stream, body);2388 try self.writeBracedBody(stream, body);
...@@ -2403,7 +2395,7 @@ const Writer = struct {...@@ -2403,7 +2395,7 @@ const Writer = struct {
2403 try stream.writeAll("])");2395 try stream.writeAll("])");
2404 }2396 }
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 {
2407 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2399 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2408 const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);2400 const extra = self.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index);
2409 const body = self.code.bodySlice(extra.end, extra.data.body_len);2401 const body = self.code.bodySlice(extra.end, extra.data.body_len);
...@@ -2414,7 +2406,7 @@ const Writer = struct {...@@ -2414,7 +2406,7 @@ const Writer = struct {
2414 try self.writeSrcNode(stream, inst_data.src_node);2406 try self.writeSrcNode(stream, inst_data.src_node);
2415 }2407 }
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 {
2418 const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;2410 const int_type = self.code.instructions.items(.data)[@intFromEnum(inst)].int_type;
2419 const prefix: u8 = switch (int_type.signedness) {2411 const prefix: u8 = switch (int_type.signedness) {
2420 .signed => 'i',2412 .signed => 'i',
...@@ -2424,7 +2416,7 @@ const Writer = struct {...@@ -2424,7 +2416,7 @@ const Writer = struct {
2424 try self.writeSrcNode(stream, int_type.src_node);2416 try self.writeSrcNode(stream, int_type.src_node);
2425 }2417 }
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 {
2428 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;2420 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24292421
2430 try self.writeInstRef(stream, inst_data.operand);2422 try self.writeInstRef(stream, inst_data.operand);
...@@ -2432,7 +2424,7 @@ const Writer = struct {...@@ -2432,7 +2424,7 @@ const Writer = struct {
2432 try stream.writeAll(")");2424 try stream.writeAll(")");
2433 }2425 }
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 {
2436 const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;2428 const extra = self.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data;
24372429
2438 try self.writeInstRef(stream, extra.block);2430 try self.writeInstRef(stream, extra.block);
...@@ -2442,7 +2434,7 @@ const Writer = struct {...@@ -2442,7 +2434,7 @@ const Writer = struct {
2442 try self.writeSrcNode(stream, extra.src_node);2434 try self.writeSrcNode(stream, extra.src_node);
2443 }2435 }
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 {
2446 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";2438 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"break";
2447 const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;2439 const extra = self.code.extraData(Zir.Inst.Break, inst_data.payload_index).data;
24482440
...@@ -2452,7 +2444,7 @@ const Writer = struct {...@@ -2452,7 +2444,7 @@ const Writer = struct {
2452 try stream.writeAll(")");2444 try stream.writeAll(")");
2453 }2445 }
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 {
2456 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2448 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24572449
2458 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);2450 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
...@@ -2468,7 +2460,7 @@ const Writer = struct {...@@ -2468,7 +2460,7 @@ const Writer = struct {
2468 try self.writeSrcNode(stream, inst_data.src_node);2460 try self.writeSrcNode(stream, inst_data.src_node);
2469 }2461 }
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 {
2472 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2464 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24732465
2474 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);2466 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
...@@ -2483,7 +2475,7 @@ const Writer = struct {...@@ -2483,7 +2475,7 @@ const Writer = struct {
2483 try self.writeSrcNode(stream, inst_data.src_node);2475 try self.writeSrcNode(stream, inst_data.src_node);
2484 }2476 }
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 {
2487 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;2479 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24882480
2489 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);2481 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
...@@ -2503,7 +2495,7 @@ const Writer = struct {...@@ -2503,7 +2495,7 @@ const Writer = struct {
2503 try self.writeSrcNode(stream, inst_data.src_node);2495 try self.writeSrcNode(stream, inst_data.src_node);
2504 }2496 }
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 {
2507 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";2499 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable";
2508 try stream.writeAll(") ");2500 try stream.writeAll(") ");
2509 try self.writeSrcNode(stream, inst_data.src_node);2501 try self.writeSrcNode(stream, inst_data.src_node);
...@@ -2511,7 +2503,7 @@ const Writer = struct {...@@ -2511,7 +2503,7 @@ const Writer = struct {
25112503
2512 fn writeFuncCommon(2504 fn writeFuncCommon(
2513 self: *Writer,2505 self: *Writer,
2514 stream: anytype,2506 stream: *std.io.Writer,
2515 inferred_error_set: bool,2507 inferred_error_set: bool,
2516 var_args: bool,2508 var_args: bool,
2517 is_noinline: bool,2509 is_noinline: bool,
...@@ -2548,19 +2540,19 @@ const Writer = struct {...@@ -2548,19 +2540,19 @@ const Writer = struct {
2548 try self.writeSrcNode(stream, src_node);2540 try self.writeSrcNode(stream, src_node);
2549 }2541 }
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 {
2552 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;2544 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
2553 try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });2545 try stream.print("{d}, {d})", .{ inst_data.line + 1, inst_data.column + 1 });
2554 }2546 }
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 {
2557 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";2549 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].@"defer";
2558 const body = self.code.bodySlice(inst_data.index, inst_data.len);2550 const body = self.code.bodySlice(inst_data.index, inst_data.len);
2559 try self.writeBracedBody(stream, body);2551 try self.writeBracedBody(stream, body);
2560 try stream.writeByte(')');2552 try stream.writeByte(')');
2561 }2553 }
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 {
2564 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;2556 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code;
2565 const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;2557 const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data;
25662558
...@@ -2573,7 +2565,7 @@ const Writer = struct {...@@ -2573,7 +2565,7 @@ const Writer = struct {
2573 try stream.writeByte(')');2565 try stream.writeByte(')');
2574 }2566 }
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 {
2577 const decl = self.code.getDeclaration(inst);2569 const decl = self.code.getDeclaration(inst);
25782570
2579 const prev_parent_decl_node = self.parent_decl_node;2571 const prev_parent_decl_node = self.parent_decl_node;
...@@ -2594,7 +2586,9 @@ const Writer = struct {...@@ -2594,7 +2586,9 @@ const Writer = struct {
2594 },2586 },
2595 }2587 }
2596 const src_hash = self.code.getAssociatedSrcHash(inst).?;2588 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
2599 {2593 {
2600 if (decl.type_body) |b| {2594 if (decl.type_body) |b| {
...@@ -2627,26 +2621,26 @@ const Writer = struct {...@@ -2627,26 +2621,26 @@ const Writer = struct {
2627 try self.writeSrcNode(stream, .zero);2621 try self.writeSrcNode(stream, .zero);
2628 }2622 }
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 {
2631 try stream.print("{d})) ", .{extended.small});2625 try stream.print("{d})) ", .{extended.small});
2632 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));2626 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
2633 try self.writeSrcNode(stream, src_node);2627 try self.writeSrcNode(stream, src_node);
2634 }2628 }
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 {
2637 const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);2631 const val: Zir.Inst.BuiltinValue = @enumFromInt(extended.small);
2638 try stream.print("{s})) ", .{@tagName(val)});2632 try stream.print("{s})) ", .{@tagName(val)});
2639 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));2633 const src_node: Ast.Node.Offset = @enumFromInt(@as(i32, @bitCast(extended.operand)));
2640 try self.writeSrcNode(stream, src_node);2634 try self.writeSrcNode(stream, src_node);
2641 }2635 }
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 {
2644 const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small);2638 const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small);
2645 try self.writeInstRef(stream, @enumFromInt(extended.operand));2639 try self.writeInstRef(stream, @enumFromInt(extended.operand));
2646 try stream.print(", {s}))", .{@tagName(op)});2640 try stream.print(", {s}))", .{@tagName(op)});
2647 }2641 }
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 {
2650 if (ref == .none) {2644 if (ref == .none) {
2651 return stream.writeAll(".none");2645 return stream.writeAll(".none");
2652 } else if (ref.toIndex()) |i| {2646 } else if (ref.toIndex()) |i| {
...@@ -2657,12 +2651,12 @@ const Writer = struct {...@@ -2657,12 +2651,12 @@ const Writer = struct {
2657 }2651 }
2658 }2652 }
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 {
2661 _ = self;2655 _ = self;
2662 return stream.print("%{d}", .{@intFromEnum(inst)});2656 return stream.print("%{d}", .{@intFromEnum(inst)});
2663 }2657 }
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 {
2666 if (captures_len == 0) {2660 if (captures_len == 0) {
2667 try stream.writeAll("{}");2661 try stream.writeAll("{}");
2668 return extra_index;2662 return extra_index;
...@@ -2682,7 +2676,7 @@ const Writer = struct {...@@ -2682,7 +2676,7 @@ const Writer = struct {
2682 return extra_index + 2 * captures_len;2676 return extra_index + 2 * captures_len;
2683 }2677 }
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 {
2686 switch (capture.unwrap()) {2680 switch (capture.unwrap()) {
2687 .nested => |i| return stream.print("[{d}]", .{i}),2681 .nested => |i| return stream.print("[{d}]", .{i}),
2688 .instruction => |inst| return self.writeInstIndex(stream, inst),2682 .instruction => |inst| return self.writeInstIndex(stream, inst),
...@@ -2701,7 +2695,7 @@ const Writer = struct {...@@ -2701,7 +2695,7 @@ const Writer = struct {
27012695
2702 fn writeOptionalInstRef(2696 fn writeOptionalInstRef(
2703 self: *Writer,2697 self: *Writer,
2704 stream: anytype,2698 stream: *std.io.Writer,
2705 prefix: []const u8,2699 prefix: []const u8,
2706 inst: Zir.Inst.Ref,2700 inst: Zir.Inst.Ref,
2707 ) !void {2701 ) !void {
...@@ -2712,7 +2706,7 @@ const Writer = struct {...@@ -2712,7 +2706,7 @@ const Writer = struct {
27122706
2713 fn writeOptionalInstRefOrBody(2707 fn writeOptionalInstRefOrBody(
2714 self: *Writer,2708 self: *Writer,
2715 stream: anytype,2709 stream: *std.io.Writer,
2716 prefix: []const u8,2710 prefix: []const u8,
2717 ref: Zir.Inst.Ref,2711 ref: Zir.Inst.Ref,
2718 body: []const Zir.Inst.Index,2712 body: []const Zir.Inst.Index,
...@@ -2730,7 +2724,7 @@ const Writer = struct {...@@ -2730,7 +2724,7 @@ const Writer = struct {
27302724
2731 fn writeFlag(2725 fn writeFlag(
2732 self: *Writer,2726 self: *Writer,
2733 stream: anytype,2727 stream: *std.io.Writer,
2734 name: []const u8,2728 name: []const u8,
2735 flag: bool,2729 flag: bool,
2736 ) !void {2730 ) !void {
...@@ -2739,7 +2733,7 @@ const Writer = struct {...@@ -2739,7 +2733,7 @@ const Writer = struct {
2739 try stream.writeAll(name);2733 try stream.writeAll(name);
2740 }2734 }
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 {
2743 const tree = self.tree orelse return;2737 const tree = self.tree orelse return;
2744 const abs_node = src_node.toAbsolute(self.parent_decl_node);2738 const abs_node = src_node.toAbsolute(self.parent_decl_node);
2745 const src_span = tree.nodeToSpan(abs_node);2739 const src_span = tree.nodeToSpan(abs_node);
...@@ -2751,7 +2745,7 @@ const Writer = struct {...@@ -2751,7 +2745,7 @@ const Writer = struct {
2751 });2745 });
2752 }2746 }
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 {
2755 const tree = self.tree orelse return;2749 const tree = self.tree orelse return;
2756 const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));2750 const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));
2757 const span_start = tree.tokenStart(abs_tok);2751 const span_start = tree.tokenStart(abs_tok);
...@@ -2764,7 +2758,7 @@ const Writer = struct {...@@ -2764,7 +2758,7 @@ const Writer = struct {
2764 });2758 });
2765 }2759 }
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 {
2768 const tree = self.tree orelse return;2762 const tree = self.tree orelse return;
2769 const span_start = tree.tokenStart(src_tok);2763 const span_start = tree.tokenStart(src_tok);
2770 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));2764 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
...@@ -2776,15 +2770,15 @@ const Writer = struct {...@@ -2776,15 +2770,15 @@ const Writer = struct {
2776 });2770 });
2777 }2771 }
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 {
2780 try self.writeBracedBodyConditional(stream, body, self.recurse_decls);2774 try self.writeBracedBodyConditional(stream, body, self.recurse_decls);
2781 }2775 }
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 {
2784 try self.writeBracedBodyConditional(stream, body, self.recurse_blocks);2778 try self.writeBracedBodyConditional(stream, body, self.recurse_blocks);
2785 }2779 }
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 {
2788 if (body.len == 0) {2782 if (body.len == 0) {
2789 try stream.writeAll("{}");2783 try stream.writeAll("{}");
2790 } else if (enabled) {2784 } else if (enabled) {
...@@ -2792,7 +2786,7 @@ const Writer = struct {...@@ -2792,7 +2786,7 @@ const Writer = struct {
2792 self.indent += 2;2786 self.indent += 2;
2793 try self.writeBody(stream, body);2787 try self.writeBody(stream, body);
2794 self.indent -= 2;2788 self.indent -= 2;
2795 try stream.writeByteNTimes(' ', self.indent);2789 try stream.splatByteAll(' ', self.indent);
2796 try stream.writeAll("}");2790 try stream.writeAll("}");
2797 } else if (body.len == 1) {2791 } else if (body.len == 1) {
2798 try stream.writeByte('{');2792 try stream.writeByte('{');
...@@ -2813,16 +2807,16 @@ const Writer = struct {...@@ -2813,16 +2807,16 @@ const Writer = struct {
2813 }2807 }
2814 }2808 }
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 {
2817 for (body) |inst| {2811 for (body) |inst| {
2818 try stream.writeByteNTimes(' ', self.indent);2812 try stream.splatByteAll(' ', self.indent);
2819 try stream.print("%{d} ", .{@intFromEnum(inst)});2813 try stream.print("%{d} ", .{@intFromEnum(inst)});
2820 try self.writeInstToStream(stream, inst);2814 try self.writeInstToStream(stream, inst);
2821 try stream.writeByte('\n');2815 try stream.writeByte('\n');
2822 }2816 }
2823 }2817 }
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 {
2826 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;2820 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok;
2827 const extra = self.code.extraData(Zir.Inst.Import, inst_data.payload_index).data;2821 const extra = self.code.extraData(Zir.Inst.Import, inst_data.payload_index).data;
2828 try self.writeInstRef(stream, extra.res_ty);2822 try self.writeInstRef(stream, extra.res_ty);
src/print_zoir.zig+19-25
...@@ -1,13 +1,8 @@...@@ -1,13 +1,8 @@
1pub fn renderToFile(zoir: Zoir, arena: Allocator, f: std.fs.File) (std.fs.File.WriteError || Allocator.Error)!void {1pub const Error = error{ WriteFailed, OutOfMemory };
2 var bw = std.io.bufferedWriter(f.writer());
3 try renderToWriter(zoir, arena, bw.writer());
4 try bw.flush();
5}
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 {
8 assert(!zoir.hasCompileErrors());4 assert(!zoir.hasCompileErrors());
95
10 const fmtIntSizeBin = std.fmt.fmtIntSizeBin;
11 const bytes_per_node = comptime n: {6 const bytes_per_node = comptime n: {
12 var n: usize = 0;7 var n: usize = 0;
13 for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| {8 for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| {
...@@ -23,42 +18,42 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: anytype) (@TypeOf(w).Erro...@@ -23,42 +18,42 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: anytype) (@TypeOf(w).Erro
2318
24 // zig fmt: off19 // zig fmt: off
25 try w.print(20 try w.print(
26 \\# Nodes: {} ({})21 \\# Nodes: {} ({Bi})
27 \\# Extra Data Items: {} ({})22 \\# Extra Data Items: {} ({Bi})
28 \\# BigInt Limbs: {} ({})23 \\# BigInt Limbs: {} ({Bi})
29 \\# String Table Bytes: {}24 \\# String Table Bytes: {Bi}
30 \\# Total ZON Bytes: {}25 \\# Total ZON Bytes: {Bi}
31 \\26 \\
32 , .{27 , .{
33 zoir.nodes.len, fmtIntSizeBin(node_bytes),28 zoir.nodes.len, node_bytes,
34 zoir.extra.len, fmtIntSizeBin(extra_bytes),29 zoir.extra.len, extra_bytes,
35 zoir.limbs.len, fmtIntSizeBin(limb_bytes),30 zoir.limbs.len, limb_bytes,
36 fmtIntSizeBin(string_bytes),31 string_bytes,
37 fmtIntSizeBin(node_bytes + extra_bytes + limb_bytes + string_bytes),32 node_bytes + extra_bytes + limb_bytes + string_bytes,
38 });33 });
39 // zig fmt: on34 // zig fmt: on
40 var pz: PrintZon = .{35 var pz: PrintZon = .{
41 .w = w.any(),36 .w = w,
42 .arena = arena,37 .arena = arena,
43 .zoir = zoir,38 .zoir = zoir,
44 .indent = 0,39 .indent = 0,
45 };40 };
4641
47 return @errorCast(pz.renderRoot());42 return pz.renderRoot();
48}43}
4944
50const PrintZon = struct {45const PrintZon = struct {
51 w: std.io.AnyWriter,46 w: *Writer,
52 arena: Allocator,47 arena: Allocator,
53 zoir: Zoir,48 zoir: Zoir,
54 indent: u32,49 indent: u32,
5550
56 fn renderRoot(pz: *PrintZon) anyerror!void {51 fn renderRoot(pz: *PrintZon) Error!void {
57 try pz.renderNode(.root);52 try pz.renderNode(.root);
58 try pz.w.writeByte('\n');53 try pz.w.writeByte('\n');
59 }54 }
6055
61 fn renderNode(pz: *PrintZon, node: Zoir.Node.Index) anyerror!void {56 fn renderNode(pz: *PrintZon, node: Zoir.Node.Index) Error!void {
62 const zoir = pz.zoir;57 const zoir = pz.zoir;
63 try pz.w.print("%{d} = ", .{@intFromEnum(node)});58 try pz.w.print("%{d} = ", .{@intFromEnum(node)});
64 switch (node.get(zoir)) {59 switch (node.get(zoir)) {
...@@ -110,9 +105,7 @@ const PrintZon = struct {...@@ -110,9 +105,7 @@ const PrintZon = struct {
110105
111 fn newline(pz: *PrintZon) !void {106 fn newline(pz: *PrintZon) !void {
112 try pz.w.writeByte('\n');107 try pz.w.writeByte('\n');
113 for (0..pz.indent) |_| {108 try pz.w.splatByteAll(' ', 2 * pz.indent);
114 try pz.w.writeByteNTimes(' ', 2);
115 }
116 }109 }
117};110};
118111
...@@ -120,3 +113,4 @@ const std = @import("std");...@@ -120,3 +113,4 @@ const std = @import("std");
120const assert = std.debug.assert;113const assert = std.debug.assert;
121const Allocator = std.mem.Allocator;114const Allocator = std.mem.Allocator;
122const Zoir = std.zig.Zoir;115const Zoir = std.zig.Zoir;
116const Writer = std.io.Writer;