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

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

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

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

src/Air/Verify.zig+1-1
...@@ -41,7 +41,7 @@ pub fn run(pt: Zcu.PerThread, func_index: InternPool.Index, air: *const Air) voi...@@ -41,7 +41,7 @@ pub fn run(pt: Zcu.PerThread, func_index: InternPool.Index, air: *const Air) voi
41 error.Canceled => return io.recancel(),41 error.Canceled => return io.recancel(),
42 };42 };
43 defer io.unlockStderr();43 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) {
45 error.WriteFailed => switch (stderr.file_writer.err.?) {45 error.WriteFailed => switch (stderr.file_writer.err.?) {
46 error.Canceled => return io.recancel(),46 error.Canceled => return io.recancel(),
47 else => {},47 else => {},
src/Air/print.zig+20-20
...@@ -9,7 +9,7 @@ const Type = @import("../Type.zig");...@@ -9,7 +9,7 @@ const Type = @import("../Type.zig");
9const Air = @import("../Air.zig");9const Air = @import("../Air.zig");
10const InternPool = @import("../InternPool.zig");10const 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 {
13 comptime assert(build_options.enable_debug_extensions);13 comptime assert(build_options.enable_debug_extensions);
14 const instruction_bytes = air.instructions.len *14 const instruction_bytes = air.instructions.len *
15 // Here we don't use @sizeOf(Air.Inst.Data) because it would include15 // 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...@@ -43,8 +43,8 @@ pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air
43 // zig fmt: on43 // zig fmt: on
4444
45 var writer: Writer = .{45 var writer: Writer = .{
46 .pt = pt,46 .zcu = zcu,
47 .gpa = pt.zcu.gpa,47 .gpa = zcu.comp.gpa,
48 .air = air,48 .air = air,
49 .liveness = liveness,49 .liveness = liveness,
50 .indent = 2,50 .indent = 2,
...@@ -57,13 +57,13 @@ pub fn writeInst(...@@ -57,13 +57,13 @@ pub fn writeInst(
57 air: Air,57 air: Air,
58 stream: *std.Io.Writer,58 stream: *std.Io.Writer,
59 inst: Air.Inst.Index,59 inst: Air.Inst.Index,
60 pt: Zcu.PerThread,60 zcu: *Zcu,
61 liveness: ?Air.Liveness,61 liveness: ?Air.Liveness,
62) void {62) void {
63 comptime assert(build_options.enable_debug_extensions);63 comptime assert(build_options.enable_debug_extensions);
64 var writer: Writer = .{64 var writer: Writer = .{
65 .pt = pt,65 .zcu = zcu,
66 .gpa = pt.zcu.gpa,66 .gpa = zcu.comp.gpa,
67 .air = air,67 .air = air,
68 .liveness = liveness,68 .liveness = liveness,
69 .indent = 2,69 .indent = 2,
...@@ -89,7 +89,7 @@ pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Ai...@@ -89,7 +89,7 @@ pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Ai
89}89}
9090
91const Writer = struct {91const Writer = struct {
92 pt: Zcu.PerThread,92 zcu: *Zcu,
93 gpa: Allocator,93 gpa: Allocator,
94 air: Air,94 air: Air,
95 liveness: ?Air.Liveness,95 liveness: ?Air.Liveness,
...@@ -377,7 +377,7 @@ const Writer = struct {...@@ -377,7 +377,7 @@ const Writer = struct {
377 }377 }
378378
379 fn writeType(w: *Writer, s: *std.Io.Writer, ty: Type) !void {379 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);
381 }381 }
382382
383 fn writeTy(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {383 fn writeTy(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {
...@@ -446,7 +446,7 @@ const Writer = struct {...@@ -446,7 +446,7 @@ const Writer = struct {
446 }446 }
447447
448 fn writeAggregateInit(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {448 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;
450 const ty_pl = w.air.instructions.items(.data)[@backingInt(inst)].ty_pl;450 const ty_pl = w.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
451 const vector_ty = ty_pl.ty;451 const vector_ty = ty_pl.ty;
452 const len = @as(usize, @intCast(vector_ty.arrayLen(zcu)));452 const len = @as(usize, @intCast(vector_ty.arrayLen(zcu)));
...@@ -539,7 +539,7 @@ const Writer = struct {...@@ -539,7 +539,7 @@ const Writer = struct {
539 }539 }
540540
541 fn writeShuffleOne(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {541 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);
543 try w.writeType(s, unwrapped.result_ty);543 try w.writeType(s, unwrapped.result_ty);
544 try s.writeAll(", ");544 try s.writeAll(", ");
545 try w.writeOperand(s, inst, 0, unwrapped.operand);545 try w.writeOperand(s, inst, 0, unwrapped.operand);
...@@ -548,14 +548,14 @@ const Writer = struct {...@@ -548,14 +548,14 @@ const Writer = struct {
548 if (mask_idx > 0) try s.writeAll(", ");548 if (mask_idx > 0) try s.writeAll(", ");
549 switch (mask_elem.unwrap()) {549 switch (mask_elem.unwrap()) {
550 .elem => |idx| try s.print("elem {d}", .{idx}),550 .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)}),
552 }552 }
553 }553 }
554 try s.writeByte(']');554 try s.writeByte(']');
555 }555 }
556556
557 fn writeShuffleTwo(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {557 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);
559 try w.writeType(s, unwrapped.result_ty);559 try w.writeType(s, unwrapped.result_ty);
560 try s.writeAll(", ");560 try s.writeAll(", ");
561 try w.writeOperand(s, inst, 0, unwrapped.operand_a);561 try w.writeOperand(s, inst, 0, unwrapped.operand_a);
...@@ -574,7 +574,7 @@ const Writer = struct {...@@ -574,7 +574,7 @@ const Writer = struct {
574 }574 }
575575
576 fn writeSelect(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {576 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;
578 const pl_op = w.air.instructions.items(.data)[@backingInt(inst)].pl_op;578 const pl_op = w.air.instructions.items(.data)[@backingInt(inst)].pl_op;
579 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;579 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
580580
...@@ -606,7 +606,7 @@ const Writer = struct {...@@ -606,7 +606,7 @@ const Writer = struct {
606 }606 }
607607
608 fn writeRuntimeNavPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void {608 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;
610 const ty_nav = w.air.instructions.items(.data)[@backingInt(inst)].ty_nav;610 const ty_nav = w.air.instructions.items(.data)[@backingInt(inst)].ty_nav;
611 try w.writeType(s, ty_nav.ty);611 try w.writeType(s, ty_nav.ty);
612 try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});612 try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)});
...@@ -695,7 +695,7 @@ const Writer = struct {...@@ -695,7 +695,7 @@ const Writer = struct {
695 try s.writeByte(')');695 try s.writeByte(')');
696 }696 }
697697
698 const zcu = w.pt.zcu;698 const zcu = w.zcu;
699 const ip = &zcu.intern_pool;699 const ip = &zcu.intern_pool;
700 const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers);700 const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers);
701 const clobbers_ty = clobbers_val.typeOf(zcu);701 const clobbers_ty = clobbers_val.typeOf(zcu);
...@@ -1019,11 +1019,11 @@ const Writer = struct {...@@ -1019,11 +1019,11 @@ const Writer = struct {
1019 if (@backingInt(operand) < InternPool.static_len) {1019 if (@backingInt(operand) < InternPool.static_len) {
1020 return s.print("@{}", .{operand});1020 return s.print("@{}", .{operand});
1021 } else if (operand.toInterned()) |ip_index| {1021 } else if (operand.toInterned()) |ip_index| {
1022 const pt = w.pt;1022 const zcu = w.zcu;
1023 const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf());1023 const ty = Type.fromInterned(zcu.intern_pool.indexToKey(ip_index).typeOf());
1024 try s.print("<{f}, {f}>", .{1024 try s.print("<{f}, {f}>", .{
1025 ty.fmt(pt),1025 ty.fmt(zcu),
1026 Value.fromInterned(ip_index).fmtValue(pt),1026 Value.fromInterned(ip_index).fmtValue(w.zcu),
1027 });1027 });
1028 } else {1028 } else {
1029 return w.writeInstIndex(s, operand.toIndex().?, dies);1029 return w.writeInstIndex(s, operand.toIndex().?, dies);
...@@ -1042,7 +1042,7 @@ const Writer = struct {...@@ -1042,7 +1042,7 @@ const Writer = struct {
1042 }1042 }
10431043
1044 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {1044 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
1045 const zcu = w.pt.zcu;1045 const zcu = w.zcu;
1046 return w.air.typeOfIndex(inst, &zcu.intern_pool);1046 return w.air.typeOfIndex(inst, &zcu.intern_pool);
1047 }1047 }
1048};1048};
src/Sema.zig+384-381
...@@ -910,6 +910,7 @@ const ComptimeReason = union(enum) {...@@ -910,6 +910,7 @@ const ComptimeReason = union(enum) {
910 },910 },
911911
912 fn explain(reason: ComptimeReason, sema: *Sema, src: LazySrcLoc, err_msg: *Zcu.ErrorMsg) !void {912 fn explain(reason: ComptimeReason, sema: *Sema, src: LazySrcLoc, err_msg: *Zcu.ErrorMsg) !void {
913 const zcu = sema.pt.zcu;
913 switch (reason) {914 switch (reason) {
914 .simple => |simple| {915 .simple => |simple| {
915 try sema.errNote(src, err_msg, "{s}", .{simple.message()});916 try sema.errNote(src, err_msg, "{s}", .{simple.message()});
...@@ -920,17 +921,17 @@ const ComptimeReason = union(enum) {...@@ -920,17 +921,17 @@ const ComptimeReason = union(enum) {
920 .struct_init => .{ "initializer of comptime-only struct", "must be comptime-known" },921 .struct_init => .{ "initializer of comptime-only struct", "must be comptime-known" },
921 .tuple_init => .{ "initializer of comptime-only tuple", "must be comptime-known" },922 .tuple_init => .{ "initializer of comptime-only tuple", "must be comptime-known" },
922 };923 };
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 });
924 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);925 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
925 },926 },
926 .comptime_only_param_ty => |co| {927 .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)});
928 try sema.errNote(co.param_ty_src, err_msg, "parameter type declared here", .{});929 try sema.errNote(co.param_ty_src, err_msg, "parameter type declared here", .{});
929 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);930 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
930 },931 },
931 .comptime_only_ret_ty => |co| {932 .comptime_only_ret_ty => |co| {
932 const function_with: []const u8 = if (co.is_generic_inst) "generic function instantiated with" else "function with";933 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) });
934 try sema.errNote(co.ret_ty_src, err_msg, "return type declared here", .{});935 try sema.errNote(co.ret_ty_src, err_msg, "return type declared here", .{});
935 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);936 try sema.explainWhyTypeIsComptime(err_msg, src, co.ty);
936 },937 },
...@@ -1901,7 +1902,7 @@ fn analyzeBodyInner(...@@ -1901,7 +1902,7 @@ fn analyzeBodyInner(
1901 const err_union_ty = sema.typeOf(err_union);1902 const err_union_ty = sema.typeOf(err_union);
1902 if (err_union_ty.zigTypeTag(zcu) != .error_union) {1903 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
1903 return sema.failWithOwnedErrorMsg(block, msg: {1904 return sema.failWithOwnedErrorMsg(block, msg: {
1904 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});1905 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
1905 errdefer msg.destroy(sema.gpa);1906 errdefer msg.destroy(sema.gpa);
1906 try sema.addDeclaredHereNote(msg, err_union_ty);1907 try sema.addDeclaredHereNote(msg, err_union_ty);
1907 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});1908 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
...@@ -2366,7 +2367,7 @@ pub fn failWithTooLargeShiftAmount(...@@ -2366,7 +2367,7 @@ pub fn failWithTooLargeShiftAmount(
2366 const msg = try sema.errMsg(2367 const msg = try sema.errMsg(
2367 shift_src,2368 shift_src,
2368 "shift amount '{f}' is too large for operand type '{f}'",2369 "shift amount '{f}' is too large for operand type '{f}'",
2369 .{ shift_amt.fmtValueSema(sema.pt, sema), operand_ty.fmt(sema.pt) },2370 .{ shift_amt.fmtValueSema(sema), operand_ty.fmt(sema.pt.zcu) },
2370 );2371 );
2371 errdefer msg.destroy(sema.gpa);2372 errdefer msg.destroy(sema.gpa);
2372 if (vector_index) |i| try sema.errNote(shift_src, msg, "when computing vector element at index '{d}'", .{i});2373 if (vector_index) |i| try sema.errNote(shift_src, msg, "when computing vector element at index '{d}'", .{i});
...@@ -2376,7 +2377,7 @@ pub fn failWithTooLargeShiftAmount(...@@ -2376,7 +2377,7 @@ pub fn failWithTooLargeShiftAmount(
23762377
2377pub fn failWithNegativeShiftAmount(sema: *Sema, block: *Block, src: LazySrcLoc, shift_amt: Value, vector_index: ?usize) CompileError {2378pub fn failWithNegativeShiftAmount(sema: *Sema, block: *Block, src: LazySrcLoc, shift_amt: Value, vector_index: ?usize) CompileError {
2378 return sema.failWithOwnedErrorMsg(block, msg: {2379 return sema.failWithOwnedErrorMsg(block, msg: {
2379 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema.pt, sema)});2380 const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema)});
2380 errdefer msg.destroy(sema.gpa);2381 errdefer msg.destroy(sema.gpa);
2381 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});2382 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
2382 break :msg msg;2383 break :msg msg;
...@@ -2397,9 +2398,9 @@ pub fn failWithUnsupportedComptimeShiftAmount(sema: *Sema, block: *Block, src: L...@@ -2397,9 +2398,9 @@ pub fn failWithUnsupportedComptimeShiftAmount(sema: *Sema, block: *Block, src: L
2397}2398}
23982399
2399fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {2400fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
2400 const pt = sema.pt;2401 const zcu = sema.pt.zcu;
2401 return sema.fail(block, src, "remainder division with '{f}' and '{f}': signed integers and floats must use @rem or @mod", .{2402 return sema.fail(block, src, "remainder division with '{f}' and '{f}': signed integers and floats must use @rem or @mod", .{
2402 lhs_ty.fmt(pt), rhs_ty.fmt(pt),2403 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
2403 });2404 });
2404}2405}
24052406
...@@ -2421,7 +2422,7 @@ fn failWithInvalidSwitchTagCapture(sema: *Sema, block: *Block, tag_capture_src:...@@ -2421,7 +2422,7 @@ fn failWithInvalidSwitchTagCapture(sema: *Sema, block: *Block, tag_capture_src:
2421 }2422 }
2422 return sema.failWithOwnedErrorMsg(block, msg: {2423 return sema.failWithOwnedErrorMsg(block, msg: {
2423 const msg = try sema.errMsg(tag_capture_src, "cannot capture tag of non-union type '{f}'", .{2424 const msg = try sema.errMsg(tag_capture_src, "cannot capture tag of non-union type '{f}'", .{
2424 operand_ty.fmt(pt),2425 operand_ty.fmt(zcu),
2425 });2426 });
2426 errdefer msg.destroy(sema.gpa);2427 errdefer msg.destroy(sema.gpa);
2427 try sema.addDeclaredHereNote(msg, operand_ty);2428 try sema.addDeclaredHereNote(msg, operand_ty);
...@@ -2440,7 +2441,7 @@ fn failWithAmbiguousBackingIntType(...@@ -2440,7 +2441,7 @@ fn failWithAmbiguousBackingIntType(
2440 const zcu = pt.zcu;2441 const zcu = pt.zcu;
2441 return sema.failWithOwnedErrorMsg(block, msg: {2442 return sema.failWithOwnedErrorMsg(block, msg: {
2442 const msg = try sema.errMsg(src, "{s} is ambiguous for type '{f}'", .{2443 const msg = try sema.errMsg(src, "{s} is ambiguous for type '{f}'", .{
2443 builtin_name, int_backed_ty.fmt(pt),2444 builtin_name, int_backed_ty.fmt(zcu),
2444 });2445 });
2445 errdefer msg.destroy(sema.gpa);2446 errdefer msg.destroy(sema.gpa);
2446 try sema.errNote(int_backed_ty.srcLoc(zcu), msg, "backing integer type of {t} is inferred", .{2447 try sema.errNote(int_backed_ty.srcLoc(zcu), msg, "backing integer type of {t} is inferred", .{
...@@ -2452,13 +2453,13 @@ fn failWithAmbiguousBackingIntType(...@@ -2452,13 +2453,13 @@ fn failWithAmbiguousBackingIntType(
2452}2453}
24532454
2454fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {2455fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
2455 const pt = sema.pt;2456 const zcu = sema.pt.zcu;
2456 const msg = msg: {2457 const msg = msg: {
2457 const msg = try sema.errMsg(src, "expected optional type, found '{f}'", .{2458 const msg = try sema.errMsg(src, "expected optional type, found '{f}'", .{
2458 non_optional_ty.fmt(pt),2459 non_optional_ty.fmt(zcu),
2459 });2460 });
2460 errdefer msg.destroy(sema.gpa);2461 errdefer msg.destroy(sema.gpa);
2461 if (non_optional_ty.zigTypeTag(pt.zcu) == .error_union) {2462 if (non_optional_ty.zigTypeTag(zcu) == .error_union) {
2462 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});2463 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2463 }2464 }
2464 try addDeclaredHereNote(sema, msg, non_optional_ty);2465 try addDeclaredHereNote(sema, msg, non_optional_ty);
...@@ -2468,15 +2469,14 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non...@@ -2468,15 +2469,14 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
2468}2469}
24692470
2470fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {2471fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2471 const pt = sema.pt;2472 const zcu = sema.pt.zcu;
2472 const zcu = pt.zcu;
2473 const msg = msg: {2473 const msg = msg: {
2474 const msg = try sema.errMsg(src, "type '{f}' does not support array initialization syntax", .{2474 const msg = try sema.errMsg(src, "type '{f}' does not support array initialization syntax", .{
2475 ty.fmt(pt),2475 ty.fmt(zcu),
2476 });2476 });
2477 errdefer msg.destroy(sema.gpa);2477 errdefer msg.destroy(sema.gpa);
2478 if (ty.isSlice(zcu)) {2478 if (ty.isSlice(zcu)) {
2479 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(pt)});2479 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(zcu)});
2480 }2480 }
2481 break :msg msg;2481 break :msg msg;
2482 };2482 };
...@@ -2484,17 +2484,17 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty...@@ -2484,17 +2484,17 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
2484}2484}
24852485
2486fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {2486fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2487 const pt = sema.pt;2487 const zcu = sema.pt.zcu;
2488 return sema.fail(block, src, "type '{f}' does not support struct initialization syntax", .{2488 return sema.fail(block, src, "type '{f}' does not support struct initialization syntax", .{
2489 ty.fmt(pt),2489 ty.fmt(zcu),
2490 });2490 });
2491}2491}
24922492
2493pub fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: Type, val: Value, vector_index: ?usize) CompileError {2493pub fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: Type, val: Value, vector_index: ?usize) CompileError {
2494 const pt = sema.pt;2494 const zcu = sema.pt.zcu;
2495 return sema.failWithOwnedErrorMsg(block, msg: {2495 return sema.failWithOwnedErrorMsg(block, msg: {
2496 const msg = try sema.errMsg(src, "overflow of integer type '{f}' with value '{f}'", .{2496 const msg = try sema.errMsg(src, "overflow of integer type '{f}' with value '{f}'", .{
2497 int_ty.fmt(pt), val.fmtValueSema(pt, sema),2497 int_ty.fmt(zcu), val.fmtValueSema(sema),
2498 });2498 });
2499 errdefer msg.destroy(sema.gpa);2499 errdefer msg.destroy(sema.gpa);
2500 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});2500 if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i});
...@@ -2543,7 +2543,7 @@ fn failWithInvalidFieldAccess(...@@ -2543,7 +2543,7 @@ fn failWithInvalidFieldAccess(
2543 const child_ty = inner_ty.optionalChild(zcu);2543 const child_ty = inner_ty.optionalChild(zcu);
2544 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;2544 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;
2545 const msg = msg: {2545 const msg = msg: {
2546 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(pt)});2546 const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(zcu)});
2547 errdefer msg.destroy(sema.gpa);2547 errdefer msg.destroy(sema.gpa);
2548 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});2548 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2549 break :msg msg;2549 break :msg msg;
...@@ -2553,14 +2553,14 @@ fn failWithInvalidFieldAccess(...@@ -2553,14 +2553,14 @@ fn failWithInvalidFieldAccess(
2553 const child_ty = inner_ty.errorUnionPayload(zcu);2553 const child_ty = inner_ty.errorUnionPayload(zcu);
2554 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;2554 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;
2555 const msg = msg: {2555 const msg = msg: {
2556 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(pt)});2556 const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(zcu)});
2557 errdefer msg.destroy(sema.gpa);2557 errdefer msg.destroy(sema.gpa);
2558 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});2558 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2559 break :msg msg;2559 break :msg msg;
2560 };2560 };
2561 return sema.failWithOwnedErrorMsg(block, msg);2561 return sema.failWithOwnedErrorMsg(block, msg);
2562 }2562 }
2563 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(pt)});2563 return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(zcu)});
2564}2564}
25652565
2566fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {2566fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {
...@@ -2650,20 +2650,20 @@ pub fn errMsg(...@@ -2650,20 +2650,20 @@ pub fn errMsg(
2650}2650}
26512651
2652fn typeMismatchErrMsg(sema: *Sema, src: LazySrcLoc, expected: Type, found: Type) Allocator.Error!*Zcu.ErrorMsg {2652fn typeMismatchErrMsg(sema: *Sema, src: LazySrcLoc, expected: Type, found: Type) Allocator.Error!*Zcu.ErrorMsg {
2653 const pt = sema.pt;2653 const zcu = sema.pt.zcu;
2654 var cmp: Type.Comparison = try .init(&.{ expected, found }, pt);2654 var cmp: Type.Comparison = try .init(&.{ expected, found }, zcu);
2655 defer cmp.deinit(pt);2655 defer cmp.deinit(zcu.comp.gpa);
26562656
2657 const msg = try sema.errMsg(src, "expected type '{f}', found '{f}'", .{2657 const msg = try sema.errMsg(src, "expected type '{f}', found '{f}'", .{
2658 cmp.fmtType(expected, pt),2658 cmp.fmtType(expected, zcu),
2659 cmp.fmtType(found, pt),2659 cmp.fmtType(found, zcu),
2660 });2660 });
2661 errdefer msg.destroy(sema.gpa);2661 errdefer msg.destroy(sema.gpa);
26622662
2663 for (cmp.type_dedupe_cache.keys(), cmp.type_dedupe_cache.values()) |ty, value| {2663 for (cmp.type_dedupe_cache.keys(), cmp.type_dedupe_cache.values()) |ty, value| {
2664 if (value == .dont_dedupe) continue;2664 if (value == .dont_dedupe) continue;
2665 const placeholder = value.dedupe;2665 const placeholder = value.dedupe;
2666 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(pt) });2666 try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(zcu) });
2667 }2667 }
26682668
2669 return msg;2669 return msg;
...@@ -2679,7 +2679,7 @@ pub fn fail(...@@ -2679,7 +2679,7 @@ pub fn fail(
2679 const err_msg = try sema.errMsg(src, format, args);2679 const err_msg = try sema.errMsg(src, format, args);
2680 inline for (args) |arg| {2680 inline for (args) |arg| {
2681 if (@TypeOf(arg) == Type.Formatter) {2681 if (@TypeOf(arg) == Type.Formatter) {
2682 try addDeclaredHereNote(sema, err_msg, arg.data.ty);2682 try addDeclaredHereNote(sema, err_msg, arg.ty);
2683 }2683 }
2684 }2684 }
2685 return sema.failWithOwnedErrorMsg(block, err_msg);2685 return sema.failWithOwnedErrorMsg(block, err_msg);
...@@ -3154,11 +3154,11 @@ fn validateDeref(...@@ -3154,11 +3154,11 @@ fn validateDeref(
3154 const zcu = pt.zcu;3154 const zcu = pt.zcu;
3155 const ip = &zcu.intern_pool;3155 const ip = &zcu.intern_pool;
3156 if (ty.zigTypeTag(zcu) != .pointer) {3156 if (ty.zigTypeTag(zcu) != .pointer) {
3157 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(pt)});3157 return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(zcu)});
3158 }3158 }
3159 const size = ty.ptrSize(zcu);3159 const size = ty.ptrSize(zcu);
3160 switch (size) {3160 switch (size) {
3161 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(pt)}),3161 .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(zcu)}),
3162 .one, .c, .slice => {},3162 .one, .c, .slice => {},
3163 }3163 }
3164 if (sema.resolveValue(ref)) |val| {3164 if (sema.resolveValue(ref)) |val| {
...@@ -3194,11 +3194,11 @@ fn ensureResultUsed(...@@ -3194,11 +3194,11 @@ fn ensureResultUsed(
3194 switch (ty.zigTypeTag(zcu)) {3194 switch (ty.zigTypeTag(zcu)) {
3195 .void, .noreturn => return,3195 .void, .noreturn => return,
3196 .error_set => {3196 .error_set => {
3197 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(pt)});3197 return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(zcu)});
3198 },3198 },
3199 .error_union => {3199 .error_union => {
3200 const msg = msg: {3200 const msg = msg: {
3201 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(pt)});3201 const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(zcu)});
3202 errdefer msg.destroy(sema.gpa);3202 errdefer msg.destroy(sema.gpa);
3203 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});3203 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
3204 break :msg msg;3204 break :msg msg;
...@@ -3207,7 +3207,7 @@ fn ensureResultUsed(...@@ -3207,7 +3207,7 @@ fn ensureResultUsed(
3207 },3207 },
3208 else => {3208 else => {
3209 const msg = msg: {3209 const msg = msg: {
3210 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(pt)});3210 const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(zcu)});
3211 errdefer msg.destroy(sema.gpa);3211 errdefer msg.destroy(sema.gpa);
3212 try sema.errNote(src, msg, "all non-void values must be used", .{});3212 try sema.errNote(src, msg, "all non-void values must be used", .{});
3213 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});3213 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
...@@ -3469,7 +3469,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3469,7 +3469,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3469 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.3469 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
3470 // TODO: source location of runtime control flow3470 // TODO: source location of runtime control flow
3471 const init_src = block.src(.{ .node_offset_var_decl_init = inst_data.src_node });3471 const init_src = block.src(.{ .node_offset_var_decl_init = inst_data.src_node });
3472 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(pt)});3472 return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(zcu)});
3473 }3473 }
34743474
3475 // This is a runtime value.3475 // This is a runtime value.
...@@ -3990,7 +3990,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3990,7 +3990,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3990 // The alloc wasn't comptime-known per the above logic, so the3990 // The alloc wasn't comptime-known per the above logic, so the
3991 // type cannot be comptime-only.3991 // type cannot be comptime-only.
3992 // TODO: source location of runtime control flow3992 // TODO: source location of runtime control flow
3993 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});3993 return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(zcu)});
3994 }3994 }
3995 if (sema.func_is_naked and final_elem_ty.hasRuntimeBits(zcu)) {3995 if (sema.func_is_naked and final_elem_ty.hasRuntimeBits(zcu)) {
3996 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });3996 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
...@@ -4090,7 +4090,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4090,7 +4090,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4090 if (!object_ty.isIndexable(zcu)) {4090 if (!object_ty.isIndexable(zcu)) {
4091 // Instead of using checkIndexable we customize this error.4091 // Instead of using checkIndexable we customize this error.
4092 const msg = msg: {4092 const msg = msg: {
4093 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(pt)});4093 const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(zcu)});
4094 errdefer msg.destroy(sema.gpa);4094 errdefer msg.destroy(sema.gpa);
4095 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});4095 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
40964096
...@@ -4129,10 +4129,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4129,10 +4129,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4129 .input_index = len_idx,4129 .input_index = len_idx,
4130 } });4130 } });
4131 try sema.errNote(a_src, msg, "length {f} here", .{4131 try sema.errNote(a_src, msg, "length {f} here", .{
4132 v.fmtValueSema(pt, sema),4132 v.fmtValueSema(sema),
4133 });4133 });
4134 try sema.errNote(arg_src, msg, "length {f} here", .{4134 try sema.errNote(arg_src, msg, "length {f} here", .{
4135 arg_val.fmtValueSema(pt, sema),4135 arg_val.fmtValueSema(sema),
4136 });4136 });
4137 break :msg msg;4137 break :msg msg;
4138 };4138 };
...@@ -4164,7 +4164,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4164,7 +4164,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4164 .input_index = i,4164 .input_index = i,
4165 } });4165 } });
4166 try sema.errNote(arg_src, msg, "type '{f}' has no upper bound", .{4166 try sema.errNote(arg_src, msg, "type '{f}' has no upper bound", .{
4167 object_ty.fmt(pt),4167 object_ty.fmt(zcu),
4168 });4168 });
4169 }4169 }
4170 break :msg msg;4170 break :msg msg;
...@@ -4249,7 +4249,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -4249,7 +4249,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
4249 switch (val_ty.zigTypeTag(zcu)) {4249 switch (val_ty.zigTypeTag(zcu)) {
4250 .array, .vector => {},4250 .array, .vector => {},
4251 else => if (!val_ty.isTuple(zcu)) {4251 else => if (!val_ty.isTuple(zcu)) {
4252 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });4252 return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(zcu), val_ty.fmt(zcu) });
4253 },4253 },
4254 }4254 }
4255 const want_ty = try pt.arrayType(.{4255 const want_ty = try pt.arrayType(.{
...@@ -4327,7 +4327,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -4327,7 +4327,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4327 const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return;4327 const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return;
4328 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) {4328 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) {
4329 return sema.failWithOwnedErrorMsg(block, msg: {4329 return sema.failWithOwnedErrorMsg(block, msg: {
4330 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(pt)});4330 const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(zcu)});
4331 errdefer msg.destroy(sema.gpa);4331 errdefer msg.destroy(sema.gpa);
4332 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});4332 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
4333 break :msg msg;4333 break :msg msg;
...@@ -4713,7 +4713,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -4713,7 +4713,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
47134713
4714 if (!operand_ty.destructurable(zcu)) {4714 if (!operand_ty.destructurable(zcu)) {
4715 return sema.failWithOwnedErrorMsg(block, msg: {4715 return sema.failWithOwnedErrorMsg(block, msg: {
4716 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(pt)});4716 const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(zcu)});
4717 errdefer msg.destroy(sema.gpa);4717 errdefer msg.destroy(sema.gpa);
4718 try sema.errNote(destructure_src, msg, "result destructured here", .{});4718 try sema.errNote(destructure_src, msg, "result destructured here", .{});
4719 if (operand_ty.zigTypeTag(pt.zcu) == .error_union) {4719 if (operand_ty.zigTypeTag(pt.zcu) == .error_union) {
...@@ -4758,13 +4758,13 @@ fn failWithBadMemberAccess(...@@ -4758,13 +4758,13 @@ fn failWithBadMemberAccess(
4758 const inst_index = inst.resolve(ip) orelse return sema.failTransitive(.{ .lost_tracking = inst });4758 const inst_index = inst.resolve(ip) orelse return sema.failTransitive(.{ .lost_tracking = inst });
4759 if (inst_index == .main_struct_inst) {4759 if (inst_index == .main_struct_inst) {
4760 return sema.fail(block, field_src, "root source file struct '{f}' has no member named '{f}'", .{4760 return sema.fail(block, field_src, "root source file struct '{f}' has no member named '{f}'", .{
4761 agg_ty.fmt(pt), field_name.fmt(ip),4761 agg_ty.fmt(zcu), field_name.fmt(ip),
4762 });4762 });
4763 }4763 }
4764 }4764 }
47654765
4766 return sema.fail(block, field_src, "{s} '{f}' has no member named '{f}'", .{4766 return sema.fail(block, field_src, "{s} '{f}' has no member named '{f}'", .{
4767 kw_name, agg_ty.fmt(pt), field_name.fmt(ip),4767 kw_name, agg_ty.fmt(zcu), field_name.fmt(ip),
4768 });4768 });
4769}4769}
47704770
...@@ -5061,10 +5061,10 @@ fn zirCompileLog(...@@ -5061,10 +5061,10 @@ fn zirCompileLog(
5061 const arg_ty = sema.typeOf(arg);5061 const arg_ty = sema.typeOf(arg);
5062 if (sema.resolveValue(arg)) |val| {5062 if (sema.resolveValue(arg)) |val| {
5063 writer.print("@as({f}, {f})", .{5063 writer.print("@as({f}, {f})", .{
5064 arg_ty.fmt(pt), val.fmtValueSema(pt, sema),5064 arg_ty.fmt(zcu), val.fmtValueSema(sema),
5065 }) catch return error.OutOfMemory;5065 }) catch return error.OutOfMemory;
5066 } else {5066 } else {
5067 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch return error.OutOfMemory;5067 writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(zcu)}) catch return error.OutOfMemory;
5068 }5068 }
5069 }5069 }
50705070
...@@ -5505,7 +5505,7 @@ fn resolveAnalyzedBlock(...@@ -5505,7 +5505,7 @@ fn resolveAnalyzedBlock(
5505 const type_src = src; // TODO: better source location5505 const type_src = src; // TODO: better source location
5506 if (resolved_ty.comptimeOnly(zcu)) {5506 if (resolved_ty.comptimeOnly(zcu)) {
5507 const msg = msg: {5507 const msg = msg: {
5508 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(pt)});5508 const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(zcu)});
5509 errdefer msg.destroy(sema.gpa);5509 errdefer msg.destroy(sema.gpa);
55105510
5511 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;5511 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
...@@ -5619,7 +5619,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -5619,7 +5619,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
56195619
5620 {5620 {
5621 if (ptr_ty.zigTypeTag(zcu) != .pointer) {5621 if (ptr_ty.zigTypeTag(zcu) != .pointer) {
5622 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(pt)});5622 return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(zcu)});
5623 }5623 }
5624 const ptr_ty_info = ptr_ty.ptrInfo(zcu);5624 const ptr_ty_info = ptr_ty.ptrInfo(zcu);
5625 if (ptr_ty_info.flags.size == .slice) {5625 if (ptr_ty_info.flags.size == .slice) {
...@@ -5634,7 +5634,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -5634,7 +5634,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
5634 try sema.ensureLayoutResolved(export_ty, src, .@"export");5634 try sema.ensureLayoutResolved(export_ty, src, .@"export");
5635 if (!export_ty.validateExtern(.other, zcu)) {5635 if (!export_ty.validateExtern(.other, zcu)) {
5636 return sema.failWithOwnedErrorMsg(block, msg: {5636 return sema.failWithOwnedErrorMsg(block, msg: {
5637 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});5637 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
5638 errdefer msg.destroy(sema.gpa);5638 errdefer msg.destroy(sema.gpa);
5639 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);5639 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
5640 try sema.addDeclaredHereNote(msg, export_ty);5640 try sema.addDeclaredHereNote(msg, export_ty);
...@@ -5691,7 +5691,7 @@ pub fn analyzeExportSelfNav(...@@ -5691,7 +5691,7 @@ pub fn analyzeExportSelfNav(
56915691
5692 if (!export_ty.validateExtern(.other, zcu)) {5692 if (!export_ty.validateExtern(.other, zcu)) {
5693 return sema.failWithOwnedErrorMsg(block, msg: {5693 return sema.failWithOwnedErrorMsg(block, msg: {
5694 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)});5694 const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)});
5695 errdefer msg.destroy(gpa);5695 errdefer msg.destroy(gpa);
5696 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);5696 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
5697 try sema.addDeclaredHereNote(msg, export_ty);5697 try sema.addDeclaredHereNote(msg, export_ty);
...@@ -6329,7 +6329,7 @@ fn checkCallArgumentCount(...@@ -6329,7 +6329,7 @@ fn checkCallArgumentCount(
6329 {6329 {
6330 const msg = msg: {6330 const msg = msg: {
6331 const msg = try sema.errMsg(func_src, "cannot call optional type '{f}'", .{6331 const msg = try sema.errMsg(func_src, "cannot call optional type '{f}'", .{
6332 callee_ty.fmt(pt),6332 callee_ty.fmt(zcu),
6333 });6333 });
6334 errdefer msg.destroy(sema.gpa);6334 errdefer msg.destroy(sema.gpa);
6335 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});6335 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
...@@ -6340,7 +6340,7 @@ fn checkCallArgumentCount(...@@ -6340,7 +6340,7 @@ fn checkCallArgumentCount(
6340 },6340 },
6341 else => {},6341 else => {},
6342 }6342 }
6343 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(pt)});6343 return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(zcu)});
6344 };6344 };
63456345
6346 const func_ty_info = zcu.typeToFunc(func_ty).?;6346 const func_ty_info = zcu.typeToFunc(func_ty).?;
...@@ -6403,7 +6403,7 @@ fn callBuiltin(...@@ -6403,7 +6403,7 @@ fn callBuiltin(
6403 },6403 },
6404 else => {},6404 else => {},
6405 }6405 }
6406 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});6406 std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(zcu)});
6407 };6407 };
64086408
6409 const func_ty_info = zcu.typeToFunc(func_ty).?;6409 const func_ty_info = zcu.typeToFunc(func_ty).?;
...@@ -6829,7 +6829,7 @@ fn analyzeCall(...@@ -6829,7 +6829,7 @@ fn analyzeCall(
6829 if (!param_ty.isValidParamType(zcu)) {6829 if (!param_ty.isValidParamType(zcu)) {
6830 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";6830 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
6831 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{6831 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
6832 opaque_str, param_ty.fmt(pt),6832 opaque_str, param_ty.fmt(zcu),
6833 });6833 });
6834 }6834 }
68356835
...@@ -6930,7 +6930,7 @@ fn analyzeCall(...@@ -6930,7 +6930,7 @@ fn analyzeCall(
6930 if (!full_ty.isValidReturnType(zcu)) {6930 if (!full_ty.isValidReturnType(zcu)) {
6931 const opaque_str = if (full_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";6931 const opaque_str = if (full_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
6932 return sema.fail(block, func_ret_ty_src, "{s}return type '{f}' not allowed", .{6932 return sema.fail(block, func_ret_ty_src, "{s}return type '{f}' not allowed", .{
6933 opaque_str, full_ty.fmt(pt),6933 opaque_str, full_ty.fmt(zcu),
6934 });6934 });
6935 }6935 }
69366936
...@@ -7430,7 +7430,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ...@@ -7430,7 +7430,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
7430 const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);7430 const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty);
7431 if (owner_func_ty.toIntern() != func_ty.toIntern()) {7431 if (owner_func_ty.toIntern() != func_ty.toIntern()) {
7432 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}'", .{7432 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{f}' does not match type of calling function '{f}'", .{
7433 func_ty.fmt(pt), owner_func_ty.fmt(pt),7433 func_ty.fmt(zcu), owner_func_ty.fmt(zcu),
7434 });7434 });
7435 }7435 }
7436 _ = try block.addUnOp(.ret, result);7436 _ = try block.addUnOp(.ret, result);
...@@ -7450,9 +7450,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -7450,9 +7450,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
7450 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });7450 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
7451 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);7451 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
7452 if (child_type.zigTypeTag(zcu) == .@"opaque") {7452 if (child_type.zigTypeTag(zcu) == .@"opaque") {
7453 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(pt)});7453 return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(zcu)});
7454 } else if (child_type.zigTypeTag(zcu) == .null) {7454 } else if (child_type.zigTypeTag(zcu) == .null) {
7455 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(pt)});7455 return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(zcu)});
7456 }7456 }
7457 const opt_type = try pt.optionalType(child_type.toIntern());7457 const opt_type = try pt.optionalType(child_type.toIntern());
74587458
...@@ -7513,7 +7513,7 @@ fn zirSplatOpResultType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -7513,7 +7513,7 @@ fn zirSplatOpResultType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
75137513
7514 switch (vec_ty.zigTypeTag(zcu)) {7514 switch (vec_ty.zigTypeTag(zcu)) {
7515 .array, .vector => {},7515 .array, .vector => {},
7516 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(pt)}),7516 else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(zcu)}),
7517 }7517 }
7518 return Air.internedToRef(vec_ty.childType(zcu).toIntern());7518 return Air.internedToRef(vec_ty.childType(zcu).toIntern());
7519}7519}
...@@ -7586,7 +7586,7 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src:...@@ -7586,7 +7586,7 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src:
7586 const pt = sema.pt;7586 const pt = sema.pt;
7587 const zcu = pt.zcu;7587 const zcu = pt.zcu;
7588 if (elem_type.zigTypeTag(zcu) == .@"opaque") {7588 if (elem_type.zigTypeTag(zcu) == .@"opaque") {
7589 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(pt)});7589 return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(zcu)});
7590 } else if (elem_type.zigTypeTag(zcu) == .noreturn) {7590 } else if (elem_type.zigTypeTag(zcu) == .noreturn) {
7591 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});7591 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
7592 }7592 }
...@@ -7617,7 +7617,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -7617,7 +7617,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
76177617
7618 if (error_set.zigTypeTag(zcu) != .error_set) {7618 if (error_set.zigTypeTag(zcu) != .error_set) {
7619 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{7619 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{
7620 error_set.fmt(pt),7620 error_set.fmt(zcu),
7621 });7621 });
7622 }7622 }
7623 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);7623 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);
...@@ -7630,11 +7630,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p...@@ -7630,11 +7630,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
7630 const zcu = pt.zcu;7630 const zcu = pt.zcu;
7631 if (payload_ty.zigTypeTag(zcu) == .@"opaque") {7631 if (payload_ty.zigTypeTag(zcu) == .@"opaque") {
7632 return sema.fail(block, payload_src, "error union with payload of opaque type '{f}' not allowed", .{7632 return sema.fail(block, payload_src, "error union with payload of opaque type '{f}' not allowed", .{
7633 payload_ty.fmt(pt),7633 payload_ty.fmt(zcu),
7634 });7634 });
7635 } else if (payload_ty.zigTypeTag(zcu) == .error_set) {7635 } else if (payload_ty.zigTypeTag(zcu) == .error_set) {
7636 return sema.fail(block, payload_src, "error union with payload of error set type '{f}' not allowed", .{7636 return sema.fail(block, payload_src, "error union with payload of error set type '{f}' not allowed", .{
7637 payload_ty.fmt(pt),7637 payload_ty.fmt(zcu),
7638 });7638 });
7639 }7639 }
7640}7640}
...@@ -7765,9 +7765,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -7765,9 +7765,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
7765 const lhs_ty = try sema.analyzeAsType(block, lhs_src, .type, lhs);7765 const lhs_ty = try sema.analyzeAsType(block, lhs_src, .type, lhs);
7766 const rhs_ty = try sema.analyzeAsType(block, rhs_src, .type, rhs);7766 const rhs_ty = try sema.analyzeAsType(block, rhs_src, .type, rhs);
7767 if (lhs_ty.zigTypeTag(zcu) != .error_set)7767 if (lhs_ty.zigTypeTag(zcu) != .error_set)
7768 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(pt)});7768 return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(zcu)});
7769 if (rhs_ty.zigTypeTag(zcu) != .error_set)7769 if (rhs_ty.zigTypeTag(zcu) != .error_set)
7770 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(pt)});7770 return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(zcu)});
77717771
7772 // Anything merged with anyerror is anyerror.7772 // Anything merged with anyerror is anyerror.
7773 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {7773 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
...@@ -7893,7 +7893,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7893,7 +7893,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7893 block,7893 block,
7894 operand_src,7894 operand_src,
7895 "untagged union '{f}' cannot be converted to integer",7895 "untagged union '{f}' cannot be converted to integer",
7896 .{operand_ty.fmt(pt)},7896 .{operand_ty.fmt(zcu)},
7897 );7897 );
7898 }7898 }
78997899
...@@ -7901,7 +7901,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7901,7 +7901,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7901 },7901 },
7902 else => {7902 else => {
7903 return sema.fail(block, operand_src, "expected enum or tagged union, found '{f}'", .{7903 return sema.fail(block, operand_src, "expected enum or tagged union, found '{f}'", .{
7904 operand_ty.fmt(pt),7904 operand_ty.fmt(zcu),
7905 });7905 });
7906 },7906 },
7907 };7907 };
...@@ -7930,7 +7930,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7930,7 +7930,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7930 const operand_ty = sema.typeOf(operand);7930 const operand_ty = sema.typeOf(operand);
79317931
7932 if (dest_ty.zigTypeTag(zcu) != .@"enum") {7932 if (dest_ty.zigTypeTag(zcu) != .@"enum") {
7933 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(pt)});7933 return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(zcu)});
7934 }7934 }
7935 try sema.ensureLayoutResolved(dest_ty, src, .init);7935 try sema.ensureLayoutResolved(dest_ty, src, .init);
7936 _ = try sema.checkIntType(block, operand_src, operand_ty);7936 _ = try sema.checkIntType(block, operand_src, operand_ty);
...@@ -7942,7 +7942,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7942,7 +7942,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7942 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());7942 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
7943 }7943 }
7944 return sema.fail(block, src, "int value '{f}' out of range of non-exhaustive enum '{f}'", .{7944 return sema.fail(block, src, "int value '{f}' out of range of non-exhaustive enum '{f}'", .{
7945 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),7945 int_val.fmtValueSema(sema), dest_ty.fmt(zcu),
7946 });7946 });
7947 }7947 }
7948 if (int_val.isUndef(zcu)) {7948 if (int_val.isUndef(zcu)) {
...@@ -7950,7 +7950,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -7950,7 +7950,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
7950 }7950 }
7951 if (!(try sema.enumHasInt(dest_ty, int_val))) {7951 if (!(try sema.enumHasInt(dest_ty, int_val))) {
7952 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{7952 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
7953 dest_ty.fmt(pt), int_val.fmtValueSema(pt, sema),7953 dest_ty.fmt(zcu), int_val.fmtValueSema(sema),
7954 });7954 });
7955 }7955 }
7956 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());7956 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
...@@ -8128,7 +8128,7 @@ fn zirErrUnionPayload(...@@ -8128,7 +8128,7 @@ fn zirErrUnionPayload(
8128 const err_union_ty = sema.typeOf(operand);8128 const err_union_ty = sema.typeOf(operand);
8129 if (err_union_ty.zigTypeTag(zcu) != .error_union) {8129 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
8130 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{8130 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
8131 err_union_ty.fmt(pt),8131 err_union_ty.fmt(zcu),
8132 });8132 });
8133 }8133 }
8134 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);8134 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);
...@@ -8202,7 +8202,7 @@ fn analyzeErrUnionPayloadPtr(...@@ -8202,7 +8202,7 @@ fn analyzeErrUnionPayloadPtr(
82028202
8203 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {8203 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
8204 return sema.fail(block, src, "expected error union type, found '{f}'", .{8204 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8205 operand_ty.childType(zcu).fmt(pt),8205 operand_ty.childType(zcu).fmt(zcu),
8206 });8206 });
8207 }8207 }
82088208
...@@ -8277,7 +8277,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air...@@ -8277,7 +8277,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
8277 const operand_ty = sema.typeOf(operand);8277 const operand_ty = sema.typeOf(operand);
8278 if (operand_ty.zigTypeTag(zcu) != .error_union) {8278 if (operand_ty.zigTypeTag(zcu) != .error_union) {
8279 return sema.fail(block, src, "expected error union type, found '{f}'", .{8279 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8280 operand_ty.fmt(pt),8280 operand_ty.fmt(zcu),
8281 });8281 });
8282 }8282 }
82838283
...@@ -8311,7 +8311,7 @@ fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand:...@@ -8311,7 +8311,7 @@ fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand:
83118311
8312 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {8312 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) {
8313 return sema.fail(block, src, "expected error union type, found '{f}'", .{8313 return sema.fail(block, src, "expected error union type, found '{f}'", .{
8314 operand_ty.childType(zcu).fmt(pt),8314 operand_ty.childType(zcu).fmt(zcu),
8315 });8315 });
8316 }8316 }
83178317
...@@ -8639,7 +8639,7 @@ fn checkParamType(...@@ -8639,7 +8639,7 @@ fn checkParamType(
8639 if (!param_ty.isValidParamType(zcu)) {8639 if (!param_ty.isValidParamType(zcu)) {
8640 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";8640 const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
8641 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{8641 return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{
8642 opaque_str, param_ty.fmt(pt),8642 opaque_str, param_ty.fmt(zcu),
8643 });8643 });
8644 }8644 }
8645 if (!target_util.fnCallConvAllowsZigTypes(cc)) {8645 if (!target_util.fnCallConvAllowsZigTypes(cc)) {
...@@ -8720,12 +8720,12 @@ fn checkReturnTypeAndCallConv(...@@ -8720,12 +8720,12 @@ fn checkReturnTypeAndCallConv(
8720 if (!bare_ret_ty.isValidReturnType(zcu)) {8720 if (!bare_ret_ty.isValidReturnType(zcu)) {
8721 const opaque_str = if (bare_ret_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";8721 const opaque_str = if (bare_ret_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else "";
8722 return sema.fail(block, ret_ty_src, "{s}return type '{s}{f}' not allowed", .{8722 return sema.fail(block, ret_ty_src, "{s}return type '{s}{f}' not allowed", .{
8723 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(pt),8723 opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(zcu),
8724 });8724 });
8725 }8725 }
8726 if (!target_util.fnCallConvAllowsZigTypes(@"callconv")) {8726 if (!target_util.fnCallConvAllowsZigTypes(@"callconv")) {
8727 if (inferred_error_set) {8727 if (inferred_error_set) {
8728 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(pt), @"callconv" });8728 return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(zcu), @"callconv" });
8729 }8729 }
8730 if (bare_ret_ty.isGenericPoison()) {8730 if (bare_ret_ty.isGenericPoison()) {
8731 return sema.fail(block, ret_ty_src, "generic return type not allowed in function with calling convention '{t}'", .{@"callconv"});8731 return sema.fail(block, ret_ty_src, "generic return type not allowed in function with calling convention '{t}'", .{@"callconv"});
...@@ -8857,7 +8857,7 @@ fn validateResolvedFuncType(...@@ -8857,7 +8857,7 @@ fn validateResolvedFuncType(
8857 } else src;8857 } else src;
8858 return sema.failWithOwnedErrorMsg(block, msg: {8858 return sema.failWithOwnedErrorMsg(block, msg: {
8859 const msg = try sema.errMsg(param_src, "parameter of type '{f}' not allowed in function with calling convention '{t}'", .{8859 const msg = try sema.errMsg(param_src, "parameter of type '{f}' not allowed in function with calling convention '{t}'", .{
8860 param_ty.fmt(pt), @"callconv",8860 param_ty.fmt(zcu), @"callconv",
8861 });8861 });
8862 errdefer msg.destroy(gpa);8862 errdefer msg.destroy(gpa);
8863 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);8863 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
...@@ -8874,7 +8874,7 @@ fn validateResolvedFuncType(...@@ -8874,7 +8874,7 @@ fn validateResolvedFuncType(
8874 } else src;8874 } else src;
8875 return sema.failWithOwnedErrorMsg(block, msg: {8875 return sema.failWithOwnedErrorMsg(block, msg: {
8876 const msg = try sema.errMsg(ret_ty_src, "return type '{f}' not allowed in function with calling convention '{t}'", .{8876 const msg = try sema.errMsg(ret_ty_src, "return type '{f}' not allowed in function with calling convention '{t}'", .{
8877 ret_ty.fmt(pt), @"callconv",8877 ret_ty.fmt(zcu), @"callconv",
8878 });8878 });
8879 errdefer msg.destroy(gpa);8879 errdefer msg.destroy(gpa);
8880 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, ret_ty, .ret_ty);8880 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, ret_ty, .ret_ty);
...@@ -8933,7 +8933,7 @@ fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type)...@@ -8933,7 +8933,7 @@ fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type)
8933 }8933 }
89348934
8935 return sema.failWithOwnedErrorMsg(block, msg: {8935 return sema.failWithOwnedErrorMsg(block, msg: {
8936 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(pt)});8936 const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(zcu)});
8937 errdefer msg.destroy(sema.gpa);8937 errdefer msg.destroy(sema.gpa);
89388938
8939 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;8939 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
...@@ -9166,7 +9166,7 @@ fn analyzeAs(...@@ -9166,7 +9166,7 @@ fn analyzeAs(
9166 const operand = sema.resolveInst(zir_operand);9166 const operand = sema.resolveInst(zir_operand);
9167 const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand;9167 const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand;
9168 switch (dest_ty.zigTypeTag(zcu)) {9168 switch (dest_ty.zigTypeTag(zcu)) {
9169 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(pt)}),9169 .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(zcu)}),
9170 .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}),9170 .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}),
9171 else => {},9171 else => {},
9172 }9172 }
...@@ -9191,7 +9191,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -9191,7 +9191,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
9191 const ptr_ty = operand_ty.scalarType(zcu);9191 const ptr_ty = operand_ty.scalarType(zcu);
9192 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;9192 const is_vector = operand_ty.zigTypeTag(zcu) == .vector;
9193 if (!ptr_ty.isPtrAtRuntime(zcu)) {9193 if (!ptr_ty.isPtrAtRuntime(zcu)) {
9194 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)});9194 return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)});
9195 }9195 }
91969196
9197 const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined;9197 const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined;
...@@ -9414,45 +9414,45 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9414,45 +9414,45 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9414 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.9414 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
9415 switch (dest_ty.scalarType(zcu).zigTypeTag(zcu)) {9415 switch (dest_ty.scalarType(zcu).zigTypeTag(zcu)) {
9416 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {9416 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9417 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});9417 const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
9418 errdefer msg.destroy(sema.gpa);9418 errdefer msg.destroy(sema.gpa);
9419 switch (operand_ty.zigTypeTag(zcu)) {9419 switch (operand_ty.zigTypeTag(zcu)) {
9420 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(pt)}),9420 .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(zcu)}),
9421 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(pt)}),9421 .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(zcu)}),
9422 else => {},9422 else => {},
9423 }9423 }
9424 break :msg msg;9424 break :msg msg;
9425 }),9425 }),
9426 .array => switch (dest_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {9426 .array => switch (dest_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9427 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}),9427 .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}),
9428 else => {},9428 else => {},
9429 },9429 },
9430 else => {},9430 else => {},
9431 }9431 }
9432 if (!dest_ty.hasBitRepresentation(zcu)) {9432 if (!dest_ty.hasBitRepresentation(zcu)) {
9433 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)});9433 return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)});
9434 }9434 }
94359435
9436 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.9436 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices.
9437 switch (operand_ty.scalarType(zcu).zigTypeTag(zcu)) {9437 switch (operand_ty.scalarType(zcu).zigTypeTag(zcu)) {
9438 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {9438 .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: {
9439 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});9439 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
9440 errdefer msg.destroy(sema.gpa);9440 errdefer msg.destroy(sema.gpa);
9441 switch (dest_ty.zigTypeTag(zcu)) {9441 switch (dest_ty.zigTypeTag(zcu)) {
9442 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(pt)}),9442 .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(zcu)}),
9443 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(pt)}),9443 .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(zcu)}),
9444 else => {},9444 else => {},
9445 }9445 }
9446 break :msg msg;9446 break :msg msg;
9447 }),9447 }),
9448 .array => switch (operand_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {9448 .array => switch (operand_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) {
9449 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(pt)}),9449 .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(zcu)}),
9450 else => {},9450 else => {},
9451 },9451 },
9452 else => {},9452 else => {},
9453 }9453 }
9454 if (!operand_ty.hasBitRepresentation(zcu)) {9454 if (!operand_ty.hasBitRepresentation(zcu)) {
9455 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)});9455 return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)});
9456 }9456 }
94579457
9458 operand_ty.assertHasLayout(zcu);9458 operand_ty.assertHasLayout(zcu);
...@@ -9462,9 +9462,9 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9462,9 +9462,9 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9462 const dest_bits = dest_ty.bitSize(zcu);9462 const dest_bits = dest_ty.bitSize(zcu);
9463 if (operand_bits != dest_bits) {9463 if (operand_bits != dest_bits) {
9464 return sema.fail(block, src, "@bitCast size mismatch: destination type '{f}' has {d} bits but source type '{f}' has {d} bits", .{9464 return sema.fail(block, src, "@bitCast size mismatch: destination type '{f}' has {d} bits but source type '{f}' has {d} bits", .{
9465 dest_ty.fmt(pt),9465 dest_ty.fmt(zcu),
9466 dest_bits,9466 dest_bits,
9467 operand_ty.fmt(pt),9467 operand_ty.fmt(zcu),
9468 operand_bits,9468 operand_bits,
9469 });9469 });
9470 }9470 }
...@@ -9482,7 +9482,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9482,7 +9482,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9482 dest_ty.enumTagFieldIndex(result_val, zcu) == null)9482 dest_ty.enumTagFieldIndex(result_val, zcu) == null)
9483 {9483 {
9484 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{9484 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9485 dest_ty.fmt(pt), result_val.backingInt(zcu).fmtValueSema(pt, sema),9485 dest_ty.fmt(zcu), result_val.backingInt(zcu).fmtValueSema(sema),
9486 });9486 });
9487 }9487 }
94889488
...@@ -9515,9 +9515,9 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -9515,9 +9515,9 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
9515 if (union_obj.tag_usage == .tagged) break :ref try sema.unionToTag(block, operand);9515 if (union_obj.tag_usage == .tagged) break :ref try sema.unionToTag(block, operand);
9516 if (union_obj.layout == .@"packed") break :ref operand;9516 if (union_obj.layout == .@"packed") break :ref operand;
9517 return sema.failWithOwnedErrorMsg(block, msg: {9517 return sema.failWithOwnedErrorMsg(block, msg: {
9518 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(pt)});9518 const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(zcu)});
9519 errdefer msg.deinit(gpa);9519 errdefer msg.deinit(gpa);
9520 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(pt)});9520 try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(zcu)});
9521 try sema.addDeclaredHereNote(msg, operand_ty);9521 try sema.addDeclaredHereNote(msg, operand_ty);
9522 break :msg msg;9522 break :msg msg;
9523 });9523 });
...@@ -9525,14 +9525,14 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -9525,14 +9525,14 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
9525 .@"struct" => {9525 .@"struct" => {
9526 if (operand_ty.containerLayout(zcu) != .@"packed") {9526 if (operand_ty.containerLayout(zcu) != .@"packed") {
9527 return sema.fail(block, operand_src, "non-packed struct '{f}' does not have a backing integer", .{9527 return sema.fail(block, operand_src, "non-packed struct '{f}' does not have a backing integer", .{
9528 operand_ty.fmt(pt),9528 operand_ty.fmt(zcu),
9529 });9529 });
9530 }9530 }
9531 break :ref operand;9531 break :ref operand;
9532 },9532 },
9533 else => {9533 else => {
9534 return sema.fail(block, operand_src, "expected enum, tagged union, packed union or packed struct, found '{f}'", .{9534 return sema.fail(block, operand_src, "expected enum, tagged union, packed union or packed struct, found '{f}'", .{
9535 operand_ty.fmt(pt),9535 operand_ty.fmt(zcu),
9536 });9536 });
9537 },9537 },
9538 };9538 };
...@@ -9568,12 +9568,12 @@ fn zirFromBackingIntArgTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -9568,12 +9568,12 @@ fn zirFromBackingIntArgTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
9568 .@"enum" => {},9568 .@"enum" => {},
9569 .@"struct", .@"union" => |type_tag| if (dest_ty.containerLayout(zcu) != .@"packed") {9569 .@"struct", .@"union" => |type_tag| if (dest_ty.containerLayout(zcu) != .@"packed") {
9570 return sema.fail(block, src, "non-packed {t} '{f}' does not have a backing integer", .{9570 return sema.fail(block, src, "non-packed {t} '{f}' does not have a backing integer", .{
9571 type_tag, dest_ty.fmt(pt),9571 type_tag, dest_ty.fmt(zcu),
9572 });9572 });
9573 },9573 },
9574 else => {9574 else => {
9575 return sema.fail(block, src, "expected enum, packed union or packed struct, found '{f}'", .{9575 return sema.fail(block, src, "expected enum, packed union or packed struct, found '{f}'", .{
9576 dest_ty.fmt(pt),9576 dest_ty.fmt(zcu),
9577 });9577 });
9578 },9578 },
9579 }9579 }
...@@ -9614,7 +9614,7 @@ fn zirFromBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -9614,7 +9614,7 @@ fn zirFromBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
9614 enum_obj.tagValueIndex(ip, backing_int_val.toIntern()) == null)9614 enum_obj.tagValueIndex(ip, backing_int_val.toIntern()) == null)
9615 {9615 {
9616 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{9616 return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{
9617 dest_ty.fmt(pt), backing_int_val.fmtValueSema(pt, sema),9617 dest_ty.fmt(zcu), backing_int_val.fmtValueSema(sema),
9618 });9618 });
9619 }9619 }
9620 return .fromValue(try pt.enumValue(dest_ty, backing_int_val));9620 return .fromValue(try pt.enumValue(dest_ty, backing_int_val));
...@@ -9660,7 +9660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9660,7 +9660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9660 block,9660 block,
9661 src,9661 src,
9662 "expected float or vector type, found '{f}'",9662 "expected float or vector type, found '{f}'",
9663 .{dest_ty.fmt(pt)},9663 .{dest_ty.fmt(zcu)},
9664 ),9664 ),
9665 };9665 };
96669666
...@@ -9670,7 +9670,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9670,7 +9670,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9670 block,9670 block,
9671 operand_src,9671 operand_src,
9672 "expected float or vector type, found '{f}'",9672 "expected float or vector type, found '{f}'",
9673 .{operand_ty.fmt(pt)},9673 .{operand_ty.fmt(zcu)},
9674 ),9674 ),
9675 }9675 }
96769676
...@@ -9747,7 +9747,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9747,7 +9747,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9747 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });9747 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
9748 const msg = msg: {9748 const msg = msg: {
9749 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{f}'", .{9749 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{f}'", .{
9750 indexable_ty.fmt(pt),9750 indexable_ty.fmt(zcu),
9751 });9751 });
9752 errdefer msg.destroy(sema.gpa);9752 errdefer msg.destroy(sema.gpa);
9753 if (indexable_ty.isIndexable(zcu)) {9753 if (indexable_ty.isIndexable(zcu)) {
...@@ -9869,7 +9869,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -9869,7 +9869,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
9869 const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand));9869 const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand));
9870 const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) {9870 const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) {
9871 .pointer => lhs_ptr_ty.childType(zcu),9871 .pointer => lhs_ptr_ty.childType(zcu),
9872 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(pt)}),9872 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(zcu)}),
9873 };9873 };
98749874
9875 const sentinel_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {9875 const sentinel_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) {
...@@ -9884,7 +9884,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -9884,7 +9884,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
9884 };9884 };
9885 },9885 },
9886 },9886 },
9887 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(pt)}),9887 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(zcu)}),
9888 };9888 };
98899889
9890 return Air.internedToRef(sentinel_ty.toIntern());9890 return Air.internedToRef(sentinel_ty.toIntern());
...@@ -9954,7 +9954,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -9954,7 +9954,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
9954 };9954 };
9955 if (err_union_ty.zigTypeTag(zcu) != .error_union) {9955 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
9956 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{9956 return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{
9957 err_union_ty.fmt(pt),9957 err_union_ty.fmt(zcu),
9958 });9958 });
9959 }9959 }
99609960
...@@ -10816,7 +10816,7 @@ fn finishSwitchBr(...@@ -10816,7 +10816,7 @@ fn finishSwitchBr(
10816 else => {},10816 else => {},
10817 }10817 }
10818 return sema.fail(block, else_prong_src, "cannot enumerate values of type '{f}' for 'inline else'", .{10818 return sema.fail(block, else_prong_src, "cannot enumerate values of type '{f}' for 'inline else'", .{
10819 item_ty.fmt(pt),10819 item_ty.fmt(zcu),
10820 });10820 });
10821 };10821 };
10822 var unhandled_it = validated_switch.iterateUnhandledItems(error_names, min_int);10822 var unhandled_it = validated_switch.iterateUnhandledItems(error_names, min_int);
...@@ -11252,7 +11252,7 @@ fn validateSwitchBlock(...@@ -11252,7 +11252,7 @@ fn validateSwitchBlock(
1125211252
11253 .optional => return sema.failWithOwnedErrorMsg(block, msg: {11253 .optional => return sema.failWithOwnedErrorMsg(block, msg: {
11254 const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{11254 const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{
11255 operand_ty.fmt(pt),11255 operand_ty.fmt(zcu),
11256 });11256 });
11257 errdefer msg.destroy(gpa);11257 errdefer msg.destroy(gpa);
11258 try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{});11258 try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
...@@ -11261,7 +11261,7 @@ fn validateSwitchBlock(...@@ -11261,7 +11261,7 @@ fn validateSwitchBlock(
1126111261
11262 .error_union => return sema.failWithOwnedErrorMsg(block, msg: {11262 .error_union => return sema.failWithOwnedErrorMsg(block, msg: {
11263 const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{11263 const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{
11264 operand_ty.fmt(pt),11264 operand_ty.fmt(zcu),
11265 });11265 });
11266 errdefer msg.destroy(gpa);11266 errdefer msg.destroy(gpa);
11267 try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{});11267 try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{});
...@@ -11281,14 +11281,14 @@ fn validateSwitchBlock(...@@ -11281,14 +11281,14 @@ fn validateSwitchBlock(
11281 .spirv,11281 .spirv,
11282 => {},11282 => {},
11283 }11283 }
11284 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)});11284 return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(zcu)});
11285 };11285 };
1128611286
11287 if (zir_switch.has_continue and !block.isComptime()) {11287 if (zir_switch.has_continue and !block.isComptime()) {
11288 if (operand_ty.comptimeOnly(zcu)) {11288 if (operand_ty.comptimeOnly(zcu)) {
11289 // Even if the operand is comptime-known, this `switch` is runtime.11289 // Even if the operand is comptime-known, this `switch` is runtime.
11290 return sema.failWithOwnedErrorMsg(block, msg: {11290 return sema.failWithOwnedErrorMsg(block, msg: {
11291 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(pt)});11291 const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(zcu)});
11292 errdefer msg.destroy(gpa);11292 errdefer msg.destroy(gpa);
11293 try sema.errNote(operand_src, msg, "switch loops are evaluated at runtime outside of comptime scopes", .{});11293 try sema.errNote(operand_src, msg, "switch loops are evaluated at runtime outside of comptime scopes", .{});
11294 try sema.explainWhyTypeIsComptime(msg, operand_src, operand_ty);11294 try sema.explainWhyTypeIsComptime(msg, operand_src, operand_ty);
...@@ -11404,7 +11404,7 @@ fn validateSwitchBlock(...@@ -11404,7 +11404,7 @@ fn validateSwitchBlock(
11404 const msg = try sema.errMsg(11404 const msg = try sema.errMsg(
11405 operand_src,11405 operand_src,
11406 "ranges not allowed when switching on type '{f}'",11406 "ranges not allowed when switching on type '{f}'",
11407 .{operand_ty.fmt(pt)},11407 .{operand_ty.fmt(zcu)},
11408 );11408 );
11409 errdefer msg.destroy(gpa);11409 errdefer msg.destroy(gpa);
11410 try sema.errNote(11410 try sema.errNote(
...@@ -11466,7 +11466,7 @@ fn validateSwitchBlock(...@@ -11466,7 +11466,7 @@ fn validateSwitchBlock(
11466 item_ty.srcLoc(zcu),11466 item_ty.srcLoc(zcu),
11467 msg,11467 msg,
11468 "enum '{f}' declared here",11468 "enum '{f}' declared here",
11469 .{item_ty.fmt(pt)},11469 .{item_ty.fmt(zcu)},
11470 );11470 );
11471 break :msg msg;11471 break :msg msg;
11472 };11472 };
...@@ -11589,7 +11589,7 @@ fn validateSwitchBlock(...@@ -11589,7 +11589,7 @@ fn validateSwitchBlock(
11589 block,11589 block,
11590 src,11590 src,
11591 "else prong required when switching on type '{f}'",11591 "else prong required when switching on type '{f}'",
11592 .{item_ty.fmt(pt)},11592 .{item_ty.fmt(zcu)},
11593 );11593 );
11594 }11594 }
11595 },11595 },
...@@ -12655,7 +12655,7 @@ fn validateSwitchItemOrRange(...@@ -12655,7 +12655,7 @@ fn validateSwitchItemOrRange(
12655 if (overlap_start.eql(overlap_end, item_ty, zcu)) {12655 if (overlap_start.eql(overlap_end, item_ty, zcu)) {
12656 return sema.failWithOwnedErrorMsg(block, msg: {12656 return sema.failWithOwnedErrorMsg(block, msg: {
12657 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{12657 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12658 overlap_start.fmtValueSema(pt, sema),12658 overlap_start.fmtValueSema(sema),
12659 });12659 });
12660 errdefer msg.destroy(sema.gpa);12660 errdefer msg.destroy(sema.gpa);
12661 if (prev_range.first.eql(prev_range.last, item_ty, zcu)) {12661 if (prev_range.first.eql(prev_range.last, item_ty, zcu)) {
...@@ -12677,7 +12677,7 @@ fn validateSwitchItemOrRange(...@@ -12677,7 +12677,7 @@ fn validateSwitchItemOrRange(
12677 } else {12677 } else {
12678 try sema.errNote(prev_range.src, msg, "overlaps with previous range here", .{});12678 try sema.errNote(prev_range.src, msg, "overlaps with previous range here", .{});
12679 try sema.errNote(prev_range.src, msg, "ranges overlap from '{f}' to '{f}'", .{12679 try sema.errNote(prev_range.src, msg, "ranges overlap from '{f}' to '{f}'", .{
12680 overlap_start.fmtValueSema(pt, sema), overlap_end.fmtValueSema(pt, sema),12680 overlap_start.fmtValueSema(sema), overlap_end.fmtValueSema(sema),
12681 });12681 });
12682 }12682 }
12683 break :msg msg;12683 break :msg msg;
...@@ -12719,7 +12719,7 @@ fn validateSwitchItemOrRange(...@@ -12719,7 +12719,7 @@ fn validateSwitchItemOrRange(
12719 if (maybe_prev_src) |prev_src| {12719 if (maybe_prev_src) |prev_src| {
12720 return sema.failWithOwnedErrorMsg(block, msg: {12720 return sema.failWithOwnedErrorMsg(block, msg: {
12721 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{12721 const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{
12722 item_val.fmtValueSema(pt, sema),12722 item_val.fmtValueSema(sema),
12723 });12723 });
12724 errdefer msg.destroy(sema.gpa);12724 errdefer msg.destroy(sema.gpa);
12725 try sema.errNote(prev_src, msg, "previous value here", .{});12725 try sema.errNote(prev_src, msg, "previous value here", .{});
...@@ -12876,7 +12876,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12876,7 +12876,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12876 else => {},12876 else => {},
12877 }12877 }
12878 return sema.fail(block, ty_src, "type '{f}' does not support '@hasField'", .{12878 return sema.fail(block, ty_src, "type '{f}' does not support '@hasField'", .{
12879 ty.fmt(pt),12879 ty.fmt(zcu),
12880 });12880 });
12881 };12881 };
12882 return if (has_field) .bool_true else .bool_false;12882 return if (has_field) .bool_true else .bool_false;
...@@ -13087,7 +13087,7 @@ fn zirShl(...@@ -13087,7 +13087,7 @@ fn zirShl(
13087 break :rs lhs_src;13087 break :rs lhs_src;
13088 } else {13088 } else {
13089 if (air_tag == .shl_sat and scalar_rhs_ty.isSignedInt(zcu)) {13089 if (air_tag == .shl_sat and scalar_rhs_ty.isSignedInt(zcu)) {
13090 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(pt)});13090 return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(zcu)});
13091 }13091 }
13092 if (scalar_ty.toIntern() == .comptime_int_type) {13092 if (scalar_ty.toIntern() == .comptime_int_type) {
13093 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});13093 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
...@@ -13369,7 +13369,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13369,7 +13369,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13369 const scalar_tag = scalar_ty.zigTypeTag(zcu);13369 const scalar_tag = scalar_ty.zigTypeTag(zcu);
1337013370
13371 if (scalar_tag != .int and scalar_tag != .bool)13371 if (scalar_tag != .int and scalar_tag != .bool)
13372 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(pt)});13372 return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(zcu)});
1337313373
13374 return analyzeBitNot(sema, block, operand, src);13374 return analyzeBitNot(sema, block, operand, src);
13375}13375}
...@@ -13505,11 +13505,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13505,11 +13505,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1350513505
13506 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {13506 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
13507 if (lhs_is_tuple) break :lhs_info undefined;13507 if (lhs_is_tuple) break :lhs_info undefined;
13508 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(pt)});13508 return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(zcu)});
13509 };13509 };
13510 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {13510 const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse {
13511 assert(!rhs_is_tuple);13511 assert(!rhs_is_tuple);
13512 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(pt)});13512 return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(zcu)});
13513 };13513 };
1351413514
13515 const resolved_elem_ty = t: {13515 const resolved_elem_ty = t: {
...@@ -13933,7 +13933,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13933,7 +13933,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13933 .int, .comptime_int, .float, .comptime_float => false,13933 .int, .comptime_int, .float, .comptime_float => false,
13934 else => true,13934 else => true,
13935 }) {13935 }) {
13936 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)});13936 return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)});
13937 }13937 }
1393813938
13939 if (rhs_scalar_ty.isAnyFloat()) {13939 if (rhs_scalar_ty.isAnyFloat()) {
...@@ -13964,7 +13964,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -13964,7 +13964,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1396413964
13965 switch (rhs_scalar_ty.zigTypeTag(zcu)) {13965 switch (rhs_scalar_ty.zigTypeTag(zcu)) {
13966 .int, .comptime_int, .float, .comptime_float => {},13966 .int, .comptime_int, .float, .comptime_float => {},
13967 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)}),13967 else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)}),
13968 }13968 }
1396913969
13970 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try pt.intValue(rhs_scalar_ty, 0))).toIntern());13970 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try pt.intValue(rhs_scalar_ty, 0))).toIntern());
...@@ -14036,7 +14036,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -14036,7 +14036,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
14036 block,14036 block,
14037 src,14037 src,
14038 "ambiguous coercion of division operands '{f}' and '{f}'; non-zero remainder '{f}'",14038 "ambiguous coercion of division operands '{f}' and '{f}'; non-zero remainder '{f}'",
14039 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValueSema(pt, sema) },14039 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), rem.fmtValueSema(sema) },
14040 );14040 );
14041 }14041 }
14042 }14042 }
...@@ -14087,7 +14087,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -14087,7 +14087,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
14087 block,14087 block,
14088 src,14088 src,
14089 "division with '{f}' and '{f}': signed integers must use @divTrunc, @divFloor, @divCeil, or @divExact",14089 "division with '{f}' and '{f}': signed integers must use @divTrunc, @divFloor, @divCeil, or @divExact",
14090 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt) },14090 .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu) },
14091 );14091 );
14092 }14092 }
14093 break :blk .div_trunc;14093 break :blk .div_trunc;
...@@ -14804,7 +14804,7 @@ fn zirOverflowArithmetic(...@@ -14804,7 +14804,7 @@ fn zirOverflowArithmetic(
14804 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);14804 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);
1480514805
14806 if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .int) {14806 if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .int) {
14807 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(pt)});14807 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(zcu)});
14808 }14808 }
1480914809
14810 const maybe_lhs_val = sema.resolveValue(lhs);14810 const maybe_lhs_val = sema.resolveValue(lhs);
...@@ -15064,7 +15064,7 @@ fn analyzeArithmetic(...@@ -15064,7 +15064,7 @@ fn analyzeArithmetic(
15064 };15064 };
15065 if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) {15065 if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) {
15066 return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{15066 return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{
15067 lhs_ty.fmt(pt), rhs_ty.fmt(pt),15067 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
15068 });15068 });
15069 }15069 }
1507015070
...@@ -15072,7 +15072,7 @@ fn analyzeArithmetic(...@@ -15072,7 +15072,7 @@ fn analyzeArithmetic(
15072 const elem_size = lhs_elem_ty.abiSize(zcu);15072 const elem_size = lhs_elem_ty.abiSize(zcu);
15073 if (elem_size == 0) {15073 if (elem_size == 0) {
15074 return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{15074 return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{
15075 lhs_elem_ty.fmt(pt),15075 lhs_elem_ty.fmt(zcu),
15076 });15076 });
15077 }15077 }
1507815078
...@@ -15379,20 +15379,20 @@ fn zirAsm(...@@ -15379,20 +15379,20 @@ fn zirAsm(
15379 .int, .float, .bool, .vector => {},15379 .int, .float, .bool, .vector => {},
1538015380
15381 .pointer => if (out_ty.isSlice(zcu)) return sema.failWithOwnedErrorMsg(block, msg: {15381 .pointer => if (out_ty.isSlice(zcu)) return sema.failWithOwnedErrorMsg(block, msg: {
15382 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15382 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15383 errdefer msg.destroy(gpa);15383 errdefer msg.destroy(gpa);
15384 try sema.errNote(output_src, msg, "consider separate outputs for 'ptr' and 'len'", .{});15384 try sema.errNote(output_src, msg, "consider separate outputs for 'ptr' and 'len'", .{});
15385 break :msg msg;15385 break :msg msg;
15386 }),15386 }),
1538715387
15388 .optional => if (!out_ty.isPtrLikeOptional(zcu)) {15388 .optional => if (!out_ty.isPtrLikeOptional(zcu)) {
15389 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15389 return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15390 },15390 },
1539115391
15392 .@"enum" => switch (ip.loadEnumType(out_ty.toIntern()).int_tag_mode) {15392 .@"enum" => switch (ip.loadEnumType(out_ty.toIntern()).int_tag_mode) {
15393 .explicit => {},15393 .explicit => {},
15394 .auto => return sema.failWithOwnedErrorMsg(block, msg: {15394 .auto => return sema.failWithOwnedErrorMsg(block, msg: {
15395 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15395 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15396 errdefer msg.destroy(gpa);15396 errdefer msg.destroy(gpa);
15397 try sema.errNote(out_ty.srcLoc(zcu), msg, "integer tag type of enum is inferred", .{});15397 try sema.errNote(out_ty.srcLoc(zcu), msg, "integer tag type of enum is inferred", .{});
15398 try sema.errNote(out_ty.srcLoc(zcu), msg, "consider explicitly specifying the integer tag type", .{});15398 try sema.errNote(out_ty.srcLoc(zcu), msg, "consider explicitly specifying the integer tag type", .{});
...@@ -15403,7 +15403,7 @@ fn zirAsm(...@@ -15403,7 +15403,7 @@ fn zirAsm(
15403 .@"struct" => switch (out_ty.containerLayout(zcu)) {15403 .@"struct" => switch (out_ty.containerLayout(zcu)) {
15404 .@"packed" => {},15404 .@"packed" => {},
15405 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {15405 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15406 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15406 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15407 errdefer msg.destroy(gpa);15407 errdefer msg.destroy(gpa);
15408 try sema.errNote(output_src, msg, "struct types cannot be passed to inline assembly", .{});15408 try sema.errNote(output_src, msg, "struct types cannot be passed to inline assembly", .{});
15409 try sema.addDeclaredHereNote(msg, out_ty);15409 try sema.addDeclaredHereNote(msg, out_ty);
...@@ -15414,7 +15414,7 @@ fn zirAsm(...@@ -15414,7 +15414,7 @@ fn zirAsm(
15414 .@"union" => switch (out_ty.containerLayout(zcu)) {15414 .@"union" => switch (out_ty.containerLayout(zcu)) {
15415 .@"packed" => {},15415 .@"packed" => {},
15416 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {15416 .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: {
15417 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15417 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15418 errdefer msg.destroy(gpa);15418 errdefer msg.destroy(gpa);
15419 try sema.errNote(output_src, msg, "union types cannot be passed to inline assembly", .{});15419 try sema.errNote(output_src, msg, "union types cannot be passed to inline assembly", .{});
15420 try sema.addDeclaredHereNote(msg, out_ty);15420 try sema.addDeclaredHereNote(msg, out_ty);
...@@ -15423,7 +15423,7 @@ fn zirAsm(...@@ -15423,7 +15423,7 @@ fn zirAsm(
15423 },15423 },
1542415424
15425 .array => return sema.failWithOwnedErrorMsg(block, msg: {15425 .array => return sema.failWithOwnedErrorMsg(block, msg: {
15426 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)});15426 const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)});
15427 errdefer msg.destroy(gpa);15427 errdefer msg.destroy(gpa);
15428 try sema.errNote(output_src, msg, "array types cannot be passed to inline assembly", .{});15428 try sema.errNote(output_src, msg, "array types cannot be passed to inline assembly", .{});
15429 break :msg msg;15429 break :msg msg;
...@@ -15444,7 +15444,7 @@ fn zirAsm(...@@ -15444,7 +15444,7 @@ fn zirAsm(
15444 .@"anyframe",15444 .@"anyframe",
15445 .enum_literal,15445 .enum_literal,
15446 .spirv,15446 .spirv,
15447 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}),15447 => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}),
15448 }15448 }
1544915449
15450 const constraint = sema.code.nullTerminatedString(output.data.constraint);15450 const constraint = sema.code.nullTerminatedString(output.data.constraint);
...@@ -15500,7 +15500,7 @@ fn zirAsm(...@@ -15500,7 +15500,7 @@ fn zirAsm(
15500 },15500 },
15501 else => true,15501 else => true,
15502 };15502 };
15503 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(pt)});15503 if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(zcu)});
15504 }15504 }
15505 needed_capacity += (constraint.len + name.len + (2 + 3)) / 4;15505 needed_capacity += (constraint.len + name.len + (2 + 3)) / 4;
15506 inputs[arg_i] = .{ .c = constraint, .n = name };15506 inputs[arg_i] = .{ .c = constraint, .n = name };
...@@ -15598,7 +15598,7 @@ fn zirCmpEq(...@@ -15598,7 +15598,7 @@ fn zirCmpEq(
1559815598
15599 if (lhs_ty_tag == .null or rhs_ty_tag == .null) {15599 if (lhs_ty_tag == .null or rhs_ty_tag == .null) {
15600 const non_null_type = if (lhs_ty_tag == .null) rhs_ty else lhs_ty;15600 const non_null_type = if (lhs_ty_tag == .null) rhs_ty else lhs_ty;
15601 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(pt)});15601 return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(zcu)});
15602 }15602 }
1560315603
15604 if (lhs_ty_tag == .@"union" and (rhs_ty_tag == .enum_literal or rhs_ty_tag == .@"enum")) {15604 if (lhs_ty_tag == .@"union" and (rhs_ty_tag == .enum_literal or rhs_ty_tag == .@"enum")) {
...@@ -15654,7 +15654,7 @@ fn analyzeCmpUnionTag(...@@ -15654,7 +15654,7 @@ fn analyzeCmpUnionTag(
15654 const msg = msg: {15654 const msg = msg: {
15655 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});15655 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
15656 errdefer msg.destroy(sema.gpa);15656 errdefer msg.destroy(sema.gpa);
15657 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(pt)});15657 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(zcu)});
15658 break :msg msg;15658 break :msg msg;
15659 };15659 };
15660 return sema.failWithOwnedErrorMsg(block, msg);15660 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -15738,7 +15738,7 @@ fn analyzeCmp(...@@ -15738,7 +15738,7 @@ fn analyzeCmp(
15738 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });15738 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
15739 if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) {15739 if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) {
15740 return sema.fail(block, src, "operator {s} not allowed for type '{f}'", .{15740 return sema.fail(block, src, "operator {s} not allowed for type '{f}'", .{
15741 compareOperatorName(op), resolved_type.fmt(pt),15741 compareOperatorName(op), resolved_type.fmt(zcu),
15742 });15742 });
15743 }15743 }
15744 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15744 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
...@@ -15844,11 +15844,11 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15844,11 +15844,11 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15844 try sema.ensureLayoutResolved(ty, operand_src, .size_of);15844 try sema.ensureLayoutResolved(ty, operand_src, .size_of);
15845 switch (ty.classify(zcu)) {15845 switch (ty.classify(zcu)) {
15846 .no_possible_value,15846 .no_possible_value,
15847 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(pt)}),15847 => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(zcu)}),
1584815848
15849 .partially_comptime,15849 .partially_comptime,
15850 .fully_comptime,15850 .fully_comptime,
15851 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(pt)}),15851 => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(zcu)}),
1585215852
15853 .one_possible_value => {15853 .one_possible_value => {
15854 assert(ty.abiSize(zcu) == 0);15854 assert(ty.abiSize(zcu) == 0);
...@@ -15871,7 +15871,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -15871,7 +15871,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
15871 operand_ty.zigTypeTag(zcu) != .error_set and15871 operand_ty.zigTypeTag(zcu) != .error_set and
15872 operand_ty.zigTypeTag(zcu) != .@"enum")15872 operand_ty.zigTypeTag(zcu) != .@"enum")
15873 {15873 {
15874 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(pt)});15874 return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(zcu)});
15875 }15875 }
15876 try sema.ensureLayoutResolved(operand_ty, operand_src, .size_of);15876 try sema.ensureLayoutResolved(operand_ty, operand_src, .size_of);
15877 return .fromValue(try pt.intValue(.comptime_int, operand_ty.bitSize(zcu)));15877 return .fromValue(try pt.intValue(.comptime_int, operand_ty.bitSize(zcu)));
...@@ -17356,7 +17356,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi...@@ -17356,7 +17356,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
17356 block,17356 block,
17357 src,17357 src,
17358 "bit shifting operation expected integer type, found '{f}'",17358 "bit shifting operation expected integer type, found '{f}'",
17359 .{operand.fmt(pt)},17359 .{operand.fmt(zcu)},
17360 );17360 );
17361}17361}
1736217362
...@@ -17413,7 +17413,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -17413,7 +17413,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
17413 if (uncasted_ty.isVector(zcu)) {17413 if (uncasted_ty.isVector(zcu)) {
17414 if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) {17414 if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) {
17415 return sema.fail(block, operand_src, "boolean not operation on type '{f}'", .{17415 return sema.fail(block, operand_src, "boolean not operation on type '{f}'", .{
17416 uncasted_ty.fmt(pt),17416 uncasted_ty.fmt(zcu),
17417 });17417 });
17418 }17418 }
17419 return analyzeBitNot(sema, block, uncasted_operand, src);17419 return analyzeBitNot(sema, block, uncasted_operand, src);
...@@ -17589,7 +17589,7 @@ fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi...@@ -17589,7 +17589,7 @@ fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi
17589 const pt = sema.pt;17589 const pt = sema.pt;
17590 const zcu = pt.zcu;17590 const zcu = pt.zcu;
17591 if (!ty.isSelfComparable(zcu, true)) {17591 if (!ty.isSelfComparable(zcu, true)) {
17592 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(pt)});17592 return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(zcu)});
17593 }17593 }
17594}17594}
1759517595
...@@ -17641,7 +17641,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {...@@ -17641,7 +17641,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
17641 switch (ty.zigTypeTag(zcu)) {17641 switch (ty.zigTypeTag(zcu)) {
17642 .error_set, .error_union, .undefined => return,17642 .error_set, .error_union, .undefined => return,
17643 else => return sema.fail(block, src, "expected error union type, found '{f}'", .{17643 else => return sema.fail(block, src, "expected error union type, found '{f}'", .{
17644 ty.fmt(pt),17644 ty.fmt(zcu),
17645 }),17645 }),
17646 }17646 }
17647}17647}
...@@ -17779,7 +17779,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -17779,7 +17779,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
17779 const zcu = pt.zcu;17779 const zcu = pt.zcu;
17780 if (err_union_ty.zigTypeTag(zcu) != .error_union) {17780 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
17781 return sema.failWithOwnedErrorMsg(parent_block, msg: {17781 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17782 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});17782 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
17783 errdefer msg.destroy(sema.gpa);17783 errdefer msg.destroy(sema.gpa);
17784 try sema.addDeclaredHereNote(msg, err_union_ty);17784 try sema.addDeclaredHereNote(msg, err_union_ty);
17785 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});17785 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
...@@ -17847,7 +17847,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -17847,7 +17847,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
17847 const zcu = pt.zcu;17847 const zcu = pt.zcu;
17848 if (err_union_ty.zigTypeTag(zcu) != .error_union) {17848 if (err_union_ty.zigTypeTag(zcu) != .error_union) {
17849 return sema.failWithOwnedErrorMsg(parent_block, msg: {17849 return sema.failWithOwnedErrorMsg(parent_block, msg: {
17850 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)});17850 const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)});
17851 errdefer msg.destroy(sema.gpa);17851 errdefer msg.destroy(sema.gpa);
17852 try sema.addDeclaredHereNote(msg, err_union_ty);17852 try sema.addDeclaredHereNote(msg, err_union_ty);
17853 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});17853 try sema.errNote(operand_src, msg, "consider omitting 'try'", .{});
...@@ -18046,7 +18046,7 @@ fn zirRetImplicit(...@@ -18046,7 +18046,7 @@ fn zirRetImplicit(
18046 if (base_tag == .noreturn) {18046 if (base_tag == .noreturn) {
18047 const msg = msg: {18047 const msg = msg: {
18048 const msg = try sema.errMsg(ret_ty_src, "function declared '{f}' implicitly returns", .{18048 const msg = try sema.errMsg(ret_ty_src, "function declared '{f}' implicitly returns", .{
18049 sema.fn_ret_ty.fmt(pt),18049 sema.fn_ret_ty.fmt(zcu),
18050 });18050 });
18051 errdefer msg.destroy(sema.gpa);18051 errdefer msg.destroy(sema.gpa);
18052 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});18052 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
...@@ -18056,7 +18056,7 @@ fn zirRetImplicit(...@@ -18056,7 +18056,7 @@ fn zirRetImplicit(
18056 } else if (base_tag != .void) {18056 } else if (base_tag != .void) {
18057 const msg = msg: {18057 const msg = msg: {
18058 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{f}' implicitly returns", .{18058 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{f}' implicitly returns", .{
18059 sema.fn_ret_ty.fmt(pt),18059 sema.fn_ret_ty.fmt(zcu),
18060 });18060 });
18061 errdefer msg.destroy(sema.gpa);18061 errdefer msg.destroy(sema.gpa);
18062 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});18062 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
...@@ -18467,7 +18467,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18467,7 +18467,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18467 if (host_size != 0) {18467 if (host_size != 0) {
18468 try sema.ensureLayoutResolved(elem_ty, elem_ty_src, .bit_ptr_child);18468 try sema.ensureLayoutResolved(elem_ty, elem_ty_src, .bit_ptr_child);
18469 if (elem_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {18469 if (elem_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
18470 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(pt)});18470 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(zcu)});
18471 errdefer msg.destroy(sema.gpa);18471 errdefer msg.destroy(sema.gpa);
18472 try sema.explainWhyTypeIsUnpackable(msg, elem_ty_src, reason);18472 try sema.explainWhyTypeIsUnpackable(msg, elem_ty_src, reason);
18473 break :msg msg;18473 break :msg msg;
...@@ -18475,12 +18475,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18475,12 +18475,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18475 const elem_bit_size = elem_ty.bitSize(zcu);18475 const elem_bit_size = elem_ty.bitSize(zcu);
18476 if (bit_offset >= host_size * 8) {18476 if (bit_offset >= host_size * 8) {
18477 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", .{18477 return sema.fail(block, bitoffset_src, "packed type '{f}' at bit offset {d} starts {d} bits after the end of a {d} byte host integer", .{
18478 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,18478 elem_ty.fmt(zcu), bit_offset, bit_offset - host_size * 8, host_size,
18479 });18479 });
18480 }18480 }
18481 if (elem_bit_size > host_size * 8 - bit_offset) {18481 if (elem_bit_size > host_size * 8 - bit_offset) {
18482 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", .{18482 return sema.fail(block, bitoffset_src, "packed type '{f}' at bit offset {d} ends {d} bits after the end of a {d} byte host integer", .{
18483 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,18483 elem_ty.fmt(zcu), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
18484 });18484 });
18485 }18485 }
18486 }18486 }
...@@ -18490,7 +18490,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18490,7 +18490,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18490 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});18490 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
18491 }18491 }
18492 } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {18492 } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {
18493 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)});18493 return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)});
18494 }18494 }
1849518495
18496 const ty = try pt.ptrType(.{18496 const ty = try pt.ptrType(.{
...@@ -18652,7 +18652,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -18652,7 +18652,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
18652 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;18652 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
18653 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);18653 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
18654 if (union_ty.zigTypeTag(pt.zcu) != .@"union") {18654 if (union_ty.zigTypeTag(pt.zcu) != .@"union") {
18655 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(pt)});18655 return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(zcu)});
18656 }18656 }
18657 union_ty.assertHasLayout(zcu); // from a previous `field_type_ref` instruction18657 union_ty.assertHasLayout(zcu); // from a previous `field_type_ref` instruction
18658 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_names });18658 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_names });
...@@ -18784,7 +18784,7 @@ fn zirStructInit(...@@ -18784,7 +18784,7 @@ fn zirStructInit(
1878418784
18785 if (field_ty.classify(zcu) == .no_possible_value) {18785 if (field_ty.classify(zcu) == .no_possible_value) {
18786 return sema.failWithOwnedErrorMsg(block, msg: {18786 return sema.failWithOwnedErrorMsg(block, msg: {
18787 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});18787 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
18788 errdefer msg.destroy(sema.gpa);18788 errdefer msg.destroy(sema.gpa);
1878918789
18790 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{f}' declared here", .{18790 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{f}' declared here", .{
...@@ -19573,7 +19573,7 @@ fn fieldType(...@@ -19573,7 +19573,7 @@ fn fieldType(
19573 else => {},19573 else => {},
19574 }19574 }
19575 return sema.fail(block, ty_src, "expected struct or union; found '{f}'", .{19575 return sema.fail(block, ty_src, "expected struct or union; found '{f}'", .{
19576 cur_ty.fmt(pt),19576 cur_ty.fmt(zcu),
19577 });19577 });
19578 }19578 }
19579}19579}
...@@ -19627,7 +19627,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19627,7 +19627,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19627 const ty = try sema.resolveType(block, operand_src, inst_data.operand);19627 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
19628 try sema.ensureLayoutResolved(ty, operand_src, .align_of);19628 try sema.ensureLayoutResolved(ty, operand_src, .align_of);
19629 if (ty.isNoReturn(zcu)) {19629 if (ty.isNoReturn(zcu)) {
19630 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)});19630 return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(zcu)});
19631 }19631 }
19632 return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?));19632 return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?));
19633}19633}
...@@ -19702,7 +19702,7 @@ fn zirAbs(...@@ -19702,7 +19702,7 @@ fn zirAbs(
19702 block,19702 block,
19703 operand_src,19703 operand_src,
19704 "expected integer, float, or vector of either integers or floats, found '{f}'",19704 "expected integer, float, or vector of either integers or floats, found '{f}'",
19705 .{operand_ty.fmt(pt)},19705 .{operand_ty.fmt(zcu)},
19706 ),19706 ),
19707 };19707 };
1970819708
...@@ -19763,7 +19763,7 @@ fn unaryMath(...@@ -19763,7 +19763,7 @@ fn unaryMath(
19763 block,19763 block,
19764 operand_src,19764 operand_src,
19765 "expected vector of floats or float type, found '{f}'",19765 "expected vector of floats or float type, found '{f}'",
19766 .{operand_ty.fmt(pt)},19766 .{operand_ty.fmt(zcu)},
19767 ),19767 ),
19768 }19768 }
1976919769
...@@ -19804,9 +19804,9 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19804,9 +19804,9 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19804 },19804 },
19805 .@"enum" => operand_ty,19805 .@"enum" => operand_ty,
19806 .@"union" => operand_ty.unionTagType(zcu) orelse19806 .@"union" => operand_ty.unionTagType(zcu) orelse
19807 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(pt)}),19807 return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(zcu)}),
19808 else => return sema.fail(block, operand_src, "expected enum or union; found '{f}'", .{19808 else => return sema.fail(block, operand_src, "expected enum or union; found '{f}'", .{
19809 operand_ty.fmt(pt),19809 operand_ty.fmt(zcu),
19810 }),19810 }),
19811 };19811 };
19812 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);19812 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
...@@ -19814,7 +19814,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19814,7 +19814,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19814 const field_index = enum_ty.enumTagFieldIndex(val, zcu) orelse {19814 const field_index = enum_ty.enumTagFieldIndex(val, zcu) orelse {
19815 const msg = msg: {19815 const msg = msg: {
19816 const msg = try sema.errMsg(src, "no field with value '{f}' in enum '{f}'", .{19816 const msg = try sema.errMsg(src, "no field with value '{f}' in enum '{f}'", .{
19817 val.fmtValueSema(pt, sema), enum_ty.fmt(pt),19817 val.fmtValueSema(sema), enum_ty.fmt(zcu),
19818 });19818 });
19819 errdefer msg.destroy(sema.gpa);19819 errdefer msg.destroy(sema.gpa);
19820 try sema.errNote(enum_ty.srcLoc(zcu), msg, "declared here", .{});19820 try sema.errNote(enum_ty.srcLoc(zcu), msg, "declared here", .{});
...@@ -20026,7 +20026,7 @@ fn zirReifyPointer(...@@ -20026,7 +20026,7 @@ fn zirReifyPointer(
20026 },20026 },
20027 .@"opaque" => switch (size) {20027 .@"opaque" => switch (size) {
20028 .one => {},20028 .one => {},
20029 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}),20029 .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)}),
20030 },20030 },
20031 else => {},20031 else => {},
20032 }20032 }
...@@ -20962,7 +20962,7 @@ fn zirReifySpirvType(...@@ -20962,7 +20962,7 @@ fn zirReifySpirvType(
20962 if (sampled_type.toIntern() != .void_type and20962 if (sampled_type.toIntern() != .void_type and
20963 (!sampled_type.hasRuntimeBits(zcu) or (!sampled_type.isRuntimeFloat() and !sampled_type.isInt(zcu))))20963 (!sampled_type.hasRuntimeBits(zcu) or (!sampled_type.isRuntimeFloat() and !sampled_type.isInt(zcu))))
20964 {20964 {
20965 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(pt) });20965 return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(zcu) });
20966 }20966 }
2096720967
20968 if (target.os.tag == .vulkan) {20968 if (target.os.tag == .vulkan) {
...@@ -20994,7 +20994,7 @@ fn zirReifySpirvType(...@@ -20994,7 +20994,7 @@ fn zirReifySpirvType(
20994 block,20994 block,
20995 operand_src,20995 operand_src,
20996 "image 'format' '.{t}' does not match '{t}' type '{f}' under the 'vulkan' OS",20996 "image 'format' '.{t}' does not match '{t}' type '{f}' under the 'vulkan' OS",
20997 .{ format, usage_tag, sampled_type.fmt(pt) },20997 .{ format, usage_tag, sampled_type.fmt(zcu) },
20998 );20998 );
20999 }20999 }
21000 }21000 }
...@@ -21017,7 +21017,7 @@ fn zirReifySpirvType(...@@ -21017,7 +21017,7 @@ fn zirReifySpirvType(
21017 .sampled_image => blk: {21017 .sampled_image => blk: {
21018 const image_ty = Value.fromInterned(union_val.val).toType();21018 const image_ty = Value.fromInterned(union_val.val).toType();
21019 if (image_ty.zigTypeTag(zcu) != .spirv or ip.loadSpirvType(image_ty.toIntern()).flags.tag != .image) {21019 if (image_ty.zigTypeTag(zcu) != .spirv or ip.loadSpirvType(image_ty.toIntern()).flags.tag != .image) {
21020 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(pt)});21020 return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(zcu)});
21021 }21021 }
21022 const image_info = ip.loadSpirvType(image_ty.toIntern()).flags;21022 const image_info = ip.loadSpirvType(image_ty.toIntern()).flags;
21023 if (image_info.usage != .sampled) {21023 if (image_info.usage != .sampled) {
...@@ -21077,6 +21077,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In...@@ -21077,6 +21077,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
21077}21077}
2107821078
21079fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {21079fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21080 const zcu = sema.pt.zcu;
21080 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;21081 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
21081 const src = block.nodeOffset(extra.node);21082 const src = block.nodeOffset(extra.node);
21082 const va_list_src = block.builtinCallArgSrc(extra.node, 0);21083 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
...@@ -21085,9 +21086,9 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -21085,9 +21086,9 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
21085 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);21086 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
21086 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);21087 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
21087 try sema.ensureLayoutResolved(arg_ty, ty_src, .parameter);21088 try sema.ensureLayoutResolved(arg_ty, ty_src, .parameter);
21088 if (!arg_ty.validateExtern(.param_ty, sema.pt.zcu)) {21089 if (!arg_ty.validateExtern(.param_ty, zcu)) {
21089 const msg = msg: {21090 const msg = msg: {
21090 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(sema.pt)});21091 const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(zcu)});
21091 errdefer msg.destroy(sema.gpa);21092 errdefer msg.destroy(sema.gpa);
2109221093
21093 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);21094 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
...@@ -21150,7 +21151,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -21150,7 +21151,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
21150 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);21151 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21151 const ty = try sema.resolveType(block, ty_src, inst_data.operand);21152 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2115221153
21153 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(pt)}, .no_embedded_nulls);21154 const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(zcu)}, .no_embedded_nulls);
21154 return sema.addNullTerminatedStrLit(type_name);21155 return sema.addNullTerminatedStrLit(type_name);
21155}21156}
2115621157
...@@ -21179,7 +21180,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -21179,7 +21180,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2117921180
21180 switch (dest_scalar_ty.zigTypeTag(zcu)) {21181 switch (dest_scalar_ty.zigTypeTag(zcu)) {
21181 .comptime_int, .int => {},21182 .comptime_int, .int => {},
21182 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),21183 else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
21183 }21184 }
21184 try sema.checkFloatType(block, operand_src, operand_scalar_ty);21185 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
2118521186
...@@ -21260,7 +21261,7 @@ fn zirRoundCast(...@@ -21260,7 +21261,7 @@ fn zirRoundCast(
21260 block,21261 block,
21261 operand_src,21262 operand_src,
21262 "expected float or vector type, found '{f}'",21263 "expected float or vector type, found '{f}'",
21263 .{operand_ty.fmt(pt)},21264 .{operand_ty.fmt(zcu)},
21264 ),21265 ),
21265 }21266 }
2126621267
...@@ -21294,7 +21295,7 @@ fn zirRoundCast(...@@ -21294,7 +21295,7 @@ fn zirRoundCast(
21294 block,21295 block,
21295 src,21296 src,
21296 "expected integer, float, or vector of either integers or floats, found '{f}'",21297 "expected integer, float, or vector of either integers or floats, found '{f}'",
21297 .{dest_ty.fmt(pt)},21298 .{dest_ty.fmt(zcu)},
21298 ),21299 ),
21299 }21300 }
2130021301
...@@ -21358,7 +21359,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -21358,7 +21359,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2135821359
21359 switch (dest_scalar_ty.zigTypeTag(zcu)) {21360 switch (dest_scalar_ty.zigTypeTag(zcu)) {
21360 .comptime_float, .float => {},21361 .comptime_float, .float => {},
21361 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}),21362 else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}),
21362 }21363 }
21363 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);21364 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
2136421365
...@@ -21418,7 +21419,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -21418,7 +21419,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2141821419
21419 if (ptr_ty.isSlice(zcu)) {21420 if (ptr_ty.isSlice(zcu)) {
21420 const msg = msg: {21421 const msg = msg: {
21421 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(pt)});21422 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(zcu)});
21422 errdefer msg.destroy(sema.gpa);21423 errdefer msg.destroy(sema.gpa);
21423 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});21424 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
21424 break :msg msg;21425 break :msg msg;
...@@ -21491,7 +21492,7 @@ fn ptrFromIntVal(...@@ -21491,7 +21492,7 @@ fn ptrFromIntVal(
21491 }21492 }
21492 const addr = operand_val.toUnsignedInt(zcu);21493 const addr = operand_val.toUnsignedInt(zcu);
21493 if (!ptr_ty.isAllowzeroPtr(zcu) and addr == 0)21494 if (!ptr_ty.isAllowzeroPtr(zcu) and addr == 0)
21494 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(pt)});21495 return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(zcu)});
21495 if (addr != 0 and ptr_align != .none) {21496 if (addr != 0 and ptr_align != .none) {
21496 const masked_addr = if (ptr_ty.childType(zcu).fnPtrMaskOrNull(zcu)) |mask|21497 const masked_addr = if (ptr_ty.childType(zcu).fnPtrMaskOrNull(zcu)) |mask|
21497 addr & mask21498 addr & mask
...@@ -21499,7 +21500,7 @@ fn ptrFromIntVal(...@@ -21499,7 +21500,7 @@ fn ptrFromIntVal(
21499 addr;21500 addr;
2150021501
21501 if (!ptr_align.check(masked_addr)) {21502 if (!ptr_align.check(masked_addr)) {
21502 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(pt)});21503 return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(zcu)});
21503 }21504 }
21504 }21505 }
2150521506
...@@ -21544,8 +21545,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -21544,8 +21545,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
21544 errdefer msg.destroy(sema.gpa);21545 errdefer msg.destroy(sema.gpa);
21545 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);21546 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
21546 const operand_payload_ty = operand_ty.errorUnionPayload(zcu);21547 const operand_payload_ty = operand_ty.errorUnionPayload(zcu);
21547 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(pt)});21548 try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(zcu)});
21548 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(pt)});21549 try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(zcu)});
21549 try addDeclaredHereNote(sema, msg, dest_ty);21550 try addDeclaredHereNote(sema, msg, dest_ty);
21550 try addDeclaredHereNote(sema, msg, operand_ty);21551 try addDeclaredHereNote(sema, msg, operand_ty);
21551 break :msg msg;21552 break :msg msg;
...@@ -21619,7 +21620,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -21619,7 +21620,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2161921620
21620 if (result == .disjoint and !(operand_tag == .error_union and dest_tag == .error_union)) {21621 if (result == .disjoint and !(operand_tag == .error_union and dest_tag == .error_union)) {
21621 return sema.fail(block, src, "error sets '{f}' and '{f}' have no common errors", .{21622 return sema.fail(block, src, "error sets '{f}' and '{f}' have no common errors", .{
21622 operand_err_ty.fmt(pt), dest_err_ty.fmt(pt),21623 operand_err_ty.fmt(zcu), dest_err_ty.fmt(zcu),
21623 });21624 });
21624 }21625 }
2162521626
...@@ -21644,7 +21645,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -21644,7 +21645,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2164421645
21645 if (result != .superset and !dest_err_ty.errorSetHasField(err_name, zcu)) {21646 if (result != .superset and !dest_err_ty.errorSetHasField(err_name, zcu)) {
21646 return sema.fail(block, src, "'error.{f}' not a member of error set '{f}'", .{21647 return sema.fail(block, src, "'error.{f}' not a member of error set '{f}'", .{
21647 err_name.fmt(ip), dest_err_ty.fmt(pt),21648 err_name.fmt(ip), dest_err_ty.fmt(zcu),
21648 });21649 });
21649 }21650 }
2165021651
...@@ -21809,7 +21810,7 @@ fn ptrCastFull(...@@ -21809,7 +21810,7 @@ fn ptrCastFull(
21809 if (src_elem_ty.zigTypeTag(zcu) == .@"opaque") {21810 if (src_elem_ty.zigTypeTag(zcu) == .@"opaque") {
21810 return sema.failWithOwnedErrorMsg(block, msg: {21811 return sema.failWithOwnedErrorMsg(block, msg: {
21811 const msg = try sema.errMsg(src, "cannot infer length of slice of '{f}' from pointer to opaque type '{f}' with unknown size", .{21812 const msg = try sema.errMsg(src, "cannot infer length of slice of '{f}' from pointer to opaque type '{f}' with unknown size", .{
21812 dest_elem_ty.fmt(pt), src_elem_ty.fmt(pt),21813 dest_elem_ty.fmt(zcu), src_elem_ty.fmt(zcu),
21813 });21814 });
21814 errdefer msg.destroy(gpa);21815 errdefer msg.destroy(gpa);
21815 try sema.addDeclaredHereNote(msg, src_elem_ty);21816 try sema.addDeclaredHereNote(msg, src_elem_ty);
...@@ -21820,14 +21821,14 @@ fn ptrCastFull(...@@ -21820,14 +21821,14 @@ fn ptrCastFull(
21820 const dest_elem_size = dest_elem_ty.abiSize(zcu);21821 const dest_elem_size = dest_elem_ty.abiSize(zcu);
21821 if (dest_elem_size == 0) {21822 if (dest_elem_size == 0) {
21822 return sema.fail(block, src, "cannot infer length of slice of zero-bit '{f}' from '{f}'", .{21823 return sema.fail(block, src, "cannot infer length of slice of zero-bit '{f}' from '{f}'", .{
21823 dest_elem_ty.fmt(pt), operand_ty.fmt(pt),21824 dest_elem_ty.fmt(zcu), operand_ty.fmt(zcu),
21824 });21825 });
21825 }21826 }
21826 if (opt_src_len) |src_len| {21827 if (opt_src_len) |src_len| {
21827 const bytes = src_len * src_elem_size;21828 const bytes = src_len * src_elem_size;
21828 const dest_len = std.math.divExact(u64, bytes, dest_elem_size) catch switch (src_info.flags.size) {21829 const dest_len = std.math.divExact(u64, bytes, dest_elem_size) catch switch (src_info.flags.size) {
21829 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),21830 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21830 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(pt)}),21831 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(zcu)}),
21831 else => unreachable,21832 else => unreachable,
21832 };21833 };
21833 break :len .{ .constant = dest_len };21834 break :len .{ .constant = dest_len };
...@@ -21846,7 +21847,7 @@ fn ptrCastFull(...@@ -21846,7 +21847,7 @@ fn ptrCastFull(
21846 // The result value will have `dest_len * dest_base_per_elem` values of type `dest_base_ty`.21847 // The result value will have `dest_len * dest_base_per_elem` values of type `dest_base_ty`.
21847 if (dest_base_ty.toIntern() != src_base_ty.toIntern()) {21848 if (dest_base_ty.toIntern() != src_base_ty.toIntern()) {
21848 return sema.fail(block, src, "cannot infer length of comptime-only '{f}' from incompatible '{f}'", .{21849 return sema.fail(block, src, "cannot infer length of comptime-only '{f}' from incompatible '{f}'", .{
21849 dest_ty.fmt(pt), operand_ty.fmt(pt),21850 dest_ty.fmt(zcu), operand_ty.fmt(zcu),
21850 });21851 });
21851 }21852 }
21852 // `src_base_ty` is comptime-only, so `src_elem_ty` is comptime-only, so `operand_ty` is21853 // `src_base_ty` is comptime-only, so `src_elem_ty` is comptime-only, so `operand_ty` is
...@@ -21855,7 +21856,7 @@ fn ptrCastFull(...@@ -21855,7 +21856,7 @@ fn ptrCastFull(
21855 const base_len = src_len * src_base_per_elem;21856 const base_len = src_len * src_base_per_elem;
21856 const dest_len = std.math.divExact(u64, base_len, dest_base_per_elem) catch switch (src_info.flags.size) {21857 const dest_len = std.math.divExact(u64, base_len, dest_base_per_elem) catch switch (src_info.flags.size) {
21857 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),21858 .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}),
21858 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(pt)}),21859 .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(zcu)}),
21859 else => unreachable,21860 else => unreachable,
21860 };21861 };
21861 break :len .{ .constant = dest_len };21862 break :len .{ .constant = dest_len };
...@@ -21917,7 +21918,7 @@ fn ptrCastFull(...@@ -21917,7 +21918,7 @@ fn ptrCastFull(
21917 if (imc_res == .ok) break :check_child;21918 if (imc_res == .ok) break :check_child;
21918 return sema.failWithOwnedErrorMsg(block, msg: {21919 return sema.failWithOwnedErrorMsg(block, msg: {
21919 const msg = try sema.errMsg(src, "pointer element type '{f}' cannot coerce into element type '{f}'", .{21920 const msg = try sema.errMsg(src, "pointer element type '{f}' cannot coerce into element type '{f}'", .{
21920 src_child.fmt(pt), dest_child.fmt(pt),21921 src_child.fmt(zcu), dest_child.fmt(zcu),
21921 });21922 });
21922 errdefer msg.destroy(sema.gpa);21923 errdefer msg.destroy(sema.gpa);
21923 try imc_res.report(sema, src, msg);21924 try imc_res.report(sema, src, msg);
...@@ -21944,12 +21945,12 @@ fn ptrCastFull(...@@ -21944,12 +21945,12 @@ fn ptrCastFull(
21944 return sema.failWithOwnedErrorMsg(block, msg: {21945 return sema.failWithOwnedErrorMsg(block, msg: {
21945 const msg = if (src_info.sentinel == .none) blk: {21946 const msg = if (src_info.sentinel == .none) blk: {
21946 break :blk try sema.errMsg(src, "destination pointer requires '{f}' sentinel", .{21947 break :blk try sema.errMsg(src, "destination pointer requires '{f}' sentinel", .{
21947 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),21948 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
21948 });21949 });
21949 } else blk: {21950 } else blk: {
21950 break :blk try sema.errMsg(src, "pointer sentinel '{f}' cannot coerce into pointer sentinel '{f}'", .{21951 break :blk try sema.errMsg(src, "pointer sentinel '{f}' cannot coerce into pointer sentinel '{f}'", .{
21951 Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema),21952 Value.fromInterned(src_info.sentinel).fmtValueSema(sema),
21952 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),21953 Value.fromInterned(dest_info.sentinel).fmtValueSema(sema),
21953 });21954 });
21954 };21955 };
21955 errdefer msg.destroy(sema.gpa);21956 errdefer msg.destroy(sema.gpa);
...@@ -21990,8 +21991,8 @@ fn ptrCastFull(...@@ -21990,8 +21991,8 @@ fn ptrCastFull(
2199021991
21991 return sema.failWithOwnedErrorMsg(block, msg: {21992 return sema.failWithOwnedErrorMsg(block, msg: {
21992 const msg = try sema.errMsg(src, "'{f}' could have null values which are illegal in type '{f}'", .{21993 const msg = try sema.errMsg(src, "'{f}' could have null values which are illegal in type '{f}'", .{
21993 operand_ty.fmt(pt),21994 operand_ty.fmt(zcu),
21994 dest_ty.fmt(pt),21995 dest_ty.fmt(zcu),
21995 });21996 });
21996 errdefer msg.destroy(sema.gpa);21997 errdefer msg.destroy(sema.gpa);
21997 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});21998 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
...@@ -22018,10 +22019,10 @@ fn ptrCastFull(...@@ -22018,10 +22019,10 @@ fn ptrCastFull(
22018 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});22019 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
22019 errdefer msg.destroy(sema.gpa);22020 errdefer msg.destroy(sema.gpa);
22020 try sema.errNote(operand_src, msg, "'{f}' has alignment '{d}'", .{22021 try sema.errNote(operand_src, msg, "'{f}' has alignment '{d}'", .{
22021 operand_ty.fmt(pt), src_align.toByteUnits() orelse 0,22022 operand_ty.fmt(zcu), src_align.toByteUnits() orelse 0,
22022 });22023 });
22023 try sema.errNote(src, msg, "'{f}' has alignment '{d}'", .{22024 try sema.errNote(src, msg, "'{f}' has alignment '{d}'", .{
22024 dest_ty.fmt(pt), dest_align.toByteUnits() orelse 0,22025 dest_ty.fmt(zcu), dest_align.toByteUnits() orelse 0,
22025 });22026 });
22026 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});22027 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
22027 break :msg msg;22028 break :msg msg;
...@@ -22035,10 +22036,10 @@ fn ptrCastFull(...@@ -22035,10 +22036,10 @@ fn ptrCastFull(
22035 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});22036 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
22036 errdefer msg.destroy(sema.gpa);22037 errdefer msg.destroy(sema.gpa);
22037 try sema.errNote(operand_src, msg, "'{f}' has address space '{s}'", .{22038 try sema.errNote(operand_src, msg, "'{f}' has address space '{s}'", .{
22038 operand_ty.fmt(pt), @tagName(src_info.flags.address_space),22039 operand_ty.fmt(zcu), @tagName(src_info.flags.address_space),
22039 });22040 });
22040 try sema.errNote(src, msg, "'{f}' has address space '{s}'", .{22041 try sema.errNote(src, msg, "'{f}' has address space '{s}'", .{
22041 dest_ty.fmt(pt), @tagName(dest_info.flags.address_space),22042 dest_ty.fmt(zcu), @tagName(dest_info.flags.address_space),
22042 });22043 });
22043 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});22044 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
22044 break :msg msg;22045 break :msg msg;
...@@ -22104,7 +22105,7 @@ fn ptrCastFull(...@@ -22104,7 +22105,7 @@ fn ptrCastFull(
2210422105
22105 if (operand_val.isNull(zcu)) {22106 if (operand_val.isNull(zcu)) {
22106 if (!dest_ty.ptrAllowsZero(zcu)) {22107 if (!dest_ty.ptrAllowsZero(zcu)) {
22107 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});22108 return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
22108 }22109 }
22109 if (dest_ty.zigTypeTag(zcu) == .optional) {22110 if (dest_ty.zigTypeTag(zcu) == .optional) {
22110 return Air.internedToRef((try pt.nullValue(dest_ty)).toIntern());22111 return Air.internedToRef((try pt.nullValue(dest_ty)).toIntern());
...@@ -22418,7 +22419,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -22418,7 +22419,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2241822419
22419 if (operand_info.signedness != dest_info.signedness) {22420 if (operand_info.signedness != dest_info.signedness) {
22420 return sema.fail(block, operand_src, "expected {s} integer type, found '{f}'", .{22421 return sema.fail(block, operand_src, "expected {s} integer type, found '{f}'", .{
22421 @tagName(dest_info.signedness), operand_ty.fmt(pt),22422 @tagName(dest_info.signedness), operand_ty.fmt(zcu),
22422 });22423 });
22423 }22424 }
22424 if (dest_info.bits >= operand_info.bits) {22425 if (dest_info.bits >= operand_info.bits) {
...@@ -22503,7 +22504,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -22503,7 +22504,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
22503 block,22504 block,
22504 operand_src,22505 operand_src,
22505 "@byteSwap requires the number of bits to be evenly divisible by 8, but {f} has {d} bits",22506 "@byteSwap requires the number of bits to be evenly divisible by 8, but {f} has {d} bits",
22506 .{ scalar_ty.fmt(pt), bits },22507 .{ scalar_ty.fmt(zcu), bits },
22507 );22508 );
22508 }22509 }
22509 if (sema.resolveValue(operand)) |operand_val| {22510 if (sema.resolveValue(operand)) |operand_val| {
...@@ -22553,7 +22554,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -22553,7 +22554,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
22553 const ip = &zcu.intern_pool;22554 const ip = &zcu.intern_pool;
22554 switch (ty.zigTypeTag(zcu)) {22555 switch (ty.zigTypeTag(zcu)) {
22555 .@"struct" => {},22556 .@"struct" => {},
22556 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(pt)}),22557 else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(zcu)}),
22557 }22558 }
2255822559
22559 const field_index = if (ty.isTuple(zcu)) blk: {22560 const field_index = if (ty.isTuple(zcu)) blk: {
...@@ -22588,7 +22589,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com...@@ -22588,7 +22589,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
22588 const zcu = pt.zcu;22589 const zcu = pt.zcu;
22589 switch (ty.zigTypeTag(zcu)) {22590 switch (ty.zigTypeTag(zcu)) {
22590 .@"struct", .@"enum", .@"union", .@"opaque" => return,22591 .@"struct", .@"enum", .@"union", .@"opaque" => return,
22591 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(pt)}),22592 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(zcu)}),
22592 }22593 }
22593}22594}
2259422595
...@@ -22599,7 +22600,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr...@@ -22599,7 +22600,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr
22599 switch (ty.zigTypeTag(zcu)) {22600 switch (ty.zigTypeTag(zcu)) {
22600 .comptime_int => return true,22601 .comptime_int => return true,
22601 .int => return false,22602 .int => return false,
22602 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(pt)}),22603 else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(zcu)}),
22603 }22604 }
22604}22605}
2260522606
...@@ -22654,7 +22655,7 @@ fn checkPtrOperand(...@@ -22654,7 +22655,7 @@ fn checkPtrOperand(
22654 const msg = try sema.errMsg(22655 const msg = try sema.errMsg(
22655 ty_src,22656 ty_src,
22656 "expected pointer, found '{f}'",22657 "expected pointer, found '{f}'",
22657 .{ty.fmt(pt)},22658 .{ty.fmt(zcu)},
22658 );22659 );
22659 errdefer msg.destroy(sema.gpa);22660 errdefer msg.destroy(sema.gpa);
2266022661
...@@ -22667,7 +22668,7 @@ fn checkPtrOperand(...@@ -22667,7 +22668,7 @@ fn checkPtrOperand(
22667 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,22668 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
22668 else => {},22669 else => {},
22669 }22670 }
22670 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});22671 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
22671}22672}
2267222673
22673fn checkPtrType(22674fn checkPtrType(
...@@ -22686,7 +22687,7 @@ fn checkPtrType(...@@ -22686,7 +22687,7 @@ fn checkPtrType(
22686 const msg = try sema.errMsg(22687 const msg = try sema.errMsg(
22687 ty_src,22688 ty_src,
22688 "expected pointer type, found '{f}'",22689 "expected pointer type, found '{f}'",
22689 .{ty.fmt(pt)},22690 .{ty.fmt(zcu)},
22690 );22691 );
22691 errdefer msg.destroy(sema.gpa);22692 errdefer msg.destroy(sema.gpa);
2269222693
...@@ -22699,7 +22700,7 @@ fn checkPtrType(...@@ -22699,7 +22700,7 @@ fn checkPtrType(
22699 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,22700 .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return,
22700 else => {},22701 else => {},
22701 }22702 }
22702 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)});22703 return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)});
22703}22704}
2270422705
22705fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {22706fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
...@@ -22712,7 +22713,7 @@ fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ...@@ -22712,7 +22713,7 @@ fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
22712 const as = ty.ptrAddressSpace(zcu);22713 const as = ty.ptrAddressSpace(zcu);
22713 if (target_util.shouldBlockPointerOps(target, as)) {22714 if (target_util.shouldBlockPointerOps(target, as)) {
22714 return sema.failWithOwnedErrorMsg(block, msg: {22715 return sema.failWithOwnedErrorMsg(block, msg: {
22715 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(pt)});22716 const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(zcu)});
22716 errdefer msg.destroy(sema.gpa);22717 errdefer msg.destroy(sema.gpa);
22717 try sema.errNote(22718 try sema.errNote(
22718 src,22719 src,
...@@ -22761,9 +22762,9 @@ fn checkLogicalPtrCast(...@@ -22761,9 +22762,9 @@ fn checkLogicalPtrCast(
22761 },22762 },
22762 else => null,22763 else => null,
22763 } orelse return sema.failWithOwnedErrorMsg(block, msg: {22764 } orelse return sema.failWithOwnedErrorMsg(block, msg: {
22764 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(pt), dest_ty.fmt(pt) });22765 const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(zcu), dest_ty.fmt(zcu) });
22765 errdefer msg.destroy(sema.gpa);22766 errdefer msg.destroy(sema.gpa);
22766 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(pt), src_child.fmt(pt) });22767 try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(zcu), src_child.fmt(zcu) });
22767 break :msg msg;22768 break :msg msg;
22768 });22769 });
22769 }22770 }
...@@ -22782,7 +22783,7 @@ fn checkVectorElemType(...@@ -22782,7 +22783,7 @@ fn checkVectorElemType(
22782 .optional, .pointer => if (ty.isPtrAtRuntime(zcu)) return,22783 .optional, .pointer => if (ty.isPtrAtRuntime(zcu)) return,
22783 else => {},22784 else => {},
22784 }22785 }
22785 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(pt)});22786 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(zcu)});
22786}22787}
2278722788
22788fn checkFloatType(22789fn checkFloatType(
...@@ -22795,7 +22796,7 @@ fn checkFloatType(...@@ -22795,7 +22796,7 @@ fn checkFloatType(
22795 const zcu = pt.zcu;22796 const zcu = pt.zcu;
22796 switch (ty.zigTypeTag(zcu)) {22797 switch (ty.zigTypeTag(zcu)) {
22797 .comptime_int, .comptime_float, .float => {},22798 .comptime_int, .comptime_float, .float => {},
22798 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(pt)}),22799 else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(zcu)}),
22799 }22800 }
22800}22801}
2280122802
...@@ -22813,7 +22814,7 @@ fn checkNumericType(...@@ -22813,7 +22814,7 @@ fn checkNumericType(
22813 .comptime_float, .float, .comptime_int, .int => {},22814 .comptime_float, .float, .comptime_int, .int => {},
22814 else => |t| return sema.fail(block, ty_src, "expected number, found '{t}'", .{t}),22815 else => |t| return sema.fail(block, ty_src, "expected number, found '{t}'", .{t}),
22815 },22816 },
22816 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(pt)}),22817 else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(zcu)}),
22817 }22818 }
22818}22819}
2281922820
...@@ -22849,7 +22850,7 @@ fn checkAtomicPtrOperand(...@@ -22849,7 +22850,7 @@ fn checkAtomicPtrOperand(
22849 block,22850 block,
22850 elem_ty_src,22851 elem_ty_src,
22851 "expected bool, integer, float, enum, packed struct, or pointer type; found '{f}'",22852 "expected bool, integer, float, enum, packed struct, or pointer type; found '{f}'",
22852 .{elem_ty.fmt(pt)},22853 .{elem_ty.fmt(zcu)},
22853 ),22854 ),
22854 };22855 };
2285522856
...@@ -22910,12 +22911,12 @@ fn checkIntOrVector(...@@ -22910,12 +22911,12 @@ fn checkIntOrVector(
22910 switch (elem_ty.zigTypeTag(zcu)) {22911 switch (elem_ty.zigTypeTag(zcu)) {
22911 .int => return elem_ty,22912 .int => return elem_ty,
22912 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{22913 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22913 elem_ty.fmt(pt),22914 elem_ty.fmt(zcu),
22914 }),22915 }),
22915 }22916 }
22916 },22917 },
22917 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{22918 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22918 operand_ty.fmt(pt),22919 operand_ty.fmt(zcu),
22919 }),22920 }),
22920 }22921 }
22921}22922}
...@@ -22935,12 +22936,12 @@ fn checkIntOrVectorAllowComptime(...@@ -22935,12 +22936,12 @@ fn checkIntOrVectorAllowComptime(
22935 switch (elem_ty.zigTypeTag(zcu)) {22936 switch (elem_ty.zigTypeTag(zcu)) {
22936 .int, .comptime_int => return elem_ty,22937 .int, .comptime_int => return elem_ty,
22937 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{22938 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{
22938 elem_ty.fmt(pt),22939 elem_ty.fmt(zcu),
22939 }),22940 }),
22940 }22941 }
22941 },22942 },
22942 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{22943 else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{
22943 operand_ty.fmt(pt),22944 operand_ty.fmt(zcu),
22944 }),22945 }),
22945 }22946 }
22946}22947}
...@@ -23031,7 +23032,7 @@ fn checkVectorizableBinaryOperands(...@@ -23031,7 +23032,7 @@ fn checkVectorizableBinaryOperands(
23031 } else {23032 } else {
23032 const msg = msg: {23033 const msg = msg: {
23033 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{f}' and '{f}'", .{23034 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{f}' and '{f}'", .{
23034 lhs_ty.fmt(pt), rhs_ty.fmt(pt),23035 lhs_ty.fmt(zcu), rhs_ty.fmt(zcu),
23035 });23036 });
23036 errdefer msg.destroy(sema.gpa);23037 errdefer msg.destroy(sema.gpa);
23037 if (lhs_is_vector) {23038 if (lhs_is_vector) {
...@@ -23178,7 +23179,7 @@ fn zirCmpxchg(...@@ -23178,7 +23179,7 @@ fn zirCmpxchg(
23178 block,23179 block,
23179 elem_ty_src,23180 elem_ty_src,
23180 "expected bool, integer, enum, packed struct, or pointer type; found '{f}'",23181 "expected bool, integer, enum, packed struct, or pointer type; found '{f}'",
23181 .{elem_ty.fmt(pt)},23182 .{elem_ty.fmt(zcu)},
23182 );23183 );
23183 }23184 }
23184 const uncasted_ptr = sema.resolveInst(extra.ptr);23185 const uncasted_ptr = sema.resolveInst(extra.ptr);
...@@ -23258,7 +23259,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -23258,7 +23259,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2325823259
23259 switch (dest_ty.zigTypeTag(zcu)) {23260 switch (dest_ty.zigTypeTag(zcu)) {
23260 .array, .vector => {},23261 .array, .vector => {},
23261 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(pt)}),23262 else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(zcu)}),
23262 }23263 }
2326323264
23264 const operand = sema.resolveInst(extra.rhs);23265 const operand = sema.resolveInst(extra.rhs);
...@@ -23307,7 +23308,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -23307,7 +23308,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
23307 const zcu = pt.zcu;23308 const zcu = pt.zcu;
2330823309
23309 if (operand_ty.zigTypeTag(zcu) != .vector) {23310 if (operand_ty.zigTypeTag(zcu) != .vector) {
23310 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});23311 return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
23311 }23312 }
2331223313
23313 const scalar_ty = operand_ty.childType(zcu);23314 const scalar_ty = operand_ty.childType(zcu);
...@@ -23317,13 +23318,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -23317,13 +23318,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
23317 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {23318 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
23318 .int, .bool => {},23319 .int, .bool => {},
23319 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{f}'", .{23320 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{f}'", .{
23320 @tagName(operation), operand_ty.fmt(pt),23321 @tagName(operation), operand_ty.fmt(zcu),
23321 }),23322 }),
23322 },23323 },
23323 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {23324 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
23324 .int, .float => {},23325 .int, .float => {},
23325 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{f}'", .{23326 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{f}'", .{
23326 @tagName(operation), operand_ty.fmt(pt),23327 @tagName(operation), operand_ty.fmt(zcu),
23327 }),23328 }),
23328 },23329 },
23329 }23330 }
...@@ -23378,7 +23379,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -23378,7 +23379,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2337823379
23379 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {23380 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
23380 .array, .vector => sema.typeOf(mask).arrayLen(zcu),23381 .array, .vector => sema.typeOf(mask).arrayLen(zcu),
23381 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(pt)}),23382 else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(zcu)}),
23382 };23383 };
23383 mask_ty = try pt.vectorType(.{23384 mask_ty = try pt.vectorType(.{
23384 .len = @intCast(mask_len),23385 .len = @intCast(mask_len),
...@@ -23411,7 +23412,7 @@ fn analyzeShuffle(...@@ -23411,7 +23412,7 @@ fn analyzeShuffle(
23411 .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)),23412 .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)),
23412 .undefined => 0,23413 .undefined => 0,
23413 else => return sema.fail(block, a_src, "expected vector of '{f}', found '{f}'", .{23414 else => return sema.fail(block, a_src, "expected vector of '{f}', found '{f}'", .{
23414 elem_ty.fmt(pt), sema.typeOf(a_uncoerced).fmt(pt),23415 elem_ty.fmt(zcu), sema.typeOf(a_uncoerced).fmt(zcu),
23415 }),23416 }),
23416 };23417 };
23417 const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() });23418 const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() });
...@@ -23422,7 +23423,7 @@ fn analyzeShuffle(...@@ -23422,7 +23423,7 @@ fn analyzeShuffle(
23422 .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)),23423 .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)),
23423 .undefined => 0,23424 .undefined => 0,
23424 else => return sema.fail(block, b_src, "expected vector of '{f}', found '{f}'", .{23425 else => return sema.fail(block, b_src, "expected vector of '{f}', found '{f}'", .{
23425 elem_ty.fmt(pt), sema.typeOf(b_uncoerced).fmt(pt),23426 elem_ty.fmt(zcu), sema.typeOf(b_uncoerced).fmt(zcu),
23426 }),23427 }),
23427 };23428 };
23428 const b_ty = try pt.vectorType(.{ .len = b_len, .child = elem_ty.toIntern() });23429 const b_ty = try pt.vectorType(.{ .len = b_len, .child = elem_ty.toIntern() });
...@@ -23461,7 +23462,7 @@ fn analyzeShuffle(...@@ -23461,7 +23462,7 @@ fn analyzeShuffle(
23461 if (idx >= a_len) return sema.failWithOwnedErrorMsg(block, msg: {23462 if (idx >= a_len) return sema.failWithOwnedErrorMsg(block, msg: {
23462 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});23463 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
23463 errdefer msg.destroy(sema.gpa);23464 errdefer msg.destroy(sema.gpa);
23464 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(pt) });23465 try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(zcu) });
23465 if (idx < b_len) {23466 if (idx < b_len) {
23466 try sema.errNote(b_src, msg, "use '~@as(u32, {d})' to index into second vector given here", .{idx});23467 try sema.errNote(b_src, msg, "use '~@as(u32, {d})' to index into second vector given here", .{idx});
23467 }23468 }
...@@ -23474,7 +23475,7 @@ fn analyzeShuffle(...@@ -23474,7 +23475,7 @@ fn analyzeShuffle(
23474 if (idx >= b_len) return sema.failWithOwnedErrorMsg(block, msg: {23475 if (idx >= b_len) return sema.failWithOwnedErrorMsg(block, msg: {
23475 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});23476 const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx});
23476 errdefer msg.destroy(sema.gpa);23477 errdefer msg.destroy(sema.gpa);
23477 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(pt) });23478 try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(zcu) });
23478 break :msg msg;23479 break :msg msg;
23479 });23480 });
23480 }23481 }
...@@ -23576,7 +23577,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -23576,7 +23577,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2357623577
23577 const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) {23578 const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) {
23578 .vector, .array => pred_ty.arrayLen(zcu),23579 .vector, .array => pred_ty.arrayLen(zcu),
23579 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(pt)}),23580 else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(zcu)}),
23580 };23581 };
23581 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));23582 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
2358223583
...@@ -23834,7 +23835,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -23834,7 +23835,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2383423835
23835 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {23836 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
23836 .comptime_float, .float => {},23837 .comptime_float, .float => {},
23837 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(pt)}),23838 else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(zcu)}),
23838 }23839 }
2383923840
23840 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {23841 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
...@@ -23932,7 +23933,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -23932,7 +23933,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2393223933
23933 const args_ty = sema.typeOf(args);23934 const args_ty = sema.typeOf(args);
23934 if (!args_ty.isTuple(zcu)) {23935 if (!args_ty.isTuple(zcu)) {
23935 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(pt)});23936 return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(zcu)});
23936 }23937 }
2393723938
23938 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));23939 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));
...@@ -23982,13 +23983,13 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -23982,13 +23983,13 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
23982 };23983 };
23983 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);23984 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);
23984 if (parent_ptr_info.flags.size != .one) {23985 if (parent_ptr_info.flags.size != .one) {
23985 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(pt)});23986 return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(zcu)});
23986 }23987 }
23987 const parent_ty: Type = .fromInterned(parent_ptr_info.child);23988 const parent_ty: Type = .fromInterned(parent_ptr_info.child);
23988 try sema.ensureLayoutResolved(parent_ty, inst_src, .field_used);23989 try sema.ensureLayoutResolved(parent_ty, inst_src, .field_used);
23989 switch (parent_ty.zigTypeTag(zcu)) {23990 switch (parent_ty.zigTypeTag(zcu)) {
23990 .@"struct", .@"union" => {},23991 .@"struct", .@"union" => {},
23991 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(pt)}),23992 else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(zcu)}),
23992 }23993 }
2399323994
23994 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name });23995 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name });
...@@ -24071,7 +24072,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -24071,7 +24072,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2407124072
24072 if (field.index != field_index) {24073 if (field.index != field_index) {
24073 return sema.fail(block, inst_src, "field '{f}' has index '{d}' but pointer value is index '{d}' of struct '{f}'", .{24074 return sema.fail(block, inst_src, "field '{f}' has index '{d}' but pointer value is index '{d}' of struct '{f}'", .{
24074 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(pt),24075 field_name.fmt(ip), field_index, field.index, parent_ty.fmt(zcu),
24075 });24076 });
24076 }24077 }
24077 break :result .fromValue(try pt.getCoerced(.fromInterned(field.base), unaligned_parent_ptr_ty));24078 break :result .fromValue(try pt.getCoerced(.fromInterned(field.base), unaligned_parent_ptr_ty));
...@@ -24113,7 +24114,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -24113,7 +24114,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
24113 const msg = try sema.errMsg(inst_src, "@fieldParentPtr increases pointer alignment", .{});24114 const msg = try sema.errMsg(inst_src, "@fieldParentPtr increases pointer alignment", .{});
24114 errdefer msg.destroy(sema.gpa);24115 errdefer msg.destroy(sema.gpa);
24115 try sema.errNote(inst_src, msg, "parent pointer type '{f}' has alignment '{d}'", .{24116 try sema.errNote(inst_src, msg, "parent pointer type '{f}' has alignment '{d}'", .{
24116 parent_ptr_ty.fmt(pt),24117 parent_ptr_ty.fmt(zcu),
24117 parent_ptr_ty.abiAlignment(zcu),24118 parent_ptr_ty.abiAlignment(zcu),
24118 });24119 });
24119 if (parent_ty.isTuple(zcu)) {24120 if (parent_ty.isTuple(zcu)) {
...@@ -24240,7 +24241,7 @@ fn analyzeMinMax(...@@ -24240,7 +24241,7 @@ fn analyzeMinMax(
24240 try sema.checkNumericType(block, operand_src, operand_ty);24241 try sema.checkNumericType(block, operand_src, operand_ty);
24241 if (operand_ty.zigTypeTag(zcu) != .vector) {24242 if (operand_ty.zigTypeTag(zcu) != .vector) {
24242 return sema.failWithOwnedErrorMsg(block, msg: {24243 return sema.failWithOwnedErrorMsg(block, msg: {
24243 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)});24244 const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)});
24244 errdefer msg.destroy(zcu.gpa);24245 errdefer msg.destroy(zcu.gpa);
24245 try sema.errNote(operand_srcs[0], msg, "vector operand here", .{});24246 try sema.errNote(operand_srcs[0], msg, "vector operand here", .{});
24246 break :msg msg;24247 break :msg msg;
...@@ -24248,7 +24249,7 @@ fn analyzeMinMax(...@@ -24248,7 +24249,7 @@ fn analyzeMinMax(
24248 }24249 }
24249 if (operand_ty.vectorLen(zcu) != vec_len) {24250 if (operand_ty.vectorLen(zcu) != vec_len) {
24250 return sema.failWithOwnedErrorMsg(block, msg: {24251 return sema.failWithOwnedErrorMsg(block, msg: {
24251 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(pt) });24252 const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(zcu) });
24252 errdefer msg.destroy(zcu.gpa);24253 errdefer msg.destroy(zcu.gpa);
24253 try sema.errNote(operand_srcs[0], msg, "vector of length '{d}' here", .{vec_len});24254 try sema.errNote(operand_srcs[0], msg, "vector of length '{d}' here", .{vec_len});
24254 break :msg msg;24255 break :msg msg;
...@@ -24262,7 +24263,7 @@ fn analyzeMinMax(...@@ -24262,7 +24263,7 @@ fn analyzeMinMax(
24262 try sema.checkNumericType(block, operand_src, operand_ty);24263 try sema.checkNumericType(block, operand_src, operand_ty);
24263 if (operand_ty.zigTypeTag(zcu) == .vector) {24264 if (operand_ty.zigTypeTag(zcu) == .vector) {
24264 return sema.failWithOwnedErrorMsg(block, msg: {24265 return sema.failWithOwnedErrorMsg(block, msg: {
24265 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(pt)});24266 const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(zcu)});
24266 errdefer msg.destroy(zcu.gpa);24267 errdefer msg.destroy(zcu.gpa);
24267 try sema.errNote(operand_src, msg, "vector operand here", .{});24268 try sema.errNote(operand_src, msg, "vector operand here", .{});
24268 break :msg msg;24269 break :msg msg;
...@@ -24580,10 +24581,10 @@ fn zirMemcpy(...@@ -24580,10 +24581,10 @@ fn zirMemcpy(
24580 const msg = try sema.errMsg(src, "unknown copy length", .{});24581 const msg = try sema.errMsg(src, "unknown copy length", .{});
24581 errdefer msg.destroy(sema.gpa);24582 errdefer msg.destroy(sema.gpa);
24582 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{24583 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24583 dest_ty.fmt(pt),24584 dest_ty.fmt(zcu),
24584 });24585 });
24585 try sema.errNote(src_src, msg, "source type '{f}' provides no length", .{24586 try sema.errNote(src_src, msg, "source type '{f}' provides no length", .{
24586 src_ty.fmt(pt),24587 src_ty.fmt(zcu),
24587 });24588 });
24588 break :msg msg;24589 break :msg msg;
24589 };24590 };
...@@ -24610,7 +24611,7 @@ fn zirMemcpy(...@@ -24610,7 +24611,7 @@ fn zirMemcpy(
24610 const msg = try sema.errMsg(24611 const msg = try sema.errMsg(
24611 src,24612 src,
24612 "pointer element type '{f}' cannot coerce into element type '{f}'",24613 "pointer element type '{f}' cannot coerce into element type '{f}'",
24613 .{ src_elem_ty.fmt(pt), dest_elem_ty.fmt(pt) },24614 .{ src_elem_ty.fmt(zcu), dest_elem_ty.fmt(zcu) },
24614 );24615 );
24615 errdefer msg.destroy(sema.gpa);24616 errdefer msg.destroy(sema.gpa);
24616 try imc.report(sema, src, msg);24617 try imc.report(sema, src, msg);
...@@ -24629,10 +24630,10 @@ fn zirMemcpy(...@@ -24629,10 +24630,10 @@ fn zirMemcpy(
24629 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});24630 const msg = try sema.errMsg(src, "non-matching copy lengths", .{});
24630 errdefer msg.destroy(sema.gpa);24631 errdefer msg.destroy(sema.gpa);
24631 try sema.errNote(dest_src, msg, "length {f} here", .{24632 try sema.errNote(dest_src, msg, "length {f} here", .{
24632 dest_len_val.fmtValueSema(pt, sema),24633 dest_len_val.fmtValueSema(sema),
24633 });24634 });
24634 try sema.errNote(src_src, msg, "length {f} here", .{24635 try sema.errNote(src_src, msg, "length {f} here", .{
24635 src_len_val.fmtValueSema(pt, sema),24636 src_len_val.fmtValueSema(sema),
24636 });24637 });
24637 break :msg msg;24638 break :msg msg;
24638 };24639 };
...@@ -24850,7 +24851,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24850,7 +24851,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24850 const msg = try sema.errMsg(src, "unknown @memset length", .{});24851 const msg = try sema.errMsg(src, "unknown @memset length", .{});
24851 errdefer msg.destroy(sema.gpa);24852 errdefer msg.destroy(sema.gpa);
24852 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{24853 try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{
24853 dest_ptr_ty.fmt(pt),24854 dest_ptr_ty.fmt(zcu),
24854 });24855 });
24855 break :msg msg;24856 break :msg msg;
24856 });24857 });
...@@ -24896,7 +24897,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24896,7 +24897,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2489624897
24897 if (comptime_only_elem) {24898 if (comptime_only_elem) {
24898 return sema.failWithOwnedErrorMsg(block, msg: {24899 return sema.failWithOwnedErrorMsg(block, msg: {
24899 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(pt)});24900 const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(zcu)});
24900 errdefer msg.destroy(sema.gpa);24901 errdefer msg.destroy(sema.gpa);
24901 try sema.errNote(dest_src, msg, "operation is runtime due to destination pointer", .{});24902 try sema.errNote(dest_src, msg, "operation is runtime due to destination pointer", .{});
24902 break :msg msg;24903 break :msg msg;
...@@ -25267,16 +25268,16 @@ fn zirBuiltinExtern(...@@ -25267,16 +25268,16 @@ fn zirBuiltinExtern(
2526725268
25268 if (!elem_ty.validateExtern(.other, zcu)) {25269 if (!elem_ty.validateExtern(.other, zcu)) {
25269 return sema.failWithOwnedErrorMsg(block, msg: {25270 return sema.failWithOwnedErrorMsg(block, msg: {
25270 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});25271 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
25271 errdefer msg.destroy(sema.gpa);25272 errdefer msg.destroy(sema.gpa);
25272 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(pt)});25273 try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(zcu)});
25273 try sema.explainWhyTypeIsNotExtern(msg, ty_src, elem_ty, .other);25274 try sema.explainWhyTypeIsNotExtern(msg, ty_src, elem_ty, .other);
25274 break :msg msg;25275 break :msg msg;
25275 });25276 });
25276 }25277 }
25277 if (elem_ty.zigTypeTag(zcu) == .@"fn" and !ptr_info.flags.is_const) {25278 if (elem_ty.zigTypeTag(zcu) == .@"fn" and !ptr_info.flags.is_const) {
25278 return sema.failWithOwnedErrorMsg(block, msg: {25279 return sema.failWithOwnedErrorMsg(block, msg: {
25279 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)});25280 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)});
25280 errdefer msg.destroy(sema.gpa);25281 errdefer msg.destroy(sema.gpa);
25281 try sema.errNote(ty_src, msg, "pointer to extern function must be 'const'", .{});25282 try sema.errNote(ty_src, msg, "pointer to extern function must be 'const'", .{});
25282 break :msg msg;25283 break :msg msg;
...@@ -25540,7 +25541,7 @@ fn zirFloatOpResultType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended....@@ -25540,7 +25541,7 @@ fn zirFloatOpResultType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.
25540 block,25541 block,
25541 operand_src,25542 operand_src,
25542 "expected vector of floats or float type, found '{f}'",25543 "expected vector of floats or float type, found '{f}'",
25543 .{float_ty.fmt(sema.pt)},25544 .{float_ty.fmt(zcu)},
25544 ),25545 ),
25545 }25546 }
2554625547
...@@ -25597,7 +25598,7 @@ pub fn validateVarType(...@@ -25597,7 +25598,7 @@ pub fn validateVarType(
25597 if (is_extern) {25598 if (is_extern) {
25598 if (!var_ty.validateExtern(.other, zcu)) {25599 if (!var_ty.validateExtern(.other, zcu)) {
25599 const msg = msg: {25600 const msg = msg: {
25600 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(pt)});25601 const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(zcu)});
25601 errdefer msg.destroy(sema.gpa);25602 errdefer msg.destroy(sema.gpa);
25602 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);25603 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
25603 break :msg msg;25604 break :msg msg;
...@@ -25610,7 +25611,7 @@ pub fn validateVarType(...@@ -25610,7 +25611,7 @@ pub fn validateVarType(
25610 block,25611 block,
25611 src,25612 src,
25612 "non-extern variable with opaque type '{f}'",25613 "non-extern variable with opaque type '{f}'",
25613 .{var_ty.fmt(pt)},25614 .{var_ty.fmt(zcu)},
25614 );25615 );
25615 }25616 }
25616 }25617 }
...@@ -25618,7 +25619,7 @@ pub fn validateVarType(...@@ -25618,7 +25619,7 @@ pub fn validateVarType(
25618 if (!var_ty.comptimeOnly(zcu)) return;25619 if (!var_ty.comptimeOnly(zcu)) return;
2561925620
25620 const msg = msg: {25621 const msg = msg: {
25621 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(pt)});25622 const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(zcu)});
25622 errdefer msg.destroy(sema.gpa);25623 errdefer msg.destroy(sema.gpa);
2562325624
25624 try sema.explainWhyTypeIsComptime(msg, src, var_ty);25625 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
...@@ -25667,7 +25668,7 @@ fn explainWhyTypeIsComptime(...@@ -25667,7 +25668,7 @@ fn explainWhyTypeIsComptime(
25667 .optional => try sema.explainWhyTypeIsComptime(msg, src, ty.optionalChild(zcu)),25668 .optional => try sema.explainWhyTypeIsComptime(msg, src, ty.optionalChild(zcu)),
25668 .error_union => try sema.explainWhyTypeIsComptime(msg, src, ty.errorUnionPayload(zcu)),25669 .error_union => try sema.explainWhyTypeIsComptime(msg, src, ty.errorUnionPayload(zcu)),
2566925670
25670 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(pt)}),25671 .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(zcu)}),
25671 .type => try sema.errNote(src, msg, "types are not available at runtime", .{}),25672 .type => try sema.errNote(src, msg, "types are not available at runtime", .{}),
2567225673
25673 .@"struct" => if (zcu.typeToStruct(ty)) |struct_type| {25674 .@"struct" => if (zcu.typeToStruct(ty)) |struct_type| {
...@@ -25689,7 +25690,7 @@ fn explainWhyTypeIsComptime(...@@ -25689,7 +25690,7 @@ fn explainWhyTypeIsComptime(
25689 if (field_val_ip != .none) continue;25690 if (field_val_ip != .none) continue;
25690 const field_ty: Type = .fromInterned(field_ty_ip);25691 const field_ty: Type = .fromInterned(field_ty_ip);
25691 if (!field_ty.comptimeOnly(zcu)) continue;25692 if (!field_ty.comptimeOnly(zcu)) continue;
25692 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(pt)});25693 try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(zcu)});
25693 return sema.explainWhyTypeIsComptime(msg, src, field_ty);25694 return sema.explainWhyTypeIsComptime(msg, src, field_ty);
25694 }25695 }
25695 unreachable;25696 unreachable;
...@@ -25750,7 +25751,7 @@ pub fn explainWhyTypeIsNotExtern(...@@ -25750,7 +25751,7 @@ pub fn explainWhyTypeIsNotExtern(
25750 }25751 }
25751 },25752 },
2575225753
25753 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(pt)}),25754 .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(zcu)}),
25754 .pointer => if (ty.isSlice(zcu)) {25755 .pointer => if (ty.isSlice(zcu)) {
25755 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});25756 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
25756 } else {25757 } else {
...@@ -25782,7 +25783,7 @@ pub fn explainWhyTypeIsNotExtern(...@@ -25782,7 +25783,7 @@ pub fn explainWhyTypeIsNotExtern(
25782 },25783 },
25783 .explicit => {25784 .explicit => {
25784 const tag_ty: Type = .fromInterned(enum_obj.int_tag_type);25785 const tag_ty: Type = .fromInterned(enum_obj.int_tag_type);
25785 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(pt)});25786 try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(zcu)});
25786 try sema.explainWhyTypeIsNotExtern(msg, ty.srcLoc(zcu), tag_ty, position);25787 try sema.explainWhyTypeIsNotExtern(msg, ty.srcLoc(zcu), tag_ty, position);
25787 },25788 },
25788 }25789 }
...@@ -25800,7 +25801,7 @@ pub fn explainWhyTypeIsNotExtern(...@@ -25800,7 +25801,7 @@ pub fn explainWhyTypeIsNotExtern(
25800 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed struct has unspecified signedness", .{}),25801 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed struct has unspecified signedness", .{}),
25801 .explicit => {25802 .explicit => {
25802 const backing_int_ty: Type = .fromInterned(struct_obj.packed_backing_int_type);25803 const backing_int_ty: Type = .fromInterned(struct_obj.packed_backing_int_type);
25803 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});25804 try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
25804 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);25805 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
25805 },25806 },
25806 },25807 },
...@@ -25815,7 +25816,7 @@ pub fn explainWhyTypeIsNotExtern(...@@ -25815,7 +25816,7 @@ pub fn explainWhyTypeIsNotExtern(
25815 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed union has unspecified signedness", .{}),25816 .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed union has unspecified signedness", .{}),
25816 .explicit => {25817 .explicit => {
25817 const backing_int_ty: Type = .fromInterned(union_obj.packed_backing_int_type);25818 const backing_int_ty: Type = .fromInterned(union_obj.packed_backing_int_type);
25818 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)});25819 try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)});
25819 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);25820 try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position);
25820 },25821 },
25821 },25822 },
...@@ -26269,7 +26270,7 @@ fn fieldVal(...@@ -26269,7 +26270,7 @@ fn fieldVal(
26269 block,26270 block,
26270 field_name_src,26271 field_name_src,
26271 "no member named '{f}' in '{f}'",26272 "no member named '{f}' in '{f}'",
26272 .{ field_name.fmt(ip), object_ty.fmt(pt) },26273 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
26273 );26274 );
26274 }26275 }
26275 },26276 },
...@@ -26293,7 +26294,7 @@ fn fieldVal(...@@ -26293,7 +26294,7 @@ fn fieldVal(
26293 block,26294 block,
26294 field_name_src,26295 field_name_src,
26295 "no member named '{f}' in '{f}'",26296 "no member named '{f}' in '{f}'",
26296 .{ field_name.fmt(ip), object_ty.fmt(pt) },26297 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
26297 );26298 );
26298 }26299 }
26299 }26300 }
...@@ -26317,7 +26318,7 @@ fn fieldVal(...@@ -26317,7 +26318,7 @@ fn fieldVal(
26317 },26318 },
26318 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {26319 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
26319 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{26320 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26320 field_name.fmt(ip), child_type.fmt(pt),26321 field_name.fmt(ip), child_type.fmt(zcu),
26321 });26322 });
26322 } else child_type,26323 } else child_type,
26323 .simple_type => |t| {26324 .simple_type => |t| {
...@@ -26365,7 +26366,7 @@ fn fieldVal(...@@ -26365,7 +26366,7 @@ fn fieldVal(
26365 return sema.failWithBadMemberAccess(block, child_type, src, field_name);26366 return sema.failWithBadMemberAccess(block, child_type, src, field_name);
26366 },26367 },
26367 else => return sema.failWithOwnedErrorMsg(block, msg: {26368 else => return sema.failWithOwnedErrorMsg(block, msg: {
26368 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(pt)});26369 const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(zcu)});
26369 errdefer msg.destroy(sema.gpa);26370 errdefer msg.destroy(sema.gpa);
26370 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});26371 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
26371 if (child_type.zigTypeTag(zcu) == .array) try sema.errNote(src, msg, "array values have 'len' member", .{});26372 if (child_type.zigTypeTag(zcu) == .array) try sema.errNote(src, msg, "array values have 'len' member", .{});
...@@ -26525,7 +26526,7 @@ fn fieldPtr(...@@ -26525,7 +26526,7 @@ fn fieldPtr(
26525 const object_ptr_ty = sema.typeOf(object_ptr);26526 const object_ptr_ty = sema.typeOf(object_ptr);
26526 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {26527 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
26527 .pointer => object_ptr_ty.childType(zcu),26528 .pointer => object_ptr_ty.childType(zcu),
26528 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(pt)}),26529 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(zcu)}),
26529 };26530 };
2653026531
26531 // Zig allows dereferencing a single pointer during field lookup. Note that26532 // Zig allows dereferencing a single pointer during field lookup. Note that
...@@ -26580,7 +26581,7 @@ fn fieldPtr(...@@ -26580,7 +26581,7 @@ fn fieldPtr(
26580 block,26581 block,
26581 field_name_src,26582 field_name_src,
26582 "no member named '{f}' in '{f}'",26583 "no member named '{f}' in '{f}'",
26583 .{ field_name.fmt(ip), object_ty.fmt(pt) },26584 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
26584 );26585 );
26585 }26586 }
26586 },26587 },
...@@ -26617,7 +26618,7 @@ fn fieldPtr(...@@ -26617,7 +26618,7 @@ fn fieldPtr(
26617 block,26618 block,
26618 field_name_src,26619 field_name_src,
26619 "no member named '{f}' in '{f}'",26620 "no member named '{f}' in '{f}'",
26620 .{ field_name.fmt(ip), object_ty.fmt(pt) },26621 .{ field_name.fmt(ip), object_ty.fmt(zcu) },
26621 );26622 );
26622 }26623 }
26623 },26624 },
...@@ -26641,7 +26642,7 @@ fn fieldPtr(...@@ -26641,7 +26642,7 @@ fn fieldPtr(
26641 },26642 },
26642 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {26643 .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) {
26643 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{26644 return sema.fail(block, src, "no error named '{f}' in '{f}'", .{
26644 field_name.fmt(ip), child_type.fmt(pt),26645 field_name.fmt(ip), child_type.fmt(zcu),
26645 });26646 });
26646 } else child_type,26647 } else child_type,
26647 .simple_type => |t| {26648 .simple_type => |t| {
...@@ -26688,7 +26689,7 @@ fn fieldPtr(...@@ -26688,7 +26689,7 @@ fn fieldPtr(
26688 }26689 }
26689 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);26690 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
26690 },26691 },
26691 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(pt)}),26692 else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(zcu)}),
26692 }26693 }
26693 },26694 },
26694 .@"struct" => {26695 .@"struct" => {
...@@ -26745,7 +26746,7 @@ fn fieldCallBind(...@@ -26745,7 +26746,7 @@ fn fieldCallBind(
26745 const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c))26746 const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c))
26746 raw_ptr_ty.childType(zcu)26747 raw_ptr_ty.childType(zcu)
26747 else26748 else
26748 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(pt)});26749 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(zcu)});
2674926750
26750 // Optionally dereference a second pointer to get the concrete type.26751 // Optionally dereference a second pointer to get the concrete type.
26751 const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one;26752 const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one;
...@@ -26863,7 +26864,7 @@ fn fieldCallBind(...@@ -26863,7 +26864,7 @@ fn fieldCallBind(
26863 const msg = msg: {26864 const msg = msg: {
26864 const msg = try sema.errMsg(src, "no field or member function named '{f}' in '{f}'", .{26865 const msg = try sema.errMsg(src, "no field or member function named '{f}' in '{f}'", .{
26865 field_name.fmt(ip),26866 field_name.fmt(ip),
26866 concrete_ty.fmt(pt),26867 concrete_ty.fmt(zcu),
26867 });26868 });
26868 errdefer msg.destroy(sema.gpa);26869 errdefer msg.destroy(sema.gpa);
26869 try sema.addDeclaredHereNote(msg, concrete_ty);26870 try sema.addDeclaredHereNote(msg, concrete_ty);
...@@ -27099,18 +27100,18 @@ fn tupleFieldIndex(...@@ -27099,18 +27100,18 @@ fn tupleFieldIndex(
27099 field_name: InternPool.NullTerminatedString,27100 field_name: InternPool.NullTerminatedString,
27100 field_name_src: LazySrcLoc,27101 field_name_src: LazySrcLoc,
27101) CompileError!u32 {27102) CompileError!u32 {
27102 const pt = sema.pt;27103 const zcu = sema.pt.zcu;
27103 const ip = &pt.zcu.intern_pool;27104 const ip = &zcu.intern_pool;
27104 assert(!field_name.eqlSlice("len", ip));27105 assert(!field_name.eqlSlice("len", ip));
27105 if (field_name.toUnsigned(ip)) |field_index| {27106 if (field_name.toUnsigned(ip)) |field_index| {
27106 if (field_index < tuple_ty.structFieldCount(pt.zcu)) return field_index;27107 if (field_index < tuple_ty.structFieldCount(zcu)) return field_index;
27107 return sema.fail(block, field_name_src, "index '{f}' out of bounds of tuple '{f}'", .{27108 return sema.fail(block, field_name_src, "index '{f}' out of bounds of tuple '{f}'", .{
27108 field_name.fmt(ip), tuple_ty.fmt(pt),27109 field_name.fmt(ip), tuple_ty.fmt(zcu),
27109 });27110 });
27110 }27111 }
2711127112
27112 return sema.fail(block, field_name_src, "no field named '{f}' in tuple '{f}'", .{27113 return sema.fail(block, field_name_src, "no field named '{f}' in tuple '{f}'", .{
27113 field_name.fmt(ip), tuple_ty.fmt(pt),27114 field_name.fmt(ip), tuple_ty.fmt(zcu),
27114 });27115 });
27115}27116}
2711627117
...@@ -27172,7 +27173,7 @@ fn unionFieldPtr(...@@ -27172,7 +27173,7 @@ fn unionFieldPtr(
2717227173
27173 if (initializing and field_ty.classify(zcu) == .no_possible_value) {27174 if (initializing and field_ty.classify(zcu) == .no_possible_value) {
27174 const msg = msg: {27175 const msg = msg: {
27175 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});27176 const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
27176 errdefer msg.destroy(sema.gpa);27177 errdefer msg.destroy(sema.gpa);
2717727178
27178 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{27179 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
...@@ -27327,7 +27328,7 @@ fn elemPtr(...@@ -27327,7 +27328,7 @@ fn elemPtr(
2732727328
27328 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {27329 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
27329 .pointer => indexable_ptr_ty.childType(zcu),27330 .pointer => indexable_ptr_ty.childType(zcu),
27330 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(pt)}),27331 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(zcu)}),
27331 };27332 };
27332 try sema.checkIndexable(block, src, indexable_ty);27333 try sema.checkIndexable(block, src, indexable_ty);
27333 try sema.ensureLayoutResolved(indexable_ty, src, .ptr_access);27334 try sema.ensureLayoutResolved(indexable_ty, src, .ptr_access);
...@@ -27453,8 +27454,8 @@ fn elemVal(...@@ -27453,8 +27454,8 @@ fn elemVal(
27453 .runtime => {},27454 .runtime => {},
27454 .one_possible_value => return .fromValue((try child_ty.onePossibleValue(pt)).?),27455 .one_possible_value => return .fromValue((try child_ty.onePossibleValue(pt)).?),
27455 .no_possible_value => switch (child_ty.zigTypeTag(zcu)) {27456 .no_possible_value => switch (child_ty.zigTypeTag(zcu)) {
27456 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(pt)}),27457 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(zcu)}),
27457 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(pt)}),27458 else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(zcu)}),
27458 },27459 },
27459 .partially_comptime, .fully_comptime => unreachable, // caught by `validateRuntimeElemAccess`27460 .partially_comptime, .fully_comptime => unreachable, // caught by `validateRuntimeElemAccess`
27460 }27461 }
...@@ -27507,7 +27508,7 @@ fn validateRuntimeElemAccess(...@@ -27507,7 +27508,7 @@ fn validateRuntimeElemAccess(
27507 const msg = try sema.errMsg(27508 const msg = try sema.errMsg(
27508 elem_index_src,27509 elem_index_src,
27509 "values of type '{f}' must be comptime-known, but index value is runtime-known",27510 "values of type '{f}' must be comptime-known, but index value is runtime-known",
27510 .{elem_ty.fmt(sema.pt)},27511 .{elem_ty.fmt(zcu)},
27511 );27512 );
27512 errdefer msg.destroy(sema.gpa);27513 errdefer msg.destroy(sema.gpa);
2751327514
...@@ -27546,7 +27547,7 @@ fn tupleElemPtr(...@@ -27546,7 +27547,7 @@ fn tupleElemPtr(
27546 const index = elem_index_val.getUnsignedInt(zcu);27547 const index = elem_index_val.getUnsignedInt(zcu);
27547 if (index == null or index.? >= field_count) {27548 if (index == null or index.? >= field_count) {
27548 return sema.fail(block, elem_index_src, "index '{f}' out of bounds of tuple '{f}'", .{27549 return sema.fail(block, elem_index_src, "index '{f}' out of bounds of tuple '{f}'", .{
27549 elem_index_val.fmtValueSema(pt, sema), tuple_ty.fmt(pt),27550 elem_index_val.fmtValueSema(sema), tuple_ty.fmt(zcu),
27550 });27551 });
27551 }27552 }
2755227553
...@@ -28295,7 +28296,7 @@ fn coerceExtra(...@@ -28295,7 +28296,7 @@ fn coerceExtra(
28295 block,28296 block,
28296 inst_src,28297 inst_src,
28297 "coercion from slice to array pointer type '{f}' requires length to be known at compile-time",28298 "coercion from slice to array pointer type '{f}' requires length to be known at compile-time",
28298 .{dest_ty.fmt(pt)},28299 .{dest_ty.fmt(zcu)},
28299 );28300 );
28300 };28301 };
2830128302
...@@ -28308,7 +28309,7 @@ fn coerceExtra(...@@ -28308,7 +28309,7 @@ fn coerceExtra(
28308 if (!opts.report_err) return error.NotCoercible;28309 if (!opts.report_err) return error.NotCoercible;
28309 return sema.failWithOwnedErrorMsg(block, msg: {28310 return sema.failWithOwnedErrorMsg(block, msg: {
28310 const msg = try sema.errMsg(inst_src, "slice with undefined length cannot cast into array pointer type '{f}'", .{28311 const msg = try sema.errMsg(inst_src, "slice with undefined length cannot cast into array pointer type '{f}'", .{
28311 dest_ty.fmt(pt),28312 dest_ty.fmt(zcu),
28312 });28313 });
28313 errdefer msg.destroy(gpa);28314 errdefer msg.destroy(gpa);
28314 try sema.errNote(inst_src, msg, "length of slice must be defined and match length of array type", .{});28315 try sema.errNote(inst_src, msg, "length of slice must be defined and match length of array type", .{});
...@@ -28320,7 +28321,7 @@ fn coerceExtra(...@@ -28320,7 +28321,7 @@ fn coerceExtra(
28320 if (!opts.report_err) return error.NotCoercible;28321 if (!opts.report_err) return error.NotCoercible;
28321 return sema.failWithOwnedErrorMsg(block, msg: {28322 return sema.failWithOwnedErrorMsg(block, msg: {
28322 const msg = try sema.errMsg(inst_src, "slice of length {d} cannot cast into array pointer type '{f}'", .{28323 const msg = try sema.errMsg(inst_src, "slice of length {d} cannot cast into array pointer type '{f}'", .{
28323 slice_len, dest_ty.fmt(pt),28324 slice_len, dest_ty.fmt(zcu),
28324 });28325 });
28325 errdefer msg.destroy(gpa);28326 errdefer msg.destroy(gpa);
28326 try sema.errNote(inst_src, msg, "length of slice must match length of array type", .{});28327 try sema.errNote(inst_src, msg, "length of slice must match length of array type", .{});
...@@ -28375,7 +28376,7 @@ fn coerceExtra(...@@ -28375,7 +28376,7 @@ fn coerceExtra(
28375 block,28376 block,
28376 inst_src,28377 inst_src,
28377 "array literal requires address-of operator (&) to coerce to slice type '{f}'",28378 "array literal requires address-of operator (&) to coerce to slice type '{f}'",
28378 .{dest_ty.fmt(pt)},28379 .{dest_ty.fmt(zcu)},
28379 );28380 );
28380 }28381 }
2838128382
...@@ -28400,7 +28401,7 @@ fn coerceExtra(...@@ -28400,7 +28401,7 @@ fn coerceExtra(
28400 if (!dest_info.flags.is_const) {28401 if (!dest_info.flags.is_const) {
28401 if (!opts.report_err) return error.NotCoercible;28402 if (!opts.report_err) return error.NotCoercible;
28402 const err_msg = err_msg: {28403 const err_msg = err_msg: {
28403 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(pt)});28404 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(zcu)});
28404 errdefer err_msg.destroy(sema.gpa);28405 errdefer err_msg.destroy(sema.gpa);
28405 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});28406 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
28406 break :err_msg err_msg;28407 break :err_msg err_msg;
...@@ -28455,7 +28456,7 @@ fn coerceExtra(...@@ -28455,7 +28456,7 @@ fn coerceExtra(
28455 // comptime-known integer to other number28456 // comptime-known integer to other number
28456 if (!val.intFitsInType(dest_ty, null, zcu)) {28457 if (!val.intFitsInType(dest_ty, null, zcu)) {
28457 if (!opts.report_err) return error.NotCoercible;28458 if (!opts.report_err) return error.NotCoercible;
28458 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) });28459 return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) });
28459 }28460 }
28460 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {28461 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
28461 .undef => .fromValue(try dest_ty.onePossibleValue(pt) orelse try pt.undefValue(dest_ty)),28462 .undef => .fromValue(try dest_ty.onePossibleValue(pt) orelse try pt.undefValue(dest_ty)),
...@@ -28499,7 +28500,7 @@ fn coerceExtra(...@@ -28499,7 +28500,7 @@ fn coerceExtra(
28499 block,28500 block,
28500 inst_src,28501 inst_src,
28501 "type '{f}' cannot represent float value '{f}'",28502 "type '{f}' cannot represent float value '{f}'",
28502 .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) },28503 .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) },
28503 );28504 );
28504 }28505 }
28505 return Air.internedToRef(result_val.toIntern());28506 return Air.internedToRef(result_val.toIntern());
...@@ -28558,7 +28559,7 @@ fn coerceExtra(...@@ -28558,7 +28559,7 @@ fn coerceExtra(
28558 block,28559 block,
28559 inst_src,28560 inst_src,
28560 "type '{f}' cannot represent integer value '{f}'",28561 "type '{f}' cannot represent integer value '{f}'",
28561 .{ dest_ty.fmt(pt), val.fmtValue(pt) },28562 .{ dest_ty.fmt(zcu), val.fmtValue(zcu) },
28562 );28563 );
28563 }28564 }
28564 return .fromValue(result_val);28565 return .fromValue(result_val);
...@@ -28573,7 +28574,7 @@ fn coerceExtra(...@@ -28573,7 +28574,7 @@ fn coerceExtra(
28573 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {28574 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
28574 if (!opts.report_err) return error.NotCoercible;28575 if (!opts.report_err) return error.NotCoercible;
28575 return sema.fail(block, inst_src, "no field named '{f}' in enum '{f}'", .{28576 return sema.fail(block, inst_src, "no field named '{f}' in enum '{f}'", .{
28576 string.fmt(&zcu.intern_pool), dest_ty.fmt(pt),28577 string.fmt(&zcu.intern_pool), dest_ty.fmt(zcu),
28577 });28578 });
28578 };28579 };
28579 return Air.internedToRef((try pt.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern());28580 return Air.internedToRef((try pt.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern());
...@@ -28699,7 +28700,7 @@ fn coerceExtra(...@@ -28699,7 +28700,7 @@ fn coerceExtra(
28699 errdefer msg.destroy(sema.gpa);28700 errdefer msg.destroy(sema.gpa);
2870028701
28701 if (dest_is_npv) {28702 if (dest_is_npv) {
28702 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(pt)});28703 try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(zcu)});
28703 }28704 }
2870428705
28705 // E!T to T28706 // E!T to T
...@@ -28880,6 +28881,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -28880,6 +28881,7 @@ const InMemoryCoercionResult = union(enum) {
2888028881
28881 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {28882 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {
28882 const pt = sema.pt;28883 const pt = sema.pt;
28884 const zcu = pt.zcu;
28883 var cur = res;28885 var cur = res;
28884 while (true) switch (cur.*) {28886 while (true) switch (cur.*) {
28885 .ok => unreachable,28887 .ok => unreachable,
...@@ -28896,13 +28898,13 @@ const InMemoryCoercionResult = union(enum) {...@@ -28896,13 +28898,13 @@ const InMemoryCoercionResult = union(enum) {
28896 },28898 },
28897 .comptime_int_not_coercible => |int| {28899 .comptime_int_not_coercible => |int| {
28898 try sema.errNote(src, msg, "type '{f}' cannot represent value '{f}'", .{28900 try sema.errNote(src, msg, "type '{f}' cannot represent value '{f}'", .{
28899 int.wanted.fmt(pt), int.actual.fmtValueSema(pt, sema),28901 int.wanted.fmt(zcu), int.actual.fmtValueSema(sema),
28900 });28902 });
28901 break;28903 break;
28902 },28904 },
28903 .error_union_payload => |pair| {28905 .error_union_payload => |pair| {
28904 try sema.errNote(src, msg, "error union payload '{f}' cannot cast into error union payload '{f}'", .{28906 try sema.errNote(src, msg, "error union payload '{f}' cannot cast into error union payload '{f}'", .{
28905 pair.actual.fmt(pt), pair.wanted.fmt(pt),28907 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
28906 });28908 });
28907 cur = pair.child;28909 cur = pair.child;
28908 },28910 },
...@@ -28915,22 +28917,22 @@ const InMemoryCoercionResult = union(enum) {...@@ -28915,22 +28917,22 @@ const InMemoryCoercionResult = union(enum) {
28915 .array_sentinel => |sentinel| {28917 .array_sentinel => |sentinel| {
28916 if (sentinel.wanted.toIntern() == .unreachable_value) {28918 if (sentinel.wanted.toIntern() == .unreachable_value) {
28917 try sema.errNote(src, msg, "source array cannot be guaranteed to maintain '{f}' sentinel", .{28919 try sema.errNote(src, msg, "source array cannot be guaranteed to maintain '{f}' sentinel", .{
28918 sentinel.actual.fmtValueSema(pt, sema),28920 sentinel.actual.fmtValueSema(sema),
28919 });28921 });
28920 } else if (sentinel.actual.toIntern() == .unreachable_value) {28922 } else if (sentinel.actual.toIntern() == .unreachable_value) {
28921 try sema.errNote(src, msg, "destination array requires '{f}' sentinel", .{28923 try sema.errNote(src, msg, "destination array requires '{f}' sentinel", .{
28922 sentinel.wanted.fmtValueSema(pt, sema),28924 sentinel.wanted.fmtValueSema(sema),
28923 });28925 });
28924 } else {28926 } else {
28925 try sema.errNote(src, msg, "array sentinel '{f}' cannot cast into array sentinel '{f}'", .{28927 try sema.errNote(src, msg, "array sentinel '{f}' cannot cast into array sentinel '{f}'", .{
28926 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),28928 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
28927 });28929 });
28928 }28930 }
28929 break;28931 break;
28930 },28932 },
28931 .array_elem => |pair| {28933 .array_elem => |pair| {
28932 try sema.errNote(src, msg, "array element type '{f}' cannot cast into array element type '{f}'", .{28934 try sema.errNote(src, msg, "array element type '{f}' cannot cast into array element type '{f}'", .{
28933 pair.actual.fmt(pt), pair.wanted.fmt(pt),28935 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
28934 });28936 });
28935 cur = pair.child;28937 cur = pair.child;
28936 },28938 },
...@@ -28942,19 +28944,19 @@ const InMemoryCoercionResult = union(enum) {...@@ -28942,19 +28944,19 @@ const InMemoryCoercionResult = union(enum) {
28942 },28944 },
28943 .vector_elem => |pair| {28945 .vector_elem => |pair| {
28944 try sema.errNote(src, msg, "vector element type '{f}' cannot cast into vector element type '{f}'", .{28946 try sema.errNote(src, msg, "vector element type '{f}' cannot cast into vector element type '{f}'", .{
28945 pair.actual.fmt(pt), pair.wanted.fmt(pt),28947 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
28946 });28948 });
28947 cur = pair.child;28949 cur = pair.child;
28948 },28950 },
28949 .optional_shape => |pair| {28951 .optional_shape => |pair| {
28950 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{28952 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28951 pair.actual.optionalChild(pt.zcu).fmt(pt), pair.wanted.optionalChild(pt.zcu).fmt(pt),28953 pair.actual.optionalChild(pt.zcu).fmt(zcu), pair.wanted.optionalChild(pt.zcu).fmt(zcu),
28952 });28954 });
28953 break;28955 break;
28954 },28956 },
28955 .optional_child => |pair| {28957 .optional_child => |pair| {
28956 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{28958 try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{
28957 pair.actual.fmt(pt), pair.wanted.fmt(pt),28959 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
28958 });28960 });
28959 cur = pair.child;28961 cur = pair.child;
28960 },28962 },
...@@ -29018,7 +29020,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -29018,7 +29020,7 @@ const InMemoryCoercionResult = union(enum) {
29018 },29020 },
29019 .fn_param => |param| {29021 .fn_param => |param| {
29020 try sema.errNote(src, msg, "parameter {d} '{f}' cannot cast into '{f}'", .{29022 try sema.errNote(src, msg, "parameter {d} '{f}' cannot cast into '{f}'", .{
29021 param.index, param.actual.fmt(pt), param.wanted.fmt(pt),29023 param.index, param.actual.fmt(zcu), param.wanted.fmt(zcu),
29022 });29024 });
29023 cur = param.child;29025 cur = param.child;
29024 },29026 },
...@@ -29028,13 +29030,13 @@ const InMemoryCoercionResult = union(enum) {...@@ -29028,13 +29030,13 @@ const InMemoryCoercionResult = union(enum) {
29028 },29030 },
29029 .fn_return_type => |pair| {29031 .fn_return_type => |pair| {
29030 try sema.errNote(src, msg, "return type '{f}' cannot cast into return type '{f}'", .{29032 try sema.errNote(src, msg, "return type '{f}' cannot cast into return type '{f}'", .{
29031 pair.actual.fmt(pt), pair.wanted.fmt(pt),29033 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
29032 });29034 });
29033 cur = pair.child;29035 cur = pair.child;
29034 },29036 },
29035 .ptr_child => |pair| {29037 .ptr_child => |pair| {
29036 try sema.errNote(src, msg, "pointer type child '{f}' cannot cast into pointer type child '{f}'", .{29038 try sema.errNote(src, msg, "pointer type child '{f}' cannot cast into pointer type child '{f}'", .{
29037 pair.actual.fmt(pt), pair.wanted.fmt(pt),29039 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
29038 });29040 });
29039 cur = pair.child;29041 cur = pair.child;
29040 },29042 },
...@@ -29045,11 +29047,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -29045,11 +29047,11 @@ const InMemoryCoercionResult = union(enum) {
29045 .ptr_sentinel => |sentinel| {29047 .ptr_sentinel => |sentinel| {
29046 if (sentinel.actual.toIntern() != .unreachable_value) {29048 if (sentinel.actual.toIntern() != .unreachable_value) {
29047 try sema.errNote(src, msg, "pointer sentinel '{f}' cannot cast into pointer sentinel '{f}'", .{29049 try sema.errNote(src, msg, "pointer sentinel '{f}' cannot cast into pointer sentinel '{f}'", .{
29048 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),29050 sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema),
29049 });29051 });
29050 } else {29052 } else {
29051 try sema.errNote(src, msg, "destination pointer requires '{f}' sentinel", .{29053 try sema.errNote(src, msg, "destination pointer requires '{f}' sentinel", .{
29052 sentinel.wanted.fmtValueSema(pt, sema),29054 sentinel.wanted.fmtValueSema(sema),
29053 });29055 });
29054 }29056 }
29055 break;29057 break;
...@@ -29063,11 +29065,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -29063,11 +29065,11 @@ const InMemoryCoercionResult = union(enum) {
29063 const actual_allow_zero = pair.actual.ptrAllowsZero(pt.zcu);29065 const actual_allow_zero = pair.actual.ptrAllowsZero(pt.zcu);
29064 if (actual_allow_zero and !wanted_allow_zero) {29066 if (actual_allow_zero and !wanted_allow_zero) {
29065 try sema.errNote(src, msg, "'{f}' could have null values which are illegal in type '{f}'", .{29067 try sema.errNote(src, msg, "'{f}' could have null values which are illegal in type '{f}'", .{
29066 pair.actual.fmt(pt), pair.wanted.fmt(pt),29068 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
29067 });29069 });
29068 } else {29070 } else {
29069 try sema.errNote(src, msg, "mutable '{f}' would allow illegal null values stored to type '{f}'", .{29071 try sema.errNote(src, msg, "mutable '{f}' would allow illegal null values stored to type '{f}'", .{
29070 pair.wanted.fmt(pt), pair.actual.fmt(pt),29072 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
29071 });29073 });
29072 }29074 }
29073 break;29075 break;
...@@ -29079,7 +29081,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -29079,7 +29081,7 @@ const InMemoryCoercionResult = union(enum) {
29079 try sema.errNote(src, msg, "cast discards const qualifier", .{});29081 try sema.errNote(src, msg, "cast discards const qualifier", .{});
29080 } else {29082 } else {
29081 try sema.errNote(src, msg, "mutable '{f}' would allow illegal const pointers stored to type '{f}'", .{29083 try sema.errNote(src, msg, "mutable '{f}' would allow illegal const pointers stored to type '{f}'", .{
29082 pair.wanted.fmt(pt), pair.actual.fmt(pt),29084 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
29083 });29085 });
29084 }29086 }
29085 break;29087 break;
...@@ -29091,7 +29093,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -29091,7 +29093,7 @@ const InMemoryCoercionResult = union(enum) {
29091 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});29093 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
29092 } else {29094 } else {
29093 try sema.errNote(src, msg, "mutable '{f}' would allow illegal volatile pointers stored to type '{f}'", .{29095 try sema.errNote(src, msg, "mutable '{f}' would allow illegal volatile pointers stored to type '{f}'", .{
29094 pair.wanted.fmt(pt), pair.actual.fmt(pt),29096 pair.wanted.fmt(zcu), pair.actual.fmt(zcu),
29095 });29097 });
29096 }29098 }
29097 break;29099 break;
...@@ -29117,13 +29119,13 @@ const InMemoryCoercionResult = union(enum) {...@@ -29117,13 +29119,13 @@ const InMemoryCoercionResult = union(enum) {
29117 },29119 },
29118 .double_ptr_to_anyopaque => |pair| {29120 .double_ptr_to_anyopaque => |pair| {
29119 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{f}' to anyopaque pointer '{f}'", .{29121 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{f}' to anyopaque pointer '{f}'", .{
29120 pair.actual.fmt(pt), pair.wanted.fmt(pt),29122 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
29121 });29123 });
29122 break;29124 break;
29123 },29125 },
29124 .slice_to_anyopaque => |pair| {29126 .slice_to_anyopaque => |pair| {
29125 try sema.errNote(src, msg, "cannot implicitly cast slice '{f}' to anyopaque pointer '{f}'", .{29127 try sema.errNote(src, msg, "cannot implicitly cast slice '{f}' to anyopaque pointer '{f}'", .{
29126 pair.actual.fmt(pt), pair.wanted.fmt(pt),29128 pair.actual.fmt(zcu), pair.wanted.fmt(zcu),
29127 });29129 });
29128 try sema.errNote(src, msg, "consider using '.ptr'", .{});29130 try sema.errNote(src, msg, "consider using '.ptr'", .{});
29129 break;29131 break;
...@@ -29874,7 +29876,7 @@ fn coerceVarArgParam(...@@ -29874,7 +29876,7 @@ fn coerceVarArgParam(
29874 const coerced_ty = sema.typeOf(coerced);29876 const coerced_ty = sema.typeOf(coerced);
29875 if (!coerced_ty.validateExtern(.param_ty, zcu)) {29877 if (!coerced_ty.validateExtern(.param_ty, zcu)) {
29876 const msg = msg: {29878 const msg = msg: {
29877 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(pt)});29879 const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(zcu)});
29878 errdefer msg.destroy(sema.gpa);29880 errdefer msg.destroy(sema.gpa);
2987929881
29880 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);29882 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
...@@ -29941,7 +29943,7 @@ fn storePtr2(...@@ -29941,7 +29943,7 @@ fn storePtr2(
2994129943
29942 // We're performing the store at runtime, so the pointee type must not be comptime-only.29944 // We're performing the store at runtime, so the pointee type must not be comptime-only.
29943 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {29945 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
29944 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(pt)});29946 const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(zcu)});
29945 errdefer msg.destroy(zcu.gpa);29947 errdefer msg.destroy(zcu.gpa);
29946 try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{});29948 try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{});
29947 break :msg msg;29949 break :msg msg;
...@@ -30097,13 +30099,13 @@ fn storePtrVal(...@@ -30097,13 +30099,13 @@ fn storePtrVal(
30097 block,30099 block,
30098 src,30100 src,
30099 "comptime dereference requires '{f}' to have a well-defined layout",30101 "comptime dereference requires '{f}' to have a well-defined layout",
30100 .{ty.fmt(pt)},30102 .{ty.fmt(zcu)},
30101 ),30103 ),
30102 .out_of_bounds => |ty| return sema.fail(30104 .out_of_bounds => |ty| return sema.fail(
30103 block,30105 block,
30104 src,30106 src,
30105 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",30107 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
30106 .{ ptr_ty.fmt(pt), ty.fmt(pt) },30108 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
30107 ),30109 ),
30108 .exceeds_host_size => return sema.fail(block, src, "bit-pointer target exceeds host size", .{}),30110 .exceeds_host_size => return sema.fail(block, src, "bit-pointer target exceeds host size", .{}),
30109 }30111 }
...@@ -30315,7 +30317,7 @@ fn coerceCompatiblePtrs(...@@ -30315,7 +30317,7 @@ fn coerceCompatiblePtrs(
30315 const inst_ty = sema.typeOf(inst);30317 const inst_ty = sema.typeOf(inst);
30316 if (sema.resolveValue(inst)) |val| {30318 if (sema.resolveValue(inst)) |val| {
30317 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {30319 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {
30318 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)});30320 return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)});
30319 }30321 }
30320 // The comptime Value representation is compatible with both types.30322 // The comptime Value representation is compatible with both types.
30321 return Air.internedToRef(30323 return Air.internedToRef(
...@@ -30386,7 +30388,7 @@ fn coerceEnumToUnion(...@@ -30386,7 +30388,7 @@ fn coerceEnumToUnion(
30386 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {30388 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {
30387 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {30389 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {
30388 return sema.fail(block, inst_src, "union '{f}' has no tag with value '{f}'", .{30390 return sema.fail(block, inst_src, "union '{f}' has no tag with value '{f}'", .{
30389 union_ty.fmt(pt), val.fmtValueSema(pt, sema),30391 union_ty.fmt(zcu), val.fmtValueSema(sema),
30390 });30392 });
30391 };30393 };
3039230394
...@@ -30400,7 +30402,7 @@ fn coerceEnumToUnion(...@@ -30400,7 +30402,7 @@ fn coerceEnumToUnion(
30400 )),30402 )),
3040130403
30402 .no_possible_value => return sema.failWithOwnedErrorMsg(block, msg: {30404 .no_possible_value => return sema.failWithOwnedErrorMsg(block, msg: {
30403 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)});30405 const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)});
30404 errdefer msg.destroy(sema.gpa);30406 errdefer msg.destroy(sema.gpa);
30405 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{30407 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{
30406 field_name.fmt(ip),30408 field_name.fmt(ip),
...@@ -30411,8 +30413,8 @@ fn coerceEnumToUnion(...@@ -30411,8 +30413,8 @@ fn coerceEnumToUnion(
3041130413
30412 else => return sema.failWithOwnedErrorMsg(block, msg: {30414 else => return sema.failWithOwnedErrorMsg(block, msg: {
30413 const msg = try sema.errMsg(inst_src, "coercion from enum '{f}' to union '{f}' must initialize '{f}' field '{f}'", .{30415 const msg = try sema.errMsg(inst_src, "coercion from enum '{f}' to union '{f}' must initialize '{f}' field '{f}'", .{
30414 inst_ty.fmt(pt), union_ty.fmt(pt),30416 inst_ty.fmt(zcu), union_ty.fmt(zcu),
30415 field_ty.fmt(pt), field_name.fmt(ip),30417 field_ty.fmt(zcu), field_name.fmt(ip),
30416 });30418 });
30417 errdefer msg.destroy(sema.gpa);30419 errdefer msg.destroy(sema.gpa);
3041830420
...@@ -30428,7 +30430,7 @@ fn coerceEnumToUnion(...@@ -30428,7 +30430,7 @@ fn coerceEnumToUnion(
30428 if (enum_ty.isNonexhaustiveEnum(zcu)) {30430 if (enum_ty.isNonexhaustiveEnum(zcu)) {
30429 const msg = msg: {30431 const msg = msg: {
30430 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{f}' from non-exhaustive enum", .{30432 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{f}' from non-exhaustive enum", .{
30431 union_ty.fmt(pt),30433 union_ty.fmt(zcu),
30432 });30434 });
30433 errdefer msg.destroy(sema.gpa);30435 errdefer msg.destroy(sema.gpa);
30434 try sema.addDeclaredHereNote(msg, enum_ty);30436 try sema.addDeclaredHereNote(msg, enum_ty);
...@@ -30456,7 +30458,7 @@ fn coerceEnumToUnion(...@@ -30456,7 +30458,7 @@ fn coerceEnumToUnion(
30456 const msg = try sema.errMsg(30458 const msg = try sema.errMsg(
30457 inst_src,30459 inst_src,
30458 "runtime coercion from enum '{f}' to union '{f}' which has non-void fields",30460 "runtime coercion from enum '{f}' to union '{f}' which has non-void fields",
30459 .{ enum_ty.fmt(pt), union_ty.fmt(pt) },30461 .{ enum_ty.fmt(zcu), union_ty.fmt(zcu) },
30460 );30462 );
30461 errdefer msg.destroy(sema.gpa);30463 errdefer msg.destroy(sema.gpa);
3046230464
...@@ -30472,7 +30474,7 @@ fn coerceEnumToUnion(...@@ -30472,7 +30474,7 @@ fn coerceEnumToUnion(
30472 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' has {s} '{f}'", .{30474 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' has {s} '{f}'", .{
30473 field_name.fmt(ip),30475 field_name.fmt(ip),
30474 ty_description,30476 ty_description,
30475 field_ty.fmt(pt),30477 field_ty.fmt(zcu),
30476 });30478 });
30477 }30479 }
30478 try sema.addDeclaredHereNote(msg, union_ty);30480 try sema.addDeclaredHereNote(msg, union_ty);
...@@ -31082,7 +31084,7 @@ fn analyzeLoad(...@@ -31082,7 +31084,7 @@ fn analyzeLoad(
31082 const ptr_ty = sema.typeOf(ptr);31084 const ptr_ty = sema.typeOf(ptr);
31083 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {31085 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
31084 .pointer => ptr_ty.childType(zcu),31086 .pointer => ptr_ty.childType(zcu),
31085 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)}),31087 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)}),
31086 };31088 };
3108731089
31088 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);31090 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
...@@ -31093,11 +31095,11 @@ fn analyzeLoad(...@@ -31093,11 +31095,11 @@ fn analyzeLoad(
3109331095
31094 const comptime_only = switch (elem_ty.classify(zcu)) {31096 const comptime_only = switch (elem_ty.classify(zcu)) {
31095 .no_possible_value => switch (elem_ty.zigTypeTag(zcu)) {31097 .no_possible_value => switch (elem_ty.zigTypeTag(zcu)) {
31096 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(pt)}),31098 .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(zcu)}),
31097 else => {31099 else => {
31098 // Loading an uninstantiable type always invokes Illegal Behavior.31100 // Loading an uninstantiable type always invokes Illegal Behavior.
31099 if (block.isComptime()) {31101 if (block.isComptime()) {
31100 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(pt)});31102 return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(zcu)});
31101 } else if (block.wantSafety()) {31103 } else if (block.wantSafety()) {
31102 try sema.safetyPanic(block, src, .load_uninstantiable_type);31104 try sema.safetyPanic(block, src, .load_uninstantiable_type);
31103 return .unreachable_value;31105 return .unreachable_value;
...@@ -31122,9 +31124,9 @@ fn analyzeLoad(...@@ -31122,9 +31124,9 @@ fn analyzeLoad(
31122 }31124 }
3112331125
31124 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {31126 if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: {
31125 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(pt)});31127 const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(zcu)});
31126 errdefer msg.destroy(zcu.gpa);31128 errdefer msg.destroy(zcu.gpa);
31127 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(pt)});31129 try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(zcu)});
31128 break :msg msg;31130 break :msg msg;
31129 });31131 });
3113031132
...@@ -31432,7 +31434,7 @@ fn analyzeSlice(...@@ -31432,7 +31434,7 @@ fn analyzeSlice(
31432 const ptr_ptr_ty = sema.typeOf(ptr_ptr);31434 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
31433 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {31435 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
31434 .pointer => ptr_ptr_ty.childType(zcu),31436 .pointer => ptr_ptr_ty.childType(zcu),
31435 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(pt)}),31437 else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(zcu)}),
31436 };31438 };
3143731439
31438 var array_ty = ptr_ptr_child_ty;31440 var array_ty = ptr_ptr_child_ty;
...@@ -31483,8 +31485,8 @@ fn analyzeSlice(...@@ -31483,8 +31485,8 @@ fn analyzeSlice(
31483 msg,31485 msg,
31484 "expected '{f}', found '{f}'",31486 "expected '{f}', found '{f}'",
31485 .{31487 .{
31486 Value.zero_comptime_int.fmtValueSema(pt, sema),31488 Value.zero_comptime_int.fmtValueSema(sema),
31487 start_value.fmtValueSema(pt, sema),31489 start_value.fmtValueSema(sema),
31488 },31490 },
31489 );31491 );
31490 break :msg msg;31492 break :msg msg;
...@@ -31499,8 +31501,8 @@ fn analyzeSlice(...@@ -31499,8 +31501,8 @@ fn analyzeSlice(
31499 msg,31501 msg,
31500 "expected '{f}', found '{f}'",31502 "expected '{f}', found '{f}'",
31501 .{31503 .{
31502 Value.one_comptime_int.fmtValueSema(pt, sema),31504 Value.one_comptime_int.fmtValueSema(sema),
31503 end_value.fmtValueSema(pt, sema),31505 end_value.fmtValueSema(sema),
31504 },31506 },
31505 );31507 );
31506 break :msg msg;31508 break :msg msg;
...@@ -31513,7 +31515,7 @@ fn analyzeSlice(...@@ -31513,7 +31515,7 @@ fn analyzeSlice(
31513 block,31515 block,
31514 end_src,31516 end_src,
31515 "end index {f} out of bounds for slice of single-item pointer",31517 "end index {f} out of bounds for slice of single-item pointer",
31516 .{end_value.fmtValueSema(pt, sema)},31518 .{end_value.fmtValueSema(sema)},
31517 );31519 );
31518 }31520 }
31519 }31521 }
...@@ -31559,7 +31561,7 @@ fn analyzeSlice(...@@ -31559,7 +31561,7 @@ fn analyzeSlice(
31559 elem_ty = ptr_ptr_child_ty.childType(zcu);31561 elem_ty = ptr_ptr_child_ty.childType(zcu);
31560 },31562 },
31561 },31563 },
31562 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(pt)}),31564 else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(zcu)}),
31563 }31565 }
3156431566
31565 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);31567 try sema.ensureLayoutResolved(elem_ty, src, .ptr_access);
...@@ -31611,8 +31613,8 @@ fn analyzeSlice(...@@ -31611,8 +31613,8 @@ fn analyzeSlice(
31611 end_src,31613 end_src,
31612 "end index {f} out of bounds for array of length {f}{s}",31614 "end index {f} out of bounds for array of length {f}{s}",
31613 .{31615 .{
31614 end_val.fmtValueSema(pt, sema),31616 end_val.fmtValueSema(sema),
31615 len_val.fmtValueSema(pt, sema),31617 len_val.fmtValueSema(sema),
31616 sentinel_label,31618 sentinel_label,
31617 },31619 },
31618 );31620 );
...@@ -31656,7 +31658,7 @@ fn analyzeSlice(...@@ -31656,7 +31658,7 @@ fn analyzeSlice(
31656 end_src,31658 end_src,
31657 "end index {f} out of bounds for slice of length {d}{s}",31659 "end index {f} out of bounds for slice of length {d}{s}",
31658 .{31660 .{
31659 end_val.fmtValueSema(pt, sema),31661 end_val.fmtValueSema(sema),
31660 slice_val.sliceLen(zcu),31662 slice_val.sliceLen(zcu),
31661 sentinel_label,31663 sentinel_label,
31662 },31664 },
...@@ -31707,9 +31709,9 @@ fn analyzeSlice(...@@ -31707,9 +31709,9 @@ fn analyzeSlice(
31707 const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{});31709 const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{});
31708 errdefer msg.destroy(sema.gpa);31710 errdefer msg.destroy(sema.gpa);
31709 if (ptr_sentinel) |current| {31711 if (ptr_sentinel) |current| {
31710 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(pt), provided.fmtValue(pt) });31712 try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(zcu), provided.fmtValue(zcu) });
31711 } else {31713 } else {
31712 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(pt)});31714 try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(zcu)});
31713 }31715 }
31714 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});31716 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
31715 break :msg msg;31717 break :msg msg;
...@@ -31753,8 +31755,8 @@ fn analyzeSlice(...@@ -31753,8 +31755,8 @@ fn analyzeSlice(
31753 start_src,31755 start_src,
31754 "start index {f} is larger than end index {f}",31756 "start index {f} is larger than end index {f}",
31755 .{31757 .{
31756 start_val.fmtValueSema(pt, sema),31758 start_val.fmtValueSema(sema),
31757 end_val.fmtValueSema(pt, sema),31759 end_val.fmtValueSema(sema),
31758 },31760 },
31759 );31761 );
31760 }31762 }
...@@ -31776,13 +31778,13 @@ fn analyzeSlice(...@@ -31776,13 +31778,13 @@ fn analyzeSlice(
31776 block,31778 block,
31777 src,31779 src,
31778 "comptime dereference requires '{f}' to have a well-defined layout",31780 "comptime dereference requires '{f}' to have a well-defined layout",
31779 .{ty.fmt(pt)},31781 .{ty.fmt(zcu)},
31780 ),31782 ),
31781 .out_of_bounds => |ty| return sema.fail(31783 .out_of_bounds => |ty| return sema.fail(
31782 block,31784 block,
31783 end_src,31785 end_src,
31784 "slice end index {d} exceeds bounds of containing decl of type '{f}'",31786 "slice end index {d} exceeds bounds of containing decl of type '{f}'",
31785 .{ end_int, ty.fmt(pt) },31787 .{ end_int, ty.fmt(zcu) },
31786 ),31788 ),
31787 };31789 };
3178831790
...@@ -31791,8 +31793,8 @@ fn analyzeSlice(...@@ -31791,8 +31793,8 @@ fn analyzeSlice(
31791 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});31793 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
31792 errdefer msg.destroy(sema.gpa);31794 errdefer msg.destroy(sema.gpa);
31793 try sema.errNote(src, msg, "expected '{f}', found '{f}'", .{31795 try sema.errNote(src, msg, "expected '{f}', found '{f}'", .{
31794 expected_sentinel.fmtValueSema(pt, sema),31796 expected_sentinel.fmtValueSema(sema),
31795 actual_sentinel.fmtValueSema(pt, sema),31797 actual_sentinel.fmtValueSema(sema),
31796 });31798 });
3179731799
31798 break :msg msg;31800 break :msg msg;
...@@ -32604,7 +32606,7 @@ const PeerResolveResult = union(enum) {...@@ -32604,7 +32606,7 @@ const PeerResolveResult = union(enum) {
32604 instructions: []const Air.Inst.Ref,32606 instructions: []const Air.Inst.Ref,
32605 candidate_srcs: PeerTypeCandidateSrc,32607 candidate_srcs: PeerTypeCandidateSrc,
32606 ) !*Zcu.ErrorMsg {32608 ) !*Zcu.ErrorMsg {
32607 const pt = sema.pt;32609 const zcu = sema.pt.zcu;
3260832610
32609 var opt_msg: ?*Zcu.ErrorMsg = null;32611 var opt_msg: ?*Zcu.ErrorMsg = null;
32610 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);32612 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
...@@ -32630,7 +32632,7 @@ const PeerResolveResult = union(enum) {...@@ -32630,7 +32632,7 @@ const PeerResolveResult = union(enum) {
32630 },32632 },
32631 .field_error => |field_error| {32633 .field_error => |field_error| {
32632 const fmt = "struct field '{f}' has conflicting types";32634 const fmt = "struct field '{f}' has conflicting types";
32633 const args = .{field_error.field_name.fmt(&pt.zcu.intern_pool)};32635 const args = .{field_error.field_name.fmt(&zcu.intern_pool)};
32634 if (opt_msg) |msg| {32636 if (opt_msg) |msg| {
32635 try sema.errNote(src, msg, fmt, args);32637 try sema.errNote(src, msg, fmt, args);
32636 } else {32638 } else {
...@@ -32662,8 +32664,8 @@ const PeerResolveResult = union(enum) {...@@ -32662,8 +32664,8 @@ const PeerResolveResult = union(enum) {
3266232664
32663 const fmt = "incompatible types: '{f}' and '{f}'";32665 const fmt = "incompatible types: '{f}' and '{f}'";
32664 const args = .{32666 const args = .{
32665 conflict_tys[0].fmt(pt),32667 conflict_tys[0].fmt(zcu),
32666 conflict_tys[1].fmt(pt),32668 conflict_tys[1].fmt(zcu),
32667 };32669 };
32668 const msg = if (opt_msg) |msg| msg: {32670 const msg = if (opt_msg) |msg| msg: {
32669 try sema.errNote(src, msg, fmt, args);32671 try sema.errNote(src, msg, fmt, args);
...@@ -32674,8 +32676,8 @@ const PeerResolveResult = union(enum) {...@@ -32674,8 +32676,8 @@ const PeerResolveResult = union(enum) {
32674 break :msg msg;32676 break :msg msg;
32675 };32677 };
3267632678
32677 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(pt)});32679 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(zcu)});
32678 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(pt)});32680 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(zcu)});
3267932681
32680 // No child error32682 // No child error
32681 break;32683 break;
...@@ -33904,10 +33906,10 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {...@@ -33904,10 +33906,10 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
33904}33906}
3390533907
33906fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {33908fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
33907 const pt = sema.pt;33909 const zcu = sema.pt.zcu;
33908 if (!ty.isIndexable(pt.zcu)) {33910 if (!ty.isIndexable(zcu)) {
33909 const msg = msg: {33911 const msg = msg: {
33910 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(pt)});33912 const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(zcu)});
33911 errdefer msg.destroy(sema.gpa);33913 errdefer msg.destroy(sema.gpa);
33912 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});33914 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
33913 try sema.addDeclaredHereNote(msg, ty);33915 try sema.addDeclaredHereNote(msg, ty);
...@@ -33932,7 +33934,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void...@@ -33932,7 +33934,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
33932 }33934 }
33933 }33935 }
33934 const msg = msg: {33936 const msg = msg: {
33935 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(pt)});33937 const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(zcu)});
33936 errdefer msg.destroy(sema.gpa);33938 errdefer msg.destroy(sema.gpa);
33937 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});33939 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
33938 break :msg msg;33940 break :msg msg;
...@@ -34215,8 +34217,9 @@ pub fn analyzeAsAddressSpace(...@@ -34215,8 +34217,9 @@ pub fn analyzeAsAddressSpace(
34215/// Asserts the value is a pointer and dereferences it.34217/// Asserts the value is a pointer and dereferences it.
34216/// Returns `null` if the pointer contents cannot be loaded at comptime.34218/// Returns `null` if the pointer contents cannot be loaded at comptime.
34217fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value {34219fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value {
34218 // TODO: audit use sites to eliminate this coercion
34219 const pt = sema.pt;34220 const pt = sema.pt;
34221 const zcu = pt.zcu;
34222 // TODO: audit use sites to eliminate this coercion
34220 const coerced_ptr_val = try pt.getCoerced(ptr_val, ptr_ty);34223 const coerced_ptr_val = try pt.getCoerced(ptr_val, ptr_ty);
34221 switch (try sema.pointerDerefExtra(block, src, coerced_ptr_val)) {34224 switch (try sema.pointerDerefExtra(block, src, coerced_ptr_val)) {
34222 .runtime_load => return null,34225 .runtime_load => return null,
...@@ -34225,13 +34228,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr...@@ -34225,13 +34228,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr
34225 block,34228 block,
34226 src,34229 src,
34227 "comptime dereference requires '{f}' to have a well-defined layout",34230 "comptime dereference requires '{f}' to have a well-defined layout",
34228 .{ty.fmt(pt)},34231 .{ty.fmt(zcu)},
34229 ),34232 ),
34230 .out_of_bounds => |ty| return sema.fail(34233 .out_of_bounds => |ty| return sema.fail(
34231 block,34234 block,
34232 src,34235 src,
34233 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",34236 "dereference of '{f}' exceeds bounds of containing decl of type '{f}'",
34234 .{ ptr_ty.fmt(pt), ty.fmt(pt) },34237 .{ ptr_ty.fmt(zcu), ty.fmt(zcu) },
34235 ),34238 ),
34236 }34239 }
34237}34240}
...@@ -34354,12 +34357,12 @@ fn intFromFloatScalar(...@@ -34354,12 +34357,12 @@ fn intFromFloatScalar(
3435434357
34355 if (std.math.isNan(float)) {34358 if (std.math.isNan(float)) {
34356 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{f}'", .{34359 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{f}'", .{
34357 int_ty.fmt(pt),34360 int_ty.fmt(zcu),
34358 });34361 });
34359 }34362 }
34360 if (std.math.isInf(float)) {34363 if (std.math.isInf(float)) {
34361 return sema.fail(block, src, "float value Inf cannot be stored in integer type '{f}'", .{34364 return sema.fail(block, src, "float value Inf cannot be stored in integer type '{f}'", .{
34362 int_ty.fmt(pt),34365 int_ty.fmt(zcu),
34363 });34366 });
34364 }34367 }
3436534368
...@@ -34374,7 +34377,7 @@ fn intFromFloatScalar(...@@ -34374,7 +34377,7 @@ fn intFromFloatScalar(
34374 block,34377 block,
34375 src,34378 src,
34376 "fractional component prevents float value '{f}' from coercion to type '{f}'",34379 "fractional component prevents float value '{f}' from coercion to type '{f}'",
34377 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },34380 .{ val.fmtValueSema(sema), int_ty.fmt(zcu) },
34378 ),34381 ),
34379 .truncate, .round, .floor, .ceil => {},34382 .truncate, .round, .floor, .ceil => {},
34380 },34383 },
...@@ -34386,7 +34389,7 @@ fn intFromFloatScalar(...@@ -34386,7 +34389,7 @@ fn intFromFloatScalar(
34386 const int_info = int_ty.intInfo(zcu);34389 const int_info = int_ty.intInfo(zcu);
34387 if (!big_int.toConst().fitsInTwosComp(int_info.signedness, int_info.bits)) {34390 if (!big_int.toConst().fitsInTwosComp(int_info.signedness, int_info.bits)) {
34388 return sema.fail(block, src, "float value '{f}' cannot be stored in integer type '{f}'", .{34391 return sema.fail(block, src, "float value '{f}' cannot be stored in integer type '{f}'", .{
34389 val.fmtValueSema(pt, sema), int_ty.fmt(pt),34392 val.fmtValueSema(sema), int_ty.fmt(zcu),
34390 });34393 });
34391 }34394 }
34392 return pt.getCoerced(cti_result, int_ty);34395 return pt.getCoerced(cti_result, int_ty);
...@@ -34632,7 +34635,7 @@ fn notePathToComptimeAllocPtr(...@@ -34632,7 +34635,7 @@ fn notePathToComptimeAllocPtr(
34632 else => {}, // there will be another stage34635 else => {}, // there will be another stage
34633 }34636 }
3463434637
34635 const derivation = try comptime_ptr.pointerDerivation(arena, pt, sema);34638 const derivation = try comptime_ptr.pointerDerivation(arena, zcu, sema);
3463634639
34637 var second_path_aw: std.Io.Writer.Allocating = .init(arena);34640 var second_path_aw: std.Io.Writer.Allocating = .init(arena);
34638 defer second_path_aw.deinit();34641 defer second_path_aw.deinit();
...@@ -34640,19 +34643,19 @@ fn notePathToComptimeAllocPtr(...@@ -34640,19 +34643,19 @@ fn notePathToComptimeAllocPtr(
34640 const deriv_start = @import("print_value.zig").printPtrDerivation(34643 const deriv_start = @import("print_value.zig").printPtrDerivation(
34641 derivation,34644 derivation,
34642 &second_path_aw.writer,34645 &second_path_aw.writer,
34643 pt,34646 zcu,
34644 .lvalue,34647 .lvalue,
34645 .{ .str = inter_name },34648 .{ .str = inter_name },
34646 20,34649 20,
34647 ) catch return error.OutOfMemory;34650 ) catch return error.OutOfMemory;
3464834651
34649 switch (deriv_start) {34652 switch (deriv_start.addr) {
34650 .int, .nav_ptr => unreachable,34653 .int, .nav => unreachable,
34651 .uav_ptr => |uav| {34654 .uav => |uav| {
34652 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });34655 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
34653 return .{ .new_val = .fromInterned(uav.val) };34656 return .{ .new_val = uav };
34654 },34657 },
34655 .comptime_alloc_ptr => |cta_info| {34658 .comptime_alloc => |cta_info| {
34656 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });34659 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
34657 const cta = sema.getComptimeAlloc(cta_info.idx);34660 const cta = sema.getComptimeAlloc(cta_info.idx);
34658 if (cta.is_const) {34661 if (cta.is_const) {
...@@ -34662,15 +34665,15 @@ fn notePathToComptimeAllocPtr(...@@ -34662,15 +34665,15 @@ fn notePathToComptimeAllocPtr(
34662 return .done;34665 return .done;
34663 }34666 }
34664 },34667 },
34665 .comptime_field_ptr => {34668 .comptime_field => {
34666 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });34669 try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() });
34667 try sema.errNote(src, msg, "'{s}' is a comptime field", .{inter_name});34670 try sema.errNote(src, msg, "'{s}' is a comptime field", .{inter_name});
34668 return .done;34671 return .done;
34669 },34672 },
34670 .eu_payload_ptr,34673 .eu_payload,
34671 .opt_payload_ptr,34674 .opt_payload,
34672 .field_ptr,34675 .field,
34673 .elem_ptr,34676 .elem,
34674 .offset_and_cast,34677 .offset_and_cast,
34675 => unreachable,34678 => unreachable,
34676 }34679 }
...@@ -35286,7 +35289,7 @@ pub fn setTypeName(...@@ -35286,7 +35289,7 @@ pub fn setTypeName(
35286 // some tooling may not support very long symbol names.35289 // some tooling may not support very long symbol names.
35287 w.print("{f}", .{Value.fmtValueSemaFull(.{35290 w.print("{f}", .{Value.fmtValueSemaFull(.{
35288 .val = arg_val,35291 .val = arg_val,
35289 .pt = pt,35292 .zcu = zcu,
35290 .opt_sema = sema,35293 .opt_sema = sema,
35291 .depth = 1,35294 .depth = 1,
35292 })}) catch return error.OutOfMemory;35295 })}) catch return error.OutOfMemory;
src/Sema/LowerZon.zig+21-19
...@@ -323,10 +323,11 @@ fn failUnsupportedResultType(...@@ -323,10 +323,11 @@ fn failUnsupportedResultType(
323) Zcu.SemaError {323) Zcu.SemaError {
324 @branchHint(.cold);324 @branchHint(.cold);
325 const sema = self.sema;325 const sema = self.sema;
326 const gpa = sema.gpa;
327 const pt = sema.pt;326 const pt = sema.pt;
327 const zcu = pt.zcu;
328 const gpa = zcu.comp.gpa;
328 return sema.failWithOwnedErrorMsg(self.block, msg: {329 return sema.failWithOwnedErrorMsg(self.block, msg: {
329 const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(pt)});330 const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(zcu)});
330 errdefer msg.destroy(gpa);331 errdefer msg.destroy(gpa);
331 if (opt_note) |n| try sema.errNote(self.import_loc, msg, "{s}", .{n});332 if (opt_note) |n| try sema.errNote(self.import_loc, msg, "{s}", .{n});
332 break :msg msg;333 break :msg msg;
...@@ -346,9 +347,9 @@ fn fail(...@@ -346,9 +347,9 @@ fn fail(
346}347}
347348
348fn lowerExprKnownResTy(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {349fn lowerExprKnownResTy(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {
349 const pt = self.sema.pt;350 const zcu = self.sema.pt.zcu;
350 return self.lowerExprKnownResTyInner(node, res_ty) catch |err| switch (err) {351 return self.lowerExprKnownResTyInner(node, res_ty) catch |err| switch (err) {
351 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(pt)}),352 error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(zcu)}),
352 else => |e| return e,353 else => |e| return e,
353 };354 };
354}355}
...@@ -359,20 +360,21 @@ fn lowerExprKnownResTyInner(...@@ -359,20 +360,21 @@ fn lowerExprKnownResTyInner(
359 res_ty: Type,360 res_ty: Type,
360) (CompileError || error{WrongType})!InternPool.Index {361) (CompileError || error{WrongType})!InternPool.Index {
361 const pt = self.sema.pt;362 const pt = self.sema.pt;
362 switch (res_ty.zigTypeTag(pt.zcu)) {363 const zcu = pt.zcu;
364 switch (res_ty.zigTypeTag(zcu)) {
363 .optional => return pt.intern(.{365 .optional => return pt.intern(.{
364 .opt = .{366 .opt = .{
365 .ty = res_ty.toIntern(),367 .ty = res_ty.toIntern(),
366 .val = if (node.get(self.file.zoir.?) == .null) b: {368 .val = if (node.get(self.file.zoir.?) == .null) b: {
367 break :b .none;369 break :b .none;
368 } else b: {370 } else b: {
369 const child_type = res_ty.optionalChild(pt.zcu);371 const child_type = res_ty.optionalChild(zcu);
370 break :b try self.lowerExprKnownResTyInner(node, child_type);372 break :b try self.lowerExprKnownResTyInner(node, child_type);
371 },373 },
372 },374 },
373 }),375 }),
374 .pointer => {376 .pointer => {
375 const ptr_info = res_ty.ptrInfo(pt.zcu);377 const ptr_info = res_ty.ptrInfo(zcu);
376 switch (ptr_info.flags.size) {378 switch (ptr_info.flags.size) {
377 .one => return pt.intern(.{ .ptr = .{379 .one => return pt.intern(.{ .ptr = .{
378 .ty = res_ty.toIntern(),380 .ty = res_ty.toIntern(),
...@@ -413,7 +415,7 @@ fn lowerExprKnownResTyInner(...@@ -413,7 +415,7 @@ fn lowerExprKnownResTyInner(
413 .frame,415 .frame,
414 .@"anyframe",416 .@"anyframe",
415 .void,417 .void,
416 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(pt)}),418 => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(zcu)}),
417 }419 }
418}420}
419421
...@@ -444,7 +446,7 @@ fn lowerInt(...@@ -444,7 +446,7 @@ fn lowerInt(
444 if (lhs_info.signedness == .unsigned and rhs < 0) return self.fail(446 if (lhs_info.signedness == .unsigned and rhs < 0) return self.fail(
445 node,447 node,
446 "type '{f}' cannot represent integer value '{d}'",448 "type '{f}' cannot represent integer value '{d}'",
447 .{ res_ty.fmt(self.sema.pt), rhs },449 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
448 );450 );
449451
450 // If lhs has less than the 32 bits rhs can hold, we need to check the max and452 // If lhs has less than the 32 bits rhs can hold, we need to check the max and
...@@ -460,7 +462,7 @@ fn lowerInt(...@@ -460,7 +462,7 @@ fn lowerInt(
460 return self.fail(462 return self.fail(
461 node,463 node,
462 "type '{f}' cannot represent integer value '{d}'",464 "type '{f}' cannot represent integer value '{d}'",
463 .{ res_ty.fmt(self.sema.pt), rhs },465 .{ res_ty.fmt(self.sema.pt.zcu), rhs },
464 );466 );
465 }467 }
466 }468 }
...@@ -478,7 +480,7 @@ fn lowerInt(...@@ -478,7 +480,7 @@ fn lowerInt(
478 return self.fail(480 return self.fail(
479 node,481 node,
480 "type '{f}' cannot represent integer value '{d}'",482 "type '{f}' cannot represent integer value '{d}'",
481 .{ res_ty.fmt(self.sema.pt), val },483 .{ res_ty.fmt(self.sema.pt.zcu), val },
482 );484 );
483 }485 }
484 }486 }
...@@ -499,7 +501,7 @@ fn lowerInt(...@@ -499,7 +501,7 @@ fn lowerInt(
499 .inexact => return self.fail(501 .inexact => return self.fail(
500 node,502 node,
501 "fractional component prevents float value '{d}' from coercion to type '{f}'",503 "fractional component prevents float value '{d}' from coercion to type '{f}'",
502 .{ val, res_ty.fmt(self.sema.pt) },504 .{ val, res_ty.fmt(self.sema.pt.zcu) },
503 ),505 ),
504 .exact => {},506 .exact => {},
505 }507 }
...@@ -510,7 +512,7 @@ fn lowerInt(...@@ -510,7 +512,7 @@ fn lowerInt(
510 return self.fail(512 return self.fail(
511 node,513 node,
512 "type '{f}' cannot represent integer value '{d}'",514 "type '{f}' cannot represent integer value '{d}'",
513 .{ res_ty.fmt(self.sema.pt), val },515 .{ res_ty.fmt(self.sema.pt.zcu), val },
514 );516 );
515 }517 }
516518
...@@ -532,7 +534,7 @@ fn lowerInt(...@@ -532,7 +534,7 @@ fn lowerInt(
532 return self.fail(534 return self.fail(
533 node,535 node,
534 "type '{f}' cannot represent integer value '{d}'",536 "type '{f}' cannot represent integer value '{d}'",
535 .{ res_ty.fmt(self.sema.pt), val },537 .{ res_ty.fmt(self.sema.pt.zcu), val },
536 );538 );
537 }539 }
538 }540 }
...@@ -566,7 +568,7 @@ fn lowerFloat(...@@ -566,7 +568,7 @@ fn lowerFloat(
566 if (res_ty.toIntern() == .comptime_float_type) return self.fail(568 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
567 node,569 node,
568 "expected type '{f}'",570 "expected type '{f}'",
569 .{res_ty.fmt(self.sema.pt)},571 .{res_ty.fmt(self.sema.pt.zcu)},
570 );572 );
571 break :b try self.sema.pt.floatValue(res_ty, std.math.inf(f128));573 break :b try self.sema.pt.floatValue(res_ty, std.math.inf(f128));
572 },574 },
...@@ -574,7 +576,7 @@ fn lowerFloat(...@@ -574,7 +576,7 @@ fn lowerFloat(
574 if (res_ty.toIntern() == .comptime_float_type) return self.fail(576 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
575 node,577 node,
576 "expected type '{f}'",578 "expected type '{f}'",
577 .{res_ty.fmt(self.sema.pt)},579 .{res_ty.fmt(self.sema.pt.zcu)},
578 );580 );
579 break :b try self.sema.pt.floatValue(res_ty, -std.math.inf(f128));581 break :b try self.sema.pt.floatValue(res_ty, -std.math.inf(f128));
580 },582 },
...@@ -582,7 +584,7 @@ fn lowerFloat(...@@ -582,7 +584,7 @@ fn lowerFloat(
582 if (res_ty.toIntern() == .comptime_float_type) return self.fail(584 if (res_ty.toIntern() == .comptime_float_type) return self.fail(
583 node,585 node,
584 "expected type '{f}'",586 "expected type '{f}'",
585 .{res_ty.fmt(self.sema.pt)},587 .{res_ty.fmt(self.sema.pt.zcu)},
586 );588 );
587 break :b try self.sema.pt.floatValue(res_ty, std.math.nan(f128));589 break :b try self.sema.pt.floatValue(res_ty, std.math.nan(f128));
588 },590 },
...@@ -647,7 +649,7 @@ fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I...@@ -647,7 +649,7 @@ fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I
647 node,649 node,
648 "enum {f} has no member named '{f}'",650 "enum {f} has no member named '{f}'",
649 .{651 .{
650 res_ty.fmt(self.sema.pt),652 res_ty.fmt(self.sema.pt.zcu),
651 std.zig.fmtId(field_name.get(self.file.zoir.?)),653 std.zig.fmtId(field_name.get(self.file.zoir.?)),
652 },654 },
653 );655 );
...@@ -941,7 +943,7 @@ fn lowerUnion(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool....@@ -941,7 +943,7 @@ fn lowerUnion(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
941 .struct_literal => b: {943 .struct_literal => b: {
942 const fields: @FieldType(Zoir.Node, "struct_literal") = switch (node.get(self.file.zoir.?)) {944 const fields: @FieldType(Zoir.Node, "struct_literal") = switch (node.get(self.file.zoir.?)) {
943 .struct_literal => |fields| fields,945 .struct_literal => |fields| fields,
944 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt)}),946 else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt.zcu)}),
945 };947 };
946 if (fields.names.len != 1) {948 if (fields.names.len != 1) {
947 return error.WrongType;949 return error.WrongType;
src/Sema/type_resolution.zig+25-25
...@@ -310,7 +310,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -310,7 +310,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
310 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);310 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
311 if (field_ty.zigTypeTag(zcu) == .@"opaque") {311 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
312 return sema.failWithOwnedErrorMsg(&block, msg: {312 return sema.failWithOwnedErrorMsg(&block, msg: {
313 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});313 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
314 errdefer msg.destroy(gpa);314 errdefer msg.destroy(gpa);
315 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});315 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
316 try sema.addDeclaredHereNote(msg, field_ty);316 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -321,7 +321,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -321,7 +321,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
321 if (field_ty.isSpirvRuntimeArray(zcu)) {321 if (field_ty.isSpirvRuntimeArray(zcu)) {
322 if (struct_obj.layout != .@"extern") {322 if (struct_obj.layout != .@"extern") {
323 return sema.failWithOwnedErrorMsg(&block, msg: {323 return sema.failWithOwnedErrorMsg(&block, msg: {
324 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});324 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
325 errdefer msg.destroy(gpa);325 errdefer msg.destroy(gpa);
326 try sema.errNote(field_name_src, msg, "while checking this field", .{});326 try sema.errNote(field_name_src, msg, "while checking this field", .{});
327 break :msg msg;327 break :msg msg;
...@@ -329,7 +329,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -329,7 +329,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
329 }329 }
330 if (field_index != fields_len - 1) {330 if (field_index != fields_len - 1) {
331 return sema.failWithOwnedErrorMsg(&block, msg: {331 return sema.failWithOwnedErrorMsg(&block, msg: {
332 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(pt)});332 const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(zcu)});
333 errdefer msg.destroy(gpa);333 errdefer msg.destroy(gpa);
334 try sema.errNote(field_name_src, msg, "while checking this field", .{});334 try sema.errNote(field_name_src, msg, "while checking this field", .{});
335 break :msg msg;335 break :msg msg;
...@@ -339,7 +339,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -339,7 +339,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
339 const elem_ty: Type = field_ty.childType(zcu);339 const elem_ty: Type = field_ty.childType(zcu);
340 if (elem_ty.zigTypeTag(zcu) == .spirv) {340 if (elem_ty.zigTypeTag(zcu) == .spirv) {
341 return sema.failWithOwnedErrorMsg(&block, msg: {341 return sema.failWithOwnedErrorMsg(&block, msg: {
342 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(pt)});342 const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(zcu)});
343 errdefer msg.destroy(gpa);343 errdefer msg.destroy(gpa);
344 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});344 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
345 try sema.addDeclaredHereNote(msg, field_ty);345 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -348,7 +348,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -348,7 +348,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
348 }348 }
349 } else {349 } else {
350 return sema.failWithOwnedErrorMsg(&block, msg: {350 return sema.failWithOwnedErrorMsg(&block, msg: {
351 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(pt)});351 const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(zcu)});
352 errdefer msg.destroy(gpa);352 errdefer msg.destroy(gpa);
353 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});353 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
354 try sema.addDeclaredHereNote(msg, field_ty);354 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -359,7 +359,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {...@@ -359,7 +359,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void {
359359
360 if (struct_obj.layout == .@"extern" and !field_ty.validateExtern(.struct_field, zcu)) {360 if (struct_obj.layout == .@"extern" and !field_ty.validateExtern(.struct_field, zcu)) {
361 return sema.failWithOwnedErrorMsg(&block, msg: {361 return sema.failWithOwnedErrorMsg(&block, msg: {
362 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});362 const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
363 errdefer msg.destroy(gpa);363 errdefer msg.destroy(gpa);
364 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .struct_field);364 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .struct_field);
365 try sema.addDeclaredHereNote(msg, field_ty);365 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -516,7 +516,7 @@ fn resolvePackedStructLayout(...@@ -516,7 +516,7 @@ fn resolvePackedStructLayout(
516 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);516 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
517 if (field_ty.zigTypeTag(zcu) == .@"opaque") {517 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
518 return sema.failWithOwnedErrorMsg(block, msg: {518 return sema.failWithOwnedErrorMsg(block, msg: {
519 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)});519 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)});
520 errdefer msg.destroy(gpa);520 errdefer msg.destroy(gpa);
521 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});521 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
522 try sema.addDeclaredHereNote(msg, field_ty);522 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -524,7 +524,7 @@ fn resolvePackedStructLayout(...@@ -524,7 +524,7 @@ fn resolvePackedStructLayout(
524 });524 });
525 }525 }
526 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {526 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
527 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});527 const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
528 errdefer msg.destroy(gpa);528 errdefer msg.destroy(gpa);
529 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);529 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
530 break :msg msg;530 break :msg msg;
...@@ -565,7 +565,7 @@ fn resolvePackedStructLayout(...@@ -565,7 +565,7 @@ fn resolvePackedStructLayout(
565 block,565 block,
566 block.src(.container_arg),566 block.src(.container_arg),
567 "expected backing integer type, found '{f}'",567 "expected backing integer type, found '{f}'",
568 .{backing_ty.fmt(pt)},568 .{backing_ty.fmt(zcu)},
569 );569 );
570 if (field_bits != backing_ty.intInfo(zcu).bits) return sema.failWithOwnedErrorMsg(block, msg: {570 if (field_bits != backing_ty.intInfo(zcu).bits) return sema.failWithOwnedErrorMsg(block, msg: {
571 const src = struct_ty.srcLoc(zcu);571 const src = struct_ty.srcLoc(zcu);
...@@ -575,7 +575,7 @@ fn resolvePackedStructLayout(...@@ -575,7 +575,7 @@ fn resolvePackedStructLayout(
575 block.src(.container_arg),575 block.src(.container_arg),
576 msg,576 msg,
577 "backing integer '{f}' has bit width '{d}'",577 "backing integer '{f}' has bit width '{d}'",
578 .{ backing_ty.fmt(pt), backing_ty.bitSize(zcu) },578 .{ backing_ty.fmt(zcu), backing_ty.bitSize(zcu) },
579 );579 );
580 try sema.errNote(src, msg, "struct fields have total bit width '{d}'", .{field_bits});580 try sema.errNote(src, msg, "struct fields have total bit width '{d}'", .{field_bits});
581 break :msg msg;581 break :msg msg;
...@@ -777,7 +777,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {...@@ -777,7 +777,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
777 &block,777 &block,
778 block.src(.container_arg),778 block.src(.container_arg),
779 "expected enum tag type, found '{f}'",779 "expected enum tag type, found '{f}'",
780 .{tag_ty.fmt(pt)},780 .{tag_ty.fmt(zcu)},
781 );781 );
782 break :validated_tag_ty tag_ty;782 break :validated_tag_ty tag_ty;
783 },783 },
...@@ -922,7 +922,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {...@@ -922,7 +922,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
922 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);922 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
923 if (field_ty.zigTypeTag(zcu) == .@"opaque") {923 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
924 return sema.failWithOwnedErrorMsg(&block, msg: {924 return sema.failWithOwnedErrorMsg(&block, msg: {
925 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});925 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
926 errdefer msg.destroy(gpa);926 errdefer msg.destroy(gpa);
927 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});927 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
928 try sema.addDeclaredHereNote(msg, field_ty);928 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -931,7 +931,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {...@@ -931,7 +931,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
931 }931 }
932 if (field_ty.zigTypeTag(zcu) == .spirv) {932 if (field_ty.zigTypeTag(zcu) == .spirv) {
933 return sema.failWithOwnedErrorMsg(&block, msg: {933 return sema.failWithOwnedErrorMsg(&block, msg: {
934 const msg = try sema.errMsg(field_ty_src, "SPIR-V type '{f}' have unknown size and therefore cannot be directly embedded in unions", .{field_ty.fmt(pt)});934 const msg = try sema.errMsg(field_ty_src, "SPIR-V type '{f}' have unknown size and therefore cannot be directly embedded in unions", .{field_ty.fmt(zcu)});
935 errdefer msg.destroy(gpa);935 errdefer msg.destroy(gpa);
936 try sema.addDeclaredHereNote(msg, field_ty);936 try sema.addDeclaredHereNote(msg, field_ty);
937 break :msg msg;937 break :msg msg;
...@@ -939,7 +939,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {...@@ -939,7 +939,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void {
939 }939 }
940 if (union_obj.layout == .@"extern" and !field_ty.validateExtern(.union_field, zcu)) {940 if (union_obj.layout == .@"extern" and !field_ty.validateExtern(.union_field, zcu)) {
941 return sema.failWithOwnedErrorMsg(&block, msg: {941 return sema.failWithOwnedErrorMsg(&block, msg: {
942 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});942 const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
943 errdefer msg.destroy(gpa);943 errdefer msg.destroy(gpa);
944 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .union_field);944 try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .union_field);
945 try sema.addDeclaredHereNote(msg, field_ty);945 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -1056,7 +1056,7 @@ fn failUnionFieldMismatch(sema: *Sema, block: *Block, union_field_names: []const...@@ -1056,7 +1056,7 @@ fn failUnionFieldMismatch(sema: *Sema, block: *Block, union_field_names: []const
1056 }1056 }
1057 const union_field_src = block.src(.{ .container_field_name = @intCast(union_field_index) });1057 const union_field_src = block.src(.{ .container_field_name = @intCast(union_field_index) });
1058 return sema.failWithOwnedErrorMsg(block, msg: {1058 return sema.failWithOwnedErrorMsg(block, msg: {
1059 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(pt) });1059 const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(zcu) });
1060 errdefer msg.destroy(gpa);1060 errdefer msg.destroy(gpa);
1061 try sema.addDeclaredHereNote(msg, enum_tag_ty);1061 try sema.addDeclaredHereNote(msg, enum_tag_ty);
1062 break :msg msg;1062 break :msg msg;
...@@ -1122,7 +1122,7 @@ fn resolvePackedUnionLayout(...@@ -1122,7 +1122,7 @@ fn resolvePackedUnionLayout(
1122 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);1122 try sema.ensureLayoutResolved(field_ty, field_ty_src, .field);
1123 if (field_ty.zigTypeTag(zcu) == .@"opaque") {1123 if (field_ty.zigTypeTag(zcu) == .@"opaque") {
1124 return sema.failWithOwnedErrorMsg(block, msg: {1124 return sema.failWithOwnedErrorMsg(block, msg: {
1125 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)});1125 const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)});
1126 errdefer msg.destroy(gpa);1126 errdefer msg.destroy(gpa);
1127 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});1127 try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{});
1128 try sema.addDeclaredHereNote(msg, field_ty);1128 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -1130,7 +1130,7 @@ fn resolvePackedUnionLayout(...@@ -1130,7 +1130,7 @@ fn resolvePackedUnionLayout(
1130 });1130 });
1131 }1131 }
1132 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {1132 if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: {
1133 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)});1133 const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)});
1134 errdefer msg.destroy(gpa);1134 errdefer msg.destroy(gpa);
1135 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);1135 try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason);
1136 break :msg msg;1136 break :msg msg;
...@@ -1165,7 +1165,7 @@ fn resolvePackedUnionLayout(...@@ -1165,7 +1165,7 @@ fn resolvePackedUnionLayout(
1165 block,1165 block,
1166 block.src(.container_arg),1166 block.src(.container_arg),
1167 "expected backing integer type, found '{f}'",1167 "expected backing integer type, found '{f}'",
1168 .{backing_ty.fmt(pt)},1168 .{backing_ty.fmt(zcu)},
1169 );1169 );
1170 const backing_int_bits = backing_ty.intInfo(zcu).bits;1170 const backing_int_bits = backing_ty.intInfo(zcu).bits;
1171 for (union_obj.field_types.get(ip), 0..) |field_type_ip, field_idx| {1171 for (union_obj.field_types.get(ip), 0..) |field_type_ip, field_idx| {
...@@ -1175,12 +1175,12 @@ fn resolvePackedUnionLayout(...@@ -1175,12 +1175,12 @@ fn resolvePackedUnionLayout(
1175 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });1175 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
1176 const msg = try sema.errMsg(field_ty_src, "field bit width does not match backing integer", .{});1176 const msg = try sema.errMsg(field_ty_src, "field bit width does not match backing integer", .{});
1177 errdefer msg.destroy(gpa);1177 errdefer msg.destroy(gpa);
1178 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });1178 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
1179 try sema.errNote(1179 try sema.errNote(
1180 block.src(.container_arg),1180 block.src(.container_arg),
1181 msg,1181 msg,
1182 "backing integer '{f}' has bit width '{d}'",1182 "backing integer '{f}' has bit width '{d}'",
1183 .{ backing_ty.fmt(pt), backing_int_bits },1183 .{ backing_ty.fmt(zcu), backing_int_bits },
1184 );1184 );
1185 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});1185 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
1186 break :msg msg;1186 break :msg msg;
...@@ -1199,8 +1199,8 @@ fn resolvePackedUnionLayout(...@@ -1199,8 +1199,8 @@ fn resolvePackedUnionLayout(
1199 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });1199 const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) });
1200 const msg = try sema.errMsg(field_ty_src, "field bit width does not match earlier field", .{});1200 const msg = try sema.errMsg(field_ty_src, "field bit width does not match earlier field", .{});
1201 errdefer msg.destroy(gpa);1201 errdefer msg.destroy(gpa);
1202 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits });1202 try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits });
1203 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(pt), first_field_bits });1203 try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(zcu), first_field_bits });
1204 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});1204 try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{});
1205 break :msg msg;1205 break :msg msg;
1206 });1206 });
...@@ -1380,7 +1380,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {...@@ -1380,7 +1380,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
1380 &block,1380 &block,
1381 block.src(.container_arg),1381 block.src(.container_arg),
1382 "expected integer tag type, found '{f}'",1382 "expected integer tag type, found '{f}'",
1383 .{int_tag_ty.fmt(pt)},1383 .{int_tag_ty.fmt(zcu)},
1384 ),1384 ),
1385 }1385 }
1386 break :ty int_tag_ty;1386 break :ty int_tag_ty;
...@@ -1487,7 +1487,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {...@@ -1487,7 +1487,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
1487 &block,1487 &block,
1488 field_val_src,1488 field_val_src,
1489 "enum tag value '{f}' too large for type '{f}'",1489 "enum tag value '{f}' too large for type '{f}'",
1490 .{ result.val.fmtValueSema(pt, sema), int_tag_ty.fmt(pt) },1490 .{ result.val.fmtValueSema(sema), int_tag_ty.fmt(zcu) },
1491 );1491 );
1492 const val = result.val.toIntern();1492 const val = result.val.toIntern();
1493 enum_obj.field_values.get(ip)[field_idx] = val;1493 enum_obj.field_values.get(ip)[field_idx] = val;
...@@ -1497,7 +1497,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {...@@ -1497,7 +1497,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void {
1497 return sema.failWithOwnedErrorMsg(&block, msg: {1497 return sema.failWithOwnedErrorMsg(&block, msg: {
1498 const prev_field_val_src = block.src(.{ .container_field_value = prev_field_index });1498 const prev_field_val_src = block.src(.{ .container_field_value = prev_field_index });
1499 const msg = try sema.errMsg(field_val_src, "enum tag value '{f}' for field '{f}' already taken", .{1499 const msg = try sema.errMsg(field_val_src, "enum tag value '{f}' for field '{f}' already taken", .{
1500 Value.fromInterned(field_val).fmtValueSema(pt, sema),1500 Value.fromInterned(field_val).fmtValueSema(sema),
1501 enum_obj.field_names.get(ip)[field_idx].fmt(ip),1501 enum_obj.field_names.get(ip)[field_idx].fmt(ip),
1502 });1502 });
1503 errdefer msg.destroy(gpa);1503 errdefer msg.destroy(gpa);
src/Type.zig+144-162
...@@ -412,21 +412,14 @@ pub fn eql(a: Type, b: Type) bool {...@@ -412,21 +412,14 @@ pub fn eql(a: Type, b: Type) bool {
412412
413pub const format = @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()");413pub 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);415pub fn fmt(ty: Type, zcu: *Zcu) Formatter {
416416 return .{ .ty = ty, .zcu = zcu };
417pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter {
418 return .{ .data = .{
419 .ty = ty,
420 .pt = pt,
421 } };
422}417}
423418pub const Formatter = struct {
424const Format = struct {
425 ty: Type,419 ty: Type,
426 pt: Zcu.PerThread,420 zcu: *Zcu,
427421 pub fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void {
428 fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void {422 return print(f.ty, writer, f.zcu, null);
429 return print(f.ty, writer, f.pt, null);
430 }423 }
431};424};
432425
...@@ -442,9 +435,9 @@ pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void {...@@ -442,9 +435,9 @@ pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void {
442435
443/// Prints a name suitable for `@typeName`.436/// Prints a name suitable for `@typeName`.
444/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.437/// 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 {
446 if (ctx) |c| {439 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) {
448 error.OutOfMemory => return error.WriteFailed,441 error.OutOfMemory => return error.WriteFailed,
449 };442 };
450 switch (should_dedupe) {443 switch (should_dedupe) {
...@@ -453,7 +446,6 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -453,7 +446,6 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
453 }446 }
454 }447 }
455448
456 const zcu = pt.zcu;
457 const ip = &zcu.intern_pool;449 const ip = &zcu.intern_pool;
458 switch (ip.indexToKey(ty.toIntern())) {450 switch (ip.indexToKey(ty.toIntern())) {
459 .undef => return writer.writeAll("@as(type, undefined)"),451 .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...@@ -469,8 +461,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
469461
470 if (info.sentinel != .none) switch (info.flags.size) {462 if (info.sentinel != .none) switch (info.flags.size) {
471 .one, .c => unreachable,463 .one, .c => unreachable,
472 .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),464 .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}),
473 .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),465 .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}),
474 } else switch (info.flags.size) {466 } else switch (info.flags.size) {
475 .one => try writer.writeAll("*"),467 .one => try writer.writeAll("*"),
476 .many => try writer.writeAll("[*]"),468 .many => try writer.writeAll("[*]"),
...@@ -485,7 +477,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -485,7 +477,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
485 const alignment = if (info.flags.alignment != .none)477 const alignment = if (info.flags.alignment != .none)
486 info.flags.alignment478 info.flags.alignment
487 else479 else
488 Type.fromInterned(info.child).abiAlignment(pt.zcu);480 Type.fromInterned(info.child).abiAlignment(zcu);
489 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});481 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});
490482
491 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {483 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...@@ -504,39 +496,39 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
504 if (info.flags.is_const) try writer.writeAll("const ");496 if (info.flags.is_const) try writer.writeAll("const ");
505 if (info.flags.is_volatile) try writer.writeAll("volatile ");497 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);
508 return;500 return;
509 },501 },
510 .array_type => |array_type| {502 .array_type => |array_type| {
511 if (array_type.sentinel == .none) {503 if (array_type.sentinel == .none) {
512 try writer.print("[{d}]", .{array_type.len});504 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);
514 } else {506 } else {
515 try writer.print("[{d}:{f}]", .{507 try writer.print("[{d}:{f}]", .{
516 array_type.len,508 array_type.len,
517 Value.fromInterned(array_type.sentinel).fmtValue(pt),509 Value.fromInterned(array_type.sentinel).fmtValue(zcu),
518 });510 });
519 try print(Type.fromInterned(array_type.child), writer, pt, ctx);511 try print(Type.fromInterned(array_type.child), writer, zcu, ctx);
520 }512 }
521 return;513 return;
522 },514 },
523 .vector_type => |vector_type| {515 .vector_type => |vector_type| {
524 try writer.print("@Vector({d}, ", .{vector_type.len});516 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);
526 try writer.writeAll(")");518 try writer.writeAll(")");
527 return;519 return;
528 },520 },
529 .opt_type => |child| {521 .opt_type => |child| {
530 try writer.writeByte('?');522 try writer.writeByte('?');
531 return print(Type.fromInterned(child), writer, pt, ctx);523 return print(Type.fromInterned(child), writer, zcu, ctx);
532 },524 },
533 .error_union_type => |error_union_type| {525 .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);
535 try writer.writeByte('!');527 try writer.writeByte('!');
536 if (error_union_type.payload_type == .generic_poison_type) {528 if (error_union_type.payload_type == .generic_poison_type) {
537 try writer.writeAll("anytype");529 try writer.writeAll("anytype");
538 } else {530 } 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);
540 }532 }
541 return;533 return;
542 },534 },
...@@ -618,8 +610,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -618,8 +610,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
618 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, val, i| {610 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, val, i| {
619 try writer.writeAll(if (i == 0) " " else ", ");611 try writer.writeAll(if (i == 0) " " else ", ");
620 if (val != .none) try writer.writeAll("comptime ");612 if (val != .none) try writer.writeAll("comptime ");
621 try print(Type.fromInterned(field_ty), writer, pt, ctx);613 try print(Type.fromInterned(field_ty), writer, zcu, ctx);
622 if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(pt)});614 if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(zcu)});
623 }615 }
624 try writer.writeAll(" }");616 try writer.writeAll(" }");
625 },617 },
...@@ -643,12 +635,12 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -643,12 +635,12 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
643 .image => try writer.writeAll("@SpirvType(.image)"),635 .image => try writer.writeAll("@SpirvType(.image)"),
644 .sampled_image => {636 .sampled_image => {
645 try writer.writeAll("@SpirvType(.sampled_image, ");637 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);
647 try writer.writeAll(")");639 try writer.writeAll(")");
648 },640 },
649 .runtime_array => {641 .runtime_array => {
650 try writer.writeAll("@SpirvType(.runtime_array, ");642 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);
652 try writer.writeAll(")");644 try writer.writeAll(")");
653 },645 },
654 }646 }
...@@ -672,7 +664,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -672,7 +664,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
672 if (param_ty == .generic_poison_type) {664 if (param_ty == .generic_poison_type) {
673 try writer.writeAll("anytype");665 try writer.writeAll("anytype");
674 } else {666 } else {
675 try print(Type.fromInterned(param_ty), writer, pt, ctx);667 try print(Type.fromInterned(param_ty), writer, zcu, ctx);
676 }668 }
677 }669 }
678 if (fn_info.is_var_args) {670 if (fn_info.is_var_args) {
...@@ -699,13 +691,13 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari...@@ -699,13 +691,13 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari
699 if (fn_info.return_type == .generic_poison_type) {691 if (fn_info.return_type == .generic_poison_type) {
700 try writer.writeAll("anytype");692 try writer.writeAll("anytype");
701 } else {693 } 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);
703 }695 }
704 },696 },
705 .anyframe_type => |child| {697 .anyframe_type => |child| {
706 if (child == .none) return writer.writeAll("anyframe");698 if (child == .none) return writer.writeAll("anyframe");
707 try writer.writeAll("anyframe->");699 try writer.writeAll("anyframe->");
708 return print(Type.fromInterned(child), writer, pt, ctx);700 return print(Type.fromInterned(child), writer, zcu, ctx);
709 },701 },
710702
711 // values, not types703 // values, not types
...@@ -2869,11 +2861,62 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator...@@ -2869,11 +2861,62 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
2869 const ptr_info = ip.indexToKey(ptr_ty.toIntern()).ptr_type;2861 const ptr_info = ip.indexToKey(ptr_ty.toIntern()).ptr_type;
2870 assert(ptr_info.flags.size == .one or ptr_info.flags.size == .c);2862 assert(ptr_info.flags.size == .one or ptr_info.flags.size == .c);
2871 const aggregate_ty: Type = .fromInterned(ptr_info.child);2863 const aggregate_ty: Type = .fromInterned(ptr_info.child);
2864
2865 var field_ptr_info = ptr_info;
2866
2867 field_ptr_info.child = if (aggregate_ty.isSlice(zcu)) switch (field_index) {
2868 Value.slice_ptr_index => aggregate_ty.slicePtrFieldType(zcu).toIntern(),
2869 Value.slice_len_index => .usize_type,
2870 else => unreachable,
2871 } else aggregate_ty.fieldType(field_index, zcu).toIntern();
2872
2873 field_ptr_info.flags.alignment = aggregate_ty.fieldPtrAlign(ptr_info.flags.alignment, field_index, zcu);
2874
2875 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2876 aggregate_ty.containerLayout(zcu) == .@"packed")
2877 {
2878 field_ptr_info.packed_offset = packed_offset: {
2879 comptime assert(Type.packed_struct_layout_version == 2);
2880 const bit_offset = zcu.structPackedFieldBitOffset(
2881 ip.loadStructType(aggregate_ty.toIntern()),
2882 field_index,
2883 );
2884 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2885 .host_size = ptr_info.packed_offset.host_size,
2886 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2887 } else .{
2888 .host_size = switch (zcu.comp.getZigBackend()) {
2889 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2890 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2891 },
2892 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2893 };
2894 };
2895 }
2896
2897 return pt.ptrType(field_ptr_info);
2898}
2899
2900pub fn fieldPtrAlign(
2901 aggregate_ty: Type,
2902 aggregate_ptr_align: Alignment,
2903 field_index: u32,
2904 zcu: *const Zcu,
2905) Alignment {
2906 const ip = &zcu.intern_pool;
2907
2872 aggregate_ty.assertHasLayout(zcu);2908 aggregate_ty.assertHasLayout(zcu);
2909
2910 const aggregate_ty_align = aggregate_ty.abiAlignment(zcu);
2911 const aggregate_align: Alignment = switch (aggregate_ptr_align) {
2912 .none => aggregate_ty_align,
2913 else => |a| a,
2914 };
2915
2873 // We only exit this `switch` for default-layout aggregates, where the field pointer alignment2916 // We only exit this `switch` for default-layout aggregates, where the field pointer alignment
2874 // is a simple minimum of the aggregate pointer alignment and the field alignment.2917 // is a simple minimum of the aggregate pointer alignment and the field alignment.
2875 // `field_align` is `.none` if there is no explicit alignment annotation.2918 // `field_explicit_align` is `.none` if there is no explicit alignment annotation.
2876 const field_ty: Type, const field_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {2919 const field_ty: Type, const field_explicit_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
2877 .@"struct" => switch (aggregate_ty.containerLayout(zcu)) {2920 .@"struct" => switch (aggregate_ty.containerLayout(zcu)) {
2878 .auto => field: {2921 .auto => field: {
2879 if (aggregate_ty.isTuple(zcu)) {2922 if (aggregate_ty.isTuple(zcu)) {
...@@ -2890,56 +2933,21 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator...@@ -2890,56 +2933,21 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
2890 // `extern struct { x: u32, y: u16 }`, the `y` field is 4-byte aligned.2933 // `extern struct { x: u32, y: u16 }`, the `y` field is 4-byte aligned.
2891 const field_ty = aggregate_ty.fieldType(field_index, zcu);2934 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2892 const field_offset = aggregate_ty.structFieldOffset(field_index, zcu);2935 const field_offset = aggregate_ty.structFieldOffset(field_index, zcu);
2893 const parent_align = switch (ptr_info.flags.alignment) {2936 const field_align = aggregate_align.offset(field_offset);
2894 .none => aggregate_ty.abiAlignment(zcu),2937
2895 else => |a| a,2938 if (aggregate_ptr_align == .none and
2896 };2939 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2897 const actual_field_align = switch (field_offset) {2940 field_align == field_ty.abiAlignment(zcu))
2898 0 => parent_align,2941 {
2899 else => parent_align.minStrict(.fromLog2Units(@ctz(field_offset))),2942 // There's no user-specified 'align' in sight, and the alignment from the
2900 };2943 // field offset matches the field type's natural alignment, so just use a
2901 const field_ptr_align: Alignment = a: {2944 // default-aligned pointer.
2902 if (ptr_info.flags.alignment == .none and2945 return .none;
2903 aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and
2904 actual_field_align == field_ty.abiAlignment(zcu))
2905 {
2906 // There's no user-specified 'align' in sight, and the alignment from the
2907 // field offset matches the field type's natural alignment, so just use a
2908 // default-aligned pointer.
2909 break :a .none;
2910 }
2911 break :a actual_field_align;
2912 };
2913 var field_ptr_info = ptr_info;
2914 field_ptr_info.child = field_ty.toIntern();
2915 field_ptr_info.flags.alignment = field_ptr_align;
2916 return pt.ptrType(field_ptr_info);
2917 },
2918 .@"packed" => {
2919 var field_ptr_info = ptr_info;
2920 if (field_ptr_info.flags.alignment == .none) {
2921 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2922 }2946 }
2923 field_ptr_info.packed_offset = packed_offset: {2947
2924 comptime assert(Type.packed_struct_layout_version == 2);2948 return field_align;
2925 const bit_offset = zcu.structPackedFieldBitOffset(
2926 ip.loadStructType(aggregate_ty.toIntern()),
2927 field_index,
2928 );
2929 break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{
2930 .host_size = ptr_info.packed_offset.host_size,
2931 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2932 } else .{
2933 .host_size = switch (zcu.comp.getZigBackend()) {
2934 else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8),
2935 .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)),
2936 },
2937 .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset,
2938 };
2939 };
2940 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2941 return pt.ptrType(field_ptr_info);
2942 },2949 },
2950 .@"packed" => return aggregate_align,
2943 },2951 },
2944 .@"union" => switch (aggregate_ty.containerLayout(zcu)) {2952 .@"union" => switch (aggregate_ty.containerLayout(zcu)) {
2945 .auto => field: {2953 .auto => field: {
...@@ -2949,30 +2957,14 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator...@@ -2949,30 +2957,14 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
2949 union_obj.field_aligns.getOrNone(ip, field_index),2957 union_obj.field_aligns.getOrNone(ip, field_index),
2950 };2958 };
2951 },2959 },
2952 .@"extern" => {2960 .@"extern", .@"packed" => {
2953 // The alignment always matches that of the union pointer. If the union pointer is2961 // The alignment always matches that of the union pointer. If the union pointer is
2954 // default aligned (`.none`), we may need to explicitly align the result pointer.2962 // default aligned (`.none`), we may need to explicitly align the result pointer.
2955 const field_ty = aggregate_ty.fieldType(field_index, zcu);2963 const field_ty_align = aggregate_ty.fieldType(field_index, zcu).abiAlignment(zcu);
2956 var field_ptr_info = ptr_info;2964 return switch (aggregate_ptr_align) {
2957 field_ptr_info.child = field_ty.toIntern();2965 .none => if (field_ty_align == aggregate_ty_align) .none else aggregate_ty_align,
2958 if (field_ptr_info.flags.alignment == .none and2966 else => |a| a,
2959 Alignment.compareStrict(field_ty.abiAlignment(zcu), .neq, aggregate_ty.abiAlignment(zcu)))2967 };
2960 {
2961 field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu);
2962 }
2963 return pt.ptrType(field_ptr_info);
2964 },
2965 .@"packed" => {
2966 const field_ty = aggregate_ty.fieldType(field_index, zcu);
2967 var field_ptr_info = ptr_info;
2968 if (field_ptr_info.flags.alignment == .none) {
2969 const resolved_align = aggregate_ty.abiAlignment(zcu);
2970 if (field_ty.abiAlignment(zcu) != resolved_align) {
2971 field_ptr_info.flags.alignment = resolved_align;
2972 }
2973 }
2974 field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern();
2975 return pt.ptrType(field_ptr_info);
2976 },2968 },
2977 },2969 },
2978 .pointer => field: {2970 .pointer => field: {
...@@ -2985,39 +2977,31 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator...@@ -2985,39 +2977,31 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator
2985 },2977 },
2986 else => unreachable,2978 else => unreachable,
2987 };2979 };
2988 const field_ptr_align: Alignment = a: {2980 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and
2989 if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and aggregate_ty.structFieldIsComptime(field_index, zcu)) {2981 aggregate_ty.structFieldIsComptime(field_index, zcu))
2990 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.2982 {
2991 break :a field_align;2983 // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified.
2992 }2984 return field_explicit_align;
2993 const actual_field_align = switch (field_align) {2985 }
2994 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {2986 const field_align = switch (field_explicit_align) {
2995 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),2987 .none => switch (ip.indexToKey(aggregate_ty.toIntern())) {
2996 .ptr_type => Type.usize.abiAlignment(zcu),2988 .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu),
2997 else => unreachable,2989 .ptr_type => Type.usize.abiAlignment(zcu),
2998 },2990 else => unreachable,
2999 else => |a| a,2991 },
3000 };2992 else => |a| a,
3001 const actual_aggregate_align = switch (ptr_info.flags.alignment) {
3002 .none => aggregate_ty.abiAlignment(zcu),
3003 else => |a| a,
3004 };
3005 if (actual_aggregate_align.compareStrict(.lt, actual_field_align)) {
3006 // Underaligned aggregate; use that alignment.
3007 assert(ptr_info.flags.alignment != .none);
3008 break :a actual_aggregate_align;
3009 }
3010 if (field_align == .none and actual_field_align == field_ty.abiAlignment(zcu)) {
3011 // No explicit annotation on the field (nor an unusual default), and the aggregate
3012 // alignment is irrelevant to us, so return an un-annotated pointer.
3013 break :a .none;
3014 }
3015 break :a actual_field_align;
3016 };2993 };
3017 var field_ptr_info = ptr_info;2994 if (aggregate_align.compareStrict(.lt, field_align)) {
3018 field_ptr_info.flags.alignment = field_ptr_align;2995 // Underaligned aggregate; use that alignment.
3019 field_ptr_info.child = field_ty.toIntern();2996 assert(aggregate_ptr_align == aggregate_align);
3020 return pt.ptrType(field_ptr_info);2997 return aggregate_align;
2998 }
2999 if (field_explicit_align == .none and field_align == field_ty.abiAlignment(zcu)) {
3000 // No explicit annotation on the field (nor an unusual default), and the aggregate
3001 // alignment is irrelevant to us, so return an un-annotated pointer.
3002 return .none;
3003 }
3004 return field_align;
3021}3005}
30223006
3023pub fn containerTypeName(ty: Type, ip: *const InternPool) struct {3007pub fn containerTypeName(ty: Type, ip: *const InternPool) struct {
...@@ -3356,8 +3340,7 @@ pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {...@@ -3356,8 +3340,7 @@ pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void {
3356}3340}
33573341
3358/// Recursively walks the type and marks for each subtype how many times it has been seen3342/// Recursively walks the type and marks for each subtype how many times it has been seen
3359fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {3343fn collectSubtypes(ty: Type, zcu: *Zcu, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void {
3360 const zcu = pt.zcu;
3361 const ip = &zcu.intern_pool;3344 const ip = &zcu.intern_pool;
33623345
3363 const gop = try visited.getOrPut(zcu.gpa, ty);3346 const gop = try visited.getOrPut(zcu.gpa, ty);
...@@ -3368,34 +3351,34 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut...@@ -3368,34 +3351,34 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
3368 }3351 }
33693352
3370 switch (ip.indexToKey(ty.toIntern())) {3353 switch (ip.indexToKey(ty.toIntern())) {
3371 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), pt, visited),3354 .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), zcu, visited),
3372 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), pt, visited),3355 .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), zcu, visited),
3373 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), pt, visited),3356 .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), zcu, visited),
3374 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),3357 .opt_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
3375 .error_union_type => |error_union_type| {3358 .error_union_type => |error_union_type| {
3376 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), pt, visited);3359 try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), zcu, visited);
3377 if (error_union_type.payload_type != .generic_poison_type) {3360 if (error_union_type.payload_type != .generic_poison_type) {
3378 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), pt, visited);3361 try collectSubtypes(Type.fromInterned(error_union_type.payload_type), zcu, visited);
3379 }3362 }
3380 },3363 },
3381 .tuple_type => |tuple| {3364 .tuple_type => |tuple| {
3382 for (tuple.types.get(ip)) |field_ty| {3365 for (tuple.types.get(ip)) |field_ty| {
3383 try collectSubtypes(Type.fromInterned(field_ty), pt, visited);3366 try collectSubtypes(Type.fromInterned(field_ty), zcu, visited);
3384 }3367 }
3385 },3368 },
3386 .func_type => |fn_info| {3369 .func_type => |fn_info| {
3387 const param_types = fn_info.param_types.get(&zcu.intern_pool);3370 const param_types = fn_info.param_types.get(&zcu.intern_pool);
3388 for (param_types) |param_ty| {3371 for (param_types) |param_ty| {
3389 if (param_ty != .generic_poison_type) {3372 if (param_ty != .generic_poison_type) {
3390 try collectSubtypes(Type.fromInterned(param_ty), pt, visited);3373 try collectSubtypes(Type.fromInterned(param_ty), zcu, visited);
3391 }3374 }
3392 }3375 }
33933376
3394 if (fn_info.return_type != .generic_poison_type) {3377 if (fn_info.return_type != .generic_poison_type) {
3395 try collectSubtypes(Type.fromInterned(fn_info.return_type), pt, visited);3378 try collectSubtypes(Type.fromInterned(fn_info.return_type), zcu, visited);
3396 }3379 }
3397 },3380 },
3398 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited),3381 .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited),
33993382
3400 // leaf types3383 // leaf types
3401 .undef,3384 .undef,
...@@ -3432,7 +3415,7 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut...@@ -3432,7 +3415,7 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut
3432 }3415 }
3433}3416}
34343417
3435fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMemory}!Comparison.DedupeEntry {3418fn shouldDedupeType(ty: Type, ctx: *Comparison, zcu: *Zcu) error{OutOfMemory}!Comparison.DedupeEntry {
3436 if (ctx.type_occurrences.get(ty)) |occ| {3419 if (ctx.type_occurrences.get(ty)) |occ| {
3437 if (ctx.type_dedupe_cache.get(ty)) |cached| {3420 if (ctx.type_dedupe_cache.get(ty)) |cached| {
3438 return cached;3421 return cached;
...@@ -3440,7 +3423,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe...@@ -3440,7 +3423,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
34403423
3441 var discarding: std.Io.Writer.Discarding = .init(&.{});3424 var discarding: std.Io.Writer.Discarding = .init(&.{});
34423425
3443 print(ty, &discarding.writer, pt, null) catch3426 print(ty, &discarding.writer, zcu, null) catch
3444 unreachable; // we are writing into a discarding writer, it should never fail3427 unreachable; // we are writing into a discarding writer, it should never fail
34453428
3446 const type_len: i32 = @intCast(discarding.count);3429 const type_len: i32 = @intCast(discarding.count);
...@@ -3457,7 +3440,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe...@@ -3457,7 +3440,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe
3457 break :b .{ .dedupe = .{ .index = ctx.placeholder_index - 1 } };3440 break :b .{ .dedupe = .{ .index = ctx.placeholder_index - 1 } };
3458 } else .dont_dedupe;3441 } else .dont_dedupe;
34593442
3460 try ctx.type_dedupe_cache.put(pt.zcu.gpa, ty, entry);3443 try ctx.type_dedupe_cache.put(zcu.comp.gpa, ty, entry);
34613444
3462 return entry;3445 return entry;
3463 } else {3446 } else {
...@@ -3488,38 +3471,37 @@ pub const Comparison = struct {...@@ -3488,38 +3471,37 @@ pub const Comparison = struct {
3488 dedupe: Placeholder,3471 dedupe: Placeholder,
3489 };3472 };
34903473
3491 pub fn init(types: []const Type, pt: Zcu.PerThread) error{OutOfMemory}!Comparison {3474 pub fn init(types: []const Type, zcu: *Zcu) error{OutOfMemory}!Comparison {
3492 var cmp: Comparison = .{3475 var cmp: Comparison = .{
3493 .type_occurrences = .empty,3476 .type_occurrences = .empty,
3494 .type_dedupe_cache = .empty,3477 .type_dedupe_cache = .empty,
3495 .placeholder_index = 0,3478 .placeholder_index = 0,
3496 };3479 };
34973480
3498 errdefer cmp.deinit(pt);3481 errdefer cmp.deinit(zcu.comp.gpa);
34993482
3500 for (types) |ty| {3483 for (types) |ty| {
3501 try collectSubtypes(ty, pt, &cmp.type_occurrences);3484 try collectSubtypes(ty, zcu, &cmp.type_occurrences);
3502 }3485 }
35033486
3504 return cmp;3487 return cmp;
3505 }3488 }
35063489
3507 pub fn deinit(cmp: *Comparison, pt: Zcu.PerThread) void {3490 pub fn deinit(cmp: *Comparison, gpa: Allocator) void {
3508 const gpa = pt.zcu.gpa;
3509 cmp.type_occurrences.deinit(gpa);3491 cmp.type_occurrences.deinit(gpa);
3510 cmp.type_dedupe_cache.deinit(gpa);3492 cmp.type_dedupe_cache.deinit(gpa);
3511 }3493 }
35123494
3513 pub fn fmtType(ctx: *Comparison, ty: Type, pt: Zcu.PerThread) Comparison.Formatter {3495 pub fn fmtType(ctx: *Comparison, ty: Type, zcu: *Zcu) Comparison.Formatter {
3514 return .{ .ty = ty, .ctx = ctx, .pt = pt };3496 return .{ .ty = ty, .ctx = ctx, .zcu = zcu };
3515 }3497 }
3516 pub const Formatter = struct {3498 pub const Formatter = struct {
3517 ty: Type,3499 ty: Type,
3518 ctx: *Comparison,3500 ctx: *Comparison,
3519 pt: Zcu.PerThread,3501 zcu: *Zcu,
35203502
3521 pub fn format(self: Comparison.Formatter, writer: anytype) error{WriteFailed}!void {3503 pub fn format(self: Comparison.Formatter, writer: anytype) error{WriteFailed}!void {
3522 print(self.ty, writer, self.pt, self.ctx) catch return error.WriteFailed;3504 print(self.ty, writer, self.zcu, self.ctx) catch return error.WriteFailed;
3523 }3505 }
3524 };3506 };
3525};3507};
src/Value.zig+326-201
...@@ -34,19 +34,19 @@ pub fn fmtDebug(val: Value) std.fmt.Alt(Value, dump) {...@@ -34,19 +34,19 @@ pub fn fmtDebug(val: Value) std.fmt.Alt(Value, dump) {
34 return .{ .data = val };34 return .{ .data = val };
35}35}
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) {
38 return .{ .data = .{38 return .{ .data = .{
39 .val = val,39 .val = val,
40 .pt = pt,40 .zcu = zcu,
41 .opt_sema = null,41 .opt_sema = null,
42 .depth = 3,42 .depth = 3,
43 } };43 } };
44}44}
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) {
47 return .{ .data = .{47 return .{ .data = .{
48 .val = val,48 .val = val,
49 .pt = pt,49 .zcu = sema.pt.zcu,
50 .opt_sema = sema,50 .opt_sema = sema,
51 .depth = 3,51 .depth = 3,
52 } };52 } };
...@@ -1890,167 +1890,233 @@ pub fn getOffsetPtr(ptr_val: Value, byte_off: u64, new_ty: Type, pt: Zcu.PerThre...@@ -1890,167 +1890,233 @@ pub fn getOffsetPtr(ptr_val: Value, byte_off: u64, new_ty: Type, pt: Zcu.PerThre
1890 return Value.fromInterned(try pt.intern(.{ .ptr = ptr }));1890 return Value.fromInterned(try pt.intern(.{ .ptr = ptr }));
1891}1891}
18921892
1893pub const PointerDeriveStep = union(enum) {1893pub const PointerDerivation = struct {
1894 int: struct {1894 elem_ty: Type,
1895 addr: u64,1895 /// TODO: investigate eliminating this field. We should *always* know the lengths of arrays
1896 ptr_ty: Type,1896 /// which are pointed to, so `.one` should be the only possible case!
1897 },1897 size: Size,
1898 nav_ptr: InternPool.Nav.Index,1898 @"align": InternPool.Alignment,
1899 uav_ptr: InternPool.Key.Ptr.BaseAddr.Uav,1899 @"const": bool,
1900 comptime_alloc_ptr: struct {1900 @"volatile": bool,
1901 idx: InternPool.ComptimeAllocIndex,1901 @"allowzero": bool,
1902 val: Value,1902
1903 ptr_ty: Type,1903 addr: union(enum) {
1904 },1904 int: u64,
1905 comptime_field_ptr: Value,1905 nav: InternPool.Nav.Index,
1906 eu_payload_ptr: struct {1906 uav: Value,
1907 parent: *PointerDeriveStep,1907 comptime_field: Value,
1908 /// This type will never be cast: it is provided for convenience.1908 comptime_alloc: struct {
1909 result_ptr_ty: Type,1909 idx: InternPool.ComptimeAllocIndex,
1910 },1910 val: Value,
1911 opt_payload_ptr: struct {1911 },
1912 parent: *PointerDeriveStep,1912 eu_payload: struct { parent: *PointerDerivation },
1913 /// This type will never be cast: it is provided for convenience.1913 opt_payload: struct { parent: *PointerDerivation },
1914 result_ptr_ty: Type,1914 field: struct {
1915 },1915 parent: *PointerDerivation,
1916 field_ptr: struct {1916 field_index: u32,
1917 parent: *PointerDeriveStep,1917 },
1918 field_idx: u32,1918 elem: struct {
1919 /// This type will never be cast: it is provided for convenience.1919 parent: *PointerDerivation,
1920 result_ptr_ty: Type,1920 elem_index: u64,
1921 },1921 },
1922 elem_ptr: struct {1922 offset_and_cast: struct {
1923 parent: *PointerDeriveStep,1923 parent: *PointerDerivation,
1924 elem_idx: u64,1924 byte_offset: u64,
1925 /// This type will never be cast: it is provided for convenience.1925 },
1926 result_ptr_ty: Type,
1927 },
1928 offset_and_cast: struct {
1929 parent: *PointerDeriveStep,
1930 byte_offset: u64,
1931 new_ptr_ty: Type,
1932 },1926 },
19331927
1934 pub fn ptrType(step: PointerDeriveStep, pt: Zcu.PerThread) !Type {1928 pub const Size = enum { one, many };
1935 return switch (step) {1929
1936 .int => |int| int.ptr_ty,1930 pub fn fmtType(pd: PointerDerivation, zcu: *Zcu) FormatType {
1937 .nav_ptr => |nav| try pt.navPtrType(nav),1931 return .{ .pd = pd, .zcu = zcu };
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 };
1944 }1932 }
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 };
1945};1951};
19461952
1947/// Given a pointer value, get the sequence of steps to derive it, ideally by taking1953/// Given a pointer value, get the sequence of steps to derive it, ideally by taking
1948/// only field and element pointers with no casts. This can be used by codegen backends1954/// only field and element pointers with no casts. This can be used by codegen backends
1949/// which prefer field/elem accesses when lowering constant pointer values.1955/// which prefer field/elem accesses when lowering constant pointer values.
1950/// It is also used by the Value printing logic for pointers.1956/// 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 {1957pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu, opt_sema: ?*Sema) Allocator.Error!PointerDerivation {
1952 const zcu = pt.zcu;
1953 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;1958 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
1954 const base_derive: PointerDeriveStep = switch (ptr.base_addr) {1959 const ptr_ty_info: InternPool.Key.PtrType = info: {
1955 .int => return .{ .int = .{1960 var info = Type.fromInterned(ptr.ty).ptrInfo(zcu);
1956 .addr = ptr.byte_offset,1961 if (info.packed_offset.host_size != 0) {
1957 .ptr_ty = Type.fromInterned(ptr.ty),1962 // TODO: this function *should* handle packed pointers by returning the derivation of
1958 } },1963 // the backing int pointer. However, until https://github.com/ziglang/zig/issues/24061
1959 .nav => |nav| .{ .nav_ptr = nav },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 },
1960 .uav => |uav| base: {1997 .uav => |uav| base: {
1961 // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be.1998 const orig_ty_info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu);
1962 // TODO: fix this in the sites interning anon decls!1999 break :base .{
1963 const const_ty = try pt.ptrType(info: {2000 .elem_ty = .fromInterned(orig_ty_info.child),
1964 var info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu);2001 .size = .one,
1965 info.flags.is_const = true;2002 .@"align" = orig_ty_info.flags.alignment,
1966 break :info info;2003 // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be.
1967 });2004 // TODO: fix this in the sites interning anon decls!
1968 break :base .{ .uav_ptr = .{2005 .@"const" = true,
1969 .val = uav.val,2006 .@"volatile" = orig_ty_info.flags.is_volatile,
1970 .orig_ty = const_ty.toIntern(),2007 .@"allowzero" = orig_ty_info.flags.is_allowzero,
1971 } };2008
2009 .addr = .{ .uav = .fromInterned(uav.val) },
2010 };
1972 },2011 },
1973 .comptime_alloc => |idx| base: {2012 .comptime_alloc => |idx| base: {
1974 const sema = opt_sema.?;2013 const sema = opt_sema.?;
1975 const alloc = sema.getComptimeAlloc(idx);2014 const alloc = sema.getComptimeAlloc(idx);
1976 const val = try alloc.val.intern(pt, arena);2015 const val = try alloc.val.intern(sema.pt, arena);
1977 const ty = val.typeOf(zcu);2016 break :base .{
1978 break :base .{ .comptime_alloc_ptr = .{2017 .elem_ty = val.typeOf(zcu),
1979 .idx = idx,2018 .size = .one,
1980 .val = val,2019 .@"align" = alloc.alignment,
1981 .ptr_ty = try pt.ptrType(.{2020 .@"const" = alloc.is_const,
1982 .child = ty.toIntern(),2021 .@"volatile" = false,
1983 .flags = .{2022 .@"allowzero" = false,
1984 .alignment = alloc.alignment,2023 .addr = .{ .comptime_alloc = .{
1985 },2024 .idx = idx,
1986 }),2025 .val = val,
1987 } };2026 } },
1988 },2027 };
1989 .comptime_field => |val| .{ .comptime_field_ptr = Value.fromInterned(val) },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 },
1990 .eu_payload => |eu_ptr| base: {2038 .eu_payload => |eu_ptr| base: {
1991 const base_ptr = Value.fromInterned(eu_ptr);2039 const parent_step = try arena.create(PointerDerivation);
1992 const base_ptr_ty = base_ptr.typeOf(zcu);2040 parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, zcu, opt_sema);
1993 const parent_step = try arena.create(PointerDeriveStep);2041 break :base .{
1994 parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, pt, opt_sema);2042 .elem_ty = parent_step.elem_ty.errorUnionPayload(zcu),
1995 break :base .{ .eu_payload_ptr = .{2043 .size = .one,
1996 .parent = parent_step,2044 .@"align" = parent_step.@"align",
1997 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).errorUnionPayload(zcu)),2045 .@"const" = parent_step.@"const",
1998 } };2046 .@"volatile" = parent_step.@"volatile",
2047 .@"allowzero" = parent_step.@"allowzero",
2048 .addr = .{ .eu_payload = .{
2049 .parent = parent_step,
2050 } },
2051 };
1999 },2052 },
2000 .opt_payload => |opt_ptr| base: {2053 .opt_payload => |opt_ptr| base: {
2001 const base_ptr = Value.fromInterned(opt_ptr);2054 const parent_step = try arena.create(PointerDerivation);
2002 const base_ptr_ty = base_ptr.typeOf(zcu);2055 parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, zcu, opt_sema);
2003 const parent_step = try arena.create(PointerDeriveStep);2056 break :base .{
2004 parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, pt, opt_sema);2057 .elem_ty = parent_step.elem_ty.optionalChild(zcu),
2005 break :base .{ .opt_payload_ptr = .{2058 .size = .one,
2006 .parent = parent_step,2059 .@"align" = parent_step.@"align",
2007 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).optionalChild(zcu)),2060 .@"const" = parent_step.@"const",
2008 } };2061 .@"volatile" = parent_step.@"volatile",
2062 .@"allowzero" = parent_step.@"allowzero",
2063 .addr = .{ .opt_payload = .{
2064 .parent = parent_step,
2065 } },
2066 };
2009 },2067 },
2010 .field => |field| base: {2068 .field => |field| base: {
2011 const base_ptr = Value.fromInterned(field.base);2069 const parent_step = try arena.create(PointerDerivation);
2012 const base_ptr_ty = try pt.ptrType(info: {2070 parent_step.* = try pointerDerivation(.fromInterned(field.base), arena, zcu, opt_sema);
2013 var info = base_ptr.typeOf(zcu).ptrInfo(zcu);2071 break :base .{
2014 info.flags.size = .one;2072 .elem_ty = if (parent_step.elem_ty.isSlice(zcu)) switch (field.index) {
2015 break :info info;2073 Value.slice_ptr_index => parent_step.elem_ty.slicePtrFieldType(zcu),
2016 });2074 Value.slice_len_index => .usize,
2017 const parent_step = try arena.create(PointerDeriveStep);2075 else => unreachable,
2018 parent_step.* = try pointerDerivation(base_ptr, arena, pt, opt_sema);2076 } else parent_step.elem_ty.fieldType(@intCast(field.index), zcu),
2019 break :base .{ .field_ptr = .{2077 .size = .one,
2020 .parent = parent_step,2078 .@"align" = parent_step.elem_ty.fieldPtrAlign(parent_step.@"align", @intCast(field.index), zcu),
2021 .field_idx = @intCast(field.index),2079 .@"const" = parent_step.@"const",
2022 .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field.index), pt),2080 .@"volatile" = parent_step.@"volatile",
2023 } };2081 .@"allowzero" = parent_step.@"allowzero",
2082 .addr = .{ .field = .{
2083 .parent = parent_step,
2084 .field_index = @intCast(field.index),
2085 } },
2086 };
2024 },2087 },
2025 .arr_elem => |arr_elem| base: {2088 .arr_elem => |arr_elem| base: {
2026 const parent_step = try arena.create(PointerDeriveStep);2089 const parent_step = try arena.create(PointerDerivation);
2027 parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, pt, opt_sema);2090 parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, zcu, opt_sema);
2028 const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu);2091 break :base .{
2029 const result_ptr_ty = try pt.ptrType(.{2092 .elem_ty = parent_step.elem_ty,
2030 .child = parent_ptr_info.child,2093 .size = .many,
2031 .flags = flags: {2094 .@"align" = switch (parent_step.@"align") {
2032 var flags = parent_ptr_info.flags;2095 .none => .none,
2033 flags.size = .one;2096 else => |a| a.minStrict(parent_step.elem_ty.abiAlignment(zcu)),
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;
2039 },2097 },
2040 });2098 .@"const" = parent_step.@"const",
2041 break :base .{ .elem_ptr = .{2099 .@"volatile" = parent_step.@"volatile",
2042 .parent = parent_step,2100 .@"allowzero" = parent_step.@"allowzero",
2043 .elem_idx = arr_elem.index,2101 .addr = .{ .elem = .{
2044 .result_ptr_ty = result_ptr_ty,2102 .parent = parent_step,
2045 } };2103 .elem_index = arr_elem.index,
2104 } },
2105 };
2046 },2106 },
2047 };2107 };
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 {
2050 return base_derive;2117 return base_derive;
2051 }2118 }
20522119
2053 const ptr_ty_info = Type.fromInterned(ptr.ty).ptrInfo(zcu);
2054 const need_child: Type = .fromInterned(ptr_ty_info.child);2120 const need_child: Type = .fromInterned(ptr_ty_info.child);
2055 if (need_child.comptimeOnly(zcu) or2121 if (need_child.comptimeOnly(zcu) or
2056 need_child.zigTypeTag(zcu) == .@"opaque" or2122 need_child.zigTypeTag(zcu) == .@"opaque" or
...@@ -2058,27 +2124,50 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op...@@ -2058,27 +2124,50 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
2058 {2124 {
2059 // No refinement can happen - this pointer is presumably invalid.2125 // No refinement can happen - this pointer is presumably invalid.
2060 // Just offset it.2126 // Just offset it.
2061 const parent = try arena.create(PointerDeriveStep);2127 const parent = try arena.create(PointerDerivation);
2062 parent.* = base_derive;2128 parent.* = base_derive;
2063 return .{ .offset_and_cast = .{2129 return .{
2064 .parent = parent,2130 .elem_ty = .fromInterned(ptr_ty_info.child),
2065 .byte_offset = ptr.byte_offset,2131 .size = ptr_size,
2066 .new_ptr_ty = Type.fromInterned(ptr.ty),2132 .@"align" = ptr_ty_info.flags.alignment,
2067 } };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 };
2068 }2141 }
2069 const need_bytes = need_child.abiSize(zcu);2142 const need_bytes = need_child.abiSize(zcu);
20702143
2071 var cur_derive = base_derive;2144 var cur_derive = base_derive;
2072 var cur_offset = ptr.byte_offset;2145 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
2074 // Refine through fields and array elements as much as possible.2164 // Refine through fields and array elements as much as possible.
20752165
2076 if (need_bytes > 0) while (true) {2166 if (need_bytes > 0) while (true) {
2077 const cur_ty = (try cur_derive.ptrType(pt)).childType(zcu);2167 if (cur_derive.elem_ty.toIntern() == need_child.toIntern() and cur_offset == 0) {
2078 if (cur_ty.toIntern() == need_child.toIntern() and cur_offset == 0) {
2079 break;2168 break;
2080 }2169 }
2081 switch (cur_ty.zigTypeTag(zcu)) {2170 switch (cur_derive.elem_ty.zigTypeTag(zcu)) {
2082 .noreturn,2171 .noreturn,
2083 .type,2172 .type,
2084 .comptime_int,2173 .comptime_int,
...@@ -2105,71 +2194,105 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op...@@ -2105,71 +2194,105 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
21052194
2106 .optional => {2195 .optional => {
2107 ptr_opt: {2196 ptr_opt: {
2108 if (!cur_ty.isPtrLikeOptional(zcu)) break :ptr_opt;2197 if (!cur_derive.elem_ty.isPtrLikeOptional(zcu)) break :ptr_opt;
2109 if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt;2198 if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt;
2110 switch (need_child.ptrSize(zcu)) {2199 switch (need_child.ptrSize(zcu)) {
2111 .one, .many => {},2200 .one, .many => {},
2112 .slice, .c => break :ptr_opt,2201 .slice, .c => break :ptr_opt,
2113 }2202 }
2114 const parent = try arena.create(PointerDeriveStep);2203 const parent = try arena.create(PointerDerivation);
2115 parent.* = cur_derive;2204 parent.* = cur_derive;
2116 cur_derive = .{ .opt_payload_ptr = .{2205 cur_derive = .{
2117 .parent = parent,2206 .elem_ty = parent.elem_ty.optionalChild(zcu),
2118 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), cur_ty.optionalChild(zcu)),2207 .size = .one,
2119 } };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 };
2120 continue;2216 continue;
2121 }2217 }
2122 break;2218 break;
2123 },2219 },
21242220
2125 .array => {2221 .array => {
2126 const elem_ty = cur_ty.childType(zcu);2222 const elem_ty = cur_derive.elem_ty.childType(zcu);
2127 const elem_size = elem_ty.abiSize(zcu);2223 const elem_size = elem_ty.abiSize(zcu);
2128 const start_idx = cur_offset / elem_size;2224 const start_idx = cur_offset / elem_size;
2129 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;2225 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
2226 const start_off = start_idx * elem_size;
2130 if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .one) {2227 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);
2132 parent.* = cur_derive;2229 parent.* = cur_derive;
2133 cur_derive = .{ .elem_ptr = .{2230 cur_derive = .{
2134 .parent = parent,2231 .elem_ty = elem_ty,
2135 .elem_idx = start_idx,2232 .size = .one,
2136 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty),2233 .@"align" = switch (parent.@"align") {
2137 } };2234 .none => .none,
2138 cur_offset -= start_idx * elem_size;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;
2139 } else {2246 } else {
2140 // Go into the first element if needed, but don't go any deeper.2247 // Go into the first element if the byte offsets line up neatly, but don't try
2141 if (start_idx > 0) {2248 // to go any deeper.
2142 const parent = try arena.create(PointerDeriveStep);2249 if (start_idx > 0 and start_idx * elem_size == cur_offset) {
2250 const parent = try arena.create(PointerDerivation);
2143 parent.* = cur_derive;2251 parent.* = cur_derive;
2144 cur_derive = .{ .elem_ptr = .{2252 cur_derive = .{
2145 .parent = parent,2253 .elem_ty = elem_ty,
2146 .elem_idx = start_idx,2254 .size = .one,
2147 .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty),2255 .@"align" = switch (parent.@"align") {
2148 } };2256 .none => .none,
2149 cur_offset -= start_idx * elem_size;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;
2150 }2268 }
2151 break;2269 break;
2152 }2270 }
2153 },2271 },
2154 .@"struct" => switch (cur_ty.containerLayout(zcu)) {2272 .@"struct" => switch (cur_derive.elem_ty.containerLayout(zcu)) {
2155 .auto, .@"packed" => break,2273 .auto, .@"packed" => break,
2156 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {2274 .@"extern" => for (0..cur_derive.elem_ty.structFieldCount(zcu)) |field_idx| {
2157 const field_ty = cur_ty.fieldType(field_idx, zcu);2275 const field_ty = cur_derive.elem_ty.fieldType(field_idx, zcu);
2158 const start_off = cur_ty.structFieldOffset(field_idx, zcu);2276 const start_off = cur_derive.elem_ty.structFieldOffset(field_idx, zcu);
2159 const end_off = start_off + field_ty.abiSize(zcu);2277 const end_off = start_off + field_ty.abiSize(zcu);
2160 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {2278 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
2161 const base_ptr_ty = try pt.ptrType(info: {2279 const parent = try arena.create(PointerDerivation);
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);
2167 parent.* = cur_derive;2280 parent.* = cur_derive;
2168 cur_derive = .{ .field_ptr = .{2281 cur_derive = .{
2169 .parent = parent,2282 .elem_ty = field_ty,
2170 .field_idx = @intCast(field_idx),2283 .size = .one,
2171 .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field_idx), pt),2284 .@"align" = switch (parent.@"align") {
2172 } };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 };
2173 cur_offset -= start_off;2296 cur_offset -= start_off;
2174 break;2297 break;
2175 }2298 }
...@@ -2179,31 +2302,33 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op...@@ -2179,31 +2302,33 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op
2179 };2302 };
21802303
2181 if (cur_offset == 0) compatible: {2304 if (cur_offset == 0) compatible: {
2182 const src_ptr_ty_info = (try cur_derive.ptrType(pt)).ptrInfo(zcu);
2183 // We allow silently doing some "coercible" pointer things.2305 // We allow silently doing some "coercible" pointer things.
2184 // In particular, we only give up if cv qualifiers are *removed*.2306 // 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;2307 if (cur_derive.@"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;2308 if (cur_derive.@"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;2309 if (cur_derive.@"allowzero" and !ptr_ty_info.flags.is_allowzero) break :compatible;
2188 // Everything else has to match exactly.2310 // Element type and alignment, however, have to match exactly.
2189 if (src_ptr_ty_info.child != ptr_ty_info.child) break :compatible;2311 if (cur_derive.elem_ty.toIntern() != ptr_ty_info.child) break :compatible;
2190 if (src_ptr_ty_info.sentinel != ptr_ty_info.sentinel) break :compatible;2312 if (cur_derive.size != ptr_size) break :compatible;
2191 if (src_ptr_ty_info.packed_offset != ptr_ty_info.packed_offset) break :compatible;2313 if (cur_derive.@"align" != ptr_ty_info.flags.alignment) 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;
21962314
2197 return cur_derive;2315 return cur_derive;
2198 }2316 }
21992317
2200 const parent = try arena.create(PointerDeriveStep);2318 const parent = try arena.create(PointerDerivation);
2201 parent.* = cur_derive;2319 parent.* = cur_derive;
2202 return .{ .offset_and_cast = .{2320 return .{
2203 .parent = parent,2321 .elem_ty = .fromInterned(ptr_ty_info.child),
2204 .byte_offset = cur_offset,2322 .size = ptr_size,
2205 .new_ptr_ty = Type.fromInterned(ptr.ty),2323 .@"align" = ptr_ty_info.flags.alignment,
2206 } };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 };
2207}2332}
22082333
2209const InterpretMode = enum {2334const InterpretMode = enum {
src/Zcu/PerThread.zig+2-2
...@@ -3459,7 +3459,7 @@ fn analyzeFuncBodyInner(...@@ -3459,7 +3459,7 @@ fn analyzeFuncBodyInner(
3459 &inner_block,3459 &inner_block,
3460 inner_block.nodeOffset(.zero),3460 inner_block.nodeOffset(.zero),
3461 "cannot resolve inferred error set of {s} function type '{f}'",3461 "cannot resolve inferred error set of {s} function type '{f}'",
3462 .{ description, fn_ty.fmt(pt) },3462 .{ description, fn_ty.fmt(zcu) },
3463 );3463 );
3464 }3464 }
34653465
...@@ -4575,6 +4575,6 @@ fn printVerboseAir(...@@ -4575,6 +4575,6 @@ fn printVerboseAir(
4575 const zcu = pt.zcu;4575 const zcu = pt.zcu;
4576 const ip = &zcu.intern_pool;4576 const ip = &zcu.intern_pool;
4577 try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)});4577 try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)});
4578 try air.write(w, pt, liveness);4578 try air.write(w, zcu, liveness);
4579 try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)});4579 try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)});
4580}4580}
src/codegen.zig+7-6
...@@ -255,7 +255,6 @@ pub fn generateLazySymbol(...@@ -255,7 +255,6 @@ pub fn generateLazySymbol(
255) link.EmitError!void {255) link.EmitError!void {
256 const tracy = trace(@src());256 const tracy = trace(@src());
257 defer tracy.end();257 defer tracy.end();
258 tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(pt) });
259258
260 const comp = bin_file.comp;259 const comp = bin_file.comp;
261 const zcu = pt.zcu;260 const zcu = pt.zcu;
...@@ -263,9 +262,11 @@ pub fn generateLazySymbol(...@@ -263,9 +262,11 @@ pub fn generateLazySymbol(
263 const target = &comp.root_mod.resolved_target.result;262 const target = &comp.root_mod.resolved_target.result;
264 const endian = target.cpu.arch.endian();263 const endian = target.cpu.arch.endian();
265264
265 tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(zcu) });
266
266 log.debug("generateLazySymbol: kind = {s}, ty = {f}", .{267 log.debug("generateLazySymbol: kind = {s}, ty = {f}", .{
267 @tagName(lazy_sym.kind),268 @tagName(lazy_sym.kind),
268 Type.fromInterned(lazy_sym.ty).fmt(pt),269 Type.fromInterned(lazy_sym.ty).fmt(zcu),
269 });270 });
270271
271 if (lazy_sym.kind == .code) {272 if (lazy_sym.kind == .code) {
...@@ -303,7 +304,7 @@ pub fn generateLazySymbol(...@@ -303,7 +304,7 @@ pub fn generateLazySymbol(
303 }304 }
304 } else {305 } else {
305 return zcu.codegenFailType(lazy_sym.ty, "TODO implement generateLazySymbol for {s} {f}", .{306 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),
307 });308 });
308 }309 }
309}310}
...@@ -325,7 +326,7 @@ pub fn generateSymbol(...@@ -325,7 +326,7 @@ pub fn generateSymbol(
325 const target = zcu.getTarget();326 const target = zcu.getTarget();
326 const endian = target.cpu.arch.endian();327 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
330 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse {331 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse {
331 return zcu.comp.link_diags.fail("failed to generate symbol: type size overflow", .{});332 return zcu.comp.link_diags.fail("failed to generate symbol: type size overflow", .{});
...@@ -733,7 +734,7 @@ fn lowerUavRef(...@@ -733,7 +734,7 @@ fn lowerUavRef(
733 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));734 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
734 const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn";735 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
738 if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) {739 if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) {
739 try w.splatByteAll(0xaa, ptr_width_bytes);740 try w.splatByteAll(0xaa, ptr_width_bytes);
...@@ -876,7 +877,7 @@ pub fn lowerValue(pt: Zcu.PerThread, val: Value, target: *const std.Target) Allo...@@ -876,7 +877,7 @@ pub fn lowerValue(pt: Zcu.PerThread, val: Value, target: *const std.Target) Allo
876 const ip = &zcu.intern_pool;877 const ip = &zcu.intern_pool;
877 const ty = val.typeOf(zcu);878 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
881 if (val.isUndef(zcu)) return .undef;882 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...@@ -946,7 +946,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void
946 isel: *Select,946 isel: *Select,
947 inst: Air.Inst.Index,947 inst: Air.Inst.Index,
948 pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {948 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);
950 }950 }
951 } {951 } {
952 return .{ .isel = it.isel, .inst = inst };952 return .{ .isel = it.isel, .inst = inst };
...@@ -7974,11 +7974,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {...@@ -7974,11 +7974,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {
7974}7974}
79757975
7976fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {7976fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {
7977 return ty.fmt(isel.pt);7977 return ty.fmt(isel.pt.zcu);
7978}7978}
79797979
7980fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? {7980fn 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);
7982}7982}
79837983
7984fn block(7984fn block(
src/codegen/c.zig+112-90
...@@ -740,59 +740,57 @@ pub const DeclGen = struct {...@@ -740,59 +740,57 @@ pub const DeclGen = struct {
740 fn renderUav(740 fn renderUav(
741 dg: *DeclGen,741 dg: *DeclGen,
742 w: *Writer,742 w: *Writer,
743 uav: InternPool.Key.Ptr.BaseAddr.Uav,743 uav_val: Value,
744 derivation: Value.PointerDerivation,
744 location: ValueRenderLocation,745 location: ValueRenderLocation,
745 ) Error!void {746 ) Error!void {
746 const pt = dg.pt;747 const pt = dg.pt;
747 const zcu = pt.zcu;748 const zcu = pt.zcu;
748 const ip = &zcu.intern_pool;749 const ip = &zcu.intern_pool;
749 const uav_val = Value.fromInterned(uav.val);
750 const uav_ty = uav_val.typeOf(zcu);750 const uav_ty = uav_val.typeOf(zcu);
751751
752 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.752 // 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);753 if (!uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {
754 if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {754 const target = zcu.getTarget();
755 try w.writeByte('(');755 const alignment = switch (derivation.@"align") {
756 try dg.renderOpvPointer(w, ptr_ty, location);756 .none => derivation.elem_ty.abiAlignment(zcu),
757 return w.writeByte(')');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;
758 }770 }
759771
760 switch (ip.indexToKey(uav.val)) {772 switch (ip.indexToKey(uav_val.toIntern())) {
761 .func => unreachable,773 .func => unreachable,
762 .@"extern" => unreachable,774 .@"extern" => unreachable,
763 else => {},775 else => {},
764 }776 }
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 }
778 try w.writeByte('&');778 try w.writeByte('&');
779 try renderUavName(w, uav_val);779 try renderUavName(w, uav_val);
780 if (need_cast) try w.writeByte(')');
781780
782 // Indicate that the anon decl should be rendered to the output so that781 // Indicate that the anon decl should be rendered to the output so that
783 // our reference above is not undefined.782 // our reference above is not undefined.
784 const ptr_type = ip.indexToKey(uav.orig_ty).ptr_type;783 const gop = try dg.uavs.getOrPut(dg.gpa, uav_val.toIntern());
785 const gop = try dg.uavs.getOrPut(dg.gpa, uav.val);
786 if (!gop.found_existing) gop.value_ptr.* = .none;784 if (!gop.found_existing) gop.value_ptr.* = .none;
787 // If there is an explicit alignment, greater than the current one, use it.785 // If there is an explicit alignment, greater than the current one, use it.
788 // Note that we intentionally start at `.none`, so `gop.value_ptr.*` is never786 // Note that we intentionally start at `.none`, so `gop.value_ptr.*` is never
789 // underaligned, so we don't need to worry about the `.none` case here.787 // 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) {
791 // Resolve the current alignment so we can choose the bigger one.789 // Resolve the current alignment so we can choose the bigger one.
792 const cur_alignment: Alignment = if (gop.value_ptr.* == .none) abi: {790 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);
794 } else gop.value_ptr.*;792 } else gop.value_ptr.*;
795 gop.value_ptr.* = cur_alignment.maxStrict(ptr_type.flags.alignment);793 gop.value_ptr.* = cur_alignment.maxStrict(derivation.@"align");
796 }794 }
797 }795 }
798796
...@@ -818,28 +816,14 @@ pub const DeclGen = struct {...@@ -818,28 +816,14 @@ pub const DeclGen = struct {
818816
819 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.817 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
820 const nav_ty: Type = .fromInterned(ip.getNav(owner_nav).resolved.?.type);818 const nav_ty: Type = .fromInterned(ip.getNav(owner_nav).resolved.?.type);
821 const ptr_ty = try pt.navPtrType(owner_nav);
822 if (nav_ty.zigTypeTag(zcu) != .@"opaque" and !nav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {819 if (nav_ty.zigTypeTag(zcu) != .@"opaque" and !nav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) {
823 try w.writeByte('(');820 try w.writeByte('(');
824 try dg.renderOpvPointer(w, ptr_ty, location);821 try dg.renderOpvPointer(w, try pt.navPtrType(owner_nav), location);
825 return w.writeByte(')');822 return w.writeByte(')');
826 }823 }
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 }
840 try w.writeByte('&');825 try w.writeByte('&');
841 try renderNavName(w, owner_nav, ip);826 try renderNavName(w, owner_nav, ip);
842 if (need_cast) try w.writeByte(')');
843 }827 }
844828
845 fn renderOpvPointer(829 fn renderOpvPointer(
...@@ -865,92 +849,108 @@ pub const DeclGen = struct {...@@ -865,92 +849,108 @@ pub const DeclGen = struct {
865 fn renderPointer(849 fn renderPointer(
866 dg: *DeclGen,850 dg: *DeclGen,
867 w: *Writer,851 w: *Writer,
868 derivation: Value.PointerDeriveStep,852 derivation: Value.PointerDerivation,
869 location: ValueRenderLocation,853 location: ValueRenderLocation,
870 ) Error!void {854 ) Error!void {
871 const pt = dg.pt;855 const pt = dg.pt;
872 const zcu = pt.zcu;856 const zcu = pt.zcu;
873 switch (derivation) {857 switch (derivation.addr) {
874 .comptime_alloc_ptr, .comptime_field_ptr => unreachable,858 .comptime_alloc, .comptime_field => unreachable,
875 .int => |int| {859 .int => |int| {
876 const addr_val = try pt.intValue(.usize, int.addr);860 const addr_val = try pt.intValue(.usize, int);
877 try w.writeByte('(');861 try w.writeByte('(');
878 try dg.renderType(w, int.ptr_ty);862 try dg.renderDerivedPointerType(w, derivation);
879 try w.print("){f}", .{try dg.fmtIntLiteralHex(addr_val, .other)});863 try w.print("){f}", .{try dg.fmtIntLiteralHex(addr_val, .other)});
880 },864 },
881865
882 .nav_ptr => |nav| try dg.renderNav(w, nav, location),866 .nav => |nav| try dg.renderNav(w, nav, location),
883 .uav_ptr => |uav| try dg.renderUav(w, uav, 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| {
886 try w.writeAll("&(");870 try w.writeAll("&(");
887 try dg.renderPointer(w, info.parent.*, location);871 try dg.renderPointer(w, info.parent.*, location);
888 try w.writeAll(")->payload");872 try w.writeAll(")->payload");
889 },873 },
890874
891 .field_ptr => |field| {875 .field => |derived| {
892 const parent_ptr_ty = try field.parent.ptrType(pt);876 switch (fieldLocation(derived.parent.elem_ty, derivation.elem_ty, derived.field_index, zcu)) {
893
894 switch (fieldLocation(parent_ptr_ty, field.result_ptr_ty, field.field_idx, zcu)) {
895 .begin => {877 .begin => {
896 try w.writeByte('(');878 try w.writeByte('(');
897 try dg.renderType(w, field.result_ptr_ty);879 try dg.renderDerivedPointerType(w, derivation);
898 try w.writeByte(')');880 try w.writeByte(')');
899 try dg.renderPointer(w, field.parent.*, location);881 try dg.renderPointer(w, derived.parent.*, location);
900 },882 },
901 .field => |name| {883 .field => |name| {
902 try w.writeAll("&(");884 try w.writeAll("&(");
903 try dg.renderPointer(w, field.parent.*, location);885 try dg.renderPointer(w, derived.parent.*, location);
904 try w.writeAll(")->");886 try w.writeAll(")->");
905 try dg.writeCValue(w, name);887 try dg.writeCValue(w, name);
906 },888 },
907 .byte_offset => |byte_offset| {889 .byte_offset => |byte_offset| {
908 try w.writeByte('(');890 try w.writeByte('(');
909 try dg.renderType(w, field.result_ptr_ty);891 try dg.renderDerivedPointerType(w, derivation);
910 try w.writeByte(')');892 try w.writeByte(')');
911 const offset_val = try pt.intValue(.usize, byte_offset);893 const offset_val = try pt.intValue(.usize, byte_offset);
912 try w.writeAll("((char *)");894 try w.writeAll("((char *)");
913 try dg.renderPointer(w, field.parent.*, location);895 try dg.renderPointer(w, derived.parent.*, location);
914 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});896 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});
915 },897 },
916 }898 }
917 },899 },
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)) {
920 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.902 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.
921 try w.writeByte('(');903 try w.writeByte('(');
922 try dg.renderType(w, elem.result_ptr_ty);904 try dg.renderDerivedPointerType(w, derivation);
923 try w.writeByte(')');905 try w.writeByte(')');
924 try dg.renderPointer(w, elem.parent.*, location);906 try dg.renderPointer(w, derived.parent.*, location);
925 } else {907 } else {
926 const index_val = try pt.intValue(.usize, elem.elem_idx);908 const index_val = try pt.intValue(.usize, derived.elem_index);
927 try w.writeByte('(');909 try w.writeByte('(');
928 // We want to do pointer arithmetic on a pointer to the element type, but the parent910 // 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.911 // is a pointer-to-array, so we need to cast first.
930 if (elem.result_ptr_ty.toIntern() != (try elem.parent.ptrType(pt)).toIntern()) {912 try w.writeByte('(');
931 try w.writeByte('(');913 try dg.renderDerivedPointerType(w, derivation);
932 try dg.renderType(w, elem.result_ptr_ty);914 try w.writeByte(')');
933 try w.writeByte(')');915
934 }916 try dg.renderPointer(w, derived.parent.*, location);
935 try dg.renderPointer(w, elem.parent.*, location);
936 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(index_val, .other)});917 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(index_val, .other)});
937 },918 },
938919
939 .offset_and_cast => |oac| {920 .offset_and_cast => |derived| {
940 try w.writeByte('(');921 try w.writeByte('(');
941 try dg.renderType(w, oac.new_ptr_ty);922 try dg.renderDerivedPointerType(w, derivation);
942 try w.writeByte(')');923 try w.writeByte(')');
943 if (oac.byte_offset == 0) {924 if (derived.byte_offset == 0) {
944 try dg.renderPointer(w, oac.parent.*, location);925 try dg.renderPointer(w, derived.parent.*, location);
945 } else {926 } else {
946 const offset_val = try pt.intValue(.usize, oac.byte_offset);927 const offset_val = try pt.intValue(.usize, derived.byte_offset);
947 try w.writeAll("((char *)");928 try w.writeAll("((char *)");
948 try dg.renderPointer(w, oac.parent.*, location);929 try dg.renderPointer(w, derived.parent.*, location);
949 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});930 try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)});
950 }931 }
951 },932 },
952 }933 }
953 }934 }
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
955 fn renderValueAsLvalue(955 fn renderValueAsLvalue(
956 dg: *DeclGen,956 dg: *DeclGen,
...@@ -1166,7 +1166,31 @@ pub const DeclGen = struct {...@@ -1166,7 +1166,31 @@ pub const DeclGen = struct {
1166 try w.writeByte('}');1166 try w.writeByte('}');
1167 },1167 },
1168 .ptr => {1168 .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);
1170 try w.writeByte('(');1194 try w.writeByte('(');
1171 try dg.renderPointer(w, derivation, location);1195 try dg.renderPointer(w, derivation, location);
1172 try w.writeByte(')');1196 try w.writeByte(')');
...@@ -5380,8 +5404,8 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5380,8 +5404,8 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
5380}5404}
53815405
5382fn fieldLocation(5406fn fieldLocation(
5383 container_ptr_ty: Type,5407 container_ty: Type,
5384 field_ptr_ty: Type,5408 field_ty: Type,
5385 field_index: u32,5409 field_index: u32,
5386 zcu: *Zcu,5410 zcu: *Zcu,
5387) union(enum) {5411) union(enum) {
...@@ -5390,27 +5414,22 @@ fn fieldLocation(...@@ -5390,27 +5414,22 @@ fn fieldLocation(
5390 byte_offset: u64,5414 byte_offset: u64,
5391} {5415} {
5392 const ip = &zcu.intern_pool;5416 const ip = &zcu.intern_pool;
5393 const container_ty: Type = .fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child);
5394 switch (ip.indexToKey(container_ty.toIntern())) {5417 switch (ip.indexToKey(container_ty.toIntern())) {
5395 .struct_type => {5418 .struct_type => {
5396 const loaded_struct = ip.loadStructType(container_ty.toIntern());5419 const loaded_struct = ip.loadStructType(container_ty.toIntern());
5397 return switch (loaded_struct.layout) {5420 return switch (loaded_struct.layout) {
5398 .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu))5421 .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu))
5399 .begin5422 .begin
5400 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))5423 else if (!field_ty.hasRuntimeBits(zcu))
5401 .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] }5424 .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] }
5402 else5425 else
5403 .{ .field = .{ .identifier = loaded_struct.field_names.get(ip)[field_index].toSlice(ip) } },5426 .{ .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)5427 .@"packed" => .begin,
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,
5409 };5428 };
5410 },5429 },
5411 .tuple_type => return if (!container_ty.hasRuntimeBits(zcu))5430 .tuple_type => return if (!container_ty.hasRuntimeBits(zcu))
5412 .begin5431 .begin
5413 else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu))5432 else if (!field_ty.hasRuntimeBits(zcu))
5414 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }5433 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
5415 else5434 else
5416 .{ .field = .{ .field = field_index } },5435 .{ .field = .{ .field = field_index } },
...@@ -5418,7 +5437,6 @@ fn fieldLocation(...@@ -5418,7 +5437,6 @@ fn fieldLocation(
5418 const loaded_union = ip.loadUnionType(container_ty.toIntern());5437 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5419 switch (loaded_union.layout) {5438 switch (loaded_union.layout) {
5420 .auto => {5439 .auto => {
5421 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
5422 if (!field_ty.hasRuntimeBits(zcu)) {5440 if (!field_ty.hasRuntimeBits(zcu)) {
5423 if (container_ty.unionHasAllZeroBitFieldTypes(zcu)) return .begin;5441 if (container_ty.unionHasAllZeroBitFieldTypes(zcu)) return .begin;
5424 return .{ .field = .{ .identifier = "payload" } };5442 return .{ .field = .{ .identifier = "payload" } };
...@@ -5427,7 +5445,6 @@ fn fieldLocation(...@@ -5427,7 +5445,6 @@ fn fieldLocation(
5427 return .{ .field = .{ .payload_identifier = field_name.toSlice(ip) } };5445 return .{ .field = .{ .payload_identifier = field_name.toSlice(ip) } };
5428 },5446 },
5429 .@"extern" => {5447 .@"extern" => {
5430 const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]);
5431 if (!field_ty.hasRuntimeBits(zcu)) return .begin;5448 if (!field_ty.hasRuntimeBits(zcu)) return .begin;
5432 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];5449 const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index];
5433 return .{ .field = .{ .identifier = field_name.toSlice(ip) } };5450 return .{ .field = .{ .identifier = field_name.toSlice(ip) } };
...@@ -5486,7 +5503,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5486,7 +5503,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5486 try f.renderType(w, container_ptr_ty);5503 try f.renderType(w, container_ptr_ty);
5487 try w.writeByte(')');5504 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)) {
5490 .begin => try f.writeCValue(w, field_ptr_val, .other),5507 .begin => try f.writeCValue(w, field_ptr_val, .other),
5491 .field => |field| {5508 .field => |field| {
5492 const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);5509 const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
...@@ -5537,7 +5554,12 @@ fn fieldPtr(...@@ -5537,7 +5554,12 @@ fn fieldPtr(
5537 try f.renderType(w, field_ptr_ty);5554 try f.renderType(w, field_ptr_ty);
5538 try w.writeByte(')');5555 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 )) {
5541 .begin => try f.writeCValue(w, container_ptr_val, .other),5563 .begin => try f.writeCValue(w, container_ptr_val, .other),
5542 .field => |field| {5564 .field => |field| {
5543 try w.writeByte('&');5565 try w.writeByte('&');
src/codegen/c/type/render_defs.zig+4-4
...@@ -28,7 +28,7 @@ pub fn defineAligned(...@@ -28,7 +28,7 @@ pub fn defineAligned(
28 });28 });
29 if (!zcu.comp.config.root_strip) try w.print(" /* align({d}) {f} */", .{29 if (!zcu.comp.config.root_strip) try w.print(" /* align({d}) {f} */", .{
30 alignment.toByteUnits().?,30 alignment.toByteUnits().?,
31 ty.fmt(pt),31 ty.fmt(zcu),
32 });32 });
33 try w.writeByte('\n');33 try w.writeByte('\n');
34}34}
...@@ -113,7 +113,7 @@ pub fn errunionDefineComplete(...@@ -113,7 +113,7 @@ pub fn errunionDefineComplete(
113 });113 });
114 }114 }
115 if (!zcu.comp.config.root_strip) try w.print(" /* anyerror!{f} */", .{115 if (!zcu.comp.config.root_strip) try w.print(" /* anyerror!{f} */", .{
116 payload_ty.fmt(pt),116 payload_ty.fmt(zcu),
117 });117 });
118 try w.writeByte('\n');118 try w.writeByte('\n');
119}119}
...@@ -159,7 +159,7 @@ pub fn defineIncomplete(ty: Type, w: *Writer, pt: Zcu.PerThread) Writer.Error!vo...@@ -159,7 +159,7 @@ pub fn defineIncomplete(ty: Type, w: *Writer, pt: Zcu.PerThread) Writer.Error!vo
159 name_cty.fmtTypeName(zcu),159 name_cty.fmtTypeName(zcu),
160 });160 });
161 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{161 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{
162 ty.fmt(pt),162 ty.fmt(zcu),
163 });163 });
164 try w.writeByte('\n');164 try w.writeByte('\n');
165}165}
...@@ -337,7 +337,7 @@ pub fn defineComplete(...@@ -337,7 +337,7 @@ pub fn defineComplete(
337 else => return,337 else => return,
338 };338 };
339 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{339 if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{
340 ty.fmt(pt),340 ty.fmt(zcu),
341 });341 });
342 try w.writeByte('\n');342 try w.writeByte('\n');
343 if (check_cty) |cty| try writeStaticAssertTypeLayout(ty, cty, w, zcu);343 if (check_cty) |cty| try writeStaticAssertTypeLayout(ty, cty, w, zcu);
src/codegen/llvm.zig+4-3
...@@ -1354,6 +1354,7 @@ pub const Object = struct {...@@ -1354,6 +1354,7 @@ pub const Object = struct {
1354 ///1354 ///
1355 /// `val` is always a type because `o.type_pool` only contains types.1355 /// `val` is always a type because `o.type_pool` only contains types.
1356 pub fn updateConstIncomplete(o: *Object, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void {1356 pub fn updateConstIncomplete(o: *Object, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void {
1357 _ = pt;
1357 const zcu = o.zcu;1358 const zcu = o.zcu;
1358 assert(zcu.intern_pool.typeOf(val) == .type_type);1359 assert(zcu.intern_pool.typeOf(val) == .type_type);
13591360
...@@ -1367,7 +1368,7 @@ pub const Object = struct {...@@ -1367,7 +1368,7 @@ pub const Object = struct {
1367 if (!o.builder.strip) {1368 if (!o.builder.strip) {
1368 assert(val != .anyerror_type);1369 assert(val != .anyerror_type);
1369 const fwd_ref = o.debug_types.items[@backingInt(index)];1370 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)});
1371 // If `ty` is a function, use a dummy *function* type to prevent existing debug1372 // If `ty` is a function, use a dummy *function* type to prevent existing debug
1372 // subprograms from becoming ill-formed.1373 // subprograms from becoming ill-formed.
1373 const debug_incomplete_type = switch (ty.zigTypeTag(zcu)) {1374 const debug_incomplete_type = switch (ty.zigTypeTag(zcu)) {
...@@ -1458,7 +1459,7 @@ pub const Object = struct {...@@ -1458,7 +1459,7 @@ pub const Object = struct {
1458 const target = zcu.getTarget();1459 const target = zcu.getTarget();
1459 const ip = &zcu.intern_pool;1460 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
1463 // lldb cannot handle non-byte-sized types, so in the logic below, bit sizes are padded up.1464 // lldb cannot handle non-byte-sized types, so in the logic below, bit sizes are padded up.
1464 // For instance, `bool` is considered to be 8 bits, and `u60` is considered to be 64 bits.1465 // 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 {...@@ -1967,7 +1968,7 @@ pub const Object = struct {
1967 const debug_payload_type = try o.builder.debugUnionType(1968 const debug_payload_type = try o.builder.debugUnionType(
1968 payload_name: {1969 payload_name: {
1969 if (layout.tag_size == 0) break :payload_name name;1970 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)});
1971 },1972 },
1972 file,1973 file,
1973 scope,1974 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...@@ -3016,7 +3016,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void
3016 isel: *Select,3016 isel: *Select,
3017 inst: Air.Inst.Index,3017 inst: Air.Inst.Index,
3018 pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void {3018 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);
3020 }3020 }
3021 } {3021 } {
3022 return .{ .isel = it.isel, .inst = inst };3022 return .{ .isel = it.isel, .inst = inst };
...@@ -5266,11 +5266,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {...@@ -5266,11 +5266,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct {
5266}5266}
52675267
5268fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {5268fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter {
5269 return ty.fmt(isel.pt);5269 return ty.fmt(isel.pt.zcu);
5270}5270}
52715271
5272fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? {5272fn 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);
5274}5274}
52755275
5276fn fmtRegisterSet(regs: RegisterSet) struct {5276fn 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 {...@@ -1291,7 +1291,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1291 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {1291 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
1292 .@"enum" => {1292 .@"enum" => {
1293 const enum_ty = Type.fromInterned(lazy_sym.ty);1293 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
1296 const param_regs = abi.Registers.Integer.function_arg_regs;1296 const param_regs = abi.Registers.Integer.function_arg_regs;
1297 const ret_reg = param_regs[0];1297 const ret_reg = param_regs[0];
...@@ -1374,7 +1374,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -1374,7 +1374,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1374 },1374 },
1375 else => return func.fail(1375 else => return func.fail(
1376 "TODO implement {s} for {f}",1376 "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) },
1378 ),1378 ),
1379 }1379 }
1380}1380}
...@@ -1911,7 +1911,7 @@ fn splitType(func: *Func, ty: Type) ![2]Type {...@@ -1911,7 +1911,7 @@ fn splitType(func: *Func, ty: Type) ![2]Type {
1911 else => return func.fail("TODO: splitType class {}", .{class}),1911 else => return func.fail("TODO: splitType class {}", .{class}),
1912 };1912 };
1913 } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts;1913 } 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)});
1915}1915}
19161916
1917/// Truncates the value in the register in place.1917/// Truncates the value in the register in place.
...@@ -2024,7 +2024,7 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {...@@ -2024,7 +2024,7 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {
2024 const val_ty = ptr_ty.childType(zcu);2024 const val_ty = ptr_ty.childType(zcu);
2025 return func.allocFrameIndex(FrameAlloc.init(.{2025 return func.allocFrameIndex(FrameAlloc.init(.{
2026 .size = math.cast(u32, val_ty.abiSize(zcu)) orelse {2026 .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)});
2028 },2028 },
2029 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),2029 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
2030 }));2030 }));
...@@ -2164,7 +2164,7 @@ pub fn spillRegisters(func: *Func, comptime registers: []const Register) !void {...@@ -2164,7 +2164,7 @@ pub fn spillRegisters(func: *Func, comptime registers: []const Register) !void {
2164/// allocated. A second call to `copyToTmpRegister` may return the same register.2164/// allocated. A second call to `copyToTmpRegister` may return the same register.
2165/// This can have a side effect of spilling instructions to the stack to free up a register.2165/// This can have a side effect of spilling instructions to the stack to free up a register.
2166fn copyToTmpRegister(func: *Func, ty: Type, mcv: MCValue) !Register {2166fn 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)});
2168 const reg = try func.register_manager.allocReg(null, func.regTempClassForType(ty));2168 const reg = try func.register_manager.allocReg(null, func.regTempClassForType(ty));
2169 try func.genSetReg(ty, reg, mcv);2169 try func.genSetReg(ty, reg, mcv);
2170 return reg;2170 return reg;
...@@ -2249,7 +2249,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void {...@@ -2249,7 +2249,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void {
22492249
2250 break :result dst_mcv;2250 break :result dst_mcv;
2251 } orelse return func.fail("TODO: implement airIntCast from {f} to {f}", .{2251 } 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),
2253 });2253 });
22542254
2255 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });2255 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
...@@ -2636,7 +2636,7 @@ fn genBinOp(...@@ -2636,7 +2636,7 @@ fn genBinOp(
2636 .add_sat,2636 .add_sat,
2637 => {2637 => {
2638 if (bit_size != 64 or !is_unsigned)2638 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
2641 const tmp_reg = try func.copyToTmpRegister(rhs_ty, .{ .register = rhs_reg });2641 const tmp_reg = try func.copyToTmpRegister(rhs_ty, .{ .register = rhs_reg });
2642 const tmp_lock = func.register_manager.lockRegAssumeUnused(tmp_reg);2642 const tmp_lock = func.register_manager.lockRegAssumeUnused(tmp_reg);
...@@ -4057,7 +4057,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {...@@ -4057,7 +4057,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
4057 } else {4057 } else {
4058 return func.fail(4058 return func.fail(
4059 "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}, tag {f}",4059 "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) },
4061 );4061 );
4062 }4062 }
4063 },4063 },
...@@ -4177,7 +4177,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {...@@ -4177,7 +4177,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
41774177
4178 switch (scalar_ty.zigTypeTag(zcu)) {4178 switch (scalar_ty.zigTypeTag(zcu)) {
4179 .int => if (ty.zigTypeTag(zcu) == .vector) {4179 .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)});
4181 } else {4181 } else {
4182 const int_info = scalar_ty.intInfo(zcu);4182 const int_info = scalar_ty.intInfo(zcu);
4183 const int_bits = int_info.bits;4183 const int_bits = int_info.bits;
...@@ -4258,7 +4258,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {...@@ -4258,7 +4258,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void {
42584258
4259 break :result return_mcv;4259 break :result return_mcv;
4260 },4260 },
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)}),
4262 }4262 }
42634263
4264 break :result .unreach;4264 break :result .unreach;
...@@ -4322,7 +4322,7 @@ fn airByteSwap(func: *Func, inst: Air.Inst.Index) !void {...@@ -4322,7 +4322,7 @@ fn airByteSwap(func: *Func, inst: Air.Inst.Index) !void {
43224322
4323 break :result dest_mcv;4323 break :result dest_mcv;
4324 },4324 },
4325 else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(pt)}),4325 else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(zcu)}),
4326 }4326 }
4327 };4327 };
4328 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });4328 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 {...@@ -4388,7 +4388,7 @@ fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
4388 else => return func.fail("TODO: airUnaryMath Float {s}", .{@tagName(tag)}),4388 else => return func.fail("TODO: airUnaryMath Float {s}", .{@tagName(tag)}),
4389 }4389 }
4390 },4390 },
4391 else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(pt)}),4391 else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(zcu)}),
4392 }4392 }
43934393
4394 break :result MCValue{ .register = dst_reg };4394 break :result MCValue{ .register = dst_reg };
...@@ -4488,7 +4488,7 @@ fn load(func: *Func, dst_mcv: MCValue, ptr_mcv: MCValue, ptr_ty: Type) InnerErro...@@ -4488,7 +4488,7 @@ fn load(func: *Func, dst_mcv: MCValue, ptr_mcv: MCValue, ptr_ty: Type) InnerErro
4488 const zcu = pt.zcu;4488 const zcu = pt.zcu;
4489 const dst_ty = ptr_ty.childType(zcu);4489 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
4493 switch (ptr_mcv) {4493 switch (ptr_mcv) {
4494 .none,4494 .none,
...@@ -4541,7 +4541,7 @@ fn airStore(func: *Func, inst: Air.Inst.Index, safety: bool) !void {...@@ -4541,7 +4541,7 @@ fn airStore(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
4541fn store(func: *Func, ptr_mcv: MCValue, src_mcv: MCValue, ptr_ty: Type) !void {4541fn store(func: *Func, ptr_mcv: MCValue, src_mcv: MCValue, ptr_ty: Type) !void {
4542 const zcu = func.pt.zcu;4542 const zcu = func.pt.zcu;
4543 const src_ty = ptr_ty.childType(zcu);4543 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
4546 switch (ptr_mcv) {4546 switch (ptr_mcv) {
4547 .none => unreachable,4547 .none => unreachable,
...@@ -7269,7 +7269,7 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {...@@ -7269,7 +7269,7 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
7269 const bit_size = dst_ty.bitSize(zcu);7269 const bit_size = dst_ty.bitSize(zcu);
7270 if (abi_size * 8 <= bit_size) break :result dst_mcv;7270 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) });
7273 };7273 };
7274 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });7274 return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
7275}7275}
...@@ -8085,7 +8085,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {...@@ -8085,7 +8085,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
8085 );8085 );
8086 break :result .{ .load_frame = .{ .index = frame_index } };8086 break :result .{ .load_frame = .{ .index = frame_index } };
8087 },8087 },
8088 else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(pt)}),8088 else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(zcu)}),
8089 }8089 }
8090 };8090 };
80918091
...@@ -8279,7 +8279,7 @@ fn resolveCallingConventionValues(...@@ -8279,7 +8279,7 @@ fn resolveCallingConventionValues(
8279 };8279 };
82808280
8281 result.return_value = switch (ret_tracking_i) {8281 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 }),
8283 1 => ret_tracking[0],8283 1 => ret_tracking[0],
8284 2 => InstTracking.init(.{ .register_pair = .{8284 2 => InstTracking.init(.{ .register_pair = .{
8285 ret_tracking[0].short.register, ret_tracking[1].short.register,8285 ret_tracking[0].short.register, ret_tracking[1].short.register,
...@@ -8334,7 +8334,7 @@ fn resolveCallingConventionValues(...@@ -8334,7 +8334,7 @@ fn resolveCallingConventionValues(
8334 else => return func.fail("TODO: C calling convention arg class {}", .{class}),8334 else => return func.fail("TODO: C calling convention arg class {}", .{class}),
8335 } else {8335 } else {
8336 arg.* = switch (arg_mcv_i) {8336 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 }),
8338 1 => arg_mcv[0],8338 1 => arg_mcv[0],
8339 2 => .{ .register_pair = .{ arg_mcv[0].register, arg_mcv[1].register } },8339 2 => .{ .register_pair = .{ arg_mcv[0].register, arg_mcv[1].register } },
8340 };8340 };
src/codegen/sparc64/CodeGen.zig+3-3
...@@ -985,7 +985,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -985,7 +985,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!void {
985 switch (self.args[arg_index]) {985 switch (self.args[arg_index]) {
986 .stack_offset => |off| {986 .stack_offset => |off| {
987 const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {987 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)});
989 };989 };
990 const offset = off + abi_size;990 const offset = off + abi_size;
991 break :blk .{ .stack_offset = offset };991 break :blk .{ .stack_offset = offset };
...@@ -2722,7 +2722,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {...@@ -2722,7 +2722,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
2722 }2722 }
27232723
2724 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {2724 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)});
2726 };2726 };
2727 // TODO swap this for inst.ty.ptrAlign2727 // TODO swap this for inst.ty.ptrAlign
2728 const abi_align = elem_ty.abiAlignment(zcu);2728 const abi_align = elem_ty.abiAlignment(zcu);
...@@ -2734,7 +2734,7 @@ fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {...@@ -2734,7 +2734,7 @@ fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
2734 const zcu = pt.zcu;2734 const zcu = pt.zcu;
2735 const elem_ty = self.typeOfIndex(inst);2735 const elem_ty = self.typeOfIndex(inst);
2736 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {2736 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)});
2738 };2738 };
2739 const abi_align = elem_ty.abiAlignment(zcu);2739 const abi_align = elem_ty.abiAlignment(zcu);
2740 self.stack_align = self.stack_align.max(abi_align);2740 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 {...@@ -1297,8 +1297,8 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
1297 const ip = &zcu.intern_pool;1297 const ip = &zcu.intern_pool;
12981298
1299 log.debug("lowering constant: ty = {f}, val = {f}, key = {s}", .{1299 log.debug("lowering constant: ty = {f}, val = {f}, key = {s}", .{
1300 ty.fmt(pt),1300 ty.fmt(zcu),
1301 val.fmtValue(pt),1301 val.fmtValue(zcu),
1302 @tagName(ip.indexToKey(val.toIntern())),1302 @tagName(ip.indexToKey(val.toIntern())),
1303 });1303 });
1304 assert(!ty.isPtrAtRuntime(zcu));1304 assert(!ty.isPtrAtRuntime(zcu));
...@@ -1640,7 +1640,6 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {...@@ -1640,7 +1640,6 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id {
1640}1640}
16411641
1642fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {1642fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {
1643 const pt = cg.pt;
1644 const zcu = cg.zcu;1643 const zcu = cg.zcu;
1645 const gpa = cg.gpa;1644 const gpa = cg.gpa;
16461645
...@@ -1653,32 +1652,64 @@ fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {...@@ -1653,32 +1652,64 @@ fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id {
1653 var arena = std.heap.ArenaAllocator.init(gpa);1652 var arena = std.heap.ArenaAllocator.init(gpa);
1654 defer arena.deinit();1653 defer arena.deinit();
16551654
1656 const derivation = try ptr_val.pointerDerivation(arena.allocator(), pt, null);1655 // TODO: `Value.pointerDerivation` ought to do this for us, but it doesn't receive
1657 return cg.derivePtr(derivation);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);
1658}1685}
16591686
1660fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {1687fn derivePtr(cg: *CodeGen, @"addrspace": std.lang.AddressSpace, derivation: Value.PointerDerivation) !Id {
1661 const gpa = cg.gpa;1688 const gpa = cg.gpa;
1662 const pt = cg.pt;
1663 const zcu = cg.zcu;1689 const zcu = cg.zcu;
1664 const target = zcu.getTarget();1690 const target = zcu.getTarget();
1665 switch (derivation) {1691
1666 .comptime_alloc_ptr, .comptime_field_ptr => unreachable,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,
1667 .int => |int| {1699 .int => |int| {
1668 if (target.os.tag != .opencl) {1700 if (target.os.tag != .opencl) {
1669 if (int.ptr_ty.ptrAddressSpace(zcu) != .physical_storage_buffer) {1701 if (@"addrspace" != .physical_storage_buffer) {
1670 return cg.fail(1702 return cg.fail(
1671 "cannot cast integer to pointer with address space '{s}'",1703 "cannot cast integer to pointer with address space '{s}'",
1672 .{@tagName(int.ptr_ty.ptrAddressSpace(zcu))},1704 .{@tagName(@"addrspace")},
1673 );1705 );
1674 }1706 }
1675 }1707 }
1676 const result_ty_id = try cg.resolveType(int.ptr_ty, .direct);
1677 // TODO: This can probably be an OpSpecConstantOp Bitcast, but1708 // TODO: This can probably be an OpSpecConstantOp Bitcast, but
1678 // that is not implemented by Mesa yet. Therefore, just generate it1709 // that is not implemented by Mesa yet. Therefore, just generate it
1679 // as a runtime operation.1710 // as a runtime operation.
1680 const result_ptr_id = cg.allocId();1711 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);
1682 try cg.body.emit(gpa, .OpConvertUToPtr, .{1713 try cg.body.emit(gpa, .OpConvertUToPtr, .{
1683 .id_result_type = result_ty_id,1714 .id_result_type = result_ty_id,
1684 .id_result = result_ptr_id,1715 .id_result = result_ptr_id,
...@@ -1686,10 +1717,8 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1686,10 +1717,8 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1686 });1717 });
1687 return result_ptr_id;1718 return result_ptr_id;
1688 },1719 },
1689 .nav_ptr => |nav_index| {1720 .nav => |nav_index| {
1690 const ip = &zcu.intern_pool;1721 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);
1693 const nav = ip.getNav(nav_index);1722 const nav = ip.getNav(nav_index);
1694 const nav_ty: Type = .fromInterned(nav.resolved.?.type);1723 const nav_ty: Type = .fromInterned(nav.resolved.?.type);
16951724
...@@ -1698,10 +1727,10 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1698,10 +1727,10 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
16981727
1699 if (ip.isFunctionType(nav_ty.toIntern())) {1728 if (ip.isFunctionType(nav_ty.toIntern())) {
1700 if (is_extern) return try cg.resolveExternFn(nav_index);1729 if (is_extern) return try cg.resolveExternFn(nav_index);
1701 return try cg.constUndef(ty_id);1730 return try cg.constUndef(result_ty_id);
1702 }1731 }
1703 if (!nav_ty.hasRuntimeBits(zcu) and nav_ty.zigTypeTag(zcu) != .spirv) {1732 if (!nav_ty.hasRuntimeBits(zcu) and nav_ty.zigTypeTag(zcu) != .spirv) {
1704 return cg.constUndef(ty_id);1733 return cg.constUndef(result_ty_id);
1705 }1734 }
1706 if (!is_extern) {1735 if (!is_extern) {
1707 return cg.todo("pointer to constant '{f}'", .{nav.fqn.fmt(ip)});1736 return cg.todo("pointer to constant '{f}'", .{nav.fqn.fmt(ip)});
...@@ -1718,7 +1747,7 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1718,7 +1747,7 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1718 try cg.block_var_ids.put(gpa, var_id, {});1747 try cg.block_var_ids.put(gpa, var_id, {});
1719 }1748 }
17201749
1721 if (decl_ptr_ty_id == ty_id) return var_id;1750 if (decl_ptr_ty_id == result_ty_id) return var_id;
1722 switch (target.os.tag) {1751 switch (target.os.tag) {
1723 .vulkan, .opengl => return var_id,1752 .vulkan, .opengl => return var_id,
1724 else => {},1753 else => {},
...@@ -1726,63 +1755,63 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1726,63 +1755,63 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
17261755
1727 const casted_ptr_id = cg.allocId();1756 const casted_ptr_id = cg.allocId();
1728 try cg.body.emit(gpa, .OpBitcast, .{1757 try cg.body.emit(gpa, .OpBitcast, .{
1729 .id_result_type = ty_id,1758 .id_result_type = result_ty_id,
1730 .id_result = casted_ptr_id,1759 .id_result = casted_ptr_id,
1731 .operand = var_id,1760 .operand = var_id,
1732 });1761 });
1733 return casted_ptr_id;1762 return casted_ptr_id;
1734 },1763 },
1735 .uav_ptr => |uav| {1764 .uav => |uav_val| {
1736 const ip = &zcu.intern_pool;1765 const ip = &zcu.intern_pool;
1737 const result_ptr_ty: Type = .fromInterned(uav.orig_ty);1766 const uav_ty = uav_val.typeOf(zcu);
1738 const ty_id = try cg.resolveType(result_ptr_ty, .direct);
1739 const uav_ty: Type = .fromInterned(ip.typeOf(uav.val));
17401767
1741 switch (ip.indexToKey(uav.val)) {1768 switch (ip.indexToKey(uav_val.toIntern())) {
1742 .func => unreachable, // TODO1769 .func => unreachable, // TODO
1743 .@"extern" => assert(!ip.isFunctionType(uav_ty.toIntern())),1770 .@"extern" => assert(!ip.isFunctionType(uav_ty.toIntern())),
1744 else => {},1771 else => {},
1745 }1772 }
17461773
1747 if (!uav_ty.hasRuntimeBits(zcu) and uav_ty.zigTypeTag(zcu) != .spirv) {1774 if (!uav_ty.hasRuntimeBits(zcu) and uav_ty.zigTypeTag(zcu) != .spirv) {
1748 return cg.constUndef(ty_id);1775 return cg.constUndef(result_ty_id);
1749 }1776 }
17501777
1751 if (cg.storageClass(result_ptr_ty.ptrAddressSpace(zcu)) != .function) {1778 if (cg.storageClass(@"addrspace") != .function) {
1752 return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(pt)});1779 return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(zcu)});
1753 }1780 }
17541781
1755 const uav_ty_id = try cg.resolveType(uav_ty, .indirect);1782 const uav_ty_id = try cg.resolveType(uav_ty, .indirect);
1756 const ptr_id = try cg.alloc(uav_ty_id, null);1783 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);
1758 try cg.body.emit(gpa, .OpStore, .{ .pointer = ptr_id, .object = val_id });1785 try cg.body.emit(gpa, .OpStore, .{ .pointer = ptr_id, .object = val_id });
1759 return ptr_id;1786 return ptr_id;
1760 },1787 },
1761 .eu_payload_ptr => @panic("TODO"),1788 .eu_payload => @panic("TODO"),
1762 .opt_payload_ptr => @panic("TODO"),1789 .opt_payload => @panic("TODO"),
1763 .field_ptr => |field| {1790 .field => |derived| return cg.structFieldPtr(
1764 const parent_ptr_id = try cg.derivePtr(field.parent.*);1791 @"addrspace",
1765 const parent_ptr_ty = try field.parent.ptrType(pt);1792 result_ty_id,
1766 return cg.structFieldPtr(field.result_ptr_ty, parent_ptr_ty, parent_ptr_id, field.field_idx);1793 derivation.elem_ty,
1767 },1794 derived.parent.elem_ty,
1768 .elem_ptr => |elem| {1795 try cg.derivePtr(@"addrspace", derived.parent.*),
1769 const parent_ptr_id = try cg.derivePtr(elem.parent.*);1796 derived.field_index,
1770 const parent_ptr_ty = try elem.parent.ptrType(pt);1797 ),
1771 const index_id = try cg.constInt(.usize, elem.elem_idx);1798 .elem => |derived| return cg.ptrElemPtr(
1772 return cg.ptrElemPtr(parent_ptr_ty, parent_ptr_id, index_id);1799 switch (derived.parent.size) {
1773 },1800 .one => .single_array_ptr,
1774 .offset_and_cast => |oac| {1801 .many => .many_ptr,
1775 const parent_ptr_id = try cg.derivePtr(oac.parent.*);1802 },
1776 const parent_ptr_ty = try oac.parent.ptrType(pt);1803 @"addrspace",
17771804 derived.parent.elem_ty,
1778 if (oac.new_ptr_ty.ptrInfo(zcu).flags.vector_index != .none) {1805 try cg.derivePtr(@"addrspace", derived.parent.*),
1779 return parent_ptr_id;1806 try cg.constInt(.usize, derived.elem_index),
1780 }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) {
1783 var depth: u32 = 0;1812 var depth: u32 = 0;
1784 var cur = parent_ptr_ty.childType(zcu);1813 var cur = derived.parent.elem_ty;
1785 const dst_child = oac.new_ptr_ty.childType(zcu);1814 const dst_child = derivation.elem_ty;
1786 while (cur.toIntern() != dst_child.toIntern()) {1815 while (cur.toIntern() != dst_child.toIntern()) {
1787 switch (cur.zigTypeTag(zcu)) {1816 switch (cur.zigTypeTag(zcu)) {
1788 .array => {1817 .array => {
...@@ -1807,9 +1836,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1807,9 +1836,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1807 }1836 }
1808 if (cur.toIntern() == dst_child.toIntern()) {1837 if (cur.toIntern() == dst_child.toIntern()) {
1809 if (depth != 0) {1838 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));
1813 const scratch_top = cg.id_scratch.items.len;1839 const scratch_top = cg.id_scratch.items.len;
1814 defer cg.id_scratch.shrinkRetainingCapacity(scratch_top);1840 defer cg.id_scratch.shrinkRetainingCapacity(scratch_top);
1815 const zero = try cg.constInt(.u32, 0);1841 const zero = try cg.constInt(.u32, 0);
...@@ -1820,7 +1846,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1820,7 +1846,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1820 return parent_ptr_id;1846 return parent_ptr_id;
1821 }1847 }
1822 }1848 }
1823 const result_ty_id = try cg.resolveType(oac.new_ptr_ty, .direct);
1824 if (target.os.tag == .opencl) {1849 if (target.os.tag == .opencl) {
1825 const result_ptr_id = cg.allocId();1850 const result_ptr_id = cg.allocId();
1826 try cg.body.emit(gpa, .OpBitcast, .{1851 try cg.body.emit(gpa, .OpBitcast, .{
...@@ -1832,9 +1857,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {...@@ -1832,9 +1857,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id {
1832 }1857 }
1833 }1858 }
18341859
1835 return cg.fail("cannot cast pointer '{f}' to '{f}'", .{1860 return cg.fail("cannot cast pointer '*{f}' to '*{f}'", .{
1836 parent_ptr_ty.fmt(pt),1861 derived.parent.elem_ty.fmt(zcu),
1837 oac.new_ptr_ty.fmt(pt),1862 derivation.elem_ty.fmt(zcu),
1838 });1863 });
1839 },1864 },
1840 }1865 }
...@@ -1881,7 +1906,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1881,7 +1906,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1881 const ip = &zcu.intern_pool;1906 const ip = &zcu.intern_pool;
1882 const target = cg.zcu.getTarget();1907 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
1886 switch (ty.zigTypeTag(zcu)) {1911 switch (ty.zigTypeTag(zcu)) {
1887 .noreturn => {1912 .noreturn => {
...@@ -1919,7 +1944,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -1919,7 +1944,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
1919 };1944 };
1920 if (!supported) return cg.fail(1945 if (!supported) return cg.fail(
1921 "'{f}' is not supported on the current SPIR-V feature set",1946 "'{f}' is not supported on the current SPIR-V feature set",
1922 .{ty.fmt(cg.pt)},1947 .{ty.fmt(zcu)},
1923 );1948 );
1924 return try cg.floatType(bits);1949 return try cg.floatType(bits);
1925 },1950 },
...@@ -2047,7 +2072,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -2047,7 +2072,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
2047 null,2072 null,
2048 .none,2073 .none,
2049 );2074 );
2050 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});2075 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
2051 return result_id;2076 return result_id;
2052 },2077 },
2053 .struct_type => ip.loadStructType(ty.toIntern()),2078 .struct_type => ip.loadStructType(ty.toIntern()),
...@@ -2080,7 +2105,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -2080,7 +2105,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
2080 ty.toIntern(),2105 ty.toIntern(),
2081 );2106 );
20822107
2083 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});2108 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
20842109
2085 return result_id;2110 return result_id;
2086 },2111 },
...@@ -2134,7 +2159,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -2134,7 +2159,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
2134 }2159 }
21352160
2136 const result_id = try cg.structType(member_types[0..len], null, .none);2161 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)});
2138 return result_id;2163 return result_id;
2139 },2164 },
2140 }2165 }
...@@ -2169,7 +2194,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -2169,7 +2194,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
2169 member_names[0..layout.total_fields],2194 member_names[0..layout.total_fields],
2170 .none,2195 .none,
2171 );2196 );
2172 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)});2197 try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)});
2173 return result_id;2198 return result_id;
2174 },2199 },
2175 .error_set => {2200 .error_set => {
...@@ -2206,7 +2231,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {...@@ -2206,7 +2231,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
2206 },2231 },
2207 .@"opaque" => {2232 .@"opaque" => {
2208 if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{});2233 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)});
2210 },2235 },
2211 .spirv => {2236 .spirv => {
2212 const spirv_type = ip.loadSpirvType(ty.toIntern());2237 const spirv_type = ip.loadSpirvType(ty.toIntern());
...@@ -6455,21 +6480,28 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -6455,21 +6480,28 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
6455 return try cg.load(slice_ty.childType(zcu), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(zcu) });6480 return try cg.load(slice_ty.childType(zcu), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(zcu) });
6456}6481}
64576482
6458fn ptrElemPtr(cg: *CodeGen, ptr_ty: Type, ptr_id: Id, index_id: Id) !Id {6483fn ptrElemPtr(
6459 const zcu = cg.zcu;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 {
6460 // Construct new pointer type for the resulting pointer6491 // Construct new pointer type for the resulting pointer
6461 const as = ptr_ty.ptrAddressSpace(zcu);
6462 const is_single_ptr = ptr_ty.isSinglePointer(zcu);
6463 const elem_is_block = cg.block_var_ids.contains(ptr_id);6492 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);6493 const elem_ty_id = try cg.pointeeType(@"addrspace", elem_ty, elem_is_block);
6465 const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(as));6494 const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(@"addrspace"));
6466 if (is_single_ptr) {6495 switch (mode) {
6467 // Pointer-to-array. In this case, the resulting pointer is not of the same type6496 .single_array_ptr => {
6468 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.6497 // Pointer-to-array. In this case, the resulting pointer is not of the same type
6469 return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});6498 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
6470 } else {6499 return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});
6471 // Resulting pointer type is the same as the ptr_ty, so use ptrAccessChain6500 },
6472 return cg.ptrAccessChain(elem_ptr_ty_id, ptr_id, index_id, &.{});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 },
6473 }6505 }
6474}6506}
64756507
...@@ -6483,13 +6515,19 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -6483,13 +6515,19 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
6483 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;6515 const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl;
6484 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;6516 const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data;
6485 const src_ptr_ty = cg.typeOf(bin_op.lhs);6517 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);
6487 const ptr_id = try cg.resolve(bin_op.lhs);6519 const ptr_id = try cg.resolve(bin_op.lhs);
64886520
6489 assert(elem_ty.hasRuntimeBits(zcu));6521 assert(elem_ty.hasRuntimeBits(zcu));
64906522
6491 const index_id = try cg.resolve(bin_op.rhs);6523 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 );
6493}6531}
64946532
6495fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {6533fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
...@@ -6551,7 +6589,13 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -6551,7 +6589,13 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
6551 const elem_ty = cg.typeOfIndex(inst);6589 const elem_ty = cg.typeOfIndex(inst);
6552 const ptr_id = try cg.resolve(bin_op.lhs);6590 const ptr_id = try cg.resolve(bin_op.lhs);
6553 const index_id = try cg.resolve(bin_op.rhs);6591 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 );
6555 return try cg.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });6599 return try cg.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
6556}6600}
65576601
...@@ -6845,66 +6889,44 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -6845,66 +6889,44 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
68456889
6846fn structFieldPtr(6890fn structFieldPtr(
6847 cg: *CodeGen,6891 cg: *CodeGen,
6848 result_ptr_ty: Type,6892 @"addrspace": std.lang.AddressSpace,
6849 object_ptr_ty: Type,6893 result_ptr_ty_id: Id,
6894 field_ty: Type,
6895 object_ty: Type,
6850 object_ptr: Id,6896 object_ptr: Id,
6851 field_index: u32,6897 field_index: u32,
6852) !Id {6898) !Id {
6853 const result_ty_id = try cg.resolveType(result_ptr_ty, .direct);
6854
6855 const zcu = cg.zcu;6899 const zcu = cg.zcu;
6856 const object_ty = object_ptr_ty.childType(zcu);
6857 switch (object_ty.zigTypeTag(zcu)) {6900 switch (object_ty.zigTypeTag(zcu)) {
6858 .pointer => {6901 .pointer => {
6859 assert(object_ty.isSlice(zcu));6902 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});
6861 },6904 },
6862 .@"struct" => switch (object_ty.containerLayout(zcu)) {6905 .@"struct" => switch (object_ty.containerLayout(zcu)) {
6863 .@"packed" => {6906 .@"packed" => unreachable,
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 },
6884 .auto, .@"extern" => {6907 .auto, .@"extern" => {
6885 const member_index = cg.memberIndex(object_ty, field_index);6908 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});
6887 },6910 },
6888 },6911 },
6889 .@"union" => switch (object_ty.containerLayout(zcu)) {6912 .@"union" => switch (object_ty.containerLayout(zcu)) {
6890 .@"packed" => return cg.todo("implement field access for packed unions", .{}),6913 .@"packed" => unreachable,
6891 .auto => {6914 .auto => {
6892 if (!result_ptr_ty.childType(zcu).hasRuntimeBits(zcu)) return try cg.constUndef(result_ty_id);6915 if (!field_ty.hasRuntimeBits(zcu)) return try cg.constUndef(result_ptr_ty_id);
6893 return try cg.accessChain(result_ty_id, object_ptr, &.{field_index});6916 return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{field_index});
6894 },6917 },
6895 .@"extern" => {6918 .@"extern" => {
6896 const layout = cg.unionLayout(object_ty);6919 const layout = cg.unionLayout(object_ty);
6897 if (!layout.has_payload) {6920 if (!layout.has_payload) {
6898 // Asked to get a pointer to a zero-sized field. Just lower this6921 // Asked to get a pointer to a zero-sized field. Just lower this
6899 // to undefined, there is no reason to make it be a valid pointer.6922 // 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);
6901 }6924 }
69026925
6903 const storage_class = cg.storageClass(object_ptr_ty.ptrAddressSpace(zcu));6926 const storage_class = cg.storageClass(@"addrspace");
6904 const field_ty = result_ptr_ty.childType(zcu);
6905 if (field_ty.toIntern() == layout.payload_ty.toIntern()) {6927 if (field_ty.toIntern() == layout.payload_ty.toIntern()) {
6906 if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr;6928 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});
6908 }6930 }
69096931
6910 switch (zcu.getTarget().os.tag) {6932 switch (zcu.getTarget().os.tag) {
...@@ -6913,7 +6935,7 @@ fn structFieldPtr(...@@ -6913,7 +6935,7 @@ fn structFieldPtr(
6913 // type is structurally identical to the payload type (dedup will6935 // type is structurally identical to the payload type (dedup will
6914 // unify them) the access chain typed as the field type is valid.6936 // unify them) the access chain typed as the field type is valid.
6915 if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr;6937 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});
6917 },6939 },
6918 else => {},6940 else => {},
6919 }6941 }
...@@ -6927,7 +6949,7 @@ fn structFieldPtr(...@@ -6927,7 +6949,7 @@ fn structFieldPtr(
69276949
6928 const active_pl_ptr_id = cg.allocId();6950 const active_pl_ptr_id = cg.allocId();
6929 try cg.body.emit(cg.gpa, .OpBitcast, .{6951 try cg.body.emit(cg.gpa, .OpBitcast, .{
6930 .id_result_type = result_ty_id,6952 .id_result_type = result_ptr_ty_id,
6931 .id_result = active_pl_ptr_id,6953 .id_result = active_pl_ptr_id,
6932 .operand = pl_ptr_id,6954 .operand = pl_ptr_id,
6933 });6955 });
...@@ -6971,7 +6993,14 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {...@@ -6971,7 +6993,14 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id {
6971 const struct_ptr = try cg.resolve(struct_field.struct_operand);6993 const struct_ptr = try cg.resolve(struct_field.struct_operand);
6972 const struct_ptr_ty = cg.typeOf(struct_field.struct_operand);6994 const struct_ptr_ty = cg.typeOf(struct_field.struct_operand);
6973 const result_ptr_ty = cg.typeOfIndex(inst);6995 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 );
6975}7004}
69767005
6977fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, field_index: u32) !?Id {7006fn 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)...@@ -6979,7 +7008,14 @@ fn airStructFieldPtrIndex(cg: *CodeGen, inst: Air.Inst.Index, field_index: u32)
6979 const struct_ptr = try cg.resolve(ty_op.operand);7008 const struct_ptr = try cg.resolve(ty_op.operand);
6980 const struct_ptr_ty = cg.typeOf(ty_op.operand);7009 const struct_ptr_ty = cg.typeOf(ty_op.operand);
6981 const result_ptr_ty = cg.typeOfIndex(inst);7010 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 );
6983}7019}
69847020
6985fn alloc(cg: *CodeGen, ty_id: Id, initializer: ?Id) !Id {7021fn 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 {...@@ -1154,7 +1154,7 @@ fn allocStack(cg: *CodeGen, ty: Type) !WValue {
11541154
1155 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {1155 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
1156 return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{1156 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),
1158 });1158 });
1159 };1159 };
1160 const abi_align = ty.abiAlignment(zcu);1160 const abi_align = ty.abiAlignment(zcu);
...@@ -1195,7 +1195,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {...@@ -1195,7 +1195,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue {
1195 const abi_alignment = ptr_ty.ptrAlignment(zcu);1195 const abi_alignment = ptr_ty.ptrAlignment(zcu);
1196 const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse {1196 const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse {
1197 return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{1197 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),
1199 });1199 });
1200 };1200 };
1201 cg.stack_alignment = cg.stack_alignment.max(abi_alignment);1201 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)...@@ -2108,7 +2108,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)
2108 if (!arg_ty.hasRuntimeBits(zcu)) continue;2108 if (!arg_ty.hasRuntimeBits(zcu)) continue;
21092109
2110 const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse {2110 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)});
2112 };2112 };
2113 const arg_align = arg_ty.abiAlignment(zcu);2113 const arg_align = arg_ty.abiAlignment(zcu);
21142114
...@@ -2128,7 +2128,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)...@@ -2128,7 +2128,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier)
21282128
2129 const arg_val = try cg.resolveInst(arg);2129 const arg_val = try cg.resolveInst(arg);
2130 const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse {2130 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)});
2132 };2132 };
2133 const arg_align = arg_ty.abiAlignment(zcu);2133 const arg_align = arg_ty.abiAlignment(zcu);
21342134
...@@ -5189,7 +5189,7 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {...@@ -5189,7 +5189,7 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue {
5189 return .{ .imm32 = @intFromBool(!val.isNull(zcu)) };5189 return .{ .imm32 = @intFromBool(!val.isNull(zcu)) };
5190 },5190 },
5191 .aggregate => switch (ip.indexToKey(ty.ip_index)) {5191 .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)}),
5193 .vector_type => {5193 .vector_type => {
5194 assert(determineSimdStoreStrategy(ty, zcu, cg.target) == .direct);5194 assert(determineSimdStoreStrategy(ty, zcu, cg.target) == .direct);
5195 var buf: [16]u8 = undefined;5195 var buf: [16]u8 = undefined;
...@@ -5883,7 +5883,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5883,7 +5883,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5883 .@"packed" => unreachable, // legalize .expand_packed_agg_field_val5883 .@"packed" => unreachable, // legalize .expand_packed_agg_field_val
5884 else => result: {5884 else => result: {
5885 const offset = std.math.cast(u32, struct_ty.structFieldOffset(field_index, zcu)) orelse {5885 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)});
5887 };5887 };
5888 if (isByRef(field_ty, zcu, cg.target)) {5888 if (isByRef(field_ty, zcu, cg.target)) {
5889 break :result try cg.offsetPointer(operand, offset);5889 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...@@ -6296,7 +6296,7 @@ fn isNull(cg: *CodeGen, operand: WValue, op_ty: Type, opcode: std.wasm.Opcode, o
6296 // a pointer to the stack value6296 // a pointer to the stack value
6297 if (payload_ty.hasRuntimeBits(zcu)) {6297 if (payload_ty.hasRuntimeBits(zcu)) {
6298 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {6298 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)});
6300 };6300 };
6301 try cg.emitMemBase(operand);6301 try cg.emitMemBase(operand);
6302 try cg.addMemArg(.i32_load8_u, .{ .offset = operand.memOffset() + offset, .alignment = .@"1" });6302 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...@@ -6381,7 +6381,7 @@ fn airOptionalPayloadPtrSet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void
6381 }6381 }
63826382
6383 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {6383 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)});
6385 };6385 };
63866386
6387 try cg.emitMemBase(operand);6387 try cg.emitMemBase(operand);
...@@ -6412,7 +6412,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6412,7 +6412,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6412 break :result operand;6412 break :result operand;
6413 }6413 }
6414 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {6414 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)});
6416 };6416 };
64176417
6418 // Create optional type, set the non-null bit, and store the operand inside the optional type6418 // 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 {...@@ -1174,7 +1174,7 @@ const FormatAirData = struct {
1174 inst: Air.Inst.Index,1174 inst: Air.Inst.Index,
1175};1175};
1176fn formatAir(data: FormatAirData, w: *Writer) Writer.Error!void {1176fn 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);
1178}1178}
1179fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Alt(FormatAirData, formatAir) {1179fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Alt(FormatAirData, formatAir) {
1180 return .{ .data = .{ .self = self, .inst = inst } };1180 return .{ .data = .{ .self = self, .inst = inst } };
...@@ -1185,14 +1185,15 @@ const FormatWipMirData = struct {...@@ -1185,14 +1185,15 @@ const FormatWipMirData = struct {
1185 inst: Mir.Inst.Index,1185 inst: Mir.Inst.Index,
1186};1186};
1187fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {1187fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
1188 const zcu = data.self.pt.zcu;
1188 var lower: Lower = .{1189 var lower: Lower = .{
1189 .target = data.self.target,1190 .target = data.self.target,
1190 .allocator = data.self.gpa,1191 .allocator = data.self.gpa,
1191 .mir = data.self.getTmpMir(),1192 .mir = data.self.getTmpMir(),
1192 .cc = .auto,1193 .cc = .auto,
1193 .src_loc = switch (data.self.owner) {1194 .src_loc = switch (data.self.owner) {
1194 .nav_index => |nav| data.self.pt.zcu.navSrcLoc(nav),1195 .nav_index => |nav| zcu.navSrcLoc(nav),
1195 .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(data.self.pt.zcu) orelse .unneeded,1196 .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(zcu) orelse .unneeded,
1196 },1197 },
1197 };1198 };
1198 var first = true;1199 var first = true;
...@@ -1215,7 +1216,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {...@@ -1215,7 +1216,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
1215 first = false;1216 first = false;
1216 }1217 }
1217 if (first) {1218 if (first) {
1218 const ip = &data.self.pt.zcu.intern_pool;1219 const ip = &zcu.intern_pool;
1219 const mir_inst = lower.mir.instructions.get(data.inst);1220 const mir_inst = lower.mir.instructions.get(data.inst);
1220 try w.print(" | .{s}", .{@tagName(mir_inst.ops)});1221 try w.print(" | .{s}", .{@tagName(mir_inst.ops)});
1221 switch (mir_inst.ops) {1222 switch (mir_inst.ops) {
...@@ -1264,7 +1265,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {...@@ -1264,7 +1265,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void {
1264 try w.print(" {f}", .{mem_op.fmt(.m)});1265 try w.print(" {f}", .{mem_op.fmt(.m)});
1265 },1266 },
1266 .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try w.print(" {f}", .{1267 .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),
1268 }),1269 }),
1269 }1270 }
1270 }1271 }
...@@ -4532,7 +4533,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -4532,7 +4533,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4532 } }) catch |err| switch (err) {4533 } }) catch |err| switch (err) {
4533 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{4534 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
4534 @tagName(air_tag),4535 @tagName(air_tag),
4535 cg.typeOf(bin_op.lhs).fmt(pt),4536 cg.typeOf(bin_op.lhs).fmt(zcu),
4536 ops[0].tracking(cg),4537 ops[0].tracking(cg),
4537 ops[1].tracking(cg),4538 ops[1].tracking(cg),
4538 }),4539 }),
...@@ -4544,7 +4545,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -4544,7 +4545,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
4544 .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) {4545 .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
4545 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{4546 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
4546 @tagName(air_tag),4547 @tagName(air_tag),
4547 cg.typeOf(bin_op.lhs).fmt(pt),4548 cg.typeOf(bin_op.lhs).fmt(zcu),
4548 res[0].tracking(cg),4549 res[0].tracking(cg),
4549 }),4550 }),
4550 else => |e| return e,4551 else => |e| return e,
...@@ -13109,7 +13110,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -13109,7 +13110,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
13109 } }) catch |err| switch (err) {13110 } }) catch |err| switch (err) {
13110 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{13111 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
13111 @tagName(air_tag),13112 @tagName(air_tag),
13112 cg.typeOf(bin_op.lhs).fmt(pt),13113 cg.typeOf(bin_op.lhs).fmt(zcu),
13113 ops[0].tracking(cg),13114 ops[0].tracking(cg),
13114 ops[1].tracking(cg),13115 ops[1].tracking(cg),
13115 }),13116 }),
...@@ -15283,7 +15284,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -15283,7 +15284,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
15283 } }) catch |err| switch (err) {15284 } }) catch |err| switch (err) {
15284 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{15285 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
15285 @tagName(air_tag),15286 @tagName(air_tag),
15286 cg.typeOf(bin_op.lhs).fmt(pt),15287 cg.typeOf(bin_op.lhs).fmt(zcu),
15287 ops[0].tracking(cg),15288 ops[0].tracking(cg),
15288 ops[1].tracking(cg),15289 ops[1].tracking(cg),
15289 }),15290 }),
...@@ -15295,7 +15296,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -15295,7 +15296,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
15295 .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) {15296 .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) {
15296 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{15297 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
15297 @tagName(air_tag),15298 @tagName(air_tag),
15298 cg.typeOf(bin_op.lhs).fmt(pt),15299 cg.typeOf(bin_op.lhs).fmt(zcu),
15299 res[0].tracking(cg),15300 res[0].tracking(cg),
15300 }),15301 }),
15301 else => |e| return e,15302 else => |e| return e,
...@@ -22130,7 +22131,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -22130,7 +22131,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
22130 } }) catch |err| switch (err) {22131 } }) catch |err| switch (err) {
22131 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{22132 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
22132 @tagName(air_tag),22133 @tagName(air_tag),
22133 cg.typeOf(bin_op.lhs).fmt(pt),22134 cg.typeOf(bin_op.lhs).fmt(zcu),
22134 ops[0].tracking(cg),22135 ops[0].tracking(cg),
22135 ops[1].tracking(cg),22136 ops[1].tracking(cg),
22136 }),22137 }),
...@@ -25067,7 +25068,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -25067,7 +25068,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
25067 } }) catch |err| switch (err) {25068 } }) catch |err| switch (err) {
25068 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{25069 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
25069 @tagName(air_tag),25070 @tagName(air_tag),
25070 ty.fmt(pt),25071 ty.fmt(zcu),
25071 ops[0].tracking(cg),25072 ops[0].tracking(cg),
25072 ops[1].tracking(cg),25073 ops[1].tracking(cg),
25073 }),25074 }),
...@@ -26865,7 +26866,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -26865,7 +26866,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
26865 } }) catch |err| switch (err) {26866 } }) catch |err| switch (err) {
26866 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{26867 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
26867 @tagName(air_tag),26868 @tagName(air_tag),
26868 ty.fmt(pt),26869 ty.fmt(zcu),
26869 ops[0].tracking(cg),26870 ops[0].tracking(cg),
26870 ops[1].tracking(cg),26871 ops[1].tracking(cg),
26871 }),26872 }),
...@@ -26874,7 +26875,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -26874,7 +26875,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
26874 res[0].wrapInt(cg) catch |err| switch (err) {26875 res[0].wrapInt(cg) catch |err| switch (err) {
26875 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{26876 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
26876 @tagName(air_tag),26877 @tagName(air_tag),
26877 cg.typeOf(bin_op.lhs).fmt(pt),26878 cg.typeOf(bin_op.lhs).fmt(zcu),
26878 res[0].tracking(cg),26879 res[0].tracking(cg),
26879 }),26880 }),
26880 else => |e| return e,26881 else => |e| return e,
...@@ -32090,7 +32091,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -32090,7 +32091,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
32090 } }) catch |err| switch (err) {32091 } }) catch |err| switch (err) {
32091 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{32092 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
32092 @tagName(air_tag),32093 @tagName(air_tag),
32093 cg.typeOf(bin_op.lhs).fmt(pt),32094 cg.typeOf(bin_op.lhs).fmt(zcu),
32094 ops[0].tracking(cg),32095 ops[0].tracking(cg),
32095 ops[1].tracking(cg),32096 ops[1].tracking(cg),
32096 }),32097 }),
...@@ -33328,7 +33329,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -33328,7 +33329,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
33328 }) catch |err| switch (err) {33329 }) catch |err| switch (err) {
33329 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{33330 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
33330 @tagName(air_tag),33331 @tagName(air_tag),
33331 ty.fmt(pt),33332 ty.fmt(zcu),
33332 ops[0].tracking(cg),33333 ops[0].tracking(cg),
33333 ops[1].tracking(cg),33334 ops[1].tracking(cg),
33334 }),33335 }),
...@@ -34785,7 +34786,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -34785,7 +34786,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
34785 }) catch |err| switch (err) {34786 }) catch |err| switch (err) {
34786 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{34787 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
34787 @tagName(air_tag),34788 @tagName(air_tag),
34788 ty.fmt(pt),34789 ty.fmt(zcu),
34789 ops[0].tracking(cg),34790 ops[0].tracking(cg),
34790 ops[1].tracking(cg),34791 ops[1].tracking(cg),
34791 }),34792 }),
...@@ -36346,7 +36347,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -36346,7 +36347,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
36346 }) catch |err| switch (err) {36347 }) catch |err| switch (err) {
36347 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{36348 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
36348 @tagName(air_tag),36349 @tagName(air_tag),
36349 cg.typeOf(bin_op.lhs).fmt(pt),36350 cg.typeOf(bin_op.lhs).fmt(zcu),
36350 ops[0].tracking(cg),36351 ops[0].tracking(cg),
36351 ops[1].tracking(cg),36352 ops[1].tracking(cg),
36352 }),36353 }),
...@@ -38038,7 +38039,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -38038,7 +38039,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
38038 } })) catch |err| switch (err) {38039 } })) catch |err| switch (err) {
38039 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{38040 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
38040 @tagName(air_tag),38041 @tagName(air_tag),
38041 ty.fmt(pt),38042 ty.fmt(zcu),
38042 ops[0].tracking(cg),38043 ops[0].tracking(cg),
38043 ops[1].tracking(cg),38044 ops[1].tracking(cg),
38044 }),38045 }),
...@@ -39820,7 +39821,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -39820,7 +39821,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
39820 } }) catch |err| switch (err) {39821 } }) catch |err| switch (err) {
39821 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{39822 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
39822 @tagName(air_tag),39823 @tagName(air_tag),
39823 cg.typeOf(bin_op.lhs).fmt(pt),39824 cg.typeOf(bin_op.lhs).fmt(zcu),
39824 ops[0].tracking(cg),39825 ops[0].tracking(cg),
39825 ops[1].tracking(cg),39826 ops[1].tracking(cg),
39826 }),39827 }),
...@@ -43333,7 +43334,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -43333,7 +43334,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
43333 } }) catch |err| switch (err) {43334 } }) catch |err| switch (err) {
43334 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{43335 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
43335 @tagName(air_tag),43336 @tagName(air_tag),
43336 cg.typeOf(bin_op.lhs).fmt(pt),43337 cg.typeOf(bin_op.lhs).fmt(zcu),
43337 ops[0].tracking(cg),43338 ops[0].tracking(cg),
43338 ops[1].tracking(cg),43339 ops[1].tracking(cg),
43339 }),43340 }),
...@@ -43447,7 +43448,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -43447,7 +43448,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
43447 } }) catch |err| switch (err) {43448 } }) catch |err| switch (err) {
43448 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{43449 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
43449 @tagName(air_tag),43450 @tagName(air_tag),
43450 cg.typeOf(bin_op.lhs).fmt(pt),43451 cg.typeOf(bin_op.lhs).fmt(zcu),
43451 ops[0].tracking(cg),43452 ops[0].tracking(cg),
43452 ops[1].tracking(cg),43453 ops[1].tracking(cg),
43453 }),43454 }),
...@@ -43576,7 +43577,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -43576,7 +43577,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
43576 } }) catch |err| switch (err) {43577 } }) catch |err| switch (err) {
43577 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{43578 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
43578 @tagName(air_tag),43579 @tagName(air_tag),
43579 cg.typeOf(bin_op.lhs).fmt(pt),43580 cg.typeOf(bin_op.lhs).fmt(zcu),
43580 ops[0].tracking(cg),43581 ops[0].tracking(cg),
43581 ops[1].tracking(cg),43582 ops[1].tracking(cg),
43582 }),43583 }),
...@@ -47885,7 +47886,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -47885,7 +47886,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
47885 } }) catch |err| switch (err) {47886 } }) catch |err| switch (err) {
47886 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{47887 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
47887 @tagName(air_tag),47888 @tagName(air_tag),
47888 cg.typeOf(bin_op.lhs).fmt(pt),47889 cg.typeOf(bin_op.lhs).fmt(zcu),
47889 ops[0].tracking(cg),47890 ops[0].tracking(cg),
47890 ops[1].tracking(cg),47891 ops[1].tracking(cg),
47891 }),47892 }),
...@@ -52188,7 +52189,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -52188,7 +52189,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
52188 } }) catch |err| switch (err) {52189 } }) catch |err| switch (err) {
52189 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{52190 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
52190 @tagName(air_tag),52191 @tagName(air_tag),
52191 cg.typeOf(bin_op.lhs).fmt(pt),52192 cg.typeOf(bin_op.lhs).fmt(zcu),
52192 ops[0].tracking(cg),52193 ops[0].tracking(cg),
52193 ops[1].tracking(cg),52194 ops[1].tracking(cg),
52194 }),52195 }),
...@@ -53037,7 +53038,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -53037,7 +53038,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
53037 } }) catch |err| switch (err) {53038 } }) catch |err| switch (err) {
53038 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{53039 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
53039 @tagName(air_tag),53040 @tagName(air_tag),
53040 ty_pl.ty.fmt(pt),53041 ty_pl.ty.fmt(zcu),
53041 ops[0].tracking(cg),53042 ops[0].tracking(cg),
53042 ops[1].tracking(cg),53043 ops[1].tracking(cg),
53043 }),53044 }),
...@@ -53942,7 +53943,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -53942,7 +53943,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
53942 } }) catch |err| switch (err) {53943 } }) catch |err| switch (err) {
53943 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{53944 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
53944 @tagName(air_tag),53945 @tagName(air_tag),
53945 ty_pl.ty.fmt(pt),53946 ty_pl.ty.fmt(zcu),
53946 ops[0].tracking(cg),53947 ops[0].tracking(cg),
53947 ops[1].tracking(cg),53948 ops[1].tracking(cg),
53948 }),53949 }),
...@@ -57539,7 +57540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -57539,7 +57540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
57539 } }) catch |err| switch (err) {57540 } }) catch |err| switch (err) {
57540 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{57541 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
57541 @tagName(air_tag),57542 @tagName(air_tag),
57542 ty_pl.ty.fmt(pt),57543 ty_pl.ty.fmt(zcu),
57543 ops[0].tracking(cg),57544 ops[0].tracking(cg),
57544 ops[1].tracking(cg),57545 ops[1].tracking(cg),
57545 }),57546 }),
...@@ -60884,7 +60885,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -60884,7 +60885,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
60884 } }) catch |err| switch (err) {60885 } }) catch |err| switch (err) {
60885 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{60886 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
60886 @tagName(air_tag),60887 @tagName(air_tag),
60887 ty_pl.ty.fmt(pt),60888 ty_pl.ty.fmt(zcu),
60888 ops[0].tracking(cg),60889 ops[0].tracking(cg),
60889 ops[1].tracking(cg),60890 ops[1].tracking(cg),
60890 }),60891 }),
...@@ -61279,7 +61280,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -61279,7 +61280,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
61279 }) catch |err| switch (err) {61280 }) catch |err| switch (err) {
61280 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{61281 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
61281 @tagName(air_tag),61282 @tagName(air_tag),
61282 cg.typeOf(bin_op.lhs).fmt(pt),61283 cg.typeOf(bin_op.lhs).fmt(zcu),
61283 ops[0].tracking(cg),61284 ops[0].tracking(cg),
61284 ops[1].tracking(cg),61285 ops[1].tracking(cg),
61285 }),61286 }),
...@@ -61842,8 +61843,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -61842,8 +61843,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
61842 } }) catch |err| switch (err) {61843 } }) catch |err| switch (err) {
61843 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{61844 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
61844 @tagName(air_tag),61845 @tagName(air_tag),
61845 cg.typeOf(bin_op.lhs).fmt(pt),61846 cg.typeOf(bin_op.lhs).fmt(zcu),
61846 cg.typeOf(bin_op.rhs).fmt(pt),61847 cg.typeOf(bin_op.rhs).fmt(zcu),
61847 ops[0].tracking(cg),61848 ops[0].tracking(cg),
61848 ops[1].tracking(cg),61849 ops[1].tracking(cg),
61849 }),61850 }),
...@@ -62204,8 +62205,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -62204,8 +62205,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
62204 } }) catch |err| switch (err) {62205 } }) catch |err| switch (err) {
62205 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{62206 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
62206 @tagName(air_tag),62207 @tagName(air_tag),
62207 cg.typeOf(bin_op.lhs).fmt(pt),62208 cg.typeOf(bin_op.lhs).fmt(zcu),
62208 cg.typeOf(bin_op.rhs).fmt(pt),62209 cg.typeOf(bin_op.rhs).fmt(zcu),
62209 ops[0].tracking(cg),62210 ops[0].tracking(cg),
62210 ops[1].tracking(cg),62211 ops[1].tracking(cg),
62211 }),62212 }),
...@@ -62216,7 +62217,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -62216,7 +62217,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
62216 .shl => res[0].wrapInt(cg) catch |err| switch (err) {62217 .shl => res[0].wrapInt(cg) catch |err| switch (err) {
62217 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{62218 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
62218 @tagName(air_tag),62219 @tagName(air_tag),
62219 cg.typeOf(bin_op.lhs).fmt(pt),62220 cg.typeOf(bin_op.lhs).fmt(zcu),
62220 res[0].tracking(cg),62221 res[0].tracking(cg),
62221 }),62222 }),
62222 else => |e| return e,62223 else => |e| return e,
...@@ -62383,7 +62384,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -62383,7 +62384,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
62383 } }) catch |err| switch (err) {62384 } }) catch |err| switch (err) {
62384 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{62385 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
62385 @tagName(air_tag),62386 @tagName(air_tag),
62386 cg.typeOf(bin_op.rhs).fmt(pt),62387 cg.typeOf(bin_op.rhs).fmt(zcu),
62387 ops[1].tracking(cg),62388 ops[1].tracking(cg),
62388 }),62389 }),
62389 else => |e| return e,62390 else => |e| return e,
...@@ -65640,7 +65641,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -65640,7 +65641,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
65640 } }) catch |err| switch (err) {65641 } }) catch |err| switch (err) {
65641 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{65642 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
65642 @tagName(air_tag),65643 @tagName(air_tag),
65643 lhs_ty.fmt(pt),65644 lhs_ty.fmt(zcu),
65644 ops[0].tracking(cg),65645 ops[0].tracking(cg),
65645 ops[1].tracking(cg),65646 ops[1].tracking(cg),
65646 }),65647 }),
...@@ -67425,7 +67426,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -67425,7 +67426,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
67425 } }) catch |err| switch (err) {67426 } }) catch |err| switch (err) {
67426 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{67427 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
67427 @tagName(air_tag),67428 @tagName(air_tag),
67428 ty_op.ty.fmt(pt),67429 ty_op.ty.fmt(zcu),
67429 ops[0].tracking(cg),67430 ops[0].tracking(cg),
67430 }),67431 }),
67431 else => |e| return e,67432 else => |e| return e,
...@@ -70586,7 +70587,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -70586,7 +70587,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
70586 } }) catch |err| switch (err) {70587 } }) catch |err| switch (err) {
70587 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{70588 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
70588 @tagName(air_tag),70589 @tagName(air_tag),
70589 cg.typeOf(ty_op.operand).fmt(pt),70590 cg.typeOf(ty_op.operand).fmt(zcu),
70590 ops[0].tracking(cg),70591 ops[0].tracking(cg),
70591 }),70592 }),
70592 else => |e| return e,70593 else => |e| return e,
...@@ -70983,7 +70984,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -70983,7 +70984,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
70983 } }) catch |err| switch (err) {70984 } }) catch |err| switch (err) {
70984 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{70985 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
70985 @tagName(air_tag),70986 @tagName(air_tag),
70986 cg.typeOf(ty_op.operand).fmt(pt),70987 cg.typeOf(ty_op.operand).fmt(zcu),
70987 ops[0].tracking(cg),70988 ops[0].tracking(cg),
70988 }),70989 }),
70989 else => |e| return e,70990 else => |e| return e,
...@@ -71871,7 +71872,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -71871,7 +71872,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
71871 } }) catch |err| switch (err) {71872 } }) catch |err| switch (err) {
71872 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{71873 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
71873 @tagName(air_tag),71874 @tagName(air_tag),
71874 cg.typeOf(ty_op.operand).fmt(pt),71875 cg.typeOf(ty_op.operand).fmt(zcu),
71875 ops[0].tracking(cg),71876 ops[0].tracking(cg),
71876 }),71877 }),
71877 else => |e| return e,71878 else => |e| return e,
...@@ -72520,7 +72521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -72520,7 +72521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
72520 } }) catch |err| switch (err) {72521 } }) catch |err| switch (err) {
72521 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{72522 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
72522 @tagName(air_tag),72523 @tagName(air_tag),
72523 ty_op.ty.fmt(pt),72524 ty_op.ty.fmt(zcu),
72524 ops[0].tracking(cg),72525 ops[0].tracking(cg),
72525 }),72526 }),
72526 else => |e| return e,72527 else => |e| return e,
...@@ -75622,7 +75623,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -75622,7 +75623,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
75622 } }) catch |err| switch (err) {75623 } }) catch |err| switch (err) {
75623 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{75624 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
75624 @tagName(air_tag),75625 @tagName(air_tag),
75625 ty_op.ty.fmt(pt),75626 ty_op.ty.fmt(zcu),
75626 ops[0].tracking(cg),75627 ops[0].tracking(cg),
75627 }),75628 }),
75628 else => |e| return e,75629 else => |e| return e,
...@@ -76684,7 +76685,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -76684,7 +76685,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
76684 } }) catch |err| switch (err) {76685 } }) catch |err| switch (err) {
76685 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{76686 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
76686 @tagName(air_tag),76687 @tagName(air_tag),
76687 cg.typeOf(un_op).fmt(pt),76688 cg.typeOf(un_op).fmt(zcu),
76688 ops[0].tracking(cg),76689 ops[0].tracking(cg),
76689 }),76690 }),
76690 else => |e| return e,76691 else => |e| return e,
...@@ -77534,7 +77535,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -77534,7 +77535,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
77534 }) catch |err| switch (err) {77535 }) catch |err| switch (err) {
77535 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{77536 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
77536 @tagName(air_tag),77537 @tagName(air_tag),
77537 cg.typeOf(un_op).fmt(pt),77538 cg.typeOf(un_op).fmt(zcu),
77538 ops[0].tracking(cg),77539 ops[0].tracking(cg),
77539 }),77540 }),
77540 else => |e| return e,77541 else => |e| return e,
...@@ -79085,7 +79086,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -79085,7 +79086,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
79085 } }) catch |err| switch (err) {79086 } }) catch |err| switch (err) {
79086 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{79087 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
79087 @tagName(air_tag),79088 @tagName(air_tag),
79088 cg.typeOf(ty_op.operand).fmt(pt),79089 cg.typeOf(ty_op.operand).fmt(zcu),
79089 ops[0].tracking(cg),79090 ops[0].tracking(cg),
79090 }),79091 }),
79091 else => |e| return e,79092 else => |e| return e,
...@@ -80421,7 +80422,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -80421,7 +80422,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
80421 }) catch |err| switch (err) {80422 }) catch |err| switch (err) {
80422 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{80423 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
80423 @tagName(air_tag),80424 @tagName(air_tag),
80424 cg.typeOf(un_op).fmt(pt),80425 cg.typeOf(un_op).fmt(zcu),
80425 ops[0].tracking(cg),80426 ops[0].tracking(cg),
80426 }),80427 }),
80427 else => |e| return e,80428 else => |e| return e,
...@@ -80961,7 +80962,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -80961,7 +80962,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
80961 } }) catch |err| switch (err) {80962 } }) catch |err| switch (err) {
80962 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{80963 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
80963 @tagName(air_tag),80964 @tagName(air_tag),
80964 cg.typeOf(un_op).fmt(pt),80965 cg.typeOf(un_op).fmt(zcu),
80965 ops[0].tracking(cg),80966 ops[0].tracking(cg),
80966 }),80967 }),
80967 else => |e| return e,80968 else => |e| return e,
...@@ -81441,7 +81442,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -81441,7 +81442,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
81441 }) catch |err| switch (err) {81442 }) catch |err| switch (err) {
81442 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{81443 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
81443 @tagName(air_tag),81444 @tagName(air_tag),
81444 cg.typeOf(bin_op.lhs).fmt(pt),81445 cg.typeOf(bin_op.lhs).fmt(zcu),
81445 ops[0].tracking(cg),81446 ops[0].tracking(cg),
81446 ops[1].tracking(cg),81447 ops[1].tracking(cg),
81447 }),81448 }),
...@@ -82016,7 +82017,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -82016,7 +82017,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
82016 for (&ops) |*op| op.wrapInt(cg) catch |err| switch (err) {82017 for (&ops) |*op| op.wrapInt(cg) catch |err| switch (err) {
82017 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{82018 error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{
82018 @tagName(air_tag),82019 @tagName(air_tag),
82019 ty.fmt(pt),82020 ty.fmt(zcu),
82020 op.tracking(cg),82021 op.tracking(cg),
82021 }),82022 }),
82022 else => |e| return e,82023 else => |e| return e,
...@@ -82028,7 +82029,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -82028,7 +82029,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
82028 }) catch |err| switch (err) {82029 }) catch |err| switch (err) {
82029 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{82030 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
82030 @tagName(air_tag),82031 @tagName(air_tag),
82031 ty.fmt(pt),82032 ty.fmt(zcu),
82032 ops[0].tracking(cg),82033 ops[0].tracking(cg),
82033 ops[1].tracking(cg),82034 ops[1].tracking(cg),
82034 }),82035 }),
...@@ -89107,7 +89108,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -89107,7 +89108,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
89107 error.SelectFailed => return cg.fail("failed to select {s} {s} {f} {f} {f}", .{89108 error.SelectFailed => return cg.fail("failed to select {s} {s} {f} {f} {f}", .{
89108 @tagName(air_tag),89109 @tagName(air_tag),
89109 @tagName(vector_cmp.compareOperator()),89110 @tagName(vector_cmp.compareOperator()),
89110 cg.typeOf(vector_cmp.lhs).fmt(pt),89111 cg.typeOf(vector_cmp.lhs).fmt(zcu),
89111 ops[0].tracking(cg),89112 ops[0].tracking(cg),
89112 ops[1].tracking(cg),89113 ops[1].tracking(cg),
89113 }),89114 }),
...@@ -91699,8 +91700,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -91699,8 +91700,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
91699 } }) catch |err| switch (err) {91700 } }) catch |err| switch (err) {
91700 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{91701 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
91701 @tagName(air_tag),91702 @tagName(air_tag),
91702 ty_op.ty.fmt(pt),91703 ty_op.ty.fmt(zcu),
91703 cg.typeOf(ty_op.operand).fmt(pt),91704 cg.typeOf(ty_op.operand).fmt(zcu),
91704 ops[0].tracking(cg),91705 ops[0].tracking(cg),
91705 }),91706 }),
91706 else => |e| return e,91707 else => |e| return e,
...@@ -93374,8 +93375,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -93374,8 +93375,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
93374 } }) catch |err| switch (err) {93375 } }) catch |err| switch (err) {
93375 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{93376 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
93376 @tagName(air_tag),93377 @tagName(air_tag),
93377 ty_op.ty.fmt(pt),93378 ty_op.ty.fmt(zcu),
93378 cg.typeOf(ty_op.operand).fmt(pt),93379 cg.typeOf(ty_op.operand).fmt(zcu),
93379 ops[0].tracking(cg),93380 ops[0].tracking(cg),
93380 }),93381 }),
93381 else => |e| return e,93382 else => |e| return e,
...@@ -98132,8 +98133,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -98132,8 +98133,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
98132 } }) catch |err| switch (err) {98133 } }) catch |err| switch (err) {
98133 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{98134 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
98134 @tagName(air_tag),98135 @tagName(air_tag),
98135 dst_ty.fmt(pt),98136 dst_ty.fmt(zcu),
98136 src_ty.fmt(pt),98137 src_ty.fmt(zcu),
98137 ops[0].tracking(cg),98138 ops[0].tracking(cg),
98138 }),98139 }),
98139 else => |e| return e,98140 else => |e| return e,
...@@ -103798,8 +103799,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -103798,8 +103799,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
103798 } }) catch |err| switch (err) {103799 } }) catch |err| switch (err) {
103799 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{103800 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
103800 @tagName(air_tag),103801 @tagName(air_tag),
103801 ty_op.ty.fmt(pt),103802 ty_op.ty.fmt(zcu),
103802 cg.typeOf(ty_op.operand).fmt(pt),103803 cg.typeOf(ty_op.operand).fmt(zcu),
103803 ops[0].tracking(cg),103804 ops[0].tracking(cg),
103804 }),103805 }),
103805 else => |e| return e,103806 else => |e| return e,
...@@ -115168,8 +115169,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -115168,8 +115169,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
115168 } }) catch |err| switch (err) {115169 } }) catch |err| switch (err) {
115169 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{115170 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
115170 @tagName(air_tag),115171 @tagName(air_tag),
115171 ty_op.ty.fmt(pt),115172 ty_op.ty.fmt(zcu),
115172 cg.typeOf(ty_op.operand).fmt(pt),115173 cg.typeOf(ty_op.operand).fmt(zcu),
115173 ops[0].tracking(cg),115174 ops[0].tracking(cg),
115174 }),115175 }),
115175 else => |e| return e,115176 else => |e| return e,
...@@ -127059,8 +127060,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -127059,8 +127060,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
127059 } }) catch |err| switch (err) {127060 } }) catch |err| switch (err) {
127060 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{127061 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{
127061 @tagName(air_tag),127062 @tagName(air_tag),
127062 ty_op.ty.fmt(pt),127063 ty_op.ty.fmt(zcu),
127063 cg.typeOf(ty_op.operand).fmt(pt),127064 cg.typeOf(ty_op.operand).fmt(zcu),
127064 ops[0].tracking(cg),127065 ops[0].tracking(cg),
127065 }),127066 }),
127066 else => |e| return e,127067 else => |e| return e,
...@@ -161250,7 +161251,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -161250,7 +161251,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
161250 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{161251 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{
161251 @tagName(air_tag),161252 @tagName(air_tag),
161252 @tagName(reduce.operation),161253 @tagName(reduce.operation),
161253 cg.typeOf(reduce.operand).fmt(pt),161254 cg.typeOf(reduce.operand).fmt(zcu),
161254 ops[0].tracking(cg),161255 ops[0].tracking(cg),
161255 }),161256 }),
161256 else => |e| return e,161257 else => |e| return e,
...@@ -161261,7 +161262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -161261,7 +161262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
161261 error.SelectFailed => return cg.fail("failed to select {s}.{s} wrap {f} {f}", .{161262 error.SelectFailed => return cg.fail("failed to select {s}.{s} wrap {f} {f}", .{
161262 @tagName(air_tag),161263 @tagName(air_tag),
161263 @tagName(reduce.operation),161264 @tagName(reduce.operation),
161264 res_ty.fmt(pt),161265 res_ty.fmt(zcu),
161265 res[0].tracking(cg),161266 res[0].tracking(cg),
161266 }),161267 }),
161267 else => |e| return e,161268 else => |e| return e,
...@@ -168964,7 +168965,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -168964,7 +168965,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
168964 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{168965 error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{
168965 @tagName(air_tag),168966 @tagName(air_tag),
168966 @tagName(reduce.operation),168967 @tagName(reduce.operation),
168967 cg.typeOf(reduce.operand).fmt(pt),168968 cg.typeOf(reduce.operand).fmt(zcu),
168968 ops[0].tracking(cg),168969 ops[0].tracking(cg),
168969 }),168970 }),
168970 else => |e| return e,168971 else => |e| return e,
...@@ -170804,7 +170805,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -170804,7 +170805,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170804 } }) catch |err| switch (err) {170805 } }) catch |err| switch (err) {
170805 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{170806 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
170806 @tagName(air_tag),170807 @tagName(air_tag),
170807 ty_op.ty.fmt(pt),170808 ty_op.ty.fmt(zcu),
170808 ops[0].tracking(cg),170809 ops[0].tracking(cg),
170809 }),170810 }),
170810 else => |e| return e,170811 else => |e| return e,
...@@ -170820,8 +170821,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -170820,8 +170821,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170820 ops[2] = ops[0].getByteLen(cg) catch |err| switch (err) {170821 ops[2] = ops[0].getByteLen(cg) catch |err| switch (err) {
170821 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{170822 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
170822 @tagName(air_tag),170823 @tagName(air_tag),
170823 cg.typeOf(bin_op.lhs).fmt(pt),170824 cg.typeOf(bin_op.lhs).fmt(zcu),
170824 cg.typeOf(bin_op.rhs).fmt(pt),170825 cg.typeOf(bin_op.rhs).fmt(zcu),
170825 ops[0].tracking(cg),170826 ops[0].tracking(cg),
170826 ops[1].tracking(cg),170827 ops[1].tracking(cg),
170827 }),170828 }),
...@@ -170861,8 +170862,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -170861,8 +170862,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
170861 }) catch |err| switch (err) {170862 }) catch |err| switch (err) {
170862 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f} {f}", .{170863 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f} {f}", .{
170863 @tagName(air_tag),170864 @tagName(air_tag),
170864 cg.typeOf(bin_op.lhs).fmt(pt),170865 cg.typeOf(bin_op.lhs).fmt(zcu),
170865 cg.typeOf(bin_op.rhs).fmt(pt),170866 cg.typeOf(bin_op.rhs).fmt(zcu),
170866 ops[0].tracking(cg),170867 ops[0].tracking(cg),
170867 ops[1].tracking(cg),170868 ops[1].tracking(cg),
170868 ops[2].tracking(cg),170869 ops[2].tracking(cg),
...@@ -171042,7 +171043,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -171042,7 +171043,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171042 } }) catch |err| switch (err) {171043 } }) catch |err| switch (err) {
171043 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{171044 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171044 @tagName(air_tag),171045 @tagName(air_tag),
171045 cg.typeOf(un_op).fmt(pt),171046 cg.typeOf(un_op).fmt(zcu),
171046 ops[0].tracking(cg),171047 ops[0].tracking(cg),
171047 }),171048 }),
171048 else => |e| return e,171049 else => |e| return e,
...@@ -171208,7 +171209,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -171208,7 +171209,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171208 } }) catch |err| switch (err) {171209 } }) catch |err| switch (err) {
171209 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{171210 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171210 @tagName(air_tag),171211 @tagName(air_tag),
171211 cg.typeOf(un_op).fmt(pt),171212 cg.typeOf(un_op).fmt(zcu),
171212 ops[0].tracking(cg),171213 ops[0].tracking(cg),
171213 }),171214 }),
171214 else => |e| return e,171215 else => |e| return e,
...@@ -171310,7 +171311,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -171310,7 +171311,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171310 } }) catch |err| switch (err) {171311 } }) catch |err| switch (err) {
171311 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{171312 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171312 @tagName(air_tag),171313 @tagName(air_tag),
171313 cg.typeOf(un_op).fmt(pt),171314 cg.typeOf(un_op).fmt(zcu),
171314 ops[0].tracking(cg),171315 ops[0].tracking(cg),
171315 }),171316 }),
171316 else => |e| return e,171317 else => |e| return e,
...@@ -171408,7 +171409,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -171408,7 +171409,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171408 } }) catch |err| switch (err) {171409 } }) catch |err| switch (err) {
171409 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{171410 error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{
171410 @tagName(air_tag),171411 @tagName(air_tag),
171411 ty_op.ty.fmt(pt),171412 ty_op.ty.fmt(zcu),
171412 ops[0].tracking(cg),171413 ops[0].tracking(cg),
171413 }),171414 }),
171414 else => |e| return e,171415 else => |e| return e,
...@@ -171481,7 +171482,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -171481,7 +171482,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
171481 },171482 },
171482 else => return cg.fail("failed to select {s} {f}", .{171483 else => return cg.fail("failed to select {s} {f}", .{
171483 @tagName(air_tag),171484 @tagName(air_tag),
171484 agg_ty.fmt(pt),171485 agg_ty.fmt(zcu),
171485 }),171486 }),
171486 }171487 }
171487 try res.finish(inst, &.{}, &.{}, cg);171488 try res.finish(inst, &.{}, &.{}, cg);
...@@ -172927,7 +172928,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {...@@ -172927,7 +172928,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
172927 } }) catch |err| switch (err) {172928 } }) catch |err| switch (err) {
172928 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{172929 error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{
172929 @tagName(air_tag),172930 @tagName(air_tag),
172930 cg.typeOf(bin_op.lhs).fmt(pt),172931 cg.typeOf(bin_op.lhs).fmt(zcu),
172931 ops[0].tracking(cg),172932 ops[0].tracking(cg),
172932 ops[1].tracking(cg),172933 ops[1].tracking(cg),
172933 ops[2].tracking(cg),172934 ops[2].tracking(cg),
...@@ -173765,7 +173766,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -173765,7 +173766,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173765 switch (ip.indexToKey(lazy_sym.ty)) {173766 switch (ip.indexToKey(lazy_sym.ty)) {
173766 .enum_type => {173767 .enum_type => {
173767 const enum_ty: Type = .fromInterned(lazy_sym.ty);173768 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
173770 const ret_regs = abi.getCAbiIntReturnRegs(.auto)[0..2].*;173771 const ret_regs = abi.getCAbiIntReturnRegs(.auto)[0..2].*;
173771 const ret_locks = cg.register_manager.lockRegsAssumeUnused(2, ret_regs);173772 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 {...@@ -173826,7 +173827,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173826 },173827 },
173827 .error_set_type => |error_set_type| {173828 .error_set_type => |error_set_type| {
173828 const err_ty: Type = .fromInterned(lazy_sym.ty);173829 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
173831 const ret_reg = abi.getCAbiIntReturnRegs(.auto)[0];173832 const ret_reg = abi.getCAbiIntReturnRegs(.auto)[0];
173832 const ret_lock = cg.register_manager.lockRegAssumeUnused(ret_reg);173833 const ret_lock = cg.register_manager.lockRegAssumeUnused(ret_reg);
...@@ -173871,7 +173872,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -173871,7 +173872,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void {
173871 },173872 },
173872 else => return cg.fail(173873 else => return cg.fail(
173873 "TODO implement {s} for {f}",173874 "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) },
173875 ),173876 ),
173876 }173877 }
173877 try cg.resetTemps(@fromBackingInt(@intCast(0)));173878 try cg.resetTemps(@fromBackingInt(@intCast(0)));
...@@ -174080,7 +174081,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex {...@@ -174080,7 +174081,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex {
174080 const val_ty = ptr_ty.childType(zcu);174081 const val_ty = ptr_ty.childType(zcu);
174081 return self.allocFrameIndex(.init(.{174082 return self.allocFrameIndex(.init(.{
174082 .size = std.math.cast(u32, val_ty.abiSize(zcu)) orelse {174083 .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)});
174084 },174085 },
174085 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),174086 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
174086 }));174087 }));
...@@ -174098,7 +174099,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok...@@ -174098,7 +174099,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok
174098 const pt = self.pt;174099 const pt = self.pt;
174099 const zcu = pt.zcu;174100 const zcu = pt.zcu;
174100 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {174101 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)});
174102 };174103 };
174103174104
174104 if (reg_ok) need_mem: {174105 if (reg_ok) need_mem: {
...@@ -174592,9 +174593,9 @@ fn store(...@@ -174592,9 +174593,9 @@ fn store(
174592}174593}
174593174594
174594fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {174595fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
174595 const pt = self.pt;174596 const zcu = self.pt.zcu;
174596 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));174597 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
174597 if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(pt) });174598 if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(zcu) });
174598 switch (dst_mcv) {174599 switch (dst_mcv) {
174599 .none,174600 .none,
174600 .unreach,174601 .unreach,
...@@ -176294,7 +176295,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {...@@ -176294,7 +176295,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176294 } });176295 } });
176295 dst.copyToMask(&src, cg) catch |err| switch (err) {176296 dst.copyToMask(&src, cg) catch |err| switch (err) {
176296 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{176297 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{
176297 arg_ty.fmt(pt),176298 arg_ty.fmt(zcu),
176298 dst.tracking(cg),176299 dst.tracking(cg),
176299 src.tracking(cg),176300 src.tracking(cg),
176300 }),176301 }),
...@@ -176515,7 +176516,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {...@@ -176515,7 +176516,7 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176515 var dst = try cg.tempInit(arg_ty, dst_arg);176516 var dst = try cg.tempInit(arg_ty, dst_arg);
176516 dst.copyToMask(&src, cg) catch |err| switch (err) {176517 dst.copyToMask(&src, cg) catch |err| switch (err) {
176517 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{176518 error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{
176518 arg_ty.fmt(pt),176519 arg_ty.fmt(zcu),
176519 dst.tracking(cg),176520 dst.tracking(cg),
176520 src.tracking(cg),176521 src.tracking(cg),
176521 }),176522 }),
...@@ -176640,9 +176641,10 @@ fn genCall(cg: *CodeGen, info: union(enum) {...@@ -176640,9 +176641,10 @@ fn genCall(cg: *CodeGen, info: union(enum) {
176640}176641}
176641176642
176642fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {176643fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176644 const zcu = cg.pt.zcu;
176643 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;176645 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);
176646 switch (cg.ret_mcv.short) {176648 switch (cg.ret_mcv.short) {
176647 .none => {},176649 .none => {},
176648 .register => |reg| {176650 .register => |reg| {
...@@ -176660,7 +176662,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {...@@ -176660,7 +176662,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176660 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);176662 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);
176661 dst.copyToMask(&src, cg) catch |err| switch (err) {176663 dst.copyToMask(&src, cg) catch |err| switch (err) {
176662 error.SelectFailed => return cg.fail("failed to select ret {f} {f} {f}", .{176664 error.SelectFailed => return cg.fail("failed to select ret {f} {f} {f}", .{
176663 ret_ty.fmt(cg.pt),176665 ret_ty.fmt(zcu),
176664 dst.tracking(cg),176666 dst.tracking(cg),
176665 src.tracking(cg),176667 src.tracking(cg),
176666 }),176668 }),
...@@ -176706,6 +176708,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {...@@ -176706,6 +176708,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void {
176706}176708}
176707176709
176708fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {176710fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
176711 const zcu = cg.pt.zcu;
176709 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;176712 const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op;
176710 switch (cg.ret_mcv.short) {176713 switch (cg.ret_mcv.short) {
176711 .none => {},176714 .none => {},
...@@ -176716,13 +176719,13 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {...@@ -176716,13 +176719,13 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void {
176716 => try cg.load(cg.ret_mcv.short, cg.typeOf(un_op), try cg.resolveInst(un_op)),176719 => try cg.load(cg.ret_mcv.short, cg.typeOf(un_op), try cg.resolveInst(un_op)),
176717 .register_mask => {176720 .register_mask => {
176718 var ptr = try cg.tempFromOperand(un_op, true);176721 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);
176720 var src = try ptr.load(ret_ty, .{}, cg);176723 var src = try ptr.load(ret_ty, .{}, cg);
176721 try ptr.die(cg);176724 try ptr.die(cg);
176722 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);176725 var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short);
176723 dst.copyToMask(&src, cg) catch |err| switch (err) {176726 dst.copyToMask(&src, cg) catch |err| switch (err) {
176724 error.SelectFailed => return cg.fail("failed to select ret_load {f} {f} {f}", .{176727 error.SelectFailed => return cg.fail("failed to select ret_load {f} {f} {f}", .{
176725 ret_ty.fmt(cg.pt),176728 ret_ty.fmt(zcu),
176726 dst.tracking(cg),176729 dst.tracking(cg),
176727 src.tracking(cg),176730 src.tracking(cg),
176728 }),176731 }),
...@@ -176839,7 +176842,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !?Mir.Inst.Index {...@@ -176839,7 +176842,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !?Mir.Inst.Index {
176839 return try self.asmJccReloc(.z, undefined);176842 return try self.asmJccReloc(.z, undefined);
176840 },176843 },
176841 else => return self.fail("TODO implement condbr when condition is {f} {s}", .{176844 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),
176843 }),176846 }),
176844 }176847 }
176845}176848}
...@@ -178721,7 +178724,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M...@@ -178721,7 +178724,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M
178721 },178724 },
178722 .ip, .cr, .dr => {},178725 .ip, .cr, .dr => {},
178723 }178726 }
178724 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(pt)});178727 return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(zcu)});
178725}178728}
178726178729
178727const CopyOptions = struct {178730const CopyOptions = struct {
...@@ -178729,7 +178732,7 @@ const CopyOptions = struct {...@@ -178729,7 +178732,7 @@ const CopyOptions = struct {
178729};178732};
178730178733
178731fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: CopyOptions) InnerError!void {178734fn 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
178734 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;178737 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
178735 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);178738 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...@@ -178790,7 +178793,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
178790 .register => |src_reg| switch (dst_regs[0].class()) {178793 .register => |src_reg| switch (dst_regs[0].class()) {
178791 .general_purpose => switch (src_reg.class()) {178794 .general_purpose => switch (src_reg.class()) {
178792 else => unreachable,178795 else => unreachable,
178793 .sse => if (ty.abiSize(pt.zcu) <= 16) {178796 .sse => if (ty.abiSize(zcu) <= 16) {
178794 if (self.hasFeature(.avx)) {178797 if (self.hasFeature(.avx)) {
178795 try self.asmRegisterRegister(.{ .v_q, .mov }, dst_regs[0].to64(), src_reg.to128());178798 try self.asmRegisterRegister(.{ .v_q, .mov }, dst_regs[0].to64(), src_reg.to128());
178796 try self.asmRegisterRegisterImmediate(.{ .vp_q, .extr }, dst_regs[1].to64(), src_reg.to128(), .u(1));178799 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...@@ -178865,7 +178868,7 @@ fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: C
178865 },178868 },
178866 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts),178869 .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts),
178867 else => return self.fail("TODO implement genCopy for {s} of {f}", .{178870 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),
178869 }),178872 }),
178870 };178873 };
178871 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);178874 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);
...@@ -179249,7 +179252,7 @@ fn genSetReg(...@@ -179249,7 +179252,7 @@ fn genSetReg(
179249 80 => null,179252 80 => null,
179250 else => unreachable,179253 else => unreachable,
179251 },179254 },
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)}),
179253 dst_alias,179256 dst_alias,
179254 registerAlias(src_reg, @intCast(cg.unalignedSize(ty))),179257 registerAlias(src_reg, @intCast(cg.unalignedSize(ty))),
179255 ),179258 ),
...@@ -179360,7 +179363,7 @@ fn genSetReg(...@@ -179360,7 +179363,7 @@ fn genSetReg(
179360 assert(!ty.optionalReprIsPayload(zcu));179363 assert(!ty.optionalReprIsPayload(zcu));
179361 break :first_ty opt_child;179364 break :first_ty opt_child;
179362 },179365 },
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) }),
179364 });179367 });
179365 const first_size: u31 = @intCast(first_ty.abiSize(zcu));179368 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
179366 const frame_size = std.math.ceilPowerOfTwoAssert(u32, abi_size);179369 const frame_size = std.math.ceilPowerOfTwoAssert(u32, abi_size);
...@@ -179769,7 +179772,7 @@ fn genSetMem(...@@ -179769,7 +179772,7 @@ fn genSetMem(
179769 );179772 );
179770 },179773 },
179771 else => return cg.fail("TODO implement genSetMem for {s} of {f}", .{179774 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),
179773 }),179776 }),
179774 },179777 },
179775 .register_offset => |reg_off| {179778 .register_offset => |reg_off| {
...@@ -180329,7 +180332,7 @@ fn atomicOp(...@@ -180329,7 +180332,7 @@ fn atomicOp(
180329 },180332 },
180330 else => unreachable,180333 else => unreachable,
180331 }) orelse return self.fail("TODO implement atomicOp of {s} for {f}", .{180334 }) 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),
180333 });180336 });
180334 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});180337 try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{});
180335 switch (mir_tag[0]) {180338 switch (mir_tag[0]) {
...@@ -180778,12 +180781,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180778,12 +180781,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
180778 else180781 else
180779 try self.copyToTmpRegister(pred_ty, pred_mcv)180782 try self.copyToTmpRegister(pred_ty, pred_mcv)
180780 else180783 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)}),
180782 else => unreachable,180785 else => unreachable,
180783 },180786 },
180784 .register_mask => |pred_reg_mask| {180787 .register_mask => |pred_reg_mask| {
180785 if (pred_reg_mask.info.scalar.bitSize(self.target) != 8 * elem_abi_size)180788 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
180788 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {180791 const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: {
180789 try self.register_manager.getKnownReg(.xmm0, null);180792 try self.register_manager.getKnownReg(.xmm0, null);
...@@ -180857,7 +180860,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -180857,7 +180860,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
180857 else180860 else
180858 null180861 null
180859 else180862 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)});
180861 if (has_avx) {180864 if (has_avx) {
180862 const rhs_alias = if (reuse_mcv.isRegister())180865 const rhs_alias = if (reuse_mcv.isRegister())
180863 registerAlias(reuse_mcv.getReg().?, abi_size)180866 registerAlias(reuse_mcv.getReg().?, abi_size)
...@@ -181010,7 +181013,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -181010,7 +181013,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181010 else => unreachable,181013 else => unreachable,
181011 }),181014 }),
181012 );181015 );
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)});
181014 const elem_bits: u16 = @intCast(elem_abi_size * 8);181017 const elem_bits: u16 = @intCast(elem_abi_size * 8);
181015 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {181018 if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) {
181016 const mask_len = elem_abi_size * vec_len;181019 const mask_len = elem_abi_size * vec_len;
...@@ -181039,7 +181042,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -181039,7 +181042,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181039 mask_alias,181042 mask_alias,
181040 mask_mem,181043 mask_mem,
181041 );181044 );
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)});
181043 {181046 {
181044 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);181047 const mask_elem_ty = try pt.intType(.unsigned, elem_bits);
181045 const mask_ty = try pt.vectorType(.{ .len = vec_len, .child = mask_elem_ty.toIntern() });181048 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 {...@@ -181159,7 +181162,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void {
181159 else => null,181162 else => null,
181160 },181163 },
181161 },181164 },
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)});
181163 if (has_avx) {181166 if (has_avx) {
181164 const rhs_alias = if (rhs_mcv.isRegister())181167 const rhs_alias = if (rhs_mcv.isRegister())
181165 registerAlias(rhs_mcv.getReg().?, abi_size)181168 registerAlias(rhs_mcv.getReg().?, abi_size)
...@@ -181466,7 +181469,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -181466,7 +181469,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
181466 assert(classes.len == 1);181469 assert(classes.len == 1);
181467 unreachable;181470 unreachable;
181468 },181471 },
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)}),
181470 }181473 }
181471181474
181472 if (unused) break :result .unreach;181475 if (unused) break :result .unreach;
...@@ -181512,7 +181515,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -181512,7 +181515,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void {
181512 try self.genCopy(.usize, next_arg_ptr, .{ .register = next_arg_ptr_reg }, .{});181515 try self.genCopy(.usize, next_arg_ptr, .{ .register = next_arg_ptr_reg }, .{});
181513 },181516 },
181514 .memory => unreachable,181517 .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)}),
181516 }181519 }
181517181520
181518 if (unused) break :result .unreach;181521 if (unused) break :result .unreach;
...@@ -182299,7 +182302,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty...@@ -182299,7 +182302,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty
182299 if (abi_size == parts_size) return parts;182302 if (abi_size == parts_size) return parts;
182300 if (classes[classes.len - 1] == .float and abi_size > parts_size and abi_size <= parts_size + 4) return parts;182303 if (classes[classes.len - 1] == .float and abi_size > parts_size and abi_size <= parts_size + 4) return parts;
182301 };182304 };
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) });
182303}182306}
182304182307
182305/// Truncates the value in the register in place.182308/// Truncates the value in the register in place.
...@@ -183183,6 +183186,7 @@ const Temp = struct {...@@ -183183,6 +183186,7 @@ const Temp = struct {
183183 }183186 }
183184183187
183185 fn store(ptr: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {183188 fn store(ptr: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {
183189 const zcu = cg.pt.zcu;
183186 const val_ty = val.typeOf(cg);183190 const val_ty = val.typeOf(cg);
183187 try ptr.toOffset(opts.disp, cg);183191 try ptr.toOffset(opts.disp, cg);
183188 while (try ptr.toLea(cg)) {}183192 while (try ptr.toLea(cg)) {}
...@@ -183194,7 +183198,7 @@ const Temp = struct {...@@ -183194,7 +183198,7 @@ const Temp = struct {
183194 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),183198 else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }),
183195 .undef => if (opts.safe) {183199 .undef => if (opts.safe) {
183196 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });183200 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) });
183198 try ptr.memset(&pat, &len, cg);183202 try ptr.memset(&pat, &len, cg);
183199 try pat.die(cg);183203 try pat.die(cg);
183200 try len.die(cg);183204 try len.die(cg);
...@@ -183248,12 +183252,12 @@ const Temp = struct {...@@ -183248,12 +183252,12 @@ const Temp = struct {
183248 .register_offset => |val_reg_off| switch (val_reg_off.off) {183252 .register_offset => |val_reg_off| switch (val_reg_off.off) {
183249 0 => try ptr.storeRegs(val_ty, &.{registerAlias(183253 0 => try ptr.storeRegs(val_ty, &.{registerAlias(
183250 val_reg_off.reg,183254 val_reg_off.reg,
183251 @intCast(val_ty.abiSize(cg.pt.zcu)),183255 @intCast(val_ty.abiSize(zcu)),
183252 )}, cg),183256 )}, cg),
183253 else => continue :val_to_gpr,183257 else => continue :val_to_gpr,
183254 },183258 },
183255 .register_overflow => |val_reg_ov| {183259 .register_overflow => |val_reg_ov| {
183256 const ip = &cg.pt.zcu.intern_pool;183260 const ip = &zcu.intern_pool;
183257 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {183261 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {
183258 .tuple_type => |tuple_type| {183262 .tuple_type => |tuple_type| {
183259 const tuple_field_types = tuple_type.types.get(ip);183263 const tuple_field_types = tuple_type.types.get(ip);
...@@ -183261,12 +183265,12 @@ const Temp = struct {...@@ -183261,12 +183265,12 @@ const Temp = struct {
183261 break :first_ty tuple_field_types[0];183265 break :first_ty tuple_field_types[0];
183262 },183266 },
183263 .opt_type => |opt_child| {183267 .opt_type => |opt_child| {
183264 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));183268 assert(!val_ty.optionalReprIsPayload(zcu));
183265 break :first_ty opt_child;183269 break :first_ty opt_child;
183266 },183270 },
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) }),
183268 });183272 });
183269 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));183273 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
183270 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);183274 try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg);
183271 try ptr.toOffset(first_size, cg);183275 try ptr.toOffset(first_size, cg);
183272 try cg.asmSetccMemory(183276 try cg.asmSetccMemory(
...@@ -183277,7 +183281,7 @@ const Temp = struct {...@@ -183277,7 +183281,7 @@ const Temp = struct {
183277 .lea_frame, .lea_nav, .lea_uav, .lea_lazy_sym => continue :val_to_gpr,183281 .lea_frame, .lea_nav, .lea_uav, .lea_lazy_sym => continue :val_to_gpr,
183278 .memory, .indirect, .load_frame, .load_nav, .load_uav, .load_lazy_sym => {183282 .memory, .indirect, .load_frame, .load_nav, .load_uav, .load_lazy_sym => {
183279 var val_ptr = try cg.tempInit(.usize, val_mcv.address());183283 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);
183281 try val_ptr.die(cg);183285 try val_ptr.die(cg);
183282 },183286 },
183283 }183287 }
...@@ -183325,6 +183329,7 @@ const Temp = struct {...@@ -183325,6 +183329,7 @@ const Temp = struct {
183325 }183329 }
183326183330
183327 fn write(dst: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {183331 fn write(dst: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void {
183332 const zcu = cg.pt.zcu;
183328 const val_ty = val.typeOf(cg);183333 const val_ty = val.typeOf(cg);
183329 while (try dst.toBase(false, cg)) {}183334 while (try dst.toBase(false, cg)) {}
183330 val_to_gpr: while (true) : (while (try dst.toBase(false, cg) or183335 val_to_gpr: while (true) : (while (try dst.toBase(false, cg) or
...@@ -183337,7 +183342,7 @@ const Temp = struct {...@@ -183337,7 +183342,7 @@ const Temp = struct {
183337 .undef => if (opts.safe) {183342 .undef => if (opts.safe) {
183338 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));183343 var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
183339 var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa });183344 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) });
183341 try dst_ptr.memset(&pat, &len, cg);183346 try dst_ptr.memset(&pat, &len, cg);
183342 try dst_ptr.die(cg);183347 try dst_ptr.die(cg);
183343 try pat.die(cg);183348 try pat.die(cg);
...@@ -183364,7 +183369,7 @@ const Temp = struct {...@@ -183364,7 +183369,7 @@ const Temp = struct {
183364 ),183369 ),
183365 .register => |val_reg| try dst.writeReg(opts.disp, val_ty, registerAlias(183370 .register => |val_reg| try dst.writeReg(opts.disp, val_ty, registerAlias(
183366 val_reg,183371 val_reg,
183367 @intCast(val_ty.abiSize(cg.pt.zcu)),183372 @intCast(val_ty.abiSize(zcu)),
183368 ), cg),183373 ), cg),
183369 inline .register_pair,183374 inline .register_pair,
183370 .register_triple,183375 .register_triple,
...@@ -183373,12 +183378,12 @@ const Temp = struct {...@@ -183373,12 +183378,12 @@ const Temp = struct {
183373 .register_offset => |val_reg_off| switch (val_reg_off.off) {183378 .register_offset => |val_reg_off| switch (val_reg_off.off) {
183374 0 => try dst.writeReg(opts.disp, val_ty, registerAlias(183379 0 => try dst.writeReg(opts.disp, val_ty, registerAlias(
183375 val_reg_off.reg,183380 val_reg_off.reg,
183376 @intCast(val_ty.abiSize(cg.pt.zcu)),183381 @intCast(val_ty.abiSize(zcu)),
183377 ), cg),183382 ), cg),
183378 else => continue :val_to_gpr,183383 else => continue :val_to_gpr,
183379 },183384 },
183380 .register_overflow => |val_reg_ov| {183385 .register_overflow => |val_reg_ov| {
183381 const ip = &cg.pt.zcu.intern_pool;183386 const ip = &zcu.intern_pool;
183382 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {183387 const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) {
183383 .tuple_type => |tuple_type| {183388 .tuple_type => |tuple_type| {
183384 const tuple_field_types = tuple_type.types.get(ip);183389 const tuple_field_types = tuple_type.types.get(ip);
...@@ -183386,12 +183391,12 @@ const Temp = struct {...@@ -183386,12 +183391,12 @@ const Temp = struct {
183386 break :first_ty tuple_field_types[0];183391 break :first_ty tuple_field_types[0];
183387 },183392 },
183388 .opt_type => |opt_child| {183393 .opt_type => |opt_child| {
183389 assert(!val_ty.optionalReprIsPayload(cg.pt.zcu));183394 assert(!val_ty.optionalReprIsPayload(zcu));
183390 break :first_ty opt_child;183395 break :first_ty opt_child;
183391 },183396 },
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) }),
183393 });183398 });
183394 const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu));183399 const first_size: u31 = @intCast(first_ty.abiSize(zcu));
183395 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);183400 try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg);
183396 try cg.asmSetccMemory(183401 try cg.asmSetccMemory(
183397 val_reg_ov.eflags,183402 val_reg_ov.eflags,
...@@ -183406,7 +183411,7 @@ const Temp = struct {...@@ -183406,7 +183411,7 @@ const Temp = struct {
183406 var dst_ptr =183411 var dst_ptr =
183407 try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));183412 try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp));
183408 var val_ptr = try cg.tempInit(.usize, val_mcv.address());183413 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);
183410 try dst_ptr.die(cg);183415 try dst_ptr.die(cg);
183411 try val_ptr.die(cg);183416 try val_ptr.die(cg);
183412 },183417 },
...@@ -183444,7 +183449,7 @@ const Temp = struct {...@@ -183444,7 +183449,7 @@ const Temp = struct {
183444 assert(src_regs.len == @divCeil(int_info.bits, 64));183449 assert(src_regs.len == @divCeil(int_info.bits, 64));
183445 break :part_ty .u64;183450 break :part_ty .u64;
183446 } else part_ty: switch (ip.indexToKey(src_ty.toIntern())) {183451 } 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) }),
183448 .ptr_type => |ptr_info| {183453 .ptr_type => |ptr_info| {
183449 assert(ptr_info.flags.size == .slice);183454 assert(ptr_info.flags.size == .slice);
183450 assert(src_regs.len == 2);183455 assert(src_regs.len == 2);
...@@ -183463,7 +183468,7 @@ const Temp = struct {...@@ -183463,7 +183468,7 @@ const Temp = struct {
183463 }),183468 }),
183464 },183469 },
183465 .opt_type => |opt_child| switch (ip.indexToKey(opt_child)) {183470 .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) }),
183467 .ptr_type => |ptr_info| {183472 .ptr_type => |ptr_info| {
183468 assert(ptr_info.flags.size == .slice);183473 assert(ptr_info.flags.size == .slice);
183469 assert(src_regs.len == 2);183474 assert(src_regs.len == 2);
...@@ -189637,7 +189642,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {...@@ -189637,7 +189642,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void {
189637 any_valid = true;189642 any_valid = true;
189638 tracking_log.err("failed to kill {f}: {f}", .{189643 tracking_log.err("failed to kill {f}: {f}", .{
189639 temp.toIndex(),189644 temp.toIndex(),
189640 cg.temp_type[temp_index].fmt(cg.pt),189645 cg.temp_type[temp_index].fmt(cg.pt.zcu),
189641 });189646 });
189642 }189647 }
189643 cg.temp_type[temp_index] = undefined;189648 cg.temp_type[temp_index] = undefined;
src/link/Coff.zig+22-39
...@@ -5766,7 +5766,7 @@ fn flushImplib(...@@ -5766,7 +5766,7 @@ fn flushImplib(
5766 try file_writer.interface.flush();5766 try file_writer.interface.flush();
5767}5767}
57685768
5769fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {5769fn reportUndefs(coff: *Coff) !void {
5770 const comp = coff.base.comp;5770 const comp = coff.base.comp;
5771 const gpa = comp.gpa;5771 const gpa = comp.gpa;
5772 const max_notes = 4;5772 const max_notes = 4;
...@@ -5887,14 +5887,8 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {...@@ -5887,14 +5887,8 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
5887 const ip = &comp.zcu.?.intern_pool;5887 const ip = &comp.zcu.?.intern_pool;
5888 break :format ip.getNav(val.navIndex(coff)).fqn.fmt(ip);5888 break :format ip.getNav(val.navIndex(coff)).fqn.fmt(ip);
5889 },5889 },
5890 .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(.{5890 .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(coff.base.comp.zcu.?),
5891 .zcu = coff.base.comp.zcu.?,5891 inline .lazy_code, .lazy_const_data => Type.fromInterned(val.lazySymbol(coff).ty).fmt(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 }),
5898 else => unreachable,5892 else => unreachable,
5899 },5893 },
5900 });5894 });
...@@ -5927,7 +5921,7 @@ pub fn flush(...@@ -5927,7 +5921,7 @@ pub fn flush(
59275921
5928 const comp = coff.base.comp;5922 const comp = coff.base.comp;
59295923
5930 while (try coff.resolve(tid)) {}5924 while (try coff.resolve()) {}
5931 while (try coff.idle(tid)) {}5925 while (try coff.idle(tid)) {}
59325926
5933 // This has to occur after all other flushMoved / flushResized have resolved,5927 // This has to occur after all other flushMoved / flushResized have resolved,
...@@ -5951,7 +5945,7 @@ pub fn flush(...@@ -5951,7 +5945,7 @@ pub fn flush(
5951 while (try coff.idle(tid)) {}5945 while (try coff.idle(tid)) {}
59525946
5953 if (coff.isImage())5947 if (coff.isImage())
5954 try coff.reportUndefs(tid);5948 try coff.reportUndefs();
59555949
5956 if (comp.emit_implib) |implib_file|5950 if (comp.emit_implib) |implib_file|
5957 coff.flushImplib(implib_file) catch |err|5951 coff.flushImplib(implib_file) catch |err|
...@@ -5970,7 +5964,7 @@ pub fn flush(...@@ -5970,7 +5964,7 @@ pub fn flush(
5970/// Runs a single "resolution" task.5964/// Runs a single "resolution" task.
5971/// These are tasks that need to modify the node structure in some way.5965/// These are tasks that need to modify the node structure in some way.
5972/// They must run in a defined order with respect to linker tasks.5966/// 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 {
5974 const comp = coff.base.comp;5968 const comp = coff.base.comp;
5975 task: {5969 task: {
5976 while (coff.section_merge_pending_index < coff.section_merges.count()) {5970 while (coff.section_merge_pending_index < coff.section_merges.count()) {
...@@ -6046,7 +6040,6 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6046,7 +6040,6 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6046 const si = coff.symbol_table.symbols.keys()[coff.symbol_table.pending_symbol_index];6040 const si = coff.symbol_table.symbols.keys()[coff.symbol_table.pending_symbol_index];
6047 const sym = si.get(coff);6041 const sym = si.get(coff);
6048 const sub_prog_node = coff.idleProgNode(6042 const sub_prog_node = coff.idleProgNode(
6049 tid,
6050 coff.symbol_prog_node,6043 coff.symbol_prog_node,
6051 if (sym.ni.unwrap()) |sym_ni|6044 if (sym.ni.unwrap()) |sym_ni|
6052 coff.getNode(sym_ni)6045 coff.getNode(sym_ni)
...@@ -6077,6 +6070,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6077,6 +6070,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6077}6070}
60786071
6079pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {6072pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6073 _ = tid;
6080 // Idle tasks should not modify create / modify nodes, otherwise the output is not reproducible.6074 // Idle tasks should not modify create / modify nodes, otherwise the output is not reproducible.
6081 coff.mf.nodes_lock.lock();6075 coff.mf.nodes_lock.lock();
6082 defer coff.mf.nodes_lock.unlock();6076 defer coff.mf.nodes_lock.unlock();
...@@ -6087,7 +6081,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6087,7 +6081,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6087 if (coff.input_section_pending_index < coff.input_sections.items.len) {6081 if (coff.input_section_pending_index < coff.input_sections.items.len) {
6088 const isi: Node.InputSection.Index = @fromBackingInt(@intCast(coff.input_section_pending_index));6082 const isi: Node.InputSection.Index = @fromBackingInt(@intCast(coff.input_section_pending_index));
6089 coff.input_section_pending_index += 1;6083 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)));
6091 defer sub_prog_node.end();6085 defer sub_prog_node.end();
6092 coff.flushInputSection(isi) catch |err| switch (err) {6086 coff.flushInputSection(isi) catch |err| switch (err) {
6093 else => |e| {6087 else => |e| {
...@@ -6112,7 +6106,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6112,7 +6106,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6112 const clean_next_moved = ni.cleanNextMoved(&coff.mf);6106 const clean_next_moved = ni.cleanNextMoved(&coff.mf);
6113 if (!clean_moved and !clean_resized and !clean_next_moved) continue;6107 if (!clean_moved and !clean_resized and !clean_next_moved) continue;
6114 const sub_prog_node =6108 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));
6116 defer sub_prog_node.end();6110 defer sub_prog_node.end();
6117 if (clean_moved) try coff.flushMoved(ni);6111 if (clean_moved) try coff.flushMoved(ni);
6118 if (clean_resized) try coff.flushResized(ni);6112 if (clean_resized) try coff.flushResized(ni);
...@@ -6120,7 +6114,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6120,7 +6114,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6120 }6114 }
6121 while (coff.pending_members.pop()) |pending_mi| {6115 while (coff.pending_members.pop()) |pending_mi| {
6122 const sub_prog_node = coff.idleProgNode(6116 const sub_prog_node = coff.idleProgNode(
6123 tid,
6124 coff.symbol_prog_node,6117 coff.symbol_prog_node,
6125 coff.getNode(pending_mi.key.get(coff).content_ni),6118 coff.getNode(pending_mi.key.get(coff).content_ni),
6126 );6119 );
...@@ -6131,7 +6124,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6131,7 +6124,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6131 if (coff.exports_complete and coff.export_table.pending_sort) {6124 if (coff.exports_complete and coff.export_table.pending_sort) {
6132 defer coff.export_table.pending_sort = false;6125 defer coff.export_table.pending_sort = false;
6133 const sub_prog_node = coff.idleProgNode(6126 const sub_prog_node = coff.idleProgNode(
6134 tid,
6135 coff.synth_prog_node,6127 coff.synth_prog_node,
6136 coff.getNode(coff.export_table.ni),6128 coff.getNode(coff.export_table.ni),
6137 );6129 );
...@@ -6150,7 +6142,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6150,7 +6142,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
61506142
6151fn idleProgNode(6143fn idleProgNode(
6152 coff: *Coff,6144 coff: *Coff,
6153 tid: Zcu.PerThread.Id,
6154 prog_node: std.Progress.Node,6145 prog_node: std.Progress.Node,
6155 node: Node,6146 node: Node,
6156) std.Progress.Node {6147) std.Progress.Node {
...@@ -6173,10 +6164,7 @@ fn idleProgNode(...@@ -6173,10 +6164,7 @@ fn idleProgNode(
6173 break :name ip.getNav(nmi.navIndex(coff)).fqn.toSlice(ip);6164 break :name ip.getNav(nmi.navIndex(coff)).fqn.toSlice(ip);
6174 },6165 },
6175 .uav => |umi| std.mem.print(&name, "{f}", .{6166 .uav => |umi| std.mem.print(&name, "{f}", .{
6176 Value.fromInterned(umi.uavValue(coff)).fmtValue(.{6167 Value.fromInterned(umi.uavValue(coff)).fmtValue(coff.base.comp.zcu.?),
6177 .zcu = coff.base.comp.zcu.?,
6178 .tid = tid,
6179 }),
6180 }) catch &name,6168 }) catch &name,
6181 .archive_member => |mi| &mi.get(coff).headerPtr(coff).name,6169 .archive_member => |mi| &mi.get(coff).headerPtr(coff).name,
6182 }, 0);6170 }, 0);
...@@ -6185,7 +6173,7 @@ fn idleProgNode(...@@ -6185,7 +6173,7 @@ fn idleProgNode(
6185fn genPending(coff: *Coff, pt: Zcu.PerThread) Error!void {6173fn genPending(coff: *Coff, pt: Zcu.PerThread) Error!void {
6186 const comp = pt.zcu.comp;6174 const comp = pt.zcu.comp;
6187 while (coff.pending_uavs.pop()) |pending_uav| {6175 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 });
6189 defer sub_prog_node.end();6177 defer sub_prog_node.end();
6190 coff.genUav(pt, pending_uav.key, pending_uav.value.alignment) catch |err| switch (err) {6178 coff.genUav(pt, pending_uav.key, pending_uav.value.alignment) catch |err| switch (err) {
6191 else => |e| return e,6179 else => |e| return e,
...@@ -6845,7 +6833,7 @@ fn genLazy(coff: *Coff, pt: Zcu.PerThread, lmr: Node.LazyMapRef) !void {...@@ -6845,7 +6833,7 @@ fn genLazy(coff: *Coff, pt: Zcu.PerThread, lmr: Node.LazyMapRef) !void {
6845 const sub_prog_node = coff.synth_prog_node.start(6833 const sub_prog_node = coff.synth_prog_node.start(
6846 std.mem.print(&name, "lazy {s} for {f}", .{6834 std.mem.print(&name, "lazy {s} for {f}", .{
6847 kind,6835 kind,
6848 Type.fromInterned(lazy.ty).fmt(pt),6836 Type.fromInterned(lazy.ty).fmt(coff.base.comp.zcu.?),
6849 }) catch &name,6837 }) catch &name,
6850 0,6838 0,
6851 );6839 );
...@@ -7461,14 +7449,14 @@ fn updateExportInner(...@@ -7461,14 +7449,14 @@ fn updateExportInner(
7461 switch (exp.exported) {7449 switch (exp.exported) {
7462 .nav => |nav| log.debug("updateExports({f}) = {d}", .{ ip.getNav(nav).fqn.fmt(ip), exported_si }),7450 .nav => |nav| log.debug("updateExports({f}) = {d}", .{ ip.getNav(nav).fqn.fmt(ip), exported_si }),
7463 .uav => |uav| log.debug("updateExports(@as({f}, {f})) = {d}", .{7451 .uav => |uav| log.debug("updateExports(@as({f}, {f})) = {d}", .{
7464 Type.fromInterned(ip.typeOf(uav)).fmt(pt),7452 Type.fromInterned(ip.typeOf(uav)).fmt(zcu),
7465 Value.fromInterned(uav).fmtValue(pt),7453 Value.fromInterned(uav).fmtValue(zcu),
7466 exported_si,7454 exported_si,
7467 }),7455 }),
7468 }7456 }
74697457
7470 try coff.genPending(pt);7458 try coff.genPending(pt);
7471 while (try coff.resolve(pt.tid)) {}7459 while (try coff.resolve()) {}
7472 while (try coff.idle(pt.tid)) {}7460 while (try coff.idle(pt.tid)) {}
74737461
7474 const machine = coff.targetLoad(&coff.headerPtr().machine);7462 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...@@ -7627,7 +7615,7 @@ pub fn dump(coff: *Coff, w: *Io.Writer, tid: Zcu.PerThread.Id) Io.Writer.Error!l
7627 try coff.printSection(w, name, sec.si);7615 try coff.printSection(w, name, sec.si);
7628 try w.writeAll("Symbol table:\n");7616 try w.writeAll("Symbol table:\n");
7629 for (1..coff.symbols.items.len) |si|7617 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
7632 return .enabled;7620 return .enabled;
7633 }7621 }
...@@ -7648,7 +7636,6 @@ fn printSection(coff: *Coff, w: *Io.Writer, name: String, si: Symbol.Index) Io.W...@@ -7648,7 +7636,6 @@ fn printSection(coff: *Coff, w: *Io.Writer, name: String, si: Symbol.Index) Io.W
7648fn printSymbol(7636fn printSymbol(
7649 coff: *Coff,7637 coff: *Coff,
7650 w: *Io.Writer,7638 w: *Io.Writer,
7651 tid: Zcu.PerThread.Id,
7652 si: Symbol.Index,7639 si: Symbol.Index,
7653) Io.Writer.Error!void {7640) Io.Writer.Error!void {
7654 const sym = si.get(coff);7641 const sym = si.get(coff);
...@@ -7687,7 +7674,7 @@ fn printSymbol(...@@ -7687,7 +7674,7 @@ fn printSymbol(
7687 try w.print("G {f}\n", .{fmtGlobalName(coff, sym.gmi)});7674 try w.print("G {f}\n", .{fmtGlobalName(coff, sym.gmi)});
7688 } else {7675 } else {
7689 try w.writeAll("| ");7676 try w.writeAll("| ");
7690 try coff.printNodeName(w, tid, coff.getNode(sym.ni.unwrap().?));7677 try coff.printNodeName(w, coff.getNode(sym.ni.unwrap().?));
7691 if (sym.flags.extra_tag == .isli)7678 if (sym.flags.extra_tag == .isli)
7692 try w.print(" | {s}", .{sym.extra.isli.name(coff).toSlice(coff)});7679 try w.print(" | {s}", .{sym.extra.isli.name(coff).toSlice(coff)});
7693 try w.writeByte('\n');7680 try w.writeByte('\n');
...@@ -7712,7 +7699,6 @@ fn globalNameEscape(data: FmtGlobalName, w: *std.Io.Writer) std.Io.Writer.Error!...@@ -7712,7 +7699,6 @@ fn globalNameEscape(data: FmtGlobalName, w: *std.Io.Writer) std.Io.Writer.Error!
7712fn printNodeName(7699fn printNodeName(
7713 coff: *Coff,7700 coff: *Coff,
7714 w: *std.Io.Writer,7701 w: *std.Io.Writer,
7715 tid: Zcu.PerThread.Id,
7716 node: Node,7702 node: Node,
7717) Io.Writer.Error!void {7703) Io.Writer.Error!void {
7718 switch (node) {7704 switch (node) {
...@@ -7754,7 +7740,7 @@ fn printNodeName(...@@ -7754,7 +7740,7 @@ fn printNodeName(
7754 const ip = &zcu.intern_pool;7740 const ip = &zcu.intern_pool;
7755 const nav = ip.getNav(nmi.navIndex(coff));7741 const nav = ip.getNav(nmi.navIndex(coff));
7756 try w.print("({f}, {f})", .{7742 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),
7758 nav.fqn.fmt(ip),7744 nav.fqn.fmt(ip),
7759 });7745 });
7760 },7746 },
...@@ -7762,15 +7748,12 @@ fn printNodeName(...@@ -7762,15 +7748,12 @@ fn printNodeName(
7762 const zcu = coff.base.comp.zcu.?;7748 const zcu = coff.base.comp.zcu.?;
7763 const val: Value = .fromInterned(umi.uavValue(coff));7749 const val: Value = .fromInterned(umi.uavValue(coff));
7764 try w.print("({f}, {f})", .{7750 try w.print("({f}, {f})", .{
7765 val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }),7751 val.typeOf(zcu).fmt(zcu),
7766 val.fmtValue(.{ .zcu = zcu, .tid = tid }),7752 val.fmtValue(zcu),
7767 });7753 });
7768 },7754 },
7769 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{7755 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{
7770 Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(.{7756 Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(coff.base.comp.zcu.?),
7771 .zcu = coff.base.comp.zcu.?,
7772 .tid = tid,
7773 }),
7774 }),7757 }),
7775 .builtin => |si| {7758 .builtin => |si| {
7776 const sym = si.get(coff);7759 const sym = si.get(coff);
...@@ -7789,7 +7772,7 @@ pub fn printNode(...@@ -7789,7 +7772,7 @@ pub fn printNode(
7789 const node = coff.getNode(ni);7772 const node = coff.getNode(ni);
7790 try w.splatByteAll(' ', indent);7773 try w.splatByteAll(' ', indent);
7791 try w.writeAll(@tagName(node));7774 try w.writeAll(@tagName(node));
7792 try coff.printNodeName(w, tid, node);7775 try coff.printNodeName(w, node);
7793 {7776 {
7794 const mf_node = &coff.mf.nodes.items[@backingInt(ni)];7777 const mf_node = &coff.mf.nodes.items[@backingInt(ni)];
7795 const off, const size = mf_node.location().resolve(&coff.mf);7778 const off, const size = mf_node.location().resolve(&coff.mf);
src/link/Dwarf.zig+24-23
...@@ -1036,7 +1036,7 @@ const Entry = struct {...@@ -1036,7 +1036,7 @@ const Entry = struct {
1036 const val_unit, const val_entry = unit_and_entry;1036 const val_unit, const val_entry = unit_and_entry;
1037 if (sec.getUnit(val_unit) == unit and unit.getEntry(val_entry) == entry)1037 if (sec.getUnit(val_unit) == unit and unit.getEntry(val_entry) == entry)
1038 log.err("missing Value({f}({d}))", .{1038 log.err("missing Value({f}({d}))", .{
1039 Value.fromInterned(val).fmtValue(.{ .tid = .main, .zcu = zcu }),1039 Value.fromInterned(val).fmtValue(zcu),
1040 @backingInt(val),1040 @backingInt(val),
1041 });1041 });
1042 }1042 }
...@@ -2120,9 +2120,10 @@ pub const WipNav = struct {...@@ -2120,9 +2120,10 @@ pub const WipNav = struct {
2120 wip_nav: *WipNav,2120 wip_nav: *WipNav,
2121 val: Value,2121 val: Value,
2122 ) (UpdateError || Writer.Error)!void {2122 ) (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);
2124 const diw = &wip_nav.debug_info.writer;2125 const diw = &wip_nav.debug_info.writer;
2125 const size = ty.abiSize(wip_nav.pt.zcu);2126 const size = ty.abiSize(zcu);
2126 try diw.writeUleb128(size);2127 try diw.writeUleb128(size);
2127 if (size == 0) return;2128 if (size == 0) return;
2128 const old_end = diw.end;2129 const old_end = diw.end;
...@@ -2135,7 +2136,7 @@ pub const WipNav = struct {...@@ -2135,7 +2136,7 @@ pub const WipNav = struct {
2135 );2136 );
2136 if (old_end + size != diw.end) {2137 if (old_end + size != diw.end) {
2137 std.debug.print("{f} [{}]: {} != {}\n", .{2138 std.debug.print("{f} [{}]: {} != {}\n", .{
2138 ty.fmt(wip_nav.pt),2139 ty.fmt(zcu),
2139 ty.toIntern(),2140 ty.toIntern(),
2140 size,2141 size,
2141 diw.end - old_end,2142 diw.end - old_end,
...@@ -3340,8 +3341,8 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde...@@ -3340,8 +3341,8 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde
3340 switch (value_index) {3341 switch (value_index) {
3341 .generic_poison_type => log.debug("updateValueIncomplete(anytype)", .{}),3342 .generic_poison_type => log.debug("updateValueIncomplete(anytype)", .{}),
3342 else => log.debug("updateValueIncomplete(@as({f}, {f}))", .{3343 else => log.debug("updateValueIncomplete(@as({f}, {f}))", .{
3343 val.typeOf(zcu).fmt(pt),3344 val.typeOf(zcu).fmt(zcu),
3344 val.fmtValue(pt),3345 val.fmtValue(zcu),
3345 }),3346 }),
3346 }3347 }
33473348
...@@ -3435,7 +3436,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde...@@ -3435,7 +3436,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde
3435 else => |val_key| switch (val_key.typeOf()) {3436 else => |val_key| switch (val_key.typeOf()) {
3436 .type_type => {3437 .type_type => {
3437 try wip_nav.abbrevCode(.generated_empty_struct_type);3438 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)});
3439 try wip_nav.debug_info.writer.writeByte(@intFromBool(true));3440 try wip_nav.debug_info.writer.writeByte(@intFromBool(true));
3440 },3441 },
3441 else => |ty| {3442 else => |ty| {
...@@ -3509,8 +3510,8 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3509,8 +3510,8 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3509 switch (value_index) {3510 switch (value_index) {
3510 .generic_poison_type => log.debug("updateValue(anytype)", .{}),3511 .generic_poison_type => log.debug("updateValue(anytype)", .{}),
3511 else => log.debug("updateValue(@as({f}, {f}))", .{3512 else => log.debug("updateValue(@as({f}, {f}))", .{
3512 val.typeOf(zcu).fmt(pt),3513 val.typeOf(zcu).fmt(zcu),
3513 val.fmtValue(pt),3514 val.fmtValue(zcu),
3514 }),3515 }),
3515 }3516 }
35163517
...@@ -3551,7 +3552,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3551,7 +3552,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
35513552
3552 .int_type => |int_type| {3553 .int_type => |int_type| {
3553 try wip_nav.abbrevCode(.numeric_type);3554 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)});
3555 try diw.writeByte(switch (int_type.signedness) {3556 try diw.writeByte(switch (int_type.signedness) {
3556 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),3557 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),
3557 });3558 });
...@@ -3566,7 +3567,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3566,7 +3567,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3566 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,3567 .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type,
3567 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,3568 else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type,
3568 });3569 });
3569 try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)});3570 try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)});
3570 if (ptr_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(ptr_type.sentinel));3571 if (ptr_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(ptr_type.sentinel));
3571 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);3572 if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a);
3572 try diw.writeByte(@backingInt(ptr_type.flags.address_space));3573 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...@@ -3592,7 +3593,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3592 },3593 },
3593 .slice => {3594 .slice => {
3594 try wip_nav.abbrevCode(.generated_struct_type);3595 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)});
3596 try diw.writeUleb128(val.toType().abiSize(zcu));3597 try diw.writeUleb128(val.toType().abiSize(zcu));
3597 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);3598 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
3598 try wip_nav.abbrevCode(.generated_field);3599 try wip_nav.abbrevCode(.generated_field);
...@@ -3611,7 +3612,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3611,7 +3612,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3611 .array_type => |array_type| {3612 .array_type => |array_type| {
3612 const array_child_type: Type = .fromInterned(array_type.child);3613 const array_child_type: Type = .fromInterned(array_type.child);
3613 try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type);3614 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)});
3615 if (array_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(array_type.sentinel));3616 if (array_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(array_type.sentinel));
3616 try wip_nav.refType(array_child_type);3617 try wip_nav.refType(array_child_type);
3617 try wip_nav.abbrevCode(.array_len);3618 try wip_nav.abbrevCode(.array_len);
...@@ -3621,7 +3622,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3621,7 +3622,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3621 },3622 },
3622 .vector_type => |vector_type| {3623 .vector_type => |vector_type| {
3623 try wip_nav.abbrevCode(.vector_type);3624 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)});
3625 try wip_nav.refType(.fromInterned(vector_type.child));3626 try wip_nav.refType(.fromInterned(vector_type.child));
3626 try wip_nav.abbrevCode(.array_len);3627 try wip_nav.abbrevCode(.array_len);
3627 try wip_nav.refType(.usize);3628 try wip_nav.refType(.usize);
...@@ -3632,7 +3633,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3632,7 +3633,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3632 const opt_child_type: Type = .fromInterned(opt_child_type_index);3633 const opt_child_type: Type = .fromInterned(opt_child_type_index);
3633 const opt_repr = optRepr(opt_child_type, zcu);3634 const opt_repr = optRepr(opt_child_type, zcu);
3634 try wip_nav.abbrevCode(.generated_union_type);3635 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)});
3636 try diw.writeUleb128(val.toType().abiSize(zcu));3637 try diw.writeUleb128(val.toType().abiSize(zcu));
3637 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);3638 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
3638 switch (opt_repr) {3639 switch (opt_repr) {
...@@ -3713,7 +3714,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3713,7 +3714,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3713 };3714 };
37143715
3715 try wip_nav.abbrevCode(.generated_union_type);3716 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)});
3717 if (error_union_type.error_set_type != .generic_poison_type and3718 if (error_union_type.error_set_type != .generic_poison_type and
3718 error_union_type.payload_type != .generic_poison_type)3719 error_union_type.payload_type != .generic_poison_type)
3719 {3720 {
...@@ -3785,7 +3786,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3785,7 +3786,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3785 .bool,3786 .bool,
3786 => {3787 => {
3787 try wip_nav.abbrevCode(.numeric_type);3788 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)});
3789 try diw.writeByte(if (value_index == .bool_type)3790 try diw.writeByte(if (value_index == .bool_type)
3790 DW.ATE.boolean3791 DW.ATE.boolean
3791 else if (val.toType().isRuntimeFloat())3792 else if (val.toType().isRuntimeFloat())
...@@ -3815,18 +3816,18 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -3815,18 +3816,18 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
3815 .enum_literal,3816 .enum_literal,
3816 => {3817 => {
3817 try wip_nav.abbrevCode(.void_type);3818 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)});
3819 },3820 },
3820 .anyerror => unreachable, // already did early return above3821 .anyerror => unreachable, // already did early return above
3821 .adhoc_inferred_error_set => unreachable,3822 .adhoc_inferred_error_set => unreachable,
3822 },3823 },
3823 .tuple_type => |tuple_type| if (tuple_type.types.len == 0) {3824 .tuple_type => |tuple_type| if (tuple_type.types.len == 0) {
3824 try wip_nav.abbrevCode(.generated_empty_struct_type);3825 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)});
3826 try diw.writeByte(@intFromBool(false));3827 try diw.writeByte(@intFromBool(false));
3827 } else {3828 } else {
3828 try wip_nav.abbrevCode(.generated_struct_type);3829 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)});
3830 try diw.writeUleb128(val.toType().abiSize(zcu));3831 try diw.writeUleb128(val.toType().abiSize(zcu));
3831 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);3832 try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?);
3832 var field_byte_offset: u64 = 0;3833 var field_byte_offset: u64 = 0;
...@@ -4148,7 +4149,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4148,7 +4149,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4148 .func_type => |func_type| {4149 .func_type => |func_type| {
4149 const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args;4150 const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args;
4150 try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type);4151 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)});
4152 const cc: DW.CC = cc: {4153 const cc: DW.CC = cc: {
4153 if (zcu.getTarget().cCallingConvention()) |cc| {4154 if (zcu.getTarget().cCallingConvention()) |cc| {
4154 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {4155 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...@@ -4231,7 +4232,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4231 },4232 },
4232 .error_set_type => |error_set_type| {4233 .error_set_type => |error_set_type| {
4233 try wip_nav.abbrevCode(if (error_set_type.names.len == 0) .generated_empty_enum_type else .generated_enum_type);4234 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)});
4235 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{4236 try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{
4236 .signedness = .unsigned,4237 .signedness = .unsigned,
4237 .bits = zcu.errorSetBits(),4238 .bits = zcu.errorSetBits(),
...@@ -4247,7 +4248,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co...@@ -4247,7 +4248,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
4247 },4248 },
4248 .inferred_error_set_type => |func| {4249 .inferred_error_set_type => |func| {
4249 try wip_nav.abbrevCode(.inferred_error_set_type);4250 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)});
4251 try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {4252 try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) {
4252 .none => .anyerror_type,4253 .none => .anyerror_type,
4253 else => |ies| ies,4254 else => |ies| ies,
src/link/Dwarf2.zig+18-17
...@@ -2516,7 +2516,7 @@ pub fn updateConst(...@@ -2516,7 +2516,7 @@ pub fn updateConst(
2516) link.Error!void {2516) link.Error!void {
2517 switch (val) {2517 switch (val) {
2518 .generic_poison_type => log.debug("updateConst(anytype)", .{}),2518 .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)}),
2520 }2520 }
2521 dwarf.updateConstInner(pt, di_nw, val) catch |err| switch (err) {2521 dwarf.updateConstInner(pt, di_nw, val) catch |err| switch (err) {
2522 else => |e| return e,2522 else => |e| return e,
...@@ -2538,7 +2538,7 @@ fn updateConstInner(...@@ -2538,7 +2538,7 @@ fn updateConstInner(
2538 try dwarf.abbrevCode(di_nw, .numeric_type);2538 try dwarf.abbrevCode(di_nw, .numeric_type);
2539 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;2539 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
2540 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{2540 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2541 ty.fmt(pt),2541 ty.fmt(zcu),
2542 }) catch unreachable);2542 }) catch unreachable);
2543 try di_w.writeByte(switch (int_type.signedness) {2543 try di_w.writeByte(switch (int_type.signedness) {
2544 .signed => DW.ATE.signed,2544 .signed => DW.ATE.signed,
...@@ -2550,7 +2550,7 @@ fn updateConstInner(...@@ -2550,7 +2550,7 @@ fn updateConstInner(
2550 },2550 },
2551 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2551 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
2552 .one, .many, .c => {2552 .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)});
2554 defer zcu.gpa.free(name);2554 defer zcu.gpa.free(name);
2555 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {2555 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
2556 .none => .ptr_type,2556 .none => .ptr_type,
...@@ -2585,7 +2585,7 @@ fn updateConstInner(...@@ -2585,7 +2585,7 @@ fn updateConstInner(
2585 },2585 },
2586 .slice => {2586 .slice => {
2587 const ty: Type = .fromInterned(@"const");2587 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)});
2589 defer zcu.gpa.free(name);2589 defer zcu.gpa.free(name);
2590 try dwarf.abbrevCode(di_nw, .generated_struct_type);2590 try dwarf.abbrevCode(di_nw, .generated_struct_type);
2591 try dwarf.strx(di_nw, name);2591 try dwarf.strx(di_nw, name);
...@@ -2605,7 +2605,7 @@ fn updateConstInner(...@@ -2605,7 +2605,7 @@ fn updateConstInner(
2605 },2605 },
2606 },2606 },
2607 .array_type => |array_type| {2607 .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)});
2609 defer zcu.gpa.free(name);2609 defer zcu.gpa.free(name);
2610 try dwarf.abbrevCode(2610 try dwarf.abbrevCode(
2611 di_nw,2611 di_nw,
...@@ -2621,7 +2621,7 @@ fn updateConstInner(...@@ -2621,7 +2621,7 @@ fn updateConstInner(
2621 try di_w.writeUleb128(@backingInt(AbbrevCode.null));2621 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2622 },2622 },
2623 .vector_type => |vector_type| {2623 .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)});
2625 defer zcu.gpa.free(name);2625 defer zcu.gpa.free(name);
2626 try dwarf.abbrevCode(di_nw, .vector_type);2626 try dwarf.abbrevCode(di_nw, .vector_type);
2627 try dwarf.strx(di_nw, name);2627 try dwarf.strx(di_nw, name);
...@@ -2635,7 +2635,7 @@ fn updateConstInner(...@@ -2635,7 +2635,7 @@ fn updateConstInner(
2635 const opt_ty: Type = .fromInterned(@"const");2635 const opt_ty: Type = .fromInterned(@"const");
2636 const opt_child_ty: Type = .fromInterned(opt_child_type_index);2636 const opt_child_ty: Type = .fromInterned(opt_child_type_index);
2637 const opt_repr = optRepr(opt_child_ty, zcu);2637 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)});
2639 defer zcu.gpa.free(name);2639 defer zcu.gpa.free(name);
2640 try dwarf.abbrevCode(di_nw, .generated_union_type);2640 try dwarf.abbrevCode(di_nw, .generated_union_type);
2641 try dwarf.strx(di_nw, name);2641 try dwarf.strx(di_nw, name);
...@@ -2715,7 +2715,7 @@ fn updateConstInner(...@@ -2715,7 +2715,7 @@ fn updateConstInner(
2715 codegen.errUnionPayloadOffset(eu_payload_ty, zcu),2715 codegen.errUnionPayloadOffset(eu_payload_ty, zcu),
2716 },2716 },
2717 };2717 };
2718 const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(pt)});2718 const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(zcu)});
2719 defer zcu.gpa.free(name);2719 defer zcu.gpa.free(name);
27202720
2721 try dwarf.abbrevCode(di_nw, .generated_union_type);2721 try dwarf.abbrevCode(di_nw, .generated_union_type);
...@@ -2819,7 +2819,7 @@ fn updateConstInner(...@@ -2819,7 +2819,7 @@ fn updateConstInner(
2819 try dwarf.abbrevCode(di_nw, .void_type);2819 try dwarf.abbrevCode(di_nw, .void_type);
2820 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;2820 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
2821 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{2821 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
2822 ty.fmt(pt),2822 ty.fmt(zcu),
2823 }) catch unreachable);2823 }) catch unreachable);
2824 },2824 },
2825 .anyerror => {2825 .anyerror => {
...@@ -2842,7 +2842,7 @@ fn updateConstInner(...@@ -2842,7 +2842,7 @@ fn updateConstInner(
2842 },2842 },
2843 .tuple_type => |tuple_type| {2843 .tuple_type => |tuple_type| {
2844 const ty: Type = .fromInterned(@"const");2844 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)});
2846 defer zcu.gpa.free(name);2846 defer zcu.gpa.free(name);
2847 if (tuple_type.types.len == 0) {2847 if (tuple_type.types.len == 0) {
2848 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);2848 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
...@@ -3255,7 +3255,7 @@ fn updateConstInner(...@@ -3255,7 +3255,7 @@ fn updateConstInner(
3255 .spirv_type => unreachable,3255 .spirv_type => unreachable,
3256 .func_type => |func_type| {3256 .func_type => |func_type| {
3257 const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args;3257 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)});
3259 defer zcu.gpa.free(name);3259 defer zcu.gpa.free(name);
3260 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);3260 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
3261 try dwarf.strx(di_nw, name);3261 try dwarf.strx(di_nw, name);
...@@ -3340,7 +3340,7 @@ fn updateConstInner(...@@ -3340,7 +3340,7 @@ fn updateConstInner(
3340 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));3340 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3341 },3341 },
3342 .error_set_type => |error_set_type| {3342 .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)});
3344 defer zcu.gpa.free(name);3344 defer zcu.gpa.free(name);
3345 try dwarf.abbrevCode(3345 try dwarf.abbrevCode(
3346 di_nw,3346 di_nw,
...@@ -3358,7 +3358,7 @@ fn updateConstInner(...@@ -3358,7 +3358,7 @@ fn updateConstInner(
3358 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));3358 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
3359 },3359 },
3360 .inferred_error_set_type => |func| {3360 .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)});
3362 defer zcu.gpa.free(name);3362 defer zcu.gpa.free(name);
3363 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);3363 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);
3364 try dwarf.strx(di_nw, name);3364 try dwarf.strx(di_nw, name);
...@@ -3863,7 +3863,7 @@ pub fn updateConstIncomplete(...@@ -3863,7 +3863,7 @@ pub fn updateConstIncomplete(
3863 di_nw: *link.MappedFile.Node.Writer,3863 di_nw: *link.MappedFile.Node.Writer,
3864 val: InternPool.Index,3864 val: InternPool.Index,
3865) link.Error!void {3865) link.Error!void {
3866 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)});3866 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt.zcu)});
3867 dwarf.updateConstIncompleteInner(pt, di_nw, val) catch |err| switch (err) {3867 dwarf.updateConstIncompleteInner(pt, di_nw, val) catch |err| switch (err) {
3868 else => |e| return e,3868 else => |e| return e,
3869 error.WriteFailed => return dwarf.reportWriteError(di_nw),3869 error.WriteFailed => return dwarf.reportWriteError(di_nw),
...@@ -4021,7 +4021,7 @@ fn updateConstIncompleteInner(...@@ -4021,7 +4021,7 @@ fn updateConstIncompleteInner(
4021 },4021 },
4022 else => |val_key| break :done switch (val_key.typeOf()) {4022 else => |val_key| break :done switch (val_key.typeOf()) {
4023 .type_type => {4023 .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)});
4025 defer zcu.gpa.free(name);4025 defer zcu.gpa.free(name);
4026 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);4026 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
4027 try dwarf.strx(di_nw, name);4027 try dwarf.strx(di_nw, name);
...@@ -4140,11 +4140,12 @@ pub fn genDecl(...@@ -4140,11 +4140,12 @@ pub fn genDecl(
4140 di_nw: *link.MappedFile.Node.Writer,4140 di_nw: *link.MappedFile.Node.Writer,
4141 instance: Decl.Instance,4141 instance: Decl.Instance,
4142) link.Error!void {4142) link.Error!void {
4143 const zcu = pt.zcu;
4143 switch (instance) {4144 switch (instance) {
4144 .none => unreachable,4145 .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)}),
4146 .global => |global| log.debug("genDecl({f})", .{4147 .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),
4148 }),4149 }),
4149 }4150 }
4150 dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) {4151 dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) {
src/link/Elf/ZigObject.zig+2-2
...@@ -1720,7 +1720,7 @@ fn updateLazySymbol(...@@ -1720,7 +1720,7 @@ fn updateLazySymbol(
1720 const name_str_index = blk: {1720 const name_str_index = blk: {
1721 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{1721 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{
1722 @tagName(sym.kind),1722 @tagName(sym.kind),
1723 Type.fromInterned(sym.ty).fmt(pt),1723 Type.fromInterned(sym.ty).fmt(zcu),
1724 });1724 });
1725 defer gpa.free(name);1725 defer gpa.free(name);
1726 break :blk try self.strtab.insert(gpa, name);1726 break :blk try self.strtab.insert(gpa, name);
...@@ -2349,7 +2349,7 @@ fn checkUavAllocated(pt: Zcu.PerThread, index: InternPool.Index, meta: AvMetadat...@@ -2349,7 +2349,7 @@ fn checkUavAllocated(pt: Zcu.PerThread, index: InternPool.Index, meta: AvMetadat
2349 const uav = Value.fromInterned(index);2349 const uav = Value.fromInterned(index);
2350 const ty = uav.typeOf(zcu);2350 const ty = uav.typeOf(zcu);
2351 log.err("UAV {f}({d}) assigned symbol {d} but not allocated!", .{2351 log.err("UAV {f}({d}) assigned symbol {d} but not allocated!", .{
2352 ty.fmt(pt),2352 ty.fmt(zcu),
2353 index,2353 index,
2354 meta.symbol_index,2354 meta.symbol_index,
2355 });2355 });
src/link/Elf2.zig+23-23
...@@ -10328,6 +10328,8 @@ fn flushInner(...@@ -10328,6 +10328,8 @@ fn flushInner(
10328}10328}
1032910329
10330pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {10330pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
10331 _ = tid;
10332
10331 // This function is called non-deterministically, and so must not affect the layout of any nodes.10333 // This function is called non-deterministically, and so must not affect the layout of any nodes.
10332 elf.mf.nodes_lock.lock();10334 elf.mf.nodes_lock.lock();
10333 defer elf.mf.nodes_lock.unlock();10335 defer elf.mf.nodes_lock.unlock();
...@@ -10343,7 +10345,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -10343,7 +10345,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
10343 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);10345 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);
10344 elf.input_pending_index += 1;10346 elf.input_pending_index += 1;
10345 const idle_prog_node =10347 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)));
10347 defer idle_prog_node.end();10349 defer idle_prog_node.end();
10348 elf.flushInput(ii) catch |err| switch (err) {10350 elf.flushInput(ii) catch |err| switch (err) {
10349 else => |e| return e,10351 else => |e| return e,
...@@ -10355,7 +10357,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -10355,7 +10357,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
10355 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);10357 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);
10356 elf.input_section_pending_index += 1;10358 elf.input_section_pending_index += 1;
10357 const idle_prog_node =10359 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)));
10359 defer idle_prog_node.end();10361 defer idle_prog_node.end();
10360 elf.flushInputSection(isi) catch |err| switch (err) {10362 elf.flushInputSection(isi) catch |err| switch (err) {
10361 else => |e| return e,10363 else => |e| return e,
...@@ -10465,7 +10467,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -10465,7 +10467,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
10465 const clean_resized = ni.cleanResized(&elf.mf);10467 const clean_resized = ni.cleanResized(&elf.mf);
10466 const clean_next_moved = ni.cleanNextMoved(&elf.mf);10468 const clean_next_moved = ni.cleanNextMoved(&elf.mf);
10467 if (!clean_moved and !clean_resized and !clean_next_moved) continue;10469 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));
10469 defer idle_prog_node.end();10471 defer idle_prog_node.end();
10470 if (clean_moved) try elf.flushMoved(ni);10472 if (clean_moved) try elf.flushMoved(ni);
10471 if (clean_resized) try elf.flushResized(ni);10473 if (clean_resized) try elf.flushResized(ni);
...@@ -10483,7 +10485,6 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {...@@ -10483,7 +10485,6 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
1048310485
10484fn startIdleProgress(10486fn startIdleProgress(
10485 elf: *Elf,10487 elf: *Elf,
10486 tid: Zcu.PerThread.Id,
10487 prog_node: std.Progress.Node,10488 prog_node: std.Progress.Node,
10488 node: Node,10489 node: Node,
10489) std.Progress.Node {10490) std.Progress.Node {
...@@ -10508,7 +10509,7 @@ fn startIdleProgress(...@@ -10508,7 +10509,7 @@ fn startIdleProgress(
10508 break :name ip.getNav(nmi.nav(elf)).fqn.toSlice(ip);10509 break :name ip.getNav(nmi.nav(elf)).fqn.toSlice(ip);
10509 },10510 },
10510 .uav => |umi| std.mem.print(&name, "{f}", .{10511 .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.?),
10512 }) catch &name,10513 }) catch &name,
10513 .debug_shared => |ss| switch (ss) {10514 .debug_shared => |ss| switch (ss) {
10514 .debug_abbrev => "debug info abbrevs",10515 .debug_abbrev => "debug info abbrevs",
...@@ -10539,7 +10540,7 @@ fn startIdleProgress(...@@ -10539,7 +10540,7 @@ fn startIdleProgress(
10539 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {10540 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {
10540 .generic_poison_type => "anytype",10541 .generic_poison_type => "anytype",
10541 else => |val| std.mem.print(&name, "debug info for {f}", .{10542 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.?),
10543 }) catch &name,10544 }) catch &name,
10544 },10545 },
10545 .global_debug_info => |gi| {10546 .global_debug_info => |gi| {
...@@ -10571,10 +10572,11 @@ fn startIdleProgress(...@@ -10571,10 +10572,11 @@ fn startIdleProgress(
10571}10572}
1057210573
10573fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {10574fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
10575 const zcu = elf.base.comp.zcu.?;
10574 while (elf.pending_uavs.pop()) |umi| {10576 while (elf.pending_uavs.pop()) |umi| {
10575 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;10577 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;
10576 const prog_name = std.mem.print(&prog_name_buf, "{f}", .{10578 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),
10578 }) catch &prog_name_buf;10580 }) catch &prog_name_buf;
10579 const prog_node = elf.const_prog_node.start(prog_name, 0);10581 const prog_node = elf.const_prog_node.start(prog_name, 0);
10580 defer prog_node.end();10582 defer prog_node.end();
...@@ -10671,14 +10673,15 @@ fn genUav(...@@ -10671,14 +10673,15 @@ fn genUav(
10671}10673}
1067210674
10673fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void {10675fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void {
10676 const zcu = elf.base.comp.zcu.?;
10674 const lazy = lmr.lazySymbol(elf);10677 const lazy = lmr.lazySymbol(elf);
10675 if (lazy.ty == .anyerror_type) return;10678 if (lazy.ty == .anyerror_type) return;
10676 const lazy_ty: Type = .fromInterned(lazy.ty);10679 const lazy_ty: Type = .fromInterned(lazy.ty);
10677 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;10680 var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined;
10678 const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(pt.zcu)) {10681 const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(zcu)) {
10679 .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf,10682 .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(zcu)}) catch &prog_name_buf,
10680 .error_set => switch (lmr.kind) {10683 .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,
10682 .const_data => "@errorName(anyerror)",10685 .const_data => "@errorName(anyerror)",
10683 },10686 },
10684 else => unreachable,10687 else => unreachable,
...@@ -12143,8 +12146,8 @@ fn updateExportInner(...@@ -12143,8 +12146,8 @@ fn updateExportInner(
12143 switch (@"export".exported) {12146 switch (@"export".exported) {
12144 .nav => |nav| log.debug("updateExports({f})", .{ip.getNav(nav).fqn.fmt(ip)}),12147 .nav => |nav| log.debug("updateExports({f})", .{ip.getNav(nav).fqn.fmt(ip)}),
12145 .uav => |uav| log.debug("updateExports(@as({f}, {f}))", .{12148 .uav => |uav| log.debug("updateExports(@as({f}, {f}))", .{
12146 Type.fromInterned(ip.typeOf(uav)).fmt(pt),12149 Type.fromInterned(ip.typeOf(uav)).fmt(zcu),
12147 Value.fromInterned(uav).fmtValue(pt),12150 Value.fromInterned(uav).fmtValue(zcu),
12148 }),12151 }),
12149 }12152 }
12150 const exported_lsi: Symbol.LocalIndex = switch (@"export".exported) {12153 const exported_lsi: Symbol.LocalIndex = switch (@"export".exported) {
...@@ -12277,7 +12280,7 @@ pub fn printNode(...@@ -12277,7 +12280,7 @@ pub fn printNode(
12277 const ip = &zcu.intern_pool;12280 const ip = &zcu.intern_pool;
12278 const nav = ip.getNav(nmi.nav(elf));12281 const nav = ip.getNav(nmi.nav(elf));
12279 try w.print("({f}, {f})", .{12282 try w.print("({f}, {f})", .{
12280 Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }),12283 Type.fromInterned(nav.resolved.?.type).fmt(zcu),
12281 nav.fqn.fmt(ip),12284 nav.fqn.fmt(ip),
12282 });12285 });
12283 },12286 },
...@@ -12285,15 +12288,12 @@ pub fn printNode(...@@ -12285,15 +12288,12 @@ pub fn printNode(
12285 const zcu = elf.base.comp.zcu.?;12288 const zcu = elf.base.comp.zcu.?;
12286 const val: Value = .fromInterned(umi.uavValue(elf));12289 const val: Value = .fromInterned(umi.uavValue(elf));
12287 try w.print("({f}, {f})", .{12290 try w.print("({f}, {f})", .{
12288 val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }),12291 val.typeOf(zcu).fmt(zcu),
12289 val.fmtValue(.{ .zcu = zcu, .tid = tid }),12292 val.fmtValue(zcu),
12290 });12293 });
12291 },12294 },
12292 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{12295 inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{
12293 Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(.{12296 Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(elf.base.comp.zcu.?),
12294 .zcu = elf.base.comp.zcu.?,
12295 .tid = tid,
12296 }),
12297 }),12297 }),
12298 .debug_shared => |ss| try w.print("({})", .{ss}),12298 .debug_shared => |ss| try w.print("({})", .{ss}),
12299 .unit_frame,12299 .unit_frame,
...@@ -12308,7 +12308,7 @@ pub fn printNode(...@@ -12308,7 +12308,7 @@ pub fn printNode(
12308 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {12308 .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) {
12309 .generic_poison_type => try w.writeAll("(anytype)"),12309 .generic_poison_type => try w.writeAll("(anytype)"),
12310 else => |val| try w.print("({f})", .{12310 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.?),
12312 }),12312 }),
12313 },12313 },
12314 .global_debug_info => |gi| {12314 .global_debug_info => |gi| {
...@@ -12317,11 +12317,11 @@ pub fn printNode(...@@ -12317,11 +12317,11 @@ pub fn printNode(
12317 const nav = ip.getNav(gi.nav(&elf.dwarf));12317 const nav = ip.getNav(gi.nav(&elf.dwarf));
12318 try w.writeByte('(');12318 try w.writeByte('(');
12319 if (nav.resolved) |resolved| try w.print("{f}, ", .{12319 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),
12321 });12321 });
12322 try w.print("{f}", .{nav.fqn.fmt(ip)});12322 try w.print("{f}", .{nav.fqn.fmt(ip)});
12323 if (nav.resolved) |resolved| try w.print(", {f}", .{12323 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),
12325 });12325 });
12326 try w.writeByte(')');12326 try w.writeByte(')');
12327 },12327 },
...@@ -12331,7 +12331,7 @@ pub fn printNode(...@@ -12331,7 +12331,7 @@ pub fn printNode(
12331 const nav = ip.getNav(fi.nav(&elf.dwarf));12331 const nav = ip.getNav(fi.nav(&elf.dwarf));
12332 try w.writeByte('(');12332 try w.writeByte('(');
12333 if (nav.resolved) |resolved| try w.print("{f}, ", .{12333 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),
12335 });12335 });
12336 try w.print("{f})", .{nav.fqn.fmt(ip)});12336 try w.print("{f})", .{nav.fqn.fmt(ip)});
12337 },12337 },
src/link/MachO/ZigObject.zig+1-1
...@@ -1330,7 +1330,7 @@ fn updateLazySymbol(...@@ -1330,7 +1330,7 @@ fn updateLazySymbol(
1330 const name_str = blk: {1330 const name_str = blk: {
1331 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{1331 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{
1332 @tagName(lazy_sym.kind),1332 @tagName(lazy_sym.kind),
1333 Type.fromInterned(lazy_sym.ty).fmt(pt),1333 Type.fromInterned(lazy_sym.ty).fmt(zcu),
1334 });1334 });
1335 defer gpa.free(name);1335 defer gpa.free(name);
1336 break :blk try self.addString(gpa, name);1336 break :blk try self.addString(gpa, name);
src/print_value.zig+121-122
...@@ -10,28 +10,29 @@ const InternPool = @import("InternPool.zig");...@@ -10,28 +10,29 @@ const InternPool = @import("InternPool.zig");
10const Allocator = std.mem.Allocator;10const Allocator = std.mem.Allocator;
11const Target = std.Target;11const Target = std.Target;
12const Writer = std.Io.Writer;12const Writer = std.Io.Writer;
13const assert = std.debug.assert;
1314
14const max_aggregate_items = 100;15const max_aggregate_items = 100;
15const max_string_len = 256;16const max_string_len = 256;
1617
17pub const FormatContext = struct {18pub const FormatContext = struct {
18 val: Value,19 val: Value,
19 pt: Zcu.PerThread,20 zcu: *Zcu,
20 opt_sema: ?*Sema,21 opt_sema: ?*Sema,
21 depth: u8,22 depth: u8,
22};23};
2324
24pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {25pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void {
25 const sema = ctx.opt_sema.?;26 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) {
27 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function28 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
28 error.WriteFailed => |e| return e,29 error.WriteFailed => |e| return e,
29 };30 };
30}31}
3132
32pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {33pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void {
33 std.debug.assert(ctx.opt_sema == null);34 assert(ctx.opt_sema == null);
34 return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) {35 return print(ctx.val, writer, ctx.depth, ctx.zcu, null) catch |err| switch (err) {
35 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function36 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
36 error.WriteFailed => |e| return e,37 error.WriteFailed => |e| return e,
37 };38 };
...@@ -41,10 +42,9 @@ pub fn print(...@@ -41,10 +42,9 @@ pub fn print(
41 val: Value,42 val: Value,
42 writer: *Writer,43 writer: *Writer,
43 level: u8,44 level: u8,
44 pt: Zcu.PerThread,45 zcu: *Zcu,
45 opt_sema: ?*Sema,46 opt_sema: ?*Sema,
46) (Writer.Error || Allocator.Error)!void {47) (Writer.Error || Allocator.Error)!void {
47 const zcu = pt.zcu;
48 const ip = &zcu.intern_pool;48 const ip = &zcu.intern_pool;
49 switch (ip.indexToKey(val.toIntern())) {49 switch (ip.indexToKey(val.toIntern())) {
50 .int_type,50 .int_type,
...@@ -64,7 +64,7 @@ pub fn print(...@@ -64,7 +64,7 @@ pub fn print(
64 .func_type,64 .func_type,
65 .error_set_type,65 .error_set_type,
66 .inferred_error_set_type,66 .inferred_error_set_type,
67 => try Type.print(val.toType(), writer, pt, null),67 => try Type.print(val.toType(), writer, zcu, null),
68 .undef => try writer.writeAll("undefined"),68 .undef => try writer.writeAll("undefined"),
69 .simple_value => |simple_value| switch (simple_value) {69 .simple_value => |simple_value| switch (simple_value) {
70 .void => try writer.writeAll("{}"),70 .void => try writer.writeAll("{}"),
...@@ -88,7 +88,7 @@ pub fn print(...@@ -88,7 +88,7 @@ pub fn print(
88 .err_name => |err_name| try writer.print("error.{f}", .{88 .err_name => |err_name| try writer.print("error.{f}", .{
89 err_name.fmt(ip),89 err_name.fmt(ip),
90 }),90 }),
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),
92 },92 },
93 .enum_literal => |enum_literal| try writer.print(".{f}", .{93 .enum_literal => |enum_literal| try writer.print(".{f}", .{
94 enum_literal.fmt(ip),94 enum_literal.fmt(ip),
...@@ -101,7 +101,7 @@ pub fn print(...@@ -101,7 +101,7 @@ pub fn print(
101 }101 }
102 try writer.writeAll("@fromBackingInt(");102 try writer.writeAll("@fromBackingInt(");
103 if (level == 0) return writer.writeAll("...)");103 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);
105 try writer.writeAll(")");105 try writer.writeAll(")");
106 },106 },
107 .float => |float| switch (float.storage) {107 .float => |float| switch (float.storage) {
...@@ -112,7 +112,7 @@ pub fn print(...@@ -112,7 +112,7 @@ pub fn print(
112 if (slice.len == .zero_usize) {112 if (slice.len == .zero_usize) {
113 return writer.writeAll("&.{}");113 return writer.writeAll("&.{}");
114 }114 }
115 try print(.fromInterned(slice.ptr), writer, level, pt, opt_sema);115 try print(.fromInterned(slice.ptr), writer, level, zcu, opt_sema);
116 } else {116 } else {
117 const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) {117 const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) {
118 .field, .arr_elem, .eu_payload, .opt_payload => unreachable,118 .field, .arr_elem, .eu_payload, .opt_payload => unreachable,
...@@ -123,13 +123,13 @@ pub fn print(...@@ -123,13 +123,13 @@ pub fn print(
123 // TODO: eventually we want to load the slice as an array with `sema`, but that's123 // TODO: eventually we want to load the slice as an array with `sema`, but that's
124 // currently not possible without e.g. triggering compile errors.124 // currently not possible without e.g. triggering compile errors.
125 }125 }
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);
127 }127 }
128 try writer.writeAll("[0..");128 try writer.writeAll("[0..");
129 if (level == 0) {129 if (level == 0) {
130 try writer.writeAll("(...)");130 try writer.writeAll("(...)");
131 } else {131 } 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);
133 }133 }
134 try writer.writeAll("]");134 try writer.writeAll("]");
135 },135 },
...@@ -143,28 +143,28 @@ pub fn print(...@@ -143,28 +143,28 @@ pub fn print(
143 // TODO: eventually we want to load the pointer with `sema`, but that's143 // TODO: eventually we want to load the pointer with `sema`, but that's
144 // currently not possible without e.g. triggering compile errors.144 // currently not possible without e.g. triggering compile errors.
145 }145 }
146 try printPtr(val, .rvalue, writer, level, pt, opt_sema);146 try printPtr(val, .rvalue, writer, level, zcu, opt_sema);
147 },147 },
148 .opt => |opt| switch (opt.val) {148 .opt => |opt| switch (opt.val) {
149 .none => try writer.writeAll("null"),149 .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),
151 },151 },
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),
153 .un => |un| {153 .un => |un| {
154 if (level == 0) {154 if (level == 0) {
155 try writer.writeAll(".{ ... }");155 try writer.writeAll(".{ ... }");
156 return;156 return;
157 }157 }
158 if (un.tag == .none) {158 if (un.tag == .none) {
159 const backing_ty = try val.typeOf(zcu).externUnionBackingType(pt);159 const backing_val: Value = .fromInterned(un.val);
160 try writer.print("@bitCast(@as({f}, ", .{backing_ty.fmt(pt)});160 try writer.print("@bitCast(@as({f}, ", .{backing_val.typeOf(zcu).fmt(zcu)});
161 try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema);161 try print(backing_val, writer, level - 1, zcu, opt_sema);
162 try writer.writeAll("))");162 try writer.writeAll("))");
163 } else {163 } else {
164 try writer.writeAll(".{ ");164 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);
166 try writer.writeAll(" = ");166 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);
168 try writer.writeAll(" }");168 try writer.writeAll(" }");
169 }169 }
170 },170 },
...@@ -173,35 +173,17 @@ pub fn print(...@@ -173,35 +173,17 @@ pub fn print(
173 return writer.writeAll(".{ ... }");173 return writer.writeAll(".{ ... }");
174 }174 }
175 const ty: Type = .fromInterned(bitpack.ty);175 const ty: Type = .fromInterned(bitpack.ty);
176 switch (ty.zigTypeTag(zcu)) {176 switch (ty.backingIntMode(zcu)) {
177 .@"struct" => {177 .auto => {
178 if (ty.structFieldCount(zcu) == 0) {178 try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(zcu)});
179 return writer.writeAll(".{}");179 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema);
180 }180 try writer.writeAll("))");
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;
191 },181 },
192 .@"union" => switch (ty.backingIntMode(zcu)) {182 .explicit => {
193 .auto => {183 try writer.writeAll("@fromBackingInt(");
194 try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(pt)});184 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema);
195 try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, pt, opt_sema);185 try writer.writeAll(")");
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 },
203 },186 },
204 else => unreachable,
205 }187 }
206 },188 },
207 .memoized_call => unreachable,189 .memoized_call => unreachable,
...@@ -214,14 +196,13 @@ fn printAggregate(...@@ -214,14 +196,13 @@ fn printAggregate(
214 is_ref: bool,196 is_ref: bool,
215 writer: *Writer,197 writer: *Writer,
216 level: u8,198 level: u8,
217 pt: Zcu.PerThread,199 zcu: *Zcu,
218 opt_sema: ?*Sema,200 opt_sema: ?*Sema,
219) (Writer.Error || Allocator.Error)!void {201) (Writer.Error || Allocator.Error)!void {
220 if (level == 0) {202 if (level == 0) {
221 if (is_ref) try writer.writeByte('&');203 if (is_ref) try writer.writeByte('&');
222 return writer.writeAll(".{ ... }");204 return writer.writeAll(".{ ... }");
223 }205 }
224 const zcu = pt.zcu;
225 const ip = &zcu.intern_pool;206 const ip = &zcu.intern_pool;
226 const ty = Type.fromInterned(aggregate.ty);207 const ty = Type.fromInterned(aggregate.ty);
227 switch (ty.zigTypeTag(zcu)) {208 switch (ty.zigTypeTag(zcu)) {
...@@ -236,7 +217,7 @@ fn printAggregate(...@@ -236,7 +217,7 @@ fn printAggregate(
236 if (i != 0) try writer.writeAll(", ");217 if (i != 0) try writer.writeAll(", ");
237 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;218 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;
238 try writer.print(".{f} = ", .{field_name.fmt(ip)});219 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);
240 }221 }
241 try writer.writeAll(" }");222 try writer.writeAll(" }");
242 return;223 return;
...@@ -285,7 +266,7 @@ fn printAggregate(...@@ -285,7 +266,7 @@ fn printAggregate(
285 0 => try writer.writeAll(".{}"),266 0 => try writer.writeAll(".{}"),
286 1 => {267 1 => {
287 try writer.writeAll(".{");268 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);
289 try writer.writeByte('}');270 try writer.writeByte('}');
290 },271 },
291 else => {272 else => {
...@@ -293,7 +274,7 @@ fn printAggregate(...@@ -293,7 +274,7 @@ fn printAggregate(
293 const max_len = @min(len, max_aggregate_items);274 const max_len = @min(len, max_aggregate_items);
294 for (0..max_len) |i| {275 for (0..max_len) |i| {
295 if (i != 0) try writer.writeAll(", ");276 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);
297 }278 }
298 if (len > max_aggregate_items) {279 if (len > max_aggregate_items) {
299 try writer.writeAll(", ...");280 try writer.writeAll(", ...");
...@@ -303,16 +284,40 @@ fn printAggregate(...@@ -303,16 +284,40 @@ fn printAggregate(
303 }284 }
304}285}
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
306fn printPtr(311fn printPtr(
307 ptr_val: Value,312 ptr_val: Value,
308 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.313 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
309 want_kind: ?PrintPtrKind,314 want_kind: ?PrintPtrKind,
310 writer: *Writer,315 writer: *Writer,
311 level: u8,316 level: u8,
312 pt: Zcu.PerThread,317 zcu: *Zcu,
313 opt_sema: ?*Sema,318 opt_sema: ?*Sema,
314) (Writer.Error || Allocator.Error)!void {319) (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())) {
316 .undef => return writer.writeAll("undefined"),321 .undef => return writer.writeAll("undefined"),
317 .ptr => |ptr| ptr,322 .ptr => |ptr| ptr,
318 else => unreachable,323 else => unreachable,
...@@ -320,25 +325,25 @@ fn printPtr(...@@ -320,25 +325,25 @@ fn printPtr(
320325
321 if (ptr.base_addr == .uav) {326 if (ptr.base_addr == .uav) {
322 // If the value is an aggregate, we can potentially print it more nicely.327 // 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)) {
324 .aggregate => |agg| return printAggregate(329 .aggregate => |agg| return printAggregate(
325 Value.fromInterned(ptr.base_addr.uav.val),330 Value.fromInterned(ptr.base_addr.uav.val),
326 agg,331 agg,
327 true,332 true,
328 writer,333 writer,
329 level,334 level,
330 pt,335 zcu,
331 opt_sema,336 opt_sema,
332 ),337 ),
333 else => {},338 else => {},
334 }339 }
335 }340 }
336341
337 var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa);342 var arena = std.heap.ArenaAllocator.init(zcu.gpa);
338 defer arena.deinit();343 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 = .{
342 .level = level,347 .level = level,
343 .opt_sema = opt_sema,348 .opt_sema = opt_sema,
344 } }, 20);349 } }, 20);
...@@ -349,9 +354,9 @@ const PrintPtrKind = enum { lvalue, rvalue };...@@ -349,9 +354,9 @@ const PrintPtrKind = enum { lvalue, rvalue };
349/// Print the pointer defined by `derivation` as an lvalue or an rvalue.354/// Print the pointer defined by `derivation` as an lvalue or an rvalue.
350/// Returns the root derivation, which may be ignored.355/// Returns the root derivation, which may be ignored.
351pub fn printPtrDerivation(356pub fn printPtrDerivation(
352 derivation: Value.PointerDeriveStep,357 derivation: Value.PointerDerivation,
353 writer: *Writer,358 writer: *Writer,
354 pt: Zcu.PerThread,359 zcu: *Zcu,
355 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.360 /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen.
356 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as361 /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as
357 /// an atom -- e.g. `&foo.*` is distinct from `(&foo).*`.362 /// an atom -- e.g. `&foo.*` is distinct from `(&foo).*`.
...@@ -368,33 +373,36 @@ pub fn printPtrDerivation(...@@ -368,33 +373,36 @@ pub fn printPtrDerivation(
368 /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary,373 /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary,
369 /// so at this depth we just write "..." to prevent stack overflow.374 /// so at this depth we just write "..." to prevent stack overflow.
370 ptr_depth: u8,375 ptr_depth: u8,
371) !Value.PointerDeriveStep {376) !Value.PointerDerivation {
372 const zcu = pt.zcu;
373 const ip = &zcu.intern_pool;377 const ip = &zcu.intern_pool;
374378
375 if (ptr_depth == 0) {379 if (ptr_depth == 0) {
376 const root_step = root: switch (derivation) {380 var root_step = derivation;
377 inline .eu_payload_ptr,381 while (true) {
378 .opt_payload_ptr,382 switch (derivation.addr) {
379 .field_ptr,383 inline .eu_payload,
380 .elem_ptr,384 .opt_payload,
381 .offset_and_cast,385 .field,
382 => |step| continue :root step.parent.*,386 .elem,
383 else => |step| break :root step,387 .offset_and_cast,
384 };388 => |derived| root_step = derived.parent.*,
389
390 .int, .nav, .uav, .comptime_alloc, .comptime_field => break,
391 }
392 }
385 try writer.writeAll("...");393 try writer.writeAll("...");
386 return root_step;394 return root_step;
387 }395 }
388396
389 const result_kind: PrintPtrKind = switch (derivation) {397 const result_kind: PrintPtrKind = switch (derivation.addr) {
390 .nav_ptr,398 .nav,
391 .uav_ptr,399 .uav,
392 .comptime_alloc_ptr,400 .comptime_alloc,
393 .comptime_field_ptr,401 .comptime_field,
394 .eu_payload_ptr,402 .eu_payload,
395 .opt_payload_ptr,403 .opt_payload,
396 .field_ptr,404 .field,
397 .elem_ptr,405 .elem,
398 => .lvalue,406 => .lvalue,
399407
400 .offset_and_cast,408 .offset_and_cast,
...@@ -409,33 +417,33 @@ pub fn printPtrDerivation(...@@ -409,33 +417,33 @@ pub fn printPtrDerivation(
409 }417 }
410418
411 // null if `derivation` is the root.419 // null if `derivation` is the root.
412 const root_or_null: ?Value.PointerDeriveStep = switch (derivation) {420 const root_or_null: ?Value.PointerDerivation = switch (derivation.addr) {
413 .eu_payload_ptr => |info| root: {421 .eu_payload => |info| root: {
414 try writer.writeByte('(');422 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);
416 try writer.writeAll(" catch unreachable)");424 try writer.writeAll(" catch unreachable)");
417 break :root root;425 break :root root;
418 },426 },
419 .opt_payload_ptr => |info| root: {427 .opt_payload => |info| root: {
420 const root = try printPtrDerivation(info.parent.*, writer, pt, .lvalue, root_strat, ptr_depth - 1);428 const root = try printPtrDerivation(info.parent.*, writer, zcu, .lvalue, root_strat, ptr_depth - 1);
421 try writer.writeAll(".?");429 try writer.writeAll(".?");
422 break :root root;430 break :root root;
423 },431 },
424 .field_ptr => |field| root: {432 .field => |derived| root: {
425 const root = try printPtrDerivation(field.parent.*, writer, pt, null, root_strat, ptr_depth - 1);433 const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1);
426 const agg_ty = (try field.parent.ptrType(pt)).childType(zcu);434 const agg_ty = derived.parent.elem_ty;
427 switch (agg_ty.zigTypeTag(zcu)) {435 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| {
429 try writer.print(".{f}", .{field_name.fmt(ip)});437 try writer.print(".{f}", .{field_name.fmt(ip)});
430 } else {438 } else {
431 try writer.print("[{d}]", .{field.field_idx});439 try writer.print("[{d}]", .{derived.field_index});
432 },440 },
433 .@"union" => {441 .@"union" => {
434 const tag_ty = agg_ty.unionTagTypeHypothetical(zcu);442 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);
436 try writer.print(".{f}", .{field_name.fmt(ip)});444 try writer.print(".{f}", .{field_name.fmt(ip)});
437 },445 },
438 .pointer => switch (field.field_idx) {446 .pointer => switch (derived.field_index) {
439 Value.slice_ptr_index => try writer.writeAll(".ptr"),447 Value.slice_ptr_index => try writer.writeAll(".ptr"),
440 Value.slice_len_index => try writer.writeAll(".len"),448 Value.slice_len_index => try writer.writeAll(".len"),
441 else => unreachable,449 else => unreachable,
...@@ -444,58 +452,49 @@ pub fn printPtrDerivation(...@@ -444,58 +452,49 @@ pub fn printPtrDerivation(
444 }452 }
445 break :root root;453 break :root root;
446 },454 },
447 .elem_ptr => |elem| root: {455 .elem => |derived| root: {
448 const root = try printPtrDerivation(elem.parent.*, writer, pt, null, root_strat, ptr_depth - 1);456 const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1);
449 try writer.print("[{d}]", .{elem.elem_idx});457 try writer.print("[{d}]", .{derived.elem_index});
450 break :root root;458 break :root root;
451 },459 },
452460
453 .offset_and_cast => |oac| if (oac.byte_offset == 0) root: {461 .offset_and_cast => |derived| if (derived.byte_offset == 0) root: {
454 try writer.print("@as({f}, @ptrCast(", .{oac.new_ptr_ty.fmt(pt)});462 try writer.print("@as({f}, @ptrCast(", .{derivation.fmtType(zcu)});
455 const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1);463 const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1);
456 try writer.writeAll("))");464 try writer.writeAll("))");
457 break :root root;465 break :root root;
458 } else root: {466 } else root: {
459 try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{oac.new_ptr_ty.fmt(pt)});467 try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{derivation.fmtType(zcu)});
460 const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1);468 const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1);
461 try writer.print(") + {d}))", .{oac.byte_offset});469 try writer.print(") + {d}))", .{derived.byte_offset});
462 break :root root;470 break :root root;
463 },471 },
464472
465 .int, .nav_ptr, .uav_ptr, .comptime_alloc_ptr, .comptime_field_ptr => null,473 .int, .nav, .uav, .comptime_alloc, .comptime_field => null,
466 };474 };
467475
468 if (root_or_null == null) switch (root_strat) {476 if (root_or_null == null) switch (root_strat) {
469 .str => |x| try writer.writeAll(x),477 .str => |x| try writer.writeAll(x),
470 .print_val => |x| switch (derivation) {478 .print_val => |x| switch (derivation.addr) {
471 .int => |int| try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ int.ptr_ty.fmt(pt), int.addr }),479 .int => |int| {
472 .nav_ptr => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}),480 try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ derivation.fmtType(zcu), int });
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(')');
482 },481 },
483 .comptime_alloc_ptr => |info| {482 .nav => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}),
484 try writer.print("@as({f}, ", .{info.val.typeOf(zcu).fmt(pt)});483 .uav, .comptime_field => |val| {
484 try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)});
485 if (x.level == 0) {485 if (x.level == 0) {
486 try writer.writeAll("...");486 try writer.writeAll("...");
487 } else {487 } 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);
489 }489 }
490 try writer.writeByte(')');490 try writer.writeByte(')');
491 },491 },
492 .comptime_field_ptr => |val| {492 .comptime_alloc => |info| {
493 const ty = val.typeOf(zcu);493 try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)});
494 try writer.print("@as({f}, ", .{ty.fmt(pt)});
495 if (x.level == 0) {494 if (x.level == 0) {
496 try writer.writeAll("...");495 try writer.writeAll("...");
497 } else {496 } 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);
499 }498 }
500 try writer.writeByte(')');499 try writer.writeByte(')');
501 },500 },