authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-09-26 17:43:41+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-09-29 10:32:05-07:00
logebb8683ef1298e5d45f8d9912cf161954cc7ca99
tree8db2839f3e22229c081383805cbab888a4ab9fdd
parentac77c23aff39272f99369c247ded29d960122ecd
signature Commit is signed but in an unrecognized format.

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 },
......@@ -1900,7 +1901,7 @@ fn analyzeBodyInner(
19001901 const err_union_ty = sema.typeOf(err_union);
19011902 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
19021903 return sema.failWithOwnedErrorMsg(block, msg: {
1903 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
1904 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
19041905 errdefer msg.destroy(gpa);
19051906 try sema.addDeclaredHereNote(msg, err_union_ty);
19061907 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -2365,7 +2366,7 @@ pub fn failWithTooLargeShiftAmount(
23652366 const msg = try sema.errMsg(
23662367 shift_src,
23672368 "shift amount '{f}' is too large for operand type '{f}'",
2368 .{ shift_amt.fmtValueSema(sema.pt, sema), operand_ty.fmt(sema.pt) },
2369 .{ shift_amt.fmtValueSema(sema), operand_ty.fmt(sema.pt.zcu) },
23692370 );
23702371 errdefer msg.destroy(sema.gpa);
23712372 if (vector_index) |i| try sema.errNote(shift_src, msg, "when computing vector element at index '{d}'", .{i});
......@@ -2375,7 +2376,7 @@ pub fn failWithTooLargeShiftAmount(
23752376
23762377pub fn failWithNegativeShiftAmount(sema: *Sema, block: *Block, src: LazySrcLoc, shift_amt: Value, vector_index: ?usize) CompileError {
23772378 return sema.failWithOwnedErrorMsg(block, msg: {
2378 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema.pt, sema)});
2379 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema)});
23792380 errdefer msg.destroy(sema.gpa);
23802381 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
23812382 break :msg msg;
......@@ -2396,9 +2397,9 @@ pub fn failWithUnsupportedComptimeShiftAmount(sema: *Sema, block: *Block, src: L
23962397}
23972398
23982399fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
2399 const pt = sema.pt;
2400 const zcu = sema.pt.zcu;
24002401 return sema.fail(block, src, "remainder division with '{f}' and '{f}': signed integers and floats must use @rem or @mod", .{
2401 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
2402 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
24022403 });
24032404}
24042405
......@@ -2420,7 +2421,7 @@ fn failWithInvalidSwitchTagCapture(sema: *Sema, block: *Block, tag_capture_src:
24202421 }
24212422 return sema.failWithOwnedErrorMsg(block, msg: {
24222423 const msg = try sema.errMsg(tag_capture_src, "cannot capture tag of non-union type '{f}'", .{
2423 operand_ty.fmt(pt),
2424 operand_ty.fmt(zcu),
24242425 });
24252426 errdefer msg.destroy(sema.gpa);
24262427 try sema.addDeclaredHereNote(msg, operand_ty);
......@@ -2439,7 +2440,7 @@ fn failWithAmbiguousBackingIntType(
24392440 const zcu = pt.zcu;
24402441 return sema.failWithOwnedErrorMsg(block, msg: {
24412442 const msg = try sema.errMsg(src, "{s} is ambiguous for type '{f}'", .{
2442 builtin_name, int_backed_ty.fmt(pt),
2443 builtin_name, int_backed_ty.fmt(zcu),
24432444 });
24442445 errdefer msg.destroy(sema.gpa);
24452446 try sema.errNote(int_backed_ty.srcLoc(zcu), msg, "backing integer type of {t} is inferred", .{
......@@ -2451,13 +2452,13 @@ fn failWithAmbiguousBackingIntType(
24512452}
24522453
24532454fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
2454 const pt = sema.pt;
2455 const zcu = sema.pt.zcu;
24552456 const msg = msg: {
24562457 const msg = try sema.errMsg(src, "expected optional type, found '{f}'", .{
2457 non_optional_ty.fmt(pt),
2458 non_optional_ty.fmt(zcu),
24582459 });
24592460 errdefer msg.destroy(sema.gpa);
2460 if (non_optional_ty.zigTypeTag(pt.zcu) == .error_union) {
2461 if (non_optional_ty.zigTypeTag(zcu) == .error_union) {
24612462 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
24622463 }
24632464 try addDeclaredHereNote(sema, msg, non_optional_ty);
......@@ -2467,15 +2468,14 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
24672468}
24682469
24692470fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2470 const pt = sema.pt;
2471 const zcu = pt.zcu;
2471 const zcu = sema.pt.zcu;
24722472 const msg = msg: {
24732473 const msg = try sema.errMsg(src, "type '{f}' does not support array initialization syntax", .{
2474 ty.fmt(pt),
2474 ty.fmt(zcu),
24752475 });
24762476 errdefer msg.destroy(sema.gpa);
24772477 if (ty.isSlice(zcu)) {
2478 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(pt)});
2478 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(zcu)});
24792479 }
24802480 break :msg msg;
24812481 };
......@@ -2483,17 +2483,17 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
24832483}
24842484
24852485fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2486 const pt = sema.pt;
2486 const zcu = sema.pt.zcu;
24872487 return sema.fail(block, src, "type '{f}' does not support struct initialization syntax", .{
2488 ty.fmt(pt),
2488 ty.fmt(zcu),
24892489 });
24902490}
24912491
24922492pub fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: Type, val: Value, vector_index: ?usize) CompileError {
2493 const pt = sema.pt;
2493 const zcu = sema.pt.zcu;
24942494 return sema.failWithOwnedErrorMsg(block, msg: {
24952495 const msg = try sema.errMsg(src, "overflow of integer type '{f}' with value '{f}'", .{
2496 int_ty.fmt(pt), val.fmtValueSema(pt, sema),
2496 int_ty.fmt(zcu), val.fmtValueSema(sema),
24972497 });
24982498 errdefer msg.destroy(sema.gpa);
24992499 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
......@@ -2542,7 +2542,7 @@ fn failWithInvalidFieldAccess(
25422542 const child_ty = inner_ty.optionalChild(zcu);
25432543 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;
25442544 const msg = msg: {
2545 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(pt)});
2545 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25462546 errdefer msg.destroy(sema.gpa);
25472547 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
25482548 break :msg msg;
......@@ -2552,14 +2552,14 @@ fn failWithInvalidFieldAccess(
25522552 const child_ty = inner_ty.errorUnionPayload(zcu);
25532553 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;
25542554 const msg = msg: {
2555 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(pt)});
2555 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25562556 errdefer msg.destroy(sema.gpa);
25572557 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
25582558 break :msg msg;
25592559 };
25602560 return sema.failWithOwnedErrorMsg(block, msg);
25612561 }
2562 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(pt)});
2562 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(zcu)});
25632563}
25642564
25652565fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {
......@@ -2649,20 +2649,20 @@ pub fn errMsg(
26492649}
26502650
26512651fn typeMismatchErrMsg(sema: *Sema, src: LazySrcLoc, expected: Type, found: Type) Allocator.Error!*Zcu.ErrorMsg {
2652 const pt = sema.pt;
2653 var cmp: Type.Comparison = try .init(&.{ expected, found }, pt);
2654 defer cmp.deinit(pt);
2652 const zcu = sema.pt.zcu;
2653 var cmp: Type.Comparison = try .init(&.{ expected, found }, zcu);
2654 defer cmp.deinit(zcu.comp.gpa);
26552655
26562656 const msg = try sema.errMsg(src, "expected type '{f}', found '{f}'", .{
2657 cmp.fmtType(expected, pt),
2658 cmp.fmtType(found, pt),
2657 cmp.fmtType(expected, zcu),
2658 cmp.fmtType(found, zcu),
26592659 });
26602660 errdefer msg.destroy(sema.gpa);
26612661
26622662 for (cmp.type_dedupe_cache.keys(), cmp.type_dedupe_cache.values()) |ty, value| {
26632663 if (value == .dont_dedupe) continue;
26642664 const placeholder = value.dedupe;
2665 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(pt) });
2665 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(zcu) });
26662666 }
26672667
26682668 return msg;
......@@ -2678,7 +2678,7 @@ pub fn fail(
26782678 const err_msg = try sema.errMsg(src, format, args);
26792679 inline for (args) |arg| {
26802680 if (@TypeOf(arg) == Type.Formatter) {
2681 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
2681 try addDeclaredHereNote(sema, err_msg, arg.ty);
26822682 }
26832683 }
26842684 return sema.failWithOwnedErrorMsg(block, err_msg);
......@@ -3152,11 +3152,11 @@ fn validateDeref(
31523152 const zcu = pt.zcu;
31533153 const ip = &zcu.intern_pool;
31543154 if (ty.zigTypeTag(zcu) != .pointer) {
3155 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(pt)});
3155 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(zcu)});
31563156 }
31573157 const size = ty.ptrSize(zcu);
31583158 switch (size) {
3159 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(pt)}),
3159 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(zcu)}),
31603160 .one, .c, .slice => {},
31613161 }
31623162 if (sema.resolveValue(ref)) |val| {
......@@ -3192,11 +3192,11 @@ fn ensureResultUsed(
31923192 switch (ty.zigTypeTag(zcu)) {
31933193 .void, .noreturn => return,
31943194 .error_set => {
3195 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(pt)});
3195 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(zcu)});
31963196 },
31973197 .error_union => {
31983198 const msg = msg: {
3199 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(pt)});
3199 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(zcu)});
32003200 errdefer msg.destroy(sema.gpa);
32013201 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
32023202 break :msg msg;
......@@ -3205,7 +3205,7 @@ fn ensureResultUsed(
32053205 },
32063206 else => {
32073207 const msg = msg: {
3208 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(pt)});
3208 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(zcu)});
32093209 errdefer msg.destroy(sema.gpa);
32103210 try sema.errNote(src, msg, "all non-void values must be used", .{});
32113211 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
......@@ -3467,7 +3467,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
34673467 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
34683468 // TODO: source location of runtime control flow
34693469 const init_src = block.src(.{ .node_offset_var_decl_init = inst_data.src_node });
3470 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(pt)});
3470 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(zcu)});
34713471 }
34723472
34733473 // This is a runtime value.
......@@ -3988,7 +3988,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39883988 // The alloc wasn't comptime-known per the above logic, so the
39893989 // type cannot be comptime-only.
39903990 // TODO: source location of runtime control flow
3991 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});
3991 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(zcu)});
39923992 }
39933993 if (sema.func_is_naked and final_elem_ty.hasRuntimeBits(zcu)) {
39943994 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
......@@ -4088,7 +4088,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
40884088 if (!object_ty.isIndexable(zcu)) {
40894089 // Instead of using checkIndexable we customize this error.
40904090 const msg = msg: {
4091 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(pt)});
4091 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(zcu)});
40924092 errdefer msg.destroy(sema.gpa);
40934093 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
40944094
......@@ -4127,10 +4127,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41274127 .input_index = len_idx,
41284128 } });
41294129 try sema.errNote(a_src, msg, "length {f} here", .{
4130 v.fmtValueSema(pt, sema),
4130 v.fmtValueSema(sema),
41314131 });
41324132 try sema.errNote(arg_src, msg, "length {f} here", .{
4133 arg_val.fmtValueSema(pt, sema),
4133 arg_val.fmtValueSema(sema),
41344134 });
41354135 break :msg msg;
41364136 };
......@@ -4162,7 +4162,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
41624162 .input_index = i,
41634163 } });
41644164 try sema.errNote(arg_src, msg, "type '{f}' has no upper bound", .{
4165 object_ty.fmt(pt),
4165 object_ty.fmt(zcu),
41664166 });
41674167 }
41684168 break :msg msg;
......@@ -4247,7 +4247,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
42474247 switch (val_ty.zigTypeTag(zcu)) {
42484248 .array, .vector => {},
42494249 else => if (!val_ty.isTuple(zcu)) {
4250 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });
4250 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(zcu), val_ty.fmt(zcu) });
42514251 },
42524252 }
42534253 const want_ty = try pt.arrayType(.{
......@@ -4325,7 +4325,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
43254325 const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return;
43264326 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) {
43274327 return sema.failWithOwnedErrorMsg(block, msg: {
4328 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(pt)});
4328 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(zcu)});
43294329 errdefer msg.destroy(sema.gpa);
43304330 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
43314331 break :msg msg;
......@@ -4711,7 +4711,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
47114711
47124712 if (!operand_ty.destructurable(zcu)) {
47134713 return sema.failWithOwnedErrorMsg(block, msg: {
4714 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(pt)});
4714 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(zcu)});
47154715 errdefer msg.destroy(sema.gpa);
47164716 try sema.errNote(destructure_src, msg, "result destructured here", .{});
47174717 if (operand_ty.zigTypeTag(pt.zcu) == .error_union) {
......@@ -4756,13 +4756,13 @@ fn failWithBadMemberAccess(
47564756 const inst_index = inst.resolve(ip) orelse return sema.failTransitive(.{ .lost_tracking = inst });
47574757 if (inst_index == .main_struct_inst) {
47584758 return sema.fail(block, field_src, "root source file struct '{f}' has no member named '{f}'", .{
4759 agg_ty.fmt(pt), field_name.fmt(ip),
4759 agg_ty.fmt(zcu), field_name.fmt(ip),
47604760 });
47614761 }
47624762 }
47634763
47644764 return sema.fail(block, field_src, "{s} '{f}' has no member named '{f}'", .{
4765 kw_name, agg_ty.fmt(pt), field_name.fmt(ip),
4765 kw_name, agg_ty.fmt(zcu), field_name.fmt(ip),
47664766 });
47674767}
47684768
......@@ -5059,10 +5059,10 @@ fn zirCompileLog(
50595059 const arg_ty = sema.typeOf(arg);
50605060 if (sema.resolveValue(arg)) |val| {
50615061 writer.print("@as({f}, {f})", .{
5062 arg_ty.fmt(pt), val.fmtValueSema(pt, sema),
5062 arg_ty.fmt(zcu), val.fmtValueSema(sema),
50635063 }) catch return error.OutOfMemory;
50645064 } else {
5065 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch return error.OutOfMemory;
5065 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(zcu)}) catch return error.OutOfMemory;
50665066 }
50675067 }
50685068
......@@ -5503,7 +5503,7 @@ fn resolveAnalyzedBlock(
55035503 const type_src = src; // TODO: better source location
55045504 if (resolved_ty.comptimeOnly(zcu)) {
55055505 const msg = msg: {
5506 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(pt)});
5506 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(zcu)});
55075507 errdefer msg.destroy(sema.gpa);
55085508
55095509 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
......@@ -5617,7 +5617,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
56175617
56185618 {
56195619 if (ptr_ty.zigTypeTag(zcu) != .pointer) {
5620 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(pt)});
5620 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(zcu)});
56215621 }
56225622 const ptr_ty_info = ptr_ty.ptrInfo(zcu);
56235623 if (ptr_ty_info.flags.size == .slice) {
......@@ -5632,7 +5632,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
56325632 try sema.ensureLayoutResolved(export_ty, src, .@"export");
56335633 if (!export_ty.validateExtern(.other, zcu)) {
56345634 return sema.failWithOwnedErrorMsg(block, msg: {
5635 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});
5635 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
56365636 errdefer msg.destroy(sema.gpa);
56375637 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
56385638 try sema.addDeclaredHereNote(msg, export_ty);
......@@ -5689,7 +5689,7 @@ pub fn analyzeExportSelfNav(
56895689
56905690 if (!export_ty.validateExtern(.other, zcu)) {
56915691 return sema.failWithOwnedErrorMsg(block, msg: {
5692 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});
5692 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
56935693 errdefer msg.destroy(gpa);
56945694 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
56955695 try sema.addDeclaredHereNote(msg, export_ty);
......@@ -6327,7 +6327,7 @@ fn checkCallArgumentCount(
63276327 {
63286328 const msg = msg: {
63296329 const msg = try sema.errMsg(func_src, "cannot call optional type '{f}'", .{
6330 callee_ty.fmt(pt),
6330 callee_ty.fmt(zcu),
63316331 });
63326332 errdefer msg.destroy(sema.gpa);
63336333 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
......@@ -6338,7 +6338,7 @@ fn checkCallArgumentCount(
63386338 },
63396339 else => {},
63406340 }
6341 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(pt)});
6341 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(zcu)});
63426342 };
63436343
63446344 const func_ty_info = zcu.typeToFunc(func_ty).?;
......@@ -6401,7 +6401,7 @@ fn callBuiltin(
64016401 },
64026402 else => {},
64036403 }
6404 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});
6404 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(zcu)});
64056405 };
64066406
64076407 const func_ty_info = zcu.typeToFunc(func_ty).?;
......@@ -6827,7 +6827,7 @@ fn analyzeCall(
68276827 if (!param_ty.isValidParamType(zcu)) {
68286828 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
68296829 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
6830 opaque_str, param_ty.fmt(pt),
6830 opaque_str, param_ty.fmt(zcu),
68316831 });
68326832 }
68336833
......@@ -6931,7 +6931,7 @@ fn analyzeCall(
69316931 if (!full_ty.isValidReturnType(zcu)) {
69326932 const opaque_str = if (full_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
69336933 return sema.fail(block, func_ret_ty_src, "{s}return type '{f}' not allowed", .{
6934 opaque_str, full_ty.fmt(pt),
6934 opaque_str, full_ty.fmt(zcu),
69356935 });
69366936 }
69376937
......@@ -7431,7 +7431,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
74317431 const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);
74327432 if (owner_func_ty.toIntern() != func_ty.toIntern()) {
74337433 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}'", .{
7434 func_ty.fmt(pt), owner_func_ty.fmt(pt),
7434 func_ty.fmt(zcu), owner_func_ty.fmt(zcu),
74357435 });
74367436 }
74377437 _ = try block.addUnOp(.ret, result);
......@@ -7451,9 +7451,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
74517451 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
74527452 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
74537453 if (child_type.zigTypeTag(zcu) == .@"opaque") {
7454 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(pt)});
7454 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(zcu)});
74557455 } else if (child_type.zigTypeTag(zcu) == .null) {
7456 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(pt)});
7456 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(zcu)});
74577457 }
74587458 const opt_type = try pt.optionalType(child_type.toIntern());
74597459
......@@ -7514,7 +7514,7 @@ fn zirSplatOpResultType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
75147514
75157515 switch (vec_ty.zigTypeTag(zcu)) {
75167516 .array, .vector => {},
7517 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(pt)}),
7517 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(zcu)}),
75187518 }
75197519 return Air.internedToRef(vec_ty.childType(zcu).toIntern());
75207520}
......@@ -7587,7 +7587,7 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src:
75877587 const pt = sema.pt;
75887588 const zcu = pt.zcu;
75897589 if (elem_type.zigTypeTag(zcu) == .@"opaque") {
7590 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(pt)});
7590 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(zcu)});
75917591 } else if (elem_type.zigTypeTag(zcu) == .noreturn) {
75927592 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
75937593 }
......@@ -7618,7 +7618,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
76187618
76197619 if (error_set.zigTypeTag(zcu) != .error_set) {
76207620 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{
7621 error_set.fmt(pt),
7621 error_set.fmt(zcu),
76227622 });
76237623 }
76247624 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);
......@@ -7631,11 +7631,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
76317631 const zcu = pt.zcu;
76327632 if (payload_ty.zigTypeTag(zcu) == .@"opaque") {
76337633 return sema.fail(block, payload_src, "error union with payload of opaque type '{f}' not allowed", .{
7634 payload_ty.fmt(pt),
7634 payload_ty.fmt(zcu),
76357635 });
76367636 } else if (payload_ty.zigTypeTag(zcu) == .error_set) {
76377637 return sema.fail(block, payload_src, "error union with payload of error set type '{f}' not allowed", .{
7638 payload_ty.fmt(pt),
7638 payload_ty.fmt(zcu),
76397639 });
76407640 }
76417641}
......@@ -7766,9 +7766,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
77667766 const lhs_ty = try sema.analyzeAsType(block, lhs_src, .type, lhs);
77677767 const rhs_ty = try sema.analyzeAsType(block, rhs_src, .type, rhs);
77687768 if (lhs_ty.zigTypeTag(zcu) != .error_set)
7769 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(pt)});
7769 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(zcu)});
77707770 if (rhs_ty.zigTypeTag(zcu) != .error_set)
7771 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(pt)});
7771 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(zcu)});
77727772
77737773 // Anything merged with anyerror is anyerror.
77747774 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
......@@ -7894,7 +7894,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
78947894 block,
78957895 operand_src,
78967896 "untagged union '{f}' cannot be converted to integer",
7897 .{operand_ty.fmt(pt)},
7897 .{operand_ty.fmt(zcu)},
78987898 );
78997899 }
79007900
......@@ -7902,7 +7902,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79027902 },
79037903 else => {
79047904 return sema.fail(block, operand_src, "expected enum or tagged union, found '{f}'", .{
7905 operand_ty.fmt(pt),
7905 operand_ty.fmt(zcu),
79067906 });
79077907 },
79087908 };
......@@ -7931,7 +7931,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79317931 const operand_ty = sema.typeOf(operand);
79327932
79337933 if (dest_ty.zigTypeTag(zcu) != .@"enum") {
7934 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(pt)});
7934 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(zcu)});
79357935 }
79367936 try sema.ensureLayoutResolved(dest_ty, src, .init);
79377937 _ = try sema.checkIntType(block, operand_src, operand_ty);
......@@ -7943,7 +7943,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79437943 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
79447944 }
79457945 return sema.fail(block, src, "int value '{f}' out of range of non-exhaustive enum '{f}'", .{
7946 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),
7946 int_val.fmtValueSema(sema), dest_ty.fmt(zcu),
79477947 });
79487948 }
79497949 if (int_val.isUndef(zcu)) {
......@@ -7951,7 +7951,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
79517951 }
79527952 if (!(try sema.enumHasInt(dest_ty, int_val))) {
79537953 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
7954 dest_ty.fmt(pt), int_val.fmtValueSema(pt, sema),
7954 dest_ty.fmt(zcu), int_val.fmtValueSema(sema),
79557955 });
79567956 }
79577957 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
......@@ -8129,7 +8129,7 @@ fn zirErrUnionPayload(
81298129 const err_union_ty = sema.typeOf(operand);
81308130 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
81318131 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
8132 err_union_ty.fmt(pt),
8132 err_union_ty.fmt(zcu),
81338133 });
81348134 }
81358135 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);
......@@ -8203,7 +8203,7 @@ fn analyzeErrUnionPayloadPtr(
82038203
82048204 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
82058205 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8206 operand_ty.childType(zcu).fmt(pt),
8206 operand_ty.childType(zcu).fmt(zcu),
82078207 });
82088208 }
82098209
......@@ -8278,7 +8278,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
82788278 const operand_ty = sema.typeOf(operand);
82798279 if (operand_ty.zigTypeTag(zcu) != .error_union) {
82808280 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8281 operand_ty.fmt(pt),
8281 operand_ty.fmt(zcu),
82828282 });
82838283 }
82848284
......@@ -8312,7 +8312,7 @@ fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand:
83128312
83138313 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
83148314 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8315 operand_ty.childType(zcu).fmt(pt),
8315 operand_ty.childType(zcu).fmt(zcu),
83168316 });
83178317 }
83188318
......@@ -8640,7 +8640,7 @@ fn checkParamType(
86408640 if (!param_ty.isValidParamType(zcu)) {
86418641 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
86428642 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
8643 opaque_str, param_ty.fmt(pt),
8643 opaque_str, param_ty.fmt(zcu),
86448644 });
86458645 }
86468646 if (!target_util.fnCallConvAllowsZigTypes(cc)) {
......@@ -8721,12 +8721,12 @@ fn checkReturnTypeAndCallConv(
87218721 if (!bare_ret_ty.isValidReturnType(zcu)) {
87228722 const opaque_str = if (bare_ret_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
87238723 return sema.fail(block, ret_ty_src, "{s}return type '{s}{f}' not allowed", .{
8724 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(pt),
8724 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(zcu),
87258725 });
87268726 }
87278727 if (!target_util.fnCallConvAllowsZigTypes(@"callconv")) {
87288728 if (inferred_error_set) {
8729 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(pt), @"callconv" });
8729 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(zcu), @"callconv" });
87308730 }
87318731 if (bare_ret_ty.isGenericPoison()) {
87328732 return sema.fail(block, ret_ty_src, "generic return type not allowed in function with calling convention '{t}'", .{@"callconv"});
......@@ -8858,7 +8858,7 @@ fn validateResolvedFuncType(
88588858 } else src;
88598859 return sema.failWithOwnedErrorMsg(block, msg: {
88608860 const msg = try sema.errMsg(param_src, "parameter of type '{f}' not allowed in function with calling convention '{t}'", .{
8861 param_ty.fmt(pt), @"callconv",
8861 param_ty.fmt(zcu), @"callconv",
88628862 });
88638863 errdefer msg.destroy(gpa);
88648864 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
......@@ -8875,7 +8875,7 @@ fn validateResolvedFuncType(
88758875 } else src;
88768876 return sema.failWithOwnedErrorMsg(block, msg: {
88778877 const msg = try sema.errMsg(ret_ty_src, "return type '{f}' not allowed in function with calling convention '{t}'", .{
8878 ret_ty.fmt(pt), @"callconv",
8878 ret_ty.fmt(zcu), @"callconv",
88798879 });
88808880 errdefer msg.destroy(gpa);
88818881 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, ret_ty, .ret_ty);
......@@ -8934,7 +8934,7 @@ fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type)
89348934 }
89358935
89368936 return sema.failWithOwnedErrorMsg(block, msg: {
8937 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(pt)});
8937 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(zcu)});
89388938 errdefer msg.destroy(sema.gpa);
89398939
89408940 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
......@@ -9167,7 +9167,7 @@ fn analyzeAs(
91679167 const operand = sema.resolveInst(zir_operand);
91689168 const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand;
91699169 switch (dest_ty.zigTypeTag(zcu)) {
9170 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(pt)}),
9170 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(zcu)}),
91719171 .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}),
91729172 else => {},
91739173 }
......@@ -9192,7 +9192,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
91929192 const ptr_ty = operand_ty.scalarType(zcu);
91939193 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
91949194 if (!ptr_ty.isPtrAtRuntime(zcu)) {
9195 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)});
9195 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)});
91969196 }
91979197
91989198 const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined;
......@@ -9415,45 +9415,45 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94159415 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
94169416 switch (dest_ty.scalarType(zcu).zigTypeTag(zcu)) {
94179417 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9418 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});
9418 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
94199419 errdefer msg.destroy(sema.gpa);
94209420 switch (operand_ty.zigTypeTag(zcu)) {
9421 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(pt)}),
9422 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(pt)}),
9421 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(zcu)}),
9422 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(zcu)}),
94239423 else => {},
94249424 }
94259425 break :msg msg;
94269426 }),
94279427 .array => switch (dest_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9428 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}),
9428 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}),
94299429 else => {},
94309430 },
94319431 else => {},
94329432 }
94339433 if (!dest_ty.hasBitRepresentation(zcu)) {
9434 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});
9434 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
94359435 }
94369436
94379437 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
94389438 switch (operand_ty.scalarType(zcu).zigTypeTag(zcu)) {
94399439 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9440 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});
9440 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
94419441 errdefer msg.destroy(sema.gpa);
94429442 switch (dest_ty.zigTypeTag(zcu)) {
9443 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(pt)}),
9444 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(pt)}),
9443 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(zcu)}),
9444 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(zcu)}),
94459445 else => {},
94469446 }
94479447 break :msg msg;
94489448 }),
94499449 .array => switch (operand_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9450 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(pt)}),
9450 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(zcu)}),
94519451 else => {},
94529452 },
94539453 else => {},
94549454 }
94559455 if (!operand_ty.hasBitRepresentation(zcu)) {
9456 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});
9456 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
94579457 }
94589458
94599459 operand_ty.assertHasLayout(zcu);
......@@ -9463,9 +9463,9 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94639463 const dest_bits = dest_ty.bitSize(zcu);
94649464 if (operand_bits != dest_bits) {
94659465 return sema.fail(block, src, "@bitCast size mismatch: destination type '{f}' has {d} bits but source type '{f}' has {d} bits", .{
9466 dest_ty.fmt(pt),
9466 dest_ty.fmt(zcu),
94679467 dest_bits,
9468 operand_ty.fmt(pt),
9468 operand_ty.fmt(zcu),
94699469 operand_bits,
94709470 });
94719471 }
......@@ -9483,7 +9483,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
94839483 dest_ty.enumTagFieldIndex(result_val, zcu) == null)
94849484 {
94859485 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9486 dest_ty.fmt(pt), result_val.backingInt(zcu).fmtValueSema(pt, sema),
9486 dest_ty.fmt(zcu), result_val.backingInt(zcu).fmtValueSema(sema),
94879487 });
94889488 }
94899489
......@@ -9516,9 +9516,9 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
95169516 if (union_obj.tag_usage == .tagged) break :ref try sema.unionToTag(block, operand);
95179517 if (union_obj.layout == .@"packed") break :ref operand;
95189518 return sema.failWithOwnedErrorMsg(block, msg: {
9519 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(pt)});
9519 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(zcu)});
95209520 errdefer msg.deinit(gpa);
9521 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(pt)});
9521 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(zcu)});
95229522 try sema.addDeclaredHereNote(msg, operand_ty);
95239523 break :msg msg;
95249524 });
......@@ -9526,14 +9526,14 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
95269526 .@"struct" => {
95279527 if (operand_ty.containerLayout(zcu) != .@"packed") {
95289528 return sema.fail(block, operand_src, "non-packed struct '{f}' does not have a backing integer", .{
9529 operand_ty.fmt(pt),
9529 operand_ty.fmt(zcu),
95309530 });
95319531 }
95329532 break :ref operand;
95339533 },
95349534 else => {
95359535 return sema.fail(block, operand_src, "expected enum, tagged union, packed union or packed struct, found '{f}'", .{
9536 operand_ty.fmt(pt),
9536 operand_ty.fmt(zcu),
95379537 });
95389538 },
95399539 };
......@@ -9569,12 +9569,12 @@ fn zirFromBackingIntArgTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
95699569 .@"enum" => {},
95709570 .@"struct", .@"union" => |type_tag| if (dest_ty.containerLayout(zcu) != .@"packed") {
95719571 return sema.fail(block, src, "non-packed {t} '{f}' does not have a backing integer", .{
9572 type_tag, dest_ty.fmt(pt),
9572 type_tag, dest_ty.fmt(zcu),
95739573 });
95749574 },
95759575 else => {
95769576 return sema.fail(block, src, "expected enum, packed union or packed struct, found '{f}'", .{
9577 dest_ty.fmt(pt),
9577 dest_ty.fmt(zcu),
95789578 });
95799579 },
95809580 }
......@@ -9615,7 +9615,7 @@ fn zirFromBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
96159615 enum_obj.tagValueIndex(ip, backing_int_val.toIntern()) == null)
96169616 {
96179617 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9618 dest_ty.fmt(pt), backing_int_val.fmtValueSema(pt, sema),
9618 dest_ty.fmt(zcu), backing_int_val.fmtValueSema(sema),
96199619 });
96209620 }
96219621 return .fromValue(try pt.enumValue(dest_ty, backing_int_val));
......@@ -9661,7 +9661,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
96619661 block,
96629662 src,
96639663 "expected float or vector type, found '{f}'",
9664 .{dest_ty.fmt(pt)},
9664 .{dest_ty.fmt(zcu)},
96659665 ),
96669666 };
96679667
......@@ -9671,7 +9671,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
96719671 block,
96729672 operand_src,
96739673 "expected float or vector type, found '{f}'",
9674 .{operand_ty.fmt(pt)},
9674 .{operand_ty.fmt(zcu)},
96759675 ),
96769676 }
96779677
......@@ -9748,7 +9748,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97489748 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
97499749 const msg = msg: {
97509750 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{f}'", .{
9751 indexable_ty.fmt(pt),
9751 indexable_ty.fmt(zcu),
97529752 });
97539753 errdefer msg.destroy(sema.gpa);
97549754 if (indexable_ty.isIndexable(zcu)) {
......@@ -9870,7 +9870,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
98709870 const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand));
98719871 const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) {
98729872 .pointer => lhs_ptr_ty.childType(zcu),
9873 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(pt)}),
9873 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(zcu)}),
98749874 };
98759875
98769876 const sentinel_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
......@@ -9885,7 +9885,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
98859885 };
98869886 },
98879887 },
9888 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(pt)}),
9888 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(zcu)}),
98899889 };
98909890
98919891 return Air.internedToRef(sentinel_ty.toIntern());
......@@ -9955,7 +9955,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
99559955 };
99569956 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
99579957 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
9958 err_union_ty.fmt(pt),
9958 err_union_ty.fmt(zcu),
99599959 });
99609960 }
99619961
......@@ -10817,7 +10817,7 @@ fn finishSwitchBr(
1081710817 else => {},
1081810818 }
1081910819 return sema.fail(block, else_prong_src, "cannot enumerate values of type '{f}' for 'inline else'", .{
10820 item_ty.fmt(pt),
10820 item_ty.fmt(zcu),
1082110821 });
1082210822 };
1082310823 var unhandled_it = validated_switch.iterateUnhandledItems(error_names, min_int);
......@@ -11253,7 +11253,7 @@ fn validateSwitchBlock(
1125311253
1125411254 .optional => return sema.failWithOwnedErrorMsg(block, msg: {
1125511255 const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{
11256 operand_ty.fmt(pt),
11256 operand_ty.fmt(zcu),
1125711257 });
1125811258 errdefer msg.destroy(gpa);
1125911259 try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
......@@ -11262,7 +11262,7 @@ fn validateSwitchBlock(
1126211262
1126311263 .error_union => return sema.failWithOwnedErrorMsg(block, msg: {
1126411264 const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{
11265 operand_ty.fmt(pt),
11265 operand_ty.fmt(zcu),
1126611266 });
1126711267 errdefer msg.destroy(gpa);
1126811268 try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{});
......@@ -11282,14 +11282,14 @@ fn validateSwitchBlock(
1128211282 .spirv,
1128311283 => {},
1128411284 }
11285 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)});
11285 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(zcu)});
1128611286 };
1128711287
1128811288 if (zir_switch.has_continue and !block.isComptime()) {
1128911289 if (operand_ty.comptimeOnly(zcu)) {
1129011290 // Even if the operand is comptime-known, this `switch` is runtime.
1129111291 return sema.failWithOwnedErrorMsg(block, msg: {
11292 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(pt)});
11292 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(zcu)});
1129311293 errdefer msg.destroy(gpa);
1129411294 try sema.errNote(operand_src, msg, "switch loops are evaluated at runtime outside of comptime scopes", .{});
1129511295 try sema.explainWhyTypeIsComptime(msg, operand_src, operand_ty);
......@@ -11405,7 +11405,7 @@ fn validateSwitchBlock(
1140511405 const msg = try sema.errMsg(
1140611406 operand_src,
1140711407 "ranges not allowed when switching on type '{f}'",
11408 .{operand_ty.fmt(pt)},
11408 .{operand_ty.fmt(zcu)},
1140911409 );
1141011410 errdefer msg.destroy(gpa);
1141111411 try sema.errNote(
......@@ -11467,7 +11467,7 @@ fn validateSwitchBlock(
1146711467 item_ty.srcLoc(zcu),
1146811468 msg,
1146911469 "enum '{f}' declared here",
11470 .{item_ty.fmt(pt)},
11470 .{item_ty.fmt(zcu)},
1147111471 );
1147211472 break :msg msg;
1147311473 };
......@@ -11590,7 +11590,7 @@ fn validateSwitchBlock(
1159011590 block,
1159111591 src,
1159211592 "else prong required when switching on type '{f}'",
11593 .{item_ty.fmt(pt)},
11593 .{item_ty.fmt(zcu)},
1159411594 );
1159511595 }
1159611596 },
......@@ -12656,7 +12656,7 @@ fn validateSwitchItemOrRange(
1265612656 if (overlap_start.eql(overlap_end, item_ty, zcu)) {
1265712657 return sema.failWithOwnedErrorMsg(block, msg: {
1265812658 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12659 overlap_start.fmtValueSema(pt, sema),
12659 overlap_start.fmtValueSema(sema),
1266012660 });
1266112661 errdefer msg.destroy(sema.gpa);
1266212662 if (prev_range.first.eql(prev_range.last, item_ty, zcu)) {
......@@ -12678,7 +12678,7 @@ fn validateSwitchItemOrRange(
1267812678 } else {
1267912679 try sema.errNote(prev_range.src, msg, "overlaps with previous range here", .{});
1268012680 try sema.errNote(prev_range.src, msg, "ranges overlap from '{f}' to '{f}'", .{
12681 overlap_start.fmtValueSema(pt, sema), overlap_end.fmtValueSema(pt, sema),
12681 overlap_start.fmtValueSema(sema), overlap_end.fmtValueSema(sema),
1268212682 });
1268312683 }
1268412684 break :msg msg;
......@@ -12720,7 +12720,7 @@ fn validateSwitchItemOrRange(
1272012720 if (maybe_prev_src) |prev_src| {
1272112721 return sema.failWithOwnedErrorMsg(block, msg: {
1272212722 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12723 item_val.fmtValueSema(pt, sema),
12723 item_val.fmtValueSema(sema),
1272412724 });
1272512725 errdefer msg.destroy(sema.gpa);
1272612726 try sema.errNote(prev_src, msg, "previous value here", .{});
......@@ -12877,7 +12877,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1287712877 else => {},
1287812878 }
1287912879 return sema.fail(block, ty_src, "type '{f}' does not support '@hasField'", .{
12880 ty.fmt(pt),
12880 ty.fmt(zcu),
1288112881 });
1288212882 };
1288312883 return if (has_field) .bool_true else .bool_false;
......@@ -13088,7 +13088,7 @@ fn zirShl(
1308813088 break :rs lhs_src;
1308913089 } else {
1309013090 if (air_tag == .shl_sat and scalar_rhs_ty.isSignedInt(zcu)) {
13091 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(pt)});
13091 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(zcu)});
1309213092 }
1309313093 if (scalar_ty.toIntern() == .comptime_int_type) {
1309413094 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
......@@ -13370,7 +13370,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1337013370 const scalar_tag = scalar_ty.zigTypeTag(zcu);
1337113371
1337213372 if (scalar_tag != .int and scalar_tag != .bool)
13373 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(pt)});
13373 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(zcu)});
1337413374
1337513375 return analyzeBitNot(sema, block, operand, src);
1337613376}
......@@ -13506,11 +13506,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1350613506
1350713507 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
1350813508 if (lhs_is_tuple) break :lhs_info undefined;
13509 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(pt)});
13509 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(zcu)});
1351013510 };
1351113511 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {
1351213512 assert(!rhs_is_tuple);
13513 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(pt)});
13513 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(zcu)});
1351413514 };
1351513515
1351613516 const resolved_elem_ty = t: {
......@@ -13934,7 +13934,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1393413934 .int, .comptime_int, .float, .comptime_float => false,
1393513935 else => true,
1393613936 }) {
13937 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)});
13937 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)});
1393813938 }
1393913939
1394013940 if (rhs_scalar_ty.isAnyFloat()) {
......@@ -13965,7 +13965,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1396513965
1396613966 switch (rhs_scalar_ty.zigTypeTag(zcu)) {
1396713967 .int, .comptime_int, .float, .comptime_float => {},
13968 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)}),
13968 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)}),
1396913969 }
1397013970
1397113971 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try pt.intValue(rhs_scalar_ty, 0))).toIntern());
......@@ -14037,7 +14037,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1403714037 block,
1403814038 src,
1403914039 "ambiguous coercion of division operands '{f}' and '{f}'; non-zero remainder '{f}'",
14040 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValueSema(pt, sema) },
14040 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), rem.fmtValueSema(sema) },
1404114041 );
1404214042 }
1404314043 }
......@@ -14088,7 +14088,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1408814088 block,
1408914089 src,
1409014090 "division with '{f}' and '{f}': signed integers must use @divTrunc, @divFloor, @divCeil, or @divExact",
14091 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt) },
14091 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu) },
1409214092 );
1409314093 }
1409414094 break :blk .div_trunc;
......@@ -14805,7 +14805,7 @@ fn zirOverflowArithmetic(
1480514805 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);
1480614806
1480714807 if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .int) {
14808 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(pt)});
14808 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(zcu)});
1480914809 }
1481014810
1481114811 const maybe_lhs_val = sema.resolveValue(lhs);
......@@ -15065,7 +15065,7 @@ fn analyzeArithmetic(
1506515065 };
1506615066 if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) {
1506715067 return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{
15068 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
15068 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
1506915069 });
1507015070 }
1507115071
......@@ -15073,7 +15073,7 @@ fn analyzeArithmetic(
1507315073 const elem_size = lhs_elem_ty.abiSize(zcu);
1507415074 if (elem_size == 0) {
1507515075 return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{
15076 lhs_elem_ty.fmt(pt),
15076 lhs_elem_ty.fmt(zcu),
1507715077 });
1507815078 }
1507915079
......@@ -15380,20 +15380,20 @@ fn zirAsm(
1538015380 .int, .float, .bool, .vector => {},
1538115381
1538215382 .pointer => if (out_ty.isSlice(zcu)) return sema.failWithOwnedErrorMsg(block, msg: {
15383 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15383 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1538415384 errdefer msg.destroy(gpa);
1538515385 try sema.errNote(output_src, msg, "consider separate outputs for 'ptr' and 'len'", .{});
1538615386 break :msg msg;
1538715387 }),
1538815388
1538915389 .optional => if (!out_ty.isPtrLikeOptional(zcu)) {
15390 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15390 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1539115391 },
1539215392
1539315393 .@"enum" => switch (ip.loadEnumType(out_ty.toIntern()).int_tag_mode) {
1539415394 .explicit => {},
1539515395 .auto => return sema.failWithOwnedErrorMsg(block, msg: {
15396 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15396 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1539715397 errdefer msg.destroy(gpa);
1539815398 try sema.errNote(out_ty.srcLoc(zcu), msg, "integer tag type of enum is inferred", .{});
1539915399 try sema.errNote(out_ty.srcLoc(zcu), msg, "consider explicitly specifying the integer tag type", .{});
......@@ -15404,7 +15404,7 @@ fn zirAsm(
1540415404 .@"struct" => switch (out_ty.containerLayout(zcu)) {
1540515405 .@"packed" => {},
1540615406 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15407 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15407 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1540815408 errdefer msg.destroy(gpa);
1540915409 try sema.errNote(output_src, msg, "struct types cannot be passed to inline assembly", .{});
1541015410 try sema.addDeclaredHereNote(msg, out_ty);
......@@ -15415,7 +15415,7 @@ fn zirAsm(
1541515415 .@"union" => switch (out_ty.containerLayout(zcu)) {
1541615416 .@"packed" => {},
1541715417 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15418 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15418 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1541915419 errdefer msg.destroy(gpa);
1542015420 try sema.errNote(output_src, msg, "union types cannot be passed to inline assembly", .{});
1542115421 try sema.addDeclaredHereNote(msg, out_ty);
......@@ -15424,7 +15424,7 @@ fn zirAsm(
1542415424 },
1542515425
1542615426 .array => return sema.failWithOwnedErrorMsg(block, msg: {
15427 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});
15427 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
1542815428 errdefer msg.destroy(gpa);
1542915429 try sema.errNote(output_src, msg, "array types cannot be passed to inline assembly", .{});
1543015430 break :msg msg;
......@@ -15445,7 +15445,7 @@ fn zirAsm(
1544515445 .@"anyframe",
1544615446 .enum_literal,
1544715447 .spirv,
15448 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}),
15448 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}),
1544915449 }
1545015450
1545115451 const constraint = sema.code.nullTerminatedString(output.data.constraint);
......@@ -15501,7 +15501,7 @@ fn zirAsm(
1550115501 },
1550215502 else => true,
1550315503 };
15504 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(pt)});
15504 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(zcu)});
1550515505 }
1550615506 needed_capacity += (constraint.len + name.len + (2 + 3)) / 4;
1550715507 inputs[arg_i] = .{ .c = constraint, .n = name };
......@@ -15599,7 +15599,7 @@ fn zirCmpEq(
1559915599
1560015600 if (lhs_ty_tag == .null or rhs_ty_tag == .null) {
1560115601 const non_null_type = if (lhs_ty_tag == .null) rhs_ty else lhs_ty;
15602 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(pt)});
15602 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(zcu)});
1560315603 }
1560415604
1560515605 if (lhs_ty_tag == .@"union" and (rhs_ty_tag == .enum_literal or rhs_ty_tag == .@"enum")) {
......@@ -15655,7 +15655,7 @@ fn analyzeCmpUnionTag(
1565515655 const msg = msg: {
1565615656 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1565715657 errdefer msg.destroy(sema.gpa);
15658 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(pt)});
15658 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(zcu)});
1565915659 break :msg msg;
1566015660 };
1566115661 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -15739,7 +15739,7 @@ fn analyzeCmp(
1573915739 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
1574015740 if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) {
1574115741 return sema.fail(block, src, "operator {s} not allowed for type '{f}'", .{
15742 compareOperatorName(op), resolved_type.fmt(pt),
15742 compareOperatorName(op), resolved_type.fmt(zcu),
1574315743 });
1574415744 }
1574515745 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
......@@ -15845,11 +15845,11 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1584515845 try sema.ensureLayoutResolved(ty, operand_src, .size_of);
1584615846 switch (ty.classify(zcu)) {
1584715847 .no_possible_value,
15848 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(pt)}),
15848 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(zcu)}),
1584915849
1585015850 .partially_comptime,
1585115851 .fully_comptime,
15852 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(pt)}),
15852 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(zcu)}),
1585315853
1585415854 .one_possible_value => {
1585515855 assert(ty.abiSize(zcu) == 0);
......@@ -15872,7 +15872,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1587215872 operand_ty.zigTypeTag(zcu) != .error_set and
1587315873 operand_ty.zigTypeTag(zcu) != .@"enum")
1587415874 {
15875 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(pt)});
15875 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(zcu)});
1587615876 }
1587715877 try sema.ensureLayoutResolved(operand_ty, operand_src, .size_of);
1587815878 return .fromValue(try pt.intValue(.comptime_int, operand_ty.bitSize(zcu)));
......@@ -17357,7 +17357,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1735717357 block,
1735817358 src,
1735917359 "bit shifting operation expected integer type, found '{f}'",
17360 .{operand.fmt(pt)},
17360 .{operand.fmt(zcu)},
1736117361 );
1736217362}
1736317363
......@@ -17414,7 +17414,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1741417414 if (uncasted_ty.isVector(zcu)) {
1741517415 if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) {
1741617416 return sema.fail(block, operand_src, "boolean not operation on type '{f}'", .{
17417 uncasted_ty.fmt(pt),
17417 uncasted_ty.fmt(zcu),
1741817418 });
1741917419 }
1742017420 return analyzeBitNot(sema, block, uncasted_operand, src);
......@@ -17590,7 +17590,7 @@ fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi
1759017590 const pt = sema.pt;
1759117591 const zcu = pt.zcu;
1759217592 if (!ty.isSelfComparable(zcu, true)) {
17593 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(pt)});
17593 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(zcu)});
1759417594 }
1759517595}
1759617596
......@@ -17642,7 +17642,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1764217642 switch (ty.zigTypeTag(zcu)) {
1764317643 .error_set, .error_union, .undefined => return,
1764417644 else => return sema.fail(block, src, "expected error union type, found '{f}'", .{
17645 ty.fmt(pt),
17645 ty.fmt(zcu),
1764617646 }),
1764717647 }
1764817648}
......@@ -17780,7 +17780,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1778017780 const zcu = pt.zcu;
1778117781 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
1778217782 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17783 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
17783 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
1778417784 errdefer msg.destroy(sema.gpa);
1778517785 try sema.addDeclaredHereNote(msg, err_union_ty);
1778617786 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -17848,7 +17848,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1784817848 const zcu = pt.zcu;
1784917849 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
1785017850 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17851 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});
17851 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
1785217852 errdefer msg.destroy(sema.gpa);
1785317853 try sema.addDeclaredHereNote(msg, err_union_ty);
1785417854 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
......@@ -18047,7 +18047,7 @@ fn zirRetImplicit(
1804718047 if (base_tag == .noreturn) {
1804818048 const msg = msg: {
1804918049 const msg = try sema.errMsg(ret_ty_src, "function declared '{f}' implicitly returns", .{
18050 sema.fn_ret_ty.fmt(pt),
18050 sema.fn_ret_ty.fmt(zcu),
1805118051 });
1805218052 errdefer msg.destroy(sema.gpa);
1805318053 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
......@@ -18057,7 +18057,7 @@ fn zirRetImplicit(
1805718057 } else if (base_tag != .void) {
1805818058 const msg = msg: {
1805918059 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{f}' implicitly returns", .{
18060 sema.fn_ret_ty.fmt(pt),
18060 sema.fn_ret_ty.fmt(zcu),
1806118061 });
1806218062 errdefer msg.destroy(sema.gpa);
1806318063 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
......@@ -18468,7 +18468,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1846818468 if (host_size != 0) {
1846918469 try sema.ensureLayoutResolved(elem_ty, elem_ty_src, .bit_ptr_child);
1847018470 if (elem_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
18471 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(pt)});
18471 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(zcu)});
1847218472 errdefer msg.destroy(sema.gpa);
1847318473 try sema.explainWhyTypeIsUnpackable(msg, elem_ty_src, reason);
1847418474 break :msg msg;
......@@ -18476,12 +18476,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1847618476 const elem_bit_size = elem_ty.bitSize(zcu);
1847718477 if (bit_offset >= host_size * 8) {
1847818478 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", .{
18479 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,
18479 elem_ty.fmt(zcu), bit_offset, bit_offset - host_size * 8, host_size,
1848018480 });
1848118481 }
1848218482 if (elem_bit_size > host_size * 8 - bit_offset) {
1848318483 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", .{
18484 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
18484 elem_ty.fmt(zcu), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
1848518485 });
1848618486 }
1848718487 }
......@@ -18491,7 +18491,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1849118491 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
1849218492 }
1849318493 } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {
18494 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)});
18494 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)});
1849518495 }
1849618496
1849718497 const ty = try pt.ptrType(.{
......@@ -18653,7 +18653,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1865318653 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
1865418654 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
1865518655 if (union_ty.zigTypeTag(pt.zcu) != .@"union") {
18656 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(pt)});
18656 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(zcu)});
1865718657 }
1865818658 union_ty.assertHasLayout(zcu); // from a previous `field_type_ref` instruction
1865918659 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_names });
......@@ -18785,7 +18785,7 @@ fn zirStructInit(
1878518785
1878618786 if (field_ty.classify(zcu) == .no_possible_value) {
1878718787 return sema.failWithOwnedErrorMsg(block, msg: {
18788 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
18788 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
1878918789 errdefer msg.destroy(sema.gpa);
1879018790
1879118791 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{f}' declared here", .{
......@@ -19574,7 +19574,7 @@ fn fieldType(
1957419574 else => {},
1957519575 }
1957619576 return sema.fail(block, ty_src, "expected struct or union; found '{f}'", .{
19577 cur_ty.fmt(pt),
19577 cur_ty.fmt(zcu),
1957819578 });
1957919579 }
1958019580}
......@@ -19628,7 +19628,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1962819628 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1962919629 try sema.ensureLayoutResolved(ty, operand_src, .align_of);
1963019630 if (ty.isNoReturn(zcu)) {
19631 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)});
19631 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(zcu)});
1963219632 }
1963319633 return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?));
1963419634}
......@@ -19703,7 +19703,7 @@ fn zirAbs(
1970319703 block,
1970419704 operand_src,
1970519705 "expected integer, float, or vector of either integers or floats, found '{f}'",
19706 .{operand_ty.fmt(pt)},
19706 .{operand_ty.fmt(zcu)},
1970719707 ),
1970819708 };
1970919709
......@@ -19764,7 +19764,7 @@ fn unaryMath(
1976419764 block,
1976519765 operand_src,
1976619766 "expected vector of floats or float type, found '{f}'",
19767 .{operand_ty.fmt(pt)},
19767 .{operand_ty.fmt(zcu)},
1976819768 ),
1976919769 }
1977019770
......@@ -19805,9 +19805,9 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1980519805 },
1980619806 .@"enum" => operand_ty,
1980719807 .@"union" => operand_ty.unionTagType(zcu) orelse
19808 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(pt)}),
19808 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(zcu)}),
1980919809 else => return sema.fail(block, operand_src, "expected enum or union; found '{f}'", .{
19810 operand_ty.fmt(pt),
19810 operand_ty.fmt(zcu),
1981119811 }),
1981219812 };
1981319813 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
......@@ -19815,7 +19815,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1981519815 const field_index = enum_ty.enumTagFieldIndex(val, zcu) orelse {
1981619816 const msg = msg: {
1981719817 const msg = try sema.errMsg(src, "no field with value '{f}' in enum '{f}'", .{
19818 val.fmtValueSema(pt, sema), enum_ty.fmt(pt),
19818 val.fmtValueSema(sema), enum_ty.fmt(zcu),
1981919819 });
1982019820 errdefer msg.destroy(sema.gpa);
1982119821 try sema.errNote(enum_ty.srcLoc(zcu), msg, "declared here", .{});
......@@ -20027,7 +20027,7 @@ fn zirReifyPointer(
2002720027 },
2002820028 .@"opaque" => switch (size) {
2002920029 .one => {},
20030 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}),
20030 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)}),
2003120031 },
2003220032 else => {},
2003320033 }
......@@ -20963,7 +20963,7 @@ fn zirReifySpirvType(
2096320963 if (sampled_type.toIntern() != .void_type and
2096420964 (!sampled_type.hasRuntimeBits(zcu) or (!sampled_type.isRuntimeFloat() and !sampled_type.isInt(zcu))))
2096520965 {
20966 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(pt) });
20966 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(zcu) });
2096720967 }
2096820968
2096920969 if (target.os.tag == .vulkan) {
......@@ -20995,7 +20995,7 @@ fn zirReifySpirvType(
2099520995 block,
2099620996 operand_src,
2099720997 "image 'format' '.{t}' does not match '{t}' type '{f}' under the 'vulkan' OS",
20998 .{ format, usage_tag, sampled_type.fmt(pt) },
20998 .{ format, usage_tag, sampled_type.fmt(zcu) },
2099920999 );
2100021000 }
2100121001 }
......@@ -21018,7 +21018,7 @@ fn zirReifySpirvType(
2101821018 .sampled_image => blk: {
2101921019 const image_ty = Value.fromInterned(union_val.val).toType();
2102021020 if (image_ty.zigTypeTag(zcu) != .spirv or ip.loadSpirvType(image_ty.toIntern()).flags.tag != .image) {
21021 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(pt)});
21021 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(zcu)});
2102221022 }
2102321023 const image_info = ip.loadSpirvType(image_ty.toIntern()).flags;
2102421024 if (image_info.usage != .sampled) {
......@@ -21078,6 +21078,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
2107821078}
2107921079
2108021080fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21081 const zcu = sema.pt.zcu;
2108121082 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2108221083 const src = block.nodeOffset(extra.node);
2108321084 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
......@@ -21086,9 +21087,9 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2108621087 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
2108721088 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2108821089 try sema.ensureLayoutResolved(arg_ty, ty_src, .parameter);
21089 if (!arg_ty.validateExtern(.param_ty, sema.pt.zcu)) {
21090 if (!arg_ty.validateExtern(.param_ty, zcu)) {
2109021091 const msg = msg: {
21091 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(sema.pt)});
21092 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(zcu)});
2109221093 errdefer msg.destroy(sema.gpa);
2109321094
2109421095 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
......@@ -21151,7 +21152,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2115121152 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2115221153 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2115321154
21154 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(pt)}, .no_embedded_nulls);
21155 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(zcu)}, .no_embedded_nulls);
2115521156 return sema.addNullTerminatedStrLit(type_name);
2115621157}
2115721158
......@@ -21180,7 +21181,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2118021181
2118121182 switch (dest_scalar_ty.zigTypeTag(zcu)) {
2118221183 .comptime_int, .int => {},
21183 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),
21184 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
2118421185 }
2118521186 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
2118621187
......@@ -21261,7 +21262,7 @@ fn zirRoundCast(
2126121262 block,
2126221263 operand_src,
2126321264 "expected float or vector type, found '{f}'",
21264 .{operand_ty.fmt(pt)},
21265 .{operand_ty.fmt(zcu)},
2126521266 ),
2126621267 }
2126721268
......@@ -21295,7 +21296,7 @@ fn zirRoundCast(
2129521296 block,
2129621297 src,
2129721298 "expected integer, float, or vector of either integers or floats, found '{f}'",
21298 .{dest_ty.fmt(pt)},
21299 .{dest_ty.fmt(zcu)},
2129921300 ),
2130021301 }
2130121302
......@@ -21359,7 +21360,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2135921360
2136021361 switch (dest_scalar_ty.zigTypeTag(zcu)) {
2136121362 .comptime_float, .float => {},
21362 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),
21363 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
2136321364 }
2136421365 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
2136521366
......@@ -21419,7 +21420,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2141921420
2142021421 if (ptr_ty.isSlice(zcu)) {
2142121422 const msg = msg: {
21422 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(pt)});
21423 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(zcu)});
2142321424 errdefer msg.destroy(sema.gpa);
2142421425 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
2142521426 break :msg msg;
......@@ -21492,7 +21493,7 @@ fn ptrFromIntVal(
2149221493 }
2149321494 const addr = operand_val.toUnsignedInt(zcu);
2149421495 if (!ptr_ty.isAllowzeroPtr(zcu) and addr == 0)
21495 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(pt)});
21496 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(zcu)});
2149621497 if (addr != 0 and ptr_align != .none) {
2149721498 const masked_addr = if (ptr_ty.childType(zcu).fnPtrMaskOrNull(zcu)) |mask|
2149821499 addr & mask
......@@ -21500,7 +21501,7 @@ fn ptrFromIntVal(
2150021501 addr;
2150121502
2150221503 if (!ptr_align.check(masked_addr)) {
21503 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(pt)});
21504 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(zcu)});
2150421505 }
2150521506 }
2150621507
......@@ -21545,8 +21546,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2154521546 errdefer msg.destroy(sema.gpa);
2154621547 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
2154721548 const operand_payload_ty = operand_ty.errorUnionPayload(zcu);
21548 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(pt)});
21549 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(pt)});
21549 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(zcu)});
21550 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(zcu)});
2155021551 try addDeclaredHereNote(sema, msg, dest_ty);
2155121552 try addDeclaredHereNote(sema, msg, operand_ty);
2155221553 break :msg msg;
......@@ -21620,7 +21621,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2162021621
2162121622 if (result == .disjoint and !(operand_tag == .error_union and dest_tag == .error_union)) {
2162221623 return sema.fail(block, src, "error sets '{f}' and '{f}' have no common errors", .{
21623 operand_err_ty.fmt(pt), dest_err_ty.fmt(pt),
21624 operand_err_ty.fmt(zcu), dest_err_ty.fmt(zcu),
2162421625 });
2162521626 }
2162621627
......@@ -21645,7 +21646,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2164521646
2164621647 if (result != .superset and !dest_err_ty.errorSetHasField(err_name, zcu)) {
2164721648 return sema.fail(block, src, "'error.{f}' not a member of error set '{f}'", .{
21648 err_name.fmt(ip), dest_err_ty.fmt(pt),
21649 err_name.fmt(ip), dest_err_ty.fmt(zcu),
2164921650 });
2165021651 }
2165121652
......@@ -21810,7 +21811,7 @@ fn ptrCastFull(
2181021811 if (src_elem_ty.zigTypeTag(zcu) == .@"opaque") {
2181121812 return sema.failWithOwnedErrorMsg(block, msg: {
2181221813 const msg = try sema.errMsg(src, "cannot infer length of slice of '{f}' from pointer to opaque type '{f}' with unknown size", .{
21813 dest_elem_ty.fmt(pt), src_elem_ty.fmt(pt),
21814 dest_elem_ty.fmt(zcu), src_elem_ty.fmt(zcu),
2181421815 });
2181521816 errdefer msg.destroy(gpa);
2181621817 try sema.addDeclaredHereNote(msg, src_elem_ty);
......@@ -21821,14 +21822,14 @@ fn ptrCastFull(
2182121822 const dest_elem_size = dest_elem_ty.abiSize(zcu);
2182221823 if (dest_elem_size == 0) {
2182321824 return sema.fail(block, src, "cannot infer length of slice of zero-bit '{f}' from '{f}'", .{
21824 dest_elem_ty.fmt(pt), operand_ty.fmt(pt),
21825 dest_elem_ty.fmt(zcu), operand_ty.fmt(zcu),
2182521826 });
2182621827 }
2182721828 if (opt_src_len) |src_len| {
2182821829 const bytes = src_len * src_elem_size;
2182921830 const dest_len = std.math.divExact(u64, bytes, dest_elem_size) catch switch (src_info.flags.size) {
2183021831 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21831 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(pt)}),
21832 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(zcu)}),
2183221833 else => unreachable,
2183321834 };
2183421835 break :len .{ .constant = dest_len };
......@@ -21847,7 +21848,7 @@ fn ptrCastFull(
2184721848 // The result value will have `dest_len * dest_base_per_elem` values of type `dest_base_ty`.
2184821849 if (dest_base_ty.toIntern() != src_base_ty.toIntern()) {
2184921850 return sema.fail(block, src, "cannot infer length of comptime-only '{f}' from incompatible '{f}'", .{
21850 dest_ty.fmt(pt), operand_ty.fmt(pt),
21851 dest_ty.fmt(zcu), operand_ty.fmt(zcu),
2185121852 });
2185221853 }
2185321854 // `src_base_ty` is comptime-only, so `src_elem_ty` is comptime-only, so `operand_ty` is
......@@ -21856,7 +21857,7 @@ fn ptrCastFull(
2185621857 const base_len = src_len * src_base_per_elem;
2185721858 const dest_len = std.math.divExact(u64, base_len, dest_base_per_elem) catch switch (src_info.flags.size) {
2185821859 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21859 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(pt)}),
21860 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(zcu)}),
2186021861 else => unreachable,
2186121862 };
2186221863 break :len .{ .constant = dest_len };
......@@ -21918,7 +21919,7 @@ fn ptrCastFull(
2191821919 if (imc_res == .ok) break :check_child;
2191921920 return sema.failWithOwnedErrorMsg(block, msg: {
2192021921 const msg = try sema.errMsg(src, "pointer element type '{f}' cannot coerce into element type '{f}'", .{
21921 src_child.fmt(pt), dest_child.fmt(pt),
21922 src_child.fmt(zcu), dest_child.fmt(zcu),
2192221923 });
2192321924 errdefer msg.destroy(sema.gpa);
2192421925 try imc_res.report(sema, src, msg);
......@@ -21945,12 +21946,12 @@ fn ptrCastFull(
2194521946 return sema.failWithOwnedErrorMsg(block, msg: {
2194621947 const msg = if (src_info.sentinel == .none) blk: {
2194721948 break :blk try sema.errMsg(src, "destination pointer requires '{f}' sentinel", .{
21948 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
21949 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
2194921950 });
2195021951 } else blk: {
2195121952 break :blk try sema.errMsg(src, "pointer sentinel '{f}' cannot coerce into pointer sentinel '{f}'", .{
21952 Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema),
21953 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
21953 Value.fromInterned(src_info.sentinel).fmtValueSema(sema),
21954 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
2195421955 });
2195521956 };
2195621957 errdefer msg.destroy(sema.gpa);
......@@ -21991,8 +21992,8 @@ fn ptrCastFull(
2199121992
2199221993 return sema.failWithOwnedErrorMsg(block, msg: {
2199321994 const msg = try sema.errMsg(src, "'{f}' could have null values which are illegal in type '{f}'", .{
21994 operand_ty.fmt(pt),
21995 dest_ty.fmt(pt),
21995 operand_ty.fmt(zcu),
21996 dest_ty.fmt(zcu),
2199621997 });
2199721998 errdefer msg.destroy(sema.gpa);
2199821999 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
......@@ -22019,10 +22020,10 @@ fn ptrCastFull(
2201922020 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
2202022021 errdefer msg.destroy(sema.gpa);
2202122022 try sema.errNote(operand_src, msg, "'{f}' has alignment '{d}'", .{
22022 operand_ty.fmt(pt), src_align.toByteUnits() orelse 0,
22023 operand_ty.fmt(zcu), src_align.toByteUnits() orelse 0,
2202322024 });
2202422025 try sema.errNote(src, msg, "'{f}' has alignment '{d}'", .{
22025 dest_ty.fmt(pt), dest_align.toByteUnits() orelse 0,
22026 dest_ty.fmt(zcu), dest_align.toByteUnits() orelse 0,
2202622027 });
2202722028 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
2202822029 break :msg msg;
......@@ -22036,10 +22037,10 @@ fn ptrCastFull(
2203622037 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
2203722038 errdefer msg.destroy(sema.gpa);
2203822039 try sema.errNote(operand_src, msg, "'{f}' has address space '{s}'", .{
22039 operand_ty.fmt(pt), @tagName(src_info.flags.address_space),
22040 operand_ty.fmt(zcu), @tagName(src_info.flags.address_space),
2204022041 });
2204122042 try sema.errNote(src, msg, "'{f}' has address space '{s}'", .{
22042 dest_ty.fmt(pt), @tagName(dest_info.flags.address_space),
22043 dest_ty.fmt(zcu), @tagName(dest_info.flags.address_space),
2204322044 });
2204422045 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
2204522046 break :msg msg;
......@@ -22105,7 +22106,7 @@ fn ptrCastFull(
2210522106
2210622107 if (operand_val.isNull(zcu)) {
2210722108 if (!dest_ty.ptrAllowsZero(zcu)) {
22108 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});
22109 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
2210922110 }
2211022111 if (dest_ty.zigTypeTag(zcu) == .optional) {
2211122112 return Air.internedToRef((try pt.nullValue(dest_ty)).toIntern());
......@@ -22419,7 +22420,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2241922420
2242022421 if (operand_info.signedness != dest_info.signedness) {
2242122422 return sema.fail(block, operand_src, "expected {s} integer type, found '{f}'", .{
22422 @tagName(dest_info.signedness), operand_ty.fmt(pt),
22423 @tagName(dest_info.signedness), operand_ty.fmt(zcu),
2242322424 });
2242422425 }
2242522426 if (dest_info.bits >= operand_info.bits) {
......@@ -22504,7 +22505,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2250422505 block,
2250522506 operand_src,
2250622507 "@byteSwap requires the number of bits to be evenly divisible by 8, but {f} has {d} bits",
22507 .{ scalar_ty.fmt(pt), bits },
22508 .{ scalar_ty.fmt(zcu), bits },
2250822509 );
2250922510 }
2251022511 if (sema.resolveValue(operand)) |operand_val| {
......@@ -22554,7 +22555,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2255422555 const ip = &zcu.intern_pool;
2255522556 switch (ty.zigTypeTag(zcu)) {
2255622557 .@"struct" => {},
22557 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(pt)}),
22558 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(zcu)}),
2255822559 }
2255922560
2256022561 const field_index = if (ty.isTuple(zcu)) blk: {
......@@ -22589,7 +22590,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
2258922590 const zcu = pt.zcu;
2259022591 switch (ty.zigTypeTag(zcu)) {
2259122592 .@"struct", .@"enum", .@"union", .@"opaque" => return,
22592 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(pt)}),
22593 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(zcu)}),
2259322594 }
2259422595}
2259522596
......@@ -22600,7 +22601,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr
2260022601 switch (ty.zigTypeTag(zcu)) {
2260122602 .comptime_int => return true,
2260222603 .int => return false,
22603 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(pt)}),
22604 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(zcu)}),
2260422605 }
2260522606}
2260622607
......@@ -22655,7 +22656,7 @@ fn checkPtrOperand(
2265522656 const msg = try sema.errMsg(
2265622657 ty_src,
2265722658 "expected pointer, found '{f}'",
22658 .{ty.fmt(pt)},
22659 .{ty.fmt(zcu)},
2265922660 );
2266022661 errdefer msg.destroy(sema.gpa);
2266122662
......@@ -22668,7 +22669,7 @@ fn checkPtrOperand(
2266822669 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
2266922670 else => {},
2267022671 }
22671 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});
22672 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
2267222673}
2267322674
2267422675fn checkPtrType(
......@@ -22687,7 +22688,7 @@ fn checkPtrType(
2268722688 const msg = try sema.errMsg(
2268822689 ty_src,
2268922690 "expected pointer type, found '{f}'",
22690 .{ty.fmt(pt)},
22691 .{ty.fmt(zcu)},
2269122692 );
2269222693 errdefer msg.destroy(sema.gpa);
2269322694
......@@ -22700,7 +22701,7 @@ fn checkPtrType(
2270022701 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
2270122702 else => {},
2270222703 }
22703 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});
22704 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
2270422705}
2270522706
2270622707fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
......@@ -22713,7 +22714,7 @@ fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2271322714 const as = ty.ptrAddressSpace(zcu);
2271422715 if (target_util.shouldBlockPointerOps(target, as)) {
2271522716 return sema.failWithOwnedErrorMsg(block, msg: {
22716 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(pt)});
22717 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(zcu)});
2271722718 errdefer msg.destroy(sema.gpa);
2271822719 try sema.errNote(
2271922720 src,
......@@ -22762,9 +22763,9 @@ fn checkLogicalPtrCast(
2276222763 },
2276322764 else => null,
2276422765 } orelse return sema.failWithOwnedErrorMsg(block, msg: {
22765 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(pt), dest_ty.fmt(pt) });
22766 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(zcu), dest_ty.fmt(zcu) });
2276622767 errdefer msg.destroy(sema.gpa);
22767 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(pt), src_child.fmt(pt) });
22768 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(zcu), src_child.fmt(zcu) });
2276822769 break :msg msg;
2276922770 });
2277022771 }
......@@ -22783,7 +22784,7 @@ fn checkVectorElemType(
2278322784 .optional, .pointer => if (ty.isPtrAtRuntime(zcu)) return,
2278422785 else => {},
2278522786 }
22786 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(pt)});
22787 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(zcu)});
2278722788}
2278822789
2278922790fn checkFloatType(
......@@ -22796,7 +22797,7 @@ fn checkFloatType(
2279622797 const zcu = pt.zcu;
2279722798 switch (ty.zigTypeTag(zcu)) {
2279822799 .comptime_int, .comptime_float, .float => {},
22799 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(pt)}),
22800 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(zcu)}),
2280022801 }
2280122802}
2280222803
......@@ -22814,7 +22815,7 @@ fn checkNumericType(
2281422815 .comptime_float, .float, .comptime_int, .int => {},
2281522816 else => |t| return sema.fail(block, ty_src, "expected number, found '{t}'", .{t}),
2281622817 },
22817 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(pt)}),
22818 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(zcu)}),
2281822819 }
2281922820}
2282022821
......@@ -22850,7 +22851,7 @@ fn checkAtomicPtrOperand(
2285022851 block,
2285122852 elem_ty_src,
2285222853 "expected bool, integer, float, enum, packed struct, or pointer type; found '{f}'",
22853 .{elem_ty.fmt(pt)},
22854 .{elem_ty.fmt(zcu)},
2285422855 ),
2285522856 };
2285622857
......@@ -22911,12 +22912,12 @@ fn checkIntOrVector(
2291122912 switch (elem_ty.zigTypeTag(zcu)) {
2291222913 .int => return elem_ty,
2291322914 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22914 elem_ty.fmt(pt),
22915 elem_ty.fmt(zcu),
2291522916 }),
2291622917 }
2291722918 },
2291822919 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22919 operand_ty.fmt(pt),
22920 operand_ty.fmt(zcu),
2292022921 }),
2292122922 }
2292222923}
......@@ -22936,12 +22937,12 @@ fn checkIntOrVectorAllowComptime(
2293622937 switch (elem_ty.zigTypeTag(zcu)) {
2293722938 .int, .comptime_int => return elem_ty,
2293822939 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22939 elem_ty.fmt(pt),
22940 elem_ty.fmt(zcu),
2294022941 }),
2294122942 }
2294222943 },
2294322944 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22944 operand_ty.fmt(pt),
22945 operand_ty.fmt(zcu),
2294522946 }),
2294622947 }
2294722948}
......@@ -23032,7 +23033,7 @@ fn checkVectorizableBinaryOperands(
2303223033 } else {
2303323034 const msg = msg: {
2303423035 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{f}' and '{f}'", .{
23035 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
23036 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
2303623037 });
2303723038 errdefer msg.destroy(sema.gpa);
2303823039 if (lhs_is_vector) {
......@@ -23179,7 +23180,7 @@ fn zirCmpxchg(
2317923180 block,
2318023181 elem_ty_src,
2318123182 "expected bool, integer, enum, packed struct, or pointer type; found '{f}'",
23182 .{elem_ty.fmt(pt)},
23183 .{elem_ty.fmt(zcu)},
2318323184 );
2318423185 }
2318523186 const uncasted_ptr = sema.resolveInst(extra.ptr);
......@@ -23259,7 +23260,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2325923260
2326023261 switch (dest_ty.zigTypeTag(zcu)) {
2326123262 .array, .vector => {},
23262 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(pt)}),
23263 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(zcu)}),
2326323264 }
2326423265
2326523266 const operand = sema.resolveInst(extra.rhs);
......@@ -23308,7 +23309,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2330823309 const zcu = pt.zcu;
2330923310
2331023311 if (operand_ty.zigTypeTag(zcu) != .vector) {
23311 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});
23312 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
2331223313 }
2331323314
2331423315 const scalar_ty = operand_ty.childType(zcu);
......@@ -23318,13 +23319,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2331823319 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
2331923320 .int, .bool => {},
2332023321 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{f}'", .{
23321 @tagName(operation), operand_ty.fmt(pt),
23322 @tagName(operation), operand_ty.fmt(zcu),
2332223323 }),
2332323324 },
2332423325 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
2332523326 .int, .float => {},
2332623327 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{f}'", .{
23327 @tagName(operation), operand_ty.fmt(pt),
23328 @tagName(operation), operand_ty.fmt(zcu),
2332823329 }),
2332923330 },
2333023331 }
......@@ -23379,7 +23380,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2337923380
2338023381 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
2338123382 .array, .vector => sema.typeOf(mask).arrayLen(zcu),
23382 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(pt)}),
23383 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(zcu)}),
2338323384 };
2338423385 mask_ty = try pt.vectorType(.{
2338523386 .len = @intCast(mask_len),
......@@ -23412,7 +23413,7 @@ fn analyzeShuffle(
2341223413 .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)),
2341323414 .undefined => 0,
2341423415 else => return sema.fail(block, a_src, "expected vector of '{f}', found '{f}'", .{
23415 elem_ty.fmt(pt), sema.typeOf(a_uncoerced).fmt(pt),
23416 elem_ty.fmt(zcu), sema.typeOf(a_uncoerced).fmt(zcu),
2341623417 }),
2341723418 };
2341823419 const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() });
......@@ -23423,7 +23424,7 @@ fn analyzeShuffle(
2342323424 .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)),
2342423425 .undefined => 0,
2342523426 else => return sema.fail(block, b_src, "expected vector of '{f}', found '{f}'", .{
23426 elem_ty.fmt(pt), sema.typeOf(b_uncoerced).fmt(pt),
23427 elem_ty.fmt(zcu), sema.typeOf(b_uncoerced).fmt(zcu),
2342723428 }),
2342823429 };
2342923430 const b_ty = try pt.vectorType(.{ .len = b_len, .child = elem_ty.toIntern() });
......@@ -23462,7 +23463,7 @@ fn analyzeShuffle(
2346223463 if (idx >= a_len) return sema.failWithOwnedErrorMsg(block, msg: {
2346323464 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
2346423465 errdefer msg.destroy(sema.gpa);
23465 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(pt) });
23466 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(zcu) });
2346623467 if (idx < b_len) {
2346723468 try sema.errNote(b_src, msg, "use '~@as(u32, {d})' to index into second vector given here", .{idx});
2346823469 }
......@@ -23475,7 +23476,7 @@ fn analyzeShuffle(
2347523476 if (idx >= b_len) return sema.failWithOwnedErrorMsg(block, msg: {
2347623477 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
2347723478 errdefer msg.destroy(sema.gpa);
23478 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(pt) });
23479 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(zcu) });
2347923480 break :msg msg;
2348023481 });
2348123482 }
......@@ -23577,7 +23578,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2357723578
2357823579 const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) {
2357923580 .vector, .array => pred_ty.arrayLen(zcu),
23580 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(pt)}),
23581 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(zcu)}),
2358123582 };
2358223583 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
2358323584
......@@ -23835,7 +23836,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2383523836
2383623837 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
2383723838 .comptime_float, .float => {},
23838 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(pt)}),
23839 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(zcu)}),
2383923840 }
2384023841
2384123842 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
......@@ -23933,7 +23934,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2393323934
2393423935 const args_ty = sema.typeOf(args);
2393523936 if (!args_ty.isTuple(zcu)) {
23936 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(pt)});
23937 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(zcu)});
2393723938 }
2393823939
2393923940 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));
......@@ -23983,13 +23984,13 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2398323984 };
2398423985 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);
2398523986 if (parent_ptr_info.flags.size != .one) {
23986 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(pt)});
23987 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(zcu)});
2398723988 }
2398823989 const parent_ty: Type = .fromInterned(parent_ptr_info.child);
2398923990 try sema.ensureLayoutResolved(parent_ty, inst_src, .field_used);
2399023991 switch (parent_ty.zigTypeTag(zcu)) {
2399123992 .@"struct", .@"union" => {},
23992 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(pt)}),
23993 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(zcu)}),
2399323994 }
2399423995
2399523996 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name });
......@@ -24072,7 +24073,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2407224073
2407324074 if (field.index != field_index) {
2407424075 return sema.fail(block, inst_src, "field '{f}' has index '{d}' but pointer value is index '{d}' of struct '{f}'", .{
24075 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(pt),
24076 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(zcu),
2407624077 });
2407724078 }
2407824079 break :result .fromValue(try pt.getCoerced(.fromInterned(field.base), unaligned_parent_ptr_ty));
......@@ -24114,7 +24115,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2411424115 const msg = try sema.errMsg(inst_src, "@fieldParentPtr increases pointer alignment", .{});
2411524116 errdefer msg.destroy(sema.gpa);
2411624117 try sema.errNote(inst_src, msg, "parent pointer type '{f}' has alignment '{d}'", .{
24117 parent_ptr_ty.fmt(pt),
24118 parent_ptr_ty.fmt(zcu),
2411824119 parent_ptr_ty.abiAlignment(zcu),
2411924120 });
2412024121 if (parent_ty.isTuple(zcu)) {
......@@ -24241,7 +24242,7 @@ fn analyzeMinMax(
2424124242 try sema.checkNumericType(block, operand_src, operand_ty);
2424224243 if (operand_ty.zigTypeTag(zcu) != .vector) {
2424324244 return sema.failWithOwnedErrorMsg(block, msg: {
24244 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});
24245 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
2424524246 errdefer msg.destroy(zcu.gpa);
2424624247 try sema.errNote(operand_srcs[0], msg, "vector operand here", .{});
2424724248 break :msg msg;
......@@ -24249,7 +24250,7 @@ fn analyzeMinMax(
2424924250 }
2425024251 if (operand_ty.vectorLen(zcu) != vec_len) {
2425124252 return sema.failWithOwnedErrorMsg(block, msg: {
24252 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(pt) });
24253 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(zcu) });
2425324254 errdefer msg.destroy(zcu.gpa);
2425424255 try sema.errNote(operand_srcs[0], msg, "vector of length '{d}' here", .{vec_len});
2425524256 break :msg msg;
......@@ -24263,7 +24264,7 @@ fn analyzeMinMax(
2426324264 try sema.checkNumericType(block, operand_src, operand_ty);
2426424265 if (operand_ty.zigTypeTag(zcu) == .vector) {
2426524266 return sema.failWithOwnedErrorMsg(block, msg: {
24266 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(pt)});
24267 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(zcu)});
2426724268 errdefer msg.destroy(zcu.gpa);
2426824269 try sema.errNote(operand_src, msg, "vector operand here", .{});
2426924270 break :msg msg;
......@@ -24581,10 +24582,10 @@ fn zirMemcpy(
2458124582 const msg = try sema.errMsg(src, "unknown copy length", .{});
2458224583 errdefer msg.destroy(sema.gpa);
2458324584 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24584 dest_ty.fmt(pt),
24585 dest_ty.fmt(zcu),
2458524586 });
2458624587 try sema.errNote(src_src, msg, "source type '{f}' provides no length", .{
24587 src_ty.fmt(pt),
24588 src_ty.fmt(zcu),
2458824589 });
2458924590 break :msg msg;
2459024591 };
......@@ -24611,7 +24612,7 @@ fn zirMemcpy(
2461124612 const msg = try sema.errMsg(
2461224613 src,
2461324614 "pointer element type '{f}' cannot coerce into element type '{f}'",
24614 .{ src_elem_ty.fmt(pt), dest_elem_ty.fmt(pt) },
24615 .{ src_elem_ty.fmt(zcu), dest_elem_ty.fmt(zcu) },
2461524616 );
2461624617 errdefer msg.destroy(sema.gpa);
2461724618 try imc.report(sema, src, msg);
......@@ -24630,10 +24631,10 @@ fn zirMemcpy(
2463024631 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
2463124632 errdefer msg.destroy(sema.gpa);
2463224633 try sema.errNote(dest_src, msg, "length {f} here", .{
24633 dest_len_val.fmtValueSema(pt, sema),
24634 dest_len_val.fmtValueSema(sema),
2463424635 });
2463524636 try sema.errNote(src_src, msg, "length {f} here", .{
24636 src_len_val.fmtValueSema(pt, sema),
24637 src_len_val.fmtValueSema(sema),
2463724638 });
2463824639 break :msg msg;
2463924640 };
......@@ -24851,7 +24852,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2485124852 const msg = try sema.errMsg(src, "unknown @memset length", .{});
2485224853 errdefer msg.destroy(sema.gpa);
2485324854 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24854 dest_ptr_ty.fmt(pt),
24855 dest_ptr_ty.fmt(zcu),
2485524856 });
2485624857 break :msg msg;
2485724858 });
......@@ -24897,7 +24898,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2489724898
2489824899 if (comptime_only_elem) {
2489924900 return sema.failWithOwnedErrorMsg(block, msg: {
24900 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(pt)});
24901 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(zcu)});
2490124902 errdefer msg.destroy(sema.gpa);
2490224903 try sema.errNote(dest_src, msg, "operation is runtime due to destination pointer", .{});
2490324904 break :msg msg;
......@@ -25268,16 +25269,16 @@ fn zirBuiltinExtern(
2526825269
2526925270 if (!elem_ty.validateExtern(.other, zcu)) {
2527025271 return sema.failWithOwnedErrorMsg(block, msg: {
25271 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});
25272 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
2527225273 errdefer msg.destroy(sema.gpa);
25273 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(pt)});
25274 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(zcu)});
2527425275 try sema.explainWhyTypeIsNotExtern(msg, ty_src, elem_ty, .other);
2527525276 break :msg msg;
2527625277 });
2527725278 }
2527825279 if (elem_ty.zigTypeTag(zcu) == .@"fn" and !ptr_info.flags.is_const) {
2527925280 return sema.failWithOwnedErrorMsg(block, msg: {
25280 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});
25281 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
2528125282 errdefer msg.destroy(sema.gpa);
2528225283 try sema.errNote(ty_src, msg, "pointer to extern function must be 'const'", .{});
2528325284 break :msg msg;
......@@ -25541,7 +25542,7 @@ fn zirFloatOpResultType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.
2554125542 block,
2554225543 operand_src,
2554325544 "expected vector of floats or float type, found '{f}'",
25544 .{float_ty.fmt(sema.pt)},
25545 .{float_ty.fmt(zcu)},
2554525546 ),
2554625547 }
2554725548
......@@ -25598,7 +25599,7 @@ pub fn validateVarType(
2559825599 if (is_extern) {
2559925600 if (!var_ty.validateExtern(.other, zcu)) {
2560025601 const msg = msg: {
25601 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(pt)});
25602 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(zcu)});
2560225603 errdefer msg.destroy(sema.gpa);
2560325604 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
2560425605 break :msg msg;
......@@ -25611,7 +25612,7 @@ pub fn validateVarType(
2561125612 block,
2561225613 src,
2561325614 "non-extern variable with opaque type '{f}'",
25614 .{var_ty.fmt(pt)},
25615 .{var_ty.fmt(zcu)},
2561525616 );
2561625617 }
2561725618 }
......@@ -25619,7 +25620,7 @@ pub fn validateVarType(
2561925620 if (!var_ty.comptimeOnly(zcu)) return;
2562025621
2562125622 const msg = msg: {
25622 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(pt)});
25623 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(zcu)});
2562325624 errdefer msg.destroy(sema.gpa);
2562425625
2562525626 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
......@@ -25668,7 +25669,7 @@ fn explainWhyTypeIsComptime(
2566825669 .optional => try sema.explainWhyTypeIsComptime(msg, src, ty.optionalChild(zcu)),
2566925670 .error_union => try sema.explainWhyTypeIsComptime(msg, src, ty.errorUnionPayload(zcu)),
2567025671
25671 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(pt)}),
25672 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(zcu)}),
2567225673 .type => try sema.errNote(src, msg, "types are not available at runtime", .{}),
2567325674
2567425675 .@"struct" => if (zcu.typeToStruct(ty)) |struct_type| {
......@@ -25690,7 +25691,7 @@ fn explainWhyTypeIsComptime(
2569025691 if (field_val_ip != .none) continue;
2569125692 const field_ty: Type = .fromInterned(field_ty_ip);
2569225693 if (!field_ty.comptimeOnly(zcu)) continue;
25693 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(pt)});
25694 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(zcu)});
2569425695 return sema.explainWhyTypeIsComptime(msg, src, field_ty);
2569525696 }
2569625697 unreachable;
......@@ -25751,7 +25752,7 @@ pub fn explainWhyTypeIsNotExtern(
2575125752 }
2575225753 },
2575325754
25754 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(pt)}),
25755 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(zcu)}),
2575525756 .pointer => if (ty.isSlice(zcu)) {
2575625757 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2575725758 } else {
......@@ -25783,7 +25784,7 @@ pub fn explainWhyTypeIsNotExtern(
2578325784 },
2578425785 .explicit => {
2578525786 const tag_ty: Type = .fromInterned(enum_obj.int_tag_type);
25786 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(pt)});
25787 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(zcu)});
2578725788 try sema.explainWhyTypeIsNotExtern(msg, ty.srcLoc(zcu), tag_ty, position);
2578825789 },
2578925790 }
......@@ -25801,7 +25802,7 @@ pub fn explainWhyTypeIsNotExtern(
2580125802 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed struct has unspecified signedness", .{}),
2580225803 .explicit => {
2580325804 const backing_int_ty: Type = .fromInterned(struct_obj.packed_backing_int_type);
25804 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});
25805 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
2580525806 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
2580625807 },
2580725808 },
......@@ -25816,7 +25817,7 @@ pub fn explainWhyTypeIsNotExtern(
2581625817 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed union has unspecified signedness", .{}),
2581725818 .explicit => {
2581825819 const backing_int_ty: Type = .fromInterned(union_obj.packed_backing_int_type);
25819 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});
25820 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
2582025821 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
2582125822 },
2582225823 },
......@@ -26270,7 +26271,7 @@ fn fieldVal(
2627026271 block,
2627126272 field_name_src,
2627226273 "no member named '{f}' in '{f}'",
26273 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26274 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2627426275 );
2627526276 }
2627626277 },
......@@ -26294,7 +26295,7 @@ fn fieldVal(
2629426295 block,
2629526296 field_name_src,
2629626297 "no member named '{f}' in '{f}'",
26297 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26298 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2629826299 );
2629926300 }
2630026301 }
......@@ -26318,7 +26319,7 @@ fn fieldVal(
2631826319 },
2631926320 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
2632026321 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26321 field_name.fmt(ip), child_type.fmt(pt),
26322 field_name.fmt(ip), child_type.fmt(zcu),
2632226323 });
2632326324 } else child_type,
2632426325 .simple_type => |t| {
......@@ -26366,7 +26367,7 @@ fn fieldVal(
2636626367 return sema.failWithBadMemberAccess(block, child_type, src, field_name);
2636726368 },
2636826369 else => return sema.failWithOwnedErrorMsg(block, msg: {
26369 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(pt)});
26370 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(zcu)});
2637026371 errdefer msg.destroy(sema.gpa);
2637126372 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
2637226373 if (child_type.zigTypeTag(zcu) == .array) try sema.errNote(src, msg, "array values have 'len' member", .{});
......@@ -26526,7 +26527,7 @@ fn fieldPtr(
2652626527 const object_ptr_ty = sema.typeOf(object_ptr);
2652726528 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
2652826529 .pointer => object_ptr_ty.childType(zcu),
26529 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(pt)}),
26530 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(zcu)}),
2653026531 };
2653126532
2653226533 // Zig allows dereferencing a single pointer during field lookup. Note that
......@@ -26581,7 +26582,7 @@ fn fieldPtr(
2658126582 block,
2658226583 field_name_src,
2658326584 "no member named '{f}' in '{f}'",
26584 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26585 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2658526586 );
2658626587 }
2658726588 },
......@@ -26618,7 +26619,7 @@ fn fieldPtr(
2661826619 block,
2661926620 field_name_src,
2662026621 "no member named '{f}' in '{f}'",
26621 .{ field_name.fmt(ip), object_ty.fmt(pt) },
26622 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
2662226623 );
2662326624 }
2662426625 },
......@@ -26642,7 +26643,7 @@ fn fieldPtr(
2664226643 },
2664326644 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
2664426645 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26645 field_name.fmt(ip), child_type.fmt(pt),
26646 field_name.fmt(ip), child_type.fmt(zcu),
2664626647 });
2664726648 } else child_type,
2664826649 .simple_type => |t| {
......@@ -26689,7 +26690,7 @@ fn fieldPtr(
2668926690 }
2669026691 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2669126692 },
26692 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(pt)}),
26693 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(zcu)}),
2669326694 }
2669426695 },
2669526696 .@"struct" => {
......@@ -26746,7 +26747,7 @@ fn fieldCallBind(
2674626747 const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c))
2674726748 raw_ptr_ty.childType(zcu)
2674826749 else
26749 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(pt)});
26750 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(zcu)});
2675026751
2675126752 // Optionally dereference a second pointer to get the concrete type.
2675226753 const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one;
......@@ -26864,7 +26865,7 @@ fn fieldCallBind(
2686426865 const msg = msg: {
2686526866 const msg = try sema.errMsg(src, "no field or member function named '{f}' in '{f}'", .{
2686626867 field_name.fmt(ip),
26867 concrete_ty.fmt(pt),
26868 concrete_ty.fmt(zcu),
2686826869 });
2686926870 errdefer msg.destroy(sema.gpa);
2687026871 try sema.addDeclaredHereNote(msg, concrete_ty);
......@@ -27100,18 +27101,18 @@ fn tupleFieldIndex(
2710027101 field_name: InternPool.NullTerminatedString,
2710127102 field_name_src: LazySrcLoc,
2710227103) CompileError!u32 {
27103 const pt = sema.pt;
27104 const ip = &pt.zcu.intern_pool;
27104 const zcu = sema.pt.zcu;
27105 const ip = &zcu.intern_pool;
2710527106 assert(!field_name.eqlSlice("len", ip));
2710627107 if (field_name.toUnsigned(ip)) |field_index| {
27107 if (field_index < tuple_ty.structFieldCount(pt.zcu)) return field_index;
27108 if (field_index < tuple_ty.structFieldCount(zcu)) return field_index;
2710827109 return sema.fail(block, field_name_src, "index '{f}' out of bounds of tuple '{f}'", .{
27109 field_name.fmt(ip), tuple_ty.fmt(pt),
27110 field_name.fmt(ip), tuple_ty.fmt(zcu),
2711027111 });
2711127112 }
2711227113
2711327114 return sema.fail(block, field_name_src, "no field named '{f}' in tuple '{f}'", .{
27114 field_name.fmt(ip), tuple_ty.fmt(pt),
27115 field_name.fmt(ip), tuple_ty.fmt(zcu),
2711527116 });
2711627117}
2711727118
......@@ -27173,7 +27174,7 @@ fn unionFieldPtr(
2717327174
2717427175 if (initializing and field_ty.classify(zcu) == .no_possible_value) {
2717527176 const msg = msg: {
27176 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
27177 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
2717727178 errdefer msg.destroy(sema.gpa);
2717827179
2717927180 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
......@@ -27328,7 +27329,7 @@ fn elemPtr(
2732827329
2732927330 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
2733027331 .pointer => indexable_ptr_ty.childType(zcu),
27331 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(pt)}),
27332 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(zcu)}),
2733227333 };
2733327334 try sema.checkIndexable(block, src, indexable_ty);
2733427335 try sema.ensureLayoutResolved(indexable_ty, src, .ptr_access);
......@@ -27454,8 +27455,8 @@ fn elemVal(
2745427455 .runtime => {},
2745527456 .one_possible_value => return .fromValue((try child_ty.onePossibleValue(pt)).?),
2745627457 .no_possible_value => switch (child_ty.zigTypeTag(zcu)) {
27457 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(pt)}),
27458 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(pt)}),
27458 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(zcu)}),
27459 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(zcu)}),
2745927460 },
2746027461 .partially_comptime, .fully_comptime => unreachable, // caught by `validateRuntimeElemAccess`
2746127462 }
......@@ -27508,7 +27509,7 @@ fn validateRuntimeElemAccess(
2750827509 const msg = try sema.errMsg(
2750927510 elem_index_src,
2751027511 "values of type '{f}' must be comptime-known, but index value is runtime-known",
27511 .{elem_ty.fmt(sema.pt)},
27512 .{elem_ty.fmt(zcu)},
2751227513 );
2751327514 errdefer msg.destroy(sema.gpa);
2751427515
......@@ -27547,7 +27548,7 @@ fn tupleElemPtr(
2754727548 const index = elem_index_val.getUnsignedInt(zcu);
2754827549 if (index == null or index.? >= field_count) {
2754927550 return sema.fail(block, elem_index_src, "index '{f}' out of bounds of tuple '{f}'", .{
27550 elem_index_val.fmtValueSema(pt, sema), tuple_ty.fmt(pt),
27551 elem_index_val.fmtValueSema(sema), tuple_ty.fmt(zcu),
2755127552 });
2755227553 }
2755327554
......@@ -28296,7 +28297,7 @@ fn coerceExtra(
2829628297 block,
2829728298 inst_src,
2829828299 "coercion from slice to array pointer type '{f}' requires length to be known at compile-time",
28299 .{dest_ty.fmt(pt)},
28300 .{dest_ty.fmt(zcu)},
2830028301 );
2830128302 };
2830228303
......@@ -28309,7 +28310,7 @@ fn coerceExtra(
2830928310 if (!opts.report_err) return error.NotCoercible;
2831028311 return sema.failWithOwnedErrorMsg(block, msg: {
2831128312 const msg = try sema.errMsg(inst_src, "slice with undefined length cannot cast into array pointer type '{f}'", .{
28312 dest_ty.fmt(pt),
28313 dest_ty.fmt(zcu),
2831328314 });
2831428315 errdefer msg.destroy(gpa);
2831528316 try sema.errNote(inst_src, msg, "length of slice must be defined and match length of array type", .{});
......@@ -28321,7 +28322,7 @@ fn coerceExtra(
2832128322 if (!opts.report_err) return error.NotCoercible;
2832228323 return sema.failWithOwnedErrorMsg(block, msg: {
2832328324 const msg = try sema.errMsg(inst_src, "slice of length {d} cannot cast into array pointer type '{f}'", .{
28324 slice_len, dest_ty.fmt(pt),
28325 slice_len, dest_ty.fmt(zcu),
2832528326 });
2832628327 errdefer msg.destroy(gpa);
2832728328 try sema.errNote(inst_src, msg, "length of slice must match length of array type", .{});
......@@ -28376,7 +28377,7 @@ fn coerceExtra(
2837628377 block,
2837728378 inst_src,
2837828379 "array literal requires address-of operator (&) to coerce to slice type '{f}'",
28379 .{dest_ty.fmt(pt)},
28380 .{dest_ty.fmt(zcu)},
2838028381 );
2838128382 }
2838228383
......@@ -28401,7 +28402,7 @@ fn coerceExtra(
2840128402 if (!dest_info.flags.is_const) {
2840228403 if (!opts.report_err) return error.NotCoercible;
2840328404 const err_msg = err_msg: {
28404 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(pt)});
28405 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(zcu)});
2840528406 errdefer err_msg.destroy(sema.gpa);
2840628407 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2840728408 break :err_msg err_msg;
......@@ -28456,7 +28457,7 @@ fn coerceExtra(
2845628457 // comptime-known integer to other number
2845728458 if (!val.intFitsInType(dest_ty, null, zcu)) {
2845828459 if (!opts.report_err) return error.NotCoercible;
28459 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) });
28460 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) });
2846028461 }
2846128462 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2846228463 .undef => .fromValue(try dest_ty.onePossibleValue(pt) orelse try pt.undefValue(dest_ty)),
......@@ -28500,7 +28501,7 @@ fn coerceExtra(
2850028501 block,
2850128502 inst_src,
2850228503 "type '{f}' cannot represent float value '{f}'",
28503 .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) },
28504 .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) },
2850428505 );
2850528506 }
2850628507 return Air.internedToRef(result_val.toIntern());
......@@ -28559,7 +28560,7 @@ fn coerceExtra(
2855928560 block,
2856028561 inst_src,
2856128562 "type '{f}' cannot represent integer value '{f}'",
28562 .{ dest_ty.fmt(pt), val.fmtValue(pt) },
28563 .{ dest_ty.fmt(zcu), val.fmtValue(zcu) },
2856328564 );
2856428565 }
2856528566 return .fromValue(result_val);
......@@ -28574,7 +28575,7 @@ fn coerceExtra(
2857428575 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
2857528576 if (!opts.report_err) return error.NotCoercible;
2857628577 return sema.fail(block, inst_src, "no field named '{f}' in enum '{f}'", .{
28577 string.fmt(&zcu.intern_pool), dest_ty.fmt(pt),
28578 string.fmt(&zcu.intern_pool), dest_ty.fmt(zcu),
2857828579 });
2857928580 };
2858028581 return Air.internedToRef((try pt.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern());
......@@ -28703,7 +28704,7 @@ fn coerceExtra(
2870328704 errdefer msg.destroy(sema.gpa);
2870428705
2870528706 if (dest_is_npv) {
28706 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(pt)});
28707 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(zcu)});
2870728708 }
2870828709
2870928710 // E!T to T
......@@ -28887,6 +28888,7 @@ const InMemoryCoercionResult = union(enum) {
2888728888
2888828889 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {
2888928890 const pt = sema.pt;
28891 const zcu = pt.zcu;
2889028892 var cur = res;
2889128893 while (true) switch (cur.*) {
2889228894 .ok => unreachable,
......@@ -28903,13 +28905,13 @@ const InMemoryCoercionResult = union(enum) {
2890328905 },
2890428906 .comptime_int_not_coercible => |int| {
2890528907 try sema.errNote(src, msg, "type '{f}' cannot represent value '{f}'", .{
28906 int.wanted.fmt(pt), int.actual.fmtValueSema(pt, sema),
28908 int.wanted.fmt(zcu), int.actual.fmtValueSema(sema),
2890728909 });
2890828910 break;
2890928911 },
2891028912 .error_union_payload => |pair| {
2891128913 try sema.errNote(src, msg, "error union payload '{f}' cannot cast into error union payload '{f}'", .{
28912 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28914 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2891328915 });
2891428916 cur = pair.child;
2891528917 },
......@@ -28922,22 +28924,22 @@ const InMemoryCoercionResult = union(enum) {
2892228924 .array_sentinel => |sentinel| {
2892328925 if (sentinel.wanted.toIntern() == .unreachable_value) {
2892428926 try sema.errNote(src, msg, "source array cannot be guaranteed to maintain '{f}' sentinel", .{
28925 sentinel.actual.fmtValueSema(pt, sema),
28927 sentinel.actual.fmtValueSema(sema),
2892628928 });
2892728929 } else if (sentinel.actual.toIntern() == .unreachable_value) {
2892828930 try sema.errNote(src, msg, "destination array requires '{f}' sentinel", .{
28929 sentinel.wanted.fmtValueSema(pt, sema),
28931 sentinel.wanted.fmtValueSema(sema),
2893028932 });
2893128933 } else {
2893228934 try sema.errNote(src, msg, "array sentinel '{f}' cannot cast into array sentinel '{f}'", .{
28933 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
28935 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
2893428936 });
2893528937 }
2893628938 break;
2893728939 },
2893828940 .array_elem => |pair| {
2893928941 try sema.errNote(src, msg, "array element type '{f}' cannot cast into array element type '{f}'", .{
28940 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28942 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2894128943 });
2894228944 cur = pair.child;
2894328945 },
......@@ -28949,19 +28951,19 @@ const InMemoryCoercionResult = union(enum) {
2894928951 },
2895028952 .vector_elem => |pair| {
2895128953 try sema.errNote(src, msg, "vector element type '{f}' cannot cast into vector element type '{f}'", .{
28952 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28954 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2895328955 });
2895428956 cur = pair.child;
2895528957 },
2895628958 .optional_shape => |pair| {
2895728959 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28958 pair.actual.optionalChild(pt.zcu).fmt(pt), pair.wanted.optionalChild(pt.zcu).fmt(pt),
28960 pair.actual.optionalChild(pt.zcu).fmt(zcu), pair.wanted.optionalChild(pt.zcu).fmt(zcu),
2895928961 });
2896028962 break;
2896128963 },
2896228964 .optional_child => |pair| {
2896328965 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28964 pair.actual.fmt(pt), pair.wanted.fmt(pt),
28966 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2896528967 });
2896628968 cur = pair.child;
2896728969 },
......@@ -29025,7 +29027,7 @@ const InMemoryCoercionResult = union(enum) {
2902529027 },
2902629028 .fn_param => |param| {
2902729029 try sema.errNote(src, msg, "parameter {d} '{f}' cannot cast into '{f}'", .{
29028 param.index, param.actual.fmt(pt), param.wanted.fmt(pt),
29030 param.index, param.actual.fmt(zcu), param.wanted.fmt(zcu),
2902929031 });
2903029032 cur = param.child;
2903129033 },
......@@ -29035,13 +29037,13 @@ const InMemoryCoercionResult = union(enum) {
2903529037 },
2903629038 .fn_return_type => |pair| {
2903729039 try sema.errNote(src, msg, "return type '{f}' cannot cast into return type '{f}'", .{
29038 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29040 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2903929041 });
2904029042 cur = pair.child;
2904129043 },
2904229044 .ptr_child => |pair| {
2904329045 try sema.errNote(src, msg, "pointer type child '{f}' cannot cast into pointer type child '{f}'", .{
29044 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29046 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2904529047 });
2904629048 cur = pair.child;
2904729049 },
......@@ -29052,11 +29054,11 @@ const InMemoryCoercionResult = union(enum) {
2905229054 .ptr_sentinel => |sentinel| {
2905329055 if (sentinel.actual.toIntern() != .unreachable_value) {
2905429056 try sema.errNote(src, msg, "pointer sentinel '{f}' cannot cast into pointer sentinel '{f}'", .{
29055 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
29057 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
2905629058 });
2905729059 } else {
2905829060 try sema.errNote(src, msg, "destination pointer requires '{f}' sentinel", .{
29059 sentinel.wanted.fmtValueSema(pt, sema),
29061 sentinel.wanted.fmtValueSema(sema),
2906029062 });
2906129063 }
2906229064 break;
......@@ -29070,11 +29072,11 @@ const InMemoryCoercionResult = union(enum) {
2907029072 const actual_allow_zero = pair.actual.ptrAllowsZero(pt.zcu);
2907129073 if (actual_allow_zero and !wanted_allow_zero) {
2907229074 try sema.errNote(src, msg, "'{f}' could have null values which are illegal in type '{f}'", .{
29073 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29075 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2907429076 });
2907529077 } else {
2907629078 try sema.errNote(src, msg, "mutable '{f}' would allow illegal null values stored to type '{f}'", .{
29077 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29079 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2907829080 });
2907929081 }
2908029082 break;
......@@ -29086,7 +29088,7 @@ const InMemoryCoercionResult = union(enum) {
2908629088 try sema.errNote(src, msg, "cast discards const qualifier", .{});
2908729089 } else {
2908829090 try sema.errNote(src, msg, "mutable '{f}' would allow illegal const pointers stored to type '{f}'", .{
29089 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29091 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2909029092 });
2909129093 }
2909229094 break;
......@@ -29098,7 +29100,7 @@ const InMemoryCoercionResult = union(enum) {
2909829100 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
2909929101 } else {
2910029102 try sema.errNote(src, msg, "mutable '{f}' would allow illegal volatile pointers stored to type '{f}'", .{
29101 pair.wanted.fmt(pt), pair.actual.fmt(pt),
29103 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
2910229104 });
2910329105 }
2910429106 break;
......@@ -29124,13 +29126,13 @@ const InMemoryCoercionResult = union(enum) {
2912429126 },
2912529127 .double_ptr_to_anyopaque => |pair| {
2912629128 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{f}' to anyopaque pointer '{f}'", .{
29127 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29129 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2912829130 });
2912929131 break;
2913029132 },
2913129133 .slice_to_anyopaque => |pair| {
2913229134 try sema.errNote(src, msg, "cannot implicitly cast slice '{f}' to anyopaque pointer '{f}'", .{
29133 pair.actual.fmt(pt), pair.wanted.fmt(pt),
29135 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
2913429136 });
2913529137 try sema.errNote(src, msg, "consider using '.ptr'", .{});
2913629138 break;
......@@ -29881,7 +29883,7 @@ fn coerceVarArgParam(
2988129883 const coerced_ty = sema.typeOf(coerced);
2988229884 if (!coerced_ty.validateExtern(.param_ty, zcu)) {
2988329885 const msg = msg: {
29884 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(pt)});
29886 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(zcu)});
2988529887 errdefer msg.destroy(sema.gpa);
2988629888
2988729889 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
......@@ -29948,7 +29950,7 @@ fn storePtr2(
2994829950
2994929951 // We're performing the store at runtime, so the pointee type must not be comptime-only.
2995029952 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
29951 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(pt)});
29953 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(zcu)});
2995229954 errdefer msg.destroy(zcu.gpa);
2995329955 try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{});
2995429956 break :msg msg;
......@@ -30104,13 +30106,13 @@ fn storePtrVal(
3010430106 block,
3010530107 src,
3010630108 "comptime dereference requires '{f}' to have a well-defined layout",
30107 .{ty.fmt(pt)},
30109 .{ty.fmt(zcu)},
3010830110 ),
3010930111 .out_of_bounds => |ty| return sema.fail(
3011030112 block,
3011130113 src,
3011230114 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
30113 .{ ptr_ty.fmt(pt), ty.fmt(pt) },
30115 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
3011430116 ),
3011530117 .exceeds_host_size => return sema.fail(block, src, "bit-pointer target exceeds host size", .{}),
3011630118 }
......@@ -30322,7 +30324,7 @@ fn coerceCompatiblePtrs(
3032230324 const inst_ty = sema.typeOf(inst);
3032330325 if (sema.resolveValue(inst)) |val| {
3032430326 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {
30325 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});
30327 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
3032630328 }
3032730329 // The comptime Value representation is compatible with both types.
3032830330 return Air.internedToRef(
......@@ -30393,7 +30395,7 @@ fn coerceEnumToUnion(
3039330395 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {
3039430396 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {
3039530397 return sema.fail(block, inst_src, "union '{f}' has no tag with value '{f}'", .{
30396 union_ty.fmt(pt), val.fmtValueSema(pt, sema),
30398 union_ty.fmt(zcu), val.fmtValueSema(sema),
3039730399 });
3039830400 };
3039930401
......@@ -30407,7 +30409,7 @@ fn coerceEnumToUnion(
3040730409 )),
3040830410
3040930411 .no_possible_value => return sema.failWithOwnedErrorMsg(block, msg: {
30410 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});
30412 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
3041130413 errdefer msg.destroy(sema.gpa);
3041230414 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
3041330415 field_name.fmt(ip),
......@@ -30418,8 +30420,8 @@ fn coerceEnumToUnion(
3041830420
3041930421 else => return sema.failWithOwnedErrorMsg(block, msg: {
3042030422 const msg = try sema.errMsg(inst_src, "coercion from enum '{f}' to union '{f}' must initialize '{f}' field '{f}'", .{
30421 inst_ty.fmt(pt), union_ty.fmt(pt),
30422 field_ty.fmt(pt), field_name.fmt(ip),
30423 inst_ty.fmt(zcu), union_ty.fmt(zcu),
30424 field_ty.fmt(zcu), field_name.fmt(ip),
3042330425 });
3042430426 errdefer msg.destroy(sema.gpa);
3042530427
......@@ -30435,7 +30437,7 @@ fn coerceEnumToUnion(
3043530437 if (enum_ty.isNonexhaustiveEnum(zcu)) {
3043630438 const msg = msg: {
3043730439 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{f}' from non-exhaustive enum", .{
30438 union_ty.fmt(pt),
30440 union_ty.fmt(zcu),
3043930441 });
3044030442 errdefer msg.destroy(sema.gpa);
3044130443 try sema.addDeclaredHereNote(msg, enum_ty);
......@@ -30463,7 +30465,7 @@ fn coerceEnumToUnion(
3046330465 const msg = try sema.errMsg(
3046430466 inst_src,
3046530467 "runtime coercion from enum '{f}' to union '{f}' which has non-void fields",
30466 .{ enum_ty.fmt(pt), union_ty.fmt(pt) },
30468 .{ enum_ty.fmt(zcu), union_ty.fmt(zcu) },
3046730469 );
3046830470 errdefer msg.destroy(sema.gpa);
3046930471
......@@ -30479,7 +30481,7 @@ fn coerceEnumToUnion(
3047930481 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' has {s} '{f}'", .{
3048030482 field_name.fmt(ip),
3048130483 ty_description,
30482 field_ty.fmt(pt),
30484 field_ty.fmt(zcu),
3048330485 });
3048430486 }
3048530487 try sema.addDeclaredHereNote(msg, union_ty);
......@@ -31089,7 +31091,7 @@ fn analyzeLoad(
3108931091 const ptr_ty = sema.typeOf(ptr);
3109031092 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
3109131093 .pointer => ptr_ty.childType(zcu),
31092 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)}),
31094 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)}),
3109331095 };
3109431096
3109531097 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
......@@ -31100,11 +31102,11 @@ fn analyzeLoad(
3110031102
3110131103 const comptime_only = switch (elem_ty.classify(zcu)) {
3110231104 .no_possible_value => switch (elem_ty.zigTypeTag(zcu)) {
31103 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(pt)}),
31105 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(zcu)}),
3110431106 else => {
3110531107 // Loading an uninstantiable type always invokes Illegal Behavior.
3110631108 if (block.isComptime()) {
31107 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(pt)});
31109 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(zcu)});
3110831110 } else if (block.wantSafety()) {
3110931111 try sema.safetyPanic(block, src, .load_uninstantiable_type);
3111031112 return .unreachable_value;
......@@ -31129,9 +31131,9 @@ fn analyzeLoad(
3112931131 }
3113031132
3113131133 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
31132 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(pt)});
31134 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(zcu)});
3113331135 errdefer msg.destroy(zcu.gpa);
31134 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(pt)});
31136 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(zcu)});
3113531137 break :msg msg;
3113631138 });
3113731139
......@@ -31439,7 +31441,7 @@ fn analyzeSlice(
3143931441 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
3144031442 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
3144131443 .pointer => ptr_ptr_ty.childType(zcu),
31442 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(pt)}),
31444 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(zcu)}),
3144331445 };
3144431446
3144531447 var array_ty = ptr_ptr_child_ty;
......@@ -31490,8 +31492,8 @@ fn analyzeSlice(
3149031492 msg,
3149131493 "expected '{f}', found '{f}'",
3149231494 .{
31493 Value.zero_comptime_int.fmtValueSema(pt, sema),
31494 start_value.fmtValueSema(pt, sema),
31495 Value.zero_comptime_int.fmtValueSema(sema),
31496 start_value.fmtValueSema(sema),
3149531497 },
3149631498 );
3149731499 break :msg msg;
......@@ -31506,8 +31508,8 @@ fn analyzeSlice(
3150631508 msg,
3150731509 "expected '{f}', found '{f}'",
3150831510 .{
31509 Value.one_comptime_int.fmtValueSema(pt, sema),
31510 end_value.fmtValueSema(pt, sema),
31511 Value.one_comptime_int.fmtValueSema(sema),
31512 end_value.fmtValueSema(sema),
3151131513 },
3151231514 );
3151331515 break :msg msg;
......@@ -31520,7 +31522,7 @@ fn analyzeSlice(
3152031522 block,
3152131523 end_src,
3152231524 "end index {f} out of bounds for slice of single-item pointer",
31523 .{end_value.fmtValueSema(pt, sema)},
31525 .{end_value.fmtValueSema(sema)},
3152431526 );
3152531527 }
3152631528 }
......@@ -31566,7 +31568,7 @@ fn analyzeSlice(
3156631568 elem_ty = ptr_ptr_child_ty.childType(zcu);
3156731569 },
3156831570 },
31569 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(pt)}),
31571 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(zcu)}),
3157031572 }
3157131573
3157231574 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
......@@ -31618,8 +31620,8 @@ fn analyzeSlice(
3161831620 end_src,
3161931621 "end index {f} out of bounds for array of length {f}{s}",
3162031622 .{
31621 end_val.fmtValueSema(pt, sema),
31622 len_val.fmtValueSema(pt, sema),
31623 end_val.fmtValueSema(sema),
31624 len_val.fmtValueSema(sema),
3162331625 sentinel_label,
3162431626 },
3162531627 );
......@@ -31663,7 +31665,7 @@ fn analyzeSlice(
3166331665 end_src,
3166431666 "end index {f} out of bounds for slice of length {d}{s}",
3166531667 .{
31666 end_val.fmtValueSema(pt, sema),
31668 end_val.fmtValueSema(sema),
3166731669 slice_val.sliceLen(zcu),
3166831670 sentinel_label,
3166931671 },
......@@ -31714,9 +31716,9 @@ fn analyzeSlice(
3171431716 const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{});
3171531717 errdefer msg.destroy(sema.gpa);
3171631718 if (ptr_sentinel) |current| {
31717 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(pt), provided.fmtValue(pt) });
31719 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(zcu), provided.fmtValue(zcu) });
3171831720 } else {
31719 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(pt)});
31721 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(zcu)});
3172031722 }
3172131723 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
3172231724 break :msg msg;
......@@ -31760,8 +31762,8 @@ fn analyzeSlice(
3176031762 start_src,
3176131763 "start index {f} is larger than end index {f}",
3176231764 .{
31763 start_val.fmtValueSema(pt, sema),
31764 end_val.fmtValueSema(pt, sema),
31765 start_val.fmtValueSema(sema),
31766 end_val.fmtValueSema(sema),
3176531767 },
3176631768 );
3176731769 }
......@@ -31783,13 +31785,13 @@ fn analyzeSlice(
3178331785 block,
3178431786 src,
3178531787 "comptime dereference requires '{f}' to have a well-defined layout",
31786 .{ty.fmt(pt)},
31788 .{ty.fmt(zcu)},
3178731789 ),
3178831790 .out_of_bounds => |ty| return sema.fail(
3178931791 block,
3179031792 end_src,
3179131793 "slice end index {d} exceeds bounds of containing decl of type '{f}'",
31792 .{ end_int, ty.fmt(pt) },
31794 .{ end_int, ty.fmt(zcu) },
3179331795 ),
3179431796 };
3179531797
......@@ -31798,8 +31800,8 @@ fn analyzeSlice(
3179831800 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3179931801 errdefer msg.destroy(sema.gpa);
3180031802 try sema.errNote(src, msg, "expected '{f}', found '{f}'", .{
31801 expected_sentinel.fmtValueSema(pt, sema),
31802 actual_sentinel.fmtValueSema(pt, sema),
31803 expected_sentinel.fmtValueSema(sema),
31804 actual_sentinel.fmtValueSema(sema),
3180331805 });
3180431806
3180531807 break :msg msg;
......@@ -32611,7 +32613,7 @@ const PeerResolveResult = union(enum) {
3261132613 instructions: []const Air.Inst.Ref,
3261232614 candidate_srcs: PeerTypeCandidateSrc,
3261332615 ) !*Zcu.ErrorMsg {
32614 const pt = sema.pt;
32616 const zcu = sema.pt.zcu;
3261532617
3261632618 var opt_msg: ?*Zcu.ErrorMsg = null;
3261732619 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
......@@ -32637,7 +32639,7 @@ const PeerResolveResult = union(enum) {
3263732639 },
3263832640 .field_error => |field_error| {
3263932641 const fmt = "struct field '{f}' has conflicting types";
32640 const args = .{field_error.field_name.fmt(&pt.zcu.intern_pool)};
32642 const args = .{field_error.field_name.fmt(&zcu.intern_pool)};
3264132643 if (opt_msg) |msg| {
3264232644 try sema.errNote(src, msg, fmt, args);
3264332645 } else {
......@@ -32669,8 +32671,8 @@ const PeerResolveResult = union(enum) {
3266932671
3267032672 const fmt = "incompatible types: '{f}' and '{f}'";
3267132673 const args = .{
32672 conflict_tys[0].fmt(pt),
32673 conflict_tys[1].fmt(pt),
32674 conflict_tys[0].fmt(zcu),
32675 conflict_tys[1].fmt(zcu),
3267432676 };
3267532677 const msg = if (opt_msg) |msg| msg: {
3267632678 try sema.errNote(src, msg, fmt, args);
......@@ -32681,8 +32683,8 @@ const PeerResolveResult = union(enum) {
3268132683 break :msg msg;
3268232684 };
3268332685
32684 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(pt)});
32685 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(pt)});
32686 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(zcu)});
32687 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(zcu)});
3268632688
3268732689 // No child error
3268832690 break;
......@@ -33911,10 +33913,10 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3391133913}
3391233914
3391333915fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
33914 const pt = sema.pt;
33915 if (!ty.isIndexable(pt.zcu)) {
33916 const zcu = sema.pt.zcu;
33917 if (!ty.isIndexable(zcu)) {
3391633918 const msg = msg: {
33917 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(pt)});
33919 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(zcu)});
3391833920 errdefer msg.destroy(sema.gpa);
3391933921 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
3392033922 try sema.addDeclaredHereNote(msg, ty);
......@@ -33939,7 +33941,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
3393933941 }
3394033942 }
3394133943 const msg = msg: {
33942 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(pt)});
33944 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(zcu)});
3394333945 errdefer msg.destroy(sema.gpa);
3394433946 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
3394533947 break :msg msg;
......@@ -34222,8 +34224,9 @@ pub fn analyzeAsAddressSpace(
3422234224/// Asserts the value is a pointer and dereferences it.
3422334225/// Returns `null` if the pointer contents cannot be loaded at comptime.
3422434226fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value {
34225 // TODO: audit use sites to eliminate this coercion
3422634227 const pt = sema.pt;
34228 const zcu = pt.zcu;
34229 // TODO: audit use sites to eliminate this coercion
3422734230 const coerced_ptr_val = try pt.getCoerced(ptr_val, ptr_ty);
3422834231 switch (try sema.pointerDerefExtra(block, src, coerced_ptr_val)) {
3422934232 .runtime_load => return null,
......@@ -34232,13 +34235,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr
3423234235 block,
3423334236 src,
3423434237 "comptime dereference requires '{f}' to have a well-defined layout",
34235 .{ty.fmt(pt)},
34238 .{ty.fmt(zcu)},
3423634239 ),
3423734240 .out_of_bounds => |ty| return sema.fail(
3423834241 block,
3423934242 src,
3424034243 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
34241 .{ ptr_ty.fmt(pt), ty.fmt(pt) },
34244 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
3424234245 ),
3424334246 }
3424434247}
......@@ -34361,12 +34364,12 @@ fn intFromFloatScalar(
3436134364
3436234365 if (std.math.isNan(float)) {
3436334366 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{f}'", .{
34364 int_ty.fmt(pt),
34367 int_ty.fmt(zcu),
3436534368 });
3436634369 }
3436734370 if (std.math.isInf(float)) {
3436834371 return sema.fail(block, src, "float value Inf cannot be stored in integer type '{f}'", .{
34369 int_ty.fmt(pt),
34372 int_ty.fmt(zcu),
3437034373 });
3437134374 }
3437234375
......@@ -34381,7 +34384,7 @@ fn intFromFloatScalar(
3438134384 block,
3438234385 src,
3438334386 "fractional component prevents float value '{f}' from coercion to type '{f}'",
34384 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
34387 .{ val.fmtValueSema(sema), int_ty.fmt(zcu) },
3438534388 ),
3438634389 .truncate, .round, .floor, .ceil => {},
3438734390 },
......@@ -34393,7 +34396,7 @@ fn intFromFloatScalar(
3439334396 const int_info = int_ty.intInfo(zcu);
3439434397 if (!big_int.toConst().fitsInTwosComp(int_info.signedness, int_info.bits)) {
3439534398 return sema.fail(block, src, "float value '{f}' cannot be stored in integer type '{f}'", .{
34396 val.fmtValueSema(pt, sema), int_ty.fmt(pt),
34399 val.fmtValueSema(sema), int_ty.fmt(zcu),
3439734400 });
3439834401 }
3439934402 return pt.getCoerced(cti_result, int_ty);
......@@ -34639,7 +34642,7 @@ fn notePathToComptimeAllocPtr(
3463934642 else => {}, // there will be another stage
3464034643 }
3464134644
34642 const derivation = try comptime_ptr.pointerDerivation(arena, pt, sema);
34645 const derivation = try comptime_ptr.pointerDerivation(arena, zcu, sema);
3464334646
3464434647 var second_path_aw: std.Io.Writer.Allocating = .init(arena);
3464534648 defer second_path_aw.deinit();
......@@ -34647,19 +34650,19 @@ fn notePathToComptimeAllocPtr(
3464734650 const deriv_start = @import("print_value.zig").printPtrDerivation(
3464834651 derivation,
3464934652 &second_path_aw.writer,
34650 pt,
34653 zcu,
3465134654 .lvalue,
3465234655 .{ .str = inter_name },
3465334656 20,
3465434657 ) catch return error.OutOfMemory;
3465534658
34656 switch (deriv_start) {
34657 .int, .nav_ptr => unreachable,
34658 .uav_ptr => |uav| {
34659 switch (deriv_start.addr) {
34660 .int, .nav => unreachable,
34661 .uav => |uav| {
3465934662 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
34660 return .{ .new_val = .fromInterned(uav.val) };
34663 return .{ .new_val = uav };
3466134664 },
34662 .comptime_alloc_ptr => |cta_info| {
34665 .comptime_alloc => |cta_info| {
3466334666 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
3466434667 const cta = sema.getComptimeAlloc(cta_info.idx);
3466534668 if (cta.is_const) {
......@@ -34669,15 +34672,15 @@ fn notePathToComptimeAllocPtr(
3466934672 return .done;
3467034673 }
3467134674 },
34672 .comptime_field_ptr => {
34675 .comptime_field => {
3467334676 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
3467434677 try sema.errNote(src, msg, "'{s}' is a comptime field", .{inter_name});
3467534678 return .done;
3467634679 },
34677 .eu_payload_ptr,
34678 .opt_payload_ptr,
34679 .field_ptr,
34680 .elem_ptr,
34680 .eu_payload,
34681 .opt_payload,
34682 .field,
34683 .elem,
3468134684 .offset_and_cast,
3468234685 => unreachable,
3468334686 }
......@@ -35293,7 +35296,7 @@ pub fn setTypeName(
3529335296 // some tooling may not support very long symbol names.
3529435297 w.print("{f}", .{Value.fmtValueSemaFull(.{
3529535298 .val = arg_val,
35296 .pt = pt,
35299 .zcu = zcu,
3529735300 .opt_sema = sema,
3529835301 .depth = 1,
3529935302 })}) catch return error.OutOfMemory;
src/Sema/LowerZon.zig+21-19
......@@ -321,10 +321,11 @@ fn failUnsupportedResultType(
321321) Zcu.SemaError {
322322 @branchHint(.cold);
323323 const sema = self.sema;
324 const gpa = sema.gpa;
325324 const pt = sema.pt;
325 const zcu = pt.zcu;
326 const gpa = zcu.comp.gpa;
326327 return sema.failWithOwnedErrorMsg(self.block, msg: {
327 const msg = try sema.errMsg(self.import_src, "type '{f}' is not available in ZON", .{ty.fmt(pt)});
328 const msg = try sema.errMsg(self.import_src, "type '{f}' is not available in ZON", .{ty.fmt(zcu)});
328329 errdefer msg.destroy(gpa);
329330 if (opt_note) |n| try sema.errNote(self.import_src, msg, "{s}", .{n});
330331 break :msg msg;
......@@ -344,9 +345,9 @@ fn fail(
344345}
345346
346347fn lowerExprKnownResTy(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {
347 const pt = self.sema.pt;
348 const zcu = self.sema.pt.zcu;
348349 return self.lowerExprKnownResTyInner(node, res_ty) catch |err| switch (err) {
349 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(pt)}),
350 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(zcu)}),
350351 else => |e| return e,
351352 };
352353}
......@@ -357,20 +358,21 @@ fn lowerExprKnownResTyInner(
357358 res_ty: Type,
358359) (CompileError || error{WrongType})!InternPool.Index {
359360 const pt = self.sema.pt;
360 switch (res_ty.zigTypeTag(pt.zcu)) {
361 const zcu = pt.zcu;
362 switch (res_ty.zigTypeTag(zcu)) {
361363 .optional => return pt.intern(.{
362364 .opt = .{
363365 .ty = res_ty.toIntern(),
364366 .val = if (node.get(self.zoir.*) == .null) b: {
365367 break :b .none;
366368 } else b: {
367 const child_type = res_ty.optionalChild(pt.zcu);
369 const child_type = res_ty.optionalChild(zcu);
368370 break :b try self.lowerExprKnownResTyInner(node, child_type);
369371 },
370372 },
371373 }),
372374 .pointer => {
373 const ptr_info = res_ty.ptrInfo(pt.zcu);
375 const ptr_info = res_ty.ptrInfo(zcu);
374376 switch (ptr_info.flags.size) {
375377 .one => return pt.intern(.{ .ptr = .{
376378 .ty = res_ty.toIntern(),
......@@ -411,7 +413,7 @@ fn lowerExprKnownResTyInner(
411413 .frame,
412414 .@"anyframe",
413415 .void,
414 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(pt)}),
416 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(zcu)}),
415417 }
416418}
417419
......@@ -442,7 +444,7 @@ fn lowerInt(
442444 if (lhs_info.signedness == .unsigned and rhs < 0) return self.fail(
443445 node,
444446 "type '{f}' cannot represent integer value '{d}'",
445 .{ res_ty.fmt(self.sema.pt), rhs },
447 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
446448 );
447449
448450 // If lhs has less than the 32 bits rhs can hold, we need to check the max and
......@@ -458,7 +460,7 @@ fn lowerInt(
458460 return self.fail(
459461 node,
460462 "type '{f}' cannot represent integer value '{d}'",
461 .{ res_ty.fmt(self.sema.pt), rhs },
463 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
462464 );
463465 }
464466 }
......@@ -476,7 +478,7 @@ fn lowerInt(
476478 return self.fail(
477479 node,
478480 "type '{f}' cannot represent integer value '{d}'",
479 .{ res_ty.fmt(self.sema.pt), val },
481 .{ res_ty.fmt(self.sema.pt.zcu), val },
480482 );
481483 }
482484 }
......@@ -497,7 +499,7 @@ fn lowerInt(
497499 .inexact => return self.fail(
498500 node,
499501 "fractional component prevents float value '{d}' from coercion to type '{f}'",
500 .{ val, res_ty.fmt(self.sema.pt) },
502 .{ val, res_ty.fmt(self.sema.pt.zcu) },
501503 ),
502504 .exact => {},
503505 }
......@@ -508,7 +510,7 @@ fn lowerInt(
508510 return self.fail(
509511 node,
510512 "type '{f}' cannot represent integer value '{d}'",
511 .{ res_ty.fmt(self.sema.pt), val },
513 .{ res_ty.fmt(self.sema.pt.zcu), val },
512514 );
513515 }
514516
......@@ -530,7 +532,7 @@ fn lowerInt(
530532 return self.fail(
531533 node,
532534 "type '{f}' cannot represent integer value '{d}'",
533 .{ res_ty.fmt(self.sema.pt), val },
535 .{ res_ty.fmt(self.sema.pt.zcu), val },
534536 );
535537 }
536538 }
......@@ -564,7 +566,7 @@ fn lowerFloat(
564566 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
565567 node,
566568 "expected type '{f}'",
567 .{res_ty.fmt(self.sema.pt)},
569 .{res_ty.fmt(self.sema.pt.zcu)},
568570 );
569571 break :b try self.sema.pt.floatValue(res_ty, std.math.inf(f128));
570572 },
......@@ -572,7 +574,7 @@ fn lowerFloat(
572574 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
573575 node,
574576 "expected type '{f}'",
575 .{res_ty.fmt(self.sema.pt)},
577 .{res_ty.fmt(self.sema.pt.zcu)},
576578 );
577579 break :b try self.sema.pt.floatValue(res_ty, -std.math.inf(f128));
578580 },
......@@ -580,7 +582,7 @@ fn lowerFloat(
580582 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
581583 node,
582584 "expected type '{f}'",
583 .{res_ty.fmt(self.sema.pt)},
585 .{res_ty.fmt(self.sema.pt.zcu)},
584586 );
585587 break :b try self.sema.pt.floatValue(res_ty, std.math.nan(f128));
586588 },
......@@ -645,7 +647,7 @@ fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I
645647 node,
646648 "enum {f} has no member named '{f}'",
647649 .{
648 res_ty.fmt(self.sema.pt),
650 res_ty.fmt(self.sema.pt.zcu),
649651 std.zig.fmtId(field_name.get(self.zoir.*)),
650652 },
651653 );
......@@ -939,7 +941,7 @@ fn lowerUnion(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
939941 .struct_literal => b: {
940942 const fields: @FieldType(Zoir.Node, "struct_literal") = switch (node.get(self.zoir.*)) {
941943 .struct_literal => |fields| fields,
942 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt)}),
944 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt.zcu)}),
943945 };
944946 if (fields.names.len != 1) {
945947 return error.WrongType;
src/Sema/type_resolution.zig+25-25
......@@ -317,7 +317,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
317317 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
318318 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
319319 return sema.failWithOwnedErrorMsg(&block, msg: {
320 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});
320 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
321321 errdefer msg.destroy(gpa);
322322 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
323323 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -328,7 +328,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
328328 if (field_ty.isSpirvRuntimeArray(zcu)) {
329329 if (struct_obj.layout != .@"extern") {
330330 return sema.failWithOwnedErrorMsg(&block, msg: {
331 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
331 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
332332 errdefer msg.destroy(gpa);
333333 try sema.errNote(field_name_src, msg, "while checking this field", .{});
334334 break :msg msg;
......@@ -336,7 +336,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
336336 }
337337 if (field_index != fields_len - 1) {
338338 return sema.failWithOwnedErrorMsg(&block, msg: {
339 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(pt)});
339 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(zcu)});
340340 errdefer msg.destroy(gpa);
341341 try sema.errNote(field_name_src, msg, "while checking this field", .{});
342342 break :msg msg;
......@@ -346,7 +346,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
346346 const elem_ty: Type = field_ty.childType(zcu);
347347 if (elem_ty.zigTypeTag(zcu) == .spirv) {
348348 return sema.failWithOwnedErrorMsg(&block, msg: {
349 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(pt)});
349 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(zcu)});
350350 errdefer msg.destroy(gpa);
351351 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
352352 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -355,7 +355,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
355355 }
356356 } else {
357357 return sema.failWithOwnedErrorMsg(&block, msg: {
358 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(pt)});
358 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(zcu)});
359359 errdefer msg.destroy(gpa);
360360 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
361361 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -366,7 +366,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
366366
367367 if (struct_obj.layout == .@"extern" and !field_ty.validateExtern(.struct_field, zcu)) {
368368 return sema.failWithOwnedErrorMsg(&block, msg: {
369 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
369 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
370370 errdefer msg.destroy(gpa);
371371 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .struct_field);
372372 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -523,7 +523,7 @@ fn resolvePackedStructLayout(
523523 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
524524 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
525525 return sema.failWithOwnedErrorMsg(block, msg: {
526 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});
526 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
527527 errdefer msg.destroy(gpa);
528528 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
529529 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -531,7 +531,7 @@ fn resolvePackedStructLayout(
531531 });
532532 }
533533 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
534 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
534 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
535535 errdefer msg.destroy(gpa);
536536 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
537537 break :msg msg;
......@@ -575,7 +575,7 @@ fn resolvePackedStructLayout(
575575 block,
576576 backing_int_ty_src,
577577 "expected backing integer type, found '{f}'",
578 .{backing_ty.fmt(pt)},
578 .{backing_ty.fmt(zcu)},
579579 );
580580 if (field_bits != backing_ty.intInfo(zcu).bits) return sema.failWithOwnedErrorMsg(block, msg: {
581581 const src = struct_ty.srcLoc(zcu);
......@@ -585,7 +585,7 @@ fn resolvePackedStructLayout(
585585 backing_int_ty_src,
586586 msg,
587587 "backing integer '{f}' has bit width '{d}'",
588 .{ backing_ty.fmt(pt), backing_ty.bitSize(zcu) },
588 .{ backing_ty.fmt(zcu), backing_ty.bitSize(zcu) },
589589 );
590590 try sema.errNote(src, msg, "struct fields have total bit width '{d}'", .{field_bits});
591591 break :msg msg;
......@@ -798,7 +798,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
798798 &block,
799799 block.src(.container_arg),
800800 "expected enum tag type, found '{f}'",
801 .{tag_ty.fmt(pt)},
801 .{tag_ty.fmt(zcu)},
802802 );
803803 break :validated_tag_ty tag_ty;
804804 },
......@@ -947,7 +947,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
947947 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
948948 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
949949 return sema.failWithOwnedErrorMsg(&block, msg: {
950 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});
950 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
951951 errdefer msg.destroy(gpa);
952952 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
953953 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -956,7 +956,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
956956 }
957957 if (field_ty.zigTypeTag(zcu) == .spirv) {
958958 return sema.failWithOwnedErrorMsg(&block, msg: {
959 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)});
959 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)});
960960 errdefer msg.destroy(gpa);
961961 try sema.addDeclaredHereNote(msg, field_ty);
962962 break :msg msg;
......@@ -964,7 +964,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
964964 }
965965 if (union_obj.layout == .@"extern" and !field_ty.validateExtern(.union_field, zcu)) {
966966 return sema.failWithOwnedErrorMsg(&block, msg: {
967 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
967 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
968968 errdefer msg.destroy(gpa);
969969 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .union_field);
970970 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -1081,7 +1081,7 @@ fn failUnionFieldMismatch(sema: *Sema, block: *Block, union_field_names: []const
10811081 }
10821082 const union_field_src = block.src(.{ .container_field_name = @intCast(union_field_index) });
10831083 return sema.failWithOwnedErrorMsg(block, msg: {
1084 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(pt) });
1084 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(zcu) });
10851085 errdefer msg.destroy(gpa);
10861086 try sema.addDeclaredHereNote(msg, enum_tag_ty);
10871087 break :msg msg;
......@@ -1153,7 +1153,7 @@ fn resolvePackedUnionLayout(
11531153 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
11541154 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
11551155 return sema.failWithOwnedErrorMsg(block, msg: {
1156 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});
1156 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
11571157 errdefer msg.destroy(gpa);
11581158 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
11591159 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -1161,7 +1161,7 @@ fn resolvePackedUnionLayout(
11611161 });
11621162 }
11631163 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
1164 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});
1164 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
11651165 errdefer msg.destroy(gpa);
11661166 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
11671167 break :msg msg;
......@@ -1199,7 +1199,7 @@ fn resolvePackedUnionLayout(
11991199 block,
12001200 backing_int_ty_src,
12011201 "expected backing integer type, found '{f}'",
1202 .{backing_ty.fmt(pt)},
1202 .{backing_ty.fmt(zcu)},
12031203 );
12041204 const backing_int_bits = backing_ty.intInfo(zcu).bits;
12051205 for (union_obj.field_types.get(ip), 0..) |field_type_ip, field_idx| {
......@@ -1209,12 +1209,12 @@ fn resolvePackedUnionLayout(
12091209 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
12101210 const msg = try sema.errMsg(field_ty_src, "field bit width does not match backing integer", .{});
12111211 errdefer msg.destroy(gpa);
1212 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });
1212 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
12131213 try sema.errNote(
12141214 backing_int_ty_src,
12151215 msg,
12161216 "backing integer '{f}' has bit width '{d}'",
1217 .{ backing_ty.fmt(pt), backing_int_bits },
1217 .{ backing_ty.fmt(zcu), backing_int_bits },
12181218 );
12191219 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
12201220 break :msg msg;
......@@ -1233,8 +1233,8 @@ fn resolvePackedUnionLayout(
12331233 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
12341234 const msg = try sema.errMsg(field_ty_src, "field bit width does not match earlier field", .{});
12351235 errdefer msg.destroy(gpa);
1236 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });
1237 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(pt), first_field_bits });
1236 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
1237 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(zcu), first_field_bits });
12381238 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
12391239 break :msg msg;
12401240 });
......@@ -1421,7 +1421,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
14211421 &block,
14221422 block.src(.container_arg),
14231423 "expected integer tag type, found '{f}'",
1424 .{int_tag_ty.fmt(pt)},
1424 .{int_tag_ty.fmt(zcu)},
14251425 ),
14261426 }
14271427 break :ty int_tag_ty;
......@@ -1532,7 +1532,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
15321532 &block,
15331533 field_val_src,
15341534 "enum tag value '{f}' too large for type '{f}'",
1535 .{ result.val.fmtValueSema(pt, sema), int_tag_ty.fmt(pt) },
1535 .{ result.val.fmtValueSema(sema), int_tag_ty.fmt(zcu) },
15361536 );
15371537 const val = result.val.toIntern();
15381538 enum_obj.field_values.get(ip)[field_idx] = val;
......@@ -1542,7 +1542,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
15421542 return sema.failWithOwnedErrorMsg(&block, msg: {
15431543 const prev_field_val_src = block.src(.{ .container_field_value = prev_field_index });
15441544 const msg = try sema.errMsg(field_val_src, "enum tag value '{f}' for field '{f}' already taken", .{
1545 Value.fromInterned(field_val).fmtValueSema(pt, sema),
1545 Value.fromInterned(field_val).fmtValueSema(sema),
15461546 enum_obj.field_names.get(ip)[field_idx].fmt(ip),
15471547 });
15481548 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
......@@ -2872,11 +2864,62 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
28722864 const ptr_info = ip.indexToKey(ptr_ty.toIntern()).ptr_type;
28732865 assert(ptr_info.flags.size == .one or ptr_info.flags.size == .c);
28742866 const aggregate_ty: Type = .fromInterned(ptr_info.child);
2867
2868 var field_ptr_info = ptr_info;
2869
2870 field_ptr_info.child = if (aggregate_ty.isSlice(zcu)) switch (field_index) {
2871 Value.slice_ptr_index => aggregate_ty.slicePtrFieldType(zcu).toIntern(),
2872 Value.slice_len_index => .usize_type,
2873 else => unreachable,
2874 } else aggregate_ty.fieldType(field_index, zcu).toIntern();
2875
2876 field_ptr_info.flags.alignment = aggregate_ty.fieldPtrAlign(ptr_info.flags.alignment, field_index, zcu);
2877
2878 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2879 aggregate_ty.containerLayout(zcu) == .@"packed")
2880 {
2881 field_ptr_info.packed_offset = packed_offset: {
2882 comptime assert(Type.packed_struct_layout_version == 2);
2883 const bit_offset = zcu.structPackedFieldBitOffset(
2884 ip.loadStructType(aggregate_ty.toIntern()),
2885 field_index,
2886 );
2887 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2888 .host_size = ptr_info.packed_offset.host_size,
2889 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2890 } else .{
2891 .host_size = switch (zcu.comp.getZigBackend()) {
2892 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2893 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2894 },
2895 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2896 };
2897 };
2898 }
2899
2900 return pt.ptrType(field_ptr_info);
2901}
2902
2903pub fn fieldPtrAlign(
2904 aggregate_ty: Type,
2905 aggregate_ptr_align: Alignment,
2906 field_index: u32,
2907 zcu: *const Zcu,
2908) Alignment {
2909 const ip = &zcu.intern_pool;
2910
28752911 aggregate_ty.assertHasLayout(zcu);
2912
2913 const aggregate_ty_align = aggregate_ty.abiAlignment(zcu);
2914 const aggregate_align: Alignment = switch (aggregate_ptr_align) {
2915 .none => aggregate_ty_align,
2916 else => |a| a,
2917 };
2918
28762919 // We only exit this `switch` for default-layout aggregates, where the field pointer alignment
28772920 // is a simple minimum of the aggregate pointer alignment and the field alignment.
2878 // `field_align` is `.none` if there is no explicit alignment annotation.
2879 const field_ty: Type, const field_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
2921 // `field_explicit_align` is `.none` if there is no explicit alignment annotation.
2922 const field_ty: Type, const field_explicit_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
28802923 .@"struct" => switch (aggregate_ty.containerLayout(zcu)) {
28812924 .auto => field: {
28822925 if (aggregate_ty.isTuple(zcu)) {
......@@ -2893,56 +2936,21 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
28932936 // `extern struct { x: u32, y: u16 }`, the `y` field is 4-byte aligned.
28942937 const field_ty = aggregate_ty.fieldType(field_index, zcu);
28952938 const field_offset = aggregate_ty.structFieldOffset(field_index, zcu);
2896 const parent_align = switch (ptr_info.flags.alignment) {
2897 .none => aggregate_ty.abiAlignment(zcu),
2898 else => |a| a,
2899 };
2900 const actual_field_align = switch (field_offset) {
2901 0 => parent_align,
2902 else => parent_align.minStrict(.fromLog2Units(@ctz(field_offset))),
2903 };
2904 const field_ptr_align: Alignment = a: {
2905 if (ptr_info.flags.alignment == .none and
2906 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2907 actual_field_align == field_ty.abiAlignment(zcu))
2908 {
2909 // There's no user-specified 'align' in sight, and the alignment from the
2910 // field offset matches the field type's natural alignment, so just use a
2911 // default-aligned pointer.
2912 break :a .none;
2913 }
2914 break :a actual_field_align;
2915 };
2916 var field_ptr_info = ptr_info;
2917 field_ptr_info.child = field_ty.toIntern();
2918 field_ptr_info.flags.alignment = field_ptr_align;
2919 return pt.ptrType(field_ptr_info);
2920 },
2921 .@"packed" => {
2922 var field_ptr_info = ptr_info;
2923 if (field_ptr_info.flags.alignment == .none) {
2924 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2939 const field_align = aggregate_align.offset(field_offset);
2940
2941 if (aggregate_ptr_align == .none and
2942 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2943 field_align == field_ty.abiAlignment(zcu))
2944 {
2945 // There's no user-specified 'align' in sight, and the alignment from the
2946 // field offset matches the field type's natural alignment, so just use a
2947 // default-aligned pointer.
2948 return .none;
29252949 }
2926 field_ptr_info.packed_offset = packed_offset: {
2927 comptime assert(Type.packed_struct_layout_version == 2);
2928 const bit_offset = zcu.structPackedFieldBitOffset(
2929 ip.loadStructType(aggregate_ty.toIntern()),
2930 field_index,
2931 );
2932 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2933 .host_size = ptr_info.packed_offset.host_size,
2934 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2935 } else .{
2936 .host_size = switch (zcu.comp.getZigBackend()) {
2937 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2938 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2939 },
2940 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2941 };
2942 };
2943 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2944 return pt.ptrType(field_ptr_info);
2950
2951 return field_align;
29452952 },
2953 .@"packed" => return aggregate_align,
29462954 },
29472955 .@"union" => switch (aggregate_ty.containerLayout(zcu)) {
29482956 .auto => field: {
......@@ -2952,30 +2960,14 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
29522960 union_obj.field_aligns.getOrNone(ip, field_index),
29532961 };
29542962 },
2955 .@"extern" => {
2963 .@"extern", .@"packed" => {
29562964 // The alignment always matches that of the union pointer. If the union pointer is
29572965 // default aligned (`.none`), we may need to explicitly align the result pointer.
2958 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2959 var field_ptr_info = ptr_info;
2960 field_ptr_info.child = field_ty.toIntern();
2961 if (field_ptr_info.flags.alignment == .none and
2962 Alignment.compareStrict(field_ty.abiAlignment(zcu), .neq, aggregate_ty.abiAlignment(zcu)))
2963 {
2964 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2965 }
2966 return pt.ptrType(field_ptr_info);
2967 },
2968 .@"packed" => {
2969 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2970 var field_ptr_info = ptr_info;
2971 if (field_ptr_info.flags.alignment == .none) {
2972 const resolved_align = aggregate_ty.abiAlignment(zcu);
2973 if (field_ty.abiAlignment(zcu) != resolved_align) {
2974 field_ptr_info.flags.alignment = resolved_align;
2975 }
2976 }
2977 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2978 return pt.ptrType(field_ptr_info);
2966 const field_ty_align = aggregate_ty.fieldType(field_index, zcu).abiAlignment(zcu);
2967 return switch (aggregate_ptr_align) {
2968 .none => if (field_ty_align == aggregate_ty_align) .none else aggregate_ty_align,
2969 else => |a| a,
2970 };
29792971 },
29802972 },
29812973 .pointer => field: {
......@@ -2988,39 +2980,31 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
29882980 },
29892981 else => unreachable,
29902982 };
2991 const field_ptr_align: Alignment = a: {
2992 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and aggregate_ty.structFieldIsComptime(field_index, zcu)) {
2993 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.
2994 break :a field_align;
2995 }
2996 const actual_field_align = switch (field_align) {
2997 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {
2998 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),
2999 .ptr_type => Type.usize.abiAlignment(zcu),
3000 else => unreachable,
3001 },
3002 else => |a| a,
3003 };
3004 const actual_aggregate_align = switch (ptr_info.flags.alignment) {
3005 .none => aggregate_ty.abiAlignment(zcu),
3006 else => |a| a,
3007 };
3008 if (actual_aggregate_align.compareStrict(.lt, actual_field_align)) {
3009 // Underaligned aggregate; use that alignment.
3010 assert(ptr_info.flags.alignment != .none);
3011 break :a actual_aggregate_align;
3012 }
3013 if (field_align == .none and actual_field_align == field_ty.abiAlignment(zcu)) {
3014 // No explicit annotation on the field (nor an unusual default), and the aggregate
3015 // alignment is irrelevant to us, so return an un-annotated pointer.
3016 break :a .none;
3017 }
3018 break :a actual_field_align;
2983 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2984 aggregate_ty.structFieldIsComptime(field_index, zcu))
2985 {
2986 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.
2987 return field_explicit_align;
2988 }
2989 const field_align = switch (field_explicit_align) {
2990 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {
2991 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),
2992 .ptr_type => Type.usize.abiAlignment(zcu),
2993 else => unreachable,
2994 },
2995 else => |a| a,
30192996 };
3020 var field_ptr_info = ptr_info;
3021 field_ptr_info.flags.alignment = field_ptr_align;
3022 field_ptr_info.child = field_ty.toIntern();
3023 return pt.ptrType(field_ptr_info);
2997 if (aggregate_align.compareStrict(.lt, field_align)) {
2998 // Underaligned aggregate; use that alignment.
2999 assert(aggregate_ptr_align == aggregate_align);
3000 return aggregate_align;
3001 }
3002 if (field_explicit_align == .none and field_align == field_ty.abiAlignment(zcu)) {
3003 // No explicit annotation on the field (nor an unusual default), and the aggregate
3004 // alignment is irrelevant to us, so return an un-annotated pointer.
3005 return .none;
3006 }
3007 return field_align;
30243008}
30253009
30263010pub fn containerTypeName(ty: Type, ip: *const InternPool) struct {
......@@ -3359,8 +3343,7 @@ pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {
33593343}
33603344
33613345/// Recursively walks the type and marks for each subtype how many times it has been seen
3362fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {
3363 const zcu = pt.zcu;
3346fn collectSubtypes(ty: Type, zcu: *Zcu, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {
33643347 const ip = &zcu.intern_pool;
33653348
33663349 const gop = try visited.getOrPut(zcu.gpa, ty);
......@@ -3371,34 +3354,34 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
33713354 }
33723355
33733356 switch (ip.indexToKey(ty.toIntern())) {
3374 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), pt, visited),
3375 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), pt, visited),
3376 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), pt, visited),
3377 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),
3357 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), zcu, visited),
3358 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), zcu, visited),
3359 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), zcu, visited),
3360 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
33783361 .error_union_type => |error_union_type| {
3379 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), pt, visited);
3362 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), zcu, visited);
33803363 if (error_union_type.payload_type != .generic_poison_type) {
3381 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), pt, visited);
3364 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), zcu, visited);
33823365 }
33833366 },
33843367 .tuple_type => |tuple| {
33853368 for (tuple.types.get(ip)) |field_ty| {
3386 try collectSubtypes(Type.fromInterned(field_ty), pt, visited);
3369 try collectSubtypes(Type.fromInterned(field_ty), zcu, visited);
33873370 }
33883371 },
33893372 .func_type => |fn_info| {
33903373 const param_types = fn_info.param_types.get(&zcu.intern_pool);
33913374 for (param_types) |param_ty| {
33923375 if (param_ty != .generic_poison_type) {
3393 try collectSubtypes(Type.fromInterned(param_ty), pt, visited);
3376 try collectSubtypes(Type.fromInterned(param_ty), zcu, visited);
33943377 }
33953378 }
33963379
33973380 if (fn_info.return_type != .generic_poison_type) {
3398 try collectSubtypes(Type.fromInterned(fn_info.return_type), pt, visited);
3381 try collectSubtypes(Type.fromInterned(fn_info.return_type), zcu, visited);
33993382 }
34003383 },
3401 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),
3384 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
34023385
34033386 // leaf types
34043387 .undef,
......@@ -3435,7 +3418,7 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
34353418 }
34363419}
34373420
3438fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMemory}!Comparison.DedupeEntry {
3421fn shouldDedupeType(ty: Type, ctx: *Comparison, zcu: *Zcu) error{OutOfMemory}!Comparison.DedupeEntry {
34393422 if (ctx.type_occurrences.get(ty)) |occ| {
34403423 if (ctx.type_dedupe_cache.get(ty)) |cached| {
34413424 return cached;
......@@ -3443,7 +3426,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
34433426
34443427 var discarding: std.Io.Writer.Discarding = .init(&.{});
34453428
3446 print(ty, &discarding.writer, pt, null) catch
3429 print(ty, &discarding.writer, zcu, null) catch
34473430 unreachable; // we are writing into a discarding writer, it should never fail
34483431
34493432 const type_len: i32 = @intCast(discarding.count);
......@@ -3460,7 +3443,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
34603443 break :b .{ .dedupe = .{ .index = ctx.placeholder_index - 1 } };
34613444 } else .dont_dedupe;
34623445
3463 try ctx.type_dedupe_cache.put(pt.zcu.gpa, ty, entry);
3446 try ctx.type_dedupe_cache.put(zcu.comp.gpa, ty, entry);
34643447
34653448 return entry;
34663449 } else {
......@@ -3491,38 +3474,37 @@ pub const Comparison = struct {
34913474 dedupe: Placeholder,
34923475 };
34933476
3494 pub fn init(types: []const Type, pt: Zcu.PerThread) error{OutOfMemory}!Comparison {
3477 pub fn init(types: []const Type, zcu: *Zcu) error{OutOfMemory}!Comparison {
34953478 var cmp: Comparison = .{
34963479 .type_occurrences = .empty,
34973480 .type_dedupe_cache = .empty,
34983481 .placeholder_index = 0,
34993482 };
35003483
3501 errdefer cmp.deinit(pt);
3484 errdefer cmp.deinit(zcu.comp.gpa);
35023485
35033486 for (types) |ty| {
3504 try collectSubtypes(ty, pt, &cmp.type_occurrences);
3487 try collectSubtypes(ty, zcu, &cmp.type_occurrences);
35053488 }
35063489
35073490 return cmp;
35083491 }
35093492
3510 pub fn deinit(cmp: *Comparison, pt: Zcu.PerThread) void {
3511 const gpa = pt.zcu.gpa;
3493 pub fn deinit(cmp: *Comparison, gpa: Allocator) void {
35123494 cmp.type_occurrences.deinit(gpa);
35133495 cmp.type_dedupe_cache.deinit(gpa);
35143496 }
35153497
3516 pub fn fmtType(ctx: *Comparison, ty: Type, pt: Zcu.PerThread) Comparison.Formatter {
3517 return .{ .ty = ty, .ctx = ctx, .pt = pt };
3498 pub fn fmtType(ctx: *Comparison, ty: Type, zcu: *Zcu) Comparison.Formatter {
3499 return .{ .ty = ty, .ctx = ctx, .zcu = zcu };
35183500 }
35193501 pub const Formatter = struct {
35203502 ty: Type,
35213503 ctx: *Comparison,
3522 pt: Zcu.PerThread,
3504 zcu: *Zcu,
35233505
35243506 pub fn format(self: Comparison.Formatter, writer: anytype) error{WriteFailed}!void {
3525 print(self.ty, writer, self.pt, self.ctx) catch return error.WriteFailed;
3507 print(self.ty, writer, self.zcu, self.ctx) catch return error.WriteFailed;
35263508 }
35273509 };
35283510};
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
......@@ -3471,7 +3471,7 @@ fn analyzeFuncBodyInner(
34713471 &inner_block,
34723472 inner_block.nodeOffset(.zero),
34733473 "cannot resolve inferred error set of {s} function type '{f}'",
3474 .{ description, fn_ty.fmt(pt) },
3474 .{ description, fn_ty.fmt(zcu) },
34753475 );
34763476 }
34773477
......@@ -4587,6 +4587,6 @@ fn printVerboseAir(
45874587 const zcu = pt.zcu;
45884588 const ip = &zcu.intern_pool;
45894589 try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)});
4590 try air.write(w, pt, liveness);
4590 try air.write(w, zcu, liveness);
45914591 try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)});
45924592}
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 },