authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-09-26 17:43:41+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-27 21:39:51-04:00
log3f9d3859d4d8a55cf6cb055c1a35d99e05cfa253
treee5ed74290bde2f2da916fe384bc53fbdbd8d2cd9
parentda561521dd78dcde03fc51de8fd64551b368f56d

compiler: don't mutate the `InternPool` when printing types and values

This change at long last replaces the `Zcu.PerThread` parameters in `Type.print` and `Value.print` with `*Zcu` parameters. This required various tweaks to avoid the need to intern values when printing them. The most significant change is to `Value.pointerDerivation`, whose API and implementation has been changed quite a bit. This API is used by the C and SPIR-V backends, which I therefore also needed to update---but it seems to have been surprisingly painless overall! Most of this diff comes from replacing `fmt(pt)` with `fmt(zcu)` (plus a few more similar patterns), then following compile errors for a while to change parameters/constants/fields from `pt` to `zcu` where necessary. Actual logic changes should be limited to the following source files: * `src/print_value.zig` * `src/Type.zig` * `src/Value.zig` * `src/codegen/c.zig` * `src/codegen/spirv/CodeGen.zig`

26 files changed, 1587 insertions(+), 1426 deletions(-)

src/Air/Verify.zig+1-1
......@@ -41,7 +41,7 @@ pub fn run(pt: Zcu.PerThread, func_index: InternPool.Index, air: *const Air) voi
4141 error.Canceled => return io.recancel(),
4242 };
4343 defer io.unlockStderr();
44 air.write(&stderr.file_writer.interface, pt, null) catch |err| switch (err) {
44 air.write(&stderr.file_writer.interface, zcu, null) catch |err| switch (err) {
4545 error.WriteFailed => switch (stderr.file_writer.err.?) {
4646 error.Canceled => return io.recancel(),
4747 else => {},
src/Air/print.zig+20-20
......@@ -9,7 +9,7 @@ const Type = @import("../Type.zig");
99const Air = @import("../Air.zig");
1010const InternPool = @import("../InternPool.zig");
1111
12pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) !void {
12pub fn write(air: Air, stream: *std.Io.Writer, zcu: *Zcu, liveness: ?Air.Liveness) !void {
1313 comptime assert(build_options.enable_debug_extensions);
1414 const instruction_bytes = air.instructions.len *
1515 // Here we don't use @sizeOf(Air.Inst.Data) because it would include
......@@ -43,8 +43,8 @@ pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air
4343 // zig fmt: on
4444
4545 var writer: Writer = .{
46 .pt = pt,
47 .gpa = pt.zcu.gpa,
46 .zcu = zcu,
47 .gpa = zcu.comp.gpa,
4848 .air = air,
4949 .liveness = liveness,
5050 .indent = 2,
......@@ -57,13 +57,13 @@ pub fn writeInst(
5757 air: Air,
5858 stream: *std.Io.Writer,
5959 inst: Air.Inst.Index,
60 pt: Zcu.PerThread,
60 zcu: *Zcu,
6161 liveness: ?Air.Liveness,
6262) void {
6363 comptime assert(build_options.enable_debug_extensions);
6464 var writer: Writer = .{
65 .pt = pt,
66 .gpa = pt.zcu.gpa,
65 .zcu = zcu,
66 .gpa = zcu.comp.gpa,
6767 .air = air,
6868 .liveness = liveness,
6969 .indent = 2,
......@@ -89,7 +89,7 @@ pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Ai
8989}
9090
9191const Writer = struct {
92 pt: Zcu.PerThread,
92 zcu: *Zcu,
9393 gpa: Allocator,
9494 air: Air,
9595 liveness: ?Air.Liveness,
......@@ -377,7 +377,7 @@ const Writer = struct {
377377 }
378378
379379 fn writeType(w: *Writer, s: *std.Io.Writer, ty: Type) !void {
380 return ty.print(s, w.pt, null);
380 return ty.print(s, w.zcu, null);
381381 }
382382
383383 fn writeTy(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
......@@ -446,7 +446,7 @@ const Writer = struct {
446446 }
447447
448448 fn writeAggregateInit(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
449 const zcu = w.pt.zcu;
449 const zcu = w.zcu;
450450 const ty_pl = w.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
451451 const vector_ty = ty_pl.ty;
452452 const len = @as(usize, @intCast(vector_ty.arrayLen(zcu)));
......@@ -539,7 +539,7 @@ const Writer = struct {
539539 }
540540
541541 fn writeShuffleOne(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
542 const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst);
542 const unwrapped = w.air.unwrapShuffleOne(w.zcu, inst);
543543 try w.writeType(s, unwrapped.result_ty);
544544 try s.writeAll(", ");
545545 try w.writeOperand(s, inst, 0, unwrapped.operand);
......@@ -548,14 +548,14 @@ const Writer = struct {
548548 if (mask_idx > 0) try s.writeAll(", ");
549549 switch (mask_elem.unwrap()) {
550550 .elem => |idx| try s.print("elem {d}", .{idx}),
551 .value => |val| try s.print("val {f}", .{Value.fromInterned(val).fmtValue(w.pt)}),
551 .value => |val| try s.print("val {f}", .{Value.fromInterned(val).fmtValue(w.zcu)}),
552552 }
553553 }
554554 try s.writeByte(']');
555555 }
556556
557557 fn writeShuffleTwo(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
558 const unwrapped = w.air.unwrapShuffleTwo(w.pt.zcu, inst);
558 const unwrapped = w.air.unwrapShuffleTwo(w.zcu, inst);
559559 try w.writeType(s, unwrapped.result_ty);
560560 try s.writeAll(", ");
561561 try w.writeOperand(s, inst, 0, unwrapped.operand_a);
......@@ -574,7 +574,7 @@ const Writer = struct {
574574 }
575575
576576 fn writeSelect(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
577 const zcu = w.pt.zcu;
577 const zcu = w.zcu;
578578 const pl_op = w.air.instructions.items(.data)[@backingInt(inst)].pl_op;
579579 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
580580
......@@ -606,7 +606,7 @@ const Writer = struct {
606606 }
607607
608608 fn writeRuntimeNavPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
609 const ip = &w.pt.zcu.intern_pool;
609 const ip = &w.zcu.intern_pool;
610610 const ty_nav = w.air.instructions.items(.data)[@backingInt(inst)].ty_nav;
611611 try w.writeType(s, ty_nav.ty);
612612 try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});
......@@ -695,7 +695,7 @@ const Writer = struct {
695695 try s.writeByte(')');
696696 }
697697
698 const zcu = w.pt.zcu;
698 const zcu = w.zcu;
699699 const ip = &zcu.intern_pool;
700700 const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers);
701701 const clobbers_ty = clobbers_val.typeOf(zcu);
......@@ -1019,11 +1019,11 @@ const Writer = struct {
10191019 if (@backingInt(operand) < InternPool.static_len) {
10201020 return s.print("@{}", .{operand});
10211021 } else if (operand.toInterned()) |ip_index| {
1022 const pt = w.pt;
1023 const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf());
1022 const zcu = w.zcu;
1023 const ty = Type.fromInterned(zcu.intern_pool.indexToKey(ip_index).typeOf());
10241024 try s.print("<{f}, {f}>", .{
1025 ty.fmt(pt),
1026 Value.fromInterned(ip_index).fmtValue(pt),
1025 ty.fmt(zcu),
1026 Value.fromInterned(ip_index).fmtValue(w.zcu),
10271027 });
10281028 } else {
10291029 return w.writeInstIndex(s, operand.toIndex().?, dies);
......@@ -1042,7 +1042,7 @@ const Writer = struct {
10421042 }
10431043
10441044 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
1045 const zcu = w.pt.zcu;
1045 const zcu = w.zcu;
10461046 return w.air.typeOfIndex(inst, &zcu.intern_pool);
10471047 }
10481048};
src/Sema.zig+384-381
......@@ -910,6 +910,7 @@ const ComptimeReason = union(enum) {
910910 },
911911
912912 fn explain(reason: ComptimeReason, sema: *Sema, src: LazySrcLoc, err_msg: *Zcu.ErrorMsg) !void {
913 const zcu = sema.pt.zcu;
913914 switch (reason) {
914915 .simple => |simple| {
915916 try sema.errNote(src, err_msg, "{s}", .{simple.message()});
......@@ -920,17 +921,17 @@ const ComptimeReason = union(enum) {
920921 .struct_init => .{ "initializer of comptime-only struct", "must be comptime-known" },
921922 .tuple_init => .{ "initializer of comptime-only tuple", "must be comptime-known" },
922923 };
923 try sema.errNote(src, err_msg, "{s} '{f}' {s}", .{ pre, co.ty.fmt(sema.pt), post });
924 try sema.errNote(src, err_msg, "{s} '{f}' {s}", .{ pre, co.ty.fmt(zcu), post });
924925 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
925926 },
926927 .comptime_only_param_ty => |co| {
927 try sema.errNote(src, err_msg, "argument to parameter with comptime-only type '{f}' must be comptime-known", .{co.ty.fmt(sema.pt)});
928 try sema.errNote(src, err_msg, "argument to parameter with comptime-only type '{f}' must be comptime-known", .{co.ty.fmt(zcu)});
928929 try sema.errNote(co.param_ty_src, err_msg, "parameter type declared here", .{});
929930 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
930931 },
931932 .comptime_only_ret_ty => |co| {
932933 const function_with: []const u8 = if (co.is_generic_inst) "generic function instantiated with" else "function with";
933 try sema.errNote(src, err_msg, "call to {s} comptime-only return type '{f}' is evaluated at comptime", .{ function_with, co.ty.fmt(sema.pt) });
934 try sema.errNote(src, err_msg, "call to {s} comptime-only return type '{f}' is evaluated at comptime", .{ function_with, co.ty.fmt(zcu) });
934935 try sema.errNote(co.ret_ty_src, err_msg, "return type declared here", .{});
935936 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
936937 },
......@@ -1901,7 +1902,7 @@ fn analyzeBodyInner(
19011902 const err_union_ty = sema.typeOf(err_union);
19021903 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
19031904 return sema.failWithOwnedErrorMsg(block, msg: {
1904 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
1905 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
19051906 errdefer msg.destroy(sema.gpa);
19061907 try sema.addDeclaredHereNote(msg, err_union_ty);
19071908 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -2366,7 +2367,7 @@ pub fn failWithTooLargeShiftAmount(
23662367 const msg = try sema.errMsg(
23672368 shift_src,
23682369 "shift amount '{f}' is too large for operand type '{f}'",
2369 .{ shift_amt.fmtValueSema(sema.pt, sema), operand_ty.fmt(sema.pt) },
2370 .{ shift_amt.fmtValueSema(sema), operand_ty.fmt(sema.pt.zcu) },
23702371 );
23712372 errdefer msg.destroy(sema.gpa);
23722373 if (vector_index) |i| try sema.errNote(shift_src, msg, "when computing vector element at index '{d}'", .{i});
......@@ -2376,7 +2377,7 @@ pub fn failWithTooLargeShiftAmount(
23762377
23772378pub fn failWithNegativeShiftAmount(sema: *Sema, block: *Block, src: LazySrcLoc, shift_amt: Value, vector_index: ?usize) CompileError {
23782379 return sema.failWithOwnedErrorMsg(block, msg: {
2379 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema.pt, sema)});
2380 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema)});
23802381 errdefer msg.destroy(sema.gpa);
23812382 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
23822383 break :msg msg;
......@@ -2397,9 +2398,9 @@ pub fn failWithUnsupportedComptimeShiftAmount(sema: *Sema, block: *Block, src: L
23972398}
23982399
23992400fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
2400 const pt = sema.pt;
2401 const zcu = sema.pt.zcu;
24012402 return sema.fail(block, src, "remainder division with '{f}' and '{f}': signed integers and floats must use @rem or @mod", .{
2402 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
2403 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
24032404 });
24042405}
24052406
......@@ -2421,7 +2422,7 @@ fn failWithInvalidSwitchTagCapture(sema: *Sema, block: *Block, tag_capture_src:
24212422 }
24222423 return sema.failWithOwnedErrorMsg(block, msg: {
24232424 const msg = try sema.errMsg(tag_capture_src, "cannot capture tag of non-union type '{f}'", .{
2424 operand_ty.fmt(pt),
2425 operand_ty.fmt(zcu),
24252426 });
24262427 errdefer msg.destroy(sema.gpa);
24272428 try sema.addDeclaredHereNote(msg, operand_ty);
......@@ -2440,7 +2441,7 @@ fn failWithAmbiguousBackingIntType(
24402441 const zcu = pt.zcu;
24412442 return sema.failWithOwnedErrorMsg(block, msg: {
24422443 const msg = try sema.errMsg(src, "{s} is ambiguous for type '{f}'", .{
2443 builtin_name, int_backed_ty.fmt(pt),
2444 builtin_name, int_backed_ty.fmt(zcu),
24442445 });
24452446 errdefer msg.destroy(sema.gpa);
24462447 try sema.errNote(int_backed_ty.srcLoc(zcu), msg, "backing integer type of {t} is inferred", .{
......@@ -2452,13 +2453,13 @@ fn failWithAmbiguousBackingIntType(
24522453}
24532454
24542455fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
2455 const pt = sema.pt;
2456 const zcu = sema.pt.zcu;
24562457 const msg = msg: {
24572458 const msg = try sema.errMsg(src, "expected optional type, found '{f}'", .{
2458 non_optional_ty.fmt(pt),
2459 non_optional_ty.fmt(zcu),
24592460 });
24602461 errdefer msg.destroy(sema.gpa);
2461 if (non_optional_ty.zigTypeTag(pt.zcu) == .error_union) {
2462 if (non_optional_ty.zigTypeTag(zcu) == .error_union) {
24622463 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
24632464 }
24642465 try addDeclaredHereNote(sema, msg, non_optional_ty);
......@@ -2468,15 +2469,14 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
24682469}
24692470
24702471fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2471 const pt = sema.pt;
2472 const zcu = pt.zcu;
2472 const zcu = sema.pt.zcu;
24732473 const msg = msg: {
24742474 const msg = try sema.errMsg(src, "type '{f}' does not support array initialization syntax", .{
2475 ty.fmt(pt),
2475 ty.fmt(zcu),
24762476 });
24772477 errdefer msg.destroy(sema.gpa);
24782478 if (ty.isSlice(zcu)) {
2479 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(pt)});
2479 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(zcu)});
24802480 }
24812481 break :msg msg;
24822482 };
......@@ -2484,17 +2484,17 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
24842484}
24852485
24862486fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2487 const pt = sema.pt;
2487 const zcu = sema.pt.zcu;
24882488 return sema.fail(block, src, "type '{f}' does not support struct initialization syntax", .{
2489 ty.fmt(pt),
2489 ty.fmt(zcu),
24902490 });
24912491}
24922492
24932493pub fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: Type, val: Value, vector_index: ?usize) CompileError {
2494 const pt = sema.pt;
2494 const zcu = sema.pt.zcu;
24952495 return sema.failWithOwnedErrorMsg(block, msg: {
24962496 const msg = try sema.errMsg(src, "overflow of integer type '{f}' with value '{f}'", .{
2497 int_ty.fmt(pt), val.fmtValueSema(pt, sema),
2497 int_ty.fmt(zcu), val.fmtValueSema(sema),
24982498 });
24992499 errdefer msg.destroy(sema.gpa);
25002500 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
......@@ -2543,7 +2543,7 @@ fn failWithInvalidFieldAccess(
25432543 const child_ty = inner_ty.optionalChild(zcu);
25442544 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;
25452545 const msg = msg: {
2546 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(pt)});
2546 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25472547 errdefer msg.destroy(sema.gpa);
25482548 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
25492549 break :msg msg;
......@@ -2553,14 +2553,14 @@ fn failWithInvalidFieldAccess(
25532553 const child_ty = inner_ty.errorUnionPayload(zcu);
25542554 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;
25552555 const msg = msg: {
2556 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(pt)});
2556 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25572557 errdefer msg.destroy(sema.gpa);
25582558 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
25592559 break :msg msg;
25602560 };
25612561 return sema.failWithOwnedErrorMsg(block, msg);
25622562 }
2563 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(pt)});
2563 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25642564}
25652565
25662566fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {
......@@ -2650,20 +2650,20 @@ pub fn errMsg(
26502650}
26512651
26522652fn typeMismatchErrMsg(sema: *Sema, src: LazySrcLoc, expected: Type, found: Type) Allocator.Error!*Zcu.ErrorMsg {
2653 const pt = sema.pt;
2654 var cmp: Type.Comparison = try .init(&.{ expected, found }, pt);
2655 defer cmp.deinit(pt);
2653 const zcu = sema.pt.zcu;
2654 var cmp: Type.Comparison = try .init(&.{ expected, found }, zcu);
2655 defer cmp.deinit(zcu.comp.gpa);
26562656
26572657 const msg = try sema.errMsg(src, "expected type '{f}', found '{f}'", .{
2658 cmp.fmtType(expected, pt),
2659 cmp.fmtType(found, pt),
2658 cmp.fmtType(expected, zcu),
2659 cmp.fmtType(found, zcu),
26602660 });
26612661 errdefer msg.destroy(sema.gpa);
26622662
26632663 for (cmp.type_dedupe_cache.keys(), cmp.type_dedupe_cache.values()) |ty, value| {
26642664 if (value == .dont_dedupe) continue;
26652665 const placeholder = value.dedupe;
2666 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(pt) });
2666 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(zcu) });
26672667 }
26682668
26692669 return msg;
......@@ -2679,7 +2679,7 @@ pub fn fail(
26792679 const err_msg = try sema.errMsg(src, format, args);
26802680 inline for (args) |arg| {
26812681 if (@TypeOf(arg) == Type.Formatter) {
2682 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
2682 try addDeclaredHereNote(sema, err_msg, arg.ty);
26832683 }
26842684 }
26852685 return sema.failWithOwnedErrorMsg(block, err_msg);
......@@ -3154,11 +3154,11 @@ fn validateDeref(
31543154 const zcu = pt.zcu;
31553155 const ip = &zcu.intern_pool;
31563156 if (ty.zigTypeTag(zcu) != .pointer) {
3157 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(pt)});
3157 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(zcu)});
31583158 }
31593159 const size = ty.ptrSize(zcu);
31603160 switch (size) {
3161 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(pt)}),
3161 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(zcu)}),
31623162 .one, .c, .slice => {},
31633163 }
31643164 if (sema.resolveValue(ref)) |val| {
......@@ -3194,11 +3194,11 @@ fn ensureResultUsed(
31943194 switch (ty.zigTypeTag(zcu)) {
31953195 .void, .noreturn => return,
31963196 .error_set => {
3197 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(pt)});
3197 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(zcu)});
31983198 },
31993199 .error_union => {
32003200 const msg = msg: {
3201 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(pt)});
3201 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(zcu)});
32023202 errdefer msg.destroy(sema.gpa);
32033203 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
32043204 break :msg msg;
......@@ -3207,7 +3207,7 @@ fn ensureResultUsed(
32073207 },
32083208 else => {
32093209 const msg = msg: {
3210 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(pt)});
3210 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(zcu)});
32113211 errdefer msg.destroy(sema.gpa);
32123212 try sema.errNote(src, msg, "all non-void values must be used", .{});
32133213 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
......@@ -3469,7 +3469,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
34693469 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
34703470 // TODO: source location of runtime control flow
34713471 const init_src = block.src(.{ .node_offset_var_decl_init = inst_data.src_node });
3472 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(pt)});
3472 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(zcu)});
34733473 }
34743474
34753475 // This is a runtime value.
......@@ -3990,7 +3990,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39903990 // The alloc wasn't comptime-known per the above logic, so the
39913991 // type cannot be comptime-only.
39923992 // TODO: source location of runtime control flow
3993 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});
3993 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(zcu)});
39943994 }
39953995 if (sema.func_is_naked and final_elem_ty.hasRuntimeBits(zcu)) {
39963996 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
......@@ -4090,7 +4090,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
40904090 if (!object_ty.isIndexable(zcu)) {
40914091 // Instead of using checkIndexable we customize this error.
40924092 const msg = msg: {
4093 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(pt)});
4093 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(zcu)});
40944094 errdefer msg.destroy(sema.gpa);
40954095 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
40964096
......@@ -4129,10 +4129,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41294129 .input_index = len_idx,
41304130 } });
41314131 try sema.errNote(a_src, msg, "length {f} here", .{
4132 v.fmtValueSema(pt, sema),
4132 v.fmtValueSema(sema),
41334133 });
41344134 try sema.errNote(arg_src, msg, "length {f} here", .{
4135 arg_val.fmtValueSema(pt, sema),
4135 arg_val.fmtValueSema(sema),
41364136 });
41374137 break :msg msg;
41384138 };
......@@ -4164,7 +4164,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41644164 .input_index = i,
41654165 } });
41664166 try sema.errNote(arg_src, msg, "type '{f}' has no upper bound", .{
4167 object_ty.fmt(pt),
4167 object_ty.fmt(zcu),
41684168 });
41694169 }
41704170 break :msg msg;
......@@ -4249,7 +4249,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
42494249 switch (val_ty.zigTypeTag(zcu)) {
42504250 .array, .vector => {},
42514251 else => if (!val_ty.isTuple(zcu)) {
4252 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });
4252 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(zcu), val_ty.fmt(zcu) });
42534253 },
42544254 }
42554255 const want_ty = try pt.arrayType(.{
......@@ -4327,7 +4327,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
43274327 const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return;
43284328 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) {
43294329 return sema.failWithOwnedErrorMsg(block, msg: {
4330 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(pt)});
4330 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(zcu)});
43314331 errdefer msg.destroy(sema.gpa);
43324332 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
43334333 break :msg msg;
......@@ -4713,7 +4713,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
47134713
47144714 if (!operand_ty.destructurable(zcu)) {
47154715 return sema.failWithOwnedErrorMsg(block, msg: {
4716 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(pt)});
4716 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(zcu)});
47174717 errdefer msg.destroy(sema.gpa);
47184718 try sema.errNote(destructure_src, msg, "result destructured here", .{});
47194719 if (operand_ty.zigTypeTag(pt.zcu) == .error_union) {
......@@ -4758,13 +4758,13 @@ fn failWithBadMemberAccess(
47584758 const inst_index = inst.resolve(ip) orelse return sema.failTransitive(.{ .lost_tracking = inst });
47594759 if (inst_index == .main_struct_inst) {
47604760 return sema.fail(block, field_src, "root source file struct '{f}' has no member named '{f}'", .{
4761 agg_ty.fmt(pt), field_name.fmt(ip),
4761 agg_ty.fmt(zcu), field_name.fmt(ip),
47624762 });
47634763 }
47644764 }
47654765
47664766 return sema.fail(block, field_src, "{s} '{f}' has no member named '{f}'", .{
4767 kw_name, agg_ty.fmt(pt), field_name.fmt(ip),
4767 kw_name, agg_ty.fmt(zcu), field_name.fmt(ip),
47684768 });
47694769}
47704770
......@@ -5061,10 +5061,10 @@ fn zirCompileLog(
50615061 const arg_ty = sema.typeOf(arg);
50625062 if (sema.resolveValue(arg)) |val| {
50635063 writer.print("@as({f}, {f})", .{
5064 arg_ty.fmt(pt), val.fmtValueSema(pt, sema),
5064 arg_ty.fmt(zcu), val.fmtValueSema(sema),
50655065 }) catch return error.OutOfMemory;
50665066 } else {
5067 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch return error.OutOfMemory;
5067 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(zcu)}) catch return error.OutOfMemory;
50685068 }
50695069 }
50705070
......@@ -5505,7 +5505,7 @@ fn resolveAnalyzedBlock(
55055505 const type_src = src; // TODO: better source location
55065506 if (resolved_ty.comptimeOnly(zcu)) {
55075507 const msg = msg: {
5508 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(pt)});
5508 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(zcu)});
55095509 errdefer msg.destroy(sema.gpa);
55105510
55115511 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
......@@ -5619,7 +5619,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
56195619
56205620 {
56215621 if (ptr_ty.zigTypeTag(zcu) != .pointer) {
5622 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(pt)});
5622 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(zcu)});
56235623 }
56245624 const ptr_ty_info = ptr_ty.ptrInfo(zcu);
56255625 if (ptr_ty_info.flags.size == .slice) {
......@@ -5634,7 +5634,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
56345634 try sema.ensureLayoutResolved(export_ty, src, .@"export");
56355635 if (!export_ty.validateExtern(.other, zcu)) {
56365636 return sema.failWithOwnedErrorMsg(block, msg: {
5637 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});
5637 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
56385638 errdefer msg.destroy(sema.gpa);
56395639 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
56405640 try sema.addDeclaredHereNote(msg, export_ty);
......@@ -5691,7 +5691,7 @@ pub fn analyzeExportSelfNav(
56915691
56925692 if (!export_ty.validateExtern(.other, zcu)) {
56935693 return sema.failWithOwnedErrorMsg(block, msg: {
5694 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});
5694 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
56955695 errdefer msg.destroy(gpa);
56965696 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
56975697 try sema.addDeclaredHereNote(msg, export_ty);
......@@ -6329,7 +6329,7 @@ fn checkCallArgumentCount(
63296329 {
63306330 const msg = msg: {
63316331 const msg = try sema.errMsg(func_src, "cannot call optional type '{f}'", .{
6332 callee_ty.fmt(pt),
6332 callee_ty.fmt(zcu),
63336333 });
63346334 errdefer msg.destroy(sema.gpa);
63356335 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
......@@ -6340,7 +6340,7 @@ fn checkCallArgumentCount(
63406340 },
63416341 else => {},
63426342 }
6343 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(pt)});
6343 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(zcu)});
63446344 };
63456345
63466346 const func_ty_info = zcu.typeToFunc(func_ty).?;
......@@ -6403,7 +6403,7 @@ fn callBuiltin(
64036403 },
64046404 else => {},
64056405 }
6406 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});
6406 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(zcu)});
64076407 };
64086408
64096409 const func_ty_info = zcu.typeToFunc(func_ty).?;
......@@ -6829,7 +6829,7 @@ fn analyzeCall(
68296829 if (!param_ty.isValidParamType(zcu)) {
68306830 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
68316831 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
6832 opaque_str, param_ty.fmt(pt),
6832 opaque_str, param_ty.fmt(zcu),
68336833 });
68346834 }
68356835
......@@ -6930,7 +6930,7 @@ fn analyzeCall(
69306930 if (!full_ty.isValidReturnType(zcu)) {
69316931 const opaque_str = if (full_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
69326932 return sema.fail(block, func_ret_ty_src, "{s}return type '{f}' not allowed", .{
6933 opaque_str, full_ty.fmt(pt),
6933 opaque_str, full_ty.fmt(zcu),
69346934 });
69356935 }
69366936
......@@ -7430,7 +7430,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
74307430 const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);
74317431 if (owner_func_ty.toIntern() != func_ty.toIntern()) {
74327432 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{f}' does not match type of calling function '{f}'", .{
7433 func_ty.fmt(pt), owner_func_ty.fmt(pt),
7433 func_ty.fmt(zcu), owner_func_ty.fmt(zcu),
74347434 });
74357435 }
74367436 _ = try block.addUnOp(.ret, result);
......@@ -7450,9 +7450,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
74507450 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
74517451 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
74527452 if (child_type.zigTypeTag(zcu) == .@"opaque") {
7453 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(pt)});
7453 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(zcu)});
74547454 } else if (child_type.zigTypeTag(zcu) == .null) {
7455 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(pt)});
7455 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(zcu)});
74567456 }
74577457 const opt_type = try pt.optionalType(child_type.toIntern());
74587458
......@@ -7513,7 +7513,7 @@ fn zirSplatOpResultType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
75137513
75147514 switch (vec_ty.zigTypeTag(zcu)) {
75157515 .array, .vector => {},
7516 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(pt)}),
7516 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(zcu)}),
75177517 }
75187518 return Air.internedToRef(vec_ty.childType(zcu).toIntern());
75197519}
......@@ -7586,7 +7586,7 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src:
75867586 const pt = sema.pt;
75877587 const zcu = pt.zcu;
75887588 if (elem_type.zigTypeTag(zcu) == .@"opaque") {
7589 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(pt)});
7589 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(zcu)});
75907590 } else if (elem_type.zigTypeTag(zcu) == .noreturn) {
75917591 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
75927592 }
......@@ -7617,7 +7617,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
76177617
76187618 if (error_set.zigTypeTag(zcu) != .error_set) {
76197619 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{
7620 error_set.fmt(pt),
7620 error_set.fmt(zcu),
76217621 });
76227622 }
76237623 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);
......@@ -7630,11 +7630,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
76307630 const zcu = pt.zcu;
76317631 if (payload_ty.zigTypeTag(zcu) == .@"opaque") {
76327632 return sema.fail(block, payload_src, "error union with payload of opaque type '{f}' not allowed", .{
7633 payload_ty.fmt(pt),
7633 payload_ty.fmt(zcu),
76347634 });
76357635 } else if (payload_ty.zigTypeTag(zcu) == .error_set) {
76367636 return sema.fail(block, payload_src, "error union with payload of error set type '{f}' not allowed", .{
7637 payload_ty.fmt(pt),
7637 payload_ty.fmt(zcu),
76387638 });
76397639 }
76407640}
......@@ -7765,9 +7765,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
77657765 const lhs_ty = try sema.analyzeAsType(block, lhs_src, .type, lhs);
77667766 const rhs_ty = try sema.analyzeAsType(block, rhs_src, .type, rhs);
77677767 if (lhs_ty.zigTypeTag(zcu) != .error_set)
7768 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(pt)});
7768 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(zcu)});
77697769 if (rhs_ty.zigTypeTag(zcu) != .error_set)
7770 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(pt)});
7770 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(zcu)});
77717771
77727772 // Anything merged with anyerror is anyerror.
77737773 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
......@@ -7893,7 +7893,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
78937893 block,
78947894 operand_src,
78957895 "untagged union '{f}' cannot be converted to integer",
7896 .{operand_ty.fmt(pt)},
7896 .{operand_ty.fmt(zcu)},
78977897 );
78987898 }
78997899
......@@ -7901,7 +7901,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79017901 },
79027902 else => {
79037903 return sema.fail(block, operand_src, "expected enum or tagged union, found '{f}'", .{
7904 operand_ty.fmt(pt),
7904 operand_ty.fmt(zcu),
79057905 });
79067906 },
79077907 };
......@@ -7930,7 +7930,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79307930 const operand_ty = sema.typeOf(operand);
79317931
79327932 if (dest_ty.zigTypeTag(zcu) != .@"enum") {
7933 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(pt)});
7933 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(zcu)});
79347934 }
79357935 try sema.ensureLayoutResolved(dest_ty, src, .init);
79367936 _ = try sema.checkIntType(block, operand_src, operand_ty);
......@@ -7942,7 +7942,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79427942 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
79437943 }
79447944 return sema.fail(block, src, "int value '{f}' out of range of non-exhaustive enum '{f}'", .{
7945 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),
7945 int_val.fmtValueSema(sema), dest_ty.fmt(zcu),
79467946 });
79477947 }
79487948 if (int_val.isUndef(zcu)) {
......@@ -7950,7 +7950,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79507950 }
79517951 if (!(try sema.enumHasInt(dest_ty, int_val))) {
79527952 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
7953 dest_ty.fmt(pt), int_val.fmtValueSema(pt, sema),
7953 dest_ty.fmt(zcu), int_val.fmtValueSema(sema),
79547954 });
79557955 }
79567956 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
......@@ -8128,7 +8128,7 @@ fn zirErrUnionPayload(
81288128 const err_union_ty = sema.typeOf(operand);
81298129 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
81308130 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
8131 err_union_ty.fmt(pt),
8131 err_union_ty.fmt(zcu),
81328132 });
81338133 }
81348134 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);
......@@ -8202,7 +8202,7 @@ fn analyzeErrUnionPayloadPtr(
82028202
82038203 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
82048204 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8205 operand_ty.childType(zcu).fmt(pt),
8205 operand_ty.childType(zcu).fmt(zcu),
82068206 });
82078207 }
82088208
......@@ -8277,7 +8277,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
82778277 const operand_ty = sema.typeOf(operand);
82788278 if (operand_ty.zigTypeTag(zcu) != .error_union) {
82798279 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8280 operand_ty.fmt(pt),
8280 operand_ty.fmt(zcu),
82818281 });
82828282 }
82838283
......@@ -8311,7 +8311,7 @@ fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand:
83118311
83128312 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
83138313 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8314 operand_ty.childType(zcu).fmt(pt),
8314 operand_ty.childType(zcu).fmt(zcu),
83158315 });
83168316 }
83178317
......@@ -8639,7 +8639,7 @@ fn checkParamType(
86398639 if (!param_ty.isValidParamType(zcu)) {
86408640 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
86418641 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
8642 opaque_str, param_ty.fmt(pt),
8642 opaque_str, param_ty.fmt(zcu),
86438643 });
86448644 }
86458645 if (!target_util.fnCallConvAllowsZigTypes(cc)) {
......@@ -8720,12 +8720,12 @@ fn checkReturnTypeAndCallConv(
87208720 if (!bare_ret_ty.isValidReturnType(zcu)) {
87218721 const opaque_str = if (bare_ret_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
87228722 return sema.fail(block, ret_ty_src, "{s}return type '{s}{f}' not allowed", .{
8723 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(pt),
8723 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(zcu),
87248724 });
87258725 }
87268726 if (!target_util.fnCallConvAllowsZigTypes(@"callconv")) {
87278727 if (inferred_error_set) {
8728 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(pt), @"callconv" });
8728 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(zcu), @"callconv" });
87298729 }
87308730 if (bare_ret_ty.isGenericPoison()) {
87318731 return sema.fail(block, ret_ty_src, "generic return type not allowed in function with calling convention '{t}'", .{@"callconv"});
......@@ -8857,7 +8857,7 @@ fn validateResolvedFuncType(
88578857 } else src;
88588858 return sema.failWithOwnedErrorMsg(block, msg: {
88598859 const msg = try sema.errMsg(param_src, "parameter of type '{f}' not allowed in function with calling convention '{t}'", .{
8860 param_ty.fmt(pt), @"callconv",
8860 param_ty.fmt(zcu), @"callconv",
88618861 });
88628862 errdefer msg.destroy(gpa);
88638863 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
......@@ -8874,7 +8874,7 @@ fn validateResolvedFuncType(
88748874 } else src;
88758875 return sema.failWithOwnedErrorMsg(block, msg: {
88768876 const msg = try sema.errMsg(ret_ty_src, "return type '{f}' not allowed in function with calling convention '{t}'", .{
8877 ret_ty.fmt(pt), @"callconv",
8877 ret_ty.fmt(zcu), @"callconv",
88788878 });
88798879 errdefer msg.destroy(gpa);
88808880 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, ret_ty, .ret_ty);
......@@ -8933,7 +8933,7 @@ fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type)
89338933 }
89348934
89358935 return sema.failWithOwnedErrorMsg(block, msg: {
8936 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(pt)});
8936 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(zcu)});
89378937 errdefer msg.destroy(sema.gpa);
89388938
89398939 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
......@@ -9166,7 +9166,7 @@ fn analyzeAs(
91669166 const operand = sema.resolveInst(zir_operand);
91679167 const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand;
91689168 switch (dest_ty.zigTypeTag(zcu)) {
9169 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(pt)}),
9169 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(zcu)}),
91709170 .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}),
91719171 else => {},
91729172 }
......@@ -9191,7 +9191,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
91919191 const ptr_ty = operand_ty.scalarType(zcu);
91929192 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
91939193 if (!ptr_ty.isPtrAtRuntime(zcu)) {
9194 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)});
9194 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)});
91959195 }
91969196
91979197 const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined;
......@@ -9414,45 +9414,45 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94149414 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
94159415 switch (dest_ty.scalarType(zcu).zigTypeTag(zcu)) {
94169416 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9417 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});
9417 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
94189418 errdefer msg.destroy(sema.gpa);
94199419 switch (operand_ty.zigTypeTag(zcu)) {
9420 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(pt)}),
9421 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(pt)}),
9420 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(zcu)}),
9421 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(zcu)}),
94229422 else => {},
94239423 }
94249424 break :msg msg;
94259425 }),
94269426 .array => switch (dest_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9427 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}),
9427 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}),
94289428 else => {},
94299429 },
94309430 else => {},
94319431 }
94329432 if (!dest_ty.hasBitRepresentation(zcu)) {
9433 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});
9433 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
94349434 }
94359435
94369436 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
94379437 switch (operand_ty.scalarType(zcu).zigTypeTag(zcu)) {
94389438 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9439 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});
9439 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
94409440 errdefer msg.destroy(sema.gpa);
94419441 switch (dest_ty.zigTypeTag(zcu)) {
9442 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(pt)}),
9443 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(pt)}),
9442 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(zcu)}),
9443 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(zcu)}),
94449444 else => {},
94459445 }
94469446 break :msg msg;
94479447 }),
94489448 .array => switch (operand_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9449 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(pt)}),
9449 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(zcu)}),
94509450 else => {},
94519451 },
94529452 else => {},
94539453 }
94549454 if (!operand_ty.hasBitRepresentation(zcu)) {
9455 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});
9455 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
94569456 }
94579457
94589458 operand_ty.assertHasLayout(zcu);
......@@ -9462,9 +9462,9 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94629462 const dest_bits = dest_ty.bitSize(zcu);
94639463 if (operand_bits != dest_bits) {
94649464 return sema.fail(block, src, "@bitCast size mismatch: destination type '{f}' has {d} bits but source type '{f}' has {d} bits", .{
9465 dest_ty.fmt(pt),
9465 dest_ty.fmt(zcu),
94669466 dest_bits,
9467 operand_ty.fmt(pt),
9467 operand_ty.fmt(zcu),
94689468 operand_bits,
94699469 });
94709470 }
......@@ -9482,7 +9482,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94829482 dest_ty.enumTagFieldIndex(result_val, zcu) == null)
94839483 {
94849484 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9485 dest_ty.fmt(pt), result_val.backingInt(zcu).fmtValueSema(pt, sema),
9485 dest_ty.fmt(zcu), result_val.backingInt(zcu).fmtValueSema(sema),
94869486 });
94879487 }
94889488
......@@ -9515,9 +9515,9 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
95159515 if (union_obj.tag_usage == .tagged) break :ref try sema.unionToTag(block, operand);
95169516 if (union_obj.layout == .@"packed") break :ref operand;
95179517 return sema.failWithOwnedErrorMsg(block, msg: {
9518 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(pt)});
9518 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(zcu)});
95199519 errdefer msg.deinit(gpa);
9520 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(pt)});
9520 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(zcu)});
95219521 try sema.addDeclaredHereNote(msg, operand_ty);
95229522 break :msg msg;
95239523 });
......@@ -9525,14 +9525,14 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
95259525 .@"struct" => {
95269526 if (operand_ty.containerLayout(zcu) != .@"packed") {
95279527 return sema.fail(block, operand_src, "non-packed struct '{f}' does not have a backing integer", .{
9528 operand_ty.fmt(pt),
9528 operand_ty.fmt(zcu),
95299529 });
95309530 }
95319531 break :ref operand;
95329532 },
95339533 else => {
95349534 return sema.fail(block, operand_src, "expected enum, tagged union, packed union or packed struct, found '{f}'", .{
9535 operand_ty.fmt(pt),
9535 operand_ty.fmt(zcu),
95369536 });
95379537 },
95389538 };
......@@ -9568,12 +9568,12 @@ fn zirFromBackingIntArgTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
95689568 .@"enum" => {},
95699569 .@"struct", .@"union" => |type_tag| if (dest_ty.containerLayout(zcu) != .@"packed") {
95709570 return sema.fail(block, src, "non-packed {t} '{f}' does not have a backing integer", .{
9571 type_tag, dest_ty.fmt(pt),
9571 type_tag, dest_ty.fmt(zcu),
95729572 });
95739573 },
95749574 else => {
95759575 return sema.fail(block, src, "expected enum, packed union or packed struct, found '{f}'", .{
9576 dest_ty.fmt(pt),
9576 dest_ty.fmt(zcu),
95779577 });
95789578 },
95799579 }
......@@ -9614,7 +9614,7 @@ fn zirFromBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
96149614 enum_obj.tagValueIndex(ip, backing_int_val.toIntern()) == null)
96159615 {
96169616 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9617 dest_ty.fmt(pt), backing_int_val.fmtValueSema(pt, sema),
9617 dest_ty.fmt(zcu), backing_int_val.fmtValueSema(sema),
96189618 });
96199619 }
96209620 return .fromValue(try pt.enumValue(dest_ty, backing_int_val));
......@@ -9660,7 +9660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
96609660 block,
96619661 src,
96629662 "expected float or vector type, found '{f}'",
9663 .{dest_ty.fmt(pt)},
9663 .{dest_ty.fmt(zcu)},
96649664 ),
96659665 };
96669666
......@@ -9670,7 +9670,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
96709670 block,
96719671 operand_src,
96729672 "expected float or vector type, found '{f}'",
9673 .{operand_ty.fmt(pt)},
9673 .{operand_ty.fmt(zcu)},
96749674 ),
96759675 }
96769676
......@@ -9747,7 +9747,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97479747 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
97489748 const msg = msg: {
97499749 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{f}'", .{
9750 indexable_ty.fmt(pt),
9750 indexable_ty.fmt(zcu),
97519751 });
97529752 errdefer msg.destroy(sema.gpa);
97539753 if (indexable_ty.isIndexable(zcu)) {
......@@ -9869,7 +9869,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
98699869 const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand));
98709870 const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) {
98719871 .pointer => lhs_ptr_ty.childType(zcu),
9872 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(pt)}),
9872 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(zcu)}),
98739873 };
98749874
98759875 const sentinel_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
......@@ -9884,7 +9884,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
98849884 };
98859885 },
98869886 },
9887 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(pt)}),
9887 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(zcu)}),
98889888 };
98899889
98909890 return Air.internedToRef(sentinel_ty.toIntern());
......@@ -9954,7 +9954,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
99549954 };
99559955 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
99569956 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
9957 err_union_ty.fmt(pt),
9957 err_union_ty.fmt(zcu),
99589958 });
99599959 }
99609960
......@@ -10816,7 +10816,7 @@ fn finishSwitchBr(
1081610816 else => {},
1081710817 }
1081810818 return sema.fail(block, else_prong_src, "cannot enumerate values of type '{f}' for 'inline else'", .{
10819 item_ty.fmt(pt),
10819 item_ty.fmt(zcu),
1082010820 });
1082110821 };
1082210822 var unhandled_it = validated_switch.iterateUnhandledItems(error_names, min_int);
......@@ -11252,7 +11252,7 @@ fn validateSwitchBlock(
1125211252
1125311253 .optional => return sema.failWithOwnedErrorMsg(block, msg: {
1125411254 const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{
11255 operand_ty.fmt(pt),
11255 operand_ty.fmt(zcu),
1125611256 });
1125711257 errdefer msg.destroy(gpa);
1125811258 try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
......@@ -11261,7 +11261,7 @@ fn validateSwitchBlock(
1126111261
1126211262 .error_union => return sema.failWithOwnedErrorMsg(block, msg: {
1126311263 const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{
11264 operand_ty.fmt(pt),
11264 operand_ty.fmt(zcu),
1126511265 });
1126611266 errdefer msg.destroy(gpa);
1126711267 try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{});
......@@ -11281,14 +11281,14 @@ fn validateSwitchBlock(
1128111281 .spirv,
1128211282 => {},
1128311283 }
11284 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)});
11284 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(zcu)});
1128511285 };
1128611286
1128711287 if (zir_switch.has_continue and !block.isComptime()) {
1128811288 if (operand_ty.comptimeOnly(zcu)) {
1128911289 // Even if the operand is comptime-known, this `switch` is runtime.
1129011290 return sema.failWithOwnedErrorMsg(block, msg: {
11291 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(pt)});
11291 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(zcu)});
1129211292 errdefer msg.destroy(gpa);
1129311293 try sema.errNote(operand_src, msg, "switch loops are evaluated at runtime outside of comptime scopes", .{});
1129411294 try sema.explainWhyTypeIsComptime(msg, operand_src, operand_ty);
......@@ -11404,7 +11404,7 @@ fn validateSwitchBlock(
1140411404 const msg = try sema.errMsg(
1140511405 operand_src,
1140611406 "ranges not allowed when switching on type '{f}'",
11407 .{operand_ty.fmt(pt)},
11407 .{operand_ty.fmt(zcu)},
1140811408 );
1140911409 errdefer msg.destroy(gpa);
1141011410 try sema.errNote(
......@@ -11466,7 +11466,7 @@ fn validateSwitchBlock(
1146611466 item_ty.srcLoc(zcu),
1146711467 msg,
1146811468 "enum '{f}' declared here",
11469 .{item_ty.fmt(pt)},
11469 .{item_ty.fmt(zcu)},
1147011470 );
1147111471 break :msg msg;
1147211472 };
......@@ -11589,7 +11589,7 @@ fn validateSwitchBlock(
1158911589 block,
1159011590 src,
1159111591 "else prong required when switching on type '{f}'",
11592 .{item_ty.fmt(pt)},
11592 .{item_ty.fmt(zcu)},
1159311593 );
1159411594 }
1159511595 },
......@@ -12655,7 +12655,7 @@ fn validateSwitchItemOrRange(
1265512655 if (overlap_start.eql(overlap_end, item_ty, zcu)) {
1265612656 return sema.failWithOwnedErrorMsg(block, msg: {
1265712657 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12658 overlap_start.fmtValueSema(pt, sema),
12658 overlap_start.fmtValueSema(sema),
1265912659 });
1266012660 errdefer msg.destroy(sema.gpa);
1266112661 if (prev_range.first.eql(prev_range.last, item_ty, zcu)) {
......@@ -12677,7 +12677,7 @@ fn validateSwitchItemOrRange(
1267712677 } else {
1267812678 try sema.errNote(prev_range.src, msg, "overlaps with previous range here", .{});
1267912679 try sema.errNote(prev_range.src, msg, "ranges overlap from '{f}' to '{f}'", .{
12680 overlap_start.fmtValueSema(pt, sema), overlap_end.fmtValueSema(pt, sema),
12680 overlap_start.fmtValueSema(sema), overlap_end.fmtValueSema(sema),
1268112681 });
1268212682 }
1268312683 break :msg msg;
......@@ -12719,7 +12719,7 @@ fn validateSwitchItemOrRange(
1271912719 if (maybe_prev_src) |prev_src| {
1272012720 return sema.failWithOwnedErrorMsg(block, msg: {
1272112721 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12722 item_val.fmtValueSema(pt, sema),
12722 item_val.fmtValueSema(sema),
1272312723 });
1272412724 errdefer msg.destroy(sema.gpa);
1272512725 try sema.errNote(prev_src, msg, "previous value here", .{});
......@@ -12876,7 +12876,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1287612876 else => {},
1287712877 }
1287812878 return sema.fail(block, ty_src, "type '{f}' does not support '@hasField'", .{
12879 ty.fmt(pt),
12879 ty.fmt(zcu),
1288012880 });
1288112881 };
1288212882 return if (has_field) .bool_true else .bool_false;
......@@ -13087,7 +13087,7 @@ fn zirShl(
1308713087 break :rs lhs_src;
1308813088 } else {
1308913089 if (air_tag == .shl_sat and scalar_rhs_ty.isSignedInt(zcu)) {
13090 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(pt)});
13090 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(zcu)});
1309113091 }
1309213092 if (scalar_ty.toIntern() == .comptime_int_type) {
1309313093 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
......@@ -13369,7 +13369,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1336913369 const scalar_tag = scalar_ty.zigTypeTag(zcu);
1337013370
1337113371 if (scalar_tag != .int and scalar_tag != .bool)
13372 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(pt)});
13372 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(zcu)});
1337313373
1337413374 return analyzeBitNot(sema, block, operand, src);
1337513375}
......@@ -13505,11 +13505,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1350513505
1350613506 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
1350713507 if (lhs_is_tuple) break :lhs_info undefined;
13508 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(pt)});
13508 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(zcu)});
1350913509 };
1351013510 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {
1351113511 assert(!rhs_is_tuple);
13512 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(pt)});
13512 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(zcu)});
1351313513 };
1351413514
1351513515 const resolved_elem_ty = t: {
......@@ -13933,7 +13933,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1393313933 .int, .comptime_int, .float, .comptime_float => false,
1393413934 else => true,
1393513935 }) {
13936 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)});
13936 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)});
1393713937 }
1393813938
1393913939 if (rhs_scalar_ty.isAnyFloat()) {
......@@ -13964,7 +13964,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1396413964
1396513965 switch (rhs_scalar_ty.zigTypeTag(zcu)) {
1396613966 .int, .comptime_int, .float, .comptime_float => {},
13967 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)}),
13967 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)}),
1396813968 }
1396913969
1397013970 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try pt.intValue(rhs_scalar_ty, 0))).toIntern());
......@@ -14036,7 +14036,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1403614036 block,
1403714037 src,
1403814038 "ambiguous coercion of division operands '{f}' and '{f}'; non-zero remainder '{f}'",
14039 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValueSema(pt, sema) },
14039 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), rem.fmtValueSema(sema) },
1404014040 );
1404114041 }
1404214042 }
......@@ -14087,7 +14087,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1408714087 block,
1408814088 src,
1408914089 "division with '{f}' and '{f}': signed integers must use @divTrunc, @divFloor, @divCeil, or @divExact",
14090 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt) },
14090 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu) },
1409114091 );
1409214092 }
1409314093 break :blk .div_trunc;
......@@ -14804,7 +14804,7 @@ fn zirOverflowArithmetic(
1480414804 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);
1480514805
1480614806 if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .int) {
14807 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(pt)});
14807 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(zcu)});
1480814808 }
1480914809
1481014810 const maybe_lhs_val = sema.resolveValue(lhs);
......@@ -15064,7 +15064,7 @@ fn analyzeArithmetic(
1506415064 };
1506515065 if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) {
1506615066 return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{
15067 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
15067 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
1506815068 });
1506915069 }
1507015070
......@@ -15072,7 +15072,7 @@ fn analyzeArithmetic(
1507215072 const elem_size = lhs_elem_ty.abiSize(zcu);
1507315073 if (elem_size == 0) {
1507415074 return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{
15075 lhs_elem_ty.fmt(pt),
15075 lhs_elem_ty.fmt(zcu),
1507615076 });
1507715077 }
1507815078
......@@ -15379,20 +15379,20 @@ fn zirAsm(
1537915379 .int, .float, .bool, .vector => {},
1538015380
1538115381 .pointer => if (out_ty.isSlice(zcu)) return sema.failWithOwnedErrorMsg(block, msg: {
15382 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15382 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1538315383 errdefer msg.destroy(gpa);
1538415384 try sema.errNote(output_src, msg, "consider separate outputs for 'ptr' and 'len'", .{});
1538515385 break :msg msg;
1538615386 }),
1538715387
1538815388 .optional => if (!out_ty.isPtrLikeOptional(zcu)) {
15389 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15389 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1539015390 },
1539115391
1539215392 .@"enum" => switch (ip.loadEnumType(out_ty.toIntern()).int_tag_mode) {
1539315393 .explicit => {},
1539415394 .auto => return sema.failWithOwnedErrorMsg(block, msg: {
15395 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15395 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1539615396 errdefer msg.destroy(gpa);
1539715397 try sema.errNote(out_ty.srcLoc(zcu), msg, "integer tag type of enum is inferred", .{});
1539815398 try sema.errNote(out_ty.srcLoc(zcu), msg, "consider explicitly specifying the integer tag type", .{});
......@@ -15403,7 +15403,7 @@ fn zirAsm(
1540315403 .@"struct" => switch (out_ty.containerLayout(zcu)) {
1540415404 .@"packed" => {},
1540515405 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15406 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15406 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1540715407 errdefer msg.destroy(gpa);
1540815408 try sema.errNote(output_src, msg, "struct types cannot be passed to inline assembly", .{});
1540915409 try sema.addDeclaredHereNote(msg, out_ty);
......@@ -15414,7 +15414,7 @@ fn zirAsm(
1541415414 .@"union" => switch (out_ty.containerLayout(zcu)) {
1541515415 .@"packed" => {},
1541615416 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15417 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15417 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1541815418 errdefer msg.destroy(gpa);
1541915419 try sema.errNote(output_src, msg, "union types cannot be passed to inline assembly", .{});
1542015420 try sema.addDeclaredHereNote(msg, out_ty);
......@@ -15423,7 +15423,7 @@ fn zirAsm(
1542315423 },
1542415424
1542515425 .array => return sema.failWithOwnedErrorMsg(block, msg: {
15426 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15426 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1542715427 errdefer msg.destroy(gpa);
1542815428 try sema.errNote(output_src, msg, "array types cannot be passed to inline assembly", .{});
1542915429 break :msg msg;
......@@ -15444,7 +15444,7 @@ fn zirAsm(
1544415444 .@"anyframe",
1544515445 .enum_literal,
1544615446 .spirv,
15447 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}),
15447 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}),
1544815448 }
1544915449
1545015450 const constraint = sema.code.nullTerminatedString(output.data.constraint);
......@@ -15500,7 +15500,7 @@ fn zirAsm(
1550015500 },
1550115501 else => true,
1550215502 };
15503 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(pt)});
15503 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(zcu)});
1550415504 }
1550515505 needed_capacity += (constraint.len + name.len + (2 + 3)) / 4;
1550615506 inputs[arg_i] = .{ .c = constraint, .n = name };
......@@ -15598,7 +15598,7 @@ fn zirCmpEq(
1559815598
1559915599 if (lhs_ty_tag == .null or rhs_ty_tag == .null) {
1560015600 const non_null_type = if (lhs_ty_tag == .null) rhs_ty else lhs_ty;
15601 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(pt)});
15601 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(zcu)});
1560215602 }
1560315603
1560415604 if (lhs_ty_tag == .@"union" and (rhs_ty_tag == .enum_literal or rhs_ty_tag == .@"enum")) {
......@@ -15654,7 +15654,7 @@ fn analyzeCmpUnionTag(
1565415654 const msg = msg: {
1565515655 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1565615656 errdefer msg.destroy(sema.gpa);
15657 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(pt)});
15657 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(zcu)});
1565815658 break :msg msg;
1565915659 };
1566015660 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -15738,7 +15738,7 @@ fn analyzeCmp(
1573815738 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
1573915739 if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) {
1574015740 return sema.fail(block, src, "operator {s} not allowed for type '{f}'", .{
15741 compareOperatorName(op), resolved_type.fmt(pt),
15741 compareOperatorName(op), resolved_type.fmt(zcu),
1574215742 });
1574315743 }
1574415744 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
......@@ -15844,11 +15844,11 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1584415844 try sema.ensureLayoutResolved(ty, operand_src, .size_of);
1584515845 switch (ty.classify(zcu)) {
1584615846 .no_possible_value,
15847 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(pt)}),
15847 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(zcu)}),
1584815848
1584915849 .partially_comptime,
1585015850 .fully_comptime,
15851 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(pt)}),
15851 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(zcu)}),
1585215852
1585315853 .one_possible_value => {
1585415854 assert(ty.abiSize(zcu) == 0);
......@@ -15871,7 +15871,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1587115871 operand_ty.zigTypeTag(zcu) != .error_set and
1587215872 operand_ty.zigTypeTag(zcu) != .@"enum")
1587315873 {
15874 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(pt)});
15874 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(zcu)});
1587515875 }
1587615876 try sema.ensureLayoutResolved(operand_ty, operand_src, .size_of);
1587715877 return .fromValue(try pt.intValue(.comptime_int, operand_ty.bitSize(zcu)));
......@@ -17356,7 +17356,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1735617356 block,
1735717357 src,
1735817358 "bit shifting operation expected integer type, found '{f}'",
17359 .{operand.fmt(pt)},
17359 .{operand.fmt(zcu)},
1736017360 );
1736117361}
1736217362
......@@ -17413,7 +17413,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1741317413 if (uncasted_ty.isVector(zcu)) {
1741417414 if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) {
1741517415 return sema.fail(block, operand_src, "boolean not operation on type '{f}'", .{
17416 uncasted_ty.fmt(pt),
17416 uncasted_ty.fmt(zcu),
1741717417 });
1741817418 }
1741917419 return analyzeBitNot(sema, block, uncasted_operand, src);
......@@ -17589,7 +17589,7 @@ fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi
1758917589 const pt = sema.pt;
1759017590 const zcu = pt.zcu;
1759117591 if (!ty.isSelfComparable(zcu, true)) {
17592 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(pt)});
17592 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(zcu)});
1759317593 }
1759417594}
1759517595
......@@ -17641,7 +17641,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1764117641 switch (ty.zigTypeTag(zcu)) {
1764217642 .error_set, .error_union, .undefined => return,
1764317643 else => return sema.fail(block, src, "expected error union type, found '{f}'", .{
17644 ty.fmt(pt),
17644 ty.fmt(zcu),
1764517645 }),
1764617646 }
1764717647}
......@@ -17779,7 +17779,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1777917779 const zcu = pt.zcu;
1778017780 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
1778117781 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17782 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
17782 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
1778317783 errdefer msg.destroy(sema.gpa);
1778417784 try sema.addDeclaredHereNote(msg, err_union_ty);
1778517785 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -17847,7 +17847,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1784717847 const zcu = pt.zcu;
1784817848 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
1784917849 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17850 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
17850 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
1785117851 errdefer msg.destroy(sema.gpa);
1785217852 try sema.addDeclaredHereNote(msg, err_union_ty);
1785317853 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -18046,7 +18046,7 @@ fn zirRetImplicit(
1804618046 if (base_tag == .noreturn) {
1804718047 const msg = msg: {
1804818048 const msg = try sema.errMsg(ret_ty_src, "function declared '{f}' implicitly returns", .{
18049 sema.fn_ret_ty.fmt(pt),
18049 sema.fn_ret_ty.fmt(zcu),
1805018050 });
1805118051 errdefer msg.destroy(sema.gpa);
1805218052 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
......@@ -18056,7 +18056,7 @@ fn zirRetImplicit(
1805618056 } else if (base_tag != .void) {
1805718057 const msg = msg: {
1805818058 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{f}' implicitly returns", .{
18059 sema.fn_ret_ty.fmt(pt),
18059 sema.fn_ret_ty.fmt(zcu),
1806018060 });
1806118061 errdefer msg.destroy(sema.gpa);
1806218062 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
......@@ -18467,7 +18467,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1846718467 if (host_size != 0) {
1846818468 try sema.ensureLayoutResolved(elem_ty, elem_ty_src, .bit_ptr_child);
1846918469 if (elem_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
18470 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(pt)});
18470 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(zcu)});
1847118471 errdefer msg.destroy(sema.gpa);
1847218472 try sema.explainWhyTypeIsUnpackable(msg, elem_ty_src, reason);
1847318473 break :msg msg;
......@@ -18475,12 +18475,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1847518475 const elem_bit_size = elem_ty.bitSize(zcu);
1847618476 if (bit_offset >= host_size * 8) {
1847718477 return sema.fail(block, bitoffset_src, "packed type '{f}' at bit offset {d} starts {d} bits after the end of a {d} byte host integer", .{
18478 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,
18478 elem_ty.fmt(zcu), bit_offset, bit_offset - host_size * 8, host_size,
1847918479 });
1848018480 }
1848118481 if (elem_bit_size > host_size * 8 - bit_offset) {
1848218482 return sema.fail(block, bitoffset_src, "packed type '{f}' at bit offset {d} ends {d} bits after the end of a {d} byte host integer", .{
18483 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
18483 elem_ty.fmt(zcu), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
1848418484 });
1848518485 }
1848618486 }
......@@ -18490,7 +18490,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1849018490 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
1849118491 }
1849218492 } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {
18493 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)});
18493 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)});
1849418494 }
1849518495
1849618496 const ty = try pt.ptrType(.{
......@@ -18652,7 +18652,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1865218652 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
1865318653 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
1865418654 if (union_ty.zigTypeTag(pt.zcu) != .@"union") {
18655 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(pt)});
18655 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(zcu)});
1865618656 }
1865718657 union_ty.assertHasLayout(zcu); // from a previous `field_type_ref` instruction
1865818658 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_names });
......@@ -18784,7 +18784,7 @@ fn zirStructInit(
1878418784
1878518785 if (field_ty.classify(zcu) == .no_possible_value) {
1878618786 return sema.failWithOwnedErrorMsg(block, msg: {
18787 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
18787 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
1878818788 errdefer msg.destroy(sema.gpa);
1878918789
1879018790 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{f}' declared here", .{
......@@ -19573,7 +19573,7 @@ fn fieldType(
1957319573 else => {},
1957419574 }
1957519575 return sema.fail(block, ty_src, "expected struct or union; found '{f}'", .{
19576 cur_ty.fmt(pt),
19576 cur_ty.fmt(zcu),
1957719577 });
1957819578 }
1957919579}
......@@ -19627,7 +19627,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1962719627 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1962819628 try sema.ensureLayoutResolved(ty, operand_src, .align_of);
1962919629 if (ty.isNoReturn(zcu)) {
19630 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)});
19630 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(zcu)});
1963119631 }
1963219632 return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?));
1963319633}
......@@ -19702,7 +19702,7 @@ fn zirAbs(
1970219702 block,
1970319703 operand_src,
1970419704 "expected integer, float, or vector of either integers or floats, found '{f}'",
19705 .{operand_ty.fmt(pt)},
19705 .{operand_ty.fmt(zcu)},
1970619706 ),
1970719707 };
1970819708
......@@ -19763,7 +19763,7 @@ fn unaryMath(
1976319763 block,
1976419764 operand_src,
1976519765 "expected vector of floats or float type, found '{f}'",
19766 .{operand_ty.fmt(pt)},
19766 .{operand_ty.fmt(zcu)},
1976719767 ),
1976819768 }
1976919769
......@@ -19804,9 +19804,9 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1980419804 },
1980519805 .@"enum" => operand_ty,
1980619806 .@"union" => operand_ty.unionTagType(zcu) orelse
19807 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(pt)}),
19807 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(zcu)}),
1980819808 else => return sema.fail(block, operand_src, "expected enum or union; found '{f}'", .{
19809 operand_ty.fmt(pt),
19809 operand_ty.fmt(zcu),
1981019810 }),
1981119811 };
1981219812 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
......@@ -19814,7 +19814,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1981419814 const field_index = enum_ty.enumTagFieldIndex(val, zcu) orelse {
1981519815 const msg = msg: {
1981619816 const msg = try sema.errMsg(src, "no field with value '{f}' in enum '{f}'", .{
19817 val.fmtValueSema(pt, sema), enum_ty.fmt(pt),
19817 val.fmtValueSema(sema), enum_ty.fmt(zcu),
1981819818 });
1981919819 errdefer msg.destroy(sema.gpa);
1982019820 try sema.errNote(enum_ty.srcLoc(zcu), msg, "declared here", .{});
......@@ -20026,7 +20026,7 @@ fn zirReifyPointer(
2002620026 },
2002720027 .@"opaque" => switch (size) {
2002820028 .one => {},
20029 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}),
20029 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)}),
2003020030 },
2003120031 else => {},
2003220032 }
......@@ -20962,7 +20962,7 @@ fn zirReifySpirvType(
2096220962 if (sampled_type.toIntern() != .void_type and
2096320963 (!sampled_type.hasRuntimeBits(zcu) or (!sampled_type.isRuntimeFloat() and !sampled_type.isInt(zcu))))
2096420964 {
20965 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(pt) });
20965 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(zcu) });
2096620966 }
2096720967
2096820968 if (target.os.tag == .vulkan) {
......@@ -20994,7 +20994,7 @@ fn zirReifySpirvType(
2099420994 block,
2099520995 operand_src,
2099620996 "image 'format' '.{t}' does not match '{t}' type '{f}' under the 'vulkan' OS",
20997 .{ format, usage_tag, sampled_type.fmt(pt) },
20997 .{ format, usage_tag, sampled_type.fmt(zcu) },
2099820998 );
2099920999 }
2100021000 }
......@@ -21017,7 +21017,7 @@ fn zirReifySpirvType(
2101721017 .sampled_image => blk: {
2101821018 const image_ty = Value.fromInterned(union_val.val).toType();
2101921019 if (image_ty.zigTypeTag(zcu) != .spirv or ip.loadSpirvType(image_ty.toIntern()).flags.tag != .image) {
21020 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(pt)});
21020 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(zcu)});
2102121021 }
2102221022 const image_info = ip.loadSpirvType(image_ty.toIntern()).flags;
2102321023 if (image_info.usage != .sampled) {
......@@ -21077,6 +21077,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
2107721077}
2107821078
2107921079fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21080 const zcu = sema.pt.zcu;
2108021081 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2108121082 const src = block.nodeOffset(extra.node);
2108221083 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
......@@ -21085,9 +21086,9 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2108521086 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
2108621087 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2108721088 try sema.ensureLayoutResolved(arg_ty, ty_src, .parameter);
21088 if (!arg_ty.validateExtern(.param_ty, sema.pt.zcu)) {
21089 if (!arg_ty.validateExtern(.param_ty, zcu)) {
2108921090 const msg = msg: {
21090 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(sema.pt)});
21091 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(zcu)});
2109121092 errdefer msg.destroy(sema.gpa);
2109221093
2109321094 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
......@@ -21150,7 +21151,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2115021151 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2115121152 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2115221153
21153 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(pt)}, .no_embedded_nulls);
21154 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(zcu)}, .no_embedded_nulls);
2115421155 return sema.addNullTerminatedStrLit(type_name);
2115521156}
2115621157
......@@ -21179,7 +21180,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2117921180
2118021181 switch (dest_scalar_ty.zigTypeTag(zcu)) {
2118121182 .comptime_int, .int => {},
21182 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),
21183 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
2118321184 }
2118421185 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
2118521186
......@@ -21260,7 +21261,7 @@ fn zirRoundCast(
2126021261 block,
2126121262 operand_src,
2126221263 "expected float or vector type, found '{f}'",
21263 .{operand_ty.fmt(pt)},
21264 .{operand_ty.fmt(zcu)},
2126421265 ),
2126521266 }
2126621267
......@@ -21294,7 +21295,7 @@ fn zirRoundCast(
2129421295 block,
2129521296 src,
2129621297 "expected integer, float, or vector of either integers or floats, found '{f}'",
21297 .{dest_ty.fmt(pt)},
21298 .{dest_ty.fmt(zcu)},
2129821299 ),
2129921300 }
2130021301
......@@ -21358,7 +21359,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2135821359
2135921360 switch (dest_scalar_ty.zigTypeTag(zcu)) {
2136021361 .comptime_float, .float => {},
21361 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),
21362 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
2136221363 }
2136321364 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
2136421365
......@@ -21418,7 +21419,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2141821419
2141921420 if (ptr_ty.isSlice(zcu)) {
2142021421 const msg = msg: {
21421 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(pt)});
21422 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(zcu)});
2142221423 errdefer msg.destroy(sema.gpa);
2142321424 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
2142421425 break :msg msg;
......@@ -21491,7 +21492,7 @@ fn ptrFromIntVal(
2149121492 }
2149221493 const addr = operand_val.toUnsignedInt(zcu);
2149321494 if (!ptr_ty.isAllowzeroPtr(zcu) and addr == 0)
21494 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(pt)});
21495 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(zcu)});
2149521496 if (addr != 0 and ptr_align != .none) {
2149621497 const masked_addr = if (ptr_ty.childType(zcu).fnPtrMaskOrNull(zcu)) |mask|
2149721498 addr & mask
......@@ -21499,7 +21500,7 @@ fn ptrFromIntVal(
2149921500 addr;
2150021501
2150121502 if (!ptr_align.check(masked_addr)) {
21502 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(pt)});
21503 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(zcu)});
2150321504 }
2150421505 }
2150521506
......@@ -21544,8 +21545,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2154421545 errdefer msg.destroy(sema.gpa);
2154521546 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
2154621547 const operand_payload_ty = operand_ty.errorUnionPayload(zcu);
21547 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(pt)});
21548 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(pt)});
21548 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(zcu)});
21549 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(zcu)});
2154921550 try addDeclaredHereNote(sema, msg, dest_ty);
2155021551 try addDeclaredHereNote(sema, msg, operand_ty);
2155121552 break :msg msg;
......@@ -21619,7 +21620,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2161921620
2162021621 if (result == .disjoint and !(operand_tag == .error_union and dest_tag == .error_union)) {
2162121622 return sema.fail(block, src, "error sets '{f}' and '{f}' have no common errors", .{
21622 operand_err_ty.fmt(pt), dest_err_ty.fmt(pt),
21623 operand_err_ty.fmt(zcu), dest_err_ty.fmt(zcu),
2162321624 });
2162421625 }
2162521626
......@@ -21644,7 +21645,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2164421645
2164521646 if (result != .superset and !dest_err_ty.errorSetHasField(err_name, zcu)) {
2164621647 return sema.fail(block, src, "'error.{f}' not a member of error set '{f}'", .{
21647 err_name.fmt(ip), dest_err_ty.fmt(pt),
21648 err_name.fmt(ip), dest_err_ty.fmt(zcu),
2164821649 });
2164921650 }
2165021651
......@@ -21809,7 +21810,7 @@ fn ptrCastFull(
2180921810 if (src_elem_ty.zigTypeTag(zcu) == .@"opaque") {
2181021811 return sema.failWithOwnedErrorMsg(block, msg: {
2181121812 const msg = try sema.errMsg(src, "cannot infer length of slice of '{f}' from pointer to opaque type '{f}' with unknown size", .{
21812 dest_elem_ty.fmt(pt), src_elem_ty.fmt(pt),
21813 dest_elem_ty.fmt(zcu), src_elem_ty.fmt(zcu),
2181321814 });
2181421815 errdefer msg.destroy(gpa);
2181521816 try sema.addDeclaredHereNote(msg, src_elem_ty);
......@@ -21820,14 +21821,14 @@ fn ptrCastFull(
2182021821 const dest_elem_size = dest_elem_ty.abiSize(zcu);
2182121822 if (dest_elem_size == 0) {
2182221823 return sema.fail(block, src, "cannot infer length of slice of zero-bit '{f}' from '{f}'", .{
21823 dest_elem_ty.fmt(pt), operand_ty.fmt(pt),
21824 dest_elem_ty.fmt(zcu), operand_ty.fmt(zcu),
2182421825 });
2182521826 }
2182621827 if (opt_src_len) |src_len| {
2182721828 const bytes = src_len * src_elem_size;
2182821829 const dest_len = std.math.divExact(u64, bytes, dest_elem_size) catch switch (src_info.flags.size) {
2182921830 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21830 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(pt)}),
21831 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(zcu)}),
2183121832 else => unreachable,
2183221833 };
2183321834 break :len .{ .constant = dest_len };
......@@ -21846,7 +21847,7 @@ fn ptrCastFull(
2184621847 // The result value will have `dest_len * dest_base_per_elem` values of type `dest_base_ty`.
2184721848 if (dest_base_ty.toIntern() != src_base_ty.toIntern()) {
2184821849 return sema.fail(block, src, "cannot infer length of comptime-only '{f}' from incompatible '{f}'", .{
21849 dest_ty.fmt(pt), operand_ty.fmt(pt),
21850 dest_ty.fmt(zcu), operand_ty.fmt(zcu),
2185021851 });
2185121852 }
2185221853 // `src_base_ty` is comptime-only, so `src_elem_ty` is comptime-only, so `operand_ty` is
......@@ -21855,7 +21856,7 @@ fn ptrCastFull(
2185521856 const base_len = src_len * src_base_per_elem;
2185621857 const dest_len = std.math.divExact(u64, base_len, dest_base_per_elem) catch switch (src_info.flags.size) {
2185721858 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21858 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(pt)}),
21859 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(zcu)}),
2185921860 else => unreachable,
2186021861 };
2186121862 break :len .{ .constant = dest_len };
......@@ -21917,7 +21918,7 @@ fn ptrCastFull(
2191721918 if (imc_res == .ok) break :check_child;
2191821919 return sema.failWithOwnedErrorMsg(block, msg: {
2191921920 const msg = try sema.errMsg(src, "pointer element type '{f}' cannot coerce into element type '{f}'", .{
21920 src_child.fmt(pt), dest_child.fmt(pt),
21921 src_child.fmt(zcu), dest_child.fmt(zcu),
2192121922 });
2192221923 errdefer msg.destroy(sema.gpa);
2192321924 try imc_res.report(sema, src, msg);
......@@ -21944,12 +21945,12 @@ fn ptrCastFull(
2194421945 return sema.failWithOwnedErrorMsg(block, msg: {
2194521946 const msg = if (src_info.sentinel == .none) blk: {
2194621947 break :blk try sema.errMsg(src, "destination pointer requires '{f}' sentinel", .{
21947 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
21948 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
2194821949 });
2194921950 } else blk: {
2195021951 break :blk try sema.errMsg(src, "pointer sentinel '{f}' cannot coerce into pointer sentinel '{f}'", .{
21951 Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema),
21952 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
21952 Value.fromInterned(src_info.sentinel).fmtValueSema(sema),
21953 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
2195321954 });
2195421955 };
2195521956 errdefer msg.destroy(sema.gpa);
......@@ -21990,8 +21991,8 @@ fn ptrCastFull(
2199021991
2199121992 return sema.failWithOwnedErrorMsg(block, msg: {
2199221993 const msg = try sema.errMsg(src, "'{f}' could have null values which are illegal in type '{f}'", .{
21993 operand_ty.fmt(pt),
21994 dest_ty.fmt(pt),
21994 operand_ty.fmt(zcu),
21995 dest_ty.fmt(zcu),
2199521996 });
2199621997 errdefer msg.destroy(sema.gpa);
2199721998 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
......@@ -22018,10 +22019,10 @@ fn ptrCastFull(
2201822019 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
2201922020 errdefer msg.destroy(sema.gpa);
2202022021 try sema.errNote(operand_src, msg, "'{f}' has alignment '{d}'", .{
22021 operand_ty.fmt(pt), src_align.toByteUnits() orelse 0,
22022 operand_ty.fmt(zcu), src_align.toByteUnits() orelse 0,
2202222023 });
2202322024 try sema.errNote(src, msg, "'{f}' has alignment '{d}'", .{
22024 dest_ty.fmt(pt), dest_align.toByteUnits() orelse 0,
22025 dest_ty.fmt(zcu), dest_align.toByteUnits() orelse 0,
2202522026 });
2202622027 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
2202722028 break :msg msg;
......@@ -22035,10 +22036,10 @@ fn ptrCastFull(
2203522036 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
2203622037 errdefer msg.destroy(sema.gpa);
2203722038 try sema.errNote(operand_src, msg, "'{f}' has address space '{s}'", .{
22038 operand_ty.fmt(pt), @tagName(src_info.flags.address_space),
22039 operand_ty.fmt(zcu), @tagName(src_info.flags.address_space),
2203922040 });
2204022041 try sema.errNote(src, msg, "'{f}' has address space '{s}'", .{
22041 dest_ty.fmt(pt), @tagName(dest_info.flags.address_space),
22042 dest_ty.fmt(zcu), @tagName(dest_info.flags.address_space),
2204222043 });
2204322044 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
2204422045 break :msg msg;
......@@ -22104,7 +22105,7 @@ fn ptrCastFull(
2210422105
2210522106 if (operand_val.isNull(zcu)) {
2210622107 if (!dest_ty.ptrAllowsZero(zcu)) {
22107 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});
22108 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
2210822109 }
2210922110 if (dest_ty.zigTypeTag(zcu) == .optional) {
2211022111 return Air.internedToRef((try pt.nullValue(dest_ty)).toIntern());
......@@ -22418,7 +22419,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2241822419
2241922420 if (operand_info.signedness != dest_info.signedness) {
2242022421 return sema.fail(block, operand_src, "expected {s} integer type, found '{f}'", .{
22421 @tagName(dest_info.signedness), operand_ty.fmt(pt),
22422 @tagName(dest_info.signedness), operand_ty.fmt(zcu),
2242222423 });
2242322424 }
2242422425 if (dest_info.bits >= operand_info.bits) {
......@@ -22503,7 +22504,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2250322504 block,
2250422505 operand_src,
2250522506 "@byteSwap requires the number of bits to be evenly divisible by 8, but {f} has {d} bits",
22506 .{ scalar_ty.fmt(pt), bits },
22507 .{ scalar_ty.fmt(zcu), bits },
2250722508 );
2250822509 }
2250922510 if (sema.resolveValue(operand)) |operand_val| {
......@@ -22553,7 +22554,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2255322554 const ip = &zcu.intern_pool;
2255422555 switch (ty.zigTypeTag(zcu)) {
2255522556 .@"struct" => {},
22556 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(pt)}),
22557 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(zcu)}),
2255722558 }
2255822559
2255922560 const field_index = if (ty.isTuple(zcu)) blk: {
......@@ -22588,7 +22589,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
2258822589 const zcu = pt.zcu;
2258922590 switch (ty.zigTypeTag(zcu)) {
2259022591 .@"struct", .@"enum", .@"union", .@"opaque" => return,
22591 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(pt)}),
22592 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(zcu)}),
2259222593 }
2259322594}
2259422595
......@@ -22599,7 +22600,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr
2259922600 switch (ty.zigTypeTag(zcu)) {
2260022601 .comptime_int => return true,
2260122602 .int => return false,
22602 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(pt)}),
22603 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(zcu)}),
2260322604 }
2260422605}
2260522606
......@@ -22654,7 +22655,7 @@ fn checkPtrOperand(
2265422655 const msg = try sema.errMsg(
2265522656 ty_src,
2265622657 "expected pointer, found '{f}'",
22657 .{ty.fmt(pt)},
22658 .{ty.fmt(zcu)},
2265822659 );
2265922660 errdefer msg.destroy(sema.gpa);
2266022661
......@@ -22667,7 +22668,7 @@ fn checkPtrOperand(
2266722668 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
2266822669 else => {},
2266922670 }
22670 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});
22671 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
2267122672}
2267222673
2267322674fn checkPtrType(
......@@ -22686,7 +22687,7 @@ fn checkPtrType(
2268622687 const msg = try sema.errMsg(
2268722688 ty_src,
2268822689 "expected pointer type, found '{f}'",
22689 .{ty.fmt(pt)},
22690 .{ty.fmt(zcu)},
2269022691 );
2269122692 errdefer msg.destroy(sema.gpa);
2269222693
......@@ -22699,7 +22700,7 @@ fn checkPtrType(
2269922700 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
2270022701 else => {},
2270122702 }
22702 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});
22703 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
2270322704}
2270422705
2270522706fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
......@@ -22712,7 +22713,7 @@ fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2271222713 const as = ty.ptrAddressSpace(zcu);
2271322714 if (target_util.shouldBlockPointerOps(target, as)) {
2271422715 return sema.failWithOwnedErrorMsg(block, msg: {
22715 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(pt)});
22716 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(zcu)});
2271622717 errdefer msg.destroy(sema.gpa);
2271722718 try sema.errNote(
2271822719 src,
......@@ -22761,9 +22762,9 @@ fn checkLogicalPtrCast(
2276122762 },
2276222763 else => null,
2276322764 } orelse return sema.failWithOwnedErrorMsg(block, msg: {
22764 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(pt), dest_ty.fmt(pt) });
22765 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(zcu), dest_ty.fmt(zcu) });
2276522766 errdefer msg.destroy(sema.gpa);
22766 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(pt), src_child.fmt(pt) });
22767 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(zcu), src_child.fmt(zcu) });
2276722768 break :msg msg;
2276822769 });
2276922770 }
......@@ -22782,7 +22783,7 @@ fn checkVectorElemType(
2278222783 .optional, .pointer => if (ty.isPtrAtRuntime(zcu)) return,
2278322784 else => {},
2278422785 }
22785 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(pt)});
22786 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(zcu)});
2278622787}
2278722788
2278822789fn checkFloatType(
......@@ -22795,7 +22796,7 @@ fn checkFloatType(
2279522796 const zcu = pt.zcu;
2279622797 switch (ty.zigTypeTag(zcu)) {
2279722798 .comptime_int, .comptime_float, .float => {},
22798 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(pt)}),
22799 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(zcu)}),
2279922800 }
2280022801}
2280122802
......@@ -22813,7 +22814,7 @@ fn checkNumericType(
2281322814 .comptime_float, .float, .comptime_int, .int => {},
2281422815 else => |t| return sema.fail(block, ty_src, "expected number, found '{t}'", .{t}),
2281522816 },
22816 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(pt)}),
22817 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(zcu)}),
2281722818 }
2281822819}
2281922820
......@@ -22849,7 +22850,7 @@ fn checkAtomicPtrOperand(
2284922850 block,
2285022851 elem_ty_src,
2285122852 "expected bool, integer, float, enum, packed struct, or pointer type; found '{f}'",
22852 .{elem_ty.fmt(pt)},
22853 .{elem_ty.fmt(zcu)},
2285322854 ),
2285422855 };
2285522856
......@@ -22910,12 +22911,12 @@ fn checkIntOrVector(
2291022911 switch (elem_ty.zigTypeTag(zcu)) {
2291122912 .int => return elem_ty,
2291222913 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22913 elem_ty.fmt(pt),
22914 elem_ty.fmt(zcu),
2291422915 }),
2291522916 }
2291622917 },
2291722918 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22918 operand_ty.fmt(pt),
22919 operand_ty.fmt(zcu),
2291922920 }),
2292022921 }
2292122922}
......@@ -22935,12 +22936,12 @@ fn checkIntOrVectorAllowComptime(
2293522936 switch (elem_ty.zigTypeTag(zcu)) {
2293622937 .int, .comptime_int => return elem_ty,
2293722938 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22938 elem_ty.fmt(pt),
22939 elem_ty.fmt(zcu),
2293922940 }),
2294022941 }
2294122942 },
2294222943 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22943 operand_ty.fmt(pt),
22944 operand_ty.fmt(zcu),
2294422945 }),
2294522946 }
2294622947}
......@@ -23031,7 +23032,7 @@ fn checkVectorizableBinaryOperands(
2303123032 } else {
2303223033 const msg = msg: {
2303323034 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{f}' and '{f}'", .{
23034 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
23035 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
2303523036 });
2303623037 errdefer msg.destroy(sema.gpa);
2303723038 if (lhs_is_vector) {
......@@ -23178,7 +23179,7 @@ fn zirCmpxchg(
2317823179 block,
2317923180 elem_ty_src,
2318023181 "expected bool, integer, enum, packed struct, or pointer type; found '{f}'",
23181 .{elem_ty.fmt(pt)},
23182 .{elem_ty.fmt(zcu)},
2318223183 );
2318323184 }
2318423185 const uncasted_ptr = sema.resolveInst(extra.ptr);
......@@ -23258,7 +23259,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2325823259
2325923260 switch (dest_ty.zigTypeTag(zcu)) {
2326023261 .array, .vector => {},
23261 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(pt)}),
23262 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(zcu)}),
2326223263 }
2326323264
2326423265 const operand = sema.resolveInst(extra.rhs);
......@@ -23307,7 +23308,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2330723308 const zcu = pt.zcu;
2330823309
2330923310 if (operand_ty.zigTypeTag(zcu) != .vector) {
23310 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});
23311 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
2331123312 }
2331223313
2331323314 const scalar_ty = operand_ty.childType(zcu);
......@@ -23317,13 +23318,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2331723318 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
2331823319 .int, .bool => {},
2331923320 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{f}'", .{
23320 @tagName(operation), operand_ty.fmt(pt),
23321 @tagName(operation), operand_ty.fmt(zcu),
2332123322 }),
2332223323 },
2332323324 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
2332423325 .int, .float => {},
2332523326 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{f}'", .{
23326 @tagName(operation), operand_ty.fmt(pt),
23327 @tagName(operation), operand_ty.fmt(zcu),
2332723328 }),
2332823329 },
2332923330 }
......@@ -23378,7 +23379,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2337823379
2337923380 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
2338023381 .array, .vector => sema.typeOf(mask).arrayLen(zcu),
23381 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(pt)}),
23382 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(zcu)}),
2338223383 };
2338323384 mask_ty = try pt.vectorType(.{
2338423385 .len = @intCast(mask_len),
......@@ -23411,7 +23412,7 @@ fn analyzeShuffle(
2341123412 .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)),
2341223413 .undefined => 0,
2341323414 else => return sema.fail(block, a_src, "expected vector of '{f}', found '{f}'", .{
23414 elem_ty.fmt(pt), sema.typeOf(a_uncoerced).fmt(pt),
23415 elem_ty.fmt(zcu), sema.typeOf(a_uncoerced).fmt(zcu),
2341523416 }),
2341623417 };
2341723418 const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() });
......@@ -23422,7 +23423,7 @@ fn analyzeShuffle(
2342223423 .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)),
2342323424 .undefined => 0,
2342423425 else => return sema.fail(block, b_src, "expected vector of '{f}', found '{f}'", .{
23425 elem_ty.fmt(pt), sema.typeOf(b_uncoerced).fmt(pt),
23426 elem_ty.fmt(zcu), sema.typeOf(b_uncoerced).fmt(zcu),
2342623427 }),
2342723428 };
2342823429 const b_ty = try pt.vectorType(.{ .len = b_len, .child = elem_ty.toIntern() });
......@@ -23461,7 +23462,7 @@ fn analyzeShuffle(
2346123462 if (idx >= a_len) return sema.failWithOwnedErrorMsg(block, msg: {
2346223463 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
2346323464 errdefer msg.destroy(sema.gpa);
23464 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(pt) });
23465 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(zcu) });
2346523466 if (idx < b_len) {
2346623467 try sema.errNote(b_src, msg, "use '~@as(u32, {d})' to index into second vector given here", .{idx});
2346723468 }
......@@ -23474,7 +23475,7 @@ fn analyzeShuffle(
2347423475 if (idx >= b_len) return sema.failWithOwnedErrorMsg(block, msg: {
2347523476 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
2347623477 errdefer msg.destroy(sema.gpa);
23477 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(pt) });
23478 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(zcu) });
2347823479 break :msg msg;
2347923480 });
2348023481 }
......@@ -23576,7 +23577,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2357623577
2357723578 const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) {
2357823579 .vector, .array => pred_ty.arrayLen(zcu),
23579 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(pt)}),
23580 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(zcu)}),
2358023581 };
2358123582 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
2358223583
......@@ -23834,7 +23835,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2383423835
2383523836 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
2383623837 .comptime_float, .float => {},
23837 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(pt)}),
23838 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(zcu)}),
2383823839 }
2383923840
2384023841 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
......@@ -23932,7 +23933,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2393223933
2393323934 const args_ty = sema.typeOf(args);
2393423935 if (!args_ty.isTuple(zcu)) {
23935 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(pt)});
23936 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(zcu)});
2393623937 }
2393723938
2393823939 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));
......@@ -23982,13 +23983,13 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2398223983 };
2398323984 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);
2398423985 if (parent_ptr_info.flags.size != .one) {
23985 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(pt)});
23986 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(zcu)});
2398623987 }
2398723988 const parent_ty: Type = .fromInterned(parent_ptr_info.child);
2398823989 try sema.ensureLayoutResolved(parent_ty, inst_src, .field_used);
2398923990 switch (parent_ty.zigTypeTag(zcu)) {
2399023991 .@"struct", .@"union" => {},
23991 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(pt)}),
23992 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(zcu)}),
2399223993 }
2399323994
2399423995 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name });
......@@ -24071,7 +24072,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2407124072
2407224073 if (field.index != field_index) {
2407324074 return sema.fail(block, inst_src, "field '{f}' has index '{d}' but pointer value is index '{d}' of struct '{f}'", .{
24074 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(pt),
24075 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(zcu),
2407524076 });
2407624077 }
2407724078 break :result .fromValue(try pt.getCoerced(.fromInterned(field.base), unaligned_parent_ptr_ty));
......@@ -24113,7 +24114,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2411324114 const msg = try sema.errMsg(inst_src, "@fieldParentPtr increases pointer alignment", .{});
2411424115 errdefer msg.destroy(sema.gpa);
2411524116 try sema.errNote(inst_src, msg, "parent pointer type '{f}' has alignment '{d}'", .{
24116 parent_ptr_ty.fmt(pt),
24117 parent_ptr_ty.fmt(zcu),
2411724118 parent_ptr_ty.abiAlignment(zcu),
2411824119 });
2411924120 if (parent_ty.isTuple(zcu)) {
......@@ -24240,7 +24241,7 @@ fn analyzeMinMax(
2424024241 try sema.checkNumericType(block, operand_src, operand_ty);
2424124242 if (operand_ty.zigTypeTag(zcu) != .vector) {
2424224243 return sema.failWithOwnedErrorMsg(block, msg: {
24243 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});
24244 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
2424424245 errdefer msg.destroy(zcu.gpa);
2424524246 try sema.errNote(operand_srcs[0], msg, "vector operand here", .{});
2424624247 break :msg msg;
......@@ -24248,7 +24249,7 @@ fn analyzeMinMax(
2424824249 }
2424924250 if (operand_ty.vectorLen(zcu) != vec_len) {
2425024251 return sema.failWithOwnedErrorMsg(block, msg: {
24251 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(pt) });
24252 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(zcu) });
2425224253 errdefer msg.destroy(zcu.gpa);
2425324254 try sema.errNote(operand_srcs[0], msg, "vector of length '{d}' here", .{vec_len});
2425424255 break :msg msg;
......@@ -24262,7 +24263,7 @@ fn analyzeMinMax(
2426224263 try sema.checkNumericType(block, operand_src, operand_ty);
2426324264 if (operand_ty.zigTypeTag(zcu) == .vector) {
2426424265 return sema.failWithOwnedErrorMsg(block, msg: {
24265 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(pt)});
24266 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(zcu)});
2426624267 errdefer msg.destroy(zcu.gpa);
2426724268 try sema.errNote(operand_src, msg, "vector operand here", .{});
2426824269 break :msg msg;
......@@ -24580,10 +24581,10 @@ fn zirMemcpy(
2458024581 const msg = try sema.errMsg(src, "unknown copy length", .{});
2458124582 errdefer msg.destroy(sema.gpa);
2458224583 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24583 dest_ty.fmt(pt),
24584 dest_ty.fmt(zcu),
2458424585 });
2458524586 try sema.errNote(src_src, msg, "source type '{f}' provides no length", .{
24586 src_ty.fmt(pt),
24587 src_ty.fmt(zcu),
2458724588 });
2458824589 break :msg msg;
2458924590 };
......@@ -24610,7 +24611,7 @@ fn zirMemcpy(
2461024611 const msg = try sema.errMsg(
2461124612 src,
2461224613 "pointer element type '{f}' cannot coerce into element type '{f}'",
24613 .{ src_elem_ty.fmt(pt), dest_elem_ty.fmt(pt) },
24614 .{ src_elem_ty.fmt(zcu), dest_elem_ty.fmt(zcu) },
2461424615 );
2461524616 errdefer msg.destroy(sema.gpa);
2461624617 try imc.report(sema, src, msg);
......@@ -24629,10 +24630,10 @@ fn zirMemcpy(
2462924630 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
2463024631 errdefer msg.destroy(sema.gpa);
2463124632 try sema.errNote(dest_src, msg, "length {f} here", .{
24632 dest_len_val.fmtValueSema(pt, sema),
24633 dest_len_val.fmtValueSema(sema),
2463324634 });
2463424635 try sema.errNote(src_src, msg, "length {f} here", .{
24635 src_len_val.fmtValueSema(pt, sema),
24636 src_len_val.fmtValueSema(sema),
2463624637 });
2463724638 break :msg msg;
2463824639 };
......@@ -24850,7 +24851,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2485024851 const msg = try sema.errMsg(src, "unknown @memset length", .{});
2485124852 errdefer msg.destroy(sema.gpa);
2485224853 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24853 dest_ptr_ty.fmt(pt),
24854 dest_ptr_ty.fmt(zcu),
2485424855 });
2485524856 break :msg msg;
2485624857 });
......@@ -24896,7 +24897,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2489624897
2489724898 if (comptime_only_elem) {
2489824899 return sema.failWithOwnedErrorMsg(block, msg: {
24899 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(pt)});
24900 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(zcu)});
2490024901 errdefer msg.destroy(sema.gpa);
2490124902 try sema.errNote(dest_src, msg, "operation is runtime due to destination pointer", .{});
2490224903 break :msg msg;
......@@ -25267,16 +25268,16 @@ fn zirBuiltinExtern(
2526725268
2526825269 if (!elem_ty.validateExtern(.other, zcu)) {
2526925270 return sema.failWithOwnedErrorMsg(block, msg: {
25270 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});
25271 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
2527125272 errdefer msg.destroy(sema.gpa);
25272 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(pt)});
25273 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(zcu)});
2527325274 try sema.explainWhyTypeIsNotExtern(msg, ty_src, elem_ty, .other);
2527425275 break :msg msg;
2527525276 });
2527625277 }
2527725278 if (elem_ty.zigTypeTag(zcu) == .@"fn" and !ptr_info.flags.is_const) {
2527825279 return sema.failWithOwnedErrorMsg(block, msg: {
25279 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});
25280 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
2528025281 errdefer msg.destroy(sema.gpa);
2528125282 try sema.errNote(ty_src, msg, "pointer to extern function must be 'const'", .{});
2528225283 break :msg msg;
......@@ -25540,7 +25541,7 @@ fn zirFloatOpResultType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.
2554025541 block,
2554125542 operand_src,
2554225543 "expected vector of floats or float type, found '{f}'",
25543 .{float_ty.fmt(sema.pt)},
25544 .{float_ty.fmt(zcu)},
2554425545 ),
2554525546 }
2554625547
......@@ -25597,7 +25598,7 @@ pub fn validateVarType(
2559725598 if (is_extern) {
2559825599 if (!var_ty.validateExtern(.other, zcu)) {
2559925600 const msg = msg: {
25600 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(pt)});
25601 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(zcu)});
2560125602 errdefer msg.destroy(sema.gpa);
2560225603 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
2560325604 break :msg msg;
......@@ -25610,7 +25611,7 @@ pub fn validateVarType(
2561025611 block,
2561125612 src,
2561225613 "non-extern variable with opaque type '{f}'",
25613 .{var_ty.fmt(pt)},
25614 .{var_ty.fmt(zcu)},
2561425615 );
2561525616 }
2561625617 }
......@@ -25618,7 +25619,7 @@ pub fn validateVarType(
2561825619 if (!var_ty.comptimeOnly(zcu)) return;
2561925620
2562025621 const msg = msg: {
25621 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(pt)});
25622 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(zcu)});
2562225623 errdefer msg.destroy(sema.gpa);
2562325624
2562425625 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
......@@ -25667,7 +25668,7 @@ fn explainWhyTypeIsComptime(
2566725668 .optional => try sema.explainWhyTypeIsComptime(msg, src, ty.optionalChild(zcu)),
2566825669 .error_union => try sema.explainWhyTypeIsComptime(msg, src, ty.errorUnionPayload(zcu)),
2566925670
25670 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(pt)}),
25671 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(zcu)}),
2567125672 .type => try sema.errNote(src, msg, "types are not available at runtime", .{}),
2567225673
2567325674 .@"struct" => if (zcu.typeToStruct(ty)) |struct_type| {
......@@ -25689,7 +25690,7 @@ fn explainWhyTypeIsComptime(
2568925690 if (field_val_ip != .none) continue;
2569025691 const field_ty: Type = .fromInterned(field_ty_ip);
2569125692 if (!field_ty.comptimeOnly(zcu)) continue;
25692 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(pt)});
25693 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(zcu)});
2569325694 return sema.explainWhyTypeIsComptime(msg, src, field_ty);
2569425695 }
2569525696 unreachable;
......@@ -25750,7 +25751,7 @@ pub fn explainWhyTypeIsNotExtern(
2575025751 }
2575125752 },
2575225753
25753 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(pt)}),
25754 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(zcu)}),
2575425755 .pointer => if (ty.isSlice(zcu)) {
2575525756 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2575625757 } else {
......@@ -25782,7 +25783,7 @@ pub fn explainWhyTypeIsNotExtern(
2578225783 },
2578325784 .explicit => {
2578425785 const tag_ty: Type = .fromInterned(enum_obj.int_tag_type);
25785 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(pt)});
25786 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(zcu)});
2578625787 try sema.explainWhyTypeIsNotExtern(msg, ty.srcLoc(zcu), tag_ty, position);
2578725788 },
2578825789 }
......@@ -25800,7 +25801,7 @@ pub fn explainWhyTypeIsNotExtern(
2580025801 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed struct has unspecified signedness", .{}),
2580125802 .explicit => {
2580225803 const backing_int_ty: Type = .fromInterned(struct_obj.packed_backing_int_type);
25803 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});
25804 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
2580425805 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
2580525806 },
2580625807 },
......@@ -25815,7 +25816,7 @@ pub fn explainWhyTypeIsNotExtern(
2581525816 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed union has unspecified signedness", .{}),
2581625817 .explicit => {
2581725818 const backing_int_ty: Type = .fromInterned(union_obj.packed_backing_int_type);
25818 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});
25819 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
2581925820 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
2582025821 },
2582125822 },
......@@ -26269,7 +26270,7 @@ fn fieldVal(
2626926270 block,
2627026271 field_name_src,
2627126272 "no member named '{f}' in '{f}'",
26272 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26273 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2627326274 );
2627426275 }
2627526276 },
......@@ -26293,7 +26294,7 @@ fn fieldVal(
2629326294 block,
2629426295 field_name_src,
2629526296 "no member named '{f}' in '{f}'",
26296 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26297 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2629726298 );
2629826299 }
2629926300 }
......@@ -26317,7 +26318,7 @@ fn fieldVal(
2631726318 },
2631826319 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
2631926320 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26320 field_name.fmt(ip), child_type.fmt(pt),
26321 field_name.fmt(ip), child_type.fmt(zcu),
2632126322 });
2632226323 } else child_type,
2632326324 .simple_type => |t| {
......@@ -26365,7 +26366,7 @@ fn fieldVal(
2636526366 return sema.failWithBadMemberAccess(block, child_type, src, field_name);
2636626367 },
2636726368 else => return sema.failWithOwnedErrorMsg(block, msg: {
26368 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(pt)});
26369 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(zcu)});
2636926370 errdefer msg.destroy(sema.gpa);
2637026371 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
2637126372 if (child_type.zigTypeTag(zcu) == .array) try sema.errNote(src, msg, "array values have 'len' member", .{});
......@@ -26525,7 +26526,7 @@ fn fieldPtr(
2652526526 const object_ptr_ty = sema.typeOf(object_ptr);
2652626527 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
2652726528 .pointer => object_ptr_ty.childType(zcu),
26528 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(pt)}),
26529 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(zcu)}),
2652926530 };
2653026531
2653126532 // Zig allows dereferencing a single pointer during field lookup. Note that
......@@ -26580,7 +26581,7 @@ fn fieldPtr(
2658026581 block,
2658126582 field_name_src,
2658226583 "no member named '{f}' in '{f}'",
26583 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26584 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2658426585 );
2658526586 }
2658626587 },
......@@ -26617,7 +26618,7 @@ fn fieldPtr(
2661726618 block,
2661826619 field_name_src,
2661926620 "no member named '{f}' in '{f}'",
26620 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26621 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2662126622 );
2662226623 }
2662326624 },
......@@ -26641,7 +26642,7 @@ fn fieldPtr(
2664126642 },
2664226643 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
2664326644 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26644 field_name.fmt(ip), child_type.fmt(pt),
26645 field_name.fmt(ip), child_type.fmt(zcu),
2664526646 });
2664626647 } else child_type,
2664726648 .simple_type => |t| {
......@@ -26688,7 +26689,7 @@ fn fieldPtr(
2668826689 }
2668926690 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2669026691 },
26691 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(pt)}),
26692 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(zcu)}),
2669226693 }
2669326694 },
2669426695 .@"struct" => {
......@@ -26745,7 +26746,7 @@ fn fieldCallBind(
2674526746 const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c))
2674626747 raw_ptr_ty.childType(zcu)
2674726748 else
26748 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(pt)});
26749 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(zcu)});
2674926750
2675026751 // Optionally dereference a second pointer to get the concrete type.
2675126752 const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one;
......@@ -26863,7 +26864,7 @@ fn fieldCallBind(
2686326864 const msg = msg: {
2686426865 const msg = try sema.errMsg(src, "no field or member function named '{f}' in '{f}'", .{
2686526866 field_name.fmt(ip),
26866 concrete_ty.fmt(pt),
26867 concrete_ty.fmt(zcu),
2686726868 });
2686826869 errdefer msg.destroy(sema.gpa);
2686926870 try sema.addDeclaredHereNote(msg, concrete_ty);
......@@ -27099,18 +27100,18 @@ fn tupleFieldIndex(
2709927100 field_name: InternPool.NullTerminatedString,
2710027101 field_name_src: LazySrcLoc,
2710127102) CompileError!u32 {
27102 const pt = sema.pt;
27103 const ip = &pt.zcu.intern_pool;
27103 const zcu = sema.pt.zcu;
27104 const ip = &zcu.intern_pool;
2710427105 assert(!field_name.eqlSlice("len", ip));
2710527106 if (field_name.toUnsigned(ip)) |field_index| {
27106 if (field_index < tuple_ty.structFieldCount(pt.zcu)) return field_index;
27107 if (field_index < tuple_ty.structFieldCount(zcu)) return field_index;
2710727108 return sema.fail(block, field_name_src, "index '{f}' out of bounds of tuple '{f}'", .{
27108 field_name.fmt(ip), tuple_ty.fmt(pt),
27109 field_name.fmt(ip), tuple_ty.fmt(zcu),
2710927110 });
2711027111 }
2711127112
2711227113 return sema.fail(block, field_name_src, "no field named '{f}' in tuple '{f}'", .{
27113 field_name.fmt(ip), tuple_ty.fmt(pt),
27114 field_name.fmt(ip), tuple_ty.fmt(zcu),
2711427115 });
2711527116}
2711627117
......@@ -27172,7 +27173,7 @@ fn unionFieldPtr(
2717227173
2717327174 if (initializing and field_ty.classify(zcu) == .no_possible_value) {
2717427175 const msg = msg: {
27175 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
27176 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
2717627177 errdefer msg.destroy(sema.gpa);
2717727178
2717827179 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
......@@ -27327,7 +27328,7 @@ fn elemPtr(
2732727328
2732827329 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
2732927330 .pointer => indexable_ptr_ty.childType(zcu),
27330 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(pt)}),
27331 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(zcu)}),
2733127332 };
2733227333 try sema.checkIndexable(block, src, indexable_ty);
2733327334 try sema.ensureLayoutResolved(indexable_ty, src, .ptr_access);
......@@ -27453,8 +27454,8 @@ fn elemVal(
2745327454 .runtime => {},
2745427455 .one_possible_value => return .fromValue((try child_ty.onePossibleValue(pt)).?),
2745527456 .no_possible_value => switch (child_ty.zigTypeTag(zcu)) {
27456 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(pt)}),
27457 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(pt)}),
27457 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(zcu)}),
27458 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(zcu)}),
2745827459 },
2745927460 .partially_comptime, .fully_comptime => unreachable, // caught by `validateRuntimeElemAccess`
2746027461 }
......@@ -27507,7 +27508,7 @@ fn validateRuntimeElemAccess(
2750727508 const msg = try sema.errMsg(
2750827509 elem_index_src,
2750927510 "values of type '{f}' must be comptime-known, but index value is runtime-known",
27510 .{elem_ty.fmt(sema.pt)},
27511 .{elem_ty.fmt(zcu)},
2751127512 );
2751227513 errdefer msg.destroy(sema.gpa);
2751327514
......@@ -27546,7 +27547,7 @@ fn tupleElemPtr(
2754627547 const index = elem_index_val.getUnsignedInt(zcu);
2754727548 if (index == null or index.? >= field_count) {
2754827549 return sema.fail(block, elem_index_src, "index '{f}' out of bounds of tuple '{f}'", .{
27549 elem_index_val.fmtValueSema(pt, sema), tuple_ty.fmt(pt),
27550 elem_index_val.fmtValueSema(sema), tuple_ty.fmt(zcu),
2755027551 });
2755127552 }
2755227553
......@@ -28295,7 +28296,7 @@ fn coerceExtra(
2829528296 block,
2829628297 inst_src,
2829728298 "coercion from slice to array pointer type '{f}' requires length to be known at compile-time",
28298 .{dest_ty.fmt(pt)},
28299 .{dest_ty.fmt(zcu)},
2829928300 );
2830028301 };
2830128302
......@@ -28308,7 +28309,7 @@ fn coerceExtra(
2830828309 if (!opts.report_err) return error.NotCoercible;
2830928310 return sema.failWithOwnedErrorMsg(block, msg: {
2831028311 const msg = try sema.errMsg(inst_src, "slice with undefined length cannot cast into array pointer type '{f}'", .{
28311 dest_ty.fmt(pt),
28312 dest_ty.fmt(zcu),
2831228313 });
2831328314 errdefer msg.destroy(gpa);
2831428315 try sema.errNote(inst_src, msg, "length of slice must be defined and match length of array type", .{});
......@@ -28320,7 +28321,7 @@ fn coerceExtra(
2832028321 if (!opts.report_err) return error.NotCoercible;
2832128322 return sema.failWithOwnedErrorMsg(block, msg: {
2832228323 const msg = try sema.errMsg(inst_src, "slice of length {d} cannot cast into array pointer type '{f}'", .{
28323 slice_len, dest_ty.fmt(pt),
28324 slice_len, dest_ty.fmt(zcu),
2832428325 });
2832528326 errdefer msg.destroy(gpa);
2832628327 try sema.errNote(inst_src, msg, "length of slice must match length of array type", .{});
......@@ -28375,7 +28376,7 @@ fn coerceExtra(
2837528376 block,
2837628377 inst_src,
2837728378 "array literal requires address-of operator (&) to coerce to slice type '{f}'",
28378 .{dest_ty.fmt(pt)},
28379 .{dest_ty.fmt(zcu)},
2837928380 );
2838028381 }
2838128382
......@@ -28400,7 +28401,7 @@ fn coerceExtra(
2840028401 if (!dest_info.flags.is_const) {
2840128402 if (!opts.report_err) return error.NotCoercible;
2840228403 const err_msg = err_msg: {
28403 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(pt)});
28404 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(zcu)});
2840428405 errdefer err_msg.destroy(sema.gpa);
2840528406 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2840628407 break :err_msg err_msg;
......@@ -28455,7 +28456,7 @@ fn coerceExtra(
2845528456 // comptime-known integer to other number
2845628457 if (!val.intFitsInType(dest_ty, null, zcu)) {
2845728458 if (!opts.report_err) return error.NotCoercible;
28458 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) });
28459 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) });
2845928460 }
2846028461 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2846128462 .undef => .fromValue(try dest_ty.onePossibleValue(pt) orelse try pt.undefValue(dest_ty)),
......@@ -28499,7 +28500,7 @@ fn coerceExtra(
2849928500 block,
2850028501 inst_src,
2850128502 "type '{f}' cannot represent float value '{f}'",
28502 .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) },
28503 .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) },
2850328504 );
2850428505 }
2850528506 return Air.internedToRef(result_val.toIntern());
......@@ -28558,7 +28559,7 @@ fn coerceExtra(
2855828559 block,
2855928560 inst_src,
2856028561 "type '{f}' cannot represent integer value '{f}'",
28561 .{ dest_ty.fmt(pt), val.fmtValue(pt) },
28562 .{ dest_ty.fmt(zcu), val.fmtValue(zcu) },
2856228563 );
2856328564 }
2856428565 return .fromValue(result_val);
......@@ -28573,7 +28574,7 @@ fn coerceExtra(
2857328574 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
2857428575 if (!opts.report_err) return error.NotCoercible;
2857528576 return sema.fail(block, inst_src, "no field named '{f}' in enum '{f}'", .{
28576 string.fmt(&zcu.intern_pool), dest_ty.fmt(pt),
28577 string.fmt(&zcu.intern_pool), dest_ty.fmt(zcu),
2857728578 });
2857828579 };
2857928580 return Air.internedToRef((try pt.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern());
......@@ -28699,7 +28700,7 @@ fn coerceExtra(
2869928700 errdefer msg.destroy(sema.gpa);
2870028701
2870128702 if (dest_is_npv) {
28702 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(pt)});
28703 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(zcu)});
2870328704 }
2870428705
2870528706 // E!T to T
......@@ -28880,6 +28881,7 @@ const InMemoryCoercionResult = union(enum) {
2888028881
2888128882 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {
2888228883 const pt = sema.pt;
28884 const zcu = pt.zcu;
2888328885 var cur = res;
2888428886 while (true) switch (cur.*) {
2888528887 .ok => unreachable,
......@@ -28896,13 +28898,13 @@ const InMemoryCoercionResult = union(enum) {
2889628898 },
2889728899 .comptime_int_not_coercible => |int| {
2889828900 try sema.errNote(src, msg, "type '{f}' cannot represent value '{f}'", .{
28899 int.wanted.fmt(pt), int.actual.fmtValueSema(pt, sema),
28901 int.wanted.fmt(zcu), int.actual.fmtValueSema(sema),
2890028902 });
2890128903 break;
2890228904 },
2890328905 .error_union_payload => |pair| {
2890428906 try sema.errNote(src, msg, "error union payload '{f}' cannot cast into error union payload '{f}'", .{
28905 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28907 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2890628908 });
2890728909 cur = pair.child;
2890828910 },
......@@ -28915,22 +28917,22 @@ const InMemoryCoercionResult = union(enum) {
2891528917 .array_sentinel => |sentinel| {
2891628918 if (sentinel.wanted.toIntern() == .unreachable_value) {
2891728919 try sema.errNote(src, msg, "source array cannot be guaranteed to maintain '{f}' sentinel", .{
28918 sentinel.actual.fmtValueSema(pt, sema),
28920 sentinel.actual.fmtValueSema(sema),
2891928921 });
2892028922 } else if (sentinel.actual.toIntern() == .unreachable_value) {
2892128923 try sema.errNote(src, msg, "destination array requires '{f}' sentinel", .{
28922 sentinel.wanted.fmtValueSema(pt, sema),
28924 sentinel.wanted.fmtValueSema(sema),
2892328925 });
2892428926 } else {
2892528927 try sema.errNote(src, msg, "array sentinel '{f}' cannot cast into array sentinel '{f}'", .{
28926 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
28928 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
2892728929 });
2892828930 }
2892928931 break;
2893028932 },
2893128933 .array_elem => |pair| {
2893228934 try sema.errNote(src, msg, "array element type '{f}' cannot cast into array element type '{f}'", .{
28933 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28935 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2893428936 });
2893528937 cur = pair.child;
2893628938 },
......@@ -28942,19 +28944,19 @@ const InMemoryCoercionResult = union(enum) {
2894228944 },
2894328945 .vector_elem => |pair| {
2894428946 try sema.errNote(src, msg, "vector element type '{f}' cannot cast into vector element type '{f}'", .{
28945 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28947 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2894628948 });
2894728949 cur = pair.child;
2894828950 },
2894928951 .optional_shape => |pair| {
2895028952 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28951 pair.actual.optionalChild(pt.zcu).fmt(pt), pair.wanted.optionalChild(pt.zcu).fmt(pt),
28953 pair.actual.optionalChild(pt.zcu).fmt(zcu), pair.wanted.optionalChild(pt.zcu).fmt(zcu),
2895228954 });
2895328955 break;
2895428956 },
2895528957 .optional_child => |pair| {
2895628958 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28957 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28959 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2895828960 });
2895928961 cur = pair.child;
2896028962 },
......@@ -29018,7 +29020,7 @@ const InMemoryCoercionResult = union(enum) {
2901829020 },
2901929021 .fn_param => |param| {
2902029022 try sema.errNote(src, msg, "parameter {d} '{f}' cannot cast into '{f}'", .{
29021 param.index, param.actual.fmt(pt), param.wanted.fmt(pt),
29023 param.index, param.actual.fmt(zcu), param.wanted.fmt(zcu),
2902229024 });
2902329025 cur = param.child;
2902429026 },
......@@ -29028,13 +29030,13 @@ const InMemoryCoercionResult = union(enum) {
2902829030 },
2902929031 .fn_return_type => |pair| {
2903029032 try sema.errNote(src, msg, "return type '{f}' cannot cast into return type '{f}'", .{
29031 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29033 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2903229034 });
2903329035 cur = pair.child;
2903429036 },
2903529037 .ptr_child => |pair| {
2903629038 try sema.errNote(src, msg, "pointer type child '{f}' cannot cast into pointer type child '{f}'", .{
29037 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29039 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2903829040 });
2903929041 cur = pair.child;
2904029042 },
......@@ -29045,11 +29047,11 @@ const InMemoryCoercionResult = union(enum) {
2904529047 .ptr_sentinel => |sentinel| {
2904629048 if (sentinel.actual.toIntern() != .unreachable_value) {
2904729049 try sema.errNote(src, msg, "pointer sentinel '{f}' cannot cast into pointer sentinel '{f}'", .{
29048 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
29050 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
2904929051 });
2905029052 } else {
2905129053 try sema.errNote(src, msg, "destination pointer requires '{f}' sentinel", .{
29052 sentinel.wanted.fmtValueSema(pt, sema),
29054 sentinel.wanted.fmtValueSema(sema),
2905329055 });
2905429056 }
2905529057 break;
......@@ -29063,11 +29065,11 @@ const InMemoryCoercionResult = union(enum) {
2906329065 const actual_allow_zero = pair.actual.ptrAllowsZero(pt.zcu);
2906429066 if (actual_allow_zero and !wanted_allow_zero) {
2906529067 try sema.errNote(src, msg, "'{f}' could have null values which are illegal in type '{f}'", .{
29066 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29068 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2906729069 });
2906829070 } else {
2906929071 try sema.errNote(src, msg, "mutable '{f}' would allow illegal null values stored to type '{f}'", .{
29070 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29072 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2907129073 });
2907229074 }
2907329075 break;
......@@ -29079,7 +29081,7 @@ const InMemoryCoercionResult = union(enum) {
2907929081 try sema.errNote(src, msg, "cast discards const qualifier", .{});
2908029082 } else {
2908129083 try sema.errNote(src, msg, "mutable '{f}' would allow illegal const pointers stored to type '{f}'", .{
29082 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29084 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2908329085 });
2908429086 }
2908529087 break;
......@@ -29091,7 +29093,7 @@ const InMemoryCoercionResult = union(enum) {
2909129093 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
2909229094 } else {
2909329095 try sema.errNote(src, msg, "mutable '{f}' would allow illegal volatile pointers stored to type '{f}'", .{
29094 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29096 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2909529097 });
2909629098 }
2909729099 break;
......@@ -29117,13 +29119,13 @@ const InMemoryCoercionResult = union(enum) {
2911729119 },
2911829120 .double_ptr_to_anyopaque => |pair| {
2911929121 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{f}' to anyopaque pointer '{f}'", .{
29120 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29122 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2912129123 });
2912229124 break;
2912329125 },
2912429126 .slice_to_anyopaque => |pair| {
2912529127 try sema.errNote(src, msg, "cannot implicitly cast slice '{f}' to anyopaque pointer '{f}'", .{
29126 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29128 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2912729129 });
2912829130 try sema.errNote(src, msg, "consider using '.ptr'", .{});
2912929131 break;
......@@ -29874,7 +29876,7 @@ fn coerceVarArgParam(
2987429876 const coerced_ty = sema.typeOf(coerced);
2987529877 if (!coerced_ty.validateExtern(.param_ty, zcu)) {
2987629878 const msg = msg: {
29877 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(pt)});
29879 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(zcu)});
2987829880 errdefer msg.destroy(sema.gpa);
2987929881
2988029882 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
......@@ -29941,7 +29943,7 @@ fn storePtr2(
2994129943
2994229944 // We're performing the store at runtime, so the pointee type must not be comptime-only.
2994329945 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
29944 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(pt)});
29946 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(zcu)});
2994529947 errdefer msg.destroy(zcu.gpa);
2994629948 try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{});
2994729949 break :msg msg;
......@@ -30097,13 +30099,13 @@ fn storePtrVal(
3009730099 block,
3009830100 src,
3009930101 "comptime dereference requires '{f}' to have a well-defined layout",
30100 .{ty.fmt(pt)},
30102 .{ty.fmt(zcu)},
3010130103 ),
3010230104 .out_of_bounds => |ty| return sema.fail(
3010330105 block,
3010430106 src,
3010530107 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
30106 .{ ptr_ty.fmt(pt), ty.fmt(pt) },
30108 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
3010730109 ),
3010830110 .exceeds_host_size => return sema.fail(block, src, "bit-pointer target exceeds host size", .{}),
3010930111 }
......@@ -30315,7 +30317,7 @@ fn coerceCompatiblePtrs(
3031530317 const inst_ty = sema.typeOf(inst);
3031630318 if (sema.resolveValue(inst)) |val| {
3031730319 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {
30318 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});
30320 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
3031930321 }
3032030322 // The comptime Value representation is compatible with both types.
3032130323 return Air.internedToRef(
......@@ -30386,7 +30388,7 @@ fn coerceEnumToUnion(
3038630388 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {
3038730389 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {
3038830390 return sema.fail(block, inst_src, "union '{f}' has no tag with value '{f}'", .{
30389 union_ty.fmt(pt), val.fmtValueSema(pt, sema),
30391 union_ty.fmt(zcu), val.fmtValueSema(sema),
3039030392 });
3039130393 };
3039230394
......@@ -30400,7 +30402,7 @@ fn coerceEnumToUnion(
3040030402 )),
3040130403
3040230404 .no_possible_value => return sema.failWithOwnedErrorMsg(block, msg: {
30403 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
30405 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
3040430406 errdefer msg.destroy(sema.gpa);
3040530407 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
3040630408 field_name.fmt(ip),
......@@ -30411,8 +30413,8 @@ fn coerceEnumToUnion(
3041130413
3041230414 else => return sema.failWithOwnedErrorMsg(block, msg: {
3041330415 const msg = try sema.errMsg(inst_src, "coercion from enum '{f}' to union '{f}' must initialize '{f}' field '{f}'", .{
30414 inst_ty.fmt(pt), union_ty.fmt(pt),
30415 field_ty.fmt(pt), field_name.fmt(ip),
30416 inst_ty.fmt(zcu), union_ty.fmt(zcu),
30417 field_ty.fmt(zcu), field_name.fmt(ip),
3041630418 });
3041730419 errdefer msg.destroy(sema.gpa);
3041830420
......@@ -30428,7 +30430,7 @@ fn coerceEnumToUnion(
3042830430 if (enum_ty.isNonexhaustiveEnum(zcu)) {
3042930431 const msg = msg: {
3043030432 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{f}' from non-exhaustive enum", .{
30431 union_ty.fmt(pt),
30433 union_ty.fmt(zcu),
3043230434 });
3043330435 errdefer msg.destroy(sema.gpa);
3043430436 try sema.addDeclaredHereNote(msg, enum_ty);
......@@ -30456,7 +30458,7 @@ fn coerceEnumToUnion(
3045630458 const msg = try sema.errMsg(
3045730459 inst_src,
3045830460 "runtime coercion from enum '{f}' to union '{f}' which has non-void fields",
30459 .{ enum_ty.fmt(pt), union_ty.fmt(pt) },
30461 .{ enum_ty.fmt(zcu), union_ty.fmt(zcu) },
3046030462 );
3046130463 errdefer msg.destroy(sema.gpa);
3046230464
......@@ -30472,7 +30474,7 @@ fn coerceEnumToUnion(
3047230474 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' has {s} '{f}'", .{
3047330475 field_name.fmt(ip),
3047430476 ty_description,
30475 field_ty.fmt(pt),
30477 field_ty.fmt(zcu),
3047630478 });
3047730479 }
3047830480 try sema.addDeclaredHereNote(msg, union_ty);
......@@ -31082,7 +31084,7 @@ fn analyzeLoad(
3108231084 const ptr_ty = sema.typeOf(ptr);
3108331085 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
3108431086 .pointer => ptr_ty.childType(zcu),
31085 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)}),
31087 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)}),
3108631088 };
3108731089
3108831090 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
......@@ -31093,11 +31095,11 @@ fn analyzeLoad(
3109331095
3109431096 const comptime_only = switch (elem_ty.classify(zcu)) {
3109531097 .no_possible_value => switch (elem_ty.zigTypeTag(zcu)) {
31096 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(pt)}),
31098 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(zcu)}),
3109731099 else => {
3109831100 // Loading an uninstantiable type always invokes Illegal Behavior.
3109931101 if (block.isComptime()) {
31100 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(pt)});
31102 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(zcu)});
3110131103 } else if (block.wantSafety()) {
3110231104 try sema.safetyPanic(block, src, .load_uninstantiable_type);
3110331105 return .unreachable_value;
......@@ -31122,9 +31124,9 @@ fn analyzeLoad(
3112231124 }
3112331125
3112431126 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
31125 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(pt)});
31127 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(zcu)});
3112631128 errdefer msg.destroy(zcu.gpa);
31127 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(pt)});
31129 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(zcu)});
3112831130 break :msg msg;
3112931131 });
3113031132
......@@ -31432,7 +31434,7 @@ fn analyzeSlice(
3143231434 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
3143331435 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
3143431436 .pointer => ptr_ptr_ty.childType(zcu),
31435 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(pt)}),
31437 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(zcu)}),
3143631438 };
3143731439
3143831440 var array_ty = ptr_ptr_child_ty;
......@@ -31483,8 +31485,8 @@ fn analyzeSlice(
3148331485 msg,
3148431486 "expected '{f}', found '{f}'",
3148531487 .{
31486 Value.zero_comptime_int.fmtValueSema(pt, sema),
31487 start_value.fmtValueSema(pt, sema),
31488 Value.zero_comptime_int.fmtValueSema(sema),
31489 start_value.fmtValueSema(sema),
3148831490 },
3148931491 );
3149031492 break :msg msg;
......@@ -31499,8 +31501,8 @@ fn analyzeSlice(
3149931501 msg,
3150031502 "expected '{f}', found '{f}'",
3150131503 .{
31502 Value.one_comptime_int.fmtValueSema(pt, sema),
31503 end_value.fmtValueSema(pt, sema),
31504 Value.one_comptime_int.fmtValueSema(sema),
31505 end_value.fmtValueSema(sema),
3150431506 },
3150531507 );
3150631508 break :msg msg;
......@@ -31513,7 +31515,7 @@ fn analyzeSlice(
3151331515 block,
3151431516 end_src,
3151531517 "end index {f} out of bounds for slice of single-item pointer",
31516 .{end_value.fmtValueSema(pt, sema)},
31518 .{end_value.fmtValueSema(sema)},
3151731519 );
3151831520 }
3151931521 }
......@@ -31559,7 +31561,7 @@ fn analyzeSlice(
3155931561 elem_ty = ptr_ptr_child_ty.childType(zcu);
3156031562 },
3156131563 },
31562 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(pt)}),
31564 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(zcu)}),
3156331565 }
3156431566
3156531567 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
......@@ -31611,8 +31613,8 @@ fn analyzeSlice(
3161131613 end_src,
3161231614 "end index {f} out of bounds for array of length {f}{s}",
3161331615 .{
31614 end_val.fmtValueSema(pt, sema),
31615 len_val.fmtValueSema(pt, sema),
31616 end_val.fmtValueSema(sema),
31617 len_val.fmtValueSema(sema),
3161631618 sentinel_label,
3161731619 },
3161831620 );
......@@ -31656,7 +31658,7 @@ fn analyzeSlice(
3165631658 end_src,
3165731659 "end index {f} out of bounds for slice of length {d}{s}",
3165831660 .{
31659 end_val.fmtValueSema(pt, sema),
31661 end_val.fmtValueSema(sema),
3166031662 slice_val.sliceLen(zcu),
3166131663 sentinel_label,
3166231664 },
......@@ -31707,9 +31709,9 @@ fn analyzeSlice(
3170731709 const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{});
3170831710 errdefer msg.destroy(sema.gpa);
3170931711 if (ptr_sentinel) |current| {
31710 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(pt), provided.fmtValue(pt) });
31712 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(zcu), provided.fmtValue(zcu) });
3171131713 } else {
31712 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(pt)});
31714 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(zcu)});
3171331715 }
3171431716 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
3171531717 break :msg msg;
......@@ -31753,8 +31755,8 @@ fn analyzeSlice(
3175331755 start_src,
3175431756 "start index {f} is larger than end index {f}",
3175531757 .{
31756 start_val.fmtValueSema(pt, sema),
31757 end_val.fmtValueSema(pt, sema),
31758 start_val.fmtValueSema(sema),
31759 end_val.fmtValueSema(sema),
3175831760 },
3175931761 );
3176031762 }
......@@ -31776,13 +31778,13 @@ fn analyzeSlice(
3177631778 block,
3177731779 src,
3177831780 "comptime dereference requires '{f}' to have a well-defined layout",
31779 .{ty.fmt(pt)},
31781 .{ty.fmt(zcu)},
3178031782 ),
3178131783 .out_of_bounds => |ty| return sema.fail(
3178231784 block,
3178331785 end_src,
3178431786 "slice end index {d} exceeds bounds of containing decl of type '{f}'",
31785 .{ end_int, ty.fmt(pt) },
31787 .{ end_int, ty.fmt(zcu) },
3178631788 ),
3178731789 };
3178831790
......@@ -31791,8 +31793,8 @@ fn analyzeSlice(
3179131793 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3179231794 errdefer msg.destroy(sema.gpa);
3179331795 try sema.errNote(src, msg, "expected '{f}', found '{f}'", .{
31794 expected_sentinel.fmtValueSema(pt, sema),
31795 actual_sentinel.fmtValueSema(pt, sema),
31796 expected_sentinel.fmtValueSema(sema),
31797 actual_sentinel.fmtValueSema(sema),
3179631798 });
3179731799
3179831800 break :msg msg;
......@@ -32604,7 +32606,7 @@ const PeerResolveResult = union(enum) {
3260432606 instructions: []const Air.Inst.Ref,
3260532607 candidate_srcs: PeerTypeCandidateSrc,
3260632608 ) !*Zcu.ErrorMsg {
32607 const pt = sema.pt;
32609 const zcu = sema.pt.zcu;
3260832610
3260932611 var opt_msg: ?*Zcu.ErrorMsg = null;
3261032612 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
......@@ -32630,7 +32632,7 @@ const PeerResolveResult = union(enum) {
3263032632 },
3263132633 .field_error => |field_error| {
3263232634 const fmt = "struct field '{f}' has conflicting types";
32633 const args = .{field_error.field_name.fmt(&pt.zcu.intern_pool)};
32635 const args = .{field_error.field_name.fmt(&zcu.intern_pool)};
3263432636 if (opt_msg) |msg| {
3263532637 try sema.errNote(src, msg, fmt, args);
3263632638 } else {
......@@ -32662,8 +32664,8 @@ const PeerResolveResult = union(enum) {
3266232664
3266332665 const fmt = "incompatible types: '{f}' and '{f}'";
3266432666 const args = .{
32665 conflict_tys[0].fmt(pt),
32666 conflict_tys[1].fmt(pt),
32667 conflict_tys[0].fmt(zcu),
32668 conflict_tys[1].fmt(zcu),
3266732669 };
3266832670 const msg = if (opt_msg) |msg| msg: {
3266932671 try sema.errNote(src, msg, fmt, args);
......@@ -32674,8 +32676,8 @@ const PeerResolveResult = union(enum) {
3267432676 break :msg msg;
3267532677 };
3267632678
32677 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(pt)});
32678 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(pt)});
32679 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(zcu)});
32680 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(zcu)});
3267932681
3268032682 // No child error
3268132683 break;
......@@ -33904,10 +33906,10 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3390433906}
3390533907
3390633908fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
33907 const pt = sema.pt;
33908 if (!ty.isIndexable(pt.zcu)) {
33909 const zcu = sema.pt.zcu;
33910 if (!ty.isIndexable(zcu)) {
3390933911 const msg = msg: {
33910 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(pt)});
33912 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(zcu)});
3391133913 errdefer msg.destroy(sema.gpa);
3391233914 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
3391333915 try sema.addDeclaredHereNote(msg, ty);
......@@ -33932,7 +33934,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
3393233934 }
3393333935 }
3393433936 const msg = msg: {
33935 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(pt)});
33937 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(zcu)});
3393633938 errdefer msg.destroy(sema.gpa);
3393733939 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
3393833940 break :msg msg;
......@@ -34215,8 +34217,9 @@ pub fn analyzeAsAddressSpace(
3421534217/// Asserts the value is a pointer and dereferences it.
3421634218/// Returns `null` if the pointer contents cannot be loaded at comptime.
3421734219fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value {
34218 // TODO: audit use sites to eliminate this coercion
3421934220 const pt = sema.pt;
34221 const zcu = pt.zcu;
34222 // TODO: audit use sites to eliminate this coercion
3422034223 const coerced_ptr_val = try pt.getCoerced(ptr_val, ptr_ty);
3422134224 switch (try sema.pointerDerefExtra(block, src, coerced_ptr_val)) {
3422234225 .runtime_load => return null,
......@@ -34225,13 +34228,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr
3422534228 block,
3422634229 src,
3422734230 "comptime dereference requires '{f}' to have a well-defined layout",
34228 .{ty.fmt(pt)},
34231 .{ty.fmt(zcu)},
3422934232 ),
3423034233 .out_of_bounds => |ty| return sema.fail(
3423134234 block,
3423234235 src,
3423334236 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
34234 .{ ptr_ty.fmt(pt), ty.fmt(pt) },
34237 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
3423534238 ),
3423634239 }
3423734240}
......@@ -34354,12 +34357,12 @@ fn intFromFloatScalar(
3435434357
3435534358 if (std.math.isNan(float)) {
3435634359 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{f}'", .{
34357 int_ty.fmt(pt),
34360 int_ty.fmt(zcu),
3435834361 });
3435934362 }
3436034363 if (std.math.isInf(float)) {
3436134364 return sema.fail(block, src, "float value Inf cannot be stored in integer type '{f}'", .{
34362 int_ty.fmt(pt),
34365 int_ty.fmt(zcu),
3436334366 });
3436434367 }
3436534368
......@@ -34374,7 +34377,7 @@ fn intFromFloatScalar(
3437434377 block,
3437534378 src,
3437634379 "fractional component prevents float value '{f}' from coercion to type '{f}'",
34377 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
34380 .{ val.fmtValueSema(sema), int_ty.fmt(zcu) },
3437834381 ),
3437934382 .truncate, .round, .floor, .ceil => {},
3438034383 },
......@@ -34386,7 +34389,7 @@ fn intFromFloatScalar(
3438634389 const int_info = int_ty.intInfo(zcu);
3438734390 if (!big_int.toConst().fitsInTwosComp(int_info.signedness, int_info.bits)) {
3438834391 return sema.fail(block, src, "float value '{f}' cannot be stored in integer type '{f}'", .{
34389 val.fmtValueSema(pt, sema), int_ty.fmt(pt),
34392 val.fmtValueSema(sema), int_ty.fmt(zcu),
3439034393 });
3439134394 }
3439234395 return pt.getCoerced(cti_result, int_ty);
......@@ -34632,7 +34635,7 @@ fn notePathToComptimeAllocPtr(
3463234635 else => {}, // there will be another stage
3463334636 }
3463434637
34635 const derivation = try comptime_ptr.pointerDerivation(arena, pt, sema);
34638 const derivation = try comptime_ptr.pointerDerivation(arena, zcu, sema);
3463634639
3463734640 var second_path_aw: std.Io.Writer.Allocating = .init(arena);
3463834641 defer second_path_aw.deinit();
......@@ -34640,19 +34643,19 @@ fn notePathToComptimeAllocPtr(
3464034643 const deriv_start = @import("print_value.zig").printPtrDerivation(
3464134644 derivation,
3464234645 &second_path_aw.writer,
34643 pt,
34646 zcu,
3464434647 .lvalue,
3464534648 .{ .str = inter_name },
3464634649 20,
3464734650 ) catch return error.OutOfMemory;
3464834651
34649 switch (deriv_start) {
34650 .int, .nav_ptr => unreachable,
34651 .uav_ptr => |uav| {
34652 switch (deriv_start.addr) {
34653 .int, .nav => unreachable,
34654 .uav => |uav| {
3465234655 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
34653 return .{ .new_val = .fromInterned(uav.val) };
34656 return .{ .new_val = uav };
3465434657 },
34655 .comptime_alloc_ptr => |cta_info| {
34658 .comptime_alloc => |cta_info| {
3465634659 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
3465734660 const cta = sema.getComptimeAlloc(cta_info.idx);
3465834661 if (cta.is_const) {
......@@ -34662,15 +34665,15 @@ fn notePathToComptimeAllocPtr(
3466234665 return .done;
3466334666 }
3466434667 },
34665 .comptime_field_ptr => {
34668 .comptime_field => {
3466634669 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
3466734670 try sema.errNote(src, msg, "'{s}' is a comptime field", .{inter_name});
3466834671 return .done;
3466934672 },
34670 .eu_payload_ptr,
34671 .opt_payload_ptr,
34672 .field_ptr,
34673 .elem_ptr,
34673 .eu_payload,
34674 .opt_payload,
34675 .field,
34676 .elem,
3467434677 .offset_and_cast,
3467534678 => unreachable,
3467634679 }
......@@ -35286,7 +35289,7 @@ pub fn setTypeName(
3528635289 // some tooling may not support very long symbol names.
3528735290 w.print("{f}", .{Value.fmtValueSemaFull(.{
3528835291 .val = arg_val,
35289 .pt = pt,
35292 .zcu = zcu,
3529035293 .opt_sema = sema,
3529135294 .depth = 1,
3529235295 })}) catch return error.OutOfMemory;
src/Sema/LowerZon.zig+21-19
......@@ -323,10 +323,11 @@ fn failUnsupportedResultType(
323323) Zcu.SemaError {
324324 @branchHint(.cold);
325325 const sema = self.sema;
326 const gpa = sema.gpa;
327326 const pt = sema.pt;
327 const zcu = pt.zcu;
328 const gpa = zcu.comp.gpa;
328329 return sema.failWithOwnedErrorMsg(self.block, msg: {
329 const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(pt)});
330 const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(zcu)});
330331 errdefer msg.destroy(gpa);
331332 if (opt_note) |n| try sema.errNote(self.import_loc, msg, "{s}", .{n});
332333 break :msg msg;
......@@ -346,9 +347,9 @@ fn fail(
346347}
347348
348349fn lowerExprKnownResTy(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {
349 const pt = self.sema.pt;
350 const zcu = self.sema.pt.zcu;
350351 return self.lowerExprKnownResTyInner(node, res_ty) catch |err| switch (err) {
351 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(pt)}),
352 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(zcu)}),
352353 else => |e| return e,
353354 };
354355}
......@@ -359,20 +360,21 @@ fn lowerExprKnownResTyInner(
359360 res_ty: Type,
360361) (CompileError || error{WrongType})!InternPool.Index {
361362 const pt = self.sema.pt;
362 switch (res_ty.zigTypeTag(pt.zcu)) {
363 const zcu = pt.zcu;
364 switch (res_ty.zigTypeTag(zcu)) {
363365 .optional => return pt.intern(.{
364366 .opt = .{
365367 .ty = res_ty.toIntern(),
366368 .val = if (node.get(self.file.zoir.?) == .null) b: {
367369 break :b .none;
368370 } else b: {
369 const child_type = res_ty.optionalChild(pt.zcu);
371 const child_type = res_ty.optionalChild(zcu);
370372 break :b try self.lowerExprKnownResTyInner(node, child_type);
371373 },
372374 },
373375 }),
374376 .pointer => {
375 const ptr_info = res_ty.ptrInfo(pt.zcu);
377 const ptr_info = res_ty.ptrInfo(zcu);
376378 switch (ptr_info.flags.size) {
377379 .one => return pt.intern(.{ .ptr = .{
378380 .ty = res_ty.toIntern(),
......@@ -413,7 +415,7 @@ fn lowerExprKnownResTyInner(
413415 .frame,
414416 .@"anyframe",
415417 .void,
416 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(pt)}),
418 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(zcu)}),
417419 }
418420}
419421
......@@ -444,7 +446,7 @@ fn lowerInt(
444446 if (lhs_info.signedness == .unsigned and rhs < 0) return self.fail(
445447 node,
446448 "type '{f}' cannot represent integer value '{d}'",
447 .{ res_ty.fmt(self.sema.pt), rhs },
449 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
448450 );
449451
450452 // If lhs has less than the 32 bits rhs can hold, we need to check the max and
......@@ -460,7 +462,7 @@ fn lowerInt(
460462 return self.fail(
461463 node,
462464 "type '{f}' cannot represent integer value '{d}'",
463 .{ res_ty.fmt(self.sema.pt), rhs },
465 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
464466 );
465467 }
466468 }
......@@ -478,7 +480,7 @@ fn lowerInt(
478480 return self.fail(
479481 node,
480482 "type '{f}' cannot represent integer value '{d}'",
481 .{ res_ty.fmt(self.sema.pt), val },
483 .{ res_ty.fmt(self.sema.pt.zcu), val },
482484 );
483485 }
484486 }
......@@ -499,7 +501,7 @@ fn lowerInt(
499501 .inexact => return self.fail(
500502 node,
501503 "fractional component prevents float value '{d}' from coercion to type '{f}'",
502 .{ val, res_ty.fmt(self.sema.pt) },
504 .{ val, res_ty.fmt(self.sema.pt.zcu) },
503505 ),
504506 .exact => {},
505507 }
......@@ -510,7 +512,7 @@ fn lowerInt(
510512 return self.fail(
511513 node,
512514 "type '{f}' cannot represent integer value '{d}'",
513 .{ res_ty.fmt(self.sema.pt), val },
515 .{ res_ty.fmt(self.sema.pt.zcu), val },
514516 );
515517 }
516518
......@@ -532,7 +534,7 @@ fn lowerInt(
532534 return self.fail(
533535 node,
534536 "type '{f}' cannot represent integer value '{d}'",
535 .{ res_ty.fmt(self.sema.pt), val },
537 .{ res_ty.fmt(self.sema.pt.zcu), val },
536538 );
537539 }
538540 }
......@@ -566,7 +568,7 @@ fn lowerFloat(
566568 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
567569 node,
568570 "expected type '{f}'",
569 .{res_ty.fmt(self.sema.pt)},
571 .{res_ty.fmt(self.sema.pt.zcu)},
570572 );
571573 break :b try self.sema.pt.floatValue(res_ty, std.math.inf(f128));
572574 },
......@@ -574,7 +576,7 @@ fn lowerFloat(
574576 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
575577 node,
576578 "expected type '{f}'",
577 .{res_ty.fmt(self.sema.pt)},
579 .{res_ty.fmt(self.sema.pt.zcu)},
578580 );
579581 break :b try self.sema.pt.floatValue(res_ty, -std.math.inf(f128));
580582 },
......@@ -582,7 +584,7 @@ fn lowerFloat(
582584 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
583585 node,
584586 "expected type '{f}'",
585 .{res_ty.fmt(self.sema.pt)},
587 .{res_ty.fmt(self.sema.pt.zcu)},
586588 );
587589 break :b try self.sema.pt.floatValue(res_ty, std.math.nan(f128));
588590 },
......@@ -647,7 +649,7 @@ fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I
647649 node,
648650 "enum {f} has no member named '{f}'",
649651 .{
650 res_ty.fmt(self.sema.pt),
652 res_ty.fmt(self.sema.pt.zcu),
651653 std.zig.fmtId(field_name.get(self.file.zoir.?)),
652654 },
653655 );
......@@ -941,7 +943,7 @@ fn lowerUnion(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
941943 .struct_literal => b: {
942944 const fields: @FieldType(Zoir.Node, "struct_literal") = switch (node.get(self.file.zoir.?)) {
943945 .struct_literal => |fields| fields,
944 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt)}),
946 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt.zcu)}),
945947 };
946948 if (fields.names.len != 1) {
947949 return error.WrongType;
src/Sema/type_resolution.zig+25-25
......@@ -310,7 +310,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
310310 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
311311 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
312312 return sema.failWithOwnedErrorMsg(&block, msg: {
313 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});
313 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
314314 errdefer msg.destroy(gpa);
315315 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
316316 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -321,7 +321,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
321321 if (field_ty.isSpirvRuntimeArray(zcu)) {
322322 if (struct_obj.layout != .@"extern") {
323323 return sema.failWithOwnedErrorMsg(&block, msg: {
324 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
324 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
325325 errdefer msg.destroy(gpa);
326326 try sema.errNote(field_name_src, msg, "while checking this field", .{});
327327 break :msg msg;
......@@ -329,7 +329,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
329329 }
330330 if (field_index != fields_len - 1) {
331331 return sema.failWithOwnedErrorMsg(&block, msg: {
332 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(pt)});
332 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(zcu)});
333333 errdefer msg.destroy(gpa);
334334 try sema.errNote(field_name_src, msg, "while checking this field", .{});
335335 break :msg msg;
......@@ -339,7 +339,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
339339 const elem_ty: Type = field_ty.childType(zcu);
340340 if (elem_ty.zigTypeTag(zcu) == .spirv) {
341341 return sema.failWithOwnedErrorMsg(&block, msg: {
342 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(pt)});
342 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(zcu)});
343343 errdefer msg.destroy(gpa);
344344 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
345345 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -348,7 +348,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
348348 }
349349 } else {
350350 return sema.failWithOwnedErrorMsg(&block, msg: {
351 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(pt)});
351 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(zcu)});
352352 errdefer msg.destroy(gpa);
353353 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
354354 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -359,7 +359,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
359359
360360 if (struct_obj.layout == .@"extern" and !field_ty.validateExtern(.struct_field, zcu)) {
361361 return sema.failWithOwnedErrorMsg(&block, msg: {
362 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
362 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
363363 errdefer msg.destroy(gpa);
364364 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .struct_field);
365365 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -516,7 +516,7 @@ fn resolvePackedStructLayout(
516516 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
517517 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
518518 return sema.failWithOwnedErrorMsg(block, msg: {
519 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});
519 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
520520 errdefer msg.destroy(gpa);
521521 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
522522 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -524,7 +524,7 @@ fn resolvePackedStructLayout(
524524 });
525525 }
526526 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
527 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
527 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
528528 errdefer msg.destroy(gpa);
529529 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
530530 break :msg msg;
......@@ -565,7 +565,7 @@ fn resolvePackedStructLayout(
565565 block,
566566 block.src(.container_arg),
567567 "expected backing integer type, found '{f}'",
568 .{backing_ty.fmt(pt)},
568 .{backing_ty.fmt(zcu)},
569569 );
570570 if (field_bits != backing_ty.intInfo(zcu).bits) return sema.failWithOwnedErrorMsg(block, msg: {
571571 const src = struct_ty.srcLoc(zcu);
......@@ -575,7 +575,7 @@ fn resolvePackedStructLayout(
575575 block.src(.container_arg),
576576 msg,
577577 "backing integer '{f}' has bit width '{d}'",
578 .{ backing_ty.fmt(pt), backing_ty.bitSize(zcu) },
578 .{ backing_ty.fmt(zcu), backing_ty.bitSize(zcu) },
579579 );
580580 try sema.errNote(src, msg, "struct fields have total bit width '{d}'", .{field_bits});
581581 break :msg msg;
......@@ -777,7 +777,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
777777 &block,
778778 block.src(.container_arg),
779779 "expected enum tag type, found '{f}'",
780 .{tag_ty.fmt(pt)},
780 .{tag_ty.fmt(zcu)},
781781 );
782782 break :validated_tag_ty tag_ty;
783783 },
......@@ -922,7 +922,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
922922 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
923923 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
924924 return sema.failWithOwnedErrorMsg(&block, msg: {
925 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});
925 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
926926 errdefer msg.destroy(gpa);
927927 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
928928 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -931,7 +931,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
931931 }
932932 if (field_ty.zigTypeTag(zcu) == .spirv) {
933933 return sema.failWithOwnedErrorMsg(&block, msg: {
934 const msg = try sema.errMsg(field_ty_src, "SPIR-V type '{f}' have unknown size and therefore cannot be directly embedded in unions", .{field_ty.fmt(pt)});
934 const msg = try sema.errMsg(field_ty_src, "SPIR-V type '{f}' have unknown size and therefore cannot be directly embedded in unions", .{field_ty.fmt(zcu)});
935935 errdefer msg.destroy(gpa);
936936 try sema.addDeclaredHereNote(msg, field_ty);
937937 break :msg msg;
......@@ -939,7 +939,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
939939 }
940940 if (union_obj.layout == .@"extern" and !field_ty.validateExtern(.union_field, zcu)) {
941941 return sema.failWithOwnedErrorMsg(&block, msg: {
942 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
942 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
943943 errdefer msg.destroy(gpa);
944944 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .union_field);
945945 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -1056,7 +1056,7 @@ fn failUnionFieldMismatch(sema: *Sema, block: *Block, union_field_names: []const
10561056 }
10571057 const union_field_src = block.src(.{ .container_field_name = @intCast(union_field_index) });
10581058 return sema.failWithOwnedErrorMsg(block, msg: {
1059 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(pt) });
1059 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(zcu) });
10601060 errdefer msg.destroy(gpa);
10611061 try sema.addDeclaredHereNote(msg, enum_tag_ty);
10621062 break :msg msg;
......@@ -1122,7 +1122,7 @@ fn resolvePackedUnionLayout(
11221122 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
11231123 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
11241124 return sema.failWithOwnedErrorMsg(block, msg: {
1125 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});
1125 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
11261126 errdefer msg.destroy(gpa);
11271127 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
11281128 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -1130,7 +1130,7 @@ fn resolvePackedUnionLayout(
11301130 });
11311131 }
11321132 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
1133 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
1133 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
11341134 errdefer msg.destroy(gpa);
11351135 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
11361136 break :msg msg;
......@@ -1165,7 +1165,7 @@ fn resolvePackedUnionLayout(
11651165 block,
11661166 block.src(.container_arg),
11671167 "expected backing integer type, found '{f}'",
1168 .{backing_ty.fmt(pt)},
1168 .{backing_ty.fmt(zcu)},
11691169 );
11701170 const backing_int_bits = backing_ty.intInfo(zcu).bits;
11711171 for (union_obj.field_types.get(ip), 0..) |field_type_ip, field_idx| {
......@@ -1175,12 +1175,12 @@ fn resolvePackedUnionLayout(
11751175 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
11761176 const msg = try sema.errMsg(field_ty_src, "field bit width does not match backing integer", .{});
11771177 errdefer msg.destroy(gpa);
1178 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });
1178 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
11791179 try sema.errNote(
11801180 block.src(.container_arg),
11811181 msg,
11821182 "backing integer '{f}' has bit width '{d}'",
1183 .{ backing_ty.fmt(pt), backing_int_bits },
1183 .{ backing_ty.fmt(zcu), backing_int_bits },
11841184 );
11851185 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
11861186 break :msg msg;
......@@ -1199,8 +1199,8 @@ fn resolvePackedUnionLayout(
11991199 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
12001200 const msg = try sema.errMsg(field_ty_src, "field bit width does not match earlier field", .{});
12011201 errdefer msg.destroy(gpa);
1202 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });
1203 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(pt), first_field_bits });
1202 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
1203 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(zcu), first_field_bits });
12041204 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
12051205 break :msg msg;
12061206 });
......@@ -1380,7 +1380,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
13801380 &block,
13811381 block.src(.container_arg),
13821382 "expected integer tag type, found '{f}'",
1383 .{int_tag_ty.fmt(pt)},
1383 .{int_tag_ty.fmt(zcu)},
13841384 ),
13851385 }
13861386 break :ty int_tag_ty;
......@@ -1487,7 +1487,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
14871487 &block,
14881488 field_val_src,
14891489 "enum tag value '{f}' too large for type '{f}'",
1490 .{ result.val.fmtValueSema(pt, sema), int_tag_ty.fmt(pt) },
1490 .{ result.val.fmtValueSema(sema), int_tag_ty.fmt(zcu) },
14911491 );
14921492 const val = result.val.toIntern();
14931493 enum_obj.field_values.get(ip)[field_idx] = val;
......@@ -1497,7 +1497,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
14971497 return sema.failWithOwnedErrorMsg(&block, msg: {
14981498 const prev_field_val_src = block.src(.{ .container_field_value = prev_field_index });
14991499 const msg = try sema.errMsg(field_val_src, "enum tag value '{f}' for field '{f}' already taken", .{
1500 Value.fromInterned(field_val).fmtValueSema(pt, sema),
1500 Value.fromInterned(field_val).fmtValueSema(sema),
15011501 enum_obj.field_names.get(ip)[field_idx].fmt(ip),
15021502 });
15031503 errdefer msg.destroy(gpa);
src/Type.zig+144-162
......@@ -412,21 +412,14 @@ pub fn eql(a: Type, b: Type) bool {
412412
413413pub const format = @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");
414414
415pub const Formatter = std.fmt.Alt(Format, Format.default);
416
417pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
418 return .{ .data = .{
419 .ty = ty,
420 .pt = pt,
421 } };
415pub fn fmt(ty: Type, zcu: *Zcu) Formatter {
416 return .{ .ty = ty, .zcu = zcu };
422417}
423
424const Format = struct {
418pub const Formatter = struct {
425419 ty: Type,
426 pt: Zcu.PerThread,
427
428 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {
429 return print(f.ty, writer, f.pt, null);
420 zcu: *Zcu,
421 pub fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void {
422 return print(f.ty, writer, f.zcu, null);
430423 }
431424};
432425
......@@ -442,9 +435,9 @@ pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void {
442435
443436/// Prints a name suitable for `@typeName`.
444437/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
445pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Comparison) std.Io.Writer.Error!void {
438pub fn print(ty: Type, writer: *std.Io.Writer, zcu: *Zcu, ctx: ?*Comparison) std.Io.Writer.Error!void {
446439 if (ctx) |c| {
447 const should_dedupe = shouldDedupeType(ty, c, pt) catch |err| switch (err) {
440 const should_dedupe = shouldDedupeType(ty, c, zcu) catch |err| switch (err) {
448441 error.OutOfMemory => return error.WriteFailed,
449442 };
450443 switch (should_dedupe) {
......@@ -453,7 +446,6 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
453446 }
454447 }
455448
456 const zcu = pt.zcu;
457449 const ip = &zcu.intern_pool;
458450 switch (ip.indexToKey(ty.toIntern())) {
459451 .undef => return writer.writeAll("@as(type, undefined)"),
......@@ -469,8 +461,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
469461
470462 if (info.sentinel != .none) switch (info.flags.size) {
471463 .one, .c => unreachable,
472 .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
473 .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
464 .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}),
465 .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}),
474466 } else switch (info.flags.size) {
475467 .one => try writer.writeAll("*"),
476468 .many => try writer.writeAll("[*]"),
......@@ -485,7 +477,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
485477 const alignment = if (info.flags.alignment != .none)
486478 info.flags.alignment
487479 else
488 Type.fromInterned(info.child).abiAlignment(pt.zcu);
480 Type.fromInterned(info.child).abiAlignment(zcu);
489481 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});
490482
491483 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {
......@@ -504,39 +496,39 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
504496 if (info.flags.is_const) try writer.writeAll("const ");
505497 if (info.flags.is_volatile) try writer.writeAll("volatile ");
506498
507 try print(Type.fromInterned(info.child), writer, pt, ctx);
499 try print(Type.fromInterned(info.child), writer, zcu, ctx);
508500 return;
509501 },
510502 .array_type => |array_type| {
511503 if (array_type.sentinel == .none) {
512504 try writer.print("[{d}]", .{array_type.len});
513 try print(Type.fromInterned(array_type.child), writer, pt, ctx);
505 try print(Type.fromInterned(array_type.child), writer, zcu, ctx);
514506 } else {
515507 try writer.print("[{d}:{f}]", .{
516508 array_type.len,
517 Value.fromInterned(array_type.sentinel).fmtValue(pt),
509 Value.fromInterned(array_type.sentinel).fmtValue(zcu),
518510 });
519 try print(Type.fromInterned(array_type.child), writer, pt, ctx);
511 try print(Type.fromInterned(array_type.child), writer, zcu, ctx);
520512 }
521513 return;
522514 },
523515 .vector_type => |vector_type| {
524516 try writer.print("@Vector({d}, ", .{vector_type.len});
525 try print(Type.fromInterned(vector_type.child), writer, pt, ctx);
517 try print(Type.fromInterned(vector_type.child), writer, zcu, ctx);
526518 try writer.writeAll(")");
527519 return;
528520 },
529521 .opt_type => |child| {
530522 try writer.writeByte('?');
531 return print(Type.fromInterned(child), writer, pt, ctx);
523 return print(Type.fromInterned(child), writer, zcu, ctx);
532524 },
533525 .error_union_type => |error_union_type| {
534 try print(Type.fromInterned(error_union_type.error_set_type), writer, pt, ctx);
526 try print(Type.fromInterned(error_union_type.error_set_type), writer, zcu, ctx);
535527 try writer.writeByte('!');
536528 if (error_union_type.payload_type == .generic_poison_type) {
537529 try writer.writeAll("anytype");
538530 } else {
539 try print(Type.fromInterned(error_union_type.payload_type), writer, pt, ctx);
531 try print(Type.fromInterned(error_union_type.payload_type), writer, zcu, ctx);
540532 }
541533 return;
542534 },
......@@ -618,8 +610,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
618610 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, val, i| {
619611 try writer.writeAll(if (i == 0) " " else ", ");
620612 if (val != .none) try writer.writeAll("comptime ");
621 try print(Type.fromInterned(field_ty), writer, pt, ctx);
622 if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(pt)});
613 try print(Type.fromInterned(field_ty), writer, zcu, ctx);
614 if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(zcu)});
623615 }
624616 try writer.writeAll(" }");
625617 },
......@@ -643,12 +635,12 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
643635 .image => try writer.writeAll("@SpirvType(.image)"),
644636 .sampled_image => {
645637 try writer.writeAll("@SpirvType(.sampled_image, ");
646 try print(Type.fromInterned(info.ty), writer, pt, ctx);
638 try print(Type.fromInterned(info.ty), writer, zcu, ctx);
647639 try writer.writeAll(")");
648640 },
649641 .runtime_array => {
650642 try writer.writeAll("@SpirvType(.runtime_array, ");
651 try print(Type.fromInterned(info.ty), writer, pt, ctx);
643 try print(Type.fromInterned(info.ty), writer, zcu, ctx);
652644 try writer.writeAll(")");
653645 },
654646 }
......@@ -672,7 +664,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
672664 if (param_ty == .generic_poison_type) {
673665 try writer.writeAll("anytype");
674666 } else {
675 try print(Type.fromInterned(param_ty), writer, pt, ctx);
667 try print(Type.fromInterned(param_ty), writer, zcu, ctx);
676668 }
677669 }
678670 if (fn_info.is_var_args) {
......@@ -699,13 +691,13 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
699691 if (fn_info.return_type == .generic_poison_type) {
700692 try writer.writeAll("anytype");
701693 } else {
702 try print(Type.fromInterned(fn_info.return_type), writer, pt, ctx);
694 try print(Type.fromInterned(fn_info.return_type), writer, zcu, ctx);
703695 }
704696 },
705697 .anyframe_type => |child| {
706698 if (child == .none) return writer.writeAll("anyframe");
707699 try writer.writeAll("anyframe->");
708 return print(Type.fromInterned(child), writer, pt, ctx);
700 return print(Type.fromInterned(child), writer, zcu, ctx);
709701 },
710702
711703 // values, not types
......@@ -2869,11 +2861,62 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
28692861 const ptr_info = ip.indexToKey(ptr_ty.toIntern()).ptr_type;
28702862 assert(ptr_info.flags.size == .one or ptr_info.flags.size == .c);
28712863 const aggregate_ty: Type = .fromInterned(ptr_info.child);
2864
2865 var field_ptr_info = ptr_info;
2866
2867 field_ptr_info.child = if (aggregate_ty.isSlice(zcu)) switch (field_index) {
2868 Value.slice_ptr_index => aggregate_ty.slicePtrFieldType(zcu).toIntern(),
2869 Value.slice_len_index => .usize_type,
2870 else => unreachable,
2871 } else aggregate_ty.fieldType(field_index, zcu).toIntern();
2872
2873 field_ptr_info.flags.alignment = aggregate_ty.fieldPtrAlign(ptr_info.flags.alignment, field_index, zcu);
2874
2875 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2876 aggregate_ty.containerLayout(zcu) == .@"packed")
2877 {
2878 field_ptr_info.packed_offset = packed_offset: {
2879 comptime assert(Type.packed_struct_layout_version == 2);
2880 const bit_offset = zcu.structPackedFieldBitOffset(
2881 ip.loadStructType(aggregate_ty.toIntern()),
2882 field_index,
2883 );
2884 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2885 .host_size = ptr_info.packed_offset.host_size,
2886 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2887 } else .{
2888 .host_size = switch (zcu.comp.getZigBackend()) {
2889 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2890 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2891 },
2892 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2893 };
2894 };
2895 }
2896
2897 return pt.ptrType(field_ptr_info);
2898}
2899
2900pub fn fieldPtrAlign(
2901 aggregate_ty: Type,
2902 aggregate_ptr_align: Alignment,
2903 field_index: u32,
2904 zcu: *const Zcu,
2905) Alignment {
2906 const ip = &zcu.intern_pool;
2907
28722908 aggregate_ty.assertHasLayout(zcu);
2909
2910 const aggregate_ty_align = aggregate_ty.abiAlignment(zcu);
2911 const aggregate_align: Alignment = switch (aggregate_ptr_align) {
2912 .none => aggregate_ty_align,
2913 else => |a| a,
2914 };
2915
28732916 // We only exit this `switch` for default-layout aggregates, where the field pointer alignment
28742917 // is a simple minimum of the aggregate pointer alignment and the field alignment.
2875 // `field_align` is `.none` if there is no explicit alignment annotation.
2876 const field_ty: Type, const field_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
2918 // `field_explicit_align` is `.none` if there is no explicit alignment annotation.
2919 const field_ty: Type, const field_explicit_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
28772920 .@"struct" => switch (aggregate_ty.containerLayout(zcu)) {
28782921 .auto => field: {
28792922 if (aggregate_ty.isTuple(zcu)) {
......@@ -2890,56 +2933,21 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
28902933 // `extern struct { x: u32, y: u16 }`, the `y` field is 4-byte aligned.
28912934 const field_ty = aggregate_ty.fieldType(field_index, zcu);
28922935 const field_offset = aggregate_ty.structFieldOffset(field_index, zcu);
2893 const parent_align = switch (ptr_info.flags.alignment) {
2894 .none => aggregate_ty.abiAlignment(zcu),
2895 else => |a| a,
2896 };
2897 const actual_field_align = switch (field_offset) {
2898 0 => parent_align,
2899 else => parent_align.minStrict(.fromLog2Units(@ctz(field_offset))),
2900 };
2901 const field_ptr_align: Alignment = a: {
2902 if (ptr_info.flags.alignment == .none and
2903 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2904 actual_field_align == field_ty.abiAlignment(zcu))
2905 {
2906 // There's no user-specified 'align' in sight, and the alignment from the
2907 // field offset matches the field type's natural alignment, so just use a
2908 // default-aligned pointer.
2909 break :a .none;
2910 }
2911 break :a actual_field_align;
2912 };
2913 var field_ptr_info = ptr_info;
2914 field_ptr_info.child = field_ty.toIntern();
2915 field_ptr_info.flags.alignment = field_ptr_align;
2916 return pt.ptrType(field_ptr_info);
2917 },
2918 .@"packed" => {
2919 var field_ptr_info = ptr_info;
2920 if (field_ptr_info.flags.alignment == .none) {
2921 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2936 const field_align = aggregate_align.offset(field_offset);
2937
2938 if (aggregate_ptr_align == .none and
2939 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2940 field_align == field_ty.abiAlignment(zcu))
2941 {
2942 // There's no user-specified 'align' in sight, and the alignment from the
2943 // field offset matches the field type's natural alignment, so just use a
2944 // default-aligned pointer.
2945 return .none;
29222946 }
2923 field_ptr_info.packed_offset = packed_offset: {
2924 comptime assert(Type.packed_struct_layout_version == 2);
2925 const bit_offset = zcu.structPackedFieldBitOffset(
2926 ip.loadStructType(aggregate_ty.toIntern()),
2927 field_index,
2928 );
2929 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2930 .host_size = ptr_info.packed_offset.host_size,
2931 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2932 } else .{
2933 .host_size = switch (zcu.comp.getZigBackend()) {
2934 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2935 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2936 },
2937 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2938 };
2939 };
2940 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2941 return pt.ptrType(field_ptr_info);
2947
2948 return field_align;
29422949 },
2950 .@"packed" => return aggregate_align,
29432951 },
29442952 .@"union" => switch (aggregate_ty.containerLayout(zcu)) {
29452953 .auto => field: {
......@@ -2949,30 +2957,14 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
29492957 union_obj.field_aligns.getOrNone(ip, field_index),
29502958 };
29512959 },
2952 .@"extern" => {
2960 .@"extern", .@"packed" => {
29532961 // The alignment always matches that of the union pointer. If the union pointer is
29542962 // default aligned (`.none`), we may need to explicitly align the result pointer.
2955 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2956 var field_ptr_info = ptr_info;
2957 field_ptr_info.child = field_ty.toIntern();
2958 if (field_ptr_info.flags.alignment == .none and
2959 Alignment.compareStrict(field_ty.abiAlignment(zcu), .neq, aggregate_ty.abiAlignment(zcu)))
2960 {
2961 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2962 }
2963 return pt.ptrType(field_ptr_info);
2964 },
2965 .@"packed" => {
2966 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2967 var field_ptr_info = ptr_info;
2968 if (field_ptr_info.flags.alignment == .none) {
2969 const resolved_align = aggregate_ty.abiAlignment(zcu);
2970 if (field_ty.abiAlignment(zcu) != resolved_align) {
2971 field_ptr_info.flags.alignment = resolved_align;
2972 }
2973 }
2974 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2975 return pt.ptrType(field_ptr_info);
2963 const field_ty_align = aggregate_ty.fieldType(field_index, zcu).abiAlignment(zcu);
2964 return switch (aggregate_ptr_align) {
2965 .none => if (field_ty_align == aggregate_ty_align) .none else aggregate_ty_align,
2966 else => |a| a,
2967 };
29762968 },
29772969 },
29782970 .pointer => field: {
......@@ -2985,39 +2977,31 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
29852977 },
29862978 else => unreachable,
29872979 };
2988 const field_ptr_align: Alignment = a: {
2989 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and aggregate_ty.structFieldIsComptime(field_index, zcu)) {
2990 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.
2991 break :a field_align;
2992 }
2993 const actual_field_align = switch (field_align) {
2994 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {
2995 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),
2996 .ptr_type => Type.usize.abiAlignment(zcu),
2997 else => unreachable,
2998 },
2999 else => |a| a,
3000 };
3001 const actual_aggregate_align = switch (ptr_info.flags.alignment) {
3002 .none => aggregate_ty.abiAlignment(zcu),
3003 else => |a| a,
3004 };
3005 if (actual_aggregate_align.compareStrict(.lt, actual_field_align)) {
3006 // Underaligned aggregate; use that alignment.
3007 assert(ptr_info.flags.alignment != .none);
3008 break :a actual_aggregate_align;
3009 }
3010 if (field_align == .none and actual_field_align == field_ty.abiAlignment(zcu)) {
3011 // No explicit annotation on the field (nor an unusual default), and the aggregate
3012 // alignment is irrelevant to us, so return an un-annotated pointer.
3013 break :a .none;
3014 }
3015 break :a actual_field_align;
2980 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2981 aggregate_ty.structFieldIsComptime(field_index, zcu))
2982 {
2983 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.
2984 return field_explicit_align;
2985 }
2986 const field_align = switch (field_explicit_align) {
2987 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {
2988 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),
2989 .ptr_type => Type.usize.abiAlignment(zcu),
2990 else => unreachable,
2991 },
2992 else => |a| a,
30162993 };
3017 var field_ptr_info = ptr_info;
3018 field_ptr_info.flags.alignment = field_ptr_align;
3019 field_ptr_info.child = field_ty.toIntern();
3020 return pt.ptrType(field_ptr_info);
2994 if (aggregate_align.compareStrict(.lt, field_align)) {
2995 // Underaligned aggregate; use that alignment.
2996 assert(aggregate_ptr_align == aggregate_align);
2997 return aggregate_align;
2998 }
2999 if (field_explicit_align == .none and field_align == field_ty.abiAlignment(zcu)) {
3000 // No explicit annotation on the field (nor an unusual default), and the aggregate
3001 // alignment is irrelevant to us, so return an un-annotated pointer.
3002 return .none;
3003 }
3004 return field_align;
30213005}
30223006
30233007pub fn containerTypeName(ty: Type, ip: *const InternPool) struct {
......@@ -3356,8 +3340,7 @@ pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {
33563340}
33573341
33583342/// Recursively walks the type and marks for each subtype how many times it has been seen
3359fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {
3360 const zcu = pt.zcu;
3343fn collectSubtypes(ty: Type, zcu: *Zcu, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {
33613344 const ip = &zcu.intern_pool;
33623345
33633346 const gop = try visited.getOrPut(zcu.gpa, ty);
......@@ -3368,34 +3351,34 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
33683351 }
33693352
33703353 switch (ip.indexToKey(ty.toIntern())) {
3371 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), pt, visited),
3372 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), pt, visited),
3373 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), pt, visited),
3374 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),
3354 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), zcu, visited),
3355 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), zcu, visited),
3356 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), zcu, visited),
3357 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
33753358 .error_union_type => |error_union_type| {
3376 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), pt, visited);
3359 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), zcu, visited);
33773360 if (error_union_type.payload_type != .generic_poison_type) {
3378 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), pt, visited);
3361 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), zcu, visited);
33793362 }
33803363 },
33813364 .tuple_type => |tuple| {
33823365 for (tuple.types.get(ip)) |field_ty| {
3383 try collectSubtypes(Type.fromInterned(field_ty), pt, visited);
3366 try collectSubtypes(Type.fromInterned(field_ty), zcu, visited);
33843367 }
33853368 },
33863369 .func_type => |fn_info| {
33873370 const param_types = fn_info.param_types.get(&zcu.intern_pool);
33883371 for (param_types) |param_ty| {
33893372 if (param_ty != .generic_poison_type) {
3390 try collectSubtypes(Type.fromInterned(param_ty), pt, visited);
3373 try collectSubtypes(Type.fromInterned(param_ty), zcu, visited);
33913374 }
33923375 }
33933376
33943377 if (fn_info.return_type != .generic_poison_type) {
3395 try collectSubtypes(Type.fromInterned(fn_info.return_type), pt, visited);
3378 try collectSubtypes(Type.fromInterned(fn_info.return_type), zcu, visited);
33963379 }
33973380 },
3398 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),
3381 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
33993382
34003383 // leaf types
34013384 .undef,
......@@ -3432,7 +3415,7 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
34323415 }
34333416}
34343417
3435fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMemory}!Comparison.DedupeEntry {
3418fn shouldDedupeType(ty: Type, ctx: *Comparison, zcu: *Zcu) error{OutOfMemory}!Comparison.DedupeEntry {
34363419 if (ctx.type_occurrences.get(ty)) |occ| {
34373420 if (ctx.type_dedupe_cache.get(ty)) |cached| {
34383421 return cached;
......@@ -3440,7 +3423,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
34403423
34413424 var discarding: std.Io.Writer.Discarding = .init(&.{});
34423425
3443 print(ty, &discarding.writer, pt, null) catch
3426 print(ty, &discarding.writer, zcu, null) catch
34443427 unreachable; // we are writing into a discarding writer, it should never fail
34453428
34463429 const type_len: i32 = @intCast(discarding.count);
......@@ -3457,7 +3440,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
34573440 break :b .{ .dedupe = .{ .index = ctx.placeholder_index - 1 } };
34583441 } else .dont_dedupe;
34593442
3460 try ctx.type_dedupe_cache.put(pt.zcu.gpa, ty, entry);
3443 try ctx.type_dedupe_cache.put(zcu.comp.gpa, ty, entry);
34613444
34623445 return entry;
34633446 } else {
......@@ -3488,38 +3471,37 @@ pub const Comparison = struct {
34883471 dedupe: Placeholder,
34893472 };
34903473
3491 pub fn init(types: []const Type, pt: Zcu.PerThread) error{OutOfMemory}!Comparison {
3474 pub fn init(types: []const Type, zcu: *Zcu) error{OutOfMemory}!Comparison {
34923475 var cmp: Comparison = .{
34933476 .type_occurrences = .empty,
34943477 .type_dedupe_cache = .empty,
34953478 .placeholder_index = 0,
34963479 };
34973480
3498 errdefer cmp.deinit(pt);
3481 errdefer cmp.deinit(zcu.comp.gpa);
34993482
35003483 for (types) |ty| {
3501 try collectSubtypes(ty, pt, &cmp.type_occurrences);
3484 try collectSubtypes(ty, zcu, &cmp.type_occurrences);
35023485 }
35033486
35043487 return cmp;
35053488 }
35063489
3507 pub fn deinit(cmp: *Comparison, pt: Zcu.PerThread) void {
3508 const gpa = pt.zcu.gpa;
3490 pub fn deinit(cmp: *Comparison, gpa: Allocator) void {
35093491 cmp.type_occurrences.deinit(gpa);
35103492 cmp.type_dedupe_cache.deinit(gpa);
35113493 }
35123494
3513 pub fn fmtType(ctx: *Comparison, ty: Type, pt: Zcu.PerThread) Comparison.Formatter {
3514 return .{ .ty = ty, .ctx = ctx, .pt = pt };
3495 pub fn fmtType(ctx: *Comparison, ty: Type, zcu: *Zcu) Comparison.Formatter {
3496 return .{ .ty = ty, .ctx = ctx, .zcu = zcu };
35153497 }
35163498 pub const Formatter = struct {
35173499 ty: Type,
35183500 ctx: *Comparison,
3519 pt: Zcu.PerThread,
3501 zcu: *Zcu,
35203502
35213503 pub fn format(self: Comparison.Formatter, writer: anytype) error{WriteFailed}!void {
3522 print(self.ty, writer, self.pt, self.ctx) catch return error.WriteFailed;
3504 print(self.ty, writer, self.zcu, self.ctx) catch return error.WriteFailed;
35233505 }
35243506 };
35253507};
src/Value.zig+326-201
......@@ -34,19 +34,19 @@ pub fn fmtDebug(val: Value) std.fmt.Alt(Value, dump) {
3434 return .{ .data = val };
3535}
3636
37pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Alt(print_value.FormatContext, print_value.format) {
37pub fn fmtValue(val: Value, zcu: *Zcu) std.fmt.Alt(print_value.FormatContext, print_value.format) {
3838 return .{ .data = .{
3939 .val = val,
40 .pt = pt,
40 .zcu = zcu,
4141 .opt_sema = null,
4242 .depth = 3,
4343 } };
4444}
4545
46pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Alt(print_value.FormatContext, print_value.formatSema) {
46pub fn fmtValueSema(val: Value, sema: *Sema) std.fmt.Alt(print_value.FormatContext, print_value.formatSema) {
4747 return .{ .data = .{
4848 .val = val,
49 .pt = pt,
49 .zcu = sema.pt.zcu,
5050 .opt_sema = sema,
5151 .depth = 3,
5252 } };
......@@ -1890,167 +1890,233 @@ pub fn getOffsetPtr(ptr_val: Value, byte_off: u64, new_ty: Type, pt: Zcu.PerThre
18901890 return Value.fromInterned(try pt.intern(.{ .ptr = ptr }));
18911891}
18921892
1893pub const PointerDeriveStep = union(enum) {
1894 int: struct {
1895 addr: u64,
1896 ptr_ty: Type,
1897 },
1898 nav_ptr: InternPool.Nav.Index,
1899 uav_ptr: InternPool.Key.Ptr.BaseAddr.Uav,
1900 comptime_alloc_ptr: struct {
1901 idx: InternPool.ComptimeAllocIndex,
1902 val: Value,
1903 ptr_ty: Type,
1904 },
1905 comptime_field_ptr: Value,
1906 eu_payload_ptr: struct {
1907 parent: *PointerDeriveStep,
1908 /// This type will never be cast: it is provided for convenience.
1909 result_ptr_ty: Type,
1910 },
1911 opt_payload_ptr: struct {
1912 parent: *PointerDeriveStep,
1913 /// This type will never be cast: it is provided for convenience.
1914 result_ptr_ty: Type,
1915 },
1916 field_ptr: struct {
1917 parent: *PointerDeriveStep,
1918 field_idx: u32,
1919 /// This type will never be cast: it is provided for convenience.
1920 result_ptr_ty: Type,
1921 },
1922 elem_ptr: struct {
1923 parent: *PointerDeriveStep,
1924 elem_idx: u64,
1925 /// This type will never be cast: it is provided for convenience.
1926 result_ptr_ty: Type,
1927 },
1928 offset_and_cast: struct {
1929 parent: *PointerDeriveStep,
1930 byte_offset: u64,
1931 new_ptr_ty: Type,
1893pub const PointerDerivation = struct {
1894 elem_ty: Type,
1895 /// TODO: investigate eliminating this field. We should *always* know the lengths of arrays
1896 /// which are pointed to, so `.one` should be the only possible case!
1897 size: Size,
1898 @"align": InternPool.Alignment,
1899 @"const": bool,
1900 @"volatile": bool,
1901 @"allowzero": bool,
1902
1903 addr: union(enum) {
1904 int: u64,
1905 nav: InternPool.Nav.Index,
1906 uav: Value,
1907 comptime_field: Value,
1908 comptime_alloc: struct {
1909 idx: InternPool.ComptimeAllocIndex,
1910 val: Value,
1911 },
1912 eu_payload: struct { parent: *PointerDerivation },
1913 opt_payload: struct { parent: *PointerDerivation },
1914 field: struct {
1915 parent: *PointerDerivation,
1916 field_index: u32,
1917 },
1918 elem: struct {
1919 parent: *PointerDerivation,
1920 elem_index: u64,
1921 },
1922 offset_and_cast: struct {
1923 parent: *PointerDerivation,
1924 byte_offset: u64,
1925 },
19321926 },
19331927
1934 pub fn ptrType(step: PointerDeriveStep, pt: Zcu.PerThread) !Type {
1935 return switch (step) {
1936 .int => |int| int.ptr_ty,
1937 .nav_ptr => |nav| try pt.navPtrType(nav),
1938 .uav_ptr => |uav| Type.fromInterned(uav.orig_ty),
1939 .comptime_alloc_ptr => |info| info.ptr_ty,
1940 .comptime_field_ptr => |val| try pt.singleConstPtrType(val.typeOf(pt.zcu)),
1941 .offset_and_cast => |oac| oac.new_ptr_ty,
1942 inline .eu_payload_ptr, .opt_payload_ptr, .field_ptr, .elem_ptr => |x| x.result_ptr_ty,
1943 };
1928 pub const Size = enum { one, many };
1929
1930 pub fn fmtType(pd: PointerDerivation, zcu: *Zcu) FormatType {
1931 return .{ .pd = pd, .zcu = zcu };
19441932 }
1933 pub const FormatType = struct {
1934 pd: PointerDerivation,
1935 zcu: *Zcu,
1936 pub fn format(ctx: FormatType, w: *Io.Writer) Io.Writer.Error!void {
1937 const pd = ctx.pd;
1938 switch (pd.size) {
1939 .one => try w.writeByte('*'),
1940 .many => try w.writeAll("[*]"),
1941 }
1942 if (pd.@"align".toByteUnits()) |align_bytes| {
1943 try w.print("align({d}) ", .{align_bytes});
1944 }
1945 if (pd.@"const") try w.writeAll("const ");
1946 if (pd.@"volatile") try w.writeAll("volatile ");
1947 if (pd.@"allowzero") try w.writeAll("allowzero ");
1948 try pd.elem_ty.print(w, ctx.zcu, null);
1949 }
1950 };
19451951};
19461952
19471953/// Given a pointer value, get the sequence of steps to derive it, ideally by taking
19481954/// only field and element pointers with no casts. This can be used by codegen backends
19491955/// which prefer field/elem accesses when lowering constant pointer values.
19501956/// It is also used by the Value printing logic for pointers.
1951pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, opt_sema: ?*Sema) Allocator.Error!PointerDeriveStep {
1952 const zcu = pt.zcu;
1957pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu, opt_sema: ?*Sema) Allocator.Error!PointerDerivation {
19531958 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
1954 const base_derive: PointerDeriveStep = switch (ptr.base_addr) {
1955 .int => return .{ .int = .{
1956 .addr = ptr.byte_offset,
1957 .ptr_ty = Type.fromInterned(ptr.ty),
1958 } },
1959 .nav => |nav| .{ .nav_ptr = nav },
1959 const ptr_ty_info: InternPool.Key.PtrType = info: {
1960 var info = Type.fromInterned(ptr.ty).ptrInfo(zcu);
1961 if (info.packed_offset.host_size != 0) {
1962 // TODO: this function *should* handle packed pointers by returning the derivation of
1963 // the backing int pointer. However, until https://github.com/ziglang/zig/issues/24061
1964 // is implemented, we don't have access to the backing type. For now, fudge things a
1965 // little by pretending that this is a pointer to anyopaque. What could go wrong?
1966 info.child = .anyopaque_type;
1967 }
1968 break :info info;
1969 };
1970 const ptr_size: PointerDerivation.Size = switch (ptr_ty_info.flags.size) {
1971 .one => .one,
1972 .many, .c => .many,
1973 .slice => unreachable,
1974 };
1975 const base_derive: PointerDerivation = switch (ptr.base_addr) {
1976 .int => return .{
1977 .elem_ty = .fromInterned(ptr_ty_info.child),
1978 .size = ptr_size,
1979 .@"align" = ptr_ty_info.flags.alignment,
1980 .@"const" = ptr_ty_info.flags.is_const,
1981 .@"volatile" = ptr_ty_info.flags.is_volatile,
1982 .@"allowzero" = ptr_ty_info.flags.is_allowzero,
1983 .addr = .{ .int = ptr.byte_offset },
1984 },
1985 .nav => |nav| base: {
1986 const resolved = zcu.intern_pool.getNav(nav).resolved.?;
1987 break :base .{
1988 .elem_ty = .fromInterned(resolved.type),
1989 .size = .one,
1990 .@"align" = resolved.@"align",
1991 .@"const" = resolved.@"const",
1992 .@"volatile" = false,
1993 .@"allowzero" = false,
1994 .addr = .{ .nav = nav },
1995 };
1996 },
19601997 .uav => |uav| base: {
1961 // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be.
1962 // TODO: fix this in the sites interning anon decls!
1963 const const_ty = try pt.ptrType(info: {
1964 var info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu);
1965 info.flags.is_const = true;
1966 break :info info;
1967 });
1968 break :base .{ .uav_ptr = .{
1969 .val = uav.val,
1970 .orig_ty = const_ty.toIntern(),
1971 } };
1998 const orig_ty_info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu);
1999 break :base .{
2000 .elem_ty = .fromInterned(orig_ty_info.child),
2001 .size = .one,
2002 .@"align" = orig_ty_info.flags.alignment,
2003 // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be.
2004 // TODO: fix this in the sites interning anon decls!
2005 .@"const" = true,
2006 .@"volatile" = orig_ty_info.flags.is_volatile,
2007 .@"allowzero" = orig_ty_info.flags.is_allowzero,
2008
2009 .addr = .{ .uav = .fromInterned(uav.val) },
2010 };
19722011 },
19732012 .comptime_alloc => |idx| base: {
19742013 const sema = opt_sema.?;
19752014 const alloc = sema.getComptimeAlloc(idx);
1976 const val = try alloc.val.intern(pt, arena);
1977 const ty = val.typeOf(zcu);
1978 break :base .{ .comptime_alloc_ptr = .{
1979 .idx = idx,
1980 .val = val,
1981 .ptr_ty = try pt.ptrType(.{
1982 .child = ty.toIntern(),
1983 .flags = .{
1984 .alignment = alloc.alignment,
1985 },
1986 }),
1987 } };
1988 },
1989 .comptime_field => |val| .{ .comptime_field_ptr = Value.fromInterned(val) },
2015 const val = try alloc.val.intern(sema.pt, arena);
2016 break :base .{
2017 .elem_ty = val.typeOf(zcu),
2018 .size = .one,
2019 .@"align" = alloc.alignment,
2020 .@"const" = alloc.is_const,
2021 .@"volatile" = false,
2022 .@"allowzero" = false,
2023 .addr = .{ .comptime_alloc = .{
2024 .idx = idx,
2025 .val = val,
2026 } },
2027 };
2028 },
2029 .comptime_field => |val| .{
2030 .elem_ty = Value.fromInterned(val).typeOf(zcu),
2031 .size = .one,
2032 .@"align" = .none,
2033 .@"const" = true,
2034 .@"volatile" = false,
2035 .@"allowzero" = false,
2036 .addr = .{ .comptime_field = .fromInterned(val) },
2037 },
19902038 .eu_payload => |eu_ptr| base: {
1991 const base_ptr = Value.fromInterned(eu_ptr);
1992 const base_ptr_ty = base_ptr.typeOf(zcu);
1993 const parent_step = try arena.create(PointerDeriveStep);
1994 parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, pt, opt_sema);
1995 break :base .{ .eu_payload_ptr = .{
1996 .parent = parent_step,
1997 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).errorUnionPayload(zcu)),
1998 } };
2039 const parent_step = try arena.create(PointerDerivation);
2040 parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, zcu, opt_sema);
2041 break :base .{
2042 .elem_ty = parent_step.elem_ty.errorUnionPayload(zcu),
2043 .size = .one,
2044 .@"align" = parent_step.@"align",
2045 .@"const" = parent_step.@"const",
2046 .@"volatile" = parent_step.@"volatile",
2047 .@"allowzero" = parent_step.@"allowzero",
2048 .addr = .{ .eu_payload = .{
2049 .parent = parent_step,
2050 } },
2051 };
19992052 },
20002053 .opt_payload => |opt_ptr| base: {
2001 const base_ptr = Value.fromInterned(opt_ptr);
2002 const base_ptr_ty = base_ptr.typeOf(zcu);
2003 const parent_step = try arena.create(PointerDeriveStep);
2004 parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, pt, opt_sema);
2005 break :base .{ .opt_payload_ptr = .{
2006 .parent = parent_step,
2007 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).optionalChild(zcu)),
2008 } };
2054 const parent_step = try arena.create(PointerDerivation);
2055 parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, zcu, opt_sema);
2056 break :base .{
2057 .elem_ty = parent_step.elem_ty.optionalChild(zcu),
2058 .size = .one,
2059 .@"align" = parent_step.@"align",
2060 .@"const" = parent_step.@"const",
2061 .@"volatile" = parent_step.@"volatile",
2062 .@"allowzero" = parent_step.@"allowzero",
2063 .addr = .{ .opt_payload = .{
2064 .parent = parent_step,
2065 } },
2066 };
20092067 },
20102068 .field => |field| base: {
2011 const base_ptr = Value.fromInterned(field.base);
2012 const base_ptr_ty = try pt.ptrType(info: {
2013 var info = base_ptr.typeOf(zcu).ptrInfo(zcu);
2014 info.flags.size = .one;
2015 break :info info;
2016 });
2017 const parent_step = try arena.create(PointerDeriveStep);
2018 parent_step.* = try pointerDerivation(base_ptr, arena, pt, opt_sema);
2019 break :base .{ .field_ptr = .{
2020 .parent = parent_step,
2021 .field_idx = @intCast(field.index),
2022 .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field.index), pt),
2023 } };
2069 const parent_step = try arena.create(PointerDerivation);
2070 parent_step.* = try pointerDerivation(.fromInterned(field.base), arena, zcu, opt_sema);
2071 break :base .{
2072 .elem_ty = if (parent_step.elem_ty.isSlice(zcu)) switch (field.index) {
2073 Value.slice_ptr_index => parent_step.elem_ty.slicePtrFieldType(zcu),
2074 Value.slice_len_index => .usize,
2075 else => unreachable,
2076 } else parent_step.elem_ty.fieldType(@intCast(field.index), zcu),
2077 .size = .one,
2078 .@"align" = parent_step.elem_ty.fieldPtrAlign(parent_step.@"align", @intCast(field.index), zcu),
2079 .@"const" = parent_step.@"const",
2080 .@"volatile" = parent_step.@"volatile",
2081 .@"allowzero" = parent_step.@"allowzero",
2082 .addr = .{ .field = .{
2083 .parent = parent_step,
2084 .field_index = @intCast(field.index),
2085 } },
2086 };
20242087 },
20252088 .arr_elem => |arr_elem| base: {
2026 const parent_step = try arena.create(PointerDeriveStep);
2027 parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, pt, opt_sema);
2028 const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu);
2029 const result_ptr_ty = try pt.ptrType(.{
2030 .child = parent_ptr_info.child,
2031 .flags = flags: {
2032 var flags = parent_ptr_info.flags;
2033 flags.size = .one;
2034 if (flags.alignment != .none) flags.alignment = .minStrict(
2035 flags.alignment,
2036 Type.fromInterned(parent_ptr_info.child).abiAlignment(zcu),
2037 );
2038 break :flags flags;
2089 const parent_step = try arena.create(PointerDerivation);
2090 parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, zcu, opt_sema);
2091 break :base .{
2092 .elem_ty = parent_step.elem_ty,
2093 .size = .many,
2094 .@"align" = switch (parent_step.@"align") {
2095 .none => .none,
2096 else => |a| a.minStrict(parent_step.elem_ty.abiAlignment(zcu)),
20392097 },
2040 });
2041 break :base .{ .elem_ptr = .{
2042 .parent = parent_step,
2043 .elem_idx = arr_elem.index,
2044 .result_ptr_ty = result_ptr_ty,
2045 } };
2098 .@"const" = parent_step.@"const",
2099 .@"volatile" = parent_step.@"volatile",
2100 .@"allowzero" = parent_step.@"allowzero",
2101 .addr = .{ .elem = .{
2102 .parent = parent_step,
2103 .elem_index = arr_elem.index,
2104 } },
2105 };
20462106 },
20472107 };
20482108
2049 if (ptr.byte_offset == 0 and ptr.ty == (try base_derive.ptrType(pt)).toIntern()) {
2109 if (ptr.byte_offset == 0 and
2110 ptr_ty_info.child == base_derive.elem_ty.toIntern() and
2111 ptr_size == base_derive.size and
2112 ptr_ty_info.flags.alignment == base_derive.@"align" and
2113 ptr_ty_info.flags.is_const == base_derive.@"const" and
2114 ptr_ty_info.flags.is_volatile == base_derive.@"volatile" and
2115 ptr_ty_info.flags.is_allowzero == base_derive.@"allowzero")
2116 {
20502117 return base_derive;
20512118 }
20522119
2053 const ptr_ty_info = Type.fromInterned(ptr.ty).ptrInfo(zcu);
20542120 const need_child: Type = .fromInterned(ptr_ty_info.child);
20552121 if (need_child.comptimeOnly(zcu) or
20562122 need_child.zigTypeTag(zcu) == .@"opaque" or
......@@ -2058,27 +2124,50 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
20582124 {
20592125 // No refinement can happen - this pointer is presumably invalid.
20602126 // Just offset it.
2061 const parent = try arena.create(PointerDeriveStep);
2127 const parent = try arena.create(PointerDerivation);
20622128 parent.* = base_derive;
2063 return .{ .offset_and_cast = .{
2064 .parent = parent,
2065 .byte_offset = ptr.byte_offset,
2066 .new_ptr_ty = Type.fromInterned(ptr.ty),
2067 } };
2129 return .{
2130 .elem_ty = .fromInterned(ptr_ty_info.child),
2131 .size = ptr_size,
2132 .@"align" = ptr_ty_info.flags.alignment,
2133 .@"const" = ptr_ty_info.flags.is_const,
2134 .@"volatile" = ptr_ty_info.flags.is_volatile,
2135 .@"allowzero" = ptr_ty_info.flags.is_allowzero,
2136 .addr = .{ .offset_and_cast = .{
2137 .parent = parent,
2138 .byte_offset = ptr.byte_offset,
2139 } },
2140 };
20682141 }
20692142 const need_bytes = need_child.abiSize(zcu);
20702143
20712144 var cur_derive = base_derive;
20722145 var cur_offset = ptr.byte_offset;
20732146
2147 if (cur_derive.size == .many) {
2148 const parent = try arena.create(PointerDerivation);
2149 parent.* = cur_derive;
2150 cur_derive = .{
2151 .elem_ty = parent.elem_ty,
2152 .size = .one,
2153 .@"align" = parent.@"align",
2154 .@"const" = parent.@"const",
2155 .@"volatile" = parent.@"volatile",
2156 .@"allowzero" = parent.@"allowzero",
2157 .addr = .{ .elem = .{
2158 .parent = parent,
2159 .elem_index = 0,
2160 } },
2161 };
2162 }
2163
20742164 // Refine through fields and array elements as much as possible.
20752165
20762166 if (need_bytes > 0) while (true) {
2077 const cur_ty = (try cur_derive.ptrType(pt)).childType(zcu);
2078 if (cur_ty.toIntern() == need_child.toIntern() and cur_offset == 0) {
2167 if (cur_derive.elem_ty.toIntern() == need_child.toIntern() and cur_offset == 0) {
20792168 break;
20802169 }
2081 switch (cur_ty.zigTypeTag(zcu)) {
2170 switch (cur_derive.elem_ty.zigTypeTag(zcu)) {
20822171 .noreturn,
20832172 .type,
20842173 .comptime_int,
......@@ -2105,71 +2194,105 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
21052194
21062195 .optional => {
21072196 ptr_opt: {
2108 if (!cur_ty.isPtrLikeOptional(zcu)) break :ptr_opt;
2197 if (!cur_derive.elem_ty.isPtrLikeOptional(zcu)) break :ptr_opt;
21092198 if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt;
21102199 switch (need_child.ptrSize(zcu)) {
21112200 .one, .many => {},
21122201 .slice, .c => break :ptr_opt,
21132202 }
2114 const parent = try arena.create(PointerDeriveStep);
2203 const parent = try arena.create(PointerDerivation);
21152204 parent.* = cur_derive;
2116 cur_derive = .{ .opt_payload_ptr = .{
2117 .parent = parent,
2118 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), cur_ty.optionalChild(zcu)),
2119 } };
2205 cur_derive = .{
2206 .elem_ty = parent.elem_ty.optionalChild(zcu),
2207 .size = .one,
2208 .@"align" = parent.@"align",
2209 .@"const" = parent.@"const",
2210 .@"volatile" = parent.@"volatile",
2211 .@"allowzero" = parent.@"allowzero",
2212 .addr = .{ .opt_payload = .{
2213 .parent = parent,
2214 } },
2215 };
21202216 continue;
21212217 }
21222218 break;
21232219 },
21242220
21252221 .array => {
2126 const elem_ty = cur_ty.childType(zcu);
2222 const elem_ty = cur_derive.elem_ty.childType(zcu);
21272223 const elem_size = elem_ty.abiSize(zcu);
21282224 const start_idx = cur_offset / elem_size;
21292225 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
2226 const start_off = start_idx * elem_size;
21302227 if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .one) {
2131 const parent = try arena.create(PointerDeriveStep);
2228 const parent = try arena.create(PointerDerivation);
21322229 parent.* = cur_derive;
2133 cur_derive = .{ .elem_ptr = .{
2134 .parent = parent,
2135 .elem_idx = start_idx,
2136 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty),
2137 } };
2138 cur_offset -= start_idx * elem_size;
2230 cur_derive = .{
2231 .elem_ty = elem_ty,
2232 .size = .one,
2233 .@"align" = switch (parent.@"align") {
2234 .none => .none,
2235 else => |a| a.offset(start_off),
2236 },
2237 .@"const" = parent.@"const",
2238 .@"volatile" = parent.@"volatile",
2239 .@"allowzero" = parent.@"allowzero",
2240 .addr = .{ .elem = .{
2241 .parent = parent,
2242 .elem_index = start_idx,
2243 } },
2244 };
2245 cur_offset -= start_off;
21392246 } else {
2140 // Go into the first element if needed, but don't go any deeper.
2141 if (start_idx > 0) {
2142 const parent = try arena.create(PointerDeriveStep);
2247 // Go into the first element if the byte offsets line up neatly, but don't try
2248 // to go any deeper.
2249 if (start_idx > 0 and start_idx * elem_size == cur_offset) {
2250 const parent = try arena.create(PointerDerivation);
21432251 parent.* = cur_derive;
2144 cur_derive = .{ .elem_ptr = .{
2145 .parent = parent,
2146 .elem_idx = start_idx,
2147 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty),
2148 } };
2149 cur_offset -= start_idx * elem_size;
2252 cur_derive = .{
2253 .elem_ty = elem_ty,
2254 .size = .one,
2255 .@"align" = switch (parent.@"align") {
2256 .none => .none,
2257 else => |a| a.offset(start_off),
2258 },
2259 .@"const" = parent.@"const",
2260 .@"volatile" = parent.@"volatile",
2261 .@"allowzero" = parent.@"allowzero",
2262 .addr = .{ .elem = .{
2263 .parent = parent,
2264 .elem_index = start_idx,
2265 } },
2266 };
2267 cur_offset -= start_off;
21502268 }
21512269 break;
21522270 }
21532271 },
2154 .@"struct" => switch (cur_ty.containerLayout(zcu)) {
2272 .@"struct" => switch (cur_derive.elem_ty.containerLayout(zcu)) {
21552273 .auto, .@"packed" => break,
2156 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
2157 const field_ty = cur_ty.fieldType(field_idx, zcu);
2158 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
2274 .@"extern" => for (0..cur_derive.elem_ty.structFieldCount(zcu)) |field_idx| {
2275 const field_ty = cur_derive.elem_ty.fieldType(field_idx, zcu);
2276 const start_off = cur_derive.elem_ty.structFieldOffset(field_idx, zcu);
21592277 const end_off = start_off + field_ty.abiSize(zcu);
21602278 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
2161 const base_ptr_ty = try pt.ptrType(info: {
2162 var info = (try cur_derive.ptrType(pt)).ptrInfo(zcu);
2163 info.flags.size = .one;
2164 break :info info;
2165 });
2166 const parent = try arena.create(PointerDeriveStep);
2279 const parent = try arena.create(PointerDerivation);
21672280 parent.* = cur_derive;
2168 cur_derive = .{ .field_ptr = .{
2169 .parent = parent,
2170 .field_idx = @intCast(field_idx),
2171 .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field_idx), pt),
2172 } };
2281 cur_derive = .{
2282 .elem_ty = field_ty,
2283 .size = .one,
2284 .@"align" = switch (parent.@"align") {
2285 .none => .none,
2286 else => |a| a.offset(start_off),
2287 },
2288 .@"const" = parent.@"const",
2289 .@"volatile" = parent.@"volatile",
2290 .@"allowzero" = parent.@"allowzero",
2291 .addr = .{ .field = .{
2292 .parent = parent,
2293 .field_index = @intCast(field_idx),
2294 } },
2295 };
21732296 cur_offset -= start_off;
21742297 break;
21752298 }
......@@ -2179,31 +2302,33 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
21792302 };
21802303
21812304 if (cur_offset == 0) compatible: {
2182 const src_ptr_ty_info = (try cur_derive.ptrType(pt)).ptrInfo(zcu);
21832305 // We allow silently doing some "coercible" pointer things.
21842306 // In particular, we only give up if cv qualifiers are *removed*.
2185 if (src_ptr_ty_info.flags.is_const and !ptr_ty_info.flags.is_const) break :compatible;
2186 if (src_ptr_ty_info.flags.is_volatile and !ptr_ty_info.flags.is_volatile) break :compatible;
2187 if (src_ptr_ty_info.flags.is_allowzero and !ptr_ty_info.flags.is_allowzero) break :compatible;
2188 // Everything else has to match exactly.
2189 if (src_ptr_ty_info.child != ptr_ty_info.child) break :compatible;
2190 if (src_ptr_ty_info.sentinel != ptr_ty_info.sentinel) break :compatible;
2191 if (src_ptr_ty_info.packed_offset != ptr_ty_info.packed_offset) break :compatible;
2192 if (src_ptr_ty_info.flags.size != ptr_ty_info.flags.size) break :compatible;
2193 if (src_ptr_ty_info.flags.alignment != ptr_ty_info.flags.alignment) break :compatible;
2194 if (src_ptr_ty_info.flags.address_space != ptr_ty_info.flags.address_space) break :compatible;
2195 if (src_ptr_ty_info.flags.vector_index != ptr_ty_info.flags.vector_index) break :compatible;
2307 if (cur_derive.@"const" and !ptr_ty_info.flags.is_const) break :compatible;
2308 if (cur_derive.@"volatile" and !ptr_ty_info.flags.is_volatile) break :compatible;
2309 if (cur_derive.@"allowzero" and !ptr_ty_info.flags.is_allowzero) break :compatible;
2310 // Element type and alignment, however, have to match exactly.
2311 if (cur_derive.elem_ty.toIntern() != ptr_ty_info.child) break :compatible;
2312 if (cur_derive.size != ptr_size) break :compatible;
2313 if (cur_derive.@"align" != ptr_ty_info.flags.alignment) break :compatible;
21962314
21972315 return cur_derive;
21982316 }
21992317
2200 const parent = try arena.create(PointerDeriveStep);
2318 const parent = try arena.create(PointerDerivation);
22012319 parent.* = cur_derive;
2202 return .{ .offset_and_cast = .{
2203 .parent = parent,
2204 .byte_offset = cur_offset,
2205 .new_ptr_ty = Type.fromInterned(ptr.ty),
2206 } };
2320 return .{
2321 .elem_ty = .fromInterned(ptr_ty_info.child),
2322 .size = ptr_size,
2323 .@"align" = ptr_ty_info.flags.alignment,
2324 .@"const" = ptr_ty_info.flags.is_const,
2325 .@"volatile" = ptr_ty_info.flags.is_volatile,
2326 .@"allowzero" = ptr_ty_info.flags.is_allowzero,
2327 .addr = .{ .offset_and_cast = .{
2328 .parent = parent,
2329 .byte_offset = cur_offset,
2330 } },
2331 };
22072332}
22082333
22092334const InterpretMode = enum {
src/Zcu/PerThread.zig+2-2
......@@ -3459,7 +3459,7 @@ fn analyzeFuncBodyInner(
34593459 &inner_block,
34603460 inner_block.nodeOffset(.zero),
34613461 "cannot resolve inferred error set of {s} function type '{f}'",
3462 .{ description, fn_ty.fmt(pt) },
3462 .{ description, fn_ty.fmt(zcu) },
34633463 );
34643464 }
34653465
......@@ -4575,6 +4575,6 @@ fn printVerboseAir(
45754575 const zcu = pt.zcu;
45764576 const ip = &zcu.intern_pool;
45774577 try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)});
4578 try air.write(w, pt, liveness);
4578 try air.write(w, zcu, liveness);
45794579 try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)});
45804580}
src/codegen.zig+7-6
......@@ -255,7 +255,6 @@ pub fn generateLazySymbol(
255255) link.EmitError!void {
256256 const tracy = trace(@src());
257257 defer tracy.end();
258 tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(pt) });
259258
260259 const comp = bin_file.comp;
261260 const zcu = pt.zcu;
......@@ -263,9 +262,11 @@ pub fn generateLazySymbol(
263262 const target = &comp.root_mod.resolved_target.result;
264263 const endian = target.cpu.arch.endian();
265264
265 tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(zcu) });
266
266267 log.debug("generateLazySymbol: kind = {s}, ty = {f}", .{
267268 @tagName(lazy_sym.kind),
268 Type.fromInterned(lazy_sym.ty).fmt(pt),
269 Type.fromInterned(lazy_sym.ty).fmt(zcu),
269270 });
270271
271272 if (lazy_sym.kind == .code) {
......@@ -303,7 +304,7 @@ pub fn generateLazySymbol(
303304 }
304305 } else {
305306 return zcu.codegenFailType(lazy_sym.ty, "TODO implement generateLazySymbol for {s} {f}", .{
306 @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt),
307 @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu),
307308 });
308309 }
309310}
......@@ -325,7 +326,7 @@ pub fn generateSymbol(
325326 const target = zcu.getTarget();
326327 const endian = target.cpu.arch.endian();
327328
328 log.debug("generateSymbol: val = {f}", .{val.fmtValue(pt)});
329 log.debug("generateSymbol: val = {f}", .{val.fmtValue(zcu)});
329330
330331 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse {
331332 return zcu.comp.link_diags.fail("failed to generate symbol: type size overflow", .{});
......@@ -733,7 +734,7 @@ fn lowerUavRef(
733734 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
734735 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";
735736
736 log.debug("lowerUavRef: ty = {f}", .{uav_ty.fmt(pt)});
737 log.debug("lowerUavRef: ty = {f}", .{uav_ty.fmt(zcu)});
737738
738739 if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) {
739740 try w.splatByteAll(0xaa, ptr_width_bytes);
......@@ -876,7 +877,7 @@ pub fn lowerValue(pt: Zcu.PerThread, val: Value, target: *const std.Target) Allo
876877 const ip = &zcu.intern_pool;
877878 const ty = val.typeOf(zcu);
878879
879 log.debug("lowerValue(@as({f}, {f}))", .{ ty.fmt(pt), val.fmtValue(pt) });
880 log.debug("lowerValue(@as({f}, {f}))", .{ ty.fmt(zcu), val.fmtValue(zcu) });
880881
881882 if (val.isUndef(zcu)) return .undef;
882883
src/codegen/aarch64/Select.zig+3-3
......@@ -946,7 +946,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void
946946 isel: *Select,
947947 inst: Air.Inst.Index,
948948 pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {
949 fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt, null);
949 fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt.zcu, null);
950950 }
951951 } {
952952 return .{ .isel = it.isel, .inst = inst };
......@@ -7974,11 +7974,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {
79747974}
79757975
79767976fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {
7977 return ty.fmt(isel.pt);
7977 return ty.fmt(isel.pt.zcu);
79787978}
79797979
79807980fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? {
7981 return constant.fmtValue(isel.pt);
7981 return constant.fmtValue(isel.pt.zcu);
79827982}
79837983
79847984fn block(
src/codegen/c.zig+112-90
......@@ -740,59 +740,57 @@ pub const DeclGen = struct {
740740 fn renderUav(
741741 dg: *DeclGen,
742742 w: *Writer,
743 uav: InternPool.Key.Ptr.BaseAddr.Uav,
743 uav_val: Value,
744 derivation: Value.PointerDerivation,
744745 location: ValueRenderLocation,
745746 ) Error!void {
746747 const pt = dg.pt;
747748 const zcu = pt.zcu;
748749 const ip = &zcu.intern_pool;
749 const uav_val = Value.fromInterned(uav.val);
750750 const uav_ty = uav_val.typeOf(zcu);
751751
752752 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
753 const ptr_ty: Type = .fromInterned(uav.orig_ty);
754 if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {
755 try w.writeByte('(');
756 try dg.renderOpvPointer(w, ptr_ty, location);
757 return w.writeByte(')');
753 if (!uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {
754 const target = zcu.getTarget();
755 const alignment = switch (derivation.@"align") {
756 .none => derivation.elem_ty.abiAlignment(zcu),
757 else => |a| a,
758 };
759 try w.writeAll("((");
760 try dg.renderDerivedPointerType(w, derivation);
761 try w.print("){f})", .{fmtUnsignedIntLiteralSmall(
762 target,
763 .uintptr_t,
764 alignment.forward(undefPattern(u64) >> @intCast(64 - target.ptrBitWidth())),
765 location == .static_initializer,
766 16,
767 .lower,
768 )});
769 return;
758770 }
759771
760 switch (ip.indexToKey(uav.val)) {
772 switch (ip.indexToKey(uav_val.toIntern())) {
761773 .func => unreachable,
762774 .@"extern" => unreachable,
763775 else => {},
764776 }
765777
766 // We shouldn't cast C function pointers as this is UB (when you call
767 // them). The analysis until now should ensure that the C function
768 // pointers are compatible. If they are not, then there is a bug
769 // somewhere and we should let the C compiler tell us about it.
770 const elem_ty = ptr_ty.childType(zcu);
771 const need_cast = elem_ty.toIntern() != uav_ty.toIntern() and
772 elem_ty.zigTypeTag(zcu) != .@"fn" or uav_ty.zigTypeTag(zcu) != .@"fn";
773 if (need_cast) {
774 try w.writeAll("((");
775 try dg.renderType(w, ptr_ty);
776 try w.writeByte(')');
777 }
778778 try w.writeByte('&');
779779 try renderUavName(w, uav_val);
780 if (need_cast) try w.writeByte(')');
781780
782781 // Indicate that the anon decl should be rendered to the output so that
783782 // our reference above is not undefined.
784 const ptr_type = ip.indexToKey(uav.orig_ty).ptr_type;
785 const gop = try dg.uavs.getOrPut(dg.gpa, uav.val);
783 const gop = try dg.uavs.getOrPut(dg.gpa, uav_val.toIntern());
786784 if (!gop.found_existing) gop.value_ptr.* = .none;
787785 // If there is an explicit alignment, greater than the current one, use it.
788786 // Note that we intentionally start at `.none`, so `gop.value_ptr.*` is never
789787 // underaligned, so we don't need to worry about the `.none` case here.
790 if (ptr_type.flags.alignment != .none) {
788 if (derivation.@"align" != .none) {
791789 // Resolve the current alignment so we can choose the bigger one.
792790 const cur_alignment: Alignment = if (gop.value_ptr.* == .none) abi: {
793 break :abi Type.fromInterned(ptr_type.child).abiAlignment(zcu);
791 break :abi uav_ty.abiAlignment(zcu);
794792 } else gop.value_ptr.*;
795 gop.value_ptr.* = cur_alignment.maxStrict(ptr_type.flags.alignment);
793 gop.value_ptr.* = cur_alignment.maxStrict(derivation.@"align");
796794 }
797795 }
798796
......@@ -818,28 +816,14 @@ pub const DeclGen = struct {
818816
819817 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
820818 const nav_ty: Type = .fromInterned(ip.getNav(owner_nav).resolved.?.type);
821 const ptr_ty = try pt.navPtrType(owner_nav);
822819 if (nav_ty.zigTypeTag(zcu) != .@"opaque" and !nav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {
823820 try w.writeByte('(');
824 try dg.renderOpvPointer(w, ptr_ty, location);
821 try dg.renderOpvPointer(w, try pt.navPtrType(owner_nav), location);
825822 return w.writeByte(')');
826823 }
827824
828 // We shouldn't cast C function pointers as this is UB (when you call
829 // them). The analysis until now should ensure that the C function
830 // pointers are compatible. If they are not, then there is a bug
831 // somewhere and we should let the C compiler tell us about it.
832 const elem_ty = ptr_ty.childType(zcu);
833 const need_cast = elem_ty.toIntern() != nav_ty.toIntern() and
834 elem_ty.zigTypeTag(zcu) != .@"fn" or nav_ty.zigTypeTag(zcu) != .@"fn";
835 if (need_cast) {
836 try w.writeAll("((");
837 try dg.renderType(w, ptr_ty);
838 try w.writeByte(')');
839 }
840825 try w.writeByte('&');
841826 try renderNavName(w, owner_nav, ip);
842 if (need_cast) try w.writeByte(')');
843827 }
844828
845829 fn renderOpvPointer(
......@@ -865,92 +849,108 @@ pub const DeclGen = struct {
865849 fn renderPointer(
866850 dg: *DeclGen,
867851 w: *Writer,
868 derivation: Value.PointerDeriveStep,
852 derivation: Value.PointerDerivation,
869853 location: ValueRenderLocation,
870854 ) Error!void {
871855 const pt = dg.pt;
872856 const zcu = pt.zcu;
873 switch (derivation) {
874 .comptime_alloc_ptr, .comptime_field_ptr => unreachable,
857 switch (derivation.addr) {
858 .comptime_alloc, .comptime_field => unreachable,
875859 .int => |int| {
876 const addr_val = try pt.intValue(.usize, int.addr);
860 const addr_val = try pt.intValue(.usize, int);
877861 try w.writeByte('(');
878 try dg.renderType(w, int.ptr_ty);
862 try dg.renderDerivedPointerType(w, derivation);
879863 try w.print("){f}", .{try dg.fmtIntLiteralHex(addr_val, .other)});
880864 },
881865
882 .nav_ptr => |nav| try dg.renderNav(w, nav, location),
883 .uav_ptr => |uav| try dg.renderUav(w, uav, location),
866 .nav => |nav| try dg.renderNav(w, nav, location),
867 .uav => |val| try dg.renderUav(w, val, derivation, location),
884868
885 inline .eu_payload_ptr, .opt_payload_ptr => |info| {
869 inline .eu_payload, .opt_payload => |info| {
886870 try w.writeAll("&(");
887871 try dg.renderPointer(w, info.parent.*, location);
888872 try w.writeAll(")->payload");
889873 },
890874
891 .field_ptr => |field| {
892 const parent_ptr_ty = try field.parent.ptrType(pt);
893
894 switch (fieldLocation(parent_ptr_ty, field.result_ptr_ty, field.field_idx, zcu)) {
875 .field => |derived| {
876 switch (fieldLocation(derived.parent.elem_ty, derivation.elem_ty, derived.field_index, zcu)) {
895877 .begin => {
896878 try w.writeByte('(');
897 try dg.renderType(w, field.result_ptr_ty);
879 try dg.renderDerivedPointerType(w, derivation);
898880 try w.writeByte(')');
899 try dg.renderPointer(w, field.parent.*, location);
881 try dg.renderPointer(w, derived.parent.*, location);
900882 },
901883 .field => |name| {
902884 try w.writeAll("&(");
903 try dg.renderPointer(w, field.parent.*, location);
885 try dg.renderPointer(w, derived.parent.*, location);
904886 try w.writeAll(")->");
905887 try dg.writeCValue(w, name);
906888 },
907889 .byte_offset => |byte_offset| {
908890 try w.writeByte('(');
909 try dg.renderType(w, field.result_ptr_ty);
891 try dg.renderDerivedPointerType(w, derivation);
910892 try w.writeByte(')');
911893 const offset_val = try pt.intValue(.usize, byte_offset);
912894 try w.writeAll("((char *)");
913 try dg.renderPointer(w, field.parent.*, location);
895 try dg.renderPointer(w, derived.parent.*, location);
914896 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});
915897 },
916898 }
917899 },
918900
919 .elem_ptr => |elem| if (!(try elem.parent.ptrType(pt)).childType(zcu).hasRuntimeBits(zcu)) {
901 .elem => |derived| if (!derived.parent.elem_ty.hasRuntimeBits(zcu)) {
920902 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.
921903 try w.writeByte('(');
922 try dg.renderType(w, elem.result_ptr_ty);
904 try dg.renderDerivedPointerType(w, derivation);
923905 try w.writeByte(')');
924 try dg.renderPointer(w, elem.parent.*, location);
906 try dg.renderPointer(w, derived.parent.*, location);
925907 } else {
926 const index_val = try pt.intValue(.usize, elem.elem_idx);
908 const index_val = try pt.intValue(.usize, derived.elem_index);
927909 try w.writeByte('(');
928910 // We want to do pointer arithmetic on a pointer to the element type, but the parent
929 // might be a pointer-to-array, in which case we must cast it.
930 if (elem.result_ptr_ty.toIntern() != (try elem.parent.ptrType(pt)).toIntern()) {
931 try w.writeByte('(');
932 try dg.renderType(w, elem.result_ptr_ty);
933 try w.writeByte(')');
934 }
935 try dg.renderPointer(w, elem.parent.*, location);
911 // is a pointer-to-array, so we need to cast first.
912 try w.writeByte('(');
913 try dg.renderDerivedPointerType(w, derivation);
914 try w.writeByte(')');
915
916 try dg.renderPointer(w, derived.parent.*, location);
936917 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(index_val, .other)});
937918 },
938919
939 .offset_and_cast => |oac| {
920 .offset_and_cast => |derived| {
940921 try w.writeByte('(');
941 try dg.renderType(w, oac.new_ptr_ty);
922 try dg.renderDerivedPointerType(w, derivation);
942923 try w.writeByte(')');
943 if (oac.byte_offset == 0) {
944 try dg.renderPointer(w, oac.parent.*, location);
924 if (derived.byte_offset == 0) {
925 try dg.renderPointer(w, derived.parent.*, location);
945926 } else {
946 const offset_val = try pt.intValue(.usize, oac.byte_offset);
927 const offset_val = try pt.intValue(.usize, derived.byte_offset);
947928 try w.writeAll("((char *)");
948 try dg.renderPointer(w, oac.parent.*, location);
929 try dg.renderPointer(w, derived.parent.*, location);
949930 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});
950931 }
951932 },
952933 }
953934 }
935 fn renderDerivedPointerType(
936 dg: *DeclGen,
937 w: *Writer,
938 derivation: Value.PointerDerivation,
939 ) Error!void {
940 return dg.renderType(w, try dg.pt.ptrType(.{
941 .child = derivation.elem_ty.toIntern(),
942 .flags = .{
943 .size = switch (derivation.size) {
944 .one => .one,
945 .many => .many,
946 },
947 .alignment = derivation.@"align",
948 .is_const = derivation.@"const",
949 .is_volatile = derivation.@"volatile",
950 .is_allowzero = derivation.@"allowzero",
951 },
952 }));
953 }
954954
955955 fn renderValueAsLvalue(
956956 dg: *DeclGen,
......@@ -1166,7 +1166,31 @@ pub const DeclGen = struct {
11661166 try w.writeByte('}');
11671167 },
11681168 .ptr => {
1169 const derivation = try val.pointerDerivation(dg.arena, pt, null);
1169 // TODO: `Value.pointerDerivation` ought to do this for us, but it doesn't receive
1170 // `pt`, so it actually *can't* until https://github.com/ziglang/zig/issues/24061 is
1171 // implemented.
1172 const non_packed_ptr: Value = non_packed_ptr: {
1173 const ptr_info = val.typeOf(zcu).ptrInfo(zcu);
1174 if (ptr_info.packed_offset.host_size == 0) {
1175 break :non_packed_ptr val;
1176 }
1177 const backing_ty: Type = switch (ptr_info.flags.vector_index) {
1178 _ => .fromInterned(ptr_info.child),
1179 .none => try pt.intType(
1180 .unsigned,
1181 @intCast(ptr_info.packed_offset.host_size * 8),
1182 ),
1183 };
1184 const new_ptr_ty = try pt.ptrType(info: {
1185 var info = ptr_info;
1186 info.child = backing_ty.toIntern();
1187 info.packed_offset = .{ .host_size = 0, .bit_offset = 0 };
1188 info.flags.vector_index = .none;
1189 break :info info;
1190 });
1191 break :non_packed_ptr try pt.getCoerced(val, new_ptr_ty);
1192 };
1193 const derivation = try non_packed_ptr.pointerDerivation(dg.arena, zcu, null);
11701194 try w.writeByte('(');
11711195 try dg.renderPointer(w, derivation, location);
11721196 try w.writeByte(')');
......@@ -5380,8 +5404,8 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
53805404}
53815405
53825406fn fieldLocation(
5383 container_ptr_ty: Type,
5384 field_ptr_ty: Type,
5407 container_ty: Type,
5408 field_ty: Type,
53855409 field_index: u32,
53865410 zcu: *Zcu,
53875411) union(enum) {
......@@ -5390,27 +5414,22 @@ fn fieldLocation(
53905414 byte_offset: u64,
53915415} {
53925416 const ip = &zcu.intern_pool;
5393 const container_ty: Type = .fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child);
53945417 switch (ip.indexToKey(container_ty.toIntern())) {
53955418 .struct_type => {
53965419 const loaded_struct = ip.loadStructType(container_ty.toIntern());
53975420 return switch (loaded_struct.layout) {
53985421 .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu))
53995422 .begin
5400 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
5423 else if (!field_ty.hasRuntimeBits(zcu))
54015424 .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] }
54025425 else
54035426 .{ .field = .{ .identifier = loaded_struct.field_names.get(ip)[field_index].toSlice(ip) } },
5404 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)
5405 .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) +
5406 container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) }
5407 else
5408 .begin,
5427 .@"packed" => .begin,
54095428 };
54105429 },
54115430 .tuple_type => return if (!container_ty.hasRuntimeBits(zcu))
54125431 .begin
5413 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))
5432 else if (!field_ty.hasRuntimeBits(zcu))
54145433 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
54155434 else
54165435 .{ .field = .{ .field = field_index } },
......@@ -5418,7 +5437,6 @@ fn fieldLocation(
54185437 const loaded_union = ip.loadUnionType(container_ty.toIntern());
54195438 switch (loaded_union.layout) {
54205439 .auto => {
5421 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
54225440 if (!field_ty.hasRuntimeBits(zcu)) {
54235441 if (container_ty.unionHasAllZeroBitFieldTypes(zcu)) return .begin;
54245442 return .{ .field = .{ .identifier = "payload" } };
......@@ -5427,7 +5445,6 @@ fn fieldLocation(
54275445 return .{ .field = .{ .payload_identifier = field_name.toSlice(ip) } };
54285446 },
54295447 .@"extern" => {
5430 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
54315448 if (!field_ty.hasRuntimeBits(zcu)) return .begin;
54325449 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
54335450 return .{ .field = .{ .identifier = field_name.toSlice(ip) } };
......@@ -5486,7 +5503,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
54865503 try f.renderType(w, container_ptr_ty);
54875504 try w.writeByte(')');
54885505
5489 switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, zcu)) {
5506 switch (fieldLocation(container_ty, field_ptr_ty.childType(zcu), extra.field_index, zcu)) {
54905507 .begin => try f.writeCValue(w, field_ptr_val, .other),
54915508 .field => |field| {
54925509 const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
......@@ -5537,7 +5554,12 @@ fn fieldPtr(
55375554 try f.renderType(w, field_ptr_ty);
55385555 try w.writeByte(')');
55395556
5540 switch (fieldLocation(container_ptr_ty, field_ptr_ty, field_index, zcu)) {
5557 switch (fieldLocation(
5558 container_ptr_ty.childType(zcu),
5559 field_ptr_ty.childType(zcu),
5560 field_index,
5561 zcu,
5562 )) {
55415563 .begin => try f.writeCValue(w, container_ptr_val, .other),
55425564 .field => |field| {
55435565 try w.writeByte('&');
src/codegen/c/type/render_defs.zig+4-4
......@@ -28,7 +28,7 @@ pub fn defineAligned(
2828 });
2929 if (!zcu.comp.config.root_strip) try w.print(" /* align({d}) {f} */", .{
3030 alignment.toByteUnits().?,
31 ty.fmt(pt),
31 ty.fmt(zcu),
3232 });
3333 try w.writeByte('\n');
3434}
......@@ -113,7 +113,7 @@ pub fn errunionDefineComplete(
113113 });
114114 }
115115 if (!zcu.comp.config.root_strip) try w.print(" /* anyerror!{f} */", .{
116 payload_ty.fmt(pt),
116 payload_ty.fmt(zcu),
117117 });
118118 try w.writeByte('\n');
119119}
......@@ -159,7 +159,7 @@ pub fn defineIncomplete(ty: Type, w: *Writer, pt: Zcu.PerThread) Writer.Error!vo
159159 name_cty.fmtTypeName(zcu),
160160 });
161161 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{
162 ty.fmt(pt),
162 ty.fmt(zcu),
163163 });
164164 try w.writeByte('\n');
165165}
......@@ -337,7 +337,7 @@ pub fn defineComplete(
337337 else => return,
338338 };
339339 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{
340 ty.fmt(pt),
340 ty.fmt(zcu),
341341 });
342342 try w.writeByte('\n');
343343 if (check_cty) |cty| try writeStaticAssertTypeLayout(ty, cty, w, zcu);
src/codegen/llvm.zig+4-3
......@@ -1354,6 +1354,7 @@ pub const Object = struct {
13541354 ///
13551355 /// `val` is always a type because `o.type_pool` only contains types.
13561356 pub fn updateConstIncomplete(o: *Object, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void {
1357 _ = pt;
13571358 const zcu = o.zcu;
13581359 assert(zcu.intern_pool.typeOf(val) == .type_type);
13591360
......@@ -1367,7 +1368,7 @@ pub const Object = struct {
13671368 if (!o.builder.strip) {
13681369 assert(val != .anyerror_type);
13691370 const fwd_ref = o.debug_types.items[@backingInt(index)];
1370 const name_str = try o.builder.metadataStringFmt("{f}", .{ty.fmt(pt)});
1371 const name_str = try o.builder.metadataStringFmt("{f}", .{ty.fmt(zcu)});
13711372 // If `ty` is a function, use a dummy *function* type to prevent existing debug
13721373 // subprograms from becoming ill-formed.
13731374 const debug_incomplete_type = switch (ty.zigTypeTag(zcu)) {
......@@ -1458,7 +1459,7 @@ pub const Object = struct {
14581459 const target = zcu.getTarget();
14591460 const ip = &zcu.intern_pool;
14601461
1461 const name = try o.builder.metadataStringFmt("{f}", .{ty.fmt(pt)});
1462 const name = try o.builder.metadataStringFmt("{f}", .{ty.fmt(zcu)});
14621463
14631464 // lldb cannot handle non-byte-sized types, so in the logic below, bit sizes are padded up.
14641465 // For instance, `bool` is considered to be 8 bits, and `u60` is considered to be 64 bits.
......@@ -1967,7 +1968,7 @@ pub const Object = struct {
19671968 const debug_payload_type = try o.builder.debugUnionType(
19681969 payload_name: {
19691970 if (layout.tag_size == 0) break :payload_name name;
1970 break :payload_name try o.builder.metadataStringFmt("{f}:Payload", .{ty.fmt(pt)});
1971 break :payload_name try o.builder.metadataStringFmt("{f}:Payload", .{ty.fmt(zcu)});
19711972 },
19721973 file,
19731974 scope,
src/codegen/loongarch/Select.zig+3-3
......@@ -3016,7 +3016,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void
30163016 isel: *Select,
30173017 inst: Air.Inst.Index,
30183018 pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {
3019 fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt, null);
3019 fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt.zcu, null);
30203020 }
30213021 } {
30223022 return .{ .isel = it.isel, .inst = inst };
......@@ -5266,11 +5266,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {
52665266}
52675267
52685268fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {
5269 return ty.fmt(isel.pt);
5269 return ty.fmt(isel.pt.zcu);
52705270}
52715271
52725272fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? {
5273 return constant.fmtValue(isel.pt);
5273 return constant.fmtValue(isel.pt.zcu);
52745274}
52755275
52765276fn fmtRegisterSet(regs: RegisterSet) struct {
src/codegen/riscv64/CodeGen.zig+18-18
......@@ -1291,7 +1291,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
12911291 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
12921292 .@"enum" => {
12931293 const enum_ty = Type.fromInterned(lazy_sym.ty);
1294 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)});
1294 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(zcu)});
12951295
12961296 const param_regs = abi.Registers.Integer.function_arg_regs;
12971297 const ret_reg = param_regs[0];
......@@ -1374,7 +1374,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
13741374 },
13751375 else => return func.fail(
13761376 "TODO implement {s} for {f}",
1377 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },
1377 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu) },
13781378 ),
13791379 }
13801380}
......@@ -1911,7 +1911,7 @@ fn splitType(func: *Func, ty: Type) ![2]Type {
19111911 else => return func.fail("TODO: splitType class {}", .{class}),
19121912 };
19131913 } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts;
1914 return func.fail("TODO implement splitType for {f}", .{ty.fmt(func.pt)});
1914 return func.fail("TODO implement splitType for {f}", .{ty.fmt(zcu)});
19151915}
19161916
19171917/// Truncates the value in the register in place.
......@@ -2024,7 +2024,7 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {
20242024 const val_ty = ptr_ty.childType(zcu);
20252025 return func.allocFrameIndex(FrameAlloc.init(.{
20262026 .size = math.cast(u32, val_ty.abiSize(zcu)) orelse {
2027 return func.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)});
2027 return func.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(zcu)});
20282028 },
20292029 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
20302030 }));
......@@ -2164,7 +2164,7 @@ pub fn spillRegisters(func: *Func, comptime registers: []const Register) !void {
21642164/// allocated. A second call to `copyToTmpRegister` may return the same register.
21652165/// This can have a side effect of spilling instructions to the stack to free up a register.
21662166fn copyToTmpRegister(func: *Func, ty: Type, mcv: MCValue) !Register {
2167 log.debug("copyToTmpRegister ty: {f}", .{ty.fmt(func.pt)});
2167 log.debug("copyToTmpRegister ty: {f}", .{ty.fmt(func.pt.zcu)});
21682168 const reg = try func.register_manager.allocReg(null, func.regTempClassForType(ty));
21692169 try func.genSetReg(ty, reg, mcv);
21702170 return reg;
......@@ -2249,7 +2249,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void {
22492249
22502250 break :result dst_mcv;
22512251 } orelse return func.fail("TODO: implement airIntCast from {f} to {f}", .{
2252 src_ty.fmt(pt), dst_ty.fmt(pt),
2252 src_ty.fmt(zcu), dst_ty.fmt(zcu),
22532253 });
22542254
22552255 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -2636,7 +2636,7 @@ fn genBinOp(
26362636 .add_sat,
26372637 => {
26382638 if (bit_size != 64 or !is_unsigned)
2639 return func.fail("TODO: genBinOp ty: {f}", .{lhs_ty.fmt(pt)});
2639 return func.fail("TODO: genBinOp ty: {f}", .{lhs_ty.fmt(zcu)});
26402640
26412641 const tmp_reg = try func.copyToTmpRegister(rhs_ty, .{ .register = rhs_reg });
26422642 const tmp_lock = func.register_manager.lockRegAssumeUnused(tmp_reg);
......@@ -4057,7 +4057,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
40574057 } else {
40584058 return func.fail(
40594059 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}, tag {f}",
4060 .{ frame_mcv, tag_ty.fmt(pt) },
4060 .{ frame_mcv, tag_ty.fmt(zcu) },
40614061 );
40624062 }
40634063 },
......@@ -4177,7 +4177,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
41774177
41784178 switch (scalar_ty.zigTypeTag(zcu)) {
41794179 .int => if (ty.zigTypeTag(zcu) == .vector) {
4180 return func.fail("TODO implement airAbs for {f}", .{ty.fmt(pt)});
4180 return func.fail("TODO implement airAbs for {f}", .{ty.fmt(zcu)});
41814181 } else {
41824182 const int_info = scalar_ty.intInfo(zcu);
41834183 const int_bits = int_info.bits;
......@@ -4258,7 +4258,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
42584258
42594259 break :result return_mcv;
42604260 },
4261 else => return func.fail("TODO: implement airAbs {f}", .{scalar_ty.fmt(pt)}),
4261 else => return func.fail("TODO: implement airAbs {f}", .{scalar_ty.fmt(zcu)}),
42624262 }
42634263
42644264 break :result .unreach;
......@@ -4322,7 +4322,7 @@ fn airByteSwap(func: *Func, inst: Air.Inst.Index) !void {
43224322
43234323 break :result dest_mcv;
43244324 },
4325 else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(pt)}),
4325 else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(zcu)}),
43264326 }
43274327 };
43284328 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
......@@ -4388,7 +4388,7 @@ fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
43884388 else => return func.fail("TODO: airUnaryMath Float {s}", .{@tagName(tag)}),
43894389 }
43904390 },
4391 else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(pt)}),
4391 else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(zcu)}),
43924392 }
43934393
43944394 break :result MCValue{ .register = dst_reg };
......@@ -4488,7 +4488,7 @@ fn load(func: *Func, dst_mcv: MCValue, ptr_mcv: MCValue, ptr_ty: Type) InnerErro
44884488 const zcu = pt.zcu;
44894489 const dst_ty = ptr_ty.childType(zcu);
44904490
4491 log.debug("loading {}:{f} into {}", .{ ptr_mcv, ptr_ty.fmt(pt), dst_mcv });
4491 log.debug("loading {}:{f} into {}", .{ ptr_mcv, ptr_ty.fmt(zcu), dst_mcv });
44924492
44934493 switch (ptr_mcv) {
44944494 .none,
......@@ -4541,7 +4541,7 @@ fn airStore(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
45414541fn store(func: *Func, ptr_mcv: MCValue, src_mcv: MCValue, ptr_ty: Type) !void {
45424542 const zcu = func.pt.zcu;
45434543 const src_ty = ptr_ty.childType(zcu);
4544 log.debug("storing {}:{f} in {}:{f}", .{ src_mcv, src_ty.fmt(func.pt), ptr_mcv, ptr_ty.fmt(func.pt) });
4544 log.debug("storing {}:{f} in {}:{f}", .{ src_mcv, src_ty.fmt(zcu), ptr_mcv, ptr_ty.fmt(zcu) });
45454545
45464546 switch (ptr_mcv) {
45474547 .none => unreachable,
......@@ -7269,7 +7269,7 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
72697269 const bit_size = dst_ty.bitSize(zcu);
72707270 if (abi_size * 8 <= bit_size) break :result dst_mcv;
72717271
7272 return func.fail("TODO: airBitCast {f} to {f}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) });
7272 return func.fail("TODO: airBitCast {f} to {f}", .{ src_ty.fmt(zcu), dst_ty.fmt(zcu) });
72737273 };
72747274 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
72757275}
......@@ -8085,7 +8085,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
80858085 );
80868086 break :result .{ .load_frame = .{ .index = frame_index } };
80878087 },
8088 else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(pt)}),
8088 else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(zcu)}),
80898089 }
80908090 };
80918091
......@@ -8279,7 +8279,7 @@ fn resolveCallingConventionValues(
82798279 };
82808280
82818281 result.return_value = switch (ret_tracking_i) {
8282 else => return func.fail("ty {f} took {} tracking return indices", .{ ret_ty.fmt(pt), ret_tracking_i }),
8282 else => return func.fail("ty {f} took {} tracking return indices", .{ ret_ty.fmt(zcu), ret_tracking_i }),
82838283 1 => ret_tracking[0],
82848284 2 => InstTracking.init(.{ .register_pair = .{
82858285 ret_tracking[0].short.register, ret_tracking[1].short.register,
......@@ -8334,7 +8334,7 @@ fn resolveCallingConventionValues(
83348334 else => return func.fail("TODO: C calling convention arg class {}", .{class}),
83358335 } else {
83368336 arg.* = switch (arg_mcv_i) {
8337 else => return func.fail("ty {f} took {} tracking arg indices", .{ ty.fmt(pt), arg_mcv_i }),
8337 else => return func.fail("ty {f} took {} tracking arg indices", .{ ty.fmt(zcu), arg_mcv_i }),
83388338 1 => arg_mcv[0],
83398339 2 => .{ .register_pair = .{ arg_mcv[0].register, arg_mcv[1].register } },
83408340 };
src/codegen/sparc64/CodeGen.zig+3-3
......@@ -985,7 +985,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!void {
985985 switch (self.args[arg_index]) {
986986 .stack_offset => |off| {
987987 const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {
988 return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(pt)});
988 return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(zcu)});
989989 };
990990 const offset = off + abi_size;
991991 break :blk .{ .stack_offset = offset };
......@@ -2722,7 +2722,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27222722 }
27232723
27242724 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
2725 return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
2725 return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(zcu)});
27262726 };
27272727 // TODO swap this for inst.ty.ptrAlign
27282728 const abi_align = elem_ty.abiAlignment(zcu);
......@@ -2734,7 +2734,7 @@ fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
27342734 const zcu = pt.zcu;
27352735 const elem_ty = self.typeOfIndex(inst);
27362736 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
2737 return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
2737 return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(zcu)});
27382738 };
27392739 const abi_align = elem_ty.abiAlignment(zcu);
27402740 self.stack_align = self.stack_align.max(abi_align);
src/codegen/spirv/CodeGen.zig+157-121
......@@ -1297,8 +1297,8 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
12971297 const ip = &zcu.intern_pool;
12981298
12991299 log.debug("lowering constant: ty = {f}, val = {f}, key = {s}", .{
1300 ty.fmt(pt),
1301 val.fmtValue(pt),
1300 ty.fmt(zcu),
1301 val.fmtValue(zcu),
13021302 @tagName(ip.indexToKey(val.toIntern())),
13031303 });
13041304 assert(!ty.isPtrAtRuntime(zcu));
......@@ -1640,7 +1640,6 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
16401640}
16411641
16421642fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {
1643 const pt = cg.pt;
16441643 const zcu = cg.zcu;
16451644 const gpa = cg.gpa;
16461645
......@@ -1653,32 +1652,64 @@ fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {
16531652 var arena = std.heap.ArenaAllocator.init(gpa);
16541653 defer arena.deinit();
16551654
1656 const derivation = try ptr_val.pointerDerivation(arena.allocator(), pt, null);
1657 return cg.derivePtr(derivation);
1655 // TODO: `Value.pointerDerivation` ought to do this for us, but it doesn't receive
1656 // `pt`, so it actually *can't* until https://github.com/ziglang/zig/issues/24061 is
1657 // implemented.
1658 const non_packed_ptr_val: Value = non_packed_ptr: {
1659 const ptr_info = ptr_val.typeOf(zcu).ptrInfo(zcu);
1660 if (ptr_info.packed_offset.host_size == 0) {
1661 break :non_packed_ptr ptr_val;
1662 }
1663 const backing_ty: Type = switch (ptr_info.flags.vector_index) {
1664 _ => try cg.pt.vectorType(.{
1665 .child = ptr_info.child,
1666 .len = ptr_info.packed_offset.host_size,
1667 }),
1668 .none => try cg.pt.intType(
1669 .unsigned,
1670 @intCast(ptr_info.packed_offset.host_size * 8),
1671 ),
1672 };
1673 const new_ptr_ty = try cg.pt.ptrType(info: {
1674 var info = ptr_info;
1675 info.child = backing_ty.toIntern();
1676 info.packed_offset = .{ .host_size = 0, .bit_offset = 0 };
1677 info.flags.vector_index = .none;
1678 break :info info;
1679 });
1680 break :non_packed_ptr try cg.pt.getCoerced(ptr_val, new_ptr_ty);
1681 };
1682
1683 const derivation = try non_packed_ptr_val.pointerDerivation(arena.allocator(), zcu, null);
1684 return cg.derivePtr(ptr_val.typeOf(zcu).ptrAddressSpace(zcu), derivation);
16581685}
16591686
1660fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1687fn derivePtr(cg: *CodeGen, @"addrspace": std.lang.AddressSpace, derivation: Value.PointerDerivation) !Id {
16611688 const gpa = cg.gpa;
1662 const pt = cg.pt;
16631689 const zcu = cg.zcu;
16641690 const target = zcu.getTarget();
1665 switch (derivation) {
1666 .comptime_alloc_ptr, .comptime_field_ptr => unreachable,
1691
1692 const result_ty_id = try cg.ptrType(
1693 try cg.pointeeType(@"addrspace", derivation.elem_ty, false),
1694 cg.storageClass(@"addrspace"),
1695 );
1696
1697 switch (derivation.addr) {
1698 .comptime_alloc, .comptime_field => unreachable,
16671699 .int => |int| {
16681700 if (target.os.tag != .opencl) {
1669 if (int.ptr_ty.ptrAddressSpace(zcu) != .physical_storage_buffer) {
1701 if (@"addrspace" != .physical_storage_buffer) {
16701702 return cg.fail(
16711703 "cannot cast integer to pointer with address space '{s}'",
1672 .{@tagName(int.ptr_ty.ptrAddressSpace(zcu))},
1704 .{@tagName(@"addrspace")},
16731705 );
16741706 }
16751707 }
1676 const result_ty_id = try cg.resolveType(int.ptr_ty, .direct);
16771708 // TODO: This can probably be an OpSpecConstantOp Bitcast, but
16781709 // that is not implemented by Mesa yet. Therefore, just generate it
16791710 // as a runtime operation.
16801711 const result_ptr_id = cg.allocId();
1681 const value_id = try cg.constInt(.usize, int.addr);
1712 const value_id = try cg.constInt(.usize, int);
16821713 try cg.body.emit(gpa, .OpConvertUToPtr, .{
16831714 .id_result_type = result_ty_id,
16841715 .id_result = result_ptr_id,
......@@ -1686,10 +1717,8 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
16861717 });
16871718 return result_ptr_id;
16881719 },
1689 .nav_ptr => |nav_index| {
1720 .nav => |nav_index| {
16901721 const ip = &zcu.intern_pool;
1691 const result_ptr_ty = try pt.navPtrType(nav_index);
1692 const ty_id = try cg.resolveType(result_ptr_ty, .direct);
16931722 const nav = ip.getNav(nav_index);
16941723 const nav_ty: Type = .fromInterned(nav.resolved.?.type);
16951724
......@@ -1698,10 +1727,10 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
16981727
16991728 if (ip.isFunctionType(nav_ty.toIntern())) {
17001729 if (is_extern) return try cg.resolveExternFn(nav_index);
1701 return try cg.constUndef(ty_id);
1730 return try cg.constUndef(result_ty_id);
17021731 }
17031732 if (!nav_ty.hasRuntimeBits(zcu) and nav_ty.zigTypeTag(zcu) != .spirv) {
1704 return cg.constUndef(ty_id);
1733 return cg.constUndef(result_ty_id);
17051734 }
17061735 if (!is_extern) {
17071736 return cg.todo("pointer to constant '{f}'", .{nav.fqn.fmt(ip)});
......@@ -1718,7 +1747,7 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
17181747 try cg.block_var_ids.put(gpa, var_id, {});
17191748 }
17201749
1721 if (decl_ptr_ty_id == ty_id) return var_id;
1750 if (decl_ptr_ty_id == result_ty_id) return var_id;
17221751 switch (target.os.tag) {
17231752 .vulkan, .opengl => return var_id,
17241753 else => {},
......@@ -1726,63 +1755,63 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
17261755
17271756 const casted_ptr_id = cg.allocId();
17281757 try cg.body.emit(gpa, .OpBitcast, .{
1729 .id_result_type = ty_id,
1758 .id_result_type = result_ty_id,
17301759 .id_result = casted_ptr_id,
17311760 .operand = var_id,
17321761 });
17331762 return casted_ptr_id;
17341763 },
1735 .uav_ptr => |uav| {
1764 .uav => |uav_val| {
17361765 const ip = &zcu.intern_pool;
1737 const result_ptr_ty: Type = .fromInterned(uav.orig_ty);
1738 const ty_id = try cg.resolveType(result_ptr_ty, .direct);
1739 const uav_ty: Type = .fromInterned(ip.typeOf(uav.val));
1766 const uav_ty = uav_val.typeOf(zcu);
17401767
1741 switch (ip.indexToKey(uav.val)) {
1768 switch (ip.indexToKey(uav_val.toIntern())) {
17421769 .func => unreachable, // TODO
17431770 .@"extern" => assert(!ip.isFunctionType(uav_ty.toIntern())),
17441771 else => {},
17451772 }
17461773
17471774 if (!uav_ty.hasRuntimeBits(zcu) and uav_ty.zigTypeTag(zcu) != .spirv) {
1748 return cg.constUndef(ty_id);
1775 return cg.constUndef(result_ty_id);
17491776 }
17501777
1751 if (cg.storageClass(result_ptr_ty.ptrAddressSpace(zcu)) != .function) {
1752 return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(pt)});
1778 if (cg.storageClass(@"addrspace") != .function) {
1779 return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(zcu)});
17531780 }
17541781
17551782 const uav_ty_id = try cg.resolveType(uav_ty, .indirect);
17561783 const ptr_id = try cg.alloc(uav_ty_id, null);
1757 const val_id = try cg.constant(uav_ty, .fromInterned(uav.val), .indirect);
1784 const val_id = try cg.constant(uav_ty, uav_val, .indirect);
17581785 try cg.body.emit(gpa, .OpStore, .{ .pointer = ptr_id, .object = val_id });
17591786 return ptr_id;
17601787 },
1761 .eu_payload_ptr => @panic("TODO"),
1762 .opt_payload_ptr => @panic("TODO"),
1763 .field_ptr => |field| {
1764 const parent_ptr_id = try cg.derivePtr(field.parent.*);
1765 const parent_ptr_ty = try field.parent.ptrType(pt);
1766 return cg.structFieldPtr(field.result_ptr_ty, parent_ptr_ty, parent_ptr_id, field.field_idx);
1767 },
1768 .elem_ptr => |elem| {
1769 const parent_ptr_id = try cg.derivePtr(elem.parent.*);
1770 const parent_ptr_ty = try elem.parent.ptrType(pt);
1771 const index_id = try cg.constInt(.usize, elem.elem_idx);
1772 return cg.ptrElemPtr(parent_ptr_ty, parent_ptr_id, index_id);
1773 },
1774 .offset_and_cast => |oac| {
1775 const parent_ptr_id = try cg.derivePtr(oac.parent.*);
1776 const parent_ptr_ty = try oac.parent.ptrType(pt);
1777
1778 if (oac.new_ptr_ty.ptrInfo(zcu).flags.vector_index != .none) {
1779 return parent_ptr_id;
1780 }
1788 .eu_payload => @panic("TODO"),
1789 .opt_payload => @panic("TODO"),
1790 .field => |derived| return cg.structFieldPtr(
1791 @"addrspace",
1792 result_ty_id,
1793 derivation.elem_ty,
1794 derived.parent.elem_ty,
1795 try cg.derivePtr(@"addrspace", derived.parent.*),
1796 derived.field_index,
1797 ),
1798 .elem => |derived| return cg.ptrElemPtr(
1799 switch (derived.parent.size) {
1800 .one => .single_array_ptr,
1801 .many => .many_ptr,
1802 },
1803 @"addrspace",
1804 derived.parent.elem_ty,
1805 try cg.derivePtr(@"addrspace", derived.parent.*),
1806 try cg.constInt(.usize, derived.elem_index),
1807 ),
1808 .offset_and_cast => |derived| {
1809 const parent_ptr_id = try cg.derivePtr(@"addrspace", derived.parent.*);
17811810
1782 if (oac.byte_offset == 0) {
1811 if (derived.byte_offset == 0) {
17831812 var depth: u32 = 0;
1784 var cur = parent_ptr_ty.childType(zcu);
1785 const dst_child = oac.new_ptr_ty.childType(zcu);
1813 var cur = derived.parent.elem_ty;
1814 const dst_child = derivation.elem_ty;
17861815 while (cur.toIntern() != dst_child.toIntern()) {
17871816 switch (cur.zigTypeTag(zcu)) {
17881817 .array => {
......@@ -1807,9 +1836,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
18071836 }
18081837 if (cur.toIntern() == dst_child.toIntern()) {
18091838 if (depth != 0) {
1810 const as = oac.new_ptr_ty.ptrAddressSpace(zcu);
1811 const child_ty_id = try cg.pointeeType(as, dst_child, false);
1812 const result_ty_id = try cg.ptrType(child_ty_id, cg.storageClass(as));
18131839 const scratch_top = cg.id_scratch.items.len;
18141840 defer cg.id_scratch.shrinkRetainingCapacity(scratch_top);
18151841 const zero = try cg.constInt(.u32, 0);
......@@ -1820,7 +1846,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
18201846 return parent_ptr_id;
18211847 }
18221848 }
1823 const result_ty_id = try cg.resolveType(oac.new_ptr_ty, .direct);
18241849 if (target.os.tag == .opencl) {
18251850 const result_ptr_id = cg.allocId();
18261851 try cg.body.emit(gpa, .OpBitcast, .{
......@@ -1832,9 +1857,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
18321857 }
18331858 }
18341859
1835 return cg.fail("cannot cast pointer '{f}' to '{f}'", .{
1836 parent_ptr_ty.fmt(pt),
1837 oac.new_ptr_ty.fmt(pt),
1860 return cg.fail("cannot cast pointer '*{f}' to '*{f}'", .{
1861 derived.parent.elem_ty.fmt(zcu),
1862 derivation.elem_ty.fmt(zcu),
18381863 });
18391864 },
18401865 }
......@@ -1881,7 +1906,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
18811906 const ip = &zcu.intern_pool;
18821907 const target = cg.zcu.getTarget();
18831908
1884 log.debug("resolveType: ty = {f}", .{ty.fmt(pt)});
1909 log.debug("resolveType: ty = {f}", .{ty.fmt(zcu)});
18851910
18861911 switch (ty.zigTypeTag(zcu)) {
18871912 .noreturn => {
......@@ -1919,7 +1944,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
19191944 };
19201945 if (!supported) return cg.fail(
19211946 "'{f}' is not supported on the current SPIR-V feature set",
1922 .{ty.fmt(cg.pt)},
1947 .{ty.fmt(zcu)},
19231948 );
19241949 return try cg.floatType(bits);
19251950 },
......@@ -2047,7 +2072,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
20472072 null,
20482073 .none,
20492074 );
2050 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});
2075 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
20512076 return result_id;
20522077 },
20532078 .struct_type => ip.loadStructType(ty.toIntern()),
......@@ -2080,7 +2105,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
20802105 ty.toIntern(),
20812106 );
20822107
2083 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});
2108 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
20842109
20852110 return result_id;
20862111 },
......@@ -2134,7 +2159,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
21342159 }
21352160
21362161 const result_id = try cg.structType(member_types[0..len], null, .none);
2137 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});
2162 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
21382163 return result_id;
21392164 },
21402165 }
......@@ -2169,7 +2194,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
21692194 member_names[0..layout.total_fields],
21702195 .none,
21712196 );
2172 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});
2197 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
21732198 return result_id;
21742199 },
21752200 .error_set => {
......@@ -2206,7 +2231,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
22062231 },
22072232 .@"opaque" => {
22082233 if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{});
2209 return try cg.opaqueType("{f}", .{ty.fmt(cg.pt)});
2234 return try cg.opaqueType("{f}", .{ty.fmt(zcu)});
22102235 },
22112236 .spirv => {
22122237 const spirv_type = ip.loadSpirvType(ty.toIntern());
......@@ -6455,21 +6480,28 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
64556480 return try cg.load(slice_ty.childType(zcu), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(zcu) });
64566481}
64576482
6458fn ptrElemPtr(cg: *CodeGen, ptr_ty: Type, ptr_id: Id, index_id: Id) !Id {
6459 const zcu = cg.zcu;
6483fn ptrElemPtr(
6484 cg: *CodeGen,
6485 mode: enum { single_array_ptr, many_ptr },
6486 @"addrspace": std.lang.AddressSpace,
6487 elem_ty: Type,
6488 ptr_id: Id,
6489 index_id: Id,
6490) !Id {
64606491 // Construct new pointer type for the resulting pointer
6461 const as = ptr_ty.ptrAddressSpace(zcu);
6462 const is_single_ptr = ptr_ty.isSinglePointer(zcu);
64636492 const elem_is_block = cg.block_var_ids.contains(ptr_id);
6464 const elem_ty_id = try cg.pointeeType(as, ptr_ty.indexableElem(zcu), elem_is_block);
6465 const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(as));
6466 if (is_single_ptr) {
6467 // Pointer-to-array. In this case, the resulting pointer is not of the same type
6468 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
6469 return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});
6470 } else {
6471 // Resulting pointer type is the same as the ptr_ty, so use ptrAccessChain
6472 return cg.ptrAccessChain(elem_ptr_ty_id, ptr_id, index_id, &.{});
6493 const elem_ty_id = try cg.pointeeType(@"addrspace", elem_ty, elem_is_block);
6494 const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(@"addrspace"));
6495 switch (mode) {
6496 .single_array_ptr => {
6497 // Pointer-to-array. In this case, the resulting pointer is not of the same type
6498 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
6499 return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});
6500 },
6501 .many_ptr => {
6502 // Resulting pointer type is the same as the ptr_ty, so use ptrAccessChain
6503 return cg.ptrAccessChain(elem_ptr_ty_id, ptr_id, index_id, &.{});
6504 },
64736505 }
64746506}
64756507
......@@ -6483,13 +6515,19 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
64836515 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
64846516 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;
64856517 const src_ptr_ty = cg.typeOf(bin_op.lhs);
6486 const elem_ty = src_ptr_ty.childType(zcu);
6518 const elem_ty = src_ptr_ty.indexableElem(zcu);
64876519 const ptr_id = try cg.resolve(bin_op.lhs);
64886520
64896521 assert(elem_ty.hasRuntimeBits(zcu));
64906522
64916523 const index_id = try cg.resolve(bin_op.rhs);
6492 return try cg.ptrElemPtr(src_ptr_ty, ptr_id, index_id);
6524 return try cg.ptrElemPtr(
6525 if (src_ptr_ty.isSinglePointer(zcu)) .single_array_ptr else .many_ptr,
6526 src_ptr_ty.ptrAddressSpace(zcu),
6527 elem_ty,
6528 ptr_id,
6529 index_id,
6530 );
64936531}
64946532
64956533fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
......@@ -6551,7 +6589,13 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
65516589 const elem_ty = cg.typeOfIndex(inst);
65526590 const ptr_id = try cg.resolve(bin_op.lhs);
65536591 const index_id = try cg.resolve(bin_op.rhs);
6554 const elem_ptr_id = try cg.ptrElemPtr(ptr_ty, ptr_id, index_id);
6592 const elem_ptr_id = try cg.ptrElemPtr(
6593 if (ptr_ty.isSinglePointer(zcu)) .single_array_ptr else .many_ptr,
6594 ptr_ty.ptrAddressSpace(zcu),
6595 elem_ty,
6596 ptr_id,
6597 index_id,
6598 );
65556599 return try cg.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
65566600}
65576601
......@@ -6845,66 +6889,44 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
68456889
68466890fn structFieldPtr(
68476891 cg: *CodeGen,
6848 result_ptr_ty: Type,
6849 object_ptr_ty: Type,
6892 @"addrspace": std.lang.AddressSpace,
6893 result_ptr_ty_id: Id,
6894 field_ty: Type,
6895 object_ty: Type,
68506896 object_ptr: Id,
68516897 field_index: u32,
68526898) !Id {
6853 const result_ty_id = try cg.resolveType(result_ptr_ty, .direct);
6854
68556899 const zcu = cg.zcu;
6856 const object_ty = object_ptr_ty.childType(zcu);
68576900 switch (object_ty.zigTypeTag(zcu)) {
68586901 .pointer => {
68596902 assert(object_ty.isSlice(zcu));
6860 return cg.accessChain(result_ty_id, object_ptr, &.{field_index});
6903 return cg.accessChain(result_ptr_ty_id, object_ptr, &.{field_index});
68616904 },
68626905 .@"struct" => switch (object_ty.containerLayout(zcu)) {
6863 .@"packed" => {
6864 const byte_offset = codegen.fieldOffset(object_ptr_ty, result_ptr_ty, field_index, zcu);
6865 if (byte_offset == 0) return object_ptr;
6866 const usize_ty_id = try cg.resolveType(.usize, .direct);
6867 const base_int = cg.allocId();
6868 try cg.body.emit(cg.gpa, .OpConvertPtrToU, .{
6869 .id_result_type = usize_ty_id,
6870 .id_result = base_int,
6871 .pointer = object_ptr,
6872 });
6873 const offset_id = try cg.constInt(.usize, byte_offset);
6874 const adjusted = try cg.buildBinary(.OpIAdd, .{ .ty = .usize, .value = .{ .singleton = base_int } }, .{ .ty = .usize, .value = .{ .singleton = offset_id } });
6875 const adjusted_id = try adjusted.materialize(cg);
6876 const result_id = cg.allocId();
6877 try cg.body.emit(cg.gpa, .OpConvertUToPtr, .{
6878 .id_result_type = result_ty_id,
6879 .id_result = result_id,
6880 .integer_value = adjusted_id,
6881 });
6882 return result_id;
6883 },
6906 .@"packed" => unreachable,
68846907 .auto, .@"extern" => {
68856908 const member_index = cg.memberIndex(object_ty, field_index);
6886 return try cg.accessChain(result_ty_id, object_ptr, &.{member_index});
6909 return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{member_index});
68876910 },
68886911 },
68896912 .@"union" => switch (object_ty.containerLayout(zcu)) {
6890 .@"packed" => return cg.todo("implement field access for packed unions", .{}),
6913 .@"packed" => unreachable,
68916914 .auto => {
6892 if (!result_ptr_ty.childType(zcu).hasRuntimeBits(zcu)) return try cg.constUndef(result_ty_id);
6893 return try cg.accessChain(result_ty_id, object_ptr, &.{field_index});
6915 if (!field_ty.hasRuntimeBits(zcu)) return try cg.constUndef(result_ptr_ty_id);
6916 return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{field_index});
68946917 },
68956918 .@"extern" => {
68966919 const layout = cg.unionLayout(object_ty);
68976920 if (!layout.has_payload) {
68986921 // Asked to get a pointer to a zero-sized field. Just lower this
68996922 // to undefined, there is no reason to make it be a valid pointer.
6900 return try cg.constUndef(result_ty_id);
6923 return try cg.constUndef(result_ptr_ty_id);
69016924 }
69026925
6903 const storage_class = cg.storageClass(object_ptr_ty.ptrAddressSpace(zcu));
6904 const field_ty = result_ptr_ty.childType(zcu);
6926 const storage_class = cg.storageClass(@"addrspace");
69056927 if (field_ty.toIntern() == layout.payload_ty.toIntern()) {
69066928 if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr;
6907 return try cg.accessChain(result_ty_id, object_ptr, &.{layout.payload_index});
6929 return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{layout.payload_index});
69086930 }
69096931
69106932 switch (zcu.getTarget().os.tag) {
......@@ -6913,7 +6935,7 @@ fn structFieldPtr(
69136935 // type is structurally identical to the payload type (dedup will
69146936 // unify them) the access chain typed as the field type is valid.
69156937 if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr;
6916 return try cg.accessChain(result_ty_id, object_ptr, &.{layout.payload_index});
6938 return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{layout.payload_index});
69176939 },
69186940 else => {},
69196941 }
......@@ -6927,7 +6949,7 @@ fn structFieldPtr(
69276949
69286950 const active_pl_ptr_id = cg.allocId();
69296951 try cg.body.emit(cg.gpa, .OpBitcast, .{
6930 .id_result_type = result_ty_id,
6952 .id_result_type = result_ptr_ty_id,
69316953 .id_result = active_pl_ptr_id,
69326954 .operand = pl_ptr_id,
69336955 });
......@@ -6971,7 +6993,14 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
69716993 const struct_ptr = try cg.resolve(struct_field.struct_operand);
69726994 const struct_ptr_ty = cg.typeOf(struct_field.struct_operand);
69736995 const result_ptr_ty = cg.typeOfIndex(inst);
6974 return try cg.structFieldPtr(result_ptr_ty, struct_ptr_ty, struct_ptr, struct_field.field_index);
6996 return try cg.structFieldPtr(
6997 struct_ptr_ty.ptrAddressSpace(cg.zcu),
6998 try cg.resolveType(result_ptr_ty, .direct),
6999 result_ptr_ty.childType(cg.zcu),
7000 struct_ptr_ty.childType(cg.zcu),
7001 struct_ptr,
7002 struct_field.field_index,
7003 );
69757004}
69767005
69777006fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, field_index: u32) !?Id {
......@@ -6979,7 +7008,14 @@ fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, field_index: u32)
69797008 const struct_ptr = try cg.resolve(ty_op.operand);
69807009 const struct_ptr_ty = cg.typeOf(ty_op.operand);
69817010 const result_ptr_ty = cg.typeOfIndex(inst);
6982 return try cg.structFieldPtr(result_ptr_ty, struct_ptr_ty, struct_ptr, field_index);
7011 return try cg.structFieldPtr(
7012 struct_ptr_ty.ptrAddressSpace(cg.zcu),
7013 try cg.resolveType(result_ptr_ty, .direct),
7014 result_ptr_ty.childType(cg.zcu),
7015 struct_ptr_ty.childType(cg.zcu),
7016 struct_ptr,
7017 field_index,
7018 );
69837019}
69847020
69857021fn alloc(cg: *CodeGen, ty_id: Id, initializer: ?Id) !Id {
src/codegen/wasm/CodeGen.zig+9-9
......@@ -1154,7 +1154,7 @@ fn allocStack(cg: *CodeGen, ty: Type) !WValue {
11541154
11551155 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
11561156 return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{
1157 ty.fmt(pt), ty.abiSize(zcu),
1157 ty.fmt(zcu), ty.abiSize(zcu),
11581158 });
11591159 };
11601160 const abi_align = ty.abiAlignment(zcu);
......@@ -1195,7 +1195,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {
11951195 const abi_alignment = ptr_ty.ptrAlignment(zcu);
11961196 const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse {
11971197 return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{
1198 pointee_ty.fmt(pt), pointee_ty.abiSize(zcu),
1198 pointee_ty.fmt(zcu), pointee_ty.abiSize(zcu),
11991199 });
12001200 };
12011201 cg.stack_alignment = cg.stack_alignment.max(abi_alignment);
......@@ -2108,7 +2108,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)
21082108 if (!arg_ty.hasRuntimeBits(zcu)) continue;
21092109
21102110 const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse {
2111 return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(pt)});
2111 return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(zcu)});
21122112 };
21132113 const arg_align = arg_ty.abiAlignment(zcu);
21142114
......@@ -2128,7 +2128,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)
21282128
21292129 const arg_val = try cg.resolveInst(arg);
21302130 const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse {
2131 return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(pt)});
2131 return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(zcu)});
21322132 };
21332133 const arg_align = arg_ty.abiAlignment(zcu);
21342134
......@@ -5189,7 +5189,7 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
51895189 return .{ .imm32 = @intFromBool(!val.isNull(zcu)) };
51905190 },
51915191 .aggregate => switch (ip.indexToKey(ty.ip_index)) {
5192 .array_type => return cg.fail("Wasm TODO: LowerConstant for {f}", .{ty.fmt(pt)}),
5192 .array_type => return cg.fail("Wasm TODO: LowerConstant for {f}", .{ty.fmt(zcu)}),
51935193 .vector_type => {
51945194 assert(determineSimdStoreStrategy(ty, zcu, cg.target) == .direct);
51955195 var buf: [16]u8 = undefined;
......@@ -5883,7 +5883,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58835883 .@"packed" => unreachable, // legalize .expand_packed_agg_field_val
58845884 else => result: {
58855885 const offset = std.math.cast(u32, struct_ty.structFieldOffset(field_index, zcu)) orelse {
5886 return cg.fail("Field type '{f}' too big to fit into stack frame", .{field_ty.fmt(pt)});
5886 return cg.fail("Field type '{f}' too big to fit into stack frame", .{field_ty.fmt(zcu)});
58875887 };
58885888 if (isByRef(field_ty, zcu, cg.target)) {
58895889 break :result try cg.offsetPointer(operand, offset);
......@@ -6296,7 +6296,7 @@ fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, o
62966296 // a pointer to the stack value
62976297 if (payload_ty.hasRuntimeBits(zcu)) {
62986298 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
6299 return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(pt)});
6299 return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(zcu)});
63006300 };
63016301 try cg.emitMemBase(operand);
63026302 try cg.addMemArg(.i32_load8_u, .{ .offset = operand.memOffset() + offset, .alignment = .@"1" });
......@@ -6381,7 +6381,7 @@ fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
63816381 }
63826382
63836383 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
6384 return cg.fail("Optional type {f} too big to fit into stack frame", .{opt_ty.fmt(pt)});
6384 return cg.fail("Optional type {f} too big to fit into stack frame", .{opt_ty.fmt(zcu)});
63856385 };
63866386
63876387 try cg.emitMemBase(operand);
......@@ -6412,7 +6412,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64126412 break :result operand;
64136413 }
64146414 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
6415 return cg.fail("Optional type {f} too big to fit into stack frame", .{op_ty.fmt(pt)});
6415 return cg.fail("Optional type {f} too big to fit into stack frame", .{op_ty.fmt(zcu)});
64166416 };
64176417
64186418 // Create optional type, set the non-null bit, and store the operand inside the optional type
src/codegen/x86_64/CodeGen.zig+133-128
......@@ -1174,7 +1174,7 @@ const FormatAirData = struct {
11741174 inst: Air.Inst.Index,
11751175};
11761176fn formatAir(data: FormatAirData, w: *Writer) Writer.Error!void {
1177 data.self.air.writeInst(w, data.inst, data.self.pt, data.self.liveness);
1177 data.self.air.writeInst(w, data.inst, data.self.pt.zcu, data.self.liveness);
11781178}
11791179fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Alt(FormatAirData, formatAir) {
11801180 return .{ .data = .{ .self = self, .inst = inst } };
......@@ -1185,14 +1185,15 @@ const FormatWipMirData = struct {
11851185 inst: Mir.Inst.Index,
11861186};
11871187fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
1188 const zcu = data.self.pt.zcu;
11881189 var lower: Lower = .{
11891190 .target = data.self.target,
11901191 .allocator = data.self.gpa,
11911192 .mir = data.self.getTmpMir(),
11921193 .cc = .auto,
11931194 .src_loc = switch (data.self.owner) {
1194 .nav_index => |nav| data.self.pt.zcu.navSrcLoc(nav),
1195 .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(data.self.pt.zcu) orelse .unneeded,
1195 .nav_index => |nav| zcu.navSrcLoc(nav),
1196 .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(zcu) orelse .unneeded,
11961197 },
11971198 };
11981199 var first = true;
......@@ -1215,7 +1216,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
12151216 first = false;
12161217 }
12171218 if (first) {
1218 const ip = &data.self.pt.zcu.intern_pool;
1219 const ip = &zcu.intern_pool;
12191220 const mir_inst = lower.mir.instructions.get(data.inst);
12201221 try w.print(" | .{s}", .{@tagName(mir_inst.ops)});
12211222 switch (mir_inst.ops) {
......@@ -1264,7 +1265,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
12641265 try w.print(" {f}", .{mem_op.fmt(.m)});
12651266 },
12661267 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try w.print(" {f}", .{
1267 Value.fromInterned(mir_inst.data.ip_index).fmtValue(data.self.pt),
1268 Value.fromInterned(mir_inst.data.ip_index).fmtValue(zcu),
12681269 }),
12691270 }
12701271 }
......@@ -4532,7 +4533,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
45324533 } }) catch |err| switch (err) {
45334534 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
45344535 @tagName(air_tag),
4535 cg.typeOf(bin_op.lhs).fmt(pt),
4536 cg.typeOf(bin_op.lhs).fmt(zcu),
45364537 ops[0].tracking(cg),
45374538 ops[1].tracking(cg),
45384539 }),
......@@ -4544,7 +4545,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
45444545 .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
45454546 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
45464547 @tagName(air_tag),
4547 cg.typeOf(bin_op.lhs).fmt(pt),
4548 cg.typeOf(bin_op.lhs).fmt(zcu),
45484549 res[0].tracking(cg),
45494550 }),
45504551 else => |e| return e,
......@@ -13109,7 +13110,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1310913110 } }) catch |err| switch (err) {
1311013111 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
1311113112 @tagName(air_tag),
13112 cg.typeOf(bin_op.lhs).fmt(pt),
13113 cg.typeOf(bin_op.lhs).fmt(zcu),
1311313114 ops[0].tracking(cg),
1311413115 ops[1].tracking(cg),
1311513116 }),
......@@ -15283,7 +15284,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1528315284 } }) catch |err| switch (err) {
1528415285 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
1528515286 @tagName(air_tag),
15286 cg.typeOf(bin_op.lhs).fmt(pt),
15287 cg.typeOf(bin_op.lhs).fmt(zcu),
1528715288 ops[0].tracking(cg),
1528815289 ops[1].tracking(cg),
1528915290 }),
......@@ -15295,7 +15296,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
1529515296 .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
1529615297 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
1529715298 @tagName(air_tag),
15298 cg.typeOf(bin_op.lhs).fmt(pt),
15299 cg.typeOf(bin_op.lhs).fmt(zcu),
1529915300 res[0].tracking(cg),
1530015301 }),
1530115302 else => |e| return e,
......@@ -22130,7 +22131,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2213022131 } }) catch |err| switch (err) {
2213122132 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
2213222133 @tagName(air_tag),
22133 cg.typeOf(bin_op.lhs).fmt(pt),
22134 cg.typeOf(bin_op.lhs).fmt(zcu),
2213422135 ops[0].tracking(cg),
2213522136 ops[1].tracking(cg),
2213622137 }),
......@@ -25067,7 +25068,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2506725068 } }) catch |err| switch (err) {
2506825069 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
2506925070 @tagName(air_tag),
25070 ty.fmt(pt),
25071 ty.fmt(zcu),
2507125072 ops[0].tracking(cg),
2507225073 ops[1].tracking(cg),
2507325074 }),
......@@ -26865,7 +26866,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2686526866 } }) catch |err| switch (err) {
2686626867 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
2686726868 @tagName(air_tag),
26868 ty.fmt(pt),
26869 ty.fmt(zcu),
2686926870 ops[0].tracking(cg),
2687026871 ops[1].tracking(cg),
2687126872 }),
......@@ -26874,7 +26875,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2687426875 res[0].wrapInt(cg) catch |err| switch (err) {
2687526876 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
2687626877 @tagName(air_tag),
26877 cg.typeOf(bin_op.lhs).fmt(pt),
26878 cg.typeOf(bin_op.lhs).fmt(zcu),
2687826879 res[0].tracking(cg),
2687926880 }),
2688026881 else => |e| return e,
......@@ -32090,7 +32091,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3209032091 } }) catch |err| switch (err) {
3209132092 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3209232093 @tagName(air_tag),
32093 cg.typeOf(bin_op.lhs).fmt(pt),
32094 cg.typeOf(bin_op.lhs).fmt(zcu),
3209432095 ops[0].tracking(cg),
3209532096 ops[1].tracking(cg),
3209632097 }),
......@@ -33328,7 +33329,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3332833329 }) catch |err| switch (err) {
3332933330 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3333033331 @tagName(air_tag),
33331 ty.fmt(pt),
33332 ty.fmt(zcu),
3333233333 ops[0].tracking(cg),
3333333334 ops[1].tracking(cg),
3333433335 }),
......@@ -34785,7 +34786,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3478534786 }) catch |err| switch (err) {
3478634787 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3478734788 @tagName(air_tag),
34788 ty.fmt(pt),
34789 ty.fmt(zcu),
3478934790 ops[0].tracking(cg),
3479034791 ops[1].tracking(cg),
3479134792 }),
......@@ -36346,7 +36347,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3634636347 }) catch |err| switch (err) {
3634736348 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3634836349 @tagName(air_tag),
36349 cg.typeOf(bin_op.lhs).fmt(pt),
36350 cg.typeOf(bin_op.lhs).fmt(zcu),
3635036351 ops[0].tracking(cg),
3635136352 ops[1].tracking(cg),
3635236353 }),
......@@ -38038,7 +38039,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3803838039 } })) catch |err| switch (err) {
3803938040 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3804038041 @tagName(air_tag),
38041 ty.fmt(pt),
38042 ty.fmt(zcu),
3804238043 ops[0].tracking(cg),
3804338044 ops[1].tracking(cg),
3804438045 }),
......@@ -39820,7 +39821,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
3982039821 } }) catch |err| switch (err) {
3982139822 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
3982239823 @tagName(air_tag),
39823 cg.typeOf(bin_op.lhs).fmt(pt),
39824 cg.typeOf(bin_op.lhs).fmt(zcu),
3982439825 ops[0].tracking(cg),
3982539826 ops[1].tracking(cg),
3982639827 }),
......@@ -43333,7 +43334,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4333343334 } }) catch |err| switch (err) {
4333443335 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4333543336 @tagName(air_tag),
43336 cg.typeOf(bin_op.lhs).fmt(pt),
43337 cg.typeOf(bin_op.lhs).fmt(zcu),
4333743338 ops[0].tracking(cg),
4333843339 ops[1].tracking(cg),
4333943340 }),
......@@ -43447,7 +43448,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4344743448 } }) catch |err| switch (err) {
4344843449 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4344943450 @tagName(air_tag),
43450 cg.typeOf(bin_op.lhs).fmt(pt),
43451 cg.typeOf(bin_op.lhs).fmt(zcu),
4345143452 ops[0].tracking(cg),
4345243453 ops[1].tracking(cg),
4345343454 }),
......@@ -43576,7 +43577,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4357643577 } }) catch |err| switch (err) {
4357743578 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4357843579 @tagName(air_tag),
43579 cg.typeOf(bin_op.lhs).fmt(pt),
43580 cg.typeOf(bin_op.lhs).fmt(zcu),
4358043581 ops[0].tracking(cg),
4358143582 ops[1].tracking(cg),
4358243583 }),
......@@ -47885,7 +47886,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4788547886 } }) catch |err| switch (err) {
4788647887 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4788747888 @tagName(air_tag),
47888 cg.typeOf(bin_op.lhs).fmt(pt),
47889 cg.typeOf(bin_op.lhs).fmt(zcu),
4788947890 ops[0].tracking(cg),
4789047891 ops[1].tracking(cg),
4789147892 }),
......@@ -52188,7 +52189,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5218852189 } }) catch |err| switch (err) {
5218952190 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5219052191 @tagName(air_tag),
52191 cg.typeOf(bin_op.lhs).fmt(pt),
52192 cg.typeOf(bin_op.lhs).fmt(zcu),
5219252193 ops[0].tracking(cg),
5219352194 ops[1].tracking(cg),
5219452195 }),
......@@ -53037,7 +53038,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5303753038 } }) catch |err| switch (err) {
5303853039 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5303953040 @tagName(air_tag),
53040 ty_pl.ty.fmt(pt),
53041 ty_pl.ty.fmt(zcu),
5304153042 ops[0].tracking(cg),
5304253043 ops[1].tracking(cg),
5304353044 }),
......@@ -53942,7 +53943,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5394253943 } }) catch |err| switch (err) {
5394353944 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5394453945 @tagName(air_tag),
53945 ty_pl.ty.fmt(pt),
53946 ty_pl.ty.fmt(zcu),
5394653947 ops[0].tracking(cg),
5394753948 ops[1].tracking(cg),
5394853949 }),
......@@ -57539,7 +57540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
5753957540 } }) catch |err| switch (err) {
5754057541 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
5754157542 @tagName(air_tag),
57542 ty_pl.ty.fmt(pt),
57543 ty_pl.ty.fmt(zcu),
5754357544 ops[0].tracking(cg),
5754457545 ops[1].tracking(cg),
5754557546 }),
......@@ -60884,7 +60885,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6088460885 } }) catch |err| switch (err) {
6088560886 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
6088660887 @tagName(air_tag),
60887 ty_pl.ty.fmt(pt),
60888 ty_pl.ty.fmt(zcu),
6088860889 ops[0].tracking(cg),
6088960890 ops[1].tracking(cg),
6089060891 }),
......@@ -61279,7 +61280,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6127961280 }) catch |err| switch (err) {
6128061281 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
6128161282 @tagName(air_tag),
61282 cg.typeOf(bin_op.lhs).fmt(pt),
61283 cg.typeOf(bin_op.lhs).fmt(zcu),
6128361284 ops[0].tracking(cg),
6128461285 ops[1].tracking(cg),
6128561286 }),
......@@ -61842,8 +61843,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6184261843 } }) catch |err| switch (err) {
6184361844 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
6184461845 @tagName(air_tag),
61845 cg.typeOf(bin_op.lhs).fmt(pt),
61846 cg.typeOf(bin_op.rhs).fmt(pt),
61846 cg.typeOf(bin_op.lhs).fmt(zcu),
61847 cg.typeOf(bin_op.rhs).fmt(zcu),
6184761848 ops[0].tracking(cg),
6184861849 ops[1].tracking(cg),
6184961850 }),
......@@ -62204,8 +62205,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6220462205 } }) catch |err| switch (err) {
6220562206 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
6220662207 @tagName(air_tag),
62207 cg.typeOf(bin_op.lhs).fmt(pt),
62208 cg.typeOf(bin_op.rhs).fmt(pt),
62208 cg.typeOf(bin_op.lhs).fmt(zcu),
62209 cg.typeOf(bin_op.rhs).fmt(zcu),
6220962210 ops[0].tracking(cg),
6221062211 ops[1].tracking(cg),
6221162212 }),
......@@ -62216,7 +62217,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6221662217 .shl => res[0].wrapInt(cg) catch |err| switch (err) {
6221762218 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
6221862219 @tagName(air_tag),
62219 cg.typeOf(bin_op.lhs).fmt(pt),
62220 cg.typeOf(bin_op.lhs).fmt(zcu),
6222062221 res[0].tracking(cg),
6222162222 }),
6222262223 else => |e| return e,
......@@ -62383,7 +62384,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6238362384 } }) catch |err| switch (err) {
6238462385 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6238562386 @tagName(air_tag),
62386 cg.typeOf(bin_op.rhs).fmt(pt),
62387 cg.typeOf(bin_op.rhs).fmt(zcu),
6238762388 ops[1].tracking(cg),
6238862389 }),
6238962390 else => |e| return e,
......@@ -65640,7 +65641,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6564065641 } }) catch |err| switch (err) {
6564165642 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
6564265643 @tagName(air_tag),
65643 lhs_ty.fmt(pt),
65644 lhs_ty.fmt(zcu),
6564465645 ops[0].tracking(cg),
6564565646 ops[1].tracking(cg),
6564665647 }),
......@@ -67425,7 +67426,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
6742567426 } }) catch |err| switch (err) {
6742667427 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
6742767428 @tagName(air_tag),
67428 ty_op.ty.fmt(pt),
67429 ty_op.ty.fmt(zcu),
6742967430 ops[0].tracking(cg),
6743067431 }),
6743167432 else => |e| return e,
......@@ -70586,7 +70587,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7058670587 } }) catch |err| switch (err) {
7058770588 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7058870589 @tagName(air_tag),
70589 cg.typeOf(ty_op.operand).fmt(pt),
70590 cg.typeOf(ty_op.operand).fmt(zcu),
7059070591 ops[0].tracking(cg),
7059170592 }),
7059270593 else => |e| return e,
......@@ -70983,7 +70984,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7098370984 } }) catch |err| switch (err) {
7098470985 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7098570986 @tagName(air_tag),
70986 cg.typeOf(ty_op.operand).fmt(pt),
70987 cg.typeOf(ty_op.operand).fmt(zcu),
7098770988 ops[0].tracking(cg),
7098870989 }),
7098970990 else => |e| return e,
......@@ -71871,7 +71872,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7187171872 } }) catch |err| switch (err) {
7187271873 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7187371874 @tagName(air_tag),
71874 cg.typeOf(ty_op.operand).fmt(pt),
71875 cg.typeOf(ty_op.operand).fmt(zcu),
7187571876 ops[0].tracking(cg),
7187671877 }),
7187771878 else => |e| return e,
......@@ -72520,7 +72521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7252072521 } }) catch |err| switch (err) {
7252172522 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7252272523 @tagName(air_tag),
72523 ty_op.ty.fmt(pt),
72524 ty_op.ty.fmt(zcu),
7252472525 ops[0].tracking(cg),
7252572526 }),
7252672527 else => |e| return e,
......@@ -75622,7 +75623,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7562275623 } }) catch |err| switch (err) {
7562375624 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7562475625 @tagName(air_tag),
75625 ty_op.ty.fmt(pt),
75626 ty_op.ty.fmt(zcu),
7562675627 ops[0].tracking(cg),
7562775628 }),
7562875629 else => |e| return e,
......@@ -76684,7 +76685,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7668476685 } }) catch |err| switch (err) {
7668576686 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7668676687 @tagName(air_tag),
76687 cg.typeOf(un_op).fmt(pt),
76688 cg.typeOf(un_op).fmt(zcu),
7668876689 ops[0].tracking(cg),
7668976690 }),
7669076691 else => |e| return e,
......@@ -77534,7 +77535,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7753477535 }) catch |err| switch (err) {
7753577536 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7753677537 @tagName(air_tag),
77537 cg.typeOf(un_op).fmt(pt),
77538 cg.typeOf(un_op).fmt(zcu),
7753877539 ops[0].tracking(cg),
7753977540 }),
7754077541 else => |e| return e,
......@@ -79085,7 +79086,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
7908579086 } }) catch |err| switch (err) {
7908679087 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
7908779088 @tagName(air_tag),
79088 cg.typeOf(ty_op.operand).fmt(pt),
79089 cg.typeOf(ty_op.operand).fmt(zcu),
7908979090 ops[0].tracking(cg),
7909079091 }),
7909179092 else => |e| return e,
......@@ -80421,7 +80422,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8042180422 }) catch |err| switch (err) {
8042280423 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
8042380424 @tagName(air_tag),
80424 cg.typeOf(un_op).fmt(pt),
80425 cg.typeOf(un_op).fmt(zcu),
8042580426 ops[0].tracking(cg),
8042680427 }),
8042780428 else => |e| return e,
......@@ -80961,7 +80962,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8096180962 } }) catch |err| switch (err) {
8096280963 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
8096380964 @tagName(air_tag),
80964 cg.typeOf(un_op).fmt(pt),
80965 cg.typeOf(un_op).fmt(zcu),
8096580966 ops[0].tracking(cg),
8096680967 }),
8096780968 else => |e| return e,
......@@ -81441,7 +81442,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8144181442 }) catch |err| switch (err) {
8144281443 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
8144381444 @tagName(air_tag),
81444 cg.typeOf(bin_op.lhs).fmt(pt),
81445 cg.typeOf(bin_op.lhs).fmt(zcu),
8144581446 ops[0].tracking(cg),
8144681447 ops[1].tracking(cg),
8144781448 }),
......@@ -82016,7 +82017,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8201682017 for (&ops) |*op| op.wrapInt(cg) catch |err| switch (err) {
8201782018 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
8201882019 @tagName(air_tag),
82019 ty.fmt(pt),
82020 ty.fmt(zcu),
8202082021 op.tracking(cg),
8202182022 }),
8202282023 else => |e| return e,
......@@ -82028,7 +82029,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8202882029 }) catch |err| switch (err) {
8202982030 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
8203082031 @tagName(air_tag),
82031 ty.fmt(pt),
82032 ty.fmt(zcu),
8203282033 ops[0].tracking(cg),
8203382034 ops[1].tracking(cg),
8203482035 }),
......@@ -89107,7 +89108,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
8910789108 error.SelectFailed => return cg.fail("failed to select {s} {s} {f} {f} {f}", .{
8910889109 @tagName(air_tag),
8910989110 @tagName(vector_cmp.compareOperator()),
89110 cg.typeOf(vector_cmp.lhs).fmt(pt),
89111 cg.typeOf(vector_cmp.lhs).fmt(zcu),
8911189112 ops[0].tracking(cg),
8911289113 ops[1].tracking(cg),
8911389114 }),
......@@ -91699,8 +91700,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9169991700 } }) catch |err| switch (err) {
9170091701 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
9170191702 @tagName(air_tag),
91702 ty_op.ty.fmt(pt),
91703 cg.typeOf(ty_op.operand).fmt(pt),
91703 ty_op.ty.fmt(zcu),
91704 cg.typeOf(ty_op.operand).fmt(zcu),
9170491705 ops[0].tracking(cg),
9170591706 }),
9170691707 else => |e| return e,
......@@ -93374,8 +93375,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9337493375 } }) catch |err| switch (err) {
9337593376 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
9337693377 @tagName(air_tag),
93377 ty_op.ty.fmt(pt),
93378 cg.typeOf(ty_op.operand).fmt(pt),
93378 ty_op.ty.fmt(zcu),
93379 cg.typeOf(ty_op.operand).fmt(zcu),
9337993380 ops[0].tracking(cg),
9338093381 }),
9338193382 else => |e| return e,
......@@ -98132,8 +98133,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
9813298133 } }) catch |err| switch (err) {
9813398134 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
9813498135 @tagName(air_tag),
98135 dst_ty.fmt(pt),
98136 src_ty.fmt(pt),
98136 dst_ty.fmt(zcu),
98137 src_ty.fmt(zcu),
9813798138 ops[0].tracking(cg),
9813898139 }),
9813998140 else => |e| return e,
......@@ -103798,8 +103799,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
103798103799 } }) catch |err| switch (err) {
103799103800 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
103800103801 @tagName(air_tag),
103801 ty_op.ty.fmt(pt),
103802 cg.typeOf(ty_op.operand).fmt(pt),
103802 ty_op.ty.fmt(zcu),
103803 cg.typeOf(ty_op.operand).fmt(zcu),
103803103804 ops[0].tracking(cg),
103804103805 }),
103805103806 else => |e| return e,
......@@ -115168,8 +115169,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
115168115169 } }) catch |err| switch (err) {
115169115170 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
115170115171 @tagName(air_tag),
115171 ty_op.ty.fmt(pt),
115172 cg.typeOf(ty_op.operand).fmt(pt),
115172 ty_op.ty.fmt(zcu),
115173 cg.typeOf(ty_op.operand).fmt(zcu),
115173115174 ops[0].tracking(cg),
115174115175 }),
115175115176 else => |e| return e,
......@@ -127059,8 +127060,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
127059127060 } }) catch |err| switch (err) {
127060127061 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
127061127062 @tagName(air_tag),
127062 ty_op.ty.fmt(pt),
127063 cg.typeOf(ty_op.operand).fmt(pt),
127063 ty_op.ty.fmt(zcu),
127064 cg.typeOf(ty_op.operand).fmt(zcu),
127064127065 ops[0].tracking(cg),
127065127066 }),
127066127067 else => |e| return e,
......@@ -161250,7 +161251,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
161250161251 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{
161251161252 @tagName(air_tag),
161252161253 @tagName(reduce.operation),
161253 cg.typeOf(reduce.operand).fmt(pt),
161254 cg.typeOf(reduce.operand).fmt(zcu),
161254161255 ops[0].tracking(cg),
161255161256 }),
161256161257 else => |e| return e,
......@@ -161261,7 +161262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
161261161262 error.SelectFailed => return cg.fail("failed to select {s}.{s} wrap {f} {f}", .{
161262161263 @tagName(air_tag),
161263161264 @tagName(reduce.operation),
161264 res_ty.fmt(pt),
161265 res_ty.fmt(zcu),
161265161266 res[0].tracking(cg),
161266161267 }),
161267161268 else => |e| return e,
......@@ -168964,7 +168965,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168964168965 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{
168965168966 @tagName(air_tag),
168966168967 @tagName(reduce.operation),
168967 cg.typeOf(reduce.operand).fmt(pt),
168968 cg.typeOf(reduce.operand).fmt(zcu),
168968168969 ops[0].tracking(cg),
168969168970 }),
168970168971 else => |e| return e,
......@@ -170804,7 +170805,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170804170805 } }) catch |err| switch (err) {
170805170806 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
170806170807 @tagName(air_tag),
170807 ty_op.ty.fmt(pt),
170808 ty_op.ty.fmt(zcu),
170808170809 ops[0].tracking(cg),
170809170810 }),
170810170811 else => |e| return e,
......@@ -170820,8 +170821,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170820170821 ops[2] = ops[0].getByteLen(cg) catch |err| switch (err) {
170821170822 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
170822170823 @tagName(air_tag),
170823 cg.typeOf(bin_op.lhs).fmt(pt),
170824 cg.typeOf(bin_op.rhs).fmt(pt),
170824 cg.typeOf(bin_op.lhs).fmt(zcu),
170825 cg.typeOf(bin_op.rhs).fmt(zcu),
170825170826 ops[0].tracking(cg),
170826170827 ops[1].tracking(cg),
170827170828 }),
......@@ -170861,8 +170862,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170861170862 }) catch |err| switch (err) {
170862170863 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f} {f}", .{
170863170864 @tagName(air_tag),
170864 cg.typeOf(bin_op.lhs).fmt(pt),
170865 cg.typeOf(bin_op.rhs).fmt(pt),
170865 cg.typeOf(bin_op.lhs).fmt(zcu),
170866 cg.typeOf(bin_op.rhs).fmt(zcu),
170866170867 ops[0].tracking(cg),
170867170868 ops[1].tracking(cg),
170868170869 ops[2].tracking(cg),
......@@ -171042,7 +171043,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171042171043 } }) catch |err| switch (err) {
171043171044 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171044171045 @tagName(air_tag),
171045 cg.typeOf(un_op).fmt(pt),
171046 cg.typeOf(un_op).fmt(zcu),
171046171047 ops[0].tracking(cg),
171047171048 }),
171048171049 else => |e| return e,
......@@ -171208,7 +171209,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171208171209 } }) catch |err| switch (err) {
171209171210 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171210171211 @tagName(air_tag),
171211 cg.typeOf(un_op).fmt(pt),
171212 cg.typeOf(un_op).fmt(zcu),
171212171213 ops[0].tracking(cg),
171213171214 }),
171214171215 else => |e| return e,
......@@ -171310,7 +171311,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171310171311 } }) catch |err| switch (err) {
171311171312 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171312171313 @tagName(air_tag),
171313 cg.typeOf(un_op).fmt(pt),
171314 cg.typeOf(un_op).fmt(zcu),
171314171315 ops[0].tracking(cg),
171315171316 }),
171316171317 else => |e| return e,
......@@ -171408,7 +171409,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171408171409 } }) catch |err| switch (err) {
171409171410 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171410171411 @tagName(air_tag),
171411 ty_op.ty.fmt(pt),
171412 ty_op.ty.fmt(zcu),
171412171413 ops[0].tracking(cg),
171413171414 }),
171414171415 else => |e| return e,
......@@ -171481,7 +171482,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171481171482 },
171482171483 else => return cg.fail("failed to select {s} {f}", .{
171483171484 @tagName(air_tag),
171484 agg_ty.fmt(pt),
171485 agg_ty.fmt(zcu),
171485171486 }),
171486171487 }
171487171488 try res.finish(inst, &.{}, &.{}, cg);
......@@ -172927,7 +172928,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
172927172928 } }) catch |err| switch (err) {
172928172929 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
172929172930 @tagName(air_tag),
172930 cg.typeOf(bin_op.lhs).fmt(pt),
172931 cg.typeOf(bin_op.lhs).fmt(zcu),
172931172932 ops[0].tracking(cg),
172932172933 ops[1].tracking(cg),
172933172934 ops[2].tracking(cg),
......@@ -173765,7 +173766,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173765173766 switch (ip.indexToKey(lazy_sym.ty)) {
173766173767 .enum_type => {
173767173768 const enum_ty: Type = .fromInterned(lazy_sym.ty);
173768 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)});
173769 wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(zcu)});
173769173770
173770173771 const ret_regs = abi.getCAbiIntReturnRegs(.auto)[0..2].*;
173771173772 const ret_locks = cg.register_manager.lockRegsAssumeUnused(2, ret_regs);
......@@ -173826,7 +173827,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173826173827 },
173827173828 .error_set_type => |error_set_type| {
173828173829 const err_ty: Type = .fromInterned(lazy_sym.ty);
173829 wip_mir_log.debug("{f}.@errorCast:", .{err_ty.fmt(pt)});
173830 wip_mir_log.debug("{f}.@errorCast:", .{err_ty.fmt(zcu)});
173830173831
173831173832 const ret_reg = abi.getCAbiIntReturnRegs(.auto)[0];
173832173833 const ret_lock = cg.register_manager.lockRegAssumeUnused(ret_reg);
......@@ -173871,7 +173872,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173871173872 },
173872173873 else => return cg.fail(
173873173874 "TODO implement {s} for {f}",
173874 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) },
173875 .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu) },
173875173876 ),
173876173877 }
173877173878 try cg.resetTemps(@fromBackingInt(@intCast(0)));
......@@ -174080,7 +174081,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex {
174080174081 const val_ty = ptr_ty.childType(zcu);
174081174082 return self.allocFrameIndex(.init(.{
174082174083 .size = std.math.cast(u32, val_ty.abiSize(zcu)) orelse {
174083 return self.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)});
174084 return self.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(zcu)});
174084174085 },
174085174086 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
174086174087 }));
......@@ -174098,7 +174099,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
174098174099 const pt = self.pt;
174099174100 const zcu = pt.zcu;
174100174101 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
174101 return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(pt)});
174102 return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(zcu)});
174102174103 };
174103174104
174104174105 if (reg_ok) need_mem: {
......@@ -174592,9 +174593,9 @@ fn store(
174592174593}
174593174594
174594174595fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
174595 const pt = self.pt;
174596 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));
174597 if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(pt) });
174596 const zcu = self.pt.zcu;
174597 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
174598 if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(zcu) });
174598174599 switch (dst_mcv) {
174599174600 .none,
174600174601 .unreach,
......@@ -176294,7 +176295,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176294176295 } });
176295176296 dst.copyToMask(&src, cg) catch |err| switch (err) {
176296176297 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{
176297 arg_ty.fmt(pt),
176298 arg_ty.fmt(zcu),
176298176299 dst.tracking(cg),
176299176300 src.tracking(cg),
176300176301 }),
......@@ -176515,7 +176516,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176515176516 var dst = try cg.tempInit(arg_ty, dst_arg);
176516176517 dst.copyToMask(&src, cg) catch |err| switch (err) {
176517176518 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{
176518 arg_ty.fmt(pt),
176519 arg_ty.fmt(zcu),
176519176520 dst.tracking(cg),
176520176521 src.tracking(cg),
176521176522 }),
......@@ -176640,9 +176641,10 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176640176641}
176641176642
176642176643fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176644 const zcu = cg.pt.zcu;
176643176645 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
176644176646
176645 const ret_ty = cg.fn_type.fnReturnType(cg.pt.zcu);
176647 const ret_ty = cg.fn_type.fnReturnType(zcu);
176646176648 switch (cg.ret_mcv.short) {
176647176649 .none => {},
176648176650 .register => |reg| {
......@@ -176660,7 +176662,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176660176662 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);
176661176663 dst.copyToMask(&src, cg) catch |err| switch (err) {
176662176664 error.SelectFailed => return cg.fail("failed to select ret {f} {f} {f}", .{
176663 ret_ty.fmt(cg.pt),
176665 ret_ty.fmt(zcu),
176664176666 dst.tracking(cg),
176665176667 src.tracking(cg),
176666176668 }),
......@@ -176706,6 +176708,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176706176708}
176707176709
176708176710fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
176711 const zcu = cg.pt.zcu;
176709176712 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
176710176713 switch (cg.ret_mcv.short) {
176711176714 .none => {},
......@@ -176716,13 +176719,13 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
176716176719 => try cg.load(cg.ret_mcv.short, cg.typeOf(un_op), try cg.resolveInst(un_op)),
176717176720 .register_mask => {
176718176721 var ptr = try cg.tempFromOperand(un_op, true);
176719 const ret_ty = ptr.typeOf(cg).childType(cg.pt.zcu);
176722 const ret_ty = ptr.typeOf(cg).childType(zcu);
176720176723 var src = try ptr.load(ret_ty, .{}, cg);
176721176724 try ptr.die(cg);
176722176725 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);
176723176726 dst.copyToMask(&src, cg) catch |err| switch (err) {
176724176727 error.SelectFailed => return cg.fail("failed to select ret_load {f} {f} {f}", .{
176725 ret_ty.fmt(cg.pt),
176728 ret_ty.fmt(zcu),
176726176729 dst.tracking(cg),
176727176730 src.tracking(cg),
176728176731 }),
......@@ -176839,7 +176842,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !?Mir.Inst.Index {
176839176842 return try self.asmJccReloc(.z, undefined);
176840176843 },
176841176844 else => return self.fail("TODO implement condbr when condition is {f} {s}", .{
176842 ty.fmt(self.pt), @tagName(mcv),
176845 ty.fmt(self.pt.zcu), @tagName(mcv),
176843176846 }),
176844176847 }
176845176848}
......@@ -178721,7 +178724,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
178721178724 },
178722178725 .ip, .cr, .dr => {},
178723178726 }
178724 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(pt)});
178727 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(zcu)});
178725178728}
178726178729
178727178730const CopyOptions = struct {
......@@ -178729,7 +178732,7 @@ const CopyOptions = struct {
178729178732};
178730178733
178731178734fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: CopyOptions) InnerError!void {
178732 const pt = self.pt;
178735 const zcu = self.pt.zcu;
178733178736
178734178737 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
178735178738 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
......@@ -178790,7 +178793,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
178790178793 .register => |src_reg| switch (dst_regs[0].class()) {
178791178794 .general_purpose => switch (src_reg.class()) {
178792178795 else => unreachable,
178793 .sse => if (ty.abiSize(pt.zcu) <= 16) {
178796 .sse => if (ty.abiSize(zcu) <= 16) {
178794178797 if (self.hasFeature(.avx)) {
178795178798 try self.asmRegisterRegister(.{ .v_q, .mov }, dst_regs[0].to64(), src_reg.to128());
178796178799 try self.asmRegisterRegisterImmediate(.{ .vp_q, .extr }, dst_regs[1].to64(), src_reg.to128(), .u(1));
......@@ -178865,7 +178868,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
178865178868 },
178866178869 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts),
178867178870 else => return self.fail("TODO implement genCopy for {s} of {f}", .{
178868 @tagName(src_mcv), ty.fmt(pt),
178871 @tagName(src_mcv), ty.fmt(zcu),
178869178872 }),
178870178873 };
178871178874 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);
......@@ -179249,7 +179252,7 @@ fn genSetReg(
179249179252 80 => null,
179250179253 else => unreachable,
179251179254 },
179252 }) orelse return cg.fail("TODO implement genSetReg for {f}", .{ty.fmt(pt)}),
179255 }) orelse return cg.fail("TODO implement genSetReg for {f}", .{ty.fmt(zcu)}),
179253179256 dst_alias,
179254179257 registerAlias(src_reg, @intCast(cg.unalignedSize(ty))),
179255179258 ),
......@@ -179360,7 +179363,7 @@ fn genSetReg(
179360179363 assert(!ty.optionalReprIsPayload(zcu));
179361179364 break :first_ty opt_child;
179362179365 },
179363 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, ty.fmt(pt) }),
179366 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, ty.fmt(zcu) }),
179364179367 });
179365179368 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
179366179369 const frame_size = std.math.ceilPowerOfTwoAssert(u32, abi_size);
......@@ -179769,7 +179772,7 @@ fn genSetMem(
179769179772 );
179770179773 },
179771179774 else => return cg.fail("TODO implement genSetMem for {s} of {f}", .{
179772 @tagName(src_mcv), ty.fmt(pt),
179775 @tagName(src_mcv), ty.fmt(zcu),
179773179776 }),
179774179777 },
179775179778 .register_offset => |reg_off| {
......@@ -180329,7 +180332,7 @@ fn atomicOp(
180329180332 },
180330180333 else => unreachable,
180331180334 }) orelse return self.fail("TODO implement atomicOp of {s} for {f}", .{
180332 @tagName(op), val_ty.fmt(pt),
180335 @tagName(op), val_ty.fmt(zcu),
180333180336 });
180334180337 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});
180335180338 switch (mir_tag[0]) {
......@@ -180778,12 +180781,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
180778180781 else
180779180782 try self.copyToTmpRegister(pred_ty, pred_mcv)
180780180783 else
180781 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}),
180784 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}),
180782180785 else => unreachable,
180783180786 },
180784180787 .register_mask => |pred_reg_mask| {
180785180788 if (pred_reg_mask.info.scalar.bitSize(self.target) != 8 * elem_abi_size)
180786 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
180789 return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)});
180787180790
180788180791 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {
180789180792 try self.register_manager.getKnownReg(.xmm0, null);
......@@ -180857,7 +180860,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
180857180860 else
180858180861 null
180859180862 else
180860 null) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
180863 null) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)});
180861180864 if (has_avx) {
180862180865 const rhs_alias = if (reuse_mcv.isRegister())
180863180866 registerAlias(reuse_mcv.getReg().?, abi_size)
......@@ -181010,7 +181013,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181010181013 else => unreachable,
181011181014 }),
181012181015 );
181013 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
181016 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)});
181014181017 const elem_bits: u16 = @intCast(elem_abi_size * 8);
181015181018 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {
181016181019 const mask_len = elem_abi_size * vec_len;
......@@ -181039,7 +181042,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181039181042 mask_alias,
181040181043 mask_mem,
181041181044 );
181042 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
181045 } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)});
181043181046 {
181044181047 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);
181045181048 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });
......@@ -181159,7 +181162,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181159181162 else => null,
181160181163 },
181161181164 },
181162 }) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)});
181165 }) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)});
181163181166 if (has_avx) {
181164181167 const rhs_alias = if (rhs_mcv.isRegister())
181165181168 registerAlias(rhs_mcv.getReg().?, abi_size)
......@@ -181466,7 +181469,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
181466181469 assert(classes.len == 1);
181467181470 unreachable;
181468181471 },
181469 else => return self.fail("TODO implement c_va_arg for {f} on SysV", .{promote_ty.fmt(pt)}),
181472 else => return self.fail("TODO implement c_va_arg for {f} on SysV", .{promote_ty.fmt(zcu)}),
181470181473 }
181471181474
181472181475 if (unused) break :result .unreach;
......@@ -181512,7 +181515,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
181512181515 try self.genCopy(.usize, next_arg_ptr, .{ .register = next_arg_ptr_reg }, .{});
181513181516 },
181514181517 .memory => unreachable,
181515 else => return self.fail("TODO implement c_va_arg for {f} on Win64", .{promote_ty.fmt(pt)}),
181518 else => return self.fail("TODO implement c_va_arg for {f} on Win64", .{promote_ty.fmt(zcu)}),
181516181519 }
181517181520
181518181521 if (unused) break :result .unreach;
......@@ -182299,7 +182302,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty
182299182302 if (abi_size == parts_size) return parts;
182300182303 if (classes[classes.len - 1] == .float and abi_size > parts_size and abi_size <= parts_size + 4) return parts;
182301182304 };
182302 return self.fail("TODO implement splitType({d}, {f})", .{ parts_len, ty.fmt(pt) });
182305 return self.fail("TODO implement splitType({d}, {f})", .{ parts_len, ty.fmt(zcu) });
182303182306}
182304182307
182305182308/// Truncates the value in the register in place.
......@@ -183183,6 +183186,7 @@ const Temp = struct {
183183183186 }
183184183187
183185183188 fn store(ptr: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {
183189 const zcu = cg.pt.zcu;
183186183190 const val_ty = val.typeOf(cg);
183187183191 try ptr.toOffset(opts.disp, cg);
183188183192 while (try ptr.toLea(cg)) {}
......@@ -183194,7 +183198,7 @@ const Temp = struct {
183194183198 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
183195183199 .undef => if (opts.safe) {
183196183200 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });
183197 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) });
183201 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(zcu) });
183198183202 try ptr.memset(&pat, &len, cg);
183199183203 try pat.die(cg);
183200183204 try len.die(cg);
......@@ -183248,12 +183252,12 @@ const Temp = struct {
183248183252 .register_offset => |val_reg_off| switch (val_reg_off.off) {
183249183253 0 => try ptr.storeRegs(val_ty, &.{registerAlias(
183250183254 val_reg_off.reg,
183251 @intCast(val_ty.abiSize(cg.pt.zcu)),
183255 @intCast(val_ty.abiSize(zcu)),
183252183256 )}, cg),
183253183257 else => continue :val_to_gpr,
183254183258 },
183255183259 .register_overflow => |val_reg_ov| {
183256 const ip = &cg.pt.zcu.intern_pool;
183260 const ip = &zcu.intern_pool;
183257183261 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {
183258183262 .tuple_type => |tuple_type| {
183259183263 const tuple_field_types = tuple_type.types.get(ip);
......@@ -183261,12 +183265,12 @@ const Temp = struct {
183261183265 break :first_ty tuple_field_types[0];
183262183266 },
183263183267 .opt_type => |opt_child| {
183264 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
183268 assert(!val_ty.optionalReprIsPayload(zcu));
183265183269 break :first_ty opt_child;
183266183270 },
183267 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
183271 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(zcu) }),
183268183272 });
183269 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
183273 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
183270183274 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);
183271183275 try ptr.toOffset(first_size, cg);
183272183276 try cg.asmSetccMemory(
......@@ -183277,7 +183281,7 @@ const Temp = struct {
183277183281 .lea_frame, .lea_nav, .lea_uav, .lea_lazy_sym => continue :val_to_gpr,
183278183282 .memory, .indirect, .load_frame, .load_nav, .load_uav, .load_lazy_sym => {
183279183283 var val_ptr = try cg.tempInit(.usize, val_mcv.address());
183280 try ptr.memcpy(&val_ptr, val_ty.abiSize(cg.pt.zcu), cg);
183284 try ptr.memcpy(&val_ptr, val_ty.abiSize(zcu), cg);
183281183285 try val_ptr.die(cg);
183282183286 },
183283183287 }
......@@ -183325,6 +183329,7 @@ const Temp = struct {
183325183329 }
183326183330
183327183331 fn write(dst: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {
183332 const zcu = cg.pt.zcu;
183328183333 const val_ty = val.typeOf(cg);
183329183334 while (try dst.toBase(false, cg)) {}
183330183335 val_to_gpr: while (true) : (while (try dst.toBase(false, cg) or
......@@ -183337,7 +183342,7 @@ const Temp = struct {
183337183342 .undef => if (opts.safe) {
183338183343 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
183339183344 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });
183340 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) });
183345 var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(zcu) });
183341183346 try dst_ptr.memset(&pat, &len, cg);
183342183347 try dst_ptr.die(cg);
183343183348 try pat.die(cg);
......@@ -183364,7 +183369,7 @@ const Temp = struct {
183364183369 ),
183365183370 .register => |val_reg| try dst.writeReg(opts.disp, val_ty, registerAlias(
183366183371 val_reg,
183367 @intCast(val_ty.abiSize(cg.pt.zcu)),
183372 @intCast(val_ty.abiSize(zcu)),
183368183373 ), cg),
183369183374 inline .register_pair,
183370183375 .register_triple,
......@@ -183373,12 +183378,12 @@ const Temp = struct {
183373183378 .register_offset => |val_reg_off| switch (val_reg_off.off) {
183374183379 0 => try dst.writeReg(opts.disp, val_ty, registerAlias(
183375183380 val_reg_off.reg,
183376 @intCast(val_ty.abiSize(cg.pt.zcu)),
183381 @intCast(val_ty.abiSize(zcu)),
183377183382 ), cg),
183378183383 else => continue :val_to_gpr,
183379183384 },
183380183385 .register_overflow => |val_reg_ov| {
183381 const ip = &cg.pt.zcu.intern_pool;
183386 const ip = &zcu.intern_pool;
183382183387 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {
183383183388 .tuple_type => |tuple_type| {
183384183389 const tuple_field_types = tuple_type.types.get(ip);
......@@ -183386,12 +183391,12 @@ const Temp = struct {
183386183391 break :first_ty tuple_field_types[0];
183387183392 },
183388183393 .opt_type => |opt_child| {
183389 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));
183394 assert(!val_ty.optionalReprIsPayload(zcu));
183390183395 break :first_ty opt_child;
183391183396 },
183392 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }),
183397 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(zcu) }),
183393183398 });
183394 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));
183399 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
183395183400 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);
183396183401 try cg.asmSetccMemory(
183397183402 val_reg_ov.eflags,
......@@ -183406,7 +183411,7 @@ const Temp = struct {
183406183411 var dst_ptr =
183407183412 try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
183408183413 var val_ptr = try cg.tempInit(.usize, val_mcv.address());
183409 try dst_ptr.memcpy(&val_ptr, val_ty.abiSize(cg.pt.zcu), cg);
183414 try dst_ptr.memcpy(&val_ptr, val_ty.abiSize(zcu), cg);
183410183415 try dst_ptr.die(cg);
183411183416 try val_ptr.die(cg);
183412183417 },
......@@ -183444,7 +183449,7 @@ const Temp = struct {
183444183449 assert(src_regs.len == @divCeil(int_info.bits, 64));
183445183450 break :part_ty .u64;
183446183451 } else part_ty: switch (ip.indexToKey(src_ty.toIntern())) {
183447 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(cg.pt) }),
183452 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(zcu) }),
183448183453 .ptr_type => |ptr_info| {
183449183454 assert(ptr_info.flags.size == .slice);
183450183455 assert(src_regs.len == 2);
......@@ -183463,7 +183468,7 @@ const Temp = struct {
183463183468 }),
183464183469 },
183465183470 .opt_type => |opt_child| switch (ip.indexToKey(opt_child)) {
183466 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(cg.pt) }),
183471 else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(zcu) }),
183467183472 .ptr_type => |ptr_info| {
183468183473 assert(ptr_info.flags.size == .slice);
183469183474 assert(src_regs.len == 2);
......@@ -189637,7 +189642,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {
189637189642 any_valid = true;
189638189643 tracking_log.err("failed to kill {f}: {f}", .{
189639189644 temp.toIndex(),
189640 cg.temp_type[temp_index].fmt(cg.pt),
189645 cg.temp_type[temp_index].fmt(cg.pt.zcu),
189641189646 });
189642189647 }
189643189648 cg.temp_type[temp_index] = undefined;
src/link/Coff.zig+22-39
......@@ -5766,7 +5766,7 @@ fn flushImplib(
57665766 try file_writer.interface.flush();
57675767}
57685768
5769fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
5769fn reportUndefs(coff: *Coff) !void {
57705770 const comp = coff.base.comp;
57715771 const gpa = comp.gpa;
57725772 const max_notes = 4;
......@@ -5887,14 +5887,8 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
58875887 const ip = &comp.zcu.?.intern_pool;
58885888 break :format ip.getNav(val.navIndex(coff)).fqn.fmt(ip);
58895889 },
5890 .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(.{
5891 .zcu = coff.base.comp.zcu.?,
5892 .tid = tid,
5893 }),
5894 inline .lazy_code, .lazy_const_data => Type.fromInterned(val.lazySymbol(coff).ty).fmt(.{
5895 .zcu = coff.base.comp.zcu.?,
5896 .tid = tid,
5897 }),
5890 .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(coff.base.comp.zcu.?),
5891 inline .lazy_code, .lazy_const_data => Type.fromInterned(val.lazySymbol(coff).ty).fmt(coff.base.comp.zcu.?),
58985892 else => unreachable,
58995893 },
59005894 });
......@@ -5927,7 +5921,7 @@ pub fn flush(
59275921
59285922 const comp = coff.base.comp;
59295923
5930 while (try coff.resolve(tid)) {}
5924 while (try coff.resolve()) {}
59315925 while (try coff.idle(tid)) {}
59325926
59335927 // This has to occur after all other flushMoved / flushResized have resolved,
......@@ -5951,7 +5945,7 @@ pub fn flush(
59515945 while (try coff.idle(tid)) {}
59525946
59535947 if (coff.isImage())
5954 try coff.reportUndefs(tid);
5948 try coff.reportUndefs();
59555949
59565950 if (comp.emit_implib) |implib_file|
59575951 coff.flushImplib(implib_file) catch |err|
......@@ -5970,7 +5964,7 @@ pub fn flush(
59705964/// Runs a single "resolution" task.
59715965/// These are tasks that need to modify the node structure in some way.
59725966/// They must run in a defined order with respect to linker tasks.
5973fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
5967fn resolve(coff: *Coff) !bool {
59745968 const comp = coff.base.comp;
59755969 task: {
59765970 while (coff.section_merge_pending_index < coff.section_merges.count()) {
......@@ -6046,7 +6040,6 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
60466040 const si = coff.symbol_table.symbols.keys()[coff.symbol_table.pending_symbol_index];
60476041 const sym = si.get(coff);
60486042 const sub_prog_node = coff.idleProgNode(
6049 tid,
60506043 coff.symbol_prog_node,
60516044 if (sym.ni.unwrap()) |sym_ni|
60526045 coff.getNode(sym_ni)
......@@ -6077,6 +6070,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
60776070}
60786071
60796072pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6073 _ = tid;
60806074 // Idle tasks should not modify create / modify nodes, otherwise the output is not reproducible.
60816075 coff.mf.nodes_lock.lock();
60826076 defer coff.mf.nodes_lock.unlock();
......@@ -6087,7 +6081,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
60876081 if (coff.input_section_pending_index < coff.input_sections.items.len) {
60886082 const isi: Node.InputSection.Index = @fromBackingInt(@intCast(coff.input_section_pending_index));
60896083 coff.input_section_pending_index += 1;
6090 const sub_prog_node = coff.idleProgNode(tid, coff.input_prog_node, coff.getNode(isi.symbol(coff).node(coff)));
6084 const sub_prog_node = coff.idleProgNode(coff.input_prog_node, coff.getNode(isi.symbol(coff).node(coff)));
60916085 defer sub_prog_node.end();
60926086 coff.flushInputSection(isi) catch |err| switch (err) {
60936087 else => |e| {
......@@ -6112,7 +6106,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
61126106 const clean_next_moved = ni.cleanNextMoved(&coff.mf);
61136107 if (!clean_moved and !clean_resized and !clean_next_moved) continue;
61146108 const sub_prog_node =
6115 coff.idleProgNode(tid, coff.mf.update_prog_node, coff.getNode(ni));
6109 coff.idleProgNode(coff.mf.update_prog_node, coff.getNode(ni));
61166110 defer sub_prog_node.end();
61176111 if (clean_moved) try coff.flushMoved(ni);
61186112 if (clean_resized) try coff.flushResized(ni);
......@@ -6120,7 +6114,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
61206114 }
61216115 while (coff.pending_members.pop()) |pending_mi| {
61226116 const sub_prog_node = coff.idleProgNode(
6123 tid,
61246117 coff.symbol_prog_node,
61256118 coff.getNode(pending_mi.key.get(coff).content_ni),
61266119 );
......@@ -6131,7 +6124,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
61316124 if (coff.exports_complete and coff.export_table.pending_sort) {
61326125 defer coff.export_table.pending_sort = false;
61336126 const sub_prog_node = coff.idleProgNode(
6134 tid,
61356127 coff.synth_prog_node,
61366128 coff.getNode(coff.export_table.ni),
61376129 );
......@@ -6150,7 +6142,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
61506142
61516143fn idleProgNode(
61526144 coff: *Coff,
6153 tid: Zcu.PerThread.Id,
61546145 prog_node: std.Progress.Node,
61556146 node: Node,
61566147) std.Progress.Node {
......@@ -6173,10 +6164,7 @@ fn idleProgNode(
61736164 break :name ip.getNav(nmi.navIndex(coff)).fqn.toSlice(ip);
61746165 },
61756166 .uav => |umi| std.mem.print(&name, "{f}", .{
6176 Value.fromInterned(umi.uavValue(coff)).fmtValue(.{
6177 .zcu = coff.base.comp.zcu.?,
6178 .tid = tid,
6179 }),
6167 Value.fromInterned(umi.uavValue(coff)).fmtValue(coff.base.comp.zcu.?),
61806168 }) catch &name,
61816169 .archive_member => |mi| &mi.get(coff).headerPtr(coff).name,
61826170 }, 0);
......@@ -6185,7 +6173,7 @@ fn idleProgNode(
61856173fn genPending(coff: *Coff, pt: Zcu.PerThread) Error!void {
61866174 const comp = pt.zcu.comp;
61876175 while (coff.pending_uavs.pop()) |pending_uav| {
6188 const sub_prog_node = coff.idleProgNode(pt.tid, coff.const_prog_node, .{ .uav = pending_uav.key });
6176 const sub_prog_node = coff.idleProgNode(coff.const_prog_node, .{ .uav = pending_uav.key });
61896177 defer sub_prog_node.end();
61906178 coff.genUav(pt, pending_uav.key, pending_uav.value.alignment) catch |err| switch (err) {
61916179 else => |e| return e,
......@@ -6845,7 +6833,7 @@ fn genLazy(coff: *Coff, pt: Zcu.PerThread, lmr: Node.LazyMapRef) !void {
68456833 const sub_prog_node = coff.synth_prog_node.start(
68466834 std.mem.print(&name, "lazy {s} for {f}", .{
68476835 kind,
6848 Type.fromInterned(lazy.ty).fmt(pt),
6836 Type.fromInterned(lazy.ty).fmt(coff.base.comp.zcu.?),
68496837 }) catch &name,
68506838 0,
68516839 );
......@@ -7461,14 +7449,14 @@ fn updateExportInner(
74617449 switch (exp.exported) {
74627450 .nav => |nav| log.debug("updateExports({f}) = {d}", .{ ip.getNav(nav).fqn.fmt(ip), exported_si }),
74637451 .uav => |uav| log.debug("updateExports(@as({f}, {f})) = {d}", .{
7464 Type.fromInterned(ip.typeOf(uav)).fmt(pt),
7465 Value.fromInterned(uav).fmtValue(pt),
7452 Type.fromInterned(ip.typeOf(uav)).fmt(zcu),
7453 Value.fromInterned(uav).fmtValue(zcu),
74667454 exported_si,
74677455 }),
74687456 }
74697457
74707458 try coff.genPending(pt);
7471 while (try coff.resolve(pt.tid)) {}
7459 while (try coff.resolve()) {}
74727460 while (try coff.idle(pt.tid)) {}
74737461
74747462 const machine = coff.targetLoad(&coff.headerPtr().machine);
......@@ -7627,7 +7615,7 @@ pub fn dump(coff: *Coff, w: *Io.Writer, tid: Zcu.PerThread.Id) Io.Writer.Error!l
76277615 try coff.printSection(w, name, sec.si);
76287616 try w.writeAll("Symbol table:\n");
76297617 for (1..coff.symbols.items.len) |si|
7630 try coff.printSymbol(w, tid, @fromBackingInt(@intCast(si)));
7618 try coff.printSymbol(w, @fromBackingInt(@intCast(si)));
76317619
76327620 return .enabled;
76337621 }
......@@ -7648,7 +7636,6 @@ fn printSection(coff: *Coff, w: *Io.Writer, name: String, si: Symbol.Index) Io.W
76487636fn printSymbol(
76497637 coff: *Coff,
76507638 w: *Io.Writer,
7651 tid: Zcu.PerThread.Id,
76527639 si: Symbol.Index,
76537640) Io.Writer.Error!void {
76547641 const sym = si.get(coff);
......@@ -7687,7 +7674,7 @@ fn printSymbol(
76877674 try w.print("G {f}\n", .{fmtGlobalName(coff, sym.gmi)});
76887675 } else {
76897676 try w.writeAll("| ");
7690 try coff.printNodeName(w, tid, coff.getNode(sym.ni.unwrap().?));
7677 try coff.printNodeName(w, coff.getNode(sym.ni.unwrap().?));
76917678 if (sym.flags.extra_tag == .isli)
76927679 try w.print(" | {s}", .{sym.extra.isli.name(coff).toSlice(coff)});
76937680 try w.writeByte('\n');
......@@ -7712,7 +7699,6 @@ fn globalNameEscape(data: FmtGlobalName, w: *std.Io.Writer) std.Io.Writer.Error!
77127699fn printNodeName(
77137700 coff: *Coff,
77147701 w: *std.Io.Writer,
7715 tid: Zcu.PerThread.Id,
77167702 node: Node,
77177703) Io.Writer.Error!void {
77187704 switch (node) {
......@@ -7754,7 +7740,7 @@ fn printNodeName(
77547740 const ip = &zcu.intern_pool;
77557741 const nav = ip.getNav(nmi.navIndex(coff));
77567742 try w.print("({f}, {f})", .{
7757 Type.fromInterned(ip.typeOf(nav.resolved.?.value)).fmt(.{ .zcu = zcu, .tid = tid }),
7743 Type.fromInterned(ip.typeOf(nav.resolved.?.value)).fmt(zcu),
77587744 nav.fqn.fmt(ip),
77597745 });
77607746 },
......@@ -7762,15 +7748,12 @@ fn printNodeName(
77627748 const zcu = coff.base.comp.zcu.?;
77637749 const val: Value = .fromInterned(umi.uavValue(coff));
77647750 try w.print("({f}, {f})", .{
7765 val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }),
7766 val.fmtValue(.{ .zcu = zcu, .tid = tid }),
7751 val.typeOf(zcu).fmt(zcu),
7752 val.fmtValue(zcu),
77677753 });
77687754 },
77697755 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{
7770 Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(.{
7771 .zcu = coff.base.comp.zcu.?,
7772 .tid = tid,
7773 }),
7756 Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(coff.base.comp.zcu.?),
77747757 }),
77757758 .builtin => |si| {
77767759 const sym = si.get(coff);
......@@ -7789,7 +7772,7 @@ pub fn printNode(
77897772 const node = coff.getNode(ni);
77907773 try w.splatByteAll(' ', indent);
77917774 try w.writeAll(@tagName(node));
7792 try coff.printNodeName(w, tid, node);
7775 try coff.printNodeName(w, node);
77937776 {
77947777 const mf_node = &coff.mf.nodes.items[@backingInt(ni)];
77957778 const off, const size = mf_node.location().resolve(&coff.mf);
src/link/Dwarf.zig+24-23
......@@ -1036,7 +1036,7 @@ const Entry = struct {
10361036 const val_unit, const val_entry = unit_and_entry;
10371037 if (sec.getUnit(val_unit) == unit and unit.getEntry(val_entry) == entry)
10381038 log.err("missing Value({f}({d}))", .{
1039 Value.fromInterned(val).fmtValue(.{ .tid = .main, .zcu = zcu }),
1039 Value.fromInterned(val).fmtValue(zcu),
10401040 @backingInt(val),
10411041 });
10421042 }
......@@ -2120,9 +2120,10 @@ pub const WipNav = struct {
21202120 wip_nav: *WipNav,
21212121 val: Value,
21222122 ) (UpdateError || Writer.Error)!void {
2123 const ty = val.typeOf(wip_nav.pt.zcu);
2123 const zcu = wip_nav.pt.zcu;
2124 const ty = val.typeOf(zcu);
21242125 const diw = &wip_nav.debug_info.writer;
2125 const size = ty.abiSize(wip_nav.pt.zcu);
2126 const size = ty.abiSize(zcu);
21262127 try diw.writeUleb128(size);
21272128 if (size == 0) return;
21282129 const old_end = diw.end;
......@@ -2135,7 +2136,7 @@ pub const WipNav = struct {
21352136 );
21362137 if (old_end + size != diw.end) {
21372138 std.debug.print("{f} [{}]: {} != {}\n", .{
2138 ty.fmt(wip_nav.pt),
2139 ty.fmt(zcu),
21392140 ty.toIntern(),
21402141 size,
21412142 diw.end - old_end,
......@@ -3340,8 +3341,8 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde
33403341 switch (value_index) {
33413342 .generic_poison_type => log.debug("updateValueIncomplete(anytype)", .{}),
33423343 else => log.debug("updateValueIncomplete(@as({f}, {f}))", .{
3343 val.typeOf(zcu).fmt(pt),
3344 val.fmtValue(pt),
3344 val.typeOf(zcu).fmt(zcu),
3345 val.fmtValue(zcu),
33453346 }),
33463347 }
33473348
......@@ -3435,7 +3436,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde
34353436 else => |val_key| switch (val_key.typeOf()) {
34363437 .type_type => {
34373438 try wip_nav.abbrevCode(.generated_empty_struct_type);
3438 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3439 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
34393440 try wip_nav.debug_info.writer.writeByte(@intFromBool(true));
34403441 },
34413442 else => |ty| {
......@@ -3509,8 +3510,8 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
35093510 switch (value_index) {
35103511 .generic_poison_type => log.debug("updateValue(anytype)", .{}),
35113512 else => log.debug("updateValue(@as({f}, {f}))", .{
3512 val.typeOf(zcu).fmt(pt),
3513 val.fmtValue(pt),
3513 val.typeOf(zcu).fmt(zcu),
3514 val.fmtValue(zcu),
35143515 }),
35153516 }
35163517
......@@ -3551,7 +3552,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
35513552
35523553 .int_type => |int_type| {
35533554 try wip_nav.abbrevCode(.numeric_type);
3554 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3555 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
35553556 try diw.writeByte(switch (int_type.signedness) {
35563557 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),
35573558 });
......@@ -3566,7 +3567,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
35663567 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,
35673568 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,
35683569 });
3569 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3570 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
35703571 if (ptr_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(ptr_type.sentinel));
35713572 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);
35723573 try diw.writeByte(@backingInt(ptr_type.flags.address_space));
......@@ -3592,7 +3593,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
35923593 },
35933594 .slice => {
35943595 try wip_nav.abbrevCode(.generated_struct_type);
3595 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3596 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
35963597 try diw.writeUleb128(val.toType().abiSize(zcu));
35973598 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
35983599 try wip_nav.abbrevCode(.generated_field);
......@@ -3611,7 +3612,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
36113612 .array_type => |array_type| {
36123613 const array_child_type: Type = .fromInterned(array_type.child);
36133614 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);
3614 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3615 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
36153616 if (array_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(array_type.sentinel));
36163617 try wip_nav.refType(array_child_type);
36173618 try wip_nav.abbrevCode(.array_len);
......@@ -3621,7 +3622,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
36213622 },
36223623 .vector_type => |vector_type| {
36233624 try wip_nav.abbrevCode(.vector_type);
3624 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3625 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
36253626 try wip_nav.refType(.fromInterned(vector_type.child));
36263627 try wip_nav.abbrevCode(.array_len);
36273628 try wip_nav.refType(.usize);
......@@ -3632,7 +3633,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
36323633 const opt_child_type: Type = .fromInterned(opt_child_type_index);
36333634 const opt_repr = optRepr(opt_child_type, zcu);
36343635 try wip_nav.abbrevCode(.generated_union_type);
3635 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3636 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
36363637 try diw.writeUleb128(val.toType().abiSize(zcu));
36373638 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
36383639 switch (opt_repr) {
......@@ -3713,7 +3714,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
37133714 };
37143715
37153716 try wip_nav.abbrevCode(.generated_union_type);
3716 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3717 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
37173718 if (error_union_type.error_set_type != .generic_poison_type and
37183719 error_union_type.payload_type != .generic_poison_type)
37193720 {
......@@ -3785,7 +3786,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
37853786 .bool,
37863787 => {
37873788 try wip_nav.abbrevCode(.numeric_type);
3788 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3789 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
37893790 try diw.writeByte(if (value_index == .bool_type)
37903791 DW.ATE.boolean
37913792 else if (val.toType().isRuntimeFloat())
......@@ -3815,18 +3816,18 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
38153816 .enum_literal,
38163817 => {
38173818 try wip_nav.abbrevCode(.void_type);
3818 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3819 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
38193820 },
38203821 .anyerror => unreachable, // already did early return above
38213822 .adhoc_inferred_error_set => unreachable,
38223823 },
38233824 .tuple_type => |tuple_type| if (tuple_type.types.len == 0) {
38243825 try wip_nav.abbrevCode(.generated_empty_struct_type);
3825 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3826 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
38263827 try diw.writeByte(@intFromBool(false));
38273828 } else {
38283829 try wip_nav.abbrevCode(.generated_struct_type);
3829 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
3830 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
38303831 try diw.writeUleb128(val.toType().abiSize(zcu));
38313832 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
38323833 var field_byte_offset: u64 = 0;
......@@ -4148,7 +4149,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
41484149 .func_type => |func_type| {
41494150 const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args;
41504151 try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type);
4151 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
4152 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
41524153 const cc: DW.CC = cc: {
41534154 if (zcu.getTarget().cCallingConvention()) |cc| {
41544155 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {
......@@ -4231,7 +4232,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
42314232 },
42324233 .error_set_type => |error_set_type| {
42334234 try wip_nav.abbrevCode(if (error_set_type.names.len == 0) .generated_empty_enum_type else .generated_enum_type);
4234 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
4235 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
42354236 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
42364237 .signedness = .unsigned,
42374238 .bits = zcu.errorSetBits(),
......@@ -4247,7 +4248,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
42474248 },
42484249 .inferred_error_set_type => |func| {
42494250 try wip_nav.abbrevCode(.inferred_error_set_type);
4250 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});
4251 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
42514252 try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {
42524253 .none => .anyerror_type,
42534254 else => |ies| ies,
src/link/Dwarf2.zig+18-17
......@@ -2516,7 +2516,7 @@ pub fn updateConst(
25162516) link.Error!void {
25172517 switch (val) {
25182518 .generic_poison_type => log.debug("updateConst(anytype)", .{}),
2519 else => log.debug("updateConst({f})", .{Value.fromInterned(val).fmtValue(pt)}),
2519 else => log.debug("updateConst({f})", .{Value.fromInterned(val).fmtValue(pt.zcu)}),
25202520 }
25212521 dwarf.updateConstInner(pt, di_nw, val) catch |err| switch (err) {
25222522 else => |e| return e,
......@@ -2538,7 +2538,7 @@ fn updateConstInner(
25382538 try dwarf.abbrevCode(di_nw, .numeric_type);
25392539 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
25402540 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2541 ty.fmt(pt),
2541 ty.fmt(zcu),
25422542 }) catch unreachable);
25432543 try di_w.writeByte(switch (int_type.signedness) {
25442544 .signed => DW.ATE.signed,
......@@ -2550,7 +2550,7 @@ fn updateConstInner(
25502550 },
25512551 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
25522552 .one, .many, .c => {
2553 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2553 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
25542554 defer zcu.gpa.free(name);
25552555 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
25562556 .none => .ptr_type,
......@@ -2585,7 +2585,7 @@ fn updateConstInner(
25852585 },
25862586 .slice => {
25872587 const ty: Type = .fromInterned(@"const");
2588 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2588 const name = try zcu.gpa.print("{f}", .{ty.fmt(zcu)});
25892589 defer zcu.gpa.free(name);
25902590 try dwarf.abbrevCode(di_nw, .generated_struct_type);
25912591 try dwarf.strx(di_nw, name);
......@@ -2605,7 +2605,7 @@ fn updateConstInner(
26052605 },
26062606 },
26072607 .array_type => |array_type| {
2608 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2608 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
26092609 defer zcu.gpa.free(name);
26102610 try dwarf.abbrevCode(
26112611 di_nw,
......@@ -2621,7 +2621,7 @@ fn updateConstInner(
26212621 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
26222622 },
26232623 .vector_type => |vector_type| {
2624 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
2624 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
26252625 defer zcu.gpa.free(name);
26262626 try dwarf.abbrevCode(di_nw, .vector_type);
26272627 try dwarf.strx(di_nw, name);
......@@ -2635,7 +2635,7 @@ fn updateConstInner(
26352635 const opt_ty: Type = .fromInterned(@"const");
26362636 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
26372637 const opt_repr = optRepr(opt_child_ty, zcu);
2638 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
2638 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(zcu)});
26392639 defer zcu.gpa.free(name);
26402640 try dwarf.abbrevCode(di_nw, .generated_union_type);
26412641 try dwarf.strx(di_nw, name);
......@@ -2715,7 +2715,7 @@ fn updateConstInner(
27152715 codegen.errUnionPayloadOffset(eu_payload_ty, zcu),
27162716 },
27172717 };
2718 const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(pt)});
2718 const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(zcu)});
27192719 defer zcu.gpa.free(name);
27202720
27212721 try dwarf.abbrevCode(di_nw, .generated_union_type);
......@@ -2819,7 +2819,7 @@ fn updateConstInner(
28192819 try dwarf.abbrevCode(di_nw, .void_type);
28202820 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
28212821 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2822 ty.fmt(pt),
2822 ty.fmt(zcu),
28232823 }) catch unreachable);
28242824 },
28252825 .anyerror => {
......@@ -2842,7 +2842,7 @@ fn updateConstInner(
28422842 },
28432843 .tuple_type => |tuple_type| {
28442844 const ty: Type = .fromInterned(@"const");
2845 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
2845 const name = try zcu.gpa.print("{f}", .{ty.fmt(zcu)});
28462846 defer zcu.gpa.free(name);
28472847 if (tuple_type.types.len == 0) {
28482848 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
......@@ -3255,7 +3255,7 @@ fn updateConstInner(
32553255 .spirv_type => unreachable,
32563256 .func_type => |func_type| {
32573257 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;
3258 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
3258 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
32593259 defer zcu.gpa.free(name);
32603260 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
32613261 try dwarf.strx(di_nw, name);
......@@ -3340,7 +3340,7 @@ fn updateConstInner(
33403340 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
33413341 },
33423342 .error_set_type => |error_set_type| {
3343 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
3343 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
33443344 defer zcu.gpa.free(name);
33453345 try dwarf.abbrevCode(
33463346 di_nw,
......@@ -3358,7 +3358,7 @@ fn updateConstInner(
33583358 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
33593359 },
33603360 .inferred_error_set_type => |func| {
3361 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)});
3361 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)});
33623362 defer zcu.gpa.free(name);
33633363 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);
33643364 try dwarf.strx(di_nw, name);
......@@ -3863,7 +3863,7 @@ pub fn updateConstIncomplete(
38633863 di_nw: *link.MappedFile.Node.Writer,
38643864 val: InternPool.Index,
38653865) link.Error!void {
3866 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)});
3866 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt.zcu)});
38673867 dwarf.updateConstIncompleteInner(pt, di_nw, val) catch |err| switch (err) {
38683868 else => |e| return e,
38693869 error.WriteFailed => return dwarf.reportWriteError(di_nw),
......@@ -4021,7 +4021,7 @@ fn updateConstIncompleteInner(
40214021 },
40224022 else => |val_key| break :done switch (val_key.typeOf()) {
40234023 .type_type => {
4024 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
4024 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(zcu)});
40254025 defer zcu.gpa.free(name);
40264026 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
40274027 try dwarf.strx(di_nw, name);
......@@ -4140,11 +4140,12 @@ pub fn genDecl(
41404140 di_nw: *link.MappedFile.Node.Writer,
41414141 instance: Decl.Instance,
41424142) link.Error!void {
4143 const zcu = pt.zcu;
41434144 switch (instance) {
41444145 .none => unreachable,
4145 .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(pt)}),
4146 .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(zcu)}),
41464147 .global => |global| log.debug("genDecl({f})", .{
4147 pt.zcu.intern_pool.getNav(global).fqn.fmt(&pt.zcu.intern_pool),
4148 zcu.intern_pool.getNav(global).fqn.fmt(&zcu.intern_pool),
41484149 }),
41494150 }
41504151 dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) {
src/link/Elf/ZigObject.zig+2-2
......@@ -1720,7 +1720,7 @@ fn updateLazySymbol(
17201720 const name_str_index = blk: {
17211721 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{
17221722 @tagName(sym.kind),
1723 Type.fromInterned(sym.ty).fmt(pt),
1723 Type.fromInterned(sym.ty).fmt(zcu),
17241724 });
17251725 defer gpa.free(name);
17261726 break :blk try self.strtab.insert(gpa, name);
......@@ -2349,7 +2349,7 @@ fn checkUavAllocated(pt: Zcu.PerThread, index: InternPool.Index, meta: AvMetadat
23492349 const uav = Value.fromInterned(index);
23502350 const ty = uav.typeOf(zcu);
23512351 log.err("UAV {f}({d}) assigned symbol {d} but not allocated!", .{
2352 ty.fmt(pt),
2352 ty.fmt(zcu),
23532353 index,
23542354 meta.symbol_index,
23552355 });
src/link/Elf2.zig+23-23
......@@ -10328,6 +10328,8 @@ fn flushInner(
1032810328}
1032910329
1033010330pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
10331 _ = tid;
10332
1033110333 // This function is called non-deterministically, and so must not affect the layout of any nodes.
1033210334 elf.mf.nodes_lock.lock();
1033310335 defer elf.mf.nodes_lock.unlock();
......@@ -10343,7 +10345,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
1034310345 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);
1034410346 elf.input_pending_index += 1;
1034510347 const idle_prog_node =
10346 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
10348 elf.startIdleProgress(elf.input_prog_node, elf.getNode(ii.node(elf)));
1034710349 defer idle_prog_node.end();
1034810350 elf.flushInput(ii) catch |err| switch (err) {
1034910351 else => |e| return e,
......@@ -10355,7 +10357,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
1035510357 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);
1035610358 elf.input_section_pending_index += 1;
1035710359 const idle_prog_node =
10358 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
10360 elf.startIdleProgress(elf.input_prog_node, elf.getNode(isi.node(elf)));
1035910361 defer idle_prog_node.end();
1036010362 elf.flushInputSection(isi) catch |err| switch (err) {
1036110363 else => |e| return e,
......@@ -10465,7 +10467,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
1046510467 const clean_resized = ni.cleanResized(&elf.mf);
1046610468 const clean_next_moved = ni.cleanNextMoved(&elf.mf);
1046710469 if (!clean_moved and !clean_resized and !clean_next_moved) continue;
10468 const idle_prog_node = elf.startIdleProgress(tid, elf.mf.update_prog_node, elf.getNode(ni));
10470 const idle_prog_node = elf.startIdleProgress(elf.mf.update_prog_node, elf.getNode(ni));
1046910471 defer idle_prog_node.end();
1047010472 if (clean_moved) try elf.flushMoved(ni);
1047110473 if (clean_resized) try elf.flushResized(ni);
......@@ -10483,7 +10485,6 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
1048310485
1048410486fn startIdleProgress(
1048510487 elf: *Elf,
10486 tid: Zcu.PerThread.Id,
1048710488 prog_node: std.Progress.Node,
1048810489 node: Node,
1048910490) std.Progress.Node {
......@@ -10508,7 +10509,7 @@ fn startIdleProgress(
1050810509 break :name ip.getNav(nmi.nav(elf)).fqn.toSlice(ip);
1050910510 },
1051010511 .uav => |umi| std.mem.print(&name, "{f}", .{
10511 Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
10512 Value.fromInterned(umi.uavValue(elf)).fmtValue(elf.base.comp.zcu.?),
1051210513 }) catch &name,
1051310514 .debug_shared => |ss| switch (ss) {
1051410515 .debug_abbrev => "debug info abbrevs",
......@@ -10539,7 +10540,7 @@ fn startIdleProgress(
1053910540 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {
1054010541 .generic_poison_type => "anytype",
1054110542 else => |val| std.mem.print(&name, "debug info for {f}", .{
10542 Value.fromInterned(val).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
10543 Value.fromInterned(val).fmtValue(elf.base.comp.zcu.?),
1054310544 }) catch &name,
1054410545 },
1054510546 .global_debug_info => |gi| {
......@@ -10571,10 +10572,11 @@ fn startIdleProgress(
1057110572}
1057210573
1057310574fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
10575 const zcu = elf.base.comp.zcu.?;
1057410576 while (elf.pending_uavs.pop()) |umi| {
1057510577 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;
1057610578 const prog_name = std.mem.print(&prog_name_buf, "{f}", .{
10577 Value.fromInterned(umi.uavValue(elf)).fmtValue(pt),
10579 Value.fromInterned(umi.uavValue(elf)).fmtValue(zcu),
1057810580 }) catch &prog_name_buf;
1057910581 const prog_node = elf.const_prog_node.start(prog_name, 0);
1058010582 defer prog_node.end();
......@@ -10671,14 +10673,15 @@ fn genUav(
1067110673}
1067210674
1067310675fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void {
10676 const zcu = elf.base.comp.zcu.?;
1067410677 const lazy = lmr.lazySymbol(elf);
1067510678 if (lazy.ty == .anyerror_type) return;
1067610679 const lazy_ty: Type = .fromInterned(lazy.ty);
1067710680 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;
10678 const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(pt.zcu)) {
10679 .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf,
10681 const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(zcu)) {
10682 .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(zcu)}) catch &prog_name_buf,
1068010683 .error_set => switch (lmr.kind) {
10681 .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf,
10684 .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(zcu)}) catch &prog_name_buf,
1068210685 .const_data => "@errorName(anyerror)",
1068310686 },
1068410687 else => unreachable,
......@@ -12143,8 +12146,8 @@ fn updateExportInner(
1214312146 switch (@"export".exported) {
1214412147 .nav => |nav| log.debug("updateExports({f})", .{ip.getNav(nav).fqn.fmt(ip)}),
1214512148 .uav => |uav| log.debug("updateExports(@as({f}, {f}))", .{
12146 Type.fromInterned(ip.typeOf(uav)).fmt(pt),
12147 Value.fromInterned(uav).fmtValue(pt),
12149 Type.fromInterned(ip.typeOf(uav)).fmt(zcu),
12150 Value.fromInterned(uav).fmtValue(zcu),
1214812151 }),
1214912152 }
1215012153 const exported_lsi: Symbol.LocalIndex = switch (@"export".exported) {
......@@ -12277,7 +12280,7 @@ pub fn printNode(
1227712280 const ip = &zcu.intern_pool;
1227812281 const nav = ip.getNav(nmi.nav(elf));
1227912282 try w.print("({f}, {f})", .{
12280 Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }),
12283 Type.fromInterned(nav.resolved.?.type).fmt(zcu),
1228112284 nav.fqn.fmt(ip),
1228212285 });
1228312286 },
......@@ -12285,15 +12288,12 @@ pub fn printNode(
1228512288 const zcu = elf.base.comp.zcu.?;
1228612289 const val: Value = .fromInterned(umi.uavValue(elf));
1228712290 try w.print("({f}, {f})", .{
12288 val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }),
12289 val.fmtValue(.{ .zcu = zcu, .tid = tid }),
12291 val.typeOf(zcu).fmt(zcu),
12292 val.fmtValue(zcu),
1229012293 });
1229112294 },
1229212295 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{
12293 Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(.{
12294 .zcu = elf.base.comp.zcu.?,
12295 .tid = tid,
12296 }),
12296 Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(elf.base.comp.zcu.?),
1229712297 }),
1229812298 .debug_shared => |ss| try w.print("({})", .{ss}),
1229912299 .unit_frame,
......@@ -12308,7 +12308,7 @@ pub fn printNode(
1230812308 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {
1230912309 .generic_poison_type => try w.writeAll("(anytype)"),
1231012310 else => |val| try w.print("({f})", .{
12311 Value.fromInterned(val).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
12311 Value.fromInterned(val).fmtValue(elf.base.comp.zcu.?),
1231212312 }),
1231312313 },
1231412314 .global_debug_info => |gi| {
......@@ -12317,11 +12317,11 @@ pub fn printNode(
1231712317 const nav = ip.getNav(gi.nav(&elf.dwarf));
1231812318 try w.writeByte('(');
1231912319 if (nav.resolved) |resolved| try w.print("{f}, ", .{
12320 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
12320 Type.fromInterned(resolved.type).fmt(zcu),
1232112321 });
1232212322 try w.print("{f}", .{nav.fqn.fmt(ip)});
1232312323 if (nav.resolved) |resolved| try w.print(", {f}", .{
12324 Value.fromInterned(resolved.value).fmtValue(.{ .zcu = zcu, .tid = tid }),
12324 Value.fromInterned(resolved.value).fmtValue(zcu),
1232512325 });
1232612326 try w.writeByte(')');
1232712327 },
......@@ -12331,7 +12331,7 @@ pub fn printNode(
1233112331 const nav = ip.getNav(fi.nav(&elf.dwarf));
1233212332 try w.writeByte('(');
1233312333 if (nav.resolved) |resolved| try w.print("{f}, ", .{
12334 Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }),
12334 Type.fromInterned(resolved.type).fmt(zcu),
1233512335 });
1233612336 try w.print("{f})", .{nav.fqn.fmt(ip)});
1233712337 },
src/link/MachO/ZigObject.zig+1-1
......@@ -1330,7 +1330,7 @@ fn updateLazySymbol(
13301330 const name_str = blk: {
13311331 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{
13321332 @tagName(lazy_sym.kind),
1333 Type.fromInterned(lazy_sym.ty).fmt(pt),
1333 Type.fromInterned(lazy_sym.ty).fmt(zcu),
13341334 });
13351335 defer gpa.free(name);
13361336 break :blk try self.addString(gpa, name);
src/print_value.zig+121-122
......@@ -10,28 +10,29 @@ const InternPool = @import("InternPool.zig");
1010const Allocator = std.mem.Allocator;
1111const Target = std.Target;
1212const Writer = std.Io.Writer;
13const assert = std.debug.assert;
1314
1415const max_aggregate_items = 100;
1516const max_string_len = 256;
1617
1718pub const FormatContext = struct {
1819 val: Value,
19 pt: Zcu.PerThread,
20 zcu: *Zcu,
2021 opt_sema: ?*Sema,
2122 depth: u8,
2223};
2324
2425pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {
2526 const sema = ctx.opt_sema.?;
26 return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) {
27 return print(ctx.val, writer, ctx.depth, ctx.zcu, sema) catch |err| switch (err) {
2728 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
2829 error.WriteFailed => |e| return e,
2930 };
3031}
3132
3233pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {
33 std.debug.assert(ctx.opt_sema == null);
34 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {
34 assert(ctx.opt_sema == null);
35 return print(ctx.val, writer, ctx.depth, ctx.zcu, null) catch |err| switch (err) {
3536 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
3637 error.WriteFailed => |e| return e,
3738 };
......@@ -41,10 +42,9 @@ pub fn print(
4142 val: Value,
4243 writer: *Writer,
4344 level: u8,
44 pt: Zcu.PerThread,
45 zcu: *Zcu,
4546 opt_sema: ?*Sema,
4647) (Writer.Error || Allocator.Error)!void {
47 const zcu = pt.zcu;
4848 const ip = &zcu.intern_pool;
4949 switch (ip.indexToKey(val.toIntern())) {
5050 .int_type,
......@@ -64,7 +64,7 @@ pub fn print(
6464 .func_type,
6565 .error_set_type,
6666 .inferred_error_set_type,
67 => try Type.print(val.toType(), writer, pt, null),
67 => try Type.print(val.toType(), writer, zcu, null),
6868 .undef => try writer.writeAll("undefined"),
6969 .simple_value => |simple_value| switch (simple_value) {
7070 .void => try writer.writeAll("{}"),
......@@ -88,7 +88,7 @@ pub fn print(
8888 .err_name => |err_name| try writer.print("error.{f}", .{
8989 err_name.fmt(ip),
9090 }),
91 .payload => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema),
91 .payload => |payload| try print(Value.fromInterned(payload), writer, level, zcu, opt_sema),
9292 },
9393 .enum_literal => |enum_literal| try writer.print(".{f}", .{
9494 enum_literal.fmt(ip),
......@@ -101,7 +101,7 @@ pub fn print(
101101 }
102102 try writer.writeAll("@fromBackingInt(");
103103 if (level == 0) return writer.writeAll("...)");
104 try print(.fromInterned(enum_tag.int), writer, level - 1, pt, opt_sema);
104 try print(.fromInterned(enum_tag.int), writer, level - 1, zcu, opt_sema);
105105 try writer.writeAll(")");
106106 },
107107 .float => |float| switch (float.storage) {
......@@ -112,7 +112,7 @@ pub fn print(
112112 if (slice.len == .zero_usize) {
113113 return writer.writeAll("&.{}");
114114 }
115 try print(.fromInterned(slice.ptr), writer, level, pt, opt_sema);
115 try print(.fromInterned(slice.ptr), writer, level, zcu, opt_sema);
116116 } else {
117117 const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) {
118118 .field, .arr_elem, .eu_payload, .opt_payload => unreachable,
......@@ -123,13 +123,13 @@ pub fn print(
123123 // TODO: eventually we want to load the slice as an array with `sema`, but that's
124124 // currently not possible without e.g. triggering compile errors.
125125 }
126 try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema);
126 try printPtr(Value.fromInterned(slice.ptr), null, writer, level, zcu, opt_sema);
127127 }
128128 try writer.writeAll("[0..");
129129 if (level == 0) {
130130 try writer.writeAll("(...)");
131131 } else {
132 try print(Value.fromInterned(slice.len), writer, level - 1, pt, opt_sema);
132 try print(Value.fromInterned(slice.len), writer, level - 1, zcu, opt_sema);
133133 }
134134 try writer.writeAll("]");
135135 },
......@@ -143,28 +143,28 @@ pub fn print(
143143 // TODO: eventually we want to load the pointer with `sema`, but that's
144144 // currently not possible without e.g. triggering compile errors.
145145 }
146 try printPtr(val, .rvalue, writer, level, pt, opt_sema);
146 try printPtr(val, .rvalue, writer, level, zcu, opt_sema);
147147 },
148148 .opt => |opt| switch (opt.val) {
149149 .none => try writer.writeAll("null"),
150 else => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema),
150 else => |payload| try print(Value.fromInterned(payload), writer, level, zcu, opt_sema),
151151 },
152 .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, pt, opt_sema),
152 .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, zcu, opt_sema),
153153 .un => |un| {
154154 if (level == 0) {
155155 try writer.writeAll(".{ ... }");
156156 return;
157157 }
158158 if (un.tag == .none) {
159 const backing_ty = try val.typeOf(zcu).externUnionBackingType(pt);
160 try writer.print("@bitCast(@as({f}, ", .{backing_ty.fmt(pt)});
161 try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema);
159 const backing_val: Value = .fromInterned(un.val);
160 try writer.print("@bitCast(@as({f}, ", .{backing_val.typeOf(zcu).fmt(zcu)});
161 try print(backing_val, writer, level - 1, zcu, opt_sema);
162162 try writer.writeAll("))");
163163 } else {
164164 try writer.writeAll(".{ ");
165 try print(Value.fromInterned(un.tag), writer, level - 1, pt, opt_sema);
165 try print(Value.fromInterned(un.tag), writer, level - 1, zcu, opt_sema);
166166 try writer.writeAll(" = ");
167 try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema);
167 try print(Value.fromInterned(un.val), writer, level - 1, zcu, opt_sema);
168168 try writer.writeAll(" }");
169169 }
170170 },
......@@ -173,35 +173,17 @@ pub fn print(
173173 return writer.writeAll(".{ ... }");
174174 }
175175 const ty: Type = .fromInterned(bitpack.ty);
176 switch (ty.zigTypeTag(zcu)) {
177 .@"struct" => {
178 if (ty.structFieldCount(zcu) == 0) {
179 return writer.writeAll(".{}");
180 }
181 try writer.writeAll(".{ ");
182 const max_len = @min(ty.structFieldCount(zcu), max_aggregate_items);
183 for (0..max_len) |i| {
184 if (i != 0) try writer.writeAll(", ");
185 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;
186 try writer.print(".{f} = ", .{field_name.fmt(ip)});
187 try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema);
188 }
189 try writer.writeAll(" }");
190 return;
176 switch (ty.backingIntMode(zcu)) {
177 .auto => {
178 try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(zcu)});
179 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema);
180 try writer.writeAll("))");
191181 },
192 .@"union" => switch (ty.backingIntMode(zcu)) {
193 .auto => {
194 try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(pt)});
195 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, pt, opt_sema);
196 try writer.writeAll("))");
197 },
198 .explicit => {
199 try writer.writeAll("@fromBackingInt(");
200 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, pt, opt_sema);
201 try writer.writeAll(")");
202 },
182 .explicit => {
183 try writer.writeAll("@fromBackingInt(");
184 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema);
185 try writer.writeAll(")");
203186 },
204 else => unreachable,
205187 }
206188 },
207189 .memoized_call => unreachable,
......@@ -214,14 +196,13 @@ fn printAggregate(
214196 is_ref: bool,
215197 writer: *Writer,
216198 level: u8,
217 pt: Zcu.PerThread,
199 zcu: *Zcu,
218200 opt_sema: ?*Sema,
219201) (Writer.Error || Allocator.Error)!void {
220202 if (level == 0) {
221203 if (is_ref) try writer.writeByte('&');
222204 return writer.writeAll(".{ ... }");
223205 }
224 const zcu = pt.zcu;
225206 const ip = &zcu.intern_pool;
226207 const ty = Type.fromInterned(aggregate.ty);
227208 switch (ty.zigTypeTag(zcu)) {
......@@ -236,7 +217,7 @@ fn printAggregate(
236217 if (i != 0) try writer.writeAll(", ");
237218 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;
238219 try writer.print(".{f} = ", .{field_name.fmt(ip)});
239 try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema);
220 try printFieldValue(val, i, writer, level - 1, zcu, opt_sema);
240221 }
241222 try writer.writeAll(" }");
242223 return;
......@@ -285,7 +266,7 @@ fn printAggregate(
285266 0 => try writer.writeAll(".{}"),
286267 1 => {
287268 try writer.writeAll(".{");
288 try print(try val.fieldValue(pt, 0), writer, level - 1, pt, opt_sema);
269 try printFieldValue(val, 0, writer, level - 1, zcu, opt_sema);
289270 try writer.writeByte('}');
290271 },
291272 else => {
......@@ -293,7 +274,7 @@ fn printAggregate(
293274 const max_len = @min(len, max_aggregate_items);
294275 for (0..max_len) |i| {
295276 if (i != 0) try writer.writeAll(", ");
296 try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema);
277 try printFieldValue(val, i, writer, level - 1, zcu, opt_sema);
297278 }
298279 if (len > max_aggregate_items) {
299280 try writer.writeAll(", ...");
......@@ -303,16 +284,40 @@ fn printAggregate(
303284 }
304285}
305286
287/// We cannot use `aggregate_val.fieldValue(...)` here because for some representations of aggregate
288/// values the individual field values may not yet be in the `InternPool`. So, this function is the
289/// equivalent of doing `print(try aggregate_val.fieldValue(...))`, which understands the optimized
290/// value representations so does not need to intern new values.
291fn printFieldValue(
292 aggregate_val: Value,
293 field_index: usize,
294 writer: *Writer,
295 level: u8,
296 zcu: *Zcu,
297 opt_sema: ?*Sema,
298) (Writer.Error || Allocator.Error)!void {
299 const ip = &zcu.intern_pool;
300 switch (ip.indexToKey(aggregate_val.toIntern())) {
301 .undef => try writer.writeAll("undefined"),
302 .aggregate => |aggregate| switch (aggregate.storage) {
303 .bytes => |bytes| try writer.print("{d}", .{bytes.at(field_index, ip)}),
304 .elems => |elems| try print(.fromInterned(elems[field_index]), writer, level, zcu, opt_sema),
305 .repeated_elem => |elem| try print(.fromInterned(elem), writer, level, zcu, opt_sema),
306 },
307 else => unreachable,
308 }
309}
310
306311fn printPtr(
307312 ptr_val: Value,
308313 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
309314 want_kind: ?PrintPtrKind,
310315 writer: *Writer,
311316 level: u8,
312 pt: Zcu.PerThread,
317 zcu: *Zcu,
313318 opt_sema: ?*Sema,
314319) (Writer.Error || Allocator.Error)!void {
315 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
320 const ptr = switch (zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
316321 .undef => return writer.writeAll("undefined"),
317322 .ptr => |ptr| ptr,
318323 else => unreachable,
......@@ -320,25 +325,25 @@ fn printPtr(
320325
321326 if (ptr.base_addr == .uav) {
322327 // If the value is an aggregate, we can potentially print it more nicely.
323 switch (pt.zcu.intern_pool.indexToKey(ptr.base_addr.uav.val)) {
328 switch (zcu.intern_pool.indexToKey(ptr.base_addr.uav.val)) {
324329 .aggregate => |agg| return printAggregate(
325330 Value.fromInterned(ptr.base_addr.uav.val),
326331 agg,
327332 true,
328333 writer,
329334 level,
330 pt,
335 zcu,
331336 opt_sema,
332337 ),
333338 else => {},
334339 }
335340 }
336341
337 var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa);
342 var arena = std.heap.ArenaAllocator.init(zcu.gpa);
338343 defer arena.deinit();
339 const derivation = try ptr_val.pointerDerivation(arena.allocator(), pt, opt_sema);
344 const derivation = try ptr_val.pointerDerivation(arena.allocator(), zcu, opt_sema);
340345
341 _ = try printPtrDerivation(derivation, writer, pt, want_kind, .{ .print_val = .{
346 _ = try printPtrDerivation(derivation, writer, zcu, want_kind, .{ .print_val = .{
342347 .level = level,
343348 .opt_sema = opt_sema,
344349 } }, 20);
......@@ -349,9 +354,9 @@ const PrintPtrKind = enum { lvalue, rvalue };
349354/// Print the pointer defined by `derivation` as an lvalue or an rvalue.
350355/// Returns the root derivation, which may be ignored.
351356pub fn printPtrDerivation(
352 derivation: Value.PointerDeriveStep,
357 derivation: Value.PointerDerivation,
353358 writer: *Writer,
354 pt: Zcu.PerThread,
359 zcu: *Zcu,
355360 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
356361 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as
357362 /// an atom -- e.g. `&foo.*` is distinct from `(&foo).*`.
......@@ -368,33 +373,36 @@ pub fn printPtrDerivation(
368373 /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary,
369374 /// so at this depth we just write "..." to prevent stack overflow.
370375 ptr_depth: u8,
371) !Value.PointerDeriveStep {
372 const zcu = pt.zcu;
376) !Value.PointerDerivation {
373377 const ip = &zcu.intern_pool;
374378
375379 if (ptr_depth == 0) {
376 const root_step = root: switch (derivation) {
377 inline .eu_payload_ptr,
378 .opt_payload_ptr,
379 .field_ptr,
380 .elem_ptr,
381 .offset_and_cast,
382 => |step| continue :root step.parent.*,
383 else => |step| break :root step,
384 };
380 var root_step = derivation;
381 while (true) {
382 switch (derivation.addr) {
383 inline .eu_payload,
384 .opt_payload,
385 .field,
386 .elem,
387 .offset_and_cast,
388 => |derived| root_step = derived.parent.*,
389
390 .int, .nav, .uav, .comptime_alloc, .comptime_field => break,
391 }
392 }
385393 try writer.writeAll("...");
386394 return root_step;
387395 }
388396
389 const result_kind: PrintPtrKind = switch (derivation) {
390 .nav_ptr,
391 .uav_ptr,
392 .comptime_alloc_ptr,
393 .comptime_field_ptr,
394 .eu_payload_ptr,
395 .opt_payload_ptr,
396 .field_ptr,
397 .elem_ptr,
397 const result_kind: PrintPtrKind = switch (derivation.addr) {
398 .nav,
399 .uav,
400 .comptime_alloc,
401 .comptime_field,
402 .eu_payload,
403 .opt_payload,
404 .field,
405 .elem,
398406 => .lvalue,
399407
400408 .offset_and_cast,
......@@ -409,33 +417,33 @@ pub fn printPtrDerivation(
409417 }
410418
411419 // null if `derivation` is the root.
412 const root_or_null: ?Value.PointerDeriveStep = switch (derivation) {
413 .eu_payload_ptr => |info| root: {
420 const root_or_null: ?Value.PointerDerivation = switch (derivation.addr) {
421 .eu_payload => |info| root: {
414422 try writer.writeByte('(');
415 const root = try printPtrDerivation(info.parent.*, writer, pt, .lvalue, root_strat, ptr_depth - 1);
423 const root = try printPtrDerivation(info.parent.*, writer, zcu, .lvalue, root_strat, ptr_depth - 1);
416424 try writer.writeAll(" catch unreachable)");
417425 break :root root;
418426 },
419 .opt_payload_ptr => |info| root: {
420 const root = try printPtrDerivation(info.parent.*, writer, pt, .lvalue, root_strat, ptr_depth - 1);
427 .opt_payload => |info| root: {
428 const root = try printPtrDerivation(info.parent.*, writer, zcu, .lvalue, root_strat, ptr_depth - 1);
421429 try writer.writeAll(".?");
422430 break :root root;
423431 },
424 .field_ptr => |field| root: {
425 const root = try printPtrDerivation(field.parent.*, writer, pt, null, root_strat, ptr_depth - 1);
426 const agg_ty = (try field.parent.ptrType(pt)).childType(zcu);
432 .field => |derived| root: {
433 const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1);
434 const agg_ty = derived.parent.elem_ty;
427435 switch (agg_ty.zigTypeTag(zcu)) {
428 .@"struct" => if (agg_ty.structFieldName(field.field_idx, zcu).unwrap()) |field_name| {
436 .@"struct" => if (agg_ty.structFieldName(derived.field_index, zcu).unwrap()) |field_name| {
429437 try writer.print(".{f}", .{field_name.fmt(ip)});
430438 } else {
431 try writer.print("[{d}]", .{field.field_idx});
439 try writer.print("[{d}]", .{derived.field_index});
432440 },
433441 .@"union" => {
434442 const tag_ty = agg_ty.unionTagTypeHypothetical(zcu);
435 const field_name = tag_ty.enumFieldName(field.field_idx, zcu);
443 const field_name = tag_ty.enumFieldName(derived.field_index, zcu);
436444 try writer.print(".{f}", .{field_name.fmt(ip)});
437445 },
438 .pointer => switch (field.field_idx) {
446 .pointer => switch (derived.field_index) {
439447 Value.slice_ptr_index => try writer.writeAll(".ptr"),
440448 Value.slice_len_index => try writer.writeAll(".len"),
441449 else => unreachable,
......@@ -444,58 +452,49 @@ pub fn printPtrDerivation(
444452 }
445453 break :root root;
446454 },
447 .elem_ptr => |elem| root: {
448 const root = try printPtrDerivation(elem.parent.*, writer, pt, null, root_strat, ptr_depth - 1);
449 try writer.print("[{d}]", .{elem.elem_idx});
455 .elem => |derived| root: {
456 const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1);
457 try writer.print("[{d}]", .{derived.elem_index});
450458 break :root root;
451459 },
452460
453 .offset_and_cast => |oac| if (oac.byte_offset == 0) root: {
454 try writer.print("@as({f}, @ptrCast(", .{oac.new_ptr_ty.fmt(pt)});
455 const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1);
461 .offset_and_cast => |derived| if (derived.byte_offset == 0) root: {
462 try writer.print("@as({f}, @ptrCast(", .{derivation.fmtType(zcu)});
463 const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1);
456464 try writer.writeAll("))");
457465 break :root root;
458466 } else root: {
459 try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{oac.new_ptr_ty.fmt(pt)});
460 const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1);
461 try writer.print(") + {d}))", .{oac.byte_offset});
467 try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{derivation.fmtType(zcu)});
468 const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1);
469 try writer.print(") + {d}))", .{derived.byte_offset});
462470 break :root root;
463471 },
464472
465 .int, .nav_ptr, .uav_ptr, .comptime_alloc_ptr, .comptime_field_ptr => null,
473 .int, .nav, .uav, .comptime_alloc, .comptime_field => null,
466474 };
467475
468476 if (root_or_null == null) switch (root_strat) {
469477 .str => |x| try writer.writeAll(x),
470 .print_val => |x| switch (derivation) {
471 .int => |int| try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ int.ptr_ty.fmt(pt), int.addr }),
472 .nav_ptr => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}),
473 .uav_ptr => |uav| {
474 const ty = Value.fromInterned(uav.val).typeOf(zcu);
475 try writer.print("@as({f}, ", .{ty.fmt(pt)});
476 if (x.level == 0) {
477 try writer.writeAll("...");
478 } else {
479 try print(Value.fromInterned(uav.val), writer, x.level - 1, pt, x.opt_sema);
480 }
481 try writer.writeByte(')');
478 .print_val => |x| switch (derivation.addr) {
479 .int => |int| {
480 try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ derivation.fmtType(zcu), int });
482481 },
483 .comptime_alloc_ptr => |info| {
484 try writer.print("@as({f}, ", .{info.val.typeOf(zcu).fmt(pt)});
482 .nav => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}),
483 .uav, .comptime_field => |val| {
484 try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)});
485485 if (x.level == 0) {
486486 try writer.writeAll("...");
487487 } else {
488 try print(info.val, writer, x.level - 1, pt, x.opt_sema);
488 try print(val, writer, x.level - 1, zcu, x.opt_sema);
489489 }
490490 try writer.writeByte(')');
491491 },
492 .comptime_field_ptr => |val| {
493 const ty = val.typeOf(zcu);
494 try writer.print("@as({f}, ", .{ty.fmt(pt)});
492 .comptime_alloc => |info| {
493 try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)});
495494 if (x.level == 0) {
496495 try writer.writeAll("...");
497496 } else {
498 try print(val, writer, x.level - 1, pt, x.opt_sema);
497 try print(info.val, writer, x.level - 1, zcu, x.opt_sema);
499498 }
500499 try writer.writeByte(')');
501500 },