authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-02 13:24:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:52-07:00
log3afc6fbac63b31fd250b6cbc4451758e50f85b24
treecafa66d30c871a162cd061af2afb003c1d6263d3
parentcce32bd1d505ee5c5ea7878c9e9e57b6b63856f2

std.zig.llvm.Builder: update format API


5 files changed, 340 insertions(+), 398 deletions(-)

lib/std/zig/llvm/Builder.zig+234-203
...@@ -110,15 +110,28 @@ pub const String = enum(u32) {...@@ -110,15 +110,28 @@ pub const String = enum(u32) {
110 const quote_behavior = data.quote_behavior orelse return w.writeAll(string_slice);110 const quote_behavior = data.quote_behavior orelse return w.writeAll(string_slice);
111 return printEscapedString(string_slice, quote_behavior, w);111 return printEscapedString(string_slice, quote_behavior, w);
112 }112 }
113 pub fn fmt(113
114 self: String,114 pub fn fmt(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
115 builder: *const Builder,
116 quote_behavior: ?QuoteBehavior,
117 ) std.fmt.Formatter(FormatData, format) {
118 return .{ .data = .{115 return .{ .data = .{
119 .string = self,116 .string = self,
120 .builder = builder,117 .builder = builder,
121 .quote_behavior = quote_behavior,118 .quote_behavior = .quote_unless_valid_identifier,
119 } };
120 }
121
122 pub fn fmtQ(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
123 return .{ .data = .{
124 .string = self,
125 .builder = builder,
126 .quote_behavior = .always_quote,
127 } };
128 }
129
130 pub fn fmtRaw(self: String, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
131 return .{ .data = .{
132 .string = self,
133 .builder = builder,
134 .quote_behavior = null,
122 } };135 } };
123 }136 }
124137
...@@ -684,8 +697,8 @@ pub const Type = enum(u32) {...@@ -684,8 +697,8 @@ pub const Type = enum(u32) {
684 .function, .vararg_function => |kind| {697 .function, .vararg_function => |kind| {
685 var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);698 var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);
686 const params = extra.trail.next(extra.data.params_len, Type, data.builder);699 const params = extra.trail.next(extra.data.params_len, Type, data.builder);
687 try w.print("f_{fm}", .{extra.data.ret.fmt(data.builder)});700 try w.print("f_{f}", .{extra.data.ret.fmt(data.builder, .m)});
688 for (params) |param| try w.print("{fm}", .{param.fmt(data.builder)});701 for (params) |param| try w.print("{f}", .{param.fmt(data.builder, .m)});
689 switch (kind) {702 switch (kind) {
690 .function => {},703 .function => {},
691 .vararg_function => try w.writeAll("vararg"),704 .vararg_function => try w.writeAll("vararg"),
...@@ -700,20 +713,20 @@ pub const Type = enum(u32) {...@@ -700,20 +713,20 @@ pub const Type = enum(u32) {
700 const types = extra.trail.next(extra.data.types_len, Type, data.builder);713 const types = extra.trail.next(extra.data.types_len, Type, data.builder);
701 const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);714 const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);
702 try w.print("t{s}", .{extra.data.name.slice(data.builder).?});715 try w.print("t{s}", .{extra.data.name.slice(data.builder).?});
703 for (types) |ty| try w.print("_{fm}", .{ty.fmt(data.builder)});716 for (types) |ty| try w.print("_{f}", .{ty.fmt(data.builder, .m)});
704 for (ints) |int| try w.print("_{d}", .{int});717 for (ints) |int| try w.print("_{d}", .{int});
705 try w.writeByte('t');718 try w.writeByte('t');
706 },719 },
707 .vector, .scalable_vector => |kind| {720 .vector, .scalable_vector => |kind| {
708 const extra = data.builder.typeExtraData(Type.Vector, item.data);721 const extra = data.builder.typeExtraData(Type.Vector, item.data);
709 try w.print("{s}v{d}{fm}", .{722 try w.print("{s}v{d}{f}", .{
710 switch (kind) {723 switch (kind) {
711 .vector => "",724 .vector => "",
712 .scalable_vector => "nx",725 .scalable_vector => "nx",
713 else => unreachable,726 else => unreachable,
714 },727 },
715 extra.len,728 extra.len,
716 extra.child.fmt(data.builder),729 extra.child.fmt(data.builder, .m),
717 });730 });
718 },731 },
719 inline .small_array, .array => |kind| {732 inline .small_array, .array => |kind| {
...@@ -722,13 +735,13 @@ pub const Type = enum(u32) {...@@ -722,13 +735,13 @@ pub const Type = enum(u32) {
722 .array => Type.Array,735 .array => Type.Array,
723 else => unreachable,736 else => unreachable,
724 }, item.data);737 }, item.data);
725 try w.print("a{d}{fm}", .{ extra.length(), extra.child.fmt(data.builder) });738 try w.print("a{d}{f}", .{ extra.length(), extra.child.fmt(data.builder, .m) });
726 },739 },
727 .structure, .packed_structure => {740 .structure, .packed_structure => {
728 var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);741 var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);
729 const fields = extra.trail.next(extra.data.fields_len, Type, data.builder);742 const fields = extra.trail.next(extra.data.fields_len, Type, data.builder);
730 try w.writeAll("sl_");743 try w.writeAll("sl_");
731 for (fields) |field| try w.print("{fm}", .{field.fmt(data.builder)});744 for (fields) |field| try w.print("{f}", .{field.fmt(data.builder, .m)});
732 try w.writeByte('s');745 try w.writeByte('s');
733 },746 },
734 .named_structure => {747 .named_structure => {
...@@ -747,12 +760,12 @@ pub const Type = enum(u32) {...@@ -747,12 +760,12 @@ pub const Type = enum(u32) {
747 var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);760 var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);
748 const params = extra.trail.next(extra.data.params_len, Type, data.builder);761 const params = extra.trail.next(extra.data.params_len, Type, data.builder);
749 if (data.mode != .gt)762 if (data.mode != .gt)
750 try w.print("{f%} ", .{extra.data.ret.fmt(data.builder)});763 try w.print("{f} ", .{extra.data.ret.fmt(data.builder, .percent)});
751 if (data.mode != .lt) {764 if (data.mode != .lt) {
752 try w.writeByte('(');765 try w.writeByte('(');
753 for (params, 0..) |param, index| {766 for (params, 0..) |param, index| {
754 if (index > 0) try w.writeAll(", ");767 if (index > 0) try w.writeAll(", ");
755 try w.print("{f%}", .{param.fmt(data.builder)});768 try w.print("{f}", .{param.fmt(data.builder, .percent)});
756 }769 }
757 switch (kind) {770 switch (kind) {
758 .function => {},771 .function => {},
...@@ -772,22 +785,22 @@ pub const Type = enum(u32) {...@@ -772,22 +785,22 @@ pub const Type = enum(u32) {
772 const types = extra.trail.next(extra.data.types_len, Type, data.builder);785 const types = extra.trail.next(extra.data.types_len, Type, data.builder);
773 const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);786 const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);
774 try w.print(787 try w.print(
775 \\target({f"}788 \\target({f}
776 , .{extra.data.name.fmt(data.builder)});789 , .{extra.data.name.fmtQ(data.builder)});
777 for (types) |ty| try w.print(", {f%}", .{ty.fmt(data.builder)});790 for (types) |ty| try w.print(", {f}", .{ty.fmt(data.builder, .percent)});
778 for (ints) |int| try w.print(", {d}", .{int});791 for (ints) |int| try w.print(", {d}", .{int});
779 try w.writeByte(')');792 try w.writeByte(')');
780 },793 },
781 .vector, .scalable_vector => |kind| {794 .vector, .scalable_vector => |kind| {
782 const extra = data.builder.typeExtraData(Type.Vector, item.data);795 const extra = data.builder.typeExtraData(Type.Vector, item.data);
783 try w.print("<{s}{d} x {f%}>", .{796 try w.print("<{s}{d} x {f}>", .{
784 switch (kind) {797 switch (kind) {
785 .vector => "",798 .vector => "",
786 .scalable_vector => "vscale x ",799 .scalable_vector => "vscale x ",
787 else => unreachable,800 else => unreachable,
788 },801 },
789 extra.len,802 extra.len,
790 extra.child.fmt(data.builder),803 extra.child.fmt(data.builder, .percent),
791 });804 });
792 },805 },
793 inline .small_array, .array => |kind| {806 inline .small_array, .array => |kind| {
...@@ -796,7 +809,7 @@ pub const Type = enum(u32) {...@@ -796,7 +809,7 @@ pub const Type = enum(u32) {
796 .array => Type.Array,809 .array => Type.Array,
797 else => unreachable,810 else => unreachable,
798 }, item.data);811 }, item.data);
799 try w.print("[{d} x {f%}]", .{ extra.length(), extra.child.fmt(data.builder) });812 try w.print("[{d} x {f}]", .{ extra.length(), extra.child.fmt(data.builder, .percent) });
800 },813 },
801 .structure, .packed_structure => |kind| {814 .structure, .packed_structure => |kind| {
802 var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);815 var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);
...@@ -809,7 +822,7 @@ pub const Type = enum(u32) {...@@ -809,7 +822,7 @@ pub const Type = enum(u32) {
809 try w.writeAll("{ ");822 try w.writeAll("{ ");
810 for (fields, 0..) |field, index| {823 for (fields, 0..) |field, index| {
811 if (index > 0) try w.writeAll(", ");824 if (index > 0) try w.writeAll(", ");
812 try w.print("{f%}", .{field.fmt(data.builder)});825 try w.print("{f}", .{field.fmt(data.builder, .percent)});
813 }826 }
814 try w.writeAll(" }");827 try w.writeAll(" }");
815 switch (kind) {828 switch (kind) {
...@@ -1225,7 +1238,7 @@ pub const Attribute = union(Kind) {...@@ -1225,7 +1238,7 @@ pub const Attribute = union(Kind) {
1225 .inalloca,1238 .inalloca,
1226 .sret,1239 .sret,
1227 .elementtype,1240 .elementtype,
1228 => |ty| try w.print(" {s}({f%})", .{ @tagName(attribute), ty.fmt(data.builder) }),1241 => |ty| try w.print(" {s}({f})", .{ @tagName(attribute), ty.fmt(data.builder, .percent) }),
1229 .@"align" => |alignment| try w.print("{f }", .{alignment}),1242 .@"align" => |alignment| try w.print("{f }", .{alignment}),
1230 .dereferenceable,1243 .dereferenceable,
1231 .dereferenceable_or_null,1244 .dereferenceable_or_null,
...@@ -1248,10 +1261,14 @@ pub const Attribute = union(Kind) {...@@ -1248,10 +1261,14 @@ pub const Attribute = union(Kind) {
1248 }1261 }
1249 try w.writeByte(')');1262 try w.writeByte(')');
1250 },1263 },
1251 .alignstack => |alignment| try w.print(1264 .alignstack => |alignment| {
1252 if (data.mode == .pound) " {s}={d}" else " {s}({d})",1265 try w.print(" {s}", .{attribute});
1253 .{ @tagName(attribute), alignment.toByteUnits() orelse return },1266 const alignment_bytes = alignment.toByteUnits() orelse return;
1254 ),1267 switch (data.mode) {
1268 .pound => try w.print("({d})", .{alignment_bytes}),
1269 else => try w.print("={d}", .{alignment_bytes}),
1270 }
1271 },
1255 .allockind => |allockind| {1272 .allockind => |allockind| {
1256 try w.print(" {s}(\"", .{@tagName(attribute)});1273 try w.print(" {s}(\"", .{@tagName(attribute)});
1257 var any = false;1274 var any = false;
...@@ -1297,9 +1314,9 @@ pub const Attribute = union(Kind) {...@@ -1297,9 +1314,9 @@ pub const Attribute = union(Kind) {
1297 vscale_range.max.toByteUnits() orelse 0,1314 vscale_range.max.toByteUnits() orelse 0,
1298 }),1315 }),
1299 .string => |string_attr| if (data.mode == .quote) {1316 .string => |string_attr| if (data.mode == .quote) {
1300 try w.print(" {f\"}", .{string_attr.kind.fmt(data.builder)});1317 try w.print(" {f}", .{string_attr.kind.fmtQ(data.builder)});
1301 if (string_attr.value != .empty)1318 if (string_attr.value != .empty)
1302 try w.print("={f\"}", .{string_attr.value.fmt(data.builder)});1319 try w.print("={f}", .{string_attr.value.fmtQ(data.builder)});
1303 },1320 },
1304 .none => unreachable,1321 .none => unreachable,
1305 }1322 }
...@@ -1583,6 +1600,7 @@ pub const Attributes = enum(u32) {...@@ -1583,6 +1600,7 @@ pub const Attributes = enum(u32) {
1583 for (data.attributes.slice(data.builder)) |attribute_index| try Attribute.Index.format(.{1600 for (data.attributes.slice(data.builder)) |attribute_index| try Attribute.Index.format(.{
1584 .attribute_index = attribute_index,1601 .attribute_index = attribute_index,
1585 .builder = data.builder,1602 .builder = data.builder,
1603 .mode = .default,
1586 }, w);1604 }, w);
1587 }1605 }
1588 pub fn fmt(self: Attributes, builder: *const Builder) std.fmt.Formatter(FormatData, format) {1606 pub fn fmt(self: Attributes, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
...@@ -2315,7 +2333,7 @@ pub const Global = struct {...@@ -2315,7 +2333,7 @@ pub const Global = struct {
2315 };2333 };
2316 fn format(data: FormatData, w: *Writer) Writer.Error!void {2334 fn format(data: FormatData, w: *Writer) Writer.Error!void {
2317 try w.print("@{f}", .{2335 try w.print("@{f}", .{
2318 data.global.unwrap(data.builder).name(data.builder).fmt(data.builder),2336 data.global.unwrap(data.builder).name(data.builder).fmt(data.builder, null),
2319 });2337 });
2320 }2338 }
2321 pub fn fmt(self: Index, builder: *const Builder) std.fmt.Formatter(FormatData, format) {2339 pub fn fmt(self: Index, builder: *const Builder) std.fmt.Formatter(FormatData, format) {
...@@ -4758,12 +4776,7 @@ pub const Function = struct {...@@ -4758,12 +4776,7 @@ pub const Function = struct {
4758 instruction: Instruction.Index,4776 instruction: Instruction.Index,
4759 function: Function.Index,4777 function: Function.Index,
4760 builder: *Builder,4778 builder: *Builder,
4761 flags: Flags,4779 flags: FormatFlags,
4762 const Flags = struct {
4763 comma: bool = false,
4764 space: bool = false,
4765 percent: bool = false,
4766 };
4767 };4780 };
4768 fn format(data: FormatData, w: *Writer) Writer.Error!void {4781 fn format(data: FormatData, w: *Writer) Writer.Error!void {
4769 if (data.flags.comma) {4782 if (data.flags.comma) {
...@@ -4775,8 +4788,8 @@ pub const Function = struct {...@@ -4775,8 +4788,8 @@ pub const Function = struct {
4775 try w.writeByte(' ');4788 try w.writeByte(' ');
4776 }4789 }
4777 if (data.flags.percent) try w.print(4790 if (data.flags.percent) try w.print(
4778 "{f%} ",4791 "{f} ",
4779 .{data.instruction.typeOf(data.function, data.builder).fmt(data.builder)},4792 .{data.instruction.typeOf(data.function, data.builder).fmt(data.builder, .percent)},
4780 );4793 );
4781 assert(data.instruction != .none);4794 assert(data.instruction != .none);
4782 try w.print("%{f}", .{4795 try w.print("%{f}", .{
...@@ -4787,7 +4800,7 @@ pub const Function = struct {...@@ -4787,7 +4800,7 @@ pub const Function = struct {
4787 self: Instruction.Index,4800 self: Instruction.Index,
4788 function: Function.Index,4801 function: Function.Index,
4789 builder: *Builder,4802 builder: *Builder,
4790 flags: FormatData.Flags,4803 flags: FormatFlags,
4791 ) std.fmt.Formatter(FormatData, format) {4804 ) std.fmt.Formatter(FormatData, format) {
4792 return .{ .data = .{4805 return .{ .data = .{
4793 .instruction = self,4806 .instruction = self,
...@@ -6291,10 +6304,10 @@ pub const WipFunction = struct {...@@ -6291,10 +6304,10 @@ pub const WipFunction = struct {
62916304
6292 while (true) {6305 while (true) {
6293 gop.value_ptr.* = @enumFromInt(@intFromEnum(gop.value_ptr.*) + 1);6306 gop.value_ptr.* = @enumFromInt(@intFromEnum(gop.value_ptr.*) + 1);
6294 const unique_name = try wip_name.builder.fmt("{fr}{s}{fr}", .{6307 const unique_name = try wip_name.builder.fmt("{f}{s}{f}", .{
6295 name.fmt(wip_name.builder),6308 name.fmtRaw(wip_name.builder),
6296 sep,6309 sep,
6297 gop.value_ptr.fmt(wip_name.builder),6310 gop.value_ptr.fmtRaw(wip_name.builder),
6298 });6311 });
6299 const unique_gop = try wip_name.next_unique_name.getOrPut(unique_name);6312 const unique_gop = try wip_name.next_unique_name.getOrPut(unique_name);
6300 if (!unique_gop.found_existing) {6313 if (!unique_gop.found_existing) {
...@@ -7401,12 +7414,7 @@ pub const Constant = enum(u32) {...@@ -7401,12 +7414,7 @@ pub const Constant = enum(u32) {
7401 const FormatData = struct {7414 const FormatData = struct {
7402 constant: Constant,7415 constant: Constant,
7403 builder: *Builder,7416 builder: *Builder,
7404 flags: Flags,7417 flags: FormatFlags,
7405 const Flags = struct {
7406 comma: bool = false,
7407 space: bool = false,
7408 percent: bool = false,
7409 };
7410 };7418 };
7411 fn format(data: FormatData, w: *Writer) Writer.Error!void {7419 fn format(data: FormatData, w: *Writer) Writer.Error!void {
7412 if (data.flags.comma) {7420 if (data.flags.comma) {
...@@ -7418,7 +7426,7 @@ pub const Constant = enum(u32) {...@@ -7418,7 +7426,7 @@ pub const Constant = enum(u32) {
7418 try w.writeByte(' ');7426 try w.writeByte(' ');
7419 }7427 }
7420 if (data.flags.percent)7428 if (data.flags.percent)
7421 try w.print("{f%} ", .{data.constant.typeOf(data.builder).fmt(data.builder)});7429 try w.print("{f} ", .{data.constant.typeOf(data.builder).fmt(data.builder, .percent)});
7422 assert(data.constant != .no_init);7430 assert(data.constant != .no_init);
7423 if (std.enums.tagName(Constant, data.constant)) |name| return w.writeAll(name);7431 if (std.enums.tagName(Constant, data.constant)) |name| return w.writeAll(name);
7424 switch (data.constant.unwrap()) {7432 switch (data.constant.unwrap()) {
...@@ -7457,7 +7465,7 @@ pub const Constant = enum(u32) {...@@ -7457,7 +7465,7 @@ pub const Constant = enum(u32) {
7457 var stack align(@alignOf(ExpectedContents)) =7465 var stack align(@alignOf(ExpectedContents)) =
7458 std.heap.stackFallback(@sizeOf(ExpectedContents), data.builder.gpa);7466 std.heap.stackFallback(@sizeOf(ExpectedContents), data.builder.gpa);
7459 const allocator = stack.get();7467 const allocator = stack.get();
7460 const str = try bigint.toStringAlloc(allocator, 10, undefined);7468 const str = bigint.toStringAlloc(allocator, 10, undefined) catch return error.WriteFailed;
7461 defer allocator.free(str);7469 defer allocator.free(str);
7462 try w.writeAll(str);7470 try w.writeAll(str);
7463 },7471 },
...@@ -7563,7 +7571,7 @@ pub const Constant = enum(u32) {...@@ -7563,7 +7571,7 @@ pub const Constant = enum(u32) {
7563 });7571 });
7564 for (vals, 0..) |val, index| {7572 for (vals, 0..) |val, index| {
7565 if (index > 0) try w.writeAll(", ");7573 if (index > 0) try w.writeAll(", ");
7566 try w.print("{f%}", .{val.fmt(data.builder)});7574 try w.print("{f}", .{val.fmt(data.builder, .{ .percent = true })});
7567 }7575 }
7568 try w.writeAll(switch (tag) {7576 try w.writeAll(switch (tag) {
7569 .structure => " }",7577 .structure => " }",
...@@ -7579,12 +7587,12 @@ pub const Constant = enum(u32) {...@@ -7579,12 +7587,12 @@ pub const Constant = enum(u32) {
7579 try w.writeByte('<');7587 try w.writeByte('<');
7580 for (0..len) |index| {7588 for (0..len) |index| {
7581 if (index > 0) try w.writeAll(", ");7589 if (index > 0) try w.writeAll(", ");
7582 try w.print("{f%}", .{extra.value.fmt(data.builder)});7590 try w.print("{f}", .{extra.value.fmt(data.builder, .{ .percent = true })});
7583 }7591 }
7584 try w.writeByte('>');7592 try w.writeByte('>');
7585 },7593 },
7586 .string => try w.print("c{f\"}", .{7594 .string => try w.print("c{f}", .{
7587 @as(String, @enumFromInt(item.data)).fmt(data.builder),7595 @as(String, @enumFromInt(item.data)).fmtQ(data.builder),
7588 }),7596 }),
7589 .blockaddress => |tag| {7597 .blockaddress => |tag| {
7590 const extra = data.builder.constantExtraData(BlockAddress, item.data);7598 const extra = data.builder.constantExtraData(BlockAddress, item.data);
...@@ -7592,7 +7600,7 @@ pub const Constant = enum(u32) {...@@ -7592,7 +7600,7 @@ pub const Constant = enum(u32) {
7592 try w.print("{s}({f}, {f})", .{7600 try w.print("{s}({f}, {f})", .{
7593 @tagName(tag),7601 @tagName(tag),
7594 function.global.fmt(data.builder),7602 function.global.fmt(data.builder),
7595 extra.block.toInst(function).fmt(extra.function, data.builder),7603 extra.block.toInst(function).fmt(extra.function, data.builder, .{}),
7596 });7604 });
7597 },7605 },
7598 .dso_local_equivalent,7606 .dso_local_equivalent,
...@@ -7611,10 +7619,10 @@ pub const Constant = enum(u32) {...@@ -7611,10 +7619,10 @@ pub const Constant = enum(u32) {
7611 .addrspacecast,7619 .addrspacecast,
7612 => |tag| {7620 => |tag| {
7613 const extra = data.builder.constantExtraData(Cast, item.data);7621 const extra = data.builder.constantExtraData(Cast, item.data);
7614 try w.print("{s} ({f%} to {f%})", .{7622 try w.print("{s} ({f} to {f})", .{
7615 @tagName(tag),7623 @tagName(tag),
7616 extra.val.fmt(data.builder),7624 extra.val.fmt(data.builder, .{ .percent = true }),
7617 extra.type.fmt(data.builder),7625 extra.type.fmt(data.builder, .percent),
7618 });7626 });
7619 },7627 },
7620 .getelementptr,7628 .getelementptr,
...@@ -7623,12 +7631,12 @@ pub const Constant = enum(u32) {...@@ -7623,12 +7631,12 @@ pub const Constant = enum(u32) {
7623 var extra = data.builder.constantExtraDataTrail(GetElementPtr, item.data);7631 var extra = data.builder.constantExtraDataTrail(GetElementPtr, item.data);
7624 const indices =7632 const indices =
7625 extra.trail.next(extra.data.info.indices_len, Constant, data.builder);7633 extra.trail.next(extra.data.info.indices_len, Constant, data.builder);
7626 try w.print("{s} ({f%}, {f%}", .{7634 try w.print("{s} ({f}, {f}", .{
7627 @tagName(tag),7635 @tagName(tag),
7628 extra.data.type.fmt(data.builder),7636 extra.data.type.fmt(data.builder, .percent),
7629 extra.data.base.fmt(data.builder),7637 extra.data.base.fmt(data.builder, .{ .percent = true }),
7630 });7638 });
7631 for (indices) |index| try w.print(", {f%}", .{index.fmt(data.builder)});7639 for (indices) |index| try w.print(", {f}", .{index.fmt(data.builder, .{ .percent = true })});
7632 try w.writeByte(')');7640 try w.writeByte(')');
7633 },7641 },
7634 .add,7642 .add,
...@@ -7641,10 +7649,10 @@ pub const Constant = enum(u32) {...@@ -7641,10 +7649,10 @@ pub const Constant = enum(u32) {
7641 .xor,7649 .xor,
7642 => |tag| {7650 => |tag| {
7643 const extra = data.builder.constantExtraData(Binary, item.data);7651 const extra = data.builder.constantExtraData(Binary, item.data);
7644 try w.print("{s} ({f%}, {f%})", .{7652 try w.print("{s} ({f}, {f})", .{
7645 @tagName(tag),7653 @tagName(tag),
7646 extra.lhs.fmt(data.builder),7654 extra.lhs.fmt(data.builder, .{ .percent = true }),
7647 extra.rhs.fmt(data.builder),7655 extra.rhs.fmt(data.builder, .{ .percent = true }),
7648 });7656 });
7649 },7657 },
7650 .@"asm",7658 .@"asm",
...@@ -7665,10 +7673,10 @@ pub const Constant = enum(u32) {...@@ -7665,10 +7673,10 @@ pub const Constant = enum(u32) {
7665 .@"asm sideeffect alignstack inteldialect unwind",7673 .@"asm sideeffect alignstack inteldialect unwind",
7666 => |tag| {7674 => |tag| {
7667 const extra = data.builder.constantExtraData(Assembly, item.data);7675 const extra = data.builder.constantExtraData(Assembly, item.data);
7668 try w.print("{s} {f\"}, {f\"}", .{7676 try w.print("{s} {f}, {f}", .{
7669 @tagName(tag),7677 @tagName(tag),
7670 extra.assembly.fmt(data.builder),7678 extra.assembly.fmtQ(data.builder),
7671 extra.constraints.fmt(data.builder),7679 extra.constraints.fmtQ(data.builder),
7672 });7680 });
7673 },7681 },
7674 }7682 }
...@@ -7676,7 +7684,7 @@ pub const Constant = enum(u32) {...@@ -7676,7 +7684,7 @@ pub const Constant = enum(u32) {
7676 .global => |global| try w.print("{f}", .{global.fmt(data.builder)}),7684 .global => |global| try w.print("{f}", .{global.fmt(data.builder)}),
7677 }7685 }
7678 }7686 }
7679 pub fn fmt(self: Constant, builder: *Builder, flags: FormatData.Flags) std.fmt.Formatter(FormatData, format) {7687 pub fn fmt(self: Constant, builder: *Builder, flags: FormatFlags) std.fmt.Formatter(FormatData, format) {
7680 return .{ .data = .{7688 return .{ .data = .{
7681 .constant = self,7689 .constant = self,
7682 .builder = builder,7690 .builder = builder,
...@@ -7736,6 +7744,7 @@ pub const Value = enum(u32) {...@@ -7736,6 +7744,7 @@ pub const Value = enum(u32) {
7736 value: Value,7744 value: Value,
7737 function: Function.Index,7745 function: Function.Index,
7738 builder: *Builder,7746 builder: *Builder,
7747 flags: FormatFlags,
7739 };7748 };
7740 fn format(data: FormatData, w: *Writer) Writer.Error!void {7749 fn format(data: FormatData, w: *Writer) Writer.Error!void {
7741 switch (data.value.unwrap()) {7750 switch (data.value.unwrap()) {
...@@ -7743,16 +7752,18 @@ pub const Value = enum(u32) {...@@ -7743,16 +7752,18 @@ pub const Value = enum(u32) {
7743 .instruction = instruction,7752 .instruction = instruction,
7744 .function = data.function,7753 .function = data.function,
7745 .builder = data.builder,7754 .builder = data.builder,
7755 .flags = data.flags,
7746 }, w),7756 }, w),
7747 .constant => |constant| try Constant.format(.{7757 .constant => |constant| try Constant.format(.{
7748 .constant = constant,7758 .constant = constant,
7749 .builder = data.builder,7759 .builder = data.builder,
7760 .flags = data.flags,
7750 }, w),7761 }, w),
7751 .metadata => unreachable,7762 .metadata => unreachable,
7752 }7763 }
7753 }7764 }
7754 pub fn fmt(self: Value, function: Function.Index, builder: *Builder) std.fmt.Formatter(FormatData, format) {7765 pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Formatter(FormatData, format) {
7755 return .{ .data = .{ .value = self, .function = function, .builder = builder } };7766 return .{ .data = .{ .value = self, .function = function, .builder = builder, .flags = flags } };
7756 }7767 }
7757};7768};
77587769
...@@ -8196,9 +8207,7 @@ pub const Metadata = enum(u32) {...@@ -8196,9 +8207,7 @@ pub const Metadata = enum(u32) {
8196 formatter: *Formatter,8207 formatter: *Formatter,
8197 prefix: []const u8 = "",8208 prefix: []const u8 = "",
8198 node: Node,8209 node: Node,
8199 specialized: ?TODO,8210 specialized: ?FormatFlags,
8200
8201 const TODO = opaque {};
82028211
8203 const Node = union(enum) {8212 const Node = union(enum) {
8204 none,8213 none,
...@@ -8228,7 +8237,6 @@ pub const Metadata = enum(u32) {...@@ -8228,7 +8237,6 @@ pub const Metadata = enum(u32) {
8228 if (data.node == .none) return;8237 if (data.node == .none) return;
82298238
8230 const is_specialized = data.specialized != null;8239 const is_specialized = data.specialized != null;
8231 const recurse_fmt_str = data.specialized orelse {};
82328240
8233 if (data.formatter.need_comma) try w.writeAll(", ");8241 if (data.formatter.need_comma) try w.writeAll(", ");
8234 defer data.formatter.need_comma = true;8242 defer data.formatter.need_comma = true;
...@@ -8251,13 +8259,15 @@ pub const Metadata = enum(u32) {...@@ -8251,13 +8259,15 @@ pub const Metadata = enum(u32) {
8251 for (elements) |element| try format(.{8259 for (elements) |element| try format(.{
8252 .formatter = data.formatter,8260 .formatter = data.formatter,
8253 .node = .{ .u64 = element },8261 .node = .{ .u64 = element },
8254 }, w, "%");8262 .specialized = .{ .percent = true },
8263 }, w);
8255 try w.writeByte(')');8264 try w.writeByte(')');
8256 },8265 },
8257 .constant => try Constant.format(.{8266 .constant => try Constant.format(.{
8258 .constant = @enumFromInt(item.data),8267 .constant = @enumFromInt(item.data),
8259 .builder = builder,8268 .builder = builder,
8260 }, w, recurse_fmt_str),8269 .flags = data.specialized orelse .{},
8270 }, w),
8261 else => unreachable,8271 else => unreachable,
8262 }8272 }
8263 },8273 },
...@@ -8266,28 +8276,33 @@ pub const Metadata = enum(u32) {...@@ -8266,28 +8276,33 @@ pub const Metadata = enum(u32) {
8266 .value = node.value,8276 .value = node.value,
8267 .function = node.function,8277 .function = node.function,
8268 .builder = builder,8278 .builder = builder,
8269 }, w, switch (tag) {8279 .flags = switch (tag) {
8270 .local_value => recurse_fmt_str,8280 .local_value => data.specialized orelse .{},
8271 .local_metadata => "%",8281 .local_metadata => .{ .percent = true },
8272 else => unreachable,8282 else => unreachable,
8273 }),8283 },
8284 }, w),
8274 inline .local_inline, .local_index => |node, tag| {8285 inline .local_inline, .local_index => |node, tag| {
8275 if (comptime std.mem.eql(u8, recurse_fmt_str, "%"))8286 if (data.specialized) |flags| {
8276 try w.print("{f%} ", .{Type.metadata.fmt(builder)});8287 if (flags.onlyPercent()) {
8288 try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)});
8289 }
8290 }
8277 try format(.{8291 try format(.{
8278 .formatter = data.formatter,8292 .formatter = data.formatter,
8279 .node = @unionInit(FormatData.Node, @tagName(tag)["local_".len..], node),8293 .node = @unionInit(FormatData.Node, @tagName(tag)["local_".len..], node),
8280 }, w, "%");8294 .specialized = .{ .percent = true },
8295 }, w);
8281 },8296 },
8282 .string => |node| try w.print((if (is_specialized) "" else "!") ++ "{f}", .{8297 .string => |node| try w.print("{s}{f}", .{
8283 node.fmt(builder),8298 @as([]const u8, if (is_specialized) "" else "!"), node.fmt(builder),
8284 }),8299 }),
8285 inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),8300 inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),
8286 inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),8301 inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),
8287 .raw => |node| try w.writeAll(node),8302 .raw => |node| try w.writeAll(node),
8288 }8303 }
8289 }8304 }
8290 inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype) switch (@TypeOf(node)) {8305 inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) {
8291 Metadata => Allocator.Error,8306 Metadata => Allocator.Error,
8292 else => error{},8307 else => error{},
8293 }!std.fmt.Formatter(FormatData, format) {8308 }!std.fmt.Formatter(FormatData, format) {
...@@ -8327,6 +8342,7 @@ pub const Metadata = enum(u32) {...@@ -8327,6 +8342,7 @@ pub const Metadata = enum(u32) {
8327 .optional, .null => .none,8342 .optional, .null => .none,
8328 else => unreachable,8343 else => unreachable,
8329 },8344 },
8345 .specialized = special,
8330 } };8346 } };
8331 }8347 }
8332 inline fn fmtLocal(8348 inline fn fmtLocal(
...@@ -8359,6 +8375,7 @@ pub const Metadata = enum(u32) {...@@ -8359,6 +8375,7 @@ pub const Metadata = enum(u32) {
8359 };8375 };
8360 },8376 },
8361 },8377 },
8378 .specialized = null,
8362 } };8379 } };
8363 }8380 }
8364 fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {8381 fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {
...@@ -8437,6 +8454,7 @@ pub const Metadata = enum(u32) {...@@ -8437,6 +8454,7 @@ pub const Metadata = enum(u32) {
8437 inline for (names) |name| @field(fmt_args, name) = try formatter.fmt(8454 inline for (names) |name| @field(fmt_args, name) = try formatter.fmt(
8438 name ++ ": ",8455 name ++ ": ",
8439 @field(nodes, name),8456 @field(nodes, name),
8457 null,
8440 );8458 );
8441 try w.print(fmt_str, fmt_args);8459 try w.print(fmt_str, fmt_args);
8442 }8460 }
...@@ -8965,7 +8983,7 @@ pub fn getIntrinsic(...@@ -8965,7 +8983,7 @@ pub fn getIntrinsic(
8965 const w = &aw.writer;8983 const w = &aw.writer;
8966 defer self.strtab_string_bytes = aw.toArrayList();8984 defer self.strtab_string_bytes = aw.toArrayList();
8967 w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;8985 w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;
8968 for (overload) |ty| w.print(".{fm}", .{ty.fmt(self)}) catch return error.OutOfMemory;8986 for (overload) |ty| w.print(".{f}", .{ty.fmt(self, .m)}) catch return error.OutOfMemory;
8969 }8987 }
8970 break :name try self.trailingStrtabString();8988 break :name try self.trailingStrtabString();
8971 };8989 };
...@@ -9399,7 +9417,7 @@ pub fn printToFile(b: *Builder, file: std.fs.File, buffer: []u8) !void {...@@ -9399,7 +9417,7 @@ pub fn printToFile(b: *Builder, file: std.fs.File, buffer: []u8) !void {
9399 try fw.interface.flush();9417 try fw.interface.flush();
9400}9418}
94019419
9402pub fn print(self: *Builder, w: *Writer) Writer.Error!void {9420pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void {
9403 var need_newline = false;9421 var need_newline = false;
9404 var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined };9422 var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined };
9405 defer metadata_formatter.map.deinit(self.gpa);9423 defer metadata_formatter.map.deinit(self.gpa);
...@@ -9408,17 +9426,17 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9408,17 +9426,17 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9408 if (need_newline) try w.writeByte('\n') else need_newline = true;9426 if (need_newline) try w.writeByte('\n') else need_newline = true;
9409 if (self.source_filename != .none) try w.print(9427 if (self.source_filename != .none) try w.print(
9410 \\; ModuleID = '{s}'9428 \\; ModuleID = '{s}'
9411 \\source_filename = {f"}9429 \\source_filename = {f}
9412 \\9430 \\
9413 , .{ self.source_filename.slice(self).?, self.source_filename.fmt(self) });9431 , .{ self.source_filename.slice(self).?, self.source_filename.fmtQ(self) });
9414 if (self.data_layout != .none) try w.print(9432 if (self.data_layout != .none) try w.print(
9415 \\target datalayout = {f"}9433 \\target datalayout = {f}
9416 \\9434 \\
9417 , .{self.data_layout.fmt(self)});9435 , .{self.data_layout.fmtQ(self)});
9418 if (self.target_triple != .none) try w.print(9436 if (self.target_triple != .none) try w.print(
9419 \\target triple = {f"}9437 \\target triple = {f}
9420 \\9438 \\
9421 , .{self.target_triple.fmt(self)});9439 , .{self.target_triple.fmtQ(self)});
9422 }9440 }
94239441
9424 if (self.module_asm.items.len > 0) {9442 if (self.module_asm.items.len > 0) {
...@@ -9436,7 +9454,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9436,7 +9454,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9436 for (self.types.keys(), self.types.values()) |id, ty| try w.print(9454 for (self.types.keys(), self.types.values()) |id, ty| try w.print(
9437 \\%{f} = type {f}9455 \\%{f} = type {f}
9438 \\9456 \\
9439 , .{ id.fmt(self), ty.fmt(self) });9457 , .{ id.fmt(self), ty.fmt(self, .default) });
9440 }9458 }
94419459
9442 if (self.variables.items.len > 0) {9460 if (self.variables.items.len > 0) {
...@@ -9447,7 +9465,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9447,7 +9465,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9447 metadata_formatter.need_comma = true;9465 metadata_formatter.need_comma = true;
9448 defer metadata_formatter.need_comma = undefined;9466 defer metadata_formatter.need_comma = undefined;
9449 try w.print(9467 try w.print(
9450 \\{f} ={f}{f}{f}{f}{f }{f}{f }{f} {s} {f%}{f }{f, }{f}9468 \\{f} ={f}{f}{f}{f}{f }{f}{f }{f} {s} {f}{f}{f, }{f}
9451 \\9469 \\
9452 , .{9470 , .{
9453 variable.global.fmt(self),9471 variable.global.fmt(self),
...@@ -9461,10 +9479,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9461,10 +9479,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9461 global.addr_space,9479 global.addr_space,
9462 global.externally_initialized,9480 global.externally_initialized,
9463 @tagName(variable.mutability),9481 @tagName(variable.mutability),
9464 global.type.fmt(self),9482 global.type.fmt(self, .percent),
9465 variable.init.fmt(self),9483 variable.init.fmt(self, .{ .space = true }),
9466 variable.alignment,9484 variable.alignment,
9467 try metadata_formatter.fmt("!dbg ", global.dbg),9485 try metadata_formatter.fmt("!dbg ", global.dbg, null),
9468 });9486 });
9469 }9487 }
9470 }9488 }
...@@ -9477,7 +9495,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9477,7 +9495,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9477 metadata_formatter.need_comma = true;9495 metadata_formatter.need_comma = true;
9478 defer metadata_formatter.need_comma = undefined;9496 defer metadata_formatter.need_comma = undefined;
9479 try w.print(9497 try w.print(
9480 \\{f} ={f}{f}{f}{f}{f }{f} alias {f%}, {f%}{f}9498 \\{f} ={f}{f}{f}{f}{f }{f} alias {f}, {f}{f}
9481 \\9499 \\
9482 , .{9500 , .{
9483 alias.global.fmt(self),9501 alias.global.fmt(self),
...@@ -9487,9 +9505,9 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9487,9 +9505,9 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9487 global.dll_storage_class,9505 global.dll_storage_class,
9488 alias.thread_local,9506 alias.thread_local,
9489 global.unnamed_addr,9507 global.unnamed_addr,
9490 global.type.fmt(self),9508 global.type.fmt(self, .percent),
9491 alias.aliasee.fmt(self),9509 alias.aliasee.fmt(self, .{ .percent = true }),
9492 try metadata_formatter.fmt("!dbg ", global.dbg),9510 try metadata_formatter.fmt("!dbg ", global.dbg, null),
9493 });9511 });
9494 }9512 }
9495 }9513 }
...@@ -9509,7 +9527,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9509,7 +9527,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9509 \\9527 \\
9510 , .{function_attributes.fmt(self)});9528 , .{function_attributes.fmt(self)});
9511 try w.print(9529 try w.print(
9512 \\{s}{f}{f}{f}{f}{f}{f"} {f%} {f}(9530 \\{s}{f}{f}{f}{f}{f}{f} {f} {f}(
9513 , .{9531 , .{
9514 if (function.instructions.len > 0) "define" else "declare",9532 if (function.instructions.len > 0) "define" else "declare",
9515 global.linkage,9533 global.linkage,
...@@ -9518,19 +9536,19 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9518,19 +9536,19 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9518 global.dll_storage_class,9536 global.dll_storage_class,
9519 function.call_conv,9537 function.call_conv,
9520 function.attributes.ret(self).fmt(self),9538 function.attributes.ret(self).fmt(self),
9521 global.type.functionReturn(self).fmt(self),9539 global.type.functionReturn(self).fmt(self, .percent),
9522 function.global.fmt(self),9540 function.global.fmt(self),
9523 });9541 });
9524 for (0..params_len) |arg| {9542 for (0..params_len) |arg| {
9525 if (arg > 0) try w.writeAll(", ");9543 if (arg > 0) try w.writeAll(", ");
9526 try w.print(9544 try w.print(
9527 \\{f%}{f"}9545 \\{f}{f}
9528 , .{9546 , .{
9529 global.type.functionParameters(self)[arg].fmt(self),9547 global.type.functionParameters(self)[arg].fmt(self, .percent),
9530 function.attributes.param(arg, self).fmt(self),9548 function.attributes.param(arg, self).fmt(self),
9531 });9549 });
9532 if (function.instructions.len > 0)9550 if (function.instructions.len > 0)
9533 try w.print(" {f}", .{function.arg(@intCast(arg)).fmt(function_index, self)})9551 try w.print(" {f}", .{function.arg(@intCast(arg)).fmt(function_index, self, .{})})
9534 else9552 else
9535 try w.print(" %{d}", .{arg});9553 try w.print(" %{d}", .{arg});
9536 }9554 }
...@@ -9550,7 +9568,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9550,7 +9568,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9550 defer metadata_formatter.need_comma = undefined;9568 defer metadata_formatter.need_comma = undefined;
9551 try w.print("{f }{f}", .{9569 try w.print("{f }{f}", .{
9552 function.alignment,9570 function.alignment,
9553 try metadata_formatter.fmt(" !dbg ", global.dbg),9571 try metadata_formatter.fmt(" !dbg ", global.dbg, null),
9554 });9572 });
9555 }9573 }
9556 if (function.instructions.len > 0) {9574 if (function.instructions.len > 0) {
...@@ -9653,11 +9671,11 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9653,11 +9671,11 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9653 .xor,9671 .xor,
9654 => |tag| {9672 => |tag| {
9655 const extra = function.extraData(Function.Instruction.Binary, instruction.data);9673 const extra = function.extraData(Function.Instruction.Binary, instruction.data);
9656 try w.print(" %{f} = {s} {f%}, {f}", .{9674 try w.print(" %{f} = {s} {f}, {f}", .{
9657 instruction_index.name(&function).fmt(self),9675 instruction_index.name(&function).fmt(self),
9658 @tagName(tag),9676 @tagName(tag),
9659 extra.lhs.fmt(function_index, self),9677 extra.lhs.fmt(function_index, self, .{ .percent = true }),
9660 extra.rhs.fmt(function_index, self),9678 extra.rhs.fmt(function_index, self, .{ .percent = true }),
9661 });9679 });
9662 },9680 },
9663 .addrspacecast,9681 .addrspacecast,
...@@ -9675,25 +9693,28 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9675,25 +9693,28 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9675 .zext,9693 .zext,
9676 => |tag| {9694 => |tag| {
9677 const extra = function.extraData(Function.Instruction.Cast, instruction.data);9695 const extra = function.extraData(Function.Instruction.Cast, instruction.data);
9678 try w.print(" %{f} = {s} {f%} to {f%}", .{9696 try w.print(" %{f} = {s} {f} to {f}", .{
9679 instruction_index.name(&function).fmt(self),9697 instruction_index.name(&function).fmt(self),
9680 @tagName(tag),9698 @tagName(tag),
9681 extra.val.fmt(function_index, self),9699 extra.val.fmt(function_index, self, .{ .percent = true }),
9682 extra.type.fmt(self),9700 extra.type.fmt(self, .percent),
9683 });9701 });
9684 },9702 },
9685 .alloca,9703 .alloca,
9686 .@"alloca inalloca",9704 .@"alloca inalloca",
9687 => |tag| {9705 => |tag| {
9688 const extra = function.extraData(Function.Instruction.Alloca, instruction.data);9706 const extra = function.extraData(Function.Instruction.Alloca, instruction.data);
9689 try w.print(" %{f} = {s} {f%}{f,%}{f, }{f, }", .{9707 try w.print(" %{f} = {s} {f}{f}{f, }{f, }", .{
9690 instruction_index.name(&function).fmt(self),9708 instruction_index.name(&function).fmt(self),
9691 @tagName(tag),9709 @tagName(tag),
9692 extra.type.fmt(self),9710 extra.type.fmt(self, .percent),
9693 Value.fmt(switch (extra.len) {9711 Value.fmt(switch (extra.len) {
9694 .@"1" => .none,9712 .@"1" => .none,
9695 else => extra.len,9713 else => extra.len,
9696 }, function_index, self),9714 }, function_index, self, .{
9715 .comma = true,
9716 .percent = true,
9717 }),
9697 extra.info.alignment,9718 extra.info.alignment,
9698 extra.info.addr_space,9719 extra.info.addr_space,
9699 });9720 });
...@@ -9702,13 +9723,13 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9702,13 +9723,13 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9702 .atomicrmw => |tag| {9723 .atomicrmw => |tag| {
9703 const extra =9724 const extra =
9704 function.extraData(Function.Instruction.AtomicRmw, instruction.data);9725 function.extraData(Function.Instruction.AtomicRmw, instruction.data);
9705 try w.print(" %{f} = {s}{f } {s} {f%}, {f%}{f }{f }{f, }", .{9726 try w.print(" %{f} = {s}{f } {s} {f}, {f}{f }{f }{f, }", .{
9706 instruction_index.name(&function).fmt(self),9727 instruction_index.name(&function).fmt(self),
9707 @tagName(tag),9728 @tagName(tag),
9708 extra.info.access_kind,9729 extra.info.access_kind,
9709 @tagName(extra.info.atomic_rmw_operation),9730 @tagName(extra.info.atomic_rmw_operation),
9710 extra.ptr.fmt(function_index, self),9731 extra.ptr.fmt(function_index, self, .{ .percent = true }),
9711 extra.val.fmt(function_index, self),9732 extra.val.fmt(function_index, self, .{ .percent = true }),
9712 extra.info.sync_scope,9733 extra.info.sync_scope,
9713 extra.info.success_ordering,9734 extra.info.success_ordering,
9714 extra.info.alignment,9735 extra.info.alignment,
...@@ -9724,16 +9745,16 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9724,16 +9745,16 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9724 },9745 },
9725 .br => |tag| {9746 .br => |tag| {
9726 const target: Function.Block.Index = @enumFromInt(instruction.data);9747 const target: Function.Block.Index = @enumFromInt(instruction.data);
9727 try w.print(" {s} {f%}", .{9748 try w.print(" {s} {f}", .{
9728 @tagName(tag), target.toInst(&function).fmt(function_index, self),9749 @tagName(tag), target.toInst(&function).fmt(function_index, self, .{ .percent = true }),
9729 });9750 });
9730 },9751 },
9731 .br_cond => {9752 .br_cond => {
9732 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);9753 const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
9733 try w.print(" br {f%}, {f%}, {f%}", .{9754 try w.print(" br {f}, {f}, {f}", .{
9734 extra.cond.fmt(function_index, self),9755 extra.cond.fmt(function_index, self, .{ .percent = true }),
9735 extra.then.toInst(&function).fmt(function_index, self),9756 extra.then.toInst(&function).fmt(function_index, self, .{ .percent = true }),
9736 extra.@"else".toInst(&function).fmt(function_index, self),9757 extra.@"else".toInst(&function).fmt(function_index, self, .{ .percent = true }),
9737 });9758 });
9738 metadata_formatter.need_comma = true;9759 metadata_formatter.need_comma = true;
9739 defer metadata_formatter.need_comma = undefined;9760 defer metadata_formatter.need_comma = undefined;
...@@ -9741,7 +9762,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9741,7 +9762,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9741 .none => {},9762 .none => {},
9742 .unpredictable => try w.writeAll("!unpredictable !{}"),9763 .unpredictable => try w.writeAll("!unpredictable !{}"),
9743 _ => try w.print("{f}", .{9764 _ => try w.print("{f}", .{
9744 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.weights)))),9765 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.weights))), null),
9745 }),9766 }),
9746 }9767 }
9747 },9768 },
...@@ -9766,7 +9787,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9766,7 +9787,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9766 }),9787 }),
9767 .none => unreachable,9788 .none => unreachable,
9768 }9789 }
9769 try w.print("{s}{f}{f}{f} {f%} {f}(", .{9790 try w.print("{s}{f}{f}{f} {f} {f}(", .{
9770 @tagName(tag),9791 @tagName(tag),
9771 extra.data.info.call_conv,9792 extra.data.info.call_conv,
9772 extra.data.attributes.ret(self).fmt(self),9793 extra.data.attributes.ret(self).fmt(self),
...@@ -9774,15 +9795,15 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9774,15 +9795,15 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9774 switch (extra.data.ty.functionKind(self)) {9795 switch (extra.data.ty.functionKind(self)) {
9775 .normal => ret_ty,9796 .normal => ret_ty,
9776 .vararg => extra.data.ty,9797 .vararg => extra.data.ty,
9777 }.fmt(self),9798 }.fmt(self, .percent),
9778 extra.data.callee.fmt(function_index, self),9799 extra.data.callee.fmt(function_index, self, .{}),
9779 });9800 });
9780 for (0.., args) |arg_index, arg| {9801 for (0.., args) |arg_index, arg| {
9781 if (arg_index > 0) try w.writeAll(", ");9802 if (arg_index > 0) try w.writeAll(", ");
9782 metadata_formatter.need_comma = false;9803 metadata_formatter.need_comma = false;
9783 defer metadata_formatter.need_comma = undefined;9804 defer metadata_formatter.need_comma = undefined;
9784 try w.print("{f%}{f}{f}", .{9805 try w.print("{f}{f}{f}", .{
9785 arg.typeOf(function_index, self).fmt(self),9806 arg.typeOf(function_index, self).fmt(self, .percent),
9786 extra.data.attributes.param(arg_index, self).fmt(self),9807 extra.data.attributes.param(arg_index, self).fmt(self),
9787 try metadata_formatter.fmtLocal(" ", arg, function_index),9808 try metadata_formatter.fmtLocal(" ", arg, function_index),
9788 });9809 });
...@@ -9805,13 +9826,13 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9805,13 +9826,13 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9805 => |tag| {9826 => |tag| {
9806 const extra =9827 const extra =
9807 function.extraData(Function.Instruction.CmpXchg, instruction.data);9828 function.extraData(Function.Instruction.CmpXchg, instruction.data);
9808 try w.print(" %{f} = {s}{f } {f%}, {f%}, {f%}{f }{f }{f }{f, }", .{9829 try w.print(" %{f} = {s}{f } {f}, {f}, {f}{f }{f }{f }{f, }", .{
9809 instruction_index.name(&function).fmt(self),9830 instruction_index.name(&function).fmt(self),
9810 @tagName(tag),9831 @tagName(tag),
9811 extra.info.access_kind,9832 extra.info.access_kind,
9812 extra.ptr.fmt(function_index, self),9833 extra.ptr.fmt(function_index, self, .{ .percent = true }),
9813 extra.cmp.fmt(function_index, self),9834 extra.cmp.fmt(function_index, self, .{ .percent = true }),
9814 extra.new.fmt(function_index, self),9835 extra.new.fmt(function_index, self, .{ .percent = true }),
9815 extra.info.sync_scope,9836 extra.info.sync_scope,
9816 extra.info.success_ordering,9837 extra.info.success_ordering,
9817 extra.info.failure_ordering,9838 extra.info.failure_ordering,
...@@ -9821,11 +9842,11 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9821,11 +9842,11 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9821 .extractelement => |tag| {9842 .extractelement => |tag| {
9822 const extra =9843 const extra =
9823 function.extraData(Function.Instruction.ExtractElement, instruction.data);9844 function.extraData(Function.Instruction.ExtractElement, instruction.data);
9824 try w.print(" %{f} = {s} {f%}, {f%}", .{9845 try w.print(" %{f} = {s} {f}, {f}", .{
9825 instruction_index.name(&function).fmt(self),9846 instruction_index.name(&function).fmt(self),
9826 @tagName(tag),9847 @tagName(tag),
9827 extra.val.fmt(function_index, self),9848 extra.val.fmt(function_index, self, .{ .percent = true }),
9828 extra.index.fmt(function_index, self),9849 extra.index.fmt(function_index, self, .{ .percent = true }),
9829 });9850 });
9830 },9851 },
9831 .extractvalue => |tag| {9852 .extractvalue => |tag| {
...@@ -9834,10 +9855,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9834,10 +9855,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9834 instruction.data,9855 instruction.data,
9835 );9856 );
9836 const indices = extra.trail.next(extra.data.indices_len, u32, &function);9857 const indices = extra.trail.next(extra.data.indices_len, u32, &function);
9837 try w.print(" %{f} = {s} {f%}", .{9858 try w.print(" %{f} = {s} {f}", .{
9838 instruction_index.name(&function).fmt(self),9859 instruction_index.name(&function).fmt(self),
9839 @tagName(tag),9860 @tagName(tag),
9840 extra.data.val.fmt(function_index, self),9861 extra.data.val.fmt(function_index, self, .{ .percent = true }),
9841 });9862 });
9842 for (indices) |index| try w.print(", {d}", .{index});9863 for (indices) |index| try w.print(", {d}", .{index});
9843 },9864 },
...@@ -9853,10 +9874,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9853,10 +9874,10 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9853 .@"fneg fast",9874 .@"fneg fast",
9854 => |tag| {9875 => |tag| {
9855 const val: Value = @enumFromInt(instruction.data);9876 const val: Value = @enumFromInt(instruction.data);
9856 try w.print(" %{f} = {s} {f%}", .{9877 try w.print(" %{f} = {s} {f}", .{
9857 instruction_index.name(&function).fmt(self),9878 instruction_index.name(&function).fmt(self),
9858 @tagName(tag),9879 @tagName(tag),
9859 val.fmt(function_index, self),9880 val.fmt(function_index, self, .{ .percent = true }),
9860 });9881 });
9861 },9882 },
9862 .getelementptr,9883 .getelementptr,
...@@ -9867,14 +9888,14 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9867,14 +9888,14 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9867 instruction.data,9888 instruction.data,
9868 );9889 );
9869 const indices = extra.trail.next(extra.data.indices_len, Value, &function);9890 const indices = extra.trail.next(extra.data.indices_len, Value, &function);
9870 try w.print(" %{f} = {s} {f%}, {f%}", .{9891 try w.print(" %{f} = {s} {f}, {f}", .{
9871 instruction_index.name(&function).fmt(self),9892 instruction_index.name(&function).fmt(self),
9872 @tagName(tag),9893 @tagName(tag),
9873 extra.data.type.fmt(self),9894 extra.data.type.fmt(self, .percent),
9874 extra.data.base.fmt(function_index, self),9895 extra.data.base.fmt(function_index, self, .{ .percent = true }),
9875 });9896 });
9876 for (indices) |index| try w.print(", {f%}", .{9897 for (indices) |index| try w.print(", {f}", .{
9877 index.fmt(function_index, self),9898 index.fmt(function_index, self, .{ .percent = true }),
9878 });9899 });
9879 },9900 },
9880 .indirectbr => |tag| {9901 .indirectbr => |tag| {
...@@ -9882,14 +9903,14 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9882,14 +9903,14 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9882 function.extraDataTrail(Function.Instruction.IndirectBr, instruction.data);9903 function.extraDataTrail(Function.Instruction.IndirectBr, instruction.data);
9883 const targets =9904 const targets =
9884 extra.trail.next(extra.data.targets_len, Function.Block.Index, &function);9905 extra.trail.next(extra.data.targets_len, Function.Block.Index, &function);
9885 try w.print(" {s} {f%}, [", .{9906 try w.print(" {s} {f}, [", .{
9886 @tagName(tag),9907 @tagName(tag),
9887 extra.data.addr.fmt(function_index, self),9908 extra.data.addr.fmt(function_index, self, .{ .percent = true }),
9888 });9909 });
9889 for (0.., targets) |target_index, target| {9910 for (0.., targets) |target_index, target| {
9890 if (target_index > 0) try w.writeAll(", ");9911 if (target_index > 0) try w.writeAll(", ");
9891 try w.print("{f%}", .{9912 try w.print("{f}", .{
9892 target.toInst(&function).fmt(function_index, self),9913 target.toInst(&function).fmt(function_index, self, .{ .percent = true }),
9893 });9914 });
9894 }9915 }
9895 try w.writeByte(']');9916 try w.writeByte(']');
...@@ -9897,23 +9918,23 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9897,23 +9918,23 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9897 .insertelement => |tag| {9918 .insertelement => |tag| {
9898 const extra =9919 const extra =
9899 function.extraData(Function.Instruction.InsertElement, instruction.data);9920 function.extraData(Function.Instruction.InsertElement, instruction.data);
9900 try w.print(" %{f} = {s} {f%}, {f%}, {f%}", .{9921 try w.print(" %{f} = {s} {f}, {f}, {f}", .{
9901 instruction_index.name(&function).fmt(self),9922 instruction_index.name(&function).fmt(self),
9902 @tagName(tag),9923 @tagName(tag),
9903 extra.val.fmt(function_index, self),9924 extra.val.fmt(function_index, self, .{ .percent = true }),
9904 extra.elem.fmt(function_index, self),9925 extra.elem.fmt(function_index, self, .{ .percent = true }),
9905 extra.index.fmt(function_index, self),9926 extra.index.fmt(function_index, self, .{ .percent = true }),
9906 });9927 });
9907 },9928 },
9908 .insertvalue => |tag| {9929 .insertvalue => |tag| {
9909 var extra =9930 var extra =
9910 function.extraDataTrail(Function.Instruction.InsertValue, instruction.data);9931 function.extraDataTrail(Function.Instruction.InsertValue, instruction.data);
9911 const indices = extra.trail.next(extra.data.indices_len, u32, &function);9932 const indices = extra.trail.next(extra.data.indices_len, u32, &function);
9912 try w.print(" %{f} = {s} {f%}, {f%}", .{9933 try w.print(" %{f} = {s} {f}, {f}", .{
9913 instruction_index.name(&function).fmt(self),9934 instruction_index.name(&function).fmt(self),
9914 @tagName(tag),9935 @tagName(tag),
9915 extra.data.val.fmt(function_index, self),9936 extra.data.val.fmt(function_index, self, .{ .percent = true }),
9916 extra.data.elem.fmt(function_index, self),9937 extra.data.elem.fmt(function_index, self, .{ .percent = true }),
9917 });9938 });
9918 for (indices) |index| try w.print(", {d}", .{index});9939 for (indices) |index| try w.print(", {d}", .{index});
9919 },9940 },
...@@ -9921,12 +9942,12 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9921,12 +9942,12 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9921 .@"load atomic",9942 .@"load atomic",
9922 => |tag| {9943 => |tag| {
9923 const extra = function.extraData(Function.Instruction.Load, instruction.data);9944 const extra = function.extraData(Function.Instruction.Load, instruction.data);
9924 try w.print(" %{f} = {s}{f } {f%}, {f%}{f }{f }{f, }", .{9945 try w.print(" %{f} = {s}{f } {f}, {f}{f }{f }{f, }", .{
9925 instruction_index.name(&function).fmt(self),9946 instruction_index.name(&function).fmt(self),
9926 @tagName(tag),9947 @tagName(tag),
9927 extra.info.access_kind,9948 extra.info.access_kind,
9928 extra.type.fmt(self),9949 extra.type.fmt(self, .percent),
9929 extra.ptr.fmt(function_index, self),9950 extra.ptr.fmt(function_index, self, .{ .percent = true }),
9930 extra.info.sync_scope,9951 extra.info.sync_scope,
9931 extra.info.success_ordering,9952 extra.info.success_ordering,
9932 extra.info.alignment,9953 extra.info.alignment,
...@@ -9939,24 +9960,24 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9939,24 +9960,24 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9939 const vals = extra.trail.next(block_incoming_len, Value, &function);9960 const vals = extra.trail.next(block_incoming_len, Value, &function);
9940 const blocks =9961 const blocks =
9941 extra.trail.next(block_incoming_len, Function.Block.Index, &function);9962 extra.trail.next(block_incoming_len, Function.Block.Index, &function);
9942 try w.print(" %{f} = {s} {f%} ", .{9963 try w.print(" %{f} = {s} {f} ", .{
9943 instruction_index.name(&function).fmt(self),9964 instruction_index.name(&function).fmt(self),
9944 @tagName(tag),9965 @tagName(tag),
9945 vals[0].typeOf(function_index, self).fmt(self),9966 vals[0].typeOf(function_index, self).fmt(self, .percent),
9946 });9967 });
9947 for (0.., vals, blocks) |incoming_index, incoming_val, incoming_block| {9968 for (0.., vals, blocks) |incoming_index, incoming_val, incoming_block| {
9948 if (incoming_index > 0) try w.writeAll(", ");9969 if (incoming_index > 0) try w.writeAll(", ");
9949 try w.print("[ {f}, {f} ]", .{9970 try w.print("[ {f}, {f} ]", .{
9950 incoming_val.fmt(function_index, self),9971 incoming_val.fmt(function_index, self, .{}),
9951 incoming_block.toInst(&function).fmt(function_index, self),9972 incoming_block.toInst(&function).fmt(function_index, self, .{}),
9952 });9973 });
9953 }9974 }
9954 },9975 },
9955 .ret => |tag| {9976 .ret => |tag| {
9956 const val: Value = @enumFromInt(instruction.data);9977 const val: Value = @enumFromInt(instruction.data);
9957 try w.print(" {s} {f%}", .{9978 try w.print(" {s} {f}", .{
9958 @tagName(tag),9979 @tagName(tag),
9959 val.fmt(function_index, self),9980 val.fmt(function_index, self, .{ .percent = true }),
9960 });9981 });
9961 },9982 },
9962 .@"ret void",9983 .@"ret void",
...@@ -9966,34 +9987,34 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -9966,34 +9987,34 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
9966 .@"select fast",9987 .@"select fast",
9967 => |tag| {9988 => |tag| {
9968 const extra = function.extraData(Function.Instruction.Select, instruction.data);9989 const extra = function.extraData(Function.Instruction.Select, instruction.data);
9969 try w.print(" %{f} = {s} {f%}, {f%}, {f%}", .{9990 try w.print(" %{f} = {s} {f}, {f}, {f}", .{
9970 instruction_index.name(&function).fmt(self),9991 instruction_index.name(&function).fmt(self),
9971 @tagName(tag),9992 @tagName(tag),
9972 extra.cond.fmt(function_index, self),9993 extra.cond.fmt(function_index, self, .{ .percent = true }),
9973 extra.lhs.fmt(function_index, self),9994 extra.lhs.fmt(function_index, self, .{ .percent = true }),
9974 extra.rhs.fmt(function_index, self),9995 extra.rhs.fmt(function_index, self, .{ .percent = true }),
9975 });9996 });
9976 },9997 },
9977 .shufflevector => |tag| {9998 .shufflevector => |tag| {
9978 const extra =9999 const extra =
9979 function.extraData(Function.Instruction.ShuffleVector, instruction.data);10000 function.extraData(Function.Instruction.ShuffleVector, instruction.data);
9980 try w.print(" %{f} = {s} {f%}, {f%}, {f%}", .{10001 try w.print(" %{f} = {s} {f}, {f}, {f}", .{
9981 instruction_index.name(&function).fmt(self),10002 instruction_index.name(&function).fmt(self),
9982 @tagName(tag),10003 @tagName(tag),
9983 extra.lhs.fmt(function_index, self),10004 extra.lhs.fmt(function_index, self, .{ .percent = true }),
9984 extra.rhs.fmt(function_index, self),10005 extra.rhs.fmt(function_index, self, .{ .percent = true }),
9985 extra.mask.fmt(function_index, self),10006 extra.mask.fmt(function_index, self, .{ .percent = true }),
9986 });10007 });
9987 },10008 },
9988 .store,10009 .store,
9989 .@"store atomic",10010 .@"store atomic",
9990 => |tag| {10011 => |tag| {
9991 const extra = function.extraData(Function.Instruction.Store, instruction.data);10012 const extra = function.extraData(Function.Instruction.Store, instruction.data);
9992 try w.print(" {s}{f } {f%}, {f%}{f }{f }{f, }", .{10013 try w.print(" {s}{f } {f}, {f}{f }{f }{f, }", .{
9993 @tagName(tag),10014 @tagName(tag),
9994 extra.info.access_kind,10015 extra.info.access_kind,
9995 extra.val.fmt(function_index, self),10016 extra.val.fmt(function_index, self, .{ .percent = true }),
9996 extra.ptr.fmt(function_index, self),10017 extra.ptr.fmt(function_index, self, .{ .percent = true }),
9997 extra.info.sync_scope,10018 extra.info.sync_scope,
9998 extra.info.success_ordering,10019 extra.info.success_ordering,
9999 extra.info.alignment,10020 extra.info.alignment,
...@@ -10005,16 +10026,16 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -10005,16 +10026,16 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
10005 const vals = extra.trail.next(extra.data.cases_len, Constant, &function);10026 const vals = extra.trail.next(extra.data.cases_len, Constant, &function);
10006 const blocks =10027 const blocks =
10007 extra.trail.next(extra.data.cases_len, Function.Block.Index, &function);10028 extra.trail.next(extra.data.cases_len, Function.Block.Index, &function);
10008 try w.print(" {s} {f%}, {f%} [\n", .{10029 try w.print(" {s} {f}, {f} [\n", .{
10009 @tagName(tag),10030 @tagName(tag),
10010 extra.data.val.fmt(function_index, self),10031 extra.data.val.fmt(function_index, self, .{ .percent = true }),
10011 extra.data.default.toInst(&function).fmt(function_index, self),10032 extra.data.default.toInst(&function).fmt(function_index, self, .{ .percent = true }),
10012 });10033 });
10013 for (vals, blocks) |case_val, case_block| try w.print(10034 for (vals, blocks) |case_val, case_block| try w.print(
10014 " {f%}, {f%}\n",10035 " {f}, {f}\n",
10015 .{10036 .{
10016 case_val.fmt(self),10037 case_val.fmt(self, .{ .percent = true }),
10017 case_block.toInst(&function).fmt(function_index, self),10038 case_block.toInst(&function).fmt(function_index, self, .{ .percent = true }),
10018 },10039 },
10019 );10040 );
10020 try w.writeAll(" ]");10041 try w.writeAll(" ]");
...@@ -10024,17 +10045,17 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -10024,17 +10045,17 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
10024 .none => {},10045 .none => {},
10025 .unpredictable => try w.writeAll("!unpredictable !{}"),10046 .unpredictable => try w.writeAll("!unpredictable !{}"),
10026 _ => try w.print("{f}", .{10047 _ => try w.print("{f}", .{
10027 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.data.weights)))),10048 try metadata_formatter.fmt("!prof ", @as(Metadata, @enumFromInt(@intFromEnum(extra.data.weights))), null),
10028 }),10049 }),
10029 }10050 }
10030 },10051 },
10031 .va_arg => |tag| {10052 .va_arg => |tag| {
10032 const extra = function.extraData(Function.Instruction.VaArg, instruction.data);10053 const extra = function.extraData(Function.Instruction.VaArg, instruction.data);
10033 try w.print(" %{f} = {s} {f%}, {f%}", .{10054 try w.print(" %{f} = {s} {f}, {f}", .{
10034 instruction_index.name(&function).fmt(self),10055 instruction_index.name(&function).fmt(self),
10035 @tagName(tag),10056 @tagName(tag),
10036 extra.list.fmt(function_index, self),10057 extra.list.fmt(function_index, self, .{ .percent = true }),
10037 extra.type.fmt(self),10058 extra.type.fmt(self, .percent),
10038 });10059 });
10039 },10060 },
10040 }10061 }
...@@ -10068,7 +10089,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -10068,7 +10089,7 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
10068 try w.writeAll(" = !{");10089 try w.writeAll(" = !{");
10069 metadata_formatter.need_comma = false;10090 metadata_formatter.need_comma = false;
10070 defer metadata_formatter.need_comma = undefined;10091 defer metadata_formatter.need_comma = undefined;
10071 for (elements) |element| try w.print("{f}", .{try metadata_formatter.fmt("", element)});10092 for (elements) |element| try w.print("{f}", .{try metadata_formatter.fmt("", element, null)});
10072 try w.writeAll("}\n");10093 try w.writeAll("}\n");
10073 }10094 }
10074 }10095 }
...@@ -10371,28 +10392,28 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {...@@ -10371,28 +10392,28 @@ pub fn print(self: *Builder, w: *Writer) Writer.Error!void {
10371 var extra = self.metadataExtraDataTrail(Metadata.Tuple, metadata_item.data);10392 var extra = self.metadataExtraDataTrail(Metadata.Tuple, metadata_item.data);
10372 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);10393 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
10373 try w.writeAll("!{");10394 try w.writeAll("!{");
10374 for (elements) |element| try w.print("{[element]f%}", .{10395 for (elements) |element| try w.print("{[element]f}", .{
10375 .element = try metadata_formatter.fmt("", element),10396 .element = try metadata_formatter.fmt("", element, .{ .percent = true }),
10376 });10397 });
10377 try w.writeAll("}\n");10398 try w.writeAll("}\n");
10378 },10399 },
10379 .str_tuple => {10400 .str_tuple => {
10380 var extra = self.metadataExtraDataTrail(Metadata.StrTuple, metadata_item.data);10401 var extra = self.metadataExtraDataTrail(Metadata.StrTuple, metadata_item.data);
10381 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);10402 const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
10382 try w.print("!{{{[str]f%}", .{10403 try w.print("!{{{[str]f}", .{
10383 .str = try metadata_formatter.fmt("", extra.data.str),10404 .str = try metadata_formatter.fmt("", extra.data.str, .{ .percent = true }),
10384 });10405 });
10385 for (elements) |element| try w.print("{[element]f%}", .{10406 for (elements) |element| try w.print("{[element]f}", .{
10386 .element = try metadata_formatter.fmt("", element),10407 .element = try metadata_formatter.fmt("", element, .{ .percent = true }),
10387 });10408 });
10388 try w.writeAll("}\n");10409 try w.writeAll("}\n");
10389 },10410 },
10390 .module_flag => {10411 .module_flag => {
10391 const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data);10412 const extra = self.metadataExtraData(Metadata.ModuleFlag, metadata_item.data);
10392 try w.print("!{{{[behavior]f%}{[name]f%}{[constant]f%}}}\n", .{10413 try w.print("!{{{[behavior]f}{[name]f}{[constant]f}}}\n", .{
10393 .behavior = try metadata_formatter.fmt("", extra.behavior),10414 .behavior = try metadata_formatter.fmt("", extra.behavior, .{ .percent = true }),
10394 .name = try metadata_formatter.fmt("", extra.name),10415 .name = try metadata_formatter.fmt("", extra.name, .{ .percent = true }),
10395 .constant = try metadata_formatter.fmt("", extra.constant),10416 .constant = try metadata_formatter.fmt("", extra.constant, .{ .percent = true }),
10396 });10417 });
10397 },10418 },
10398 .local_var => {10419 .local_var => {
...@@ -15109,3 +15130,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15109,3 +15130,13 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1510915130
15110 return bitcode.toOwnedSlice();15131 return bitcode.toOwnedSlice();
15111}15132}
15133
15134const FormatFlags = struct {
15135 comma: bool = false,
15136 space: bool = false,
15137 percent: bool = false,
15138
15139 fn onlyPercent(f: FormatFlags) bool {
15140 return !f.comma and !f.space and f.percent;
15141 }
15142};
lib/std/zip.zig+9-9
...@@ -124,7 +124,7 @@ pub fn findEndRecord(seekable_stream: anytype, stream_len: u64) !EndRecord {...@@ -124,7 +124,7 @@ pub fn findEndRecord(seekable_stream: anytype, stream_len: u64) !EndRecord {
124124
125 try seekable_stream.seekTo(stream_len - @as(u64, new_loaded_len));125 try seekable_stream.seekTo(stream_len - @as(u64, new_loaded_len));
126 const read_buf: []u8 = buf[buf.len - new_loaded_len ..][0..read_len];126 const read_buf: []u8 = buf[buf.len - new_loaded_len ..][0..read_len];
127 const len = try seekable_stream.context.reader().readAll(read_buf);127 const len = try seekable_stream.context.deprecatedReader().readAll(read_buf);
128 if (len != read_len)128 if (len != read_len)
129 return error.ZipTruncated;129 return error.ZipTruncated;
130 loaded_len = new_loaded_len;130 loaded_len = new_loaded_len;
...@@ -295,7 +295,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -295,7 +295,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
295 if (locator_end_offset > stream_len)295 if (locator_end_offset > stream_len)
296 return error.ZipTruncated;296 return error.ZipTruncated;
297 try stream.seekTo(stream_len - locator_end_offset);297 try stream.seekTo(stream_len - locator_end_offset);
298 const locator = try stream.context.reader().readStructEndian(EndLocator64, .little);298 const locator = try stream.context.deprecatedReader().readStructEndian(EndLocator64, .little);
299 if (!std.mem.eql(u8, &locator.signature, &end_locator64_sig))299 if (!std.mem.eql(u8, &locator.signature, &end_locator64_sig))
300 return error.ZipBadLocatorSig;300 return error.ZipBadLocatorSig;
301 if (locator.zip64_disk_count != 0)301 if (locator.zip64_disk_count != 0)
...@@ -305,7 +305,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -305,7 +305,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
305305
306 try stream.seekTo(locator.record_file_offset);306 try stream.seekTo(locator.record_file_offset);
307307
308 const record64 = try stream.context.reader().readStructEndian(EndRecord64, .little);308 const record64 = try stream.context.deprecatedReader().readStructEndian(EndRecord64, .little);
309309
310 if (!std.mem.eql(u8, &record64.signature, &end_record64_sig))310 if (!std.mem.eql(u8, &record64.signature, &end_record64_sig))
311 return error.ZipBadEndRecord64Sig;311 return error.ZipBadEndRecord64Sig;
...@@ -357,7 +357,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -357,7 +357,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
357357
358 const header_zip_offset = self.cd_zip_offset + self.cd_record_offset;358 const header_zip_offset = self.cd_zip_offset + self.cd_record_offset;
359 try self.stream.seekTo(header_zip_offset);359 try self.stream.seekTo(header_zip_offset);
360 const header = try self.stream.context.reader().readStructEndian(CentralDirectoryFileHeader, .little);360 const header = try self.stream.context.deprecatedReader().readStructEndian(CentralDirectoryFileHeader, .little);
361 if (!std.mem.eql(u8, &header.signature, &central_file_header_sig))361 if (!std.mem.eql(u8, &header.signature, &central_file_header_sig))
362 return error.ZipBadCdOffset;362 return error.ZipBadCdOffset;
363363
...@@ -386,7 +386,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -386,7 +386,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
386386
387 {387 {
388 try self.stream.seekTo(header_zip_offset + @sizeOf(CentralDirectoryFileHeader) + header.filename_len);388 try self.stream.seekTo(header_zip_offset + @sizeOf(CentralDirectoryFileHeader) + header.filename_len);
389 const len = try self.stream.context.reader().readAll(extra);389 const len = try self.stream.context.deprecatedReader().readAll(extra);
390 if (len != extra.len)390 if (len != extra.len)
391 return error.ZipTruncated;391 return error.ZipTruncated;
392 }392 }
...@@ -449,7 +449,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -449,7 +449,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
449 try stream.seekTo(self.header_zip_offset + @sizeOf(CentralDirectoryFileHeader));449 try stream.seekTo(self.header_zip_offset + @sizeOf(CentralDirectoryFileHeader));
450450
451 {451 {
452 const len = try stream.context.reader().readAll(filename);452 const len = try stream.context.deprecatedReader().readAll(filename);
453 if (len != filename.len)453 if (len != filename.len)
454 return error.ZipBadFileOffset;454 return error.ZipBadFileOffset;
455 }455 }
...@@ -457,7 +457,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -457,7 +457,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
457 const local_data_header_offset: u64 = local_data_header_offset: {457 const local_data_header_offset: u64 = local_data_header_offset: {
458 const local_header = blk: {458 const local_header = blk: {
459 try stream.seekTo(self.file_offset);459 try stream.seekTo(self.file_offset);
460 break :blk try stream.context.reader().readStructEndian(LocalFileHeader, .little);460 break :blk try stream.context.deprecatedReader().readStructEndian(LocalFileHeader, .little);
461 };461 };
462 if (!std.mem.eql(u8, &local_header.signature, &local_file_header_sig))462 if (!std.mem.eql(u8, &local_header.signature, &local_file_header_sig))
463 return error.ZipBadFileOffset;463 return error.ZipBadFileOffset;
...@@ -483,7 +483,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -483,7 +483,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
483483
484 {484 {
485 try stream.seekTo(self.file_offset + @sizeOf(LocalFileHeader) + local_header.filename_len);485 try stream.seekTo(self.file_offset + @sizeOf(LocalFileHeader) + local_header.filename_len);
486 const len = try stream.context.reader().readAll(extra);486 const len = try stream.context.deprecatedReader().readAll(extra);
487 if (len != extra.len)487 if (len != extra.len)
488 return error.ZipTruncated;488 return error.ZipTruncated;
489 }489 }
...@@ -552,7 +552,7 @@ pub fn Iterator(comptime SeekableStream: type) type {...@@ -552,7 +552,7 @@ pub fn Iterator(comptime SeekableStream: type) type {
552 @as(u64, @sizeOf(LocalFileHeader)) +552 @as(u64, @sizeOf(LocalFileHeader)) +
553 local_data_header_offset;553 local_data_header_offset;
554 try stream.seekTo(local_data_file_offset);554 try stream.seekTo(local_data_file_offset);
555 var limited_reader = std.io.limitedReader(stream.context.reader(), self.compressed_size);555 var limited_reader = std.io.limitedReader(stream.context.deprecatedReader(), self.compressed_size);
556 const crc = try decompress(556 const crc = try decompress(
557 self.compression_method,557 self.compression_method,
558 self.uncompressed_size,558 self.uncompressed_size,
src/Air/print.zig+2-2
...@@ -710,7 +710,7 @@ const Writer = struct {...@@ -710,7 +710,7 @@ const Writer = struct {
710 }710 }
711 }711 }
712 const asm_source = std.mem.sliceAsBytes(w.air.extra.items[extra_i..])[0..extra.data.source_len];712 const asm_source = std.mem.sliceAsBytes(w.air.extra.items[extra_i..])[0..extra.data.source_len];
713 try s.print(", \"{f}\"", .{std.zig.fmtEscapes(asm_source)});713 try s.print(", \"{f}\"", .{std.zig.fmtString(asm_source)});
714 }714 }
715715
716 fn writeDbgStmt(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {716 fn writeDbgStmt(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
...@@ -722,7 +722,7 @@ const Writer = struct {...@@ -722,7 +722,7 @@ const Writer = struct {
722 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;722 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
723 try w.writeOperand(s, inst, 0, pl_op.operand);723 try w.writeOperand(s, inst, 0, pl_op.operand);
724 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);724 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
725 try s.print(", \"{f}\"", .{std.zig.fmtEscapes(name.toSlice(w.air))});725 try s.print(", \"{f}\"", .{std.zig.fmtString(name.toSlice(w.air))});
726 }726 }
727727
728 fn writeCall(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {728 fn writeCall(w: *Writer, s: *std.io.Writer, inst: Air.Inst.Index) Error!void {
src/Zcu.zig+94-183
...@@ -15,6 +15,7 @@ const BigIntConst = std.math.big.int.Const;...@@ -15,6 +15,7 @@ const BigIntConst = std.math.big.int.Const;
15const BigIntMutable = std.math.big.int.Mutable;15const BigIntMutable = std.math.big.int.Mutable;
16const Target = std.Target;16const Target = std.Target;
17const Ast = std.zig.Ast;17const Ast = std.zig.Ast;
18const Writer = std.io.Writer;
1819
19const Zcu = @This();20const Zcu = @This();
20const Compilation = @import("Compilation.zig");21const Compilation = @import("Compilation.zig");
...@@ -858,7 +859,7 @@ pub const Namespace = struct {...@@ -858,7 +859,7 @@ pub const Namespace = struct {
858 try ns.fileScope(zcu).renderFullyQualifiedDebugName(writer);859 try ns.fileScope(zcu).renderFullyQualifiedDebugName(writer);
859 break :sep ':';860 break :sep ':';
860 };861 };
861 if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) });862 if (name != .empty) try writer.print("{c}{f}", .{ sep, name.fmt(&zcu.intern_pool) });
862 }863 }
863864
864 pub fn internFullyQualifiedName(865 pub fn internFullyQualifiedName(
...@@ -870,7 +871,7 @@ pub const Namespace = struct {...@@ -870,7 +871,7 @@ pub const Namespace = struct {
870 ) !InternPool.NullTerminatedString {871 ) !InternPool.NullTerminatedString {
871 const ns_name = Type.fromInterned(ns.owner_type).containerTypeName(ip);872 const ns_name = Type.fromInterned(ns.owner_type).containerTypeName(ip);
872 if (name == .empty) return ns_name;873 if (name == .empty) return ns_name;
873 return ip.getOrPutStringFmt(gpa, tid, "{}.{}", .{ ns_name.fmt(ip), name.fmt(ip) }, .no_embedded_nulls);874 return ip.getOrPutStringFmt(gpa, tid, "{f}.{f}", .{ ns_name.fmt(ip), name.fmt(ip) }, .no_embedded_nulls);
874 }875 }
875};876};
876877
...@@ -1039,12 +1040,12 @@ pub const File = struct {...@@ -1039,12 +1040,12 @@ pub const File = struct {
1039 if (stat.size > std.math.maxInt(u32))1040 if (stat.size > std.math.maxInt(u32))
1040 return error.FileTooBig;1041 return error.FileTooBig;
10411042
1042 const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0);1043 const source = try gpa.allocSentinel(u8, @intCast(stat.size), 0);
1043 errdefer gpa.free(source);1044 errdefer gpa.free(source);
10441045
1045 const amt = try f.readAll(source);1046 var file_reader = f.reader(&.{});
1046 if (amt != stat.size)1047 file_reader.size = stat.size;
1047 return error.UnexpectedEndOfFile;1048 try file_reader.interface.readSliceAll(source);
10481049
1049 // Here we do not modify stat fields because this function is the one1050 // Here we do not modify stat fields because this function is the one
1050 // used for error reporting. We need to keep the stat fields stale so that1051 // used for error reporting. We need to keep the stat fields stale so that
...@@ -1097,11 +1098,10 @@ pub const File = struct {...@@ -1097,11 +1098,10 @@ pub const File = struct {
1097 const gpa = pt.zcu.gpa;1098 const gpa = pt.zcu.gpa;
1098 const ip = &pt.zcu.intern_pool;1099 const ip = &pt.zcu.intern_pool;
1099 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);1100 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
1100 const slice = try strings.addManyAsSlice(file.fullyQualifiedNameLen());1101 var w: Writer = .fixed((try strings.addManyAsSlice(file.fullyQualifiedNameLen()))[0]);
1101 var fbs = std.io.fixedBufferStream(slice[0]);1102 file.renderFullyQualifiedName(&w) catch unreachable;
1102 file.renderFullyQualifiedName(fbs.writer()) catch unreachable;1103 assert(w.end == w.buffer.len);
1103 assert(fbs.pos == slice[0].len);1104 return ip.getOrPutTrailingString(gpa, pt.tid, @intCast(w.end), .no_embedded_nulls);
1104 return ip.getOrPutTrailingString(gpa, pt.tid, @intCast(slice[0].len), .no_embedded_nulls);
1105 }1105 }
11061106
1107 pub const Index = InternPool.FileIndex;1107 pub const Index = InternPool.FileIndex;
...@@ -1190,13 +1190,8 @@ pub const ErrorMsg = struct {...@@ -1190,13 +1190,8 @@ pub const ErrorMsg = struct {
1190 gpa.destroy(err_msg);1190 gpa.destroy(err_msg);
1191 }1191 }
11921192
1193 pub fn init(1193 pub fn init(gpa: Allocator, src_loc: LazySrcLoc, comptime format: []const u8, args: anytype) !ErrorMsg {
1194 gpa: Allocator,1194 return .{
1195 src_loc: LazySrcLoc,
1196 comptime format: []const u8,
1197 args: anytype,
1198 ) !ErrorMsg {
1199 return ErrorMsg{
1200 .src_loc = src_loc,1195 .src_loc = src_loc,
1201 .msg = try std.fmt.allocPrint(gpa, format, args),1196 .msg = try std.fmt.allocPrint(gpa, format, args),
1202 };1197 };
...@@ -2811,10 +2806,18 @@ comptime {...@@ -2811,10 +2806,18 @@ comptime {
2811}2806}
28122807
2813pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir {2808pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir {
2814 return loadZirCacheBody(gpa, try cache_file.deprecatedReader().readStruct(Zir.Header), cache_file);2809 var buffer: [2000]u8 = undefined;
2810 var file_reader = cache_file.reader(&buffer);
2811 return result: {
2812 const header = file_reader.interface.takeStruct(Zir.Header) catch |err| break :result err;
2813 break :result loadZirCacheBody(gpa, header.*, &file_reader.interface);
2814 } catch |err| switch (err) {
2815 error.ReadFailed => return file_reader.err.?,
2816 else => |e| return e,
2817 };
2815}2818}
28162819
2817pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) !Zir {2820pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_br: *std.io.Reader) !Zir {
2818 var instructions: std.MultiArrayList(Zir.Inst) = .{};2821 var instructions: std.MultiArrayList(Zir.Inst) = .{};
2819 errdefer instructions.deinit(gpa);2822 errdefer instructions.deinit(gpa);
28202823
...@@ -2837,34 +2840,16 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.F...@@ -2837,34 +2840,16 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.F
2837 undefined;2840 undefined;
2838 defer if (data_has_safety_tag) gpa.free(safety_buffer);2841 defer if (data_has_safety_tag) gpa.free(safety_buffer);
28392842
2840 const data_ptr = if (data_has_safety_tag)2843 var vecs = [_][]u8{
2841 @as([*]u8, @ptrCast(safety_buffer.ptr))2844 @ptrCast(zir.instructions.items(.tag)),
2842 else2845 if (data_has_safety_tag)
2843 @as([*]u8, @ptrCast(zir.instructions.items(.data).ptr));2846 @ptrCast(safety_buffer)
28442847 else
2845 var iovecs = [_]std.posix.iovec{2848 @ptrCast(zir.instructions.items(.data)),
2846 .{2849 zir.string_bytes,
2847 .base = @as([*]u8, @ptrCast(zir.instructions.items(.tag).ptr)),2850 @ptrCast(zir.extra),
2848 .len = header.instructions_len,
2849 },
2850 .{
2851 .base = data_ptr,
2852 .len = header.instructions_len * 8,
2853 },
2854 .{
2855 .base = zir.string_bytes.ptr,
2856 .len = header.string_bytes_len,
2857 },
2858 .{
2859 .base = @as([*]u8, @ptrCast(zir.extra.ptr)),
2860 .len = header.extra_len * 4,
2861 },
2862 };2851 };
2863 const amt_read = try cache_file.readvAll(&iovecs);2852 try cache_br.readVecAll(&vecs);
2864 const amt_expected = zir.instructions.len * 9 +
2865 zir.string_bytes.len +
2866 zir.extra.len * 4;
2867 if (amt_read != amt_expected) return error.UnexpectedFileSize;
2868 if (data_has_safety_tag) {2853 if (data_has_safety_tag) {
2869 const tags = zir.instructions.items(.tag);2854 const tags = zir.instructions.items(.tag);
2870 for (zir.instructions.items(.data), 0..) |*data, i| {2855 for (zir.instructions.items(.data), 0..) |*data, i| {
...@@ -2876,7 +2861,6 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.F...@@ -2876,7 +2861,6 @@ pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.F
2876 };2861 };
2877 }2862 }
2878 }2863 }
2879
2880 return zir;2864 return zir;
2881}2865}
28822866
...@@ -2887,14 +2871,6 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S...@@ -2887,14 +2871,6 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S
2887 undefined;2871 undefined;
2888 defer if (data_has_safety_tag) gpa.free(safety_buffer);2872 defer if (data_has_safety_tag) gpa.free(safety_buffer);
28892873
2890 const data_ptr: [*]const u8 = if (data_has_safety_tag)
2891 if (zir.instructions.len == 0)
2892 undefined
2893 else
2894 @ptrCast(safety_buffer.ptr)
2895 else
2896 @ptrCast(zir.instructions.items(.data).ptr);
2897
2898 if (data_has_safety_tag) {2874 if (data_has_safety_tag) {
2899 // The `Data` union has a safety tag but in the file format we store it without.2875 // The `Data` union has a safety tag but in the file format we store it without.
2900 for (zir.instructions.items(.data), 0..) |*data, i| {2876 for (zir.instructions.items(.data), 0..) |*data, i| {
...@@ -2912,29 +2888,20 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S...@@ -2912,29 +2888,20 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S
2912 .stat_inode = stat.inode,2888 .stat_inode = stat.inode,
2913 .stat_mtime = stat.mtime,2889 .stat_mtime = stat.mtime,
2914 };2890 };
2915 var iovecs: [5]std.posix.iovec_const = .{2891 var vecs = [_][]const u8{
2916 .{2892 @ptrCast((&header)[0..1]),
2917 .base = @ptrCast(&header),2893 @ptrCast(zir.instructions.items(.tag)),
2918 .len = @sizeOf(Zir.Header),2894 if (data_has_safety_tag)
2919 },2895 @ptrCast(safety_buffer)
2920 .{2896 else
2921 .base = @ptrCast(zir.instructions.items(.tag).ptr),2897 @ptrCast(zir.instructions.items(.data)),
2922 .len = zir.instructions.len,2898 zir.string_bytes,
2923 },2899 @ptrCast(zir.extra),
2924 .{2900 };
2925 .base = data_ptr,2901 var cache_fw = cache_file.writer(&.{});
2926 .len = zir.instructions.len * 8,2902 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
2927 },2903 error.WriteFailed => return cache_fw.err.?,
2928 .{
2929 .base = zir.string_bytes.ptr,
2930 .len = zir.string_bytes.len,
2931 },
2932 .{
2933 .base = @ptrCast(zir.extra.ptr),
2934 .len = zir.extra.len * 4,
2935 },
2936 };2904 };
2937 try cache_file.writevAll(&iovecs);
2938}2905}
29392906
2940pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir) std.fs.File.WriteError!void {2907pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir) std.fs.File.WriteError!void {
...@@ -2950,48 +2917,24 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir...@@ -2950,48 +2917,24 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir
2950 .stat_inode = stat.inode,2917 .stat_inode = stat.inode,
2951 .stat_mtime = stat.mtime,2918 .stat_mtime = stat.mtime,
2952 };2919 };
2953 var iovecs: [9]std.posix.iovec_const = .{2920 var vecs = [_][]const u8{
2954 .{2921 @ptrCast((&header)[0..1]),
2955 .base = @ptrCast(&header),2922 @ptrCast(zoir.nodes.items(.tag)),
2956 .len = @sizeOf(Zoir.Header),2923 @ptrCast(zoir.nodes.items(.data)),
2957 },2924 @ptrCast(zoir.nodes.items(.ast_node)),
2958 .{2925 @ptrCast(zoir.extra),
2959 .base = @ptrCast(zoir.nodes.items(.tag)),2926 @ptrCast(zoir.limbs),
2960 .len = zoir.nodes.len * @sizeOf(Zoir.Node.Repr.Tag),2927 zoir.string_bytes,
2961 },2928 @ptrCast(zoir.compile_errors),
2962 .{2929 @ptrCast(zoir.error_notes),
2963 .base = @ptrCast(zoir.nodes.items(.data)),2930 };
2964 .len = zoir.nodes.len * 4,2931 var cache_fw = cache_file.writer(&.{});
2965 },2932 cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) {
2966 .{2933 error.WriteFailed => return cache_fw.err.?,
2967 .base = @ptrCast(zoir.nodes.items(.ast_node)),
2968 .len = zoir.nodes.len * 4,
2969 },
2970 .{
2971 .base = @ptrCast(zoir.extra),
2972 .len = zoir.extra.len * 4,
2973 },
2974 .{
2975 .base = @ptrCast(zoir.limbs),
2976 .len = zoir.limbs.len * @sizeOf(std.math.big.Limb),
2977 },
2978 .{
2979 .base = zoir.string_bytes.ptr,
2980 .len = zoir.string_bytes.len,
2981 },
2982 .{
2983 .base = @ptrCast(zoir.compile_errors),
2984 .len = zoir.compile_errors.len * @sizeOf(Zoir.CompileError),
2985 },
2986 .{
2987 .base = @ptrCast(zoir.error_notes),
2988 .len = zoir.error_notes.len * @sizeOf(Zoir.CompileError.Note),
2989 },
2990 };2934 };
2991 try cache_file.writevAll(&iovecs);
2992}2935}
29932936
2994pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_file: std.fs.File) !Zoir {2937pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_br: *std.io.Reader) !Zoir {
2995 var zoir: Zoir = .{2938 var zoir: Zoir = .{
2996 .nodes = .empty,2939 .nodes = .empty,
2997 .extra = &.{},2940 .extra = &.{},
...@@ -3017,49 +2960,17 @@ pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_file: std.fs...@@ -3017,49 +2960,17 @@ pub fn loadZoirCacheBody(gpa: Allocator, header: Zoir.Header, cache_file: std.fs
3017 zoir.compile_errors = try gpa.alloc(Zoir.CompileError, header.compile_errors_len);2960 zoir.compile_errors = try gpa.alloc(Zoir.CompileError, header.compile_errors_len);
3018 zoir.error_notes = try gpa.alloc(Zoir.CompileError.Note, header.error_notes_len);2961 zoir.error_notes = try gpa.alloc(Zoir.CompileError.Note, header.error_notes_len);
30192962
3020 var iovecs: [8]std.posix.iovec = .{2963 var vecs = [_][]u8{
3021 .{2964 @ptrCast(zoir.nodes.items(.tag)),
3022 .base = @ptrCast(zoir.nodes.items(.tag)),2965 @ptrCast(zoir.nodes.items(.data)),
3023 .len = header.nodes_len * @sizeOf(Zoir.Node.Repr.Tag),2966 @ptrCast(zoir.nodes.items(.ast_node)),
3024 },2967 @ptrCast(zoir.extra),
3025 .{2968 @ptrCast(zoir.limbs),
3026 .base = @ptrCast(zoir.nodes.items(.data)),2969 zoir.string_bytes,
3027 .len = header.nodes_len * 4,2970 @ptrCast(zoir.compile_errors),
3028 },2971 @ptrCast(zoir.error_notes),
3029 .{
3030 .base = @ptrCast(zoir.nodes.items(.ast_node)),
3031 .len = header.nodes_len * 4,
3032 },
3033 .{
3034 .base = @ptrCast(zoir.extra),
3035 .len = header.extra_len * 4,
3036 },
3037 .{
3038 .base = @ptrCast(zoir.limbs),
3039 .len = header.limbs_len * @sizeOf(std.math.big.Limb),
3040 },
3041 .{
3042 .base = zoir.string_bytes.ptr,
3043 .len = header.string_bytes_len,
3044 },
3045 .{
3046 .base = @ptrCast(zoir.compile_errors),
3047 .len = header.compile_errors_len * @sizeOf(Zoir.CompileError),
3048 },
3049 .{
3050 .base = @ptrCast(zoir.error_notes),
3051 .len = header.error_notes_len * @sizeOf(Zoir.CompileError.Note),
3052 },
3053 };2972 };
30542973 try cache_br.readVecAll(&vecs);
3055 const bytes_expected = expected: {
3056 var n: usize = 0;
3057 for (iovecs) |v| n += v.len;
3058 break :expected n;
3059 };
3060
3061 const bytes_read = try cache_file.readvAll(&iovecs);
3062 if (bytes_read != bytes_expected) return error.UnexpectedFileSize;
3063 return zoir;2974 return zoir;
3064}2975}
30652976
...@@ -3071,7 +2982,7 @@ pub fn markDependeeOutdated(...@@ -3071,7 +2982,7 @@ pub fn markDependeeOutdated(
3071 marked_po: enum { not_marked_po, marked_po },2982 marked_po: enum { not_marked_po, marked_po },
3072 dependee: InternPool.Dependee,2983 dependee: InternPool.Dependee,
3073) !void {2984) !void {
3074 log.debug("outdated dependee: {}", .{zcu.fmtDependee(dependee)});2985 log.debug("outdated dependee: {f}", .{zcu.fmtDependee(dependee)});
3075 var it = zcu.intern_pool.dependencyIterator(dependee);2986 var it = zcu.intern_pool.dependencyIterator(dependee);
3076 while (it.next()) |depender| {2987 while (it.next()) |depender| {
3077 if (zcu.outdated.getPtr(depender)) |po_dep_count| {2988 if (zcu.outdated.getPtr(depender)) |po_dep_count| {
...@@ -3079,9 +2990,9 @@ pub fn markDependeeOutdated(...@@ -3079,9 +2990,9 @@ pub fn markDependeeOutdated(
3079 .not_marked_po => {},2990 .not_marked_po => {},
3080 .marked_po => {2991 .marked_po => {
3081 po_dep_count.* -= 1;2992 po_dep_count.* -= 1;
3082 log.debug("outdated {} => already outdated {} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), po_dep_count.* });2993 log.debug("outdated {f} => already outdated {f} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), po_dep_count.* });
3083 if (po_dep_count.* == 0) {2994 if (po_dep_count.* == 0) {
3084 log.debug("outdated ready: {}", .{zcu.fmtAnalUnit(depender)});2995 log.debug("outdated ready: {f}", .{zcu.fmtAnalUnit(depender)});
3085 try zcu.outdated_ready.put(zcu.gpa, depender, {});2996 try zcu.outdated_ready.put(zcu.gpa, depender, {});
3086 }2997 }
3087 },2998 },
...@@ -3102,9 +3013,9 @@ pub fn markDependeeOutdated(...@@ -3102,9 +3013,9 @@ pub fn markDependeeOutdated(
3102 depender,3013 depender,
3103 new_po_dep_count,3014 new_po_dep_count,
3104 );3015 );
3105 log.debug("outdated {} => new outdated {} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), new_po_dep_count });3016 log.debug("outdated {f} => new outdated {f} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), new_po_dep_count });
3106 if (new_po_dep_count == 0) {3017 if (new_po_dep_count == 0) {
3107 log.debug("outdated ready: {}", .{zcu.fmtAnalUnit(depender)});3018 log.debug("outdated ready: {f}", .{zcu.fmtAnalUnit(depender)});
3108 try zcu.outdated_ready.put(zcu.gpa, depender, {});3019 try zcu.outdated_ready.put(zcu.gpa, depender, {});
3109 }3020 }
3110 // If this is a Decl and was not previously PO, we must recursively3021 // If this is a Decl and was not previously PO, we must recursively
...@@ -3117,16 +3028,16 @@ pub fn markDependeeOutdated(...@@ -3117,16 +3028,16 @@ pub fn markDependeeOutdated(
3117}3028}
31183029
3119pub fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {3030pub fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {
3120 log.debug("up-to-date dependee: {}", .{zcu.fmtDependee(dependee)});3031 log.debug("up-to-date dependee: {f}", .{zcu.fmtDependee(dependee)});
3121 var it = zcu.intern_pool.dependencyIterator(dependee);3032 var it = zcu.intern_pool.dependencyIterator(dependee);
3122 while (it.next()) |depender| {3033 while (it.next()) |depender| {
3123 if (zcu.outdated.getPtr(depender)) |po_dep_count| {3034 if (zcu.outdated.getPtr(depender)) |po_dep_count| {
3124 // This depender is already outdated, but it now has one3035 // This depender is already outdated, but it now has one
3125 // less PO dependency!3036 // less PO dependency!
3126 po_dep_count.* -= 1;3037 po_dep_count.* -= 1;
3127 log.debug("up-to-date {} => {} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), po_dep_count.* });3038 log.debug("up-to-date {f} => {f} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), po_dep_count.* });
3128 if (po_dep_count.* == 0) {3039 if (po_dep_count.* == 0) {
3129 log.debug("outdated ready: {}", .{zcu.fmtAnalUnit(depender)});3040 log.debug("outdated ready: {f}", .{zcu.fmtAnalUnit(depender)});
3130 try zcu.outdated_ready.put(zcu.gpa, depender, {});3041 try zcu.outdated_ready.put(zcu.gpa, depender, {});
3131 }3042 }
3132 continue;3043 continue;
...@@ -3140,11 +3051,11 @@ pub fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {...@@ -3140,11 +3051,11 @@ pub fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {
3140 };3051 };
3141 if (ptr.* > 1) {3052 if (ptr.* > 1) {
3142 ptr.* -= 1;3053 ptr.* -= 1;
3143 log.debug("up-to-date {} => {} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), ptr.* });3054 log.debug("up-to-date {f} => {f} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender), ptr.* });
3144 continue;3055 continue;
3145 }3056 }
31463057
3147 log.debug("up-to-date {} => {} po_deps=0 (up-to-date)", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender) });3058 log.debug("up-to-date {f} => {f} po_deps=0 (up-to-date)", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(depender) });
31483059
3149 // This dependency is no longer PO, i.e. is known to be up-to-date.3060 // This dependency is no longer PO, i.e. is known to be up-to-date.
3150 assert(zcu.potentially_outdated.swapRemove(depender));3061 assert(zcu.potentially_outdated.swapRemove(depender));
...@@ -3173,7 +3084,7 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: AnalUni...@@ -3173,7 +3084,7 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: AnalUni
3173 .func => |func_index| .{ .interned = func_index }, // IES3084 .func => |func_index| .{ .interned = func_index }, // IES
3174 .memoized_state => |stage| .{ .memoized_state = stage },3085 .memoized_state => |stage| .{ .memoized_state = stage },
3175 };3086 };
3176 log.debug("potentially outdated dependee: {}", .{zcu.fmtDependee(dependee)});3087 log.debug("potentially outdated dependee: {f}", .{zcu.fmtDependee(dependee)});
3177 var it = ip.dependencyIterator(dependee);3088 var it = ip.dependencyIterator(dependee);
3178 while (it.next()) |po| {3089 while (it.next()) |po| {
3179 if (zcu.outdated.getPtr(po)) |po_dep_count| {3090 if (zcu.outdated.getPtr(po)) |po_dep_count| {
...@@ -3183,17 +3094,17 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: AnalUni...@@ -3183,17 +3094,17 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: AnalUni
3183 _ = zcu.outdated_ready.swapRemove(po);3094 _ = zcu.outdated_ready.swapRemove(po);
3184 }3095 }
3185 po_dep_count.* += 1;3096 po_dep_count.* += 1;
3186 log.debug("po {} => {} [outdated] po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po), po_dep_count.* });3097 log.debug("po {f} => {f} [outdated] po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po), po_dep_count.* });
3187 continue;3098 continue;
3188 }3099 }
3189 if (zcu.potentially_outdated.getPtr(po)) |n| {3100 if (zcu.potentially_outdated.getPtr(po)) |n| {
3190 // There is now one more PO dependency.3101 // There is now one more PO dependency.
3191 n.* += 1;3102 n.* += 1;
3192 log.debug("po {} => {} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po), n.* });3103 log.debug("po {f} => {f} po_deps={}", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po), n.* });
3193 continue;3104 continue;
3194 }3105 }
3195 try zcu.potentially_outdated.putNoClobber(zcu.gpa, po, 1);3106 try zcu.potentially_outdated.putNoClobber(zcu.gpa, po, 1);
3196 log.debug("po {} => {} po_deps=1", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po) });3107 log.debug("po {f} => {f} po_deps=1", .{ zcu.fmtDependee(dependee), zcu.fmtAnalUnit(po) });
3197 // This AnalUnit was not already PO, so we must recursively mark its dependers as also PO.3108 // This AnalUnit was not already PO, so we must recursively mark its dependers as also PO.
3198 try zcu.markTransitiveDependersPotentiallyOutdated(po);3109 try zcu.markTransitiveDependersPotentiallyOutdated(po);
3199 }3110 }
...@@ -3222,7 +3133,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {...@@ -3222,7 +3133,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {
32223133
3223 if (zcu.outdated_ready.count() > 0) {3134 if (zcu.outdated_ready.count() > 0) {
3224 const unit = zcu.outdated_ready.keys()[0];3135 const unit = zcu.outdated_ready.keys()[0];
3225 log.debug("findOutdatedToAnalyze: trivial {}", .{zcu.fmtAnalUnit(unit)});3136 log.debug("findOutdatedToAnalyze: trivial {f}", .{zcu.fmtAnalUnit(unit)});
3226 return unit;3137 return unit;
3227 }3138 }
32283139
...@@ -3273,7 +3184,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {...@@ -3273,7 +3184,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?AnalUnit {
3273 }3184 }
3274 }3185 }
32753186
3276 log.debug("findOutdatedToAnalyze: heuristic returned '{}' ({d} dependers)", .{3187 log.debug("findOutdatedToAnalyze: heuristic returned '{f}' ({d} dependers)", .{
3277 zcu.fmtAnalUnit(chosen_unit.?),3188 zcu.fmtAnalUnit(chosen_unit.?),
3278 chosen_unit_dependers,3189 chosen_unit_dependers,
3279 });3190 });
...@@ -4072,7 +3983,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4072,7 +3983,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4072 const referencer = kv.value;3983 const referencer = kv.value;
4073 try checked_types.putNoClobber(gpa, ty, {});3984 try checked_types.putNoClobber(gpa, ty, {});
40743985
4075 log.debug("handle type '{}'", .{Type.fromInterned(ty).containerTypeName(ip).fmt(ip)});3986 log.debug("handle type '{f}'", .{Type.fromInterned(ty).containerTypeName(ip).fmt(ip)});
40763987
4077 // If this type undergoes type resolution, the corresponding `AnalUnit` is automatically referenced.3988 // If this type undergoes type resolution, the corresponding `AnalUnit` is automatically referenced.
4078 const has_resolution: bool = switch (ip.indexToKey(ty)) {3989 const has_resolution: bool = switch (ip.indexToKey(ty)) {
...@@ -4108,7 +4019,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4108,7 +4019,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4108 // `comptime` decls are always analyzed.4019 // `comptime` decls are always analyzed.
4109 const unit: AnalUnit = .wrap(.{ .@"comptime" = cu });4020 const unit: AnalUnit = .wrap(.{ .@"comptime" = cu });
4110 if (!result.contains(unit)) {4021 if (!result.contains(unit)) {
4111 log.debug("type '{}': ref comptime %{}", .{4022 log.debug("type '{f}': ref comptime %{}", .{
4112 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),4023 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),
4113 @intFromEnum(ip.getComptimeUnit(cu).zir_index.resolve(ip) orelse continue),4024 @intFromEnum(ip.getComptimeUnit(cu).zir_index.resolve(ip) orelse continue),
4114 });4025 });
...@@ -4139,7 +4050,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4139,7 +4050,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4139 },4050 },
4140 };4051 };
4141 if (want_analysis) {4052 if (want_analysis) {
4142 log.debug("type '{}': ref test %{}", .{4053 log.debug("type '{f}': ref test %{}", .{
4143 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),4054 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),
4144 @intFromEnum(inst_info.inst),4055 @intFromEnum(inst_info.inst),
4145 });4056 });
...@@ -4158,7 +4069,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4158,7 +4069,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4158 if (decl.linkage == .@"export") {4069 if (decl.linkage == .@"export") {
4159 const unit: AnalUnit = .wrap(.{ .nav_val = nav });4070 const unit: AnalUnit = .wrap(.{ .nav_val = nav });
4160 if (!result.contains(unit)) {4071 if (!result.contains(unit)) {
4161 log.debug("type '{}': ref named %{}", .{4072 log.debug("type '{f}': ref named %{}", .{
4162 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),4073 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),
4163 @intFromEnum(inst_info.inst),4074 @intFromEnum(inst_info.inst),
4164 });4075 });
...@@ -4174,7 +4085,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4174,7 +4085,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4174 if (decl.linkage == .@"export") {4085 if (decl.linkage == .@"export") {
4175 const unit: AnalUnit = .wrap(.{ .nav_val = nav });4086 const unit: AnalUnit = .wrap(.{ .nav_val = nav });
4176 if (!result.contains(unit)) {4087 if (!result.contains(unit)) {
4177 log.debug("type '{}': ref named %{}", .{4088 log.debug("type '{f}': ref named %{}", .{
4178 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),4089 Type.fromInterned(ty).containerTypeName(ip).fmt(ip),
4179 @intFromEnum(inst_info.inst),4090 @intFromEnum(inst_info.inst),
4180 });4091 });
...@@ -4199,7 +4110,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4199,7 +4110,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4199 try unit_queue.put(gpa, other, kv.value); // same reference location4110 try unit_queue.put(gpa, other, kv.value); // same reference location
4200 }4111 }
42014112
4202 log.debug("handle unit '{}'", .{zcu.fmtAnalUnit(unit)});4113 log.debug("handle unit '{f}'", .{zcu.fmtAnalUnit(unit)});
42034114
4204 if (zcu.reference_table.get(unit)) |first_ref_idx| {4115 if (zcu.reference_table.get(unit)) |first_ref_idx| {
4205 assert(first_ref_idx != std.math.maxInt(u32));4116 assert(first_ref_idx != std.math.maxInt(u32));
...@@ -4207,7 +4118,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4207,7 +4118,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4207 while (ref_idx != std.math.maxInt(u32)) {4118 while (ref_idx != std.math.maxInt(u32)) {
4208 const ref = zcu.all_references.items[ref_idx];4119 const ref = zcu.all_references.items[ref_idx];
4209 if (!result.contains(ref.referenced)) {4120 if (!result.contains(ref.referenced)) {
4210 log.debug("unit '{}': ref unit '{}'", .{4121 log.debug("unit '{f}': ref unit '{f}'", .{
4211 zcu.fmtAnalUnit(unit),4122 zcu.fmtAnalUnit(unit),
4212 zcu.fmtAnalUnit(ref.referenced),4123 zcu.fmtAnalUnit(ref.referenced),
4213 });4124 });
...@@ -4226,7 +4137,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -4226,7 +4137,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
4226 while (ref_idx != std.math.maxInt(u32)) {4137 while (ref_idx != std.math.maxInt(u32)) {
4227 const ref = zcu.all_type_references.items[ref_idx];4138 const ref = zcu.all_type_references.items[ref_idx];
4228 if (!checked_types.contains(ref.referenced)) {4139 if (!checked_types.contains(ref.referenced)) {
4229 log.debug("unit '{}': ref type '{}'", .{4140 log.debug("unit '{f}': ref type '{f}'", .{
4230 zcu.fmtAnalUnit(unit),4141 zcu.fmtAnalUnit(unit),
4231 Type.fromInterned(ref.referenced).containerTypeName(ip).fmt(ip),4142 Type.fromInterned(ref.referenced).containerTypeName(ip).fmt(ip),
4232 });4143 });
src/Zcu/PerThread.zig+1-1
...@@ -343,7 +343,7 @@ fn loadZirZoirCache(...@@ -343,7 +343,7 @@ fn loadZirZoirCache(
343 .zon => Zoir.Header,343 .zon => Zoir.Header,
344 };344 };
345345
346 var buffer: [@sizeOf(Header)]u8 = undefined;346 var buffer: [2000]u8 = undefined;
347 var cache_fr = cache_file.reader(&buffer);347 var cache_fr = cache_file.reader(&buffer);
348 cache_fr.size = stat.size;348 cache_fr.size = stat.size;
349 const cache_br = &cache_fr.interface;349 const cache_br = &cache_fr.interface;