diff --git a/src/Air/Verify.zig b/src/Air/Verify.zig index 5979310b1db6a1bce1637e42ee3b7317405d199b..da92e5d2460cc8d0c2e30688e945c39a43a53cde 100644 --- a/src/Air/Verify.zig +++ b/src/Air/Verify.zig @@ -41,7 +41,7 @@ pub fn run(pt: Zcu.PerThread, func_index: InternPool.Index, air: *const Air) voi error.Canceled => return io.recancel(), }; defer io.unlockStderr(); - air.write(&stderr.file_writer.interface, pt, null) catch |err| switch (err) { + air.write(&stderr.file_writer.interface, zcu, null) catch |err| switch (err) { error.WriteFailed => switch (stderr.file_writer.err.?) { error.Canceled => return io.recancel(), else => {}, diff --git a/src/Air/print.zig b/src/Air/print.zig index 18d207355f70491b92572e68ca7598791368aef5..6f43909740609da4d5ce53040307dadf3d386e1b 100644 --- a/src/Air/print.zig +++ b/src/Air/print.zig @@ -9,7 +9,7 @@ const Type = @import("../Type.zig"); const Air = @import("../Air.zig"); const InternPool = @import("../InternPool.zig"); -pub fn write(air: Air, stream: *std.Io.Writer, pt: Zcu.PerThread, liveness: ?Air.Liveness) !void { +pub fn write(air: Air, stream: *std.Io.Writer, zcu: *Zcu, liveness: ?Air.Liveness) !void { comptime assert(build_options.enable_debug_extensions); const instruction_bytes = air.instructions.len * // 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 // zig fmt: on var writer: Writer = .{ - .pt = pt, - .gpa = pt.zcu.gpa, + .zcu = zcu, + .gpa = zcu.comp.gpa, .air = air, .liveness = liveness, .indent = 2, @@ -57,13 +57,13 @@ pub fn writeInst( air: Air, stream: *std.Io.Writer, inst: Air.Inst.Index, - pt: Zcu.PerThread, + zcu: *Zcu, liveness: ?Air.Liveness, ) void { comptime assert(build_options.enable_debug_extensions); var writer: Writer = .{ - .pt = pt, - .gpa = pt.zcu.gpa, + .zcu = zcu, + .gpa = zcu.comp.gpa, .air = air, .liveness = liveness, .indent = 2, @@ -89,7 +89,7 @@ pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Ai } const Writer = struct { - pt: Zcu.PerThread, + zcu: *Zcu, gpa: Allocator, air: Air, liveness: ?Air.Liveness, @@ -377,7 +377,7 @@ const Writer = struct { } fn writeType(w: *Writer, s: *std.Io.Writer, ty: Type) !void { - return ty.print(s, w.pt, null); + return ty.print(s, w.zcu, null); } fn writeTy(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { @@ -446,7 +446,7 @@ const Writer = struct { } fn writeAggregateInit(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { - const zcu = w.pt.zcu; + const zcu = w.zcu; const ty_pl = w.air.instructions.items(.data)[@backingInt(inst)].ty_pl; const vector_ty = ty_pl.ty; const len = @as(usize, @intCast(vector_ty.arrayLen(zcu))); @@ -539,7 +539,7 @@ const Writer = struct { } fn writeShuffleOne(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { - const unwrapped = w.air.unwrapShuffleOne(w.pt.zcu, inst); + const unwrapped = w.air.unwrapShuffleOne(w.zcu, inst); try w.writeType(s, unwrapped.result_ty); try s.writeAll(", "); try w.writeOperand(s, inst, 0, unwrapped.operand); @@ -548,14 +548,14 @@ const Writer = struct { if (mask_idx > 0) try s.writeAll(", "); switch (mask_elem.unwrap()) { .elem => |idx| try s.print("elem {d}", .{idx}), - .value => |val| try s.print("val {f}", .{Value.fromInterned(val).fmtValue(w.pt)}), + .value => |val| try s.print("val {f}", .{Value.fromInterned(val).fmtValue(w.zcu)}), } } try s.writeByte(']'); } fn writeShuffleTwo(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { - const unwrapped = w.air.unwrapShuffleTwo(w.pt.zcu, inst); + const unwrapped = w.air.unwrapShuffleTwo(w.zcu, inst); try w.writeType(s, unwrapped.result_ty); try s.writeAll(", "); try w.writeOperand(s, inst, 0, unwrapped.operand_a); @@ -574,7 +574,7 @@ const Writer = struct { } fn writeSelect(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { - const zcu = w.pt.zcu; + const zcu = w.zcu; const pl_op = w.air.instructions.items(.data)[@backingInt(inst)].pl_op; const extra = w.air.extraData(Air.Bin, pl_op.payload).data; @@ -606,7 +606,7 @@ const Writer = struct { } fn writeRuntimeNavPtr(w: *Writer, s: *std.Io.Writer, inst: Air.Inst.Index) Error!void { - const ip = &w.pt.zcu.intern_pool; + const ip = &w.zcu.intern_pool; const ty_nav = w.air.instructions.items(.data)[@backingInt(inst)].ty_nav; try w.writeType(s, ty_nav.ty); try s.print(", '{f}'", .{ip.getNav(ty_nav.nav).fqn.fmt(ip)}); @@ -695,7 +695,7 @@ const Writer = struct { try s.writeByte(')'); } - const zcu = w.pt.zcu; + const zcu = w.zcu; const ip = &zcu.intern_pool; const clobbers_val: Value = .fromInterned(unwrapped_asm.clobbers); const clobbers_ty = clobbers_val.typeOf(zcu); @@ -1019,11 +1019,11 @@ const Writer = struct { if (@backingInt(operand) < InternPool.static_len) { return s.print("@{}", .{operand}); } else if (operand.toInterned()) |ip_index| { - const pt = w.pt; - const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf()); + const zcu = w.zcu; + const ty = Type.fromInterned(zcu.intern_pool.indexToKey(ip_index).typeOf()); try s.print("<{f}, {f}>", .{ - ty.fmt(pt), - Value.fromInterned(ip_index).fmtValue(pt), + ty.fmt(zcu), + Value.fromInterned(ip_index).fmtValue(w.zcu), }); } else { return w.writeInstIndex(s, operand.toIndex().?, dies); @@ -1042,7 +1042,7 @@ const Writer = struct { } fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type { - const zcu = w.pt.zcu; + const zcu = w.zcu; return w.air.typeOfIndex(inst, &zcu.intern_pool); } }; diff --git a/src/Sema.zig b/src/Sema.zig index a1d30147758234ed15ba84cbe71a85494ac574aa..4f078df5c2b7d2f33477790c0b991572fd1b5e57 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -910,6 +910,7 @@ const ComptimeReason = union(enum) { }, fn explain(reason: ComptimeReason, sema: *Sema, src: LazySrcLoc, err_msg: *Zcu.ErrorMsg) !void { + const zcu = sema.pt.zcu; switch (reason) { .simple => |simple| { try sema.errNote(src, err_msg, "{s}", .{simple.message()}); @@ -920,17 +921,17 @@ const ComptimeReason = union(enum) { .struct_init => .{ "initializer of comptime-only struct", "must be comptime-known" }, .tuple_init => .{ "initializer of comptime-only tuple", "must be comptime-known" }, }; - try sema.errNote(src, err_msg, "{s} '{f}' {s}", .{ pre, co.ty.fmt(sema.pt), post }); + try sema.errNote(src, err_msg, "{s} '{f}' {s}", .{ pre, co.ty.fmt(zcu), post }); try sema.explainWhyTypeIsComptime(err_msg, src, co.ty); }, .comptime_only_param_ty => |co| { - try sema.errNote(src, err_msg, "argument to parameter with comptime-only type '{f}' must be comptime-known", .{co.ty.fmt(sema.pt)}); + try sema.errNote(src, err_msg, "argument to parameter with comptime-only type '{f}' must be comptime-known", .{co.ty.fmt(zcu)}); try sema.errNote(co.param_ty_src, err_msg, "parameter type declared here", .{}); try sema.explainWhyTypeIsComptime(err_msg, src, co.ty); }, .comptime_only_ret_ty => |co| { const function_with: []const u8 = if (co.is_generic_inst) "generic function instantiated with" else "function with"; - 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) }); + try sema.errNote(src, err_msg, "call to {s} comptime-only return type '{f}' is evaluated at comptime", .{ function_with, co.ty.fmt(zcu) }); try sema.errNote(co.ret_ty_src, err_msg, "return type declared here", .{}); try sema.explainWhyTypeIsComptime(err_msg, src, co.ty); }, @@ -1901,7 +1902,7 @@ fn analyzeBodyInner( const err_union_ty = sema.typeOf(err_union); if (err_union_ty.zigTypeTag(zcu) != .error_union) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, err_union_ty); try sema.errNote(operand_src, msg, "consider omitting 'try'", .{}); @@ -2366,7 +2367,7 @@ pub fn failWithTooLargeShiftAmount( const msg = try sema.errMsg( shift_src, "shift amount '{f}' is too large for operand type '{f}'", - .{ shift_amt.fmtValueSema(sema.pt, sema), operand_ty.fmt(sema.pt) }, + .{ shift_amt.fmtValueSema(sema), operand_ty.fmt(sema.pt.zcu) }, ); errdefer msg.destroy(sema.gpa); 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( pub fn failWithNegativeShiftAmount(sema: *Sema, block: *Block, src: LazySrcLoc, shift_amt: Value, vector_index: ?usize) CompileError { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema.pt, sema)}); + const msg = try sema.errMsg(src, "shift by negative amount '{f}'", .{shift_amt.fmtValueSema(sema)}); errdefer msg.destroy(sema.gpa); if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i}); break :msg msg; @@ -2397,9 +2398,9 @@ pub fn failWithUnsupportedComptimeShiftAmount(sema: *Sema, block: *Block, src: L } fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { - const pt = sema.pt; + const zcu = sema.pt.zcu; return sema.fail(block, src, "remainder division with '{f}' and '{f}': signed integers and floats must use @rem or @mod", .{ - lhs_ty.fmt(pt), rhs_ty.fmt(pt), + lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), }); } @@ -2421,7 +2422,7 @@ fn failWithInvalidSwitchTagCapture(sema: *Sema, block: *Block, tag_capture_src: } return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(tag_capture_src, "cannot capture tag of non-union type '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, operand_ty); @@ -2440,7 +2441,7 @@ fn failWithAmbiguousBackingIntType( const zcu = pt.zcu; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "{s} is ambiguous for type '{f}'", .{ - builtin_name, int_backed_ty.fmt(pt), + builtin_name, int_backed_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.errNote(int_backed_ty.srcLoc(zcu), msg, "backing integer type of {t} is inferred", .{ @@ -2452,13 +2453,13 @@ fn failWithAmbiguousBackingIntType( } fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { - const pt = sema.pt; + const zcu = sema.pt.zcu; const msg = msg: { const msg = try sema.errMsg(src, "expected optional type, found '{f}'", .{ - non_optional_ty.fmt(pt), + non_optional_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); - if (non_optional_ty.zigTypeTag(pt.zcu) == .error_union) { + if (non_optional_ty.zigTypeTag(zcu) == .error_union) { try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); } try addDeclaredHereNote(sema, msg, non_optional_ty); @@ -2468,15 +2469,14 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non } fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { - const pt = sema.pt; - const zcu = pt.zcu; + const zcu = sema.pt.zcu; const msg = msg: { const msg = try sema.errMsg(src, "type '{f}' does not support array initialization syntax", .{ - ty.fmt(pt), + ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); if (ty.isSlice(zcu)) { - try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(pt)}); + try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{f}'", .{ty.childType(zcu).fmt(zcu)}); } break :msg msg; }; @@ -2484,17 +2484,17 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty } fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { - const pt = sema.pt; + const zcu = sema.pt.zcu; return sema.fail(block, src, "type '{f}' does not support struct initialization syntax", .{ - ty.fmt(pt), + ty.fmt(zcu), }); } pub fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: Type, val: Value, vector_index: ?usize) CompileError { - const pt = sema.pt; + const zcu = sema.pt.zcu; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "overflow of integer type '{f}' with value '{f}'", .{ - int_ty.fmt(pt), val.fmtValueSema(pt, sema), + int_ty.fmt(zcu), val.fmtValueSema(sema), }); errdefer msg.destroy(sema.gpa); if (vector_index) |i| try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{i}); @@ -2543,7 +2543,7 @@ fn failWithInvalidFieldAccess( const child_ty = inner_ty.optionalChild(zcu); if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt; const msg = msg: { - const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "optional type '{f}' does not support field access", .{object_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{}); break :msg msg; @@ -2553,14 +2553,14 @@ fn failWithInvalidFieldAccess( const child_ty = inner_ty.errorUnionPayload(zcu); if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err; const msg = msg: { - const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "error union type '{f}' does not support field access", .{object_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); break :msg msg; }; return sema.failWithOwnedErrorMsg(block, msg); } - return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(pt)}); + return sema.fail(block, src, "type '{f}' does not support field access", .{object_ty.fmt(zcu)}); } fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool { @@ -2650,20 +2650,20 @@ pub fn errMsg( } fn typeMismatchErrMsg(sema: *Sema, src: LazySrcLoc, expected: Type, found: Type) Allocator.Error!*Zcu.ErrorMsg { - const pt = sema.pt; - var cmp: Type.Comparison = try .init(&.{ expected, found }, pt); - defer cmp.deinit(pt); + const zcu = sema.pt.zcu; + var cmp: Type.Comparison = try .init(&.{ expected, found }, zcu); + defer cmp.deinit(zcu.comp.gpa); const msg = try sema.errMsg(src, "expected type '{f}', found '{f}'", .{ - cmp.fmtType(expected, pt), - cmp.fmtType(found, pt), + cmp.fmtType(expected, zcu), + cmp.fmtType(found, zcu), }); errdefer msg.destroy(sema.gpa); for (cmp.type_dedupe_cache.keys(), cmp.type_dedupe_cache.values()) |ty, value| { if (value == .dont_dedupe) continue; const placeholder = value.dedupe; - try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(pt) }); + try sema.errNote(src, msg, "{f} = {f}", .{ placeholder, ty.fmt(zcu) }); } return msg; @@ -2679,7 +2679,7 @@ pub fn fail( const err_msg = try sema.errMsg(src, format, args); inline for (args) |arg| { if (@TypeOf(arg) == Type.Formatter) { - try addDeclaredHereNote(sema, err_msg, arg.data.ty); + try addDeclaredHereNote(sema, err_msg, arg.ty); } } return sema.failWithOwnedErrorMsg(block, err_msg); @@ -3154,11 +3154,11 @@ fn validateDeref( const zcu = pt.zcu; const ip = &zcu.intern_pool; if (ty.zigTypeTag(zcu) != .pointer) { - return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(pt)}); + return sema.fail(block, src, "cannot dereference non-pointer type '{f}'", .{ty.fmt(zcu)}); } const size = ty.ptrSize(zcu); switch (size) { - .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(pt)}), + .many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{f}'", .{ty.fmt(zcu)}), .one, .c, .slice => {}, } if (sema.resolveValue(ref)) |val| { @@ -3194,11 +3194,11 @@ fn ensureResultUsed( switch (ty.zigTypeTag(zcu)) { .void, .noreturn => return, .error_set => { - return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(pt)}); + return sema.fail(block, src, "error set of type '{f}' is ignored", .{ty.fmt(zcu)}); }, .error_union => { const msg = msg: { - const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(pt)}); + const msg = try sema.errMsg(src, "error union of type '{f}' is ignored", .{ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); break :msg msg; @@ -3207,7 +3207,7 @@ fn ensureResultUsed( }, else => { const msg = msg: { - const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(pt)}); + const msg = try sema.errMsg(src, "value of type '{f}' ignored", .{ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "all non-void values must be used", .{}); 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 // The value was initialized through RLS, so we didn't detect the runtime condition earlier. // TODO: source location of runtime control flow const init_src = block.src(.{ .node_offset_var_decl_init = inst_data.src_node }); - return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(pt)}); + return sema.fail(block, init_src, "value with comptime-only type '{f}' depends on runtime control flow", .{elem_ty.fmt(zcu)}); } // This is a runtime value. @@ -3990,7 +3990,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com // The alloc wasn't comptime-known per the above logic, so the // type cannot be comptime-only. // TODO: source location of runtime control flow - return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(pt)}); + return sema.fail(block, src, "value with comptime-only type '{f}' depends on runtime control flow", .{final_elem_ty.fmt(zcu)}); } if (sema.func_is_naked and final_elem_ty.hasRuntimeBits(zcu)) { 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. if (!object_ty.isIndexable(zcu)) { // Instead of using checkIndexable we customize this error. const msg = msg: { - const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(pt)}); + const msg = try sema.errMsg(arg_src, "type '{f}' is not indexable and not a range", .{object_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); @@ -4129,10 +4129,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. .input_index = len_idx, } }); try sema.errNote(a_src, msg, "length {f} here", .{ - v.fmtValueSema(pt, sema), + v.fmtValueSema(sema), }); try sema.errNote(arg_src, msg, "length {f} here", .{ - arg_val.fmtValueSema(pt, sema), + arg_val.fmtValueSema(sema), }); break :msg msg; }; @@ -4164,7 +4164,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. .input_index = i, } }); try sema.errNote(arg_src, msg, "type '{f}' has no upper bound", .{ - object_ty.fmt(pt), + object_ty.fmt(zcu), }); } break :msg msg; @@ -4249,7 +4249,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE switch (val_ty.zigTypeTag(zcu)) { .array, .vector => {}, else => if (!val_ty.isTuple(zcu)) { - return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) }); + return sema.fail(block, src, "expected array of '{f}', found '{f}'", .{ elem_ty.fmt(zcu), val_ty.fmt(zcu) }); }, } const want_ty = try pt.arrayType(.{ @@ -4327,7 +4327,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr const ty_operand = try sema.resolveTypeOrPoison(block, src, un_tok.operand) orelse return; if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .pointer) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(pt)}); + const msg = try sema.errMsg(src, "expected type '{f}', found pointer", .{ty_operand.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "address-of operator always returns a pointer", .{}); break :msg msg; @@ -4713,7 +4713,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp if (!operand_ty.destructurable(zcu)) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "type '{f}' cannot be destructured", .{operand_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(destructure_src, msg, "result destructured here", .{}); if (operand_ty.zigTypeTag(pt.zcu) == .error_union) { @@ -4758,13 +4758,13 @@ fn failWithBadMemberAccess( const inst_index = inst.resolve(ip) orelse return sema.failTransitive(.{ .lost_tracking = inst }); if (inst_index == .main_struct_inst) { return sema.fail(block, field_src, "root source file struct '{f}' has no member named '{f}'", .{ - agg_ty.fmt(pt), field_name.fmt(ip), + agg_ty.fmt(zcu), field_name.fmt(ip), }); } } return sema.fail(block, field_src, "{s} '{f}' has no member named '{f}'", .{ - kw_name, agg_ty.fmt(pt), field_name.fmt(ip), + kw_name, agg_ty.fmt(zcu), field_name.fmt(ip), }); } @@ -5061,10 +5061,10 @@ fn zirCompileLog( const arg_ty = sema.typeOf(arg); if (sema.resolveValue(arg)) |val| { writer.print("@as({f}, {f})", .{ - arg_ty.fmt(pt), val.fmtValueSema(pt, sema), + arg_ty.fmt(zcu), val.fmtValueSema(sema), }) catch return error.OutOfMemory; } else { - writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(pt)}) catch return error.OutOfMemory; + writer.print("@as({f}, [runtime value])", .{arg_ty.fmt(zcu)}) catch return error.OutOfMemory; } } @@ -5505,7 +5505,7 @@ fn resolveAnalyzedBlock( const type_src = src; // TODO: better source location if (resolved_ty.comptimeOnly(zcu)) { const msg = msg: { - const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(pt)}); + const msg = try sema.errMsg(type_src, "value with comptime-only type '{f}' depends on runtime control flow", .{resolved_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); 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 { if (ptr_ty.zigTypeTag(zcu) != .pointer) { - return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(pt)}); + return sema.fail(block, ptr_src, "expected pointer type, found '{f}'", .{ptr_ty.fmt(zcu)}); } const ptr_ty_info = ptr_ty.ptrInfo(zcu); if (ptr_ty_info.flags.size == .slice) { @@ -5634,7 +5634,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void try sema.ensureLayoutResolved(export_ty, src, .@"export"); if (!export_ty.validateExtern(.other, zcu)) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other); try sema.addDeclaredHereNote(msg, export_ty); @@ -5691,7 +5691,7 @@ pub fn analyzeExportSelfNav( if (!export_ty.validateExtern(.other, zcu)) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "unable to export type '{f}'", .{export_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other); try sema.addDeclaredHereNote(msg, export_ty); @@ -6329,7 +6329,7 @@ fn checkCallArgumentCount( { const msg = msg: { const msg = try sema.errMsg(func_src, "cannot call optional type '{f}'", .{ - callee_ty.fmt(pt), + callee_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); @@ -6340,7 +6340,7 @@ fn checkCallArgumentCount( }, else => {}, } - return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(pt)}); + return sema.fail(block, func_src, "type '{f}' not a function", .{callee_ty.fmt(zcu)}); }; const func_ty_info = zcu.typeToFunc(func_ty).?; @@ -6403,7 +6403,7 @@ fn callBuiltin( }, else => {}, } - std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(pt)}); + std.debug.panic("type '{f}' is not a function calling builtin fn", .{callee_ty.fmt(zcu)}); }; const func_ty_info = zcu.typeToFunc(func_ty).?; @@ -6829,7 +6829,7 @@ fn analyzeCall( if (!param_ty.isValidParamType(zcu)) { const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else ""; return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{ - opaque_str, param_ty.fmt(pt), + opaque_str, param_ty.fmt(zcu), }); } @@ -6930,7 +6930,7 @@ fn analyzeCall( if (!full_ty.isValidReturnType(zcu)) { const opaque_str = if (full_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else ""; return sema.fail(block, func_ret_ty_src, "{s}return type '{f}' not allowed", .{ - opaque_str, full_ty.fmt(pt), + opaque_str, full_ty.fmt(zcu), }); } @@ -7430,7 +7430,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ const owner_func_ty: Type = .fromInterned(zcu.funcInfo(sema.owner.unwrap().func).ty); if (owner_func_ty.toIntern() != func_ty.toIntern()) { 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}'", .{ - func_ty.fmt(pt), owner_func_ty.fmt(pt), + func_ty.fmt(zcu), owner_func_ty.fmt(zcu), }); } _ = try block.addUnOp(.ret, result); @@ -7450,9 +7450,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); const child_type = try sema.resolveType(block, operand_src, inst_data.operand); if (child_type.zigTypeTag(zcu) == .@"opaque") { - return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(pt)}); + return sema.fail(block, operand_src, "opaque type '{f}' cannot be optional", .{child_type.fmt(zcu)}); } else if (child_type.zigTypeTag(zcu) == .null) { - return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(pt)}); + return sema.fail(block, operand_src, "type '{f}' cannot be optional", .{child_type.fmt(zcu)}); } const opt_type = try pt.optionalType(child_type.toIntern()); @@ -7513,7 +7513,7 @@ fn zirSplatOpResultType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil switch (vec_ty.zigTypeTag(zcu)) { .array, .vector => {}, - else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(pt)}), + else => return sema.fail(block, block.nodeOffset(un_node.src_node), "expected array or vector type, found '{f}'", .{vec_ty.fmt(zcu)}), } return Air.internedToRef(vec_ty.childType(zcu).toIntern()); } @@ -7586,7 +7586,7 @@ fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: const pt = sema.pt; const zcu = pt.zcu; if (elem_type.zigTypeTag(zcu) == .@"opaque") { - return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(pt)}); + return sema.fail(block, elem_src, "array of opaque type '{f}' not allowed", .{elem_type.fmt(zcu)}); } else if (elem_type.zigTypeTag(zcu) == .noreturn) { return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{}); } @@ -7617,7 +7617,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr if (error_set.zigTypeTag(zcu) != .error_set) { return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{ - error_set.fmt(pt), + error_set.fmt(zcu), }); } try sema.validateErrorUnionPayloadType(block, payload, rhs_src); @@ -7630,11 +7630,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p const zcu = pt.zcu; if (payload_ty.zigTypeTag(zcu) == .@"opaque") { return sema.fail(block, payload_src, "error union with payload of opaque type '{f}' not allowed", .{ - payload_ty.fmt(pt), + payload_ty.fmt(zcu), }); } else if (payload_ty.zigTypeTag(zcu) == .error_set) { return sema.fail(block, payload_src, "error union with payload of error set type '{f}' not allowed", .{ - payload_ty.fmt(pt), + payload_ty.fmt(zcu), }); } } @@ -7765,9 +7765,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr const lhs_ty = try sema.analyzeAsType(block, lhs_src, .type, lhs); const rhs_ty = try sema.analyzeAsType(block, rhs_src, .type, rhs); if (lhs_ty.zigTypeTag(zcu) != .error_set) - return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(pt)}); + return sema.fail(block, lhs_src, "expected error set type, found '{f}'", .{lhs_ty.fmt(zcu)}); if (rhs_ty.zigTypeTag(zcu) != .error_set) - return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(pt)}); + return sema.fail(block, rhs_src, "expected error set type, found '{f}'", .{rhs_ty.fmt(zcu)}); // Anything merged with anyerror is anyerror. 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 block, operand_src, "untagged union '{f}' cannot be converted to integer", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ); } @@ -7901,7 +7901,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError }, else => { return sema.fail(block, operand_src, "expected enum or tagged union, found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); }, }; @@ -7930,7 +7930,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const operand_ty = sema.typeOf(operand); if (dest_ty.zigTypeTag(zcu) != .@"enum") { - return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(pt)}); + return sema.fail(block, src, "expected enum, found '{f}'", .{dest_ty.fmt(zcu)}); } try sema.ensureLayoutResolved(dest_ty, src, .init); _ = try sema.checkIntType(block, operand_src, operand_ty); @@ -7942,7 +7942,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern()); } return sema.fail(block, src, "int value '{f}' out of range of non-exhaustive enum '{f}'", .{ - int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt), + int_val.fmtValueSema(sema), dest_ty.fmt(zcu), }); } if (int_val.isUndef(zcu)) { @@ -7950,7 +7950,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError } if (!(try sema.enumHasInt(dest_ty, int_val))) { return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{ - dest_ty.fmt(pt), int_val.fmtValueSema(pt, sema), + dest_ty.fmt(zcu), int_val.fmtValueSema(sema), }); } return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern()); @@ -8128,7 +8128,7 @@ fn zirErrUnionPayload( const err_union_ty = sema.typeOf(operand); if (err_union_ty.zigTypeTag(zcu) != .error_union) { return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{ - err_union_ty.fmt(pt), + err_union_ty.fmt(zcu), }); } return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); @@ -8202,7 +8202,7 @@ fn analyzeErrUnionPayloadPtr( if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) { return sema.fail(block, src, "expected error union type, found '{f}'", .{ - operand_ty.childType(zcu).fmt(pt), + operand_ty.childType(zcu).fmt(zcu), }); } @@ -8277,7 +8277,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air const operand_ty = sema.typeOf(operand); if (operand_ty.zigTypeTag(zcu) != .error_union) { return sema.fail(block, src, "expected error union type, found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); } @@ -8311,7 +8311,7 @@ fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand: if (operand_ty.childType(zcu).zigTypeTag(zcu) != .error_union) { return sema.fail(block, src, "expected error union type, found '{f}'", .{ - operand_ty.childType(zcu).fmt(pt), + operand_ty.childType(zcu).fmt(zcu), }); } @@ -8639,7 +8639,7 @@ fn checkParamType( if (!param_ty.isValidParamType(zcu)) { const opaque_str = if (param_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else ""; return sema.fail(block, param_src, "parameter of {s}type '{f}' not allowed", .{ - opaque_str, param_ty.fmt(pt), + opaque_str, param_ty.fmt(zcu), }); } if (!target_util.fnCallConvAllowsZigTypes(cc)) { @@ -8720,12 +8720,12 @@ fn checkReturnTypeAndCallConv( if (!bare_ret_ty.isValidReturnType(zcu)) { const opaque_str = if (bare_ret_ty.zigTypeTag(zcu) == .@"opaque") "opaque " else ""; return sema.fail(block, ret_ty_src, "{s}return type '{s}{f}' not allowed", .{ - opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(pt), + opaque_str, ies_ret_ty_prefix, bare_ret_ty.fmt(zcu), }); } if (!target_util.fnCallConvAllowsZigTypes(@"callconv")) { if (inferred_error_set) { - return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(pt), @"callconv" }); + return sema.fail(block, ret_ty_src, "return type '!{f}' not allowed in function with calling convention '{t}'", .{ bare_ret_ty.fmt(zcu), @"callconv" }); } if (bare_ret_ty.isGenericPoison()) { 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( } else src; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(param_src, "parameter of type '{f}' not allowed in function with calling convention '{t}'", .{ - param_ty.fmt(pt), @"callconv", + param_ty.fmt(zcu), @"callconv", }); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty); @@ -8874,7 +8874,7 @@ fn validateResolvedFuncType( } else src; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(ret_ty_src, "return type '{f}' not allowed in function with calling convention '{t}'", .{ - ret_ty.fmt(pt), @"callconv", + ret_ty.fmt(zcu), @"callconv", }); errdefer msg.destroy(gpa); 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) } return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "value with non-mergable pointer type '{f}' depends on runtime control flow", .{peer_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); const runtime_src = block.runtime_cond orelse block.runtime_loop.?; @@ -9166,7 +9166,7 @@ fn analyzeAs( const operand = sema.resolveInst(zir_operand); const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand; switch (dest_ty.zigTypeTag(zcu)) { - .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(pt)}), + .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(zcu)}), .noreturn => return sema.fail(block, src, "cannot cast to noreturn", .{}), else => {}, } @@ -9191,7 +9191,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! const ptr_ty = operand_ty.scalarType(zcu); const is_vector = operand_ty.zigTypeTag(zcu) == .vector; if (!ptr_ty.isPtrAtRuntime(zcu)) { - return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)}); + return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)}); } 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 // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices. switch (dest_ty.scalarType(zcu).zigTypeTag(zcu)) { .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); switch (operand_ty.zigTypeTag(zcu)) { - .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(pt)}), - .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(pt)}), + .int, .comptime_int => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{f}'", .{operand_ty.fmt(zcu)}), + .pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{f}'", .{operand_ty.fmt(zcu)}), else => {}, } break :msg msg; }), .array => switch (dest_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) { - .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}), + .pointer, .optional => return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}), else => {}, }, else => {}, } if (!dest_ty.hasBitRepresentation(zcu)) { - return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(pt)}); + return sema.fail(block, src, "cannot @bitCast to '{f}'", .{dest_ty.fmt(zcu)}); } // Check for pointers before checking `hasBitRepresentation` so we can emit a better message for slices. switch (operand_ty.scalarType(zcu).zigTypeTag(zcu)) { .pointer, .optional => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); switch (dest_ty.zigTypeTag(zcu)) { - .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(pt)}), - .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(pt)}), + .int, .comptime_int => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{f}'", .{dest_ty.fmt(zcu)}), + .pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{f}'", .{dest_ty.fmt(zcu)}), else => {}, } break :msg msg; }), .array => switch (operand_ty.arrayBase(zcu)[0].zigTypeTag(zcu)) { - .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(pt)}), + .pointer, .optional => return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{dest_ty.fmt(zcu)}), else => {}, }, else => {}, } if (!operand_ty.hasBitRepresentation(zcu)) { - return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(pt)}); + return sema.fail(block, operand_src, "cannot @bitCast from '{f}'", .{operand_ty.fmt(zcu)}); } operand_ty.assertHasLayout(zcu); @@ -9462,9 +9462,9 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const dest_bits = dest_ty.bitSize(zcu); if (operand_bits != dest_bits) { return sema.fail(block, src, "@bitCast size mismatch: destination type '{f}' has {d} bits but source type '{f}' has {d} bits", .{ - dest_ty.fmt(pt), + dest_ty.fmt(zcu), dest_bits, - operand_ty.fmt(pt), + operand_ty.fmt(zcu), operand_bits, }); } @@ -9482,7 +9482,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air dest_ty.enumTagFieldIndex(result_val, zcu) == null) { return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{ - dest_ty.fmt(pt), result_val.backingInt(zcu).fmtValueSema(pt, sema), + dest_ty.fmt(zcu), result_val.backingInt(zcu).fmtValueSema(sema), }); } @@ -9515,9 +9515,9 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! if (union_obj.tag_usage == .tagged) break :ref try sema.unionToTag(block, operand); if (union_obj.layout == .@"packed") break :ref operand; return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "non-packed union '{f}' does not have a backing integer", .{operand_ty.fmt(zcu)}); errdefer msg.deinit(gpa); - try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(pt)}); + try sema.errNote(operand_src, msg, "untagged union '{f}' does not have an enum tag with a backing integer", .{operand_ty.fmt(zcu)}); try sema.addDeclaredHereNote(msg, operand_ty); break :msg msg; }); @@ -9525,14 +9525,14 @@ fn zirBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! .@"struct" => { if (operand_ty.containerLayout(zcu) != .@"packed") { return sema.fail(block, operand_src, "non-packed struct '{f}' does not have a backing integer", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); } break :ref operand; }, else => { return sema.fail(block, operand_src, "expected enum, tagged union, packed union or packed struct, found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); }, }; @@ -9568,12 +9568,12 @@ fn zirFromBackingIntArgTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp .@"enum" => {}, .@"struct", .@"union" => |type_tag| if (dest_ty.containerLayout(zcu) != .@"packed") { return sema.fail(block, src, "non-packed {t} '{f}' does not have a backing integer", .{ - type_tag, dest_ty.fmt(pt), + type_tag, dest_ty.fmt(zcu), }); }, else => { return sema.fail(block, src, "expected enum, packed union or packed struct, found '{f}'", .{ - dest_ty.fmt(pt), + dest_ty.fmt(zcu), }); }, } @@ -9614,7 +9614,7 @@ fn zirFromBackingInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr enum_obj.tagValueIndex(ip, backing_int_val.toIntern()) == null) { return sema.fail(block, src, "enum '{f}' has no tag with value '{f}'", .{ - dest_ty.fmt(pt), backing_int_val.fmtValueSema(pt, sema), + dest_ty.fmt(zcu), backing_int_val.fmtValueSema(sema), }); } 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 block, src, "expected float or vector type, found '{f}'", - .{dest_ty.fmt(pt)}, + .{dest_ty.fmt(zcu)}, ), }; @@ -9670,7 +9670,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A block, operand_src, "expected float or vector type, found '{f}'", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ), } @@ -9747,7 +9747,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node }); const msg = msg: { const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{f}'", .{ - indexable_ty.fmt(pt), + indexable_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); if (indexable_ty.isIndexable(zcu)) { @@ -9869,7 +9869,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand)); const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) { .pointer => lhs_ptr_ty.childType(zcu), - else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(pt)}), + else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(zcu)}), }; const sentinel_ty: Type = switch (lhs_ty.zigTypeTag(zcu)) { @@ -9884,7 +9884,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE }; }, }, - else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(pt)}), + else => return sema.fail(block, src, "slice of non-array type '{f}'", .{lhs_ty.fmt(zcu)}), }; return Air.internedToRef(sentinel_ty.toIntern()); @@ -9954,7 +9954,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp }; if (err_union_ty.zigTypeTag(zcu) != .error_union) { return sema.fail(block, operand_src, "expected error union type, found '{f}'", .{ - err_union_ty.fmt(pt), + err_union_ty.fmt(zcu), }); } @@ -10816,7 +10816,7 @@ fn finishSwitchBr( else => {}, } return sema.fail(block, else_prong_src, "cannot enumerate values of type '{f}' for 'inline else'", .{ - item_ty.fmt(pt), + item_ty.fmt(zcu), }); }; var unhandled_it = validated_switch.iterateUnhandledItems(error_names, min_int); @@ -11252,7 +11252,7 @@ fn validateSwitchBlock( .optional => return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(operand_src, "switch on optional type '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); errdefer msg.destroy(gpa); try sema.errNote(operand_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); @@ -11261,7 +11261,7 @@ fn validateSwitchBlock( .error_union => return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(operand_src, "switch on error union type '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }); errdefer msg.destroy(gpa); try sema.errNote(operand_src, msg, "consider using 'try', 'catch', or 'if'", .{}); @@ -11281,14 +11281,14 @@ fn validateSwitchBlock( .spirv, => {}, } - return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(pt)}); + return sema.fail(block, operand_src, "switch on type '{f}'", .{operand_ty.fmt(zcu)}); }; if (zir_switch.has_continue and !block.isComptime()) { if (operand_ty.comptimeOnly(zcu)) { // Even if the operand is comptime-known, this `switch` is runtime. return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "operand of switch loop has comptime-only type '{f}'", .{operand_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(operand_src, msg, "switch loops are evaluated at runtime outside of comptime scopes", .{}); try sema.explainWhyTypeIsComptime(msg, operand_src, operand_ty); @@ -11404,7 +11404,7 @@ fn validateSwitchBlock( const msg = try sema.errMsg( operand_src, "ranges not allowed when switching on type '{f}'", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ); errdefer msg.destroy(gpa); try sema.errNote( @@ -11466,7 +11466,7 @@ fn validateSwitchBlock( item_ty.srcLoc(zcu), msg, "enum '{f}' declared here", - .{item_ty.fmt(pt)}, + .{item_ty.fmt(zcu)}, ); break :msg msg; }; @@ -11589,7 +11589,7 @@ fn validateSwitchBlock( block, src, "else prong required when switching on type '{f}'", - .{item_ty.fmt(pt)}, + .{item_ty.fmt(zcu)}, ); } }, @@ -12655,7 +12655,7 @@ fn validateSwitchItemOrRange( if (overlap_start.eql(overlap_end, item_ty, zcu)) { return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{ - overlap_start.fmtValueSema(pt, sema), + overlap_start.fmtValueSema(sema), }); errdefer msg.destroy(sema.gpa); if (prev_range.first.eql(prev_range.last, item_ty, zcu)) { @@ -12677,7 +12677,7 @@ fn validateSwitchItemOrRange( } else { try sema.errNote(prev_range.src, msg, "overlaps with previous range here", .{}); try sema.errNote(prev_range.src, msg, "ranges overlap from '{f}' to '{f}'", .{ - overlap_start.fmtValueSema(pt, sema), overlap_end.fmtValueSema(pt, sema), + overlap_start.fmtValueSema(sema), overlap_end.fmtValueSema(sema), }); } break :msg msg; @@ -12719,7 +12719,7 @@ fn validateSwitchItemOrRange( if (maybe_prev_src) |prev_src| { return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(item_src, "duplicate switch value '{f}'", .{ - item_val.fmtValueSema(pt, sema), + item_val.fmtValueSema(sema), }); errdefer msg.destroy(sema.gpa); 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 else => {}, } return sema.fail(block, ty_src, "type '{f}' does not support '@hasField'", .{ - ty.fmt(pt), + ty.fmt(zcu), }); }; return if (has_field) .bool_true else .bool_false; @@ -13087,7 +13087,7 @@ fn zirShl( break :rs lhs_src; } else { if (air_tag == .shl_sat and scalar_rhs_ty.isSignedInt(zcu)) { - return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(pt)}); + return sema.fail(block, rhs_src, "shift by signed type '{f}'", .{rhs_ty.fmt(zcu)}); } if (scalar_ty.toIntern() == .comptime_int_type) { 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. const scalar_tag = scalar_ty.zigTypeTag(zcu); if (scalar_tag != .int and scalar_tag != .bool) - return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(pt)}); + return sema.fail(block, operand_src, "bitwise not operation on type '{f}'", .{operand_ty.fmt(zcu)}); return analyzeBitNot(sema, block, operand, src); } @@ -13505,11 +13505,11 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { if (lhs_is_tuple) break :lhs_info undefined; - return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(pt)}); + return sema.fail(block, lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(zcu)}); }; const rhs_info = try sema.getArrayCatInfo(block, rhs_src, rhs, lhs_ty) orelse { assert(!rhs_is_tuple); - return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(pt)}); + return sema.fail(block, rhs_src, "expected indexable; found '{f}'", .{rhs_ty.fmt(zcu)}); }; const resolved_elem_ty = t: { @@ -13933,7 +13933,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. .int, .comptime_int, .float, .comptime_float => false, else => true, }) { - return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)}); + return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)}); } if (rhs_scalar_ty.isAnyFloat()) { @@ -13964,7 +13964,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! switch (rhs_scalar_ty.zigTypeTag(zcu)) { .int, .comptime_int, .float, .comptime_float => {}, - else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(pt)}), + else => return sema.fail(block, src, "negation of type '{f}'", .{rhs_ty.fmt(zcu)}), } 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 block, src, "ambiguous coercion of division operands '{f}' and '{f}'; non-zero remainder '{f}'", - .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValueSema(pt, sema) }, + .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), rem.fmtValueSema(sema) }, ); } } @@ -14087,7 +14087,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins block, src, "division with '{f}' and '{f}': signed integers must use @divTrunc, @divFloor, @divCeil, or @divExact", - .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt) }, + .{ lhs_ty.fmt(zcu), rhs_ty.fmt(zcu) }, ); } break :blk .div_trunc; @@ -14804,7 +14804,7 @@ fn zirOverflowArithmetic( const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src); if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .int) { - return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(pt)}); + return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(zcu)}); } const maybe_lhs_val = sema.resolveValue(lhs); @@ -15064,7 +15064,7 @@ fn analyzeArithmetic( }; if (lhs_elem_ty.toIntern() != rhs_elem_ty.toIntern()) { return sema.fail(block, src, "incompatible pointer arithmetic operands '{f}' and '{f}'", .{ - lhs_ty.fmt(pt), rhs_ty.fmt(pt), + lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), }); } @@ -15072,7 +15072,7 @@ fn analyzeArithmetic( const elem_size = lhs_elem_ty.abiSize(zcu); if (elem_size == 0) { return sema.fail(block, src, "pointer subtraction requires element type '{f}' to have runtime bits", .{ - lhs_elem_ty.fmt(pt), + lhs_elem_ty.fmt(zcu), }); } @@ -15379,20 +15379,20 @@ fn zirAsm( .int, .float, .bool, .vector => {}, .pointer => if (out_ty.isSlice(zcu)) return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(output_src, msg, "consider separate outputs for 'ptr' and 'len'", .{}); break :msg msg; }), .optional => if (!out_ty.isPtrLikeOptional(zcu)) { - return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); }, .@"enum" => switch (ip.loadEnumType(out_ty.toIntern()).int_tag_mode) { .explicit => {}, .auto => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(out_ty.srcLoc(zcu), msg, "integer tag type of enum is inferred", .{}); try sema.errNote(out_ty.srcLoc(zcu), msg, "consider explicitly specifying the integer tag type", .{}); @@ -15403,7 +15403,7 @@ fn zirAsm( .@"struct" => switch (out_ty.containerLayout(zcu)) { .@"packed" => {}, .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(output_src, msg, "struct types cannot be passed to inline assembly", .{}); try sema.addDeclaredHereNote(msg, out_ty); @@ -15414,7 +15414,7 @@ fn zirAsm( .@"union" => switch (out_ty.containerLayout(zcu)) { .@"packed" => {}, .auto, .@"extern" => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(output_src, msg, "union types cannot be passed to inline assembly", .{}); try sema.addDeclaredHereNote(msg, out_ty); @@ -15423,7 +15423,7 @@ fn zirAsm( }, .array => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}); + const msg = try sema.errMsg(output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(output_src, msg, "array types cannot be passed to inline assembly", .{}); break :msg msg; @@ -15444,7 +15444,7 @@ fn zirAsm( .@"anyframe", .enum_literal, .spirv, - => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(pt)}), + => return sema.fail(block, output_src, "invalid inline assembly output type '{f}'", .{out_ty.fmt(zcu)}), } const constraint = sema.code.nullTerminatedString(output.data.constraint); @@ -15500,7 +15500,7 @@ fn zirAsm( }, else => true, }; - if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(pt)}); + if (bad_type) return sema.fail(block, input_src, "unsupported type '{f}' for 'c' constraint", .{uncasted_arg_ty.fmt(zcu)}); } needed_capacity += (constraint.len + name.len + (2 + 3)) / 4; inputs[arg_i] = .{ .c = constraint, .n = name }; @@ -15598,7 +15598,7 @@ fn zirCmpEq( if (lhs_ty_tag == .null or rhs_ty_tag == .null) { const non_null_type = if (lhs_ty_tag == .null) rhs_ty else lhs_ty; - return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(pt)}); + return sema.fail(block, src, "comparison of '{f}' with null", .{non_null_type.fmt(zcu)}); } if (lhs_ty_tag == .@"union" and (rhs_ty_tag == .enum_literal or rhs_ty_tag == .@"enum")) { @@ -15654,7 +15654,7 @@ fn analyzeCmpUnionTag( const msg = msg: { const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); errdefer msg.destroy(sema.gpa); - try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(pt)}); + try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{f}' is not a tagged union", .{union_ty.fmt(zcu)}); break :msg msg; }; return sema.failWithOwnedErrorMsg(block, msg); @@ -15738,7 +15738,7 @@ fn analyzeCmp( const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } }); if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) { return sema.fail(block, src, "operator {s} not allowed for type '{f}'", .{ - compareOperatorName(op), resolved_type.fmt(pt), + compareOperatorName(op), resolved_type.fmt(zcu), }); } 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. try sema.ensureLayoutResolved(ty, operand_src, .size_of); switch (ty.classify(zcu)) { .no_possible_value, - => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(pt)}), + => return sema.fail(block, operand_src, "no size available for uninstantiable type '{f}'", .{ty.fmt(zcu)}), .partially_comptime, .fully_comptime, - => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(pt)}), + => return sema.fail(block, operand_src, "no size available for comptime-only type '{f}'", .{ty.fmt(zcu)}), .one_possible_value => { assert(ty.abiSize(zcu) == 0); @@ -15871,7 +15871,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A operand_ty.zigTypeTag(zcu) != .error_set and operand_ty.zigTypeTag(zcu) != .@"enum") { - return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(pt)}); + return sema.fail(block, operand_src, "no bit size available for type '{f}'", .{operand_ty.fmt(zcu)}); } try sema.ensureLayoutResolved(operand_ty, operand_src, .size_of); 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 block, src, "bit shifting operation expected integer type, found '{f}'", - .{operand.fmt(pt)}, + .{operand.fmt(zcu)}, ); } @@ -17413,7 +17413,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air if (uncasted_ty.isVector(zcu)) { if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) { return sema.fail(block, operand_src, "boolean not operation on type '{f}'", .{ - uncasted_ty.fmt(pt), + uncasted_ty.fmt(zcu), }); } return analyzeBitNot(sema, block, uncasted_operand, src); @@ -17589,7 +17589,7 @@ fn checkSentinelType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !voi const pt = sema.pt; const zcu = pt.zcu; if (!ty.isSelfComparable(zcu, true)) { - return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(pt)}); + return sema.fail(block, src, "non-scalar sentinel type '{f}'", .{ty.fmt(zcu)}); } } @@ -17641,7 +17641,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { switch (ty.zigTypeTag(zcu)) { .error_set, .error_union, .undefined => return, else => return sema.fail(block, src, "expected error union type, found '{f}'", .{ - ty.fmt(pt), + ty.fmt(zcu), }), } } @@ -17779,7 +17779,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! const zcu = pt.zcu; if (err_union_ty.zigTypeTag(zcu) != .error_union) { return sema.failWithOwnedErrorMsg(parent_block, msg: { - const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, err_union_ty); 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 const zcu = pt.zcu; if (err_union_ty.zigTypeTag(zcu) != .error_union) { return sema.failWithOwnedErrorMsg(parent_block, msg: { - const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "expected error union type, found '{f}'", .{err_union_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, err_union_ty); try sema.errNote(operand_src, msg, "consider omitting 'try'", .{}); @@ -18046,7 +18046,7 @@ fn zirRetImplicit( if (base_tag == .noreturn) { const msg = msg: { const msg = try sema.errMsg(ret_ty_src, "function declared '{f}' implicitly returns", .{ - sema.fn_ret_ty.fmt(pt), + sema.fn_ret_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{}); @@ -18056,7 +18056,7 @@ fn zirRetImplicit( } else if (base_tag != .void) { const msg = msg: { const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{f}' implicitly returns", .{ - sema.fn_ret_ty.fmt(pt), + sema.fn_ret_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); 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 if (host_size != 0) { try sema.ensureLayoutResolved(elem_ty, elem_ty_src, .bit_ptr_child); if (elem_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(pt)}); + const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{f}'", .{elem_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.explainWhyTypeIsUnpackable(msg, elem_ty_src, reason); break :msg msg; @@ -18475,12 +18475,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const elem_bit_size = elem_ty.bitSize(zcu); if (bit_offset >= host_size * 8) { 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", .{ - elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size, + elem_ty.fmt(zcu), bit_offset, bit_offset - host_size * 8, host_size, }); } if (elem_bit_size > host_size * 8 - bit_offset) { 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", .{ - elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size, + elem_ty.fmt(zcu), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size, }); } } @@ -18490,7 +18490,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{}); } } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") { - return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}); + return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)}); } const ty = try pt.ptrType(.{ @@ -18652,7 +18652,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; const union_ty = try sema.resolveType(block, ty_src, extra.union_type); if (union_ty.zigTypeTag(pt.zcu) != .@"union") { - return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(pt)}); + return sema.fail(block, ty_src, "expected union type, found '{f}'", .{union_ty.fmt(zcu)}); } union_ty.assertHasLayout(zcu); // from a previous `field_type_ref` instruction const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_names }); @@ -18784,7 +18784,7 @@ fn zirStructInit( if (field_ty.classify(zcu) == .no_possible_value) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{f}' declared here", .{ @@ -19573,7 +19573,7 @@ fn fieldType( else => {}, } return sema.fail(block, ty_src, "expected struct or union; found '{f}'", .{ - cur_ty.fmt(pt), + cur_ty.fmt(zcu), }); } } @@ -19627,7 +19627,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const ty = try sema.resolveType(block, operand_src, inst_data.operand); try sema.ensureLayoutResolved(ty, operand_src, .align_of); if (ty.isNoReturn(zcu)) { - return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(sema.pt)}); + return sema.fail(block, operand_src, "no align available for uninstantiable type '{f}'", .{ty.fmt(zcu)}); } return .fromValue(try pt.intValue(.comptime_int, ty.abiAlignment(zcu).toByteUnits().?)); } @@ -19702,7 +19702,7 @@ fn zirAbs( block, operand_src, "expected integer, float, or vector of either integers or floats, found '{f}'", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ), }; @@ -19763,7 +19763,7 @@ fn unaryMath( block, operand_src, "expected vector of floats or float type, found '{f}'", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ), } @@ -19804,9 +19804,9 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air }, .@"enum" => operand_ty, .@"union" => operand_ty.unionTagType(zcu) orelse - return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(pt)}), + return sema.fail(block, src, "union '{f}' is untagged", .{operand_ty.fmt(zcu)}), else => return sema.fail(block, operand_src, "expected enum or union; found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }), }; 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 const field_index = enum_ty.enumTagFieldIndex(val, zcu) orelse { const msg = msg: { const msg = try sema.errMsg(src, "no field with value '{f}' in enum '{f}'", .{ - val.fmtValueSema(pt, sema), enum_ty.fmt(pt), + val.fmtValueSema(sema), enum_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.errNote(enum_ty.srcLoc(zcu), msg, "declared here", .{}); @@ -20026,7 +20026,7 @@ fn zirReifyPointer( }, .@"opaque" => switch (size) { .one => {}, - .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}), + .many, .c, .slice => return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(zcu)}), }, else => {}, } @@ -20962,7 +20962,7 @@ fn zirReifySpirvType( if (sampled_type.toIntern() != .void_type and (!sampled_type.hasRuntimeBits(zcu) or (!sampled_type.isRuntimeFloat() and !sampled_type.isInt(zcu)))) { - return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(pt) }); + return sema.fail(block, operand_src, "invalid '{t}' field value '{f}'", .{ usage_tag, sampled_type.fmt(zcu) }); } if (target.os.tag == .vulkan) { @@ -20994,7 +20994,7 @@ fn zirReifySpirvType( block, operand_src, "image 'format' '.{t}' does not match '{t}' type '{f}' under the 'vulkan' OS", - .{ format, usage_tag, sampled_type.fmt(pt) }, + .{ format, usage_tag, sampled_type.fmt(zcu) }, ); } } @@ -21017,7 +21017,7 @@ fn zirReifySpirvType( .sampled_image => blk: { const image_ty = Value.fromInterned(union_val.val).toType(); if (image_ty.zigTypeTag(zcu) != .spirv or ip.loadSpirvType(image_ty.toIntern()).flags.tag != .image) { - return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(pt)}); + return sema.fail(block, operand_src, "'sampled_image' element must be an @SpirvType image, found '{f}'", .{image_ty.fmt(zcu)}); } const image_info = ip.loadSpirvType(image_ty.toIntern()).flags; if (image_info.usage != .sampled) { @@ -21077,6 +21077,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In } fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { + const zcu = sema.pt.zcu; const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; const src = block.nodeOffset(extra.node); 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 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); try sema.ensureLayoutResolved(arg_ty, ty_src, .parameter); - if (!arg_ty.validateExtern(.param_ty, sema.pt.zcu)) { + if (!arg_ty.validateExtern(.param_ty, zcu)) { const msg = msg: { - const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(sema.pt)}); + const msg = try sema.errMsg(ty_src, "cannot get '{f}' from variadic argument", .{arg_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); 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 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); const ty = try sema.resolveType(block, ty_src, inst_data.operand); - const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(pt)}, .no_embedded_nulls); + const type_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{f}", .{ty.fmt(zcu)}, .no_embedded_nulls); return sema.addNullTerminatedStrLit(type_name); } @@ -21179,7 +21180,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro switch (dest_scalar_ty.zigTypeTag(zcu)) { .comptime_int, .int => {}, - else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}), + else => return sema.fail(block, src, "expected integer result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}), } try sema.checkFloatType(block, operand_src, operand_scalar_ty); @@ -21260,7 +21261,7 @@ fn zirRoundCast( block, operand_src, "expected float or vector type, found '{f}'", - .{operand_ty.fmt(pt)}, + .{operand_ty.fmt(zcu)}, ), } @@ -21294,7 +21295,7 @@ fn zirRoundCast( block, src, "expected integer, float, or vector of either integers or floats, found '{f}'", - .{dest_ty.fmt(pt)}, + .{dest_ty.fmt(zcu)}, ), } @@ -21358,7 +21359,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro switch (dest_scalar_ty.zigTypeTag(zcu)) { .comptime_float, .float => {}, - else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(pt)}), + else => return sema.fail(block, src, "expected float result type, found '{f}'", .{dest_scalar_ty.fmt(zcu)}), } _ = try sema.checkIntType(block, operand_src, operand_scalar_ty); @@ -21418,7 +21419,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! if (ptr_ty.isSlice(zcu)) { const msg = msg: { - const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{f}'", .{ptr_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "slice length cannot be inferred from address", .{}); break :msg msg; @@ -21491,7 +21492,7 @@ fn ptrFromIntVal( } const addr = operand_val.toUnsignedInt(zcu); if (!ptr_ty.isAllowzeroPtr(zcu) and addr == 0) - return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(pt)}); + return sema.fail(block, operand_src, "pointer type '{f}' does not allow address zero", .{ptr_ty.fmt(zcu)}); if (addr != 0 and ptr_align != .none) { const masked_addr = if (ptr_ty.childType(zcu).fnPtrMaskOrNull(zcu)) |mask| addr & mask @@ -21499,7 +21500,7 @@ fn ptrFromIntVal( addr; if (!ptr_align.check(masked_addr)) { - return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(pt)}); + return sema.fail(block, operand_src, "pointer type '{f}' requires aligned address", .{ptr_ty.fmt(zcu)}); } } @@ -21544,8 +21545,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData errdefer msg.destroy(sema.gpa); const dest_payload_ty = dest_ty.errorUnionPayload(zcu); const operand_payload_ty = operand_ty.errorUnionPayload(zcu); - try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(pt)}); - try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(pt)}); + try sema.errNote(src, msg, "destination payload is '{f}'", .{dest_payload_ty.fmt(zcu)}); + try sema.errNote(src, msg, "operand payload is '{f}'", .{operand_payload_ty.fmt(zcu)}); try addDeclaredHereNote(sema, msg, dest_ty); try addDeclaredHereNote(sema, msg, operand_ty); break :msg msg; @@ -21619,7 +21620,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData if (result == .disjoint and !(operand_tag == .error_union and dest_tag == .error_union)) { return sema.fail(block, src, "error sets '{f}' and '{f}' have no common errors", .{ - operand_err_ty.fmt(pt), dest_err_ty.fmt(pt), + operand_err_ty.fmt(zcu), dest_err_ty.fmt(zcu), }); } @@ -21644,7 +21645,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData if (result != .superset and !dest_err_ty.errorSetHasField(err_name, zcu)) { return sema.fail(block, src, "'error.{f}' not a member of error set '{f}'", .{ - err_name.fmt(ip), dest_err_ty.fmt(pt), + err_name.fmt(ip), dest_err_ty.fmt(zcu), }); } @@ -21809,7 +21810,7 @@ fn ptrCastFull( if (src_elem_ty.zigTypeTag(zcu) == .@"opaque") { return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "cannot infer length of slice of '{f}' from pointer to opaque type '{f}' with unknown size", .{ - dest_elem_ty.fmt(pt), src_elem_ty.fmt(pt), + dest_elem_ty.fmt(zcu), src_elem_ty.fmt(zcu), }); errdefer msg.destroy(gpa); try sema.addDeclaredHereNote(msg, src_elem_ty); @@ -21820,14 +21821,14 @@ fn ptrCastFull( const dest_elem_size = dest_elem_ty.abiSize(zcu); if (dest_elem_size == 0) { return sema.fail(block, src, "cannot infer length of slice of zero-bit '{f}' from '{f}'", .{ - dest_elem_ty.fmt(pt), operand_ty.fmt(pt), + dest_elem_ty.fmt(zcu), operand_ty.fmt(zcu), }); } if (opt_src_len) |src_len| { const bytes = src_len * src_elem_size; const dest_len = std.math.divExact(u64, bytes, dest_elem_size) catch switch (src_info.flags.size) { .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}), - .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(pt)}), + .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{Type.fromInterned(src_info.child).fmt(zcu)}), else => unreachable, }; break :len .{ .constant = dest_len }; @@ -21846,7 +21847,7 @@ fn ptrCastFull( // The result value will have `dest_len * dest_base_per_elem` values of type `dest_base_ty`. if (dest_base_ty.toIntern() != src_base_ty.toIntern()) { return sema.fail(block, src, "cannot infer length of comptime-only '{f}' from incompatible '{f}'", .{ - dest_ty.fmt(pt), operand_ty.fmt(pt), + dest_ty.fmt(zcu), operand_ty.fmt(zcu), }); } // `src_base_ty` is comptime-only, so `src_elem_ty` is comptime-only, so `operand_ty` is @@ -21855,7 +21856,7 @@ fn ptrCastFull( const base_len = src_len * src_base_per_elem; const dest_len = std.math.divExact(u64, base_len, dest_base_per_elem) catch switch (src_info.flags.size) { .slice => return sema.fail(block, src, "slice length '{d}' does not divide exactly into destination elements", .{src_len}), - .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(pt)}), + .one => return sema.fail(block, src, "type '{f}' does not divide exactly into destination elements", .{src_elem_ty.fmt(zcu)}), else => unreachable, }; break :len .{ .constant = dest_len }; @@ -21917,7 +21918,7 @@ fn ptrCastFull( if (imc_res == .ok) break :check_child; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "pointer element type '{f}' cannot coerce into element type '{f}'", .{ - src_child.fmt(pt), dest_child.fmt(pt), + src_child.fmt(zcu), dest_child.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try imc_res.report(sema, src, msg); @@ -21944,12 +21945,12 @@ fn ptrCastFull( return sema.failWithOwnedErrorMsg(block, msg: { const msg = if (src_info.sentinel == .none) blk: { break :blk try sema.errMsg(src, "destination pointer requires '{f}' sentinel", .{ - Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema), + Value.fromInterned(dest_info.sentinel).fmtValueSema(sema), }); } else blk: { break :blk try sema.errMsg(src, "pointer sentinel '{f}' cannot coerce into pointer sentinel '{f}'", .{ - Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema), - Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema), + Value.fromInterned(src_info.sentinel).fmtValueSema(sema), + Value.fromInterned(dest_info.sentinel).fmtValueSema(sema), }); }; errdefer msg.destroy(sema.gpa); @@ -21990,8 +21991,8 @@ fn ptrCastFull( return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(src, "'{f}' could have null values which are illegal in type '{f}'", .{ - operand_ty.fmt(pt), - dest_ty.fmt(pt), + operand_ty.fmt(zcu), + dest_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{}); @@ -22018,10 +22019,10 @@ fn ptrCastFull( const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation}); errdefer msg.destroy(sema.gpa); try sema.errNote(operand_src, msg, "'{f}' has alignment '{d}'", .{ - operand_ty.fmt(pt), src_align.toByteUnits() orelse 0, + operand_ty.fmt(zcu), src_align.toByteUnits() orelse 0, }); try sema.errNote(src, msg, "'{f}' has alignment '{d}'", .{ - dest_ty.fmt(pt), dest_align.toByteUnits() orelse 0, + dest_ty.fmt(zcu), dest_align.toByteUnits() orelse 0, }); try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{}); break :msg msg; @@ -22035,10 +22036,10 @@ fn ptrCastFull( const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation}); errdefer msg.destroy(sema.gpa); try sema.errNote(operand_src, msg, "'{f}' has address space '{s}'", .{ - operand_ty.fmt(pt), @tagName(src_info.flags.address_space), + operand_ty.fmt(zcu), @tagName(src_info.flags.address_space), }); try sema.errNote(src, msg, "'{f}' has address space '{s}'", .{ - dest_ty.fmt(pt), @tagName(dest_info.flags.address_space), + dest_ty.fmt(zcu), @tagName(dest_info.flags.address_space), }); try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{}); break :msg msg; @@ -22104,7 +22105,7 @@ fn ptrCastFull( if (operand_val.isNull(zcu)) { if (!dest_ty.ptrAllowsZero(zcu)) { - return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)}); + return sema.fail(block, operand_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)}); } if (dest_ty.zigTypeTag(zcu) == .optional) { 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 if (operand_info.signedness != dest_info.signedness) { return sema.fail(block, operand_src, "expected {s} integer type, found '{f}'", .{ - @tagName(dest_info.signedness), operand_ty.fmt(pt), + @tagName(dest_info.signedness), operand_ty.fmt(zcu), }); } if (dest_info.bits >= operand_info.bits) { @@ -22503,7 +22504,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai block, operand_src, "@byteSwap requires the number of bits to be evenly divisible by 8, but {f} has {d} bits", - .{ scalar_ty.fmt(pt), bits }, + .{ scalar_ty.fmt(zcu), bits }, ); } if (sema.resolveValue(operand)) |operand_val| { @@ -22553,7 +22554,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 const ip = &zcu.intern_pool; switch (ty.zigTypeTag(zcu)) { .@"struct" => {}, - else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, ty_src, "expected struct type, found '{f}'", .{ty.fmt(zcu)}), } const field_index = if (ty.isTuple(zcu)) blk: { @@ -22588,7 +22589,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com const zcu = pt.zcu; switch (ty.zigTypeTag(zcu)) { .@"struct", .@"enum", .@"union", .@"opaque" => return, - else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{f}'", .{ty.fmt(zcu)}), } } @@ -22599,7 +22600,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr switch (ty.zigTypeTag(zcu)) { .comptime_int => return true, .int => return false, - else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, src, "expected integer type, found '{f}'", .{ty.fmt(zcu)}), } } @@ -22654,7 +22655,7 @@ fn checkPtrOperand( const msg = try sema.errMsg( ty_src, "expected pointer, found '{f}'", - .{ty.fmt(pt)}, + .{ty.fmt(zcu)}, ); errdefer msg.destroy(sema.gpa); @@ -22667,7 +22668,7 @@ fn checkPtrOperand( .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return, else => {}, } - return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)}); + return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)}); } fn checkPtrType( @@ -22686,7 +22687,7 @@ fn checkPtrType( const msg = try sema.errMsg( ty_src, "expected pointer type, found '{f}'", - .{ty.fmt(pt)}, + .{ty.fmt(zcu)}, ); errdefer msg.destroy(sema.gpa); @@ -22699,7 +22700,7 @@ fn checkPtrType( .optional => if (ty.childType(zcu).zigTypeTag(zcu) == .pointer) return, else => {}, } - return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(pt)}); + return sema.fail(block, ty_src, "expected pointer type, found '{f}'", .{ty.fmt(zcu)}); } fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { @@ -22712,7 +22713,7 @@ fn checkLogicalPtrOperation(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ const as = ty.ptrAddressSpace(zcu); if (target_util.shouldBlockPointerOps(target, as)) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(pt)}); + const msg = try sema.errMsg(src, "illegal operation on logical pointer of type '{f}'", .{ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote( src, @@ -22761,9 +22762,9 @@ fn checkLogicalPtrCast( }, else => null, } orelse return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(pt), dest_ty.fmt(pt) }); + const msg = try sema.errMsg(src, "cannot cast pointer '{f}' to '{f}'", .{ operand_ty.fmt(zcu), dest_ty.fmt(zcu) }); errdefer msg.destroy(sema.gpa); - try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(pt), src_child.fmt(pt) }); + try sema.errNote(src, msg, "'{f}' must appear at offset 0 inside '{f}'", .{ dest_child.fmt(zcu), src_child.fmt(zcu) }); break :msg msg; }); } @@ -22782,7 +22783,7 @@ fn checkVectorElemType( .optional, .pointer => if (ty.isPtrAtRuntime(zcu)) return, else => {}, } - return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(pt)}); + return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{f}'", .{ty.fmt(zcu)}); } fn checkFloatType( @@ -22795,7 +22796,7 @@ fn checkFloatType( const zcu = pt.zcu; switch (ty.zigTypeTag(zcu)) { .comptime_int, .comptime_float, .float => {}, - else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, ty_src, "expected float type, found '{f}'", .{ty.fmt(zcu)}), } } @@ -22813,7 +22814,7 @@ fn checkNumericType( .comptime_float, .float, .comptime_int, .int => {}, else => |t| return sema.fail(block, ty_src, "expected number, found '{t}'", .{t}), }, - else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, ty_src, "expected number, found '{f}'", .{ty.fmt(zcu)}), } } @@ -22849,7 +22850,7 @@ fn checkAtomicPtrOperand( block, elem_ty_src, "expected bool, integer, float, enum, packed struct, or pointer type; found '{f}'", - .{elem_ty.fmt(pt)}, + .{elem_ty.fmt(zcu)}, ), }; @@ -22910,12 +22911,12 @@ fn checkIntOrVector( switch (elem_ty.zigTypeTag(zcu)) { .int => return elem_ty, else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{ - elem_ty.fmt(pt), + elem_ty.fmt(zcu), }), } }, else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }), } } @@ -22935,12 +22936,12 @@ fn checkIntOrVectorAllowComptime( switch (elem_ty.zigTypeTag(zcu)) { .int, .comptime_int => return elem_ty, else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{f}'", .{ - elem_ty.fmt(pt), + elem_ty.fmt(zcu), }), } }, else => return sema.fail(block, operand_src, "expected integer or vector, found '{f}'", .{ - operand_ty.fmt(pt), + operand_ty.fmt(zcu), }), } } @@ -23031,7 +23032,7 @@ fn checkVectorizableBinaryOperands( } else { const msg = msg: { const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{f}' and '{f}'", .{ - lhs_ty.fmt(pt), rhs_ty.fmt(pt), + lhs_ty.fmt(zcu), rhs_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); if (lhs_is_vector) { @@ -23178,7 +23179,7 @@ fn zirCmpxchg( block, elem_ty_src, "expected bool, integer, enum, packed struct, or pointer type; found '{f}'", - .{elem_ty.fmt(pt)}, + .{elem_ty.fmt(zcu)}, ); } const uncasted_ptr = sema.resolveInst(extra.ptr); @@ -23258,7 +23259,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I switch (dest_ty.zigTypeTag(zcu)) { .array, .vector => {}, - else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(pt)}), + else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(zcu)}), } const operand = sema.resolveInst(extra.rhs); @@ -23307,7 +23308,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const zcu = pt.zcu; if (operand_ty.zigTypeTag(zcu) != .vector) { - return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)}); + return sema.fail(block, operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)}); } const scalar_ty = operand_ty.childType(zcu); @@ -23317,13 +23318,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) { .int, .bool => {}, else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{f}'", .{ - @tagName(operation), operand_ty.fmt(pt), + @tagName(operation), operand_ty.fmt(zcu), }), }, .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) { .int, .float => {}, else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{f}'", .{ - @tagName(operation), operand_ty.fmt(pt), + @tagName(operation), operand_ty.fmt(zcu), }), }, } @@ -23378,7 +23379,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) { .array, .vector => sema.typeOf(mask).arrayLen(zcu), - else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(pt)}), + else => return sema.fail(block, mask_src, "expected vector or array, found '{f}'", .{sema.typeOf(mask).fmt(zcu)}), }; mask_ty = try pt.vectorType(.{ .len = @intCast(mask_len), @@ -23411,7 +23412,7 @@ fn analyzeShuffle( .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)), .undefined => 0, else => return sema.fail(block, a_src, "expected vector of '{f}', found '{f}'", .{ - elem_ty.fmt(pt), sema.typeOf(a_uncoerced).fmt(pt), + elem_ty.fmt(zcu), sema.typeOf(a_uncoerced).fmt(zcu), }), }; const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() }); @@ -23422,7 +23423,7 @@ fn analyzeShuffle( .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)), .undefined => 0, else => return sema.fail(block, b_src, "expected vector of '{f}', found '{f}'", .{ - elem_ty.fmt(pt), sema.typeOf(b_uncoerced).fmt(pt), + elem_ty.fmt(zcu), sema.typeOf(b_uncoerced).fmt(zcu), }), }; const b_ty = try pt.vectorType(.{ .len = b_len, .child = elem_ty.toIntern() }); @@ -23461,7 +23462,7 @@ fn analyzeShuffle( if (idx >= a_len) return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx}); errdefer msg.destroy(sema.gpa); - try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(pt) }); + try sema.errNote(a_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, a_ty.fmt(zcu) }); if (idx < b_len) { try sema.errNote(b_src, msg, "use '~@as(u32, {d})' to index into second vector given here", .{idx}); } @@ -23474,7 +23475,7 @@ fn analyzeShuffle( if (idx >= b_len) return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(mask_src, "mask element at index '{d}' selects out-of-bounds index", .{mask_idx}); errdefer msg.destroy(sema.gpa); - try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(pt) }); + try sema.errNote(b_src, msg, "index '{d}' exceeds bounds of '{f}' given here", .{ idx, b_ty.fmt(zcu) }); break :msg msg; }); } @@ -23576,7 +23577,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) { .vector, .array => pred_ty.arrayLen(zcu), - else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(pt)}), + else => return sema.fail(block, pred_src, "expected vector or array, found '{f}'", .{pred_ty.fmt(zcu)}), }; const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64)); @@ -23834,7 +23835,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. switch (ty.scalarType(zcu).zigTypeTag(zcu)) { .comptime_float, .float => {}, - else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(pt)}), + else => return sema.fail(block, src, "expected vector of floats or float type, found '{f}'", .{ty.fmt(zcu)}), } const runtime_src = if (maybe_mulend1) |mulend1_val| rs: { @@ -23932,7 +23933,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError const args_ty = sema.typeOf(args); if (!args_ty.isTuple(zcu)) { - return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(pt)}); + return sema.fail(block, args_src, "expected a tuple, found '{f}'", .{args_ty.fmt(zcu)}); } 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 }; const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu); if (parent_ptr_info.flags.size != .one) { - return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(pt)}); + return sema.fail(block, inst_src, "expected single pointer type, found '{f}'", .{parent_ptr_ty.fmt(zcu)}); } const parent_ty: Type = .fromInterned(parent_ptr_info.child); try sema.ensureLayoutResolved(parent_ty, inst_src, .field_used); switch (parent_ty.zigTypeTag(zcu)) { .@"struct", .@"union" => {}, - else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(pt)}), + else => return sema.fail(block, inst_src, "expected pointer to struct or union type, found '{f}'", .{parent_ptr_ty.fmt(zcu)}), } 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 if (field.index != field_index) { return sema.fail(block, inst_src, "field '{f}' has index '{d}' but pointer value is index '{d}' of struct '{f}'", .{ - field_name.fmt(ip), field_index, field.index, parent_ty.fmt(pt), + field_name.fmt(ip), field_index, field.index, parent_ty.fmt(zcu), }); } 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 const msg = try sema.errMsg(inst_src, "@fieldParentPtr increases pointer alignment", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(inst_src, msg, "parent pointer type '{f}' has alignment '{d}'", .{ - parent_ptr_ty.fmt(pt), + parent_ptr_ty.fmt(zcu), parent_ptr_ty.abiAlignment(zcu), }); if (parent_ty.isTuple(zcu)) { @@ -24240,7 +24241,7 @@ fn analyzeMinMax( try sema.checkNumericType(block, operand_src, operand_ty); if (operand_ty.zigTypeTag(zcu) != .vector) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_src, "expected vector, found '{f}'", .{operand_ty.fmt(zcu)}); errdefer msg.destroy(zcu.gpa); try sema.errNote(operand_srcs[0], msg, "vector operand here", .{}); break :msg msg; @@ -24248,7 +24249,7 @@ fn analyzeMinMax( } if (operand_ty.vectorLen(zcu) != vec_len) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(pt) }); + const msg = try sema.errMsg(operand_src, "expected vector of length '{d}', found '{f}'", .{ vec_len, operand_ty.fmt(zcu) }); errdefer msg.destroy(zcu.gpa); try sema.errNote(operand_srcs[0], msg, "vector of length '{d}' here", .{vec_len}); break :msg msg; @@ -24262,7 +24263,7 @@ fn analyzeMinMax( try sema.checkNumericType(block, operand_src, operand_ty); if (operand_ty.zigTypeTag(zcu) == .vector) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(pt)}); + const msg = try sema.errMsg(operand_srcs[0], "expected vector, found '{f}'", .{first_operand_ty.fmt(zcu)}); errdefer msg.destroy(zcu.gpa); try sema.errNote(operand_src, msg, "vector operand here", .{}); break :msg msg; @@ -24580,10 +24581,10 @@ fn zirMemcpy( const msg = try sema.errMsg(src, "unknown copy length", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{ - dest_ty.fmt(pt), + dest_ty.fmt(zcu), }); try sema.errNote(src_src, msg, "source type '{f}' provides no length", .{ - src_ty.fmt(pt), + src_ty.fmt(zcu), }); break :msg msg; }; @@ -24610,7 +24611,7 @@ fn zirMemcpy( const msg = try sema.errMsg( src, "pointer element type '{f}' cannot coerce into element type '{f}'", - .{ src_elem_ty.fmt(pt), dest_elem_ty.fmt(pt) }, + .{ src_elem_ty.fmt(zcu), dest_elem_ty.fmt(zcu) }, ); errdefer msg.destroy(sema.gpa); try imc.report(sema, src, msg); @@ -24629,10 +24630,10 @@ fn zirMemcpy( const msg = try sema.errMsg(src, "non-matching copy lengths", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(dest_src, msg, "length {f} here", .{ - dest_len_val.fmtValueSema(pt, sema), + dest_len_val.fmtValueSema(sema), }); try sema.errNote(src_src, msg, "length {f} here", .{ - src_len_val.fmtValueSema(pt, sema), + src_len_val.fmtValueSema(sema), }); break :msg msg; }; @@ -24850,7 +24851,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void const msg = try sema.errMsg(src, "unknown @memset length", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(dest_src, msg, "destination type '{f}' provides no length", .{ - dest_ptr_ty.fmt(pt), + dest_ptr_ty.fmt(zcu), }); break :msg msg; }); @@ -24896,7 +24897,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void if (comptime_only_elem) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot store comptime-only element '{f}' at runtime", .{dest_elem_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(dest_src, msg, "operation is runtime due to destination pointer", .{}); break :msg msg; @@ -25267,16 +25268,16 @@ fn zirBuiltinExtern( if (!elem_ty.validateExtern(.other, zcu)) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)}); + const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); - try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(pt)}); + try sema.errNote(ty_src, msg, "pointer element type '{f}' is not extern compatible", .{elem_ty.fmt(zcu)}); try sema.explainWhyTypeIsNotExtern(msg, ty_src, elem_ty, .other); break :msg msg; }); } if (elem_ty.zigTypeTag(zcu) == .@"fn" and !ptr_info.flags.is_const) { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(pt)}); + const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{f}'", .{ptr_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(ty_src, msg, "pointer to extern function must be 'const'", .{}); break :msg msg; @@ -25540,7 +25541,7 @@ fn zirFloatOpResultType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended. block, operand_src, "expected vector of floats or float type, found '{f}'", - .{float_ty.fmt(sema.pt)}, + .{float_ty.fmt(zcu)}, ), } @@ -25597,7 +25598,7 @@ pub fn validateVarType( if (is_extern) { if (!var_ty.validateExtern(.other, zcu)) { const msg = msg: { - const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "extern variable cannot have type '{f}'", .{var_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other); break :msg msg; @@ -25610,7 +25611,7 @@ pub fn validateVarType( block, src, "non-extern variable with opaque type '{f}'", - .{var_ty.fmt(pt)}, + .{var_ty.fmt(zcu)}, ); } } @@ -25618,7 +25619,7 @@ pub fn validateVarType( if (!var_ty.comptimeOnly(zcu)) return; const msg = msg: { - const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "variable of type '{f}' must be const or comptime", .{var_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.explainWhyTypeIsComptime(msg, src, var_ty); @@ -25667,7 +25668,7 @@ fn explainWhyTypeIsComptime( .optional => try sema.explainWhyTypeIsComptime(msg, src, ty.optionalChild(zcu)), .error_union => try sema.explainWhyTypeIsComptime(msg, src, ty.errorUnionPayload(zcu)), - .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(pt)}), + .@"fn" => try sema.errNote(src, msg, "use '*const {f}' for a function pointer type", .{ty.fmt(zcu)}), .type => try sema.errNote(src, msg, "types are not available at runtime", .{}), .@"struct" => if (zcu.typeToStruct(ty)) |struct_type| { @@ -25689,7 +25690,7 @@ fn explainWhyTypeIsComptime( if (field_val_ip != .none) continue; const field_ty: Type = .fromInterned(field_ty_ip); if (!field_ty.comptimeOnly(zcu)) continue; - try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(pt)}); + try sema.errNote(src, msg, "tuple requires comptime because of field of type '{f}'", .{field_ty.fmt(zcu)}); return sema.explainWhyTypeIsComptime(msg, src, field_ty); } unreachable; @@ -25750,7 +25751,7 @@ pub fn explainWhyTypeIsNotExtern( } }, - .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(pt)}), + .float => try sema.errNote(src_loc, msg, "'{f}' is not extern compatible on this target", .{ty.fmt(zcu)}), .pointer => if (ty.isSlice(zcu)) { try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); } else { @@ -25782,7 +25783,7 @@ pub fn explainWhyTypeIsNotExtern( }, .explicit => { const tag_ty: Type = .fromInterned(enum_obj.int_tag_type); - try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(pt)}); + try sema.errNote(ty.srcLoc(zcu), msg, "enum tag type '{f}' is not extern compatible", .{tag_ty.fmt(zcu)}); try sema.explainWhyTypeIsNotExtern(msg, ty.srcLoc(zcu), tag_ty, position); }, } @@ -25800,7 +25801,7 @@ pub fn explainWhyTypeIsNotExtern( .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed struct has unspecified signedness", .{}), .explicit => { const backing_int_ty: Type = .fromInterned(struct_obj.packed_backing_int_type); - try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)}); + try sema.errNote(src_loc, msg, "packed struct backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)}); try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position); }, }, @@ -25815,7 +25816,7 @@ pub fn explainWhyTypeIsNotExtern( .auto => try sema.errNote(src_loc, msg, "inferred backing integer of packed union has unspecified signedness", .{}), .explicit => { const backing_int_ty: Type = .fromInterned(union_obj.packed_backing_int_type); - try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(pt)}); + try sema.errNote(src_loc, msg, "packed union backing integer type '{f}' is not extern compatible", .{backing_int_ty.fmt(zcu)}); try sema.explainWhyTypeIsNotExtern(msg, src_loc, backing_int_ty, position); }, }, @@ -26269,7 +26270,7 @@ fn fieldVal( block, field_name_src, "no member named '{f}' in '{f}'", - .{ field_name.fmt(ip), object_ty.fmt(pt) }, + .{ field_name.fmt(ip), object_ty.fmt(zcu) }, ); } }, @@ -26293,7 +26294,7 @@ fn fieldVal( block, field_name_src, "no member named '{f}' in '{f}'", - .{ field_name.fmt(ip), object_ty.fmt(pt) }, + .{ field_name.fmt(ip), object_ty.fmt(zcu) }, ); } } @@ -26317,7 +26318,7 @@ fn fieldVal( }, .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) { return sema.fail(block, src, "no error named '{f}' in '{f}'", .{ - field_name.fmt(ip), child_type.fmt(pt), + field_name.fmt(ip), child_type.fmt(zcu), }); } else child_type, .simple_type => |t| { @@ -26365,7 +26366,7 @@ fn fieldVal( return sema.failWithBadMemberAccess(block, child_type, src, field_name); }, else => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(pt)}); + const msg = try sema.errMsg(src, "type '{f}' has no members", .{child_type.fmt(zcu)}); errdefer msg.destroy(sema.gpa); if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{}); if (child_type.zigTypeTag(zcu) == .array) try sema.errNote(src, msg, "array values have 'len' member", .{}); @@ -26525,7 +26526,7 @@ fn fieldPtr( const object_ptr_ty = sema.typeOf(object_ptr); const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) { .pointer => object_ptr_ty.childType(zcu), - else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(pt)}), + else => return sema.fail(block, object_ptr_src, "expected pointer, found '{f}'", .{object_ptr_ty.fmt(zcu)}), }; // Zig allows dereferencing a single pointer during field lookup. Note that @@ -26580,7 +26581,7 @@ fn fieldPtr( block, field_name_src, "no member named '{f}' in '{f}'", - .{ field_name.fmt(ip), object_ty.fmt(pt) }, + .{ field_name.fmt(ip), object_ty.fmt(zcu) }, ); } }, @@ -26617,7 +26618,7 @@ fn fieldPtr( block, field_name_src, "no member named '{f}' in '{f}'", - .{ field_name.fmt(ip), object_ty.fmt(pt) }, + .{ field_name.fmt(ip), object_ty.fmt(zcu) }, ); } }, @@ -26641,7 +26642,7 @@ fn fieldPtr( }, .error_set_type => |err_set| if (err_set.nameIndex(ip, field_name) == null) { return sema.fail(block, src, "no error named '{f}' in '{f}'", .{ - field_name.fmt(ip), child_type.fmt(pt), + field_name.fmt(ip), child_type.fmt(zcu), }); } else child_type, .simple_type => |t| { @@ -26688,7 +26689,7 @@ fn fieldPtr( } return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); }, - else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(pt)}), + else => return sema.fail(block, src, "type '{f}' has no members", .{child_type.fmt(zcu)}), } }, .@"struct" => { @@ -26745,7 +26746,7 @@ fn fieldCallBind( const inner_ty = if (raw_ptr_ty.zigTypeTag(zcu) == .pointer and (raw_ptr_ty.ptrSize(zcu) == .one or raw_ptr_ty.ptrSize(zcu) == .c)) raw_ptr_ty.childType(zcu) else - return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(pt)}); + return sema.fail(block, raw_ptr_src, "expected single pointer, found '{f}'", .{raw_ptr_ty.fmt(zcu)}); // Optionally dereference a second pointer to get the concrete type. const is_double_ptr = inner_ty.zigTypeTag(zcu) == .pointer and inner_ty.ptrSize(zcu) == .one; @@ -26863,7 +26864,7 @@ fn fieldCallBind( const msg = msg: { const msg = try sema.errMsg(src, "no field or member function named '{f}' in '{f}'", .{ field_name.fmt(ip), - concrete_ty.fmt(pt), + concrete_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, concrete_ty); @@ -27099,18 +27100,18 @@ fn tupleFieldIndex( field_name: InternPool.NullTerminatedString, field_name_src: LazySrcLoc, ) CompileError!u32 { - const pt = sema.pt; - const ip = &pt.zcu.intern_pool; + const zcu = sema.pt.zcu; + const ip = &zcu.intern_pool; assert(!field_name.eqlSlice("len", ip)); if (field_name.toUnsigned(ip)) |field_index| { - if (field_index < tuple_ty.structFieldCount(pt.zcu)) return field_index; + if (field_index < tuple_ty.structFieldCount(zcu)) return field_index; return sema.fail(block, field_name_src, "index '{f}' out of bounds of tuple '{f}'", .{ - field_name.fmt(ip), tuple_ty.fmt(pt), + field_name.fmt(ip), tuple_ty.fmt(zcu), }); } return sema.fail(block, field_name_src, "no field named '{f}' in tuple '{f}'", .{ - field_name.fmt(ip), tuple_ty.fmt(pt), + field_name.fmt(ip), tuple_ty.fmt(zcu), }); } @@ -27172,7 +27173,7 @@ fn unionFieldPtr( if (initializing and field_ty.classify(zcu) == .no_possible_value) { const msg = msg: { - const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{ @@ -27327,7 +27328,7 @@ fn elemPtr( const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) { .pointer => indexable_ptr_ty.childType(zcu), - else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(pt)}), + else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{f}'", .{indexable_ptr_ty.fmt(zcu)}), }; try sema.checkIndexable(block, src, indexable_ty); try sema.ensureLayoutResolved(indexable_ty, src, .ptr_access); @@ -27453,8 +27454,8 @@ fn elemVal( .runtime => {}, .one_possible_value => return .fromValue((try child_ty.onePossibleValue(pt)).?), .no_possible_value => switch (child_ty.zigTypeTag(zcu)) { - .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(pt)}), - else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(pt)}), + .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{child_ty.fmt(zcu)}), + else => return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{child_ty.fmt(zcu)}), }, .partially_comptime, .fully_comptime => unreachable, // caught by `validateRuntimeElemAccess` } @@ -27507,7 +27508,7 @@ fn validateRuntimeElemAccess( const msg = try sema.errMsg( elem_index_src, "values of type '{f}' must be comptime-known, but index value is runtime-known", - .{elem_ty.fmt(sema.pt)}, + .{elem_ty.fmt(zcu)}, ); errdefer msg.destroy(sema.gpa); @@ -27546,7 +27547,7 @@ fn tupleElemPtr( const index = elem_index_val.getUnsignedInt(zcu); if (index == null or index.? >= field_count) { return sema.fail(block, elem_index_src, "index '{f}' out of bounds of tuple '{f}'", .{ - elem_index_val.fmtValueSema(pt, sema), tuple_ty.fmt(pt), + elem_index_val.fmtValueSema(sema), tuple_ty.fmt(zcu), }); } @@ -28295,7 +28296,7 @@ fn coerceExtra( block, inst_src, "coercion from slice to array pointer type '{f}' requires length to be known at compile-time", - .{dest_ty.fmt(pt)}, + .{dest_ty.fmt(zcu)}, ); }; @@ -28308,7 +28309,7 @@ fn coerceExtra( if (!opts.report_err) return error.NotCoercible; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(inst_src, "slice with undefined length cannot cast into array pointer type '{f}'", .{ - dest_ty.fmt(pt), + dest_ty.fmt(zcu), }); errdefer msg.destroy(gpa); try sema.errNote(inst_src, msg, "length of slice must be defined and match length of array type", .{}); @@ -28320,7 +28321,7 @@ fn coerceExtra( if (!opts.report_err) return error.NotCoercible; return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(inst_src, "slice of length {d} cannot cast into array pointer type '{f}'", .{ - slice_len, dest_ty.fmt(pt), + slice_len, dest_ty.fmt(zcu), }); errdefer msg.destroy(gpa); try sema.errNote(inst_src, msg, "length of slice must match length of array type", .{}); @@ -28375,7 +28376,7 @@ fn coerceExtra( block, inst_src, "array literal requires address-of operator (&) to coerce to slice type '{f}'", - .{dest_ty.fmt(pt)}, + .{dest_ty.fmt(zcu)}, ); } @@ -28400,7 +28401,7 @@ fn coerceExtra( if (!dest_info.flags.is_const) { if (!opts.report_err) return error.NotCoercible; const err_msg = err_msg: { - const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(pt)}); + const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{f}'", .{dest_ty.fmt(zcu)}); errdefer err_msg.destroy(sema.gpa); try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); break :err_msg err_msg; @@ -28455,7 +28456,7 @@ fn coerceExtra( // comptime-known integer to other number if (!val.intFitsInType(dest_ty, null, zcu)) { if (!opts.report_err) return error.NotCoercible; - return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) }); + return sema.fail(block, inst_src, "type '{f}' cannot represent integer value '{f}'", .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) }); } return switch (zcu.intern_pool.indexToKey(val.toIntern())) { .undef => .fromValue(try dest_ty.onePossibleValue(pt) orelse try pt.undefValue(dest_ty)), @@ -28499,7 +28500,7 @@ fn coerceExtra( block, inst_src, "type '{f}' cannot represent float value '{f}'", - .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) }, + .{ dest_ty.fmt(zcu), val.fmtValueSema(sema) }, ); } return Air.internedToRef(result_val.toIntern()); @@ -28558,7 +28559,7 @@ fn coerceExtra( block, inst_src, "type '{f}' cannot represent integer value '{f}'", - .{ dest_ty.fmt(pt), val.fmtValue(pt) }, + .{ dest_ty.fmt(zcu), val.fmtValue(zcu) }, ); } return .fromValue(result_val); @@ -28573,7 +28574,7 @@ fn coerceExtra( const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { if (!opts.report_err) return error.NotCoercible; return sema.fail(block, inst_src, "no field named '{f}' in enum '{f}'", .{ - string.fmt(&zcu.intern_pool), dest_ty.fmt(pt), + string.fmt(&zcu.intern_pool), dest_ty.fmt(zcu), }); }; return Air.internedToRef((try pt.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern()); @@ -28699,7 +28700,7 @@ fn coerceExtra( errdefer msg.destroy(sema.gpa); if (dest_is_npv) { - try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(pt)}); + try sema.errNote(inst_src, msg, "cannot coerce to uninstantiable type '{f}'", .{dest_ty.fmt(zcu)}); } // E!T to T @@ -28880,6 +28881,7 @@ const InMemoryCoercionResult = union(enum) { fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void { const pt = sema.pt; + const zcu = pt.zcu; var cur = res; while (true) switch (cur.*) { .ok => unreachable, @@ -28896,13 +28898,13 @@ const InMemoryCoercionResult = union(enum) { }, .comptime_int_not_coercible => |int| { try sema.errNote(src, msg, "type '{f}' cannot represent value '{f}'", .{ - int.wanted.fmt(pt), int.actual.fmtValueSema(pt, sema), + int.wanted.fmt(zcu), int.actual.fmtValueSema(sema), }); break; }, .error_union_payload => |pair| { try sema.errNote(src, msg, "error union payload '{f}' cannot cast into error union payload '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, @@ -28915,22 +28917,22 @@ const InMemoryCoercionResult = union(enum) { .array_sentinel => |sentinel| { if (sentinel.wanted.toIntern() == .unreachable_value) { try sema.errNote(src, msg, "source array cannot be guaranteed to maintain '{f}' sentinel", .{ - sentinel.actual.fmtValueSema(pt, sema), + sentinel.actual.fmtValueSema(sema), }); } else if (sentinel.actual.toIntern() == .unreachable_value) { try sema.errNote(src, msg, "destination array requires '{f}' sentinel", .{ - sentinel.wanted.fmtValueSema(pt, sema), + sentinel.wanted.fmtValueSema(sema), }); } else { try sema.errNote(src, msg, "array sentinel '{f}' cannot cast into array sentinel '{f}'", .{ - sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema), + sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema), }); } break; }, .array_elem => |pair| { try sema.errNote(src, msg, "array element type '{f}' cannot cast into array element type '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, @@ -28942,19 +28944,19 @@ const InMemoryCoercionResult = union(enum) { }, .vector_elem => |pair| { try sema.errNote(src, msg, "vector element type '{f}' cannot cast into vector element type '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, .optional_shape => |pair| { try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{ - pair.actual.optionalChild(pt.zcu).fmt(pt), pair.wanted.optionalChild(pt.zcu).fmt(pt), + pair.actual.optionalChild(pt.zcu).fmt(zcu), pair.wanted.optionalChild(pt.zcu).fmt(zcu), }); break; }, .optional_child => |pair| { try sema.errNote(src, msg, "optional type child '{f}' cannot cast into optional type child '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, @@ -29018,7 +29020,7 @@ const InMemoryCoercionResult = union(enum) { }, .fn_param => |param| { try sema.errNote(src, msg, "parameter {d} '{f}' cannot cast into '{f}'", .{ - param.index, param.actual.fmt(pt), param.wanted.fmt(pt), + param.index, param.actual.fmt(zcu), param.wanted.fmt(zcu), }); cur = param.child; }, @@ -29028,13 +29030,13 @@ const InMemoryCoercionResult = union(enum) { }, .fn_return_type => |pair| { try sema.errNote(src, msg, "return type '{f}' cannot cast into return type '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, .ptr_child => |pair| { try sema.errNote(src, msg, "pointer type child '{f}' cannot cast into pointer type child '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); cur = pair.child; }, @@ -29045,11 +29047,11 @@ const InMemoryCoercionResult = union(enum) { .ptr_sentinel => |sentinel| { if (sentinel.actual.toIntern() != .unreachable_value) { try sema.errNote(src, msg, "pointer sentinel '{f}' cannot cast into pointer sentinel '{f}'", .{ - sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema), + sentinel.actual.fmtValueSema(sema), sentinel.wanted.fmtValueSema(sema), }); } else { try sema.errNote(src, msg, "destination pointer requires '{f}' sentinel", .{ - sentinel.wanted.fmtValueSema(pt, sema), + sentinel.wanted.fmtValueSema(sema), }); } break; @@ -29063,11 +29065,11 @@ const InMemoryCoercionResult = union(enum) { const actual_allow_zero = pair.actual.ptrAllowsZero(pt.zcu); if (actual_allow_zero and !wanted_allow_zero) { try sema.errNote(src, msg, "'{f}' could have null values which are illegal in type '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); } else { try sema.errNote(src, msg, "mutable '{f}' would allow illegal null values stored to type '{f}'", .{ - pair.wanted.fmt(pt), pair.actual.fmt(pt), + pair.wanted.fmt(zcu), pair.actual.fmt(zcu), }); } break; @@ -29079,7 +29081,7 @@ const InMemoryCoercionResult = union(enum) { try sema.errNote(src, msg, "cast discards const qualifier", .{}); } else { try sema.errNote(src, msg, "mutable '{f}' would allow illegal const pointers stored to type '{f}'", .{ - pair.wanted.fmt(pt), pair.actual.fmt(pt), + pair.wanted.fmt(zcu), pair.actual.fmt(zcu), }); } break; @@ -29091,7 +29093,7 @@ const InMemoryCoercionResult = union(enum) { try sema.errNote(src, msg, "cast discards volatile qualifier", .{}); } else { try sema.errNote(src, msg, "mutable '{f}' would allow illegal volatile pointers stored to type '{f}'", .{ - pair.wanted.fmt(pt), pair.actual.fmt(pt), + pair.wanted.fmt(zcu), pair.actual.fmt(zcu), }); } break; @@ -29117,13 +29119,13 @@ const InMemoryCoercionResult = union(enum) { }, .double_ptr_to_anyopaque => |pair| { try sema.errNote(src, msg, "cannot implicitly cast double pointer '{f}' to anyopaque pointer '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); break; }, .slice_to_anyopaque => |pair| { try sema.errNote(src, msg, "cannot implicitly cast slice '{f}' to anyopaque pointer '{f}'", .{ - pair.actual.fmt(pt), pair.wanted.fmt(pt), + pair.actual.fmt(zcu), pair.wanted.fmt(zcu), }); try sema.errNote(src, msg, "consider using '.ptr'", .{}); break; @@ -29874,7 +29876,7 @@ fn coerceVarArgParam( const coerced_ty = sema.typeOf(coerced); if (!coerced_ty.validateExtern(.param_ty, zcu)) { const msg = msg: { - const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(pt)}); + const msg = try sema.errMsg(inst_src, "cannot pass '{f}' to variadic function", .{coerced_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty); @@ -29941,7 +29943,7 @@ fn storePtr2( // We're performing the store at runtime, so the pointee type must not be comptime-only. if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot store comptime-only type '{f}' at runtime", .{elem_ty.fmt(zcu)}); errdefer msg.destroy(zcu.gpa); try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{}); break :msg msg; @@ -30097,13 +30099,13 @@ fn storePtrVal( block, src, "comptime dereference requires '{f}' to have a well-defined layout", - .{ty.fmt(pt)}, + .{ty.fmt(zcu)}, ), .out_of_bounds => |ty| return sema.fail( block, src, "dereference of '{f}' exceeds bounds of containing decl of type '{f}'", - .{ ptr_ty.fmt(pt), ty.fmt(pt) }, + .{ ptr_ty.fmt(zcu), ty.fmt(zcu) }, ), .exceeds_host_size => return sema.fail(block, src, "bit-pointer target exceeds host size", .{}), } @@ -30315,7 +30317,7 @@ fn coerceCompatiblePtrs( const inst_ty = sema.typeOf(inst); if (sema.resolveValue(inst)) |val| { if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) { - return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)}); + return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(zcu)}); } // The comptime Value representation is compatible with both types. return Air.internedToRef( @@ -30386,7 +30388,7 @@ fn coerceEnumToUnion( if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| { const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse { return sema.fail(block, inst_src, "union '{f}' has no tag with value '{f}'", .{ - union_ty.fmt(pt), val.fmtValueSema(pt, sema), + union_ty.fmt(zcu), val.fmtValueSema(sema), }); }; @@ -30400,7 +30402,7 @@ fn coerceEnumToUnion( )), .no_possible_value => return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(inst_src, "cannot initialize union field with uninstantiable type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' declared here", .{ field_name.fmt(ip), @@ -30411,8 +30413,8 @@ fn coerceEnumToUnion( else => return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(inst_src, "coercion from enum '{f}' to union '{f}' must initialize '{f}' field '{f}'", .{ - inst_ty.fmt(pt), union_ty.fmt(pt), - field_ty.fmt(pt), field_name.fmt(ip), + inst_ty.fmt(zcu), union_ty.fmt(zcu), + field_ty.fmt(zcu), field_name.fmt(ip), }); errdefer msg.destroy(sema.gpa); @@ -30428,7 +30430,7 @@ fn coerceEnumToUnion( if (enum_ty.isNonexhaustiveEnum(zcu)) { const msg = msg: { const msg = try sema.errMsg(inst_src, "runtime coercion to union '{f}' from non-exhaustive enum", .{ - union_ty.fmt(pt), + union_ty.fmt(zcu), }); errdefer msg.destroy(sema.gpa); try sema.addDeclaredHereNote(msg, enum_ty); @@ -30456,7 +30458,7 @@ fn coerceEnumToUnion( const msg = try sema.errMsg( inst_src, "runtime coercion from enum '{f}' to union '{f}' which has non-void fields", - .{ enum_ty.fmt(pt), union_ty.fmt(pt) }, + .{ enum_ty.fmt(zcu), union_ty.fmt(zcu) }, ); errdefer msg.destroy(sema.gpa); @@ -30472,7 +30474,7 @@ fn coerceEnumToUnion( try sema.addFieldErrNote(union_ty, field_index, msg, "field '{f}' has {s} '{f}'", .{ field_name.fmt(ip), ty_description, - field_ty.fmt(pt), + field_ty.fmt(zcu), }); } try sema.addDeclaredHereNote(msg, union_ty); @@ -31082,7 +31084,7 @@ fn analyzeLoad( const ptr_ty = sema.typeOf(ptr); const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) { .pointer => ptr_ty.childType(zcu), - else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(pt)}), + else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ty.fmt(zcu)}), }; try sema.ensureLayoutResolved(elem_ty, src, .ptr_access); @@ -31093,11 +31095,11 @@ fn analyzeLoad( const comptime_only = switch (elem_ty.classify(zcu)) { .no_possible_value => switch (elem_ty.zigTypeTag(zcu)) { - .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(pt)}), + .@"opaque" => return sema.fail(block, src, "cannot load opaque type '{f}'", .{elem_ty.fmt(zcu)}), else => { // Loading an uninstantiable type always invokes Illegal Behavior. if (block.isComptime()) { - return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(pt)}); + return sema.fail(block, src, "cannot load uninstantiable type '{f}'", .{elem_ty.fmt(zcu)}); } else if (block.wantSafety()) { try sema.safetyPanic(block, src, .load_uninstantiable_type); return .unreachable_value; @@ -31122,9 +31124,9 @@ fn analyzeLoad( } if (comptime_only) return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(pt)}); + const msg = try sema.errMsg(src, "cannot load comptime-only type '{f}'", .{elem_ty.fmt(zcu)}); errdefer msg.destroy(zcu.gpa); - try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(pt)}); + try sema.errNote(ptr_src, msg, "pointer of type '{f}' is runtime-known", .{ptr_ty.fmt(zcu)}); break :msg msg; }); @@ -31432,7 +31434,7 @@ fn analyzeSlice( const ptr_ptr_ty = sema.typeOf(ptr_ptr); const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) { .pointer => ptr_ptr_ty.childType(zcu), - else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(pt)}), + else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{ptr_ptr_ty.fmt(zcu)}), }; var array_ty = ptr_ptr_child_ty; @@ -31483,8 +31485,8 @@ fn analyzeSlice( msg, "expected '{f}', found '{f}'", .{ - Value.zero_comptime_int.fmtValueSema(pt, sema), - start_value.fmtValueSema(pt, sema), + Value.zero_comptime_int.fmtValueSema(sema), + start_value.fmtValueSema(sema), }, ); break :msg msg; @@ -31499,8 +31501,8 @@ fn analyzeSlice( msg, "expected '{f}', found '{f}'", .{ - Value.one_comptime_int.fmtValueSema(pt, sema), - end_value.fmtValueSema(pt, sema), + Value.one_comptime_int.fmtValueSema(sema), + end_value.fmtValueSema(sema), }, ); break :msg msg; @@ -31513,7 +31515,7 @@ fn analyzeSlice( block, end_src, "end index {f} out of bounds for slice of single-item pointer", - .{end_value.fmtValueSema(pt, sema)}, + .{end_value.fmtValueSema(sema)}, ); } } @@ -31559,7 +31561,7 @@ fn analyzeSlice( elem_ty = ptr_ptr_child_ty.childType(zcu); }, }, - else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(pt)}), + else => return sema.fail(block, src, "slice of non-array type '{f}'", .{ptr_ptr_child_ty.fmt(zcu)}), } try sema.ensureLayoutResolved(elem_ty, src, .ptr_access); @@ -31611,8 +31613,8 @@ fn analyzeSlice( end_src, "end index {f} out of bounds for array of length {f}{s}", .{ - end_val.fmtValueSema(pt, sema), - len_val.fmtValueSema(pt, sema), + end_val.fmtValueSema(sema), + len_val.fmtValueSema(sema), sentinel_label, }, ); @@ -31656,7 +31658,7 @@ fn analyzeSlice( end_src, "end index {f} out of bounds for slice of length {d}{s}", .{ - end_val.fmtValueSema(pt, sema), + end_val.fmtValueSema(sema), slice_val.sliceLen(zcu), sentinel_label, }, @@ -31707,9 +31709,9 @@ fn analyzeSlice( const msg = try sema.errMsg(sentinel_src, "sentinel-terminated slicing of many-item pointer must match existing sentinel", .{}); errdefer msg.destroy(sema.gpa); if (ptr_sentinel) |current| { - try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(pt), provided.fmtValue(pt) }); + try sema.errNote(sentinel_src, msg, "expected sentinel '{f}', found '{f}'", .{ current.fmtValue(zcu), provided.fmtValue(zcu) }); } else { - try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(pt)}); + try sema.errNote(ptr_src, msg, "type '{f}' does not have a sentinel", .{slice_ty.fmt(zcu)}); } try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{}); break :msg msg; @@ -31753,8 +31755,8 @@ fn analyzeSlice( start_src, "start index {f} is larger than end index {f}", .{ - start_val.fmtValueSema(pt, sema), - end_val.fmtValueSema(pt, sema), + start_val.fmtValueSema(sema), + end_val.fmtValueSema(sema), }, ); } @@ -31776,13 +31778,13 @@ fn analyzeSlice( block, src, "comptime dereference requires '{f}' to have a well-defined layout", - .{ty.fmt(pt)}, + .{ty.fmt(zcu)}, ), .out_of_bounds => |ty| return sema.fail( block, end_src, "slice end index {d} exceeds bounds of containing decl of type '{f}'", - .{ end_int, ty.fmt(pt) }, + .{ end_int, ty.fmt(zcu) }, ), }; @@ -31791,8 +31793,8 @@ fn analyzeSlice( const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "expected '{f}', found '{f}'", .{ - expected_sentinel.fmtValueSema(pt, sema), - actual_sentinel.fmtValueSema(pt, sema), + expected_sentinel.fmtValueSema(sema), + actual_sentinel.fmtValueSema(sema), }); break :msg msg; @@ -32604,7 +32606,7 @@ const PeerResolveResult = union(enum) { instructions: []const Air.Inst.Ref, candidate_srcs: PeerTypeCandidateSrc, ) !*Zcu.ErrorMsg { - const pt = sema.pt; + const zcu = sema.pt.zcu; var opt_msg: ?*Zcu.ErrorMsg = null; errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); @@ -32630,7 +32632,7 @@ const PeerResolveResult = union(enum) { }, .field_error => |field_error| { const fmt = "struct field '{f}' has conflicting types"; - const args = .{field_error.field_name.fmt(&pt.zcu.intern_pool)}; + const args = .{field_error.field_name.fmt(&zcu.intern_pool)}; if (opt_msg) |msg| { try sema.errNote(src, msg, fmt, args); } else { @@ -32662,8 +32664,8 @@ const PeerResolveResult = union(enum) { const fmt = "incompatible types: '{f}' and '{f}'"; const args = .{ - conflict_tys[0].fmt(pt), - conflict_tys[1].fmt(pt), + conflict_tys[0].fmt(zcu), + conflict_tys[1].fmt(zcu), }; const msg = if (opt_msg) |msg| msg: { try sema.errNote(src, msg, fmt, args); @@ -32674,8 +32676,8 @@ const PeerResolveResult = union(enum) { break :msg msg; }; - if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(pt)}); - if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(pt)}); + if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[0].fmt(zcu)}); + if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{f}' here", .{conflict_tys[1].fmt(zcu)}); // No child error break; @@ -33904,10 +33906,10 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike { } fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { - const pt = sema.pt; - if (!ty.isIndexable(pt.zcu)) { + const zcu = sema.pt.zcu; + if (!ty.isIndexable(zcu)) { const msg = msg: { - const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(pt)}); + const msg = try sema.errMsg(src, "type '{f}' does not support indexing", .{ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{}); try sema.addDeclaredHereNote(msg, ty); @@ -33932,7 +33934,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void } } const msg = msg: { - const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(pt)}); + const msg = try sema.errMsg(src, "type '{f}' is not an indexable pointer", .{ty.fmt(zcu)}); errdefer msg.destroy(sema.gpa); try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); break :msg msg; @@ -34215,8 +34217,9 @@ pub fn analyzeAsAddressSpace( /// Asserts the value is a pointer and dereferences it. /// Returns `null` if the pointer contents cannot be loaded at comptime. fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value { - // TODO: audit use sites to eliminate this coercion const pt = sema.pt; + const zcu = pt.zcu; + // TODO: audit use sites to eliminate this coercion const coerced_ptr_val = try pt.getCoerced(ptr_val, ptr_ty); switch (try sema.pointerDerefExtra(block, src, coerced_ptr_val)) { .runtime_load => return null, @@ -34225,13 +34228,13 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr block, src, "comptime dereference requires '{f}' to have a well-defined layout", - .{ty.fmt(pt)}, + .{ty.fmt(zcu)}, ), .out_of_bounds => |ty| return sema.fail( block, src, "dereference of '{f}' exceeds bounds of containing decl of type '{f}'", - .{ ptr_ty.fmt(pt), ty.fmt(pt) }, + .{ ptr_ty.fmt(zcu), ty.fmt(zcu) }, ), } } @@ -34354,12 +34357,12 @@ fn intFromFloatScalar( if (std.math.isNan(float)) { return sema.fail(block, src, "float value NaN cannot be stored in integer type '{f}'", .{ - int_ty.fmt(pt), + int_ty.fmt(zcu), }); } if (std.math.isInf(float)) { return sema.fail(block, src, "float value Inf cannot be stored in integer type '{f}'", .{ - int_ty.fmt(pt), + int_ty.fmt(zcu), }); } @@ -34374,7 +34377,7 @@ fn intFromFloatScalar( block, src, "fractional component prevents float value '{f}' from coercion to type '{f}'", - .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) }, + .{ val.fmtValueSema(sema), int_ty.fmt(zcu) }, ), .truncate, .round, .floor, .ceil => {}, }, @@ -34386,7 +34389,7 @@ fn intFromFloatScalar( const int_info = int_ty.intInfo(zcu); if (!big_int.toConst().fitsInTwosComp(int_info.signedness, int_info.bits)) { return sema.fail(block, src, "float value '{f}' cannot be stored in integer type '{f}'", .{ - val.fmtValueSema(pt, sema), int_ty.fmt(pt), + val.fmtValueSema(sema), int_ty.fmt(zcu), }); } return pt.getCoerced(cti_result, int_ty); @@ -34632,7 +34635,7 @@ fn notePathToComptimeAllocPtr( else => {}, // there will be another stage } - const derivation = try comptime_ptr.pointerDerivation(arena, pt, sema); + const derivation = try comptime_ptr.pointerDerivation(arena, zcu, sema); var second_path_aw: std.Io.Writer.Allocating = .init(arena); defer second_path_aw.deinit(); @@ -34640,19 +34643,19 @@ fn notePathToComptimeAllocPtr( const deriv_start = @import("print_value.zig").printPtrDerivation( derivation, &second_path_aw.writer, - pt, + zcu, .lvalue, .{ .str = inter_name }, 20, ) catch return error.OutOfMemory; - switch (deriv_start) { - .int, .nav_ptr => unreachable, - .uav_ptr => |uav| { + switch (deriv_start.addr) { + .int, .nav => unreachable, + .uav => |uav| { try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() }); - return .{ .new_val = .fromInterned(uav.val) }; + return .{ .new_val = uav }; }, - .comptime_alloc_ptr => |cta_info| { + .comptime_alloc => |cta_info| { try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() }); const cta = sema.getComptimeAlloc(cta_info.idx); if (cta.is_const) { @@ -34662,15 +34665,15 @@ fn notePathToComptimeAllocPtr( return .done; } }, - .comptime_field_ptr => { + .comptime_field => { try sema.errNote(src, msg, "'{s}' points to '{s}', where", .{ first_path.items, second_path_aw.written() }); try sema.errNote(src, msg, "'{s}' is a comptime field", .{inter_name}); return .done; }, - .eu_payload_ptr, - .opt_payload_ptr, - .field_ptr, - .elem_ptr, + .eu_payload, + .opt_payload, + .field, + .elem, .offset_and_cast, => unreachable, } @@ -35286,7 +35289,7 @@ pub fn setTypeName( // some tooling may not support very long symbol names. w.print("{f}", .{Value.fmtValueSemaFull(.{ .val = arg_val, - .pt = pt, + .zcu = zcu, .opt_sema = sema, .depth = 1, })}) catch return error.OutOfMemory; diff --git a/src/Sema/LowerZon.zig b/src/Sema/LowerZon.zig index dd8c91c244518ac23d1d5d0be6caa30861f2c4c7..18ce3d9353662741743c134f3d2900b001d2ba66 100644 --- a/src/Sema/LowerZon.zig +++ b/src/Sema/LowerZon.zig @@ -323,10 +323,11 @@ fn failUnsupportedResultType( ) Zcu.SemaError { @branchHint(.cold); const sema = self.sema; - const gpa = sema.gpa; const pt = sema.pt; + const zcu = pt.zcu; + const gpa = zcu.comp.gpa; return sema.failWithOwnedErrorMsg(self.block, msg: { - const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(pt)}); + const msg = try sema.errMsg(self.import_loc, "type '{f}' is not available in ZON", .{ty.fmt(zcu)}); errdefer msg.destroy(gpa); if (opt_note) |n| try sema.errNote(self.import_loc, msg, "{s}", .{n}); break :msg msg; @@ -346,9 +347,9 @@ fn fail( } fn lowerExprKnownResTy(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index { - const pt = self.sema.pt; + const zcu = self.sema.pt.zcu; return self.lowerExprKnownResTyInner(node, res_ty) catch |err| switch (err) { - error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(pt)}), + error.WrongType => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(zcu)}), else => |e| return e, }; } @@ -359,20 +360,21 @@ fn lowerExprKnownResTyInner( res_ty: Type, ) (CompileError || error{WrongType})!InternPool.Index { const pt = self.sema.pt; - switch (res_ty.zigTypeTag(pt.zcu)) { + const zcu = pt.zcu; + switch (res_ty.zigTypeTag(zcu)) { .optional => return pt.intern(.{ .opt = .{ .ty = res_ty.toIntern(), .val = if (node.get(self.file.zoir.?) == .null) b: { break :b .none; } else b: { - const child_type = res_ty.optionalChild(pt.zcu); + const child_type = res_ty.optionalChild(zcu); break :b try self.lowerExprKnownResTyInner(node, child_type); }, }, }), .pointer => { - const ptr_info = res_ty.ptrInfo(pt.zcu); + const ptr_info = res_ty.ptrInfo(zcu); switch (ptr_info.flags.size) { .one => return pt.intern(.{ .ptr = .{ .ty = res_ty.toIntern(), @@ -413,7 +415,7 @@ fn lowerExprKnownResTyInner( .frame, .@"anyframe", .void, - => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(pt)}), + => return self.fail(node, "type '{f}' not available in ZON", .{res_ty.fmt(zcu)}), } } @@ -444,7 +446,7 @@ fn lowerInt( if (lhs_info.signedness == .unsigned and rhs < 0) return self.fail( node, "type '{f}' cannot represent integer value '{d}'", - .{ res_ty.fmt(self.sema.pt), rhs }, + .{ res_ty.fmt(self.sema.pt.zcu), rhs }, ); // If lhs has less than the 32 bits rhs can hold, we need to check the max and @@ -460,7 +462,7 @@ fn lowerInt( return self.fail( node, "type '{f}' cannot represent integer value '{d}'", - .{ res_ty.fmt(self.sema.pt), rhs }, + .{ res_ty.fmt(self.sema.pt.zcu), rhs }, ); } } @@ -478,7 +480,7 @@ fn lowerInt( return self.fail( node, "type '{f}' cannot represent integer value '{d}'", - .{ res_ty.fmt(self.sema.pt), val }, + .{ res_ty.fmt(self.sema.pt.zcu), val }, ); } } @@ -499,7 +501,7 @@ fn lowerInt( .inexact => return self.fail( node, "fractional component prevents float value '{d}' from coercion to type '{f}'", - .{ val, res_ty.fmt(self.sema.pt) }, + .{ val, res_ty.fmt(self.sema.pt.zcu) }, ), .exact => {}, } @@ -510,7 +512,7 @@ fn lowerInt( return self.fail( node, "type '{f}' cannot represent integer value '{d}'", - .{ res_ty.fmt(self.sema.pt), val }, + .{ res_ty.fmt(self.sema.pt.zcu), val }, ); } @@ -532,7 +534,7 @@ fn lowerInt( return self.fail( node, "type '{f}' cannot represent integer value '{d}'", - .{ res_ty.fmt(self.sema.pt), val }, + .{ res_ty.fmt(self.sema.pt.zcu), val }, ); } } @@ -566,7 +568,7 @@ fn lowerFloat( if (res_ty.toIntern() == .comptime_float_type) return self.fail( node, "expected type '{f}'", - .{res_ty.fmt(self.sema.pt)}, + .{res_ty.fmt(self.sema.pt.zcu)}, ); break :b try self.sema.pt.floatValue(res_ty, std.math.inf(f128)); }, @@ -574,7 +576,7 @@ fn lowerFloat( if (res_ty.toIntern() == .comptime_float_type) return self.fail( node, "expected type '{f}'", - .{res_ty.fmt(self.sema.pt)}, + .{res_ty.fmt(self.sema.pt.zcu)}, ); break :b try self.sema.pt.floatValue(res_ty, -std.math.inf(f128)); }, @@ -582,7 +584,7 @@ fn lowerFloat( if (res_ty.toIntern() == .comptime_float_type) return self.fail( node, "expected type '{f}'", - .{res_ty.fmt(self.sema.pt)}, + .{res_ty.fmt(self.sema.pt.zcu)}, ); break :b try self.sema.pt.floatValue(res_ty, std.math.nan(f128)); }, @@ -647,7 +649,7 @@ fn lowerEnum(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I node, "enum {f} has no member named '{f}'", .{ - res_ty.fmt(self.sema.pt), + res_ty.fmt(self.sema.pt.zcu), std.zig.fmtId(field_name.get(self.file.zoir.?)), }, ); @@ -941,7 +943,7 @@ fn lowerUnion(self: *LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool. .struct_literal => b: { const fields: @FieldType(Zoir.Node, "struct_literal") = switch (node.get(self.file.zoir.?)) { .struct_literal => |fields| fields, - else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt)}), + else => return self.fail(node, "expected type '{f}'", .{res_ty.fmt(self.sema.pt.zcu)}), }; if (fields.names.len != 1) { return error.WrongType; diff --git a/src/Sema/type_resolution.zig b/src/Sema/type_resolution.zig index 164fe262037b8262cc1324319751a7e3173be4e4..1f77043f93fb92de1f9578f0461357004f1cd0ec 100644 --- a/src/Sema/type_resolution.zig +++ b/src/Sema/type_resolution.zig @@ -310,7 +310,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { try sema.ensureLayoutResolved(field_ty, field_ty_src, .field); if (field_ty.zigTypeTag(zcu) == .@"opaque") { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -321,7 +321,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { if (field_ty.isSpirvRuntimeArray(zcu)) { if (struct_obj.layout != .@"extern") { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "non-extern struct cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_name_src, msg, "while checking this field", .{}); break :msg msg; @@ -329,7 +329,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { } if (field_index != fields_len - 1) { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(struct_ty.srcLoc(zcu), "struct field of type '{f}' must be the last field", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_name_src, msg, "while checking this field", .{}); break :msg msg; @@ -339,7 +339,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { const elem_ty: Type = field_ty.childType(zcu); if (elem_ty.zigTypeTag(zcu) == .spirv) { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot embed SPIR-V type '{f}' in struct", .{elem_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -348,7 +348,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { } } else { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot directly embed SPIR-V type '{f}' in struct", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -359,7 +359,7 @@ pub fn resolveStructLayout(sema: *Sema, struct_ty: Type) CompileError!void { if (struct_obj.layout == .@"extern" and !field_ty.validateExtern(.struct_field, zcu)) { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "extern structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .struct_field); try sema.addDeclaredHereNote(msg, field_ty); @@ -516,7 +516,7 @@ fn resolvePackedStructLayout( try sema.ensureLayoutResolved(field_ty, field_ty_src, .field); if (field_ty.zigTypeTag(zcu) == .@"opaque") { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in struct", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -524,7 +524,7 @@ fn resolvePackedStructLayout( }); } if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "packed structs cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason); break :msg msg; @@ -565,7 +565,7 @@ fn resolvePackedStructLayout( block, block.src(.container_arg), "expected backing integer type, found '{f}'", - .{backing_ty.fmt(pt)}, + .{backing_ty.fmt(zcu)}, ); if (field_bits != backing_ty.intInfo(zcu).bits) return sema.failWithOwnedErrorMsg(block, msg: { const src = struct_ty.srcLoc(zcu); @@ -575,7 +575,7 @@ fn resolvePackedStructLayout( block.src(.container_arg), msg, "backing integer '{f}' has bit width '{d}'", - .{ backing_ty.fmt(pt), backing_ty.bitSize(zcu) }, + .{ backing_ty.fmt(zcu), backing_ty.bitSize(zcu) }, ); try sema.errNote(src, msg, "struct fields have total bit width '{d}'", .{field_bits}); break :msg msg; @@ -777,7 +777,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { &block, block.src(.container_arg), "expected enum tag type, found '{f}'", - .{tag_ty.fmt(pt)}, + .{tag_ty.fmt(zcu)}, ); break :validated_tag_ty tag_ty; }, @@ -922,7 +922,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { try sema.ensureLayoutResolved(field_ty, field_ty_src, .field); if (field_ty.zigTypeTag(zcu) == .@"opaque") { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -931,7 +931,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { } if (field_ty.zigTypeTag(zcu) == .spirv) { return sema.failWithOwnedErrorMsg(&block, msg: { - 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)}); + 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)}); errdefer msg.destroy(gpa); try sema.addDeclaredHereNote(msg, field_ty); break :msg msg; @@ -939,7 +939,7 @@ pub fn resolveUnionLayout(sema: *Sema, union_ty: Type) CompileError!void { } if (union_obj.layout == .@"extern" and !field_ty.validateExtern(.union_field, zcu)) { return sema.failWithOwnedErrorMsg(&block, msg: { - const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "extern unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsNotExtern(msg, field_ty_src, field_ty, .union_field); try sema.addDeclaredHereNote(msg, field_ty); @@ -1056,7 +1056,7 @@ fn failUnionFieldMismatch(sema: *Sema, block: *Block, union_field_names: []const } const union_field_src = block.src(.{ .container_field_name = @intCast(union_field_index) }); return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(pt) }); + const msg = try sema.errMsg(union_field_src, "no field named '{f}' in enum '{f}'", .{ field_name.fmt(ip), enum_tag_ty.fmt(zcu) }); errdefer msg.destroy(gpa); try sema.addDeclaredHereNote(msg, enum_tag_ty); break :msg msg; @@ -1122,7 +1122,7 @@ fn resolvePackedUnionLayout( try sema.ensureLayoutResolved(field_ty, field_ty_src, .field); if (field_ty.zigTypeTag(zcu) == .@"opaque") { return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "cannot directly embed opaque type '{f}' in union", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.errNote(field_ty_src, msg, "opaque types have unknown size", .{}); try sema.addDeclaredHereNote(msg, field_ty); @@ -1130,7 +1130,7 @@ fn resolvePackedUnionLayout( }); } if (field_ty.unpackable(zcu)) |reason| return sema.failWithOwnedErrorMsg(block, msg: { - const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(pt)}); + const msg = try sema.errMsg(field_ty_src, "packed unions cannot contain fields of type '{f}'", .{field_ty.fmt(zcu)}); errdefer msg.destroy(gpa); try sema.explainWhyTypeIsUnpackable(msg, field_ty_src, reason); break :msg msg; @@ -1165,7 +1165,7 @@ fn resolvePackedUnionLayout( block, block.src(.container_arg), "expected backing integer type, found '{f}'", - .{backing_ty.fmt(pt)}, + .{backing_ty.fmt(zcu)}, ); const backing_int_bits = backing_ty.intInfo(zcu).bits; for (union_obj.field_types.get(ip), 0..) |field_type_ip, field_idx| { @@ -1175,12 +1175,12 @@ fn resolvePackedUnionLayout( const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) }); const msg = try sema.errMsg(field_ty_src, "field bit width does not match backing integer", .{}); errdefer msg.destroy(gpa); - try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits }); + try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits }); try sema.errNote( block.src(.container_arg), msg, "backing integer '{f}' has bit width '{d}'", - .{ backing_ty.fmt(pt), backing_int_bits }, + .{ backing_ty.fmt(zcu), backing_int_bits }, ); try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{}); break :msg msg; @@ -1199,8 +1199,8 @@ fn resolvePackedUnionLayout( const field_ty_src = block.src(.{ .container_field_type = @intCast(field_idx) }); const msg = try sema.errMsg(field_ty_src, "field bit width does not match earlier field", .{}); errdefer msg.destroy(gpa); - try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(pt), field_bits }); - try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(pt), first_field_bits }); + try sema.errNote(field_ty_src, msg, "field type '{f}' has bit width '{d}'", .{ field_type.fmt(zcu), field_bits }); + try sema.errNote(first_field_ty_src, msg, "other field type '{f}' has bit width '{d}'", .{ first_field_type.fmt(zcu), first_field_bits }); try sema.errNote(field_ty_src, msg, "all fields in a packed union must have the same bit width", .{}); break :msg msg; }); @@ -1380,7 +1380,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void { &block, block.src(.container_arg), "expected integer tag type, found '{f}'", - .{int_tag_ty.fmt(pt)}, + .{int_tag_ty.fmt(zcu)}, ), } break :ty int_tag_ty; @@ -1487,7 +1487,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void { &block, field_val_src, "enum tag value '{f}' too large for type '{f}'", - .{ result.val.fmtValueSema(pt, sema), int_tag_ty.fmt(pt) }, + .{ result.val.fmtValueSema(sema), int_tag_ty.fmt(zcu) }, ); const val = result.val.toIntern(); enum_obj.field_values.get(ip)[field_idx] = val; @@ -1497,7 +1497,7 @@ pub fn resolveEnumLayout(sema: *Sema, enum_ty: Type) CompileError!void { return sema.failWithOwnedErrorMsg(&block, msg: { const prev_field_val_src = block.src(.{ .container_field_value = prev_field_index }); const msg = try sema.errMsg(field_val_src, "enum tag value '{f}' for field '{f}' already taken", .{ - Value.fromInterned(field_val).fmtValueSema(pt, sema), + Value.fromInterned(field_val).fmtValueSema(sema), enum_obj.field_names.get(ip)[field_idx].fmt(ip), }); errdefer msg.destroy(gpa); diff --git a/src/Type.zig b/src/Type.zig index b95b0df556f68de7bc40f3ef8c07ca7767ee7a11..75e5159a9422fe2f9c5301c546d7b2e3b480525f 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -412,21 +412,14 @@ pub fn eql(a: Type, b: Type) bool { pub const format = @compileError("do not format types directly; use either ty.fmtDebug() or ty.fmt()"); -pub const Formatter = std.fmt.Alt(Format, Format.default); - -pub fn fmt(ty: Type, pt: Zcu.PerThread) Formatter { - return .{ .data = .{ - .ty = ty, - .pt = pt, - } }; +pub fn fmt(ty: Type, zcu: *Zcu) Formatter { + return .{ .ty = ty, .zcu = zcu }; } - -const Format = struct { +pub const Formatter = struct { ty: Type, - pt: Zcu.PerThread, - - fn default(f: Format, writer: *std.Io.Writer) std.Io.Writer.Error!void { - return print(f.ty, writer, f.pt, null); + zcu: *Zcu, + pub fn format(f: Formatter, writer: *std.Io.Writer) std.Io.Writer.Error!void { + return print(f.ty, writer, f.zcu, null); } }; @@ -442,9 +435,9 @@ pub fn dump(start_type: Type, writer: *std.Io.Writer) std.Io.Writer.Error!void { /// Prints a name suitable for `@typeName`. /// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels. -pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Comparison) std.Io.Writer.Error!void { +pub fn print(ty: Type, writer: *std.Io.Writer, zcu: *Zcu, ctx: ?*Comparison) std.Io.Writer.Error!void { if (ctx) |c| { - const should_dedupe = shouldDedupeType(ty, c, pt) catch |err| switch (err) { + const should_dedupe = shouldDedupeType(ty, c, zcu) catch |err| switch (err) { error.OutOfMemory => return error.WriteFailed, }; switch (should_dedupe) { @@ -453,7 +446,6 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari } } - const zcu = pt.zcu; const ip = &zcu.intern_pool; switch (ip.indexToKey(ty.toIntern())) { .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 if (info.sentinel != .none) switch (info.flags.size) { .one, .c => unreachable, - .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), - .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}), + .many => try writer.print("[*:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}), + .slice => try writer.print("[:{f}]", .{Value.fromInterned(info.sentinel).fmtValue(zcu)}), } else switch (info.flags.size) { .one => try writer.writeAll("*"), .many => try writer.writeAll("[*]"), @@ -485,7 +477,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari const alignment = if (info.flags.alignment != .none) info.flags.alignment else - Type.fromInterned(info.child).abiAlignment(pt.zcu); + Type.fromInterned(info.child).abiAlignment(zcu); try writer.print("align({d}", .{alignment.toByteUnits() orelse 0}); 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 if (info.flags.is_const) try writer.writeAll("const "); if (info.flags.is_volatile) try writer.writeAll("volatile "); - try print(Type.fromInterned(info.child), writer, pt, ctx); + try print(Type.fromInterned(info.child), writer, zcu, ctx); return; }, .array_type => |array_type| { if (array_type.sentinel == .none) { try writer.print("[{d}]", .{array_type.len}); - try print(Type.fromInterned(array_type.child), writer, pt, ctx); + try print(Type.fromInterned(array_type.child), writer, zcu, ctx); } else { try writer.print("[{d}:{f}]", .{ array_type.len, - Value.fromInterned(array_type.sentinel).fmtValue(pt), + Value.fromInterned(array_type.sentinel).fmtValue(zcu), }); - try print(Type.fromInterned(array_type.child), writer, pt, ctx); + try print(Type.fromInterned(array_type.child), writer, zcu, ctx); } return; }, .vector_type => |vector_type| { try writer.print("@Vector({d}, ", .{vector_type.len}); - try print(Type.fromInterned(vector_type.child), writer, pt, ctx); + try print(Type.fromInterned(vector_type.child), writer, zcu, ctx); try writer.writeAll(")"); return; }, .opt_type => |child| { try writer.writeByte('?'); - return print(Type.fromInterned(child), writer, pt, ctx); + return print(Type.fromInterned(child), writer, zcu, ctx); }, .error_union_type => |error_union_type| { - try print(Type.fromInterned(error_union_type.error_set_type), writer, pt, ctx); + try print(Type.fromInterned(error_union_type.error_set_type), writer, zcu, ctx); try writer.writeByte('!'); if (error_union_type.payload_type == .generic_poison_type) { try writer.writeAll("anytype"); } else { - try print(Type.fromInterned(error_union_type.payload_type), writer, pt, ctx); + try print(Type.fromInterned(error_union_type.payload_type), writer, zcu, ctx); } return; }, @@ -618,8 +610,8 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, val, i| { try writer.writeAll(if (i == 0) " " else ", "); if (val != .none) try writer.writeAll("comptime "); - try print(Type.fromInterned(field_ty), writer, pt, ctx); - if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(pt)}); + try print(Type.fromInterned(field_ty), writer, zcu, ctx); + if (val != .none) try writer.print(" = {f}", .{Value.fromInterned(val).fmtValue(zcu)}); } try writer.writeAll(" }"); }, @@ -643,12 +635,12 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari .image => try writer.writeAll("@SpirvType(.image)"), .sampled_image => { try writer.writeAll("@SpirvType(.sampled_image, "); - try print(Type.fromInterned(info.ty), writer, pt, ctx); + try print(Type.fromInterned(info.ty), writer, zcu, ctx); try writer.writeAll(")"); }, .runtime_array => { try writer.writeAll("@SpirvType(.runtime_array, "); - try print(Type.fromInterned(info.ty), writer, pt, ctx); + try print(Type.fromInterned(info.ty), writer, zcu, ctx); try writer.writeAll(")"); }, } @@ -672,7 +664,7 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari if (param_ty == .generic_poison_type) { try writer.writeAll("anytype"); } else { - try print(Type.fromInterned(param_ty), writer, pt, ctx); + try print(Type.fromInterned(param_ty), writer, zcu, ctx); } } if (fn_info.is_var_args) { @@ -699,13 +691,13 @@ pub fn print(ty: Type, writer: *std.Io.Writer, pt: Zcu.PerThread, ctx: ?*Compari if (fn_info.return_type == .generic_poison_type) { try writer.writeAll("anytype"); } else { - try print(Type.fromInterned(fn_info.return_type), writer, pt, ctx); + try print(Type.fromInterned(fn_info.return_type), writer, zcu, ctx); } }, .anyframe_type => |child| { if (child == .none) return writer.writeAll("anyframe"); try writer.writeAll("anyframe->"); - return print(Type.fromInterned(child), writer, pt, ctx); + return print(Type.fromInterned(child), writer, zcu, ctx); }, // values, not types @@ -2869,11 +2861,62 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator const ptr_info = ip.indexToKey(ptr_ty.toIntern()).ptr_type; assert(ptr_info.flags.size == .one or ptr_info.flags.size == .c); const aggregate_ty: Type = .fromInterned(ptr_info.child); + + var field_ptr_info = ptr_info; + + field_ptr_info.child = if (aggregate_ty.isSlice(zcu)) switch (field_index) { + Value.slice_ptr_index => aggregate_ty.slicePtrFieldType(zcu).toIntern(), + Value.slice_len_index => .usize_type, + else => unreachable, + } else aggregate_ty.fieldType(field_index, zcu).toIntern(); + + field_ptr_info.flags.alignment = aggregate_ty.fieldPtrAlign(ptr_info.flags.alignment, field_index, zcu); + + if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and + aggregate_ty.containerLayout(zcu) == .@"packed") + { + field_ptr_info.packed_offset = packed_offset: { + comptime assert(Type.packed_struct_layout_version == 2); + const bit_offset = zcu.structPackedFieldBitOffset( + ip.loadStructType(aggregate_ty.toIntern()), + field_index, + ); + break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{ + .host_size = ptr_info.packed_offset.host_size, + .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset, + } else .{ + .host_size = switch (zcu.comp.getZigBackend()) { + else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8), + .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)), + }, + .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset, + }; + }; + } + + return pt.ptrType(field_ptr_info); +} + +pub fn fieldPtrAlign( + aggregate_ty: Type, + aggregate_ptr_align: Alignment, + field_index: u32, + zcu: *const Zcu, +) Alignment { + const ip = &zcu.intern_pool; + aggregate_ty.assertHasLayout(zcu); + + const aggregate_ty_align = aggregate_ty.abiAlignment(zcu); + const aggregate_align: Alignment = switch (aggregate_ptr_align) { + .none => aggregate_ty_align, + else => |a| a, + }; + // We only exit this `switch` for default-layout aggregates, where the field pointer alignment // is a simple minimum of the aggregate pointer alignment and the field alignment. - // `field_align` is `.none` if there is no explicit alignment annotation. - const field_ty: Type, const field_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) { + // `field_explicit_align` is `.none` if there is no explicit alignment annotation. + const field_ty: Type, const field_explicit_align: Alignment = switch (aggregate_ty.zigTypeTag(zcu)) { .@"struct" => switch (aggregate_ty.containerLayout(zcu)) { .auto => field: { if (aggregate_ty.isTuple(zcu)) { @@ -2890,56 +2933,21 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator // `extern struct { x: u32, y: u16 }`, the `y` field is 4-byte aligned. const field_ty = aggregate_ty.fieldType(field_index, zcu); const field_offset = aggregate_ty.structFieldOffset(field_index, zcu); - const parent_align = switch (ptr_info.flags.alignment) { - .none => aggregate_ty.abiAlignment(zcu), - else => |a| a, - }; - const actual_field_align = switch (field_offset) { - 0 => parent_align, - else => parent_align.minStrict(.fromLog2Units(@ctz(field_offset))), - }; - const field_ptr_align: Alignment = a: { - if (ptr_info.flags.alignment == .none and - aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and - actual_field_align == field_ty.abiAlignment(zcu)) - { - // There's no user-specified 'align' in sight, and the alignment from the - // field offset matches the field type's natural alignment, so just use a - // default-aligned pointer. - break :a .none; - } - break :a actual_field_align; - }; - var field_ptr_info = ptr_info; - field_ptr_info.child = field_ty.toIntern(); - field_ptr_info.flags.alignment = field_ptr_align; - return pt.ptrType(field_ptr_info); - }, - .@"packed" => { - var field_ptr_info = ptr_info; - if (field_ptr_info.flags.alignment == .none) { - field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu); + const field_align = aggregate_align.offset(field_offset); + + if (aggregate_ptr_align == .none and + aggregate_ty.explicitFieldAlignment(field_index, zcu) == .none and + field_align == field_ty.abiAlignment(zcu)) + { + // There's no user-specified 'align' in sight, and the alignment from the + // field offset matches the field type's natural alignment, so just use a + // default-aligned pointer. + return .none; } - field_ptr_info.packed_offset = packed_offset: { - comptime assert(Type.packed_struct_layout_version == 2); - const bit_offset = zcu.structPackedFieldBitOffset( - ip.loadStructType(aggregate_ty.toIntern()), - field_index, - ); - break :packed_offset if (ptr_info.packed_offset.host_size != 0) .{ - .host_size = ptr_info.packed_offset.host_size, - .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset, - } else .{ - .host_size = switch (zcu.comp.getZigBackend()) { - else => @intCast((aggregate_ty.bitSize(zcu) + 7) / 8), - .stage2_x86_64, .stage2_c => @intCast(aggregate_ty.abiSize(zcu)), - }, - .bit_offset = ptr_info.packed_offset.bit_offset + bit_offset, - }; - }; - field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern(); - return pt.ptrType(field_ptr_info); + + return field_align; }, + .@"packed" => return aggregate_align, }, .@"union" => switch (aggregate_ty.containerLayout(zcu)) { .auto => field: { @@ -2949,30 +2957,14 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator union_obj.field_aligns.getOrNone(ip, field_index), }; }, - .@"extern" => { + .@"extern", .@"packed" => { // The alignment always matches that of the union pointer. If the union pointer is // default aligned (`.none`), we may need to explicitly align the result pointer. - const field_ty = aggregate_ty.fieldType(field_index, zcu); - var field_ptr_info = ptr_info; - field_ptr_info.child = field_ty.toIntern(); - if (field_ptr_info.flags.alignment == .none and - Alignment.compareStrict(field_ty.abiAlignment(zcu), .neq, aggregate_ty.abiAlignment(zcu))) - { - field_ptr_info.flags.alignment = aggregate_ty.abiAlignment(zcu); - } - return pt.ptrType(field_ptr_info); - }, - .@"packed" => { - const field_ty = aggregate_ty.fieldType(field_index, zcu); - var field_ptr_info = ptr_info; - if (field_ptr_info.flags.alignment == .none) { - const resolved_align = aggregate_ty.abiAlignment(zcu); - if (field_ty.abiAlignment(zcu) != resolved_align) { - field_ptr_info.flags.alignment = resolved_align; - } - } - field_ptr_info.child = aggregate_ty.fieldType(field_index, zcu).toIntern(); - return pt.ptrType(field_ptr_info); + const field_ty_align = aggregate_ty.fieldType(field_index, zcu).abiAlignment(zcu); + return switch (aggregate_ptr_align) { + .none => if (field_ty_align == aggregate_ty_align) .none else aggregate_ty_align, + else => |a| a, + }; }, }, .pointer => field: { @@ -2985,39 +2977,31 @@ pub fn fieldPtrType(ptr_ty: Type, field_index: u32, pt: Zcu.PerThread) Allocator }, else => unreachable, }; - const field_ptr_align: Alignment = a: { - if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and aggregate_ty.structFieldIsComptime(field_index, zcu)) { - // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified. - break :a field_align; - } - const actual_field_align = switch (field_align) { - .none => switch (ip.indexToKey(aggregate_ty.toIntern())) { - .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu), - .ptr_type => Type.usize.abiAlignment(zcu), - else => unreachable, - }, - else => |a| a, - }; - const actual_aggregate_align = switch (ptr_info.flags.alignment) { - .none => aggregate_ty.abiAlignment(zcu), - else => |a| a, - }; - if (actual_aggregate_align.compareStrict(.lt, actual_field_align)) { - // Underaligned aggregate; use that alignment. - assert(ptr_info.flags.alignment != .none); - break :a actual_aggregate_align; - } - if (field_align == .none and actual_field_align == field_ty.abiAlignment(zcu)) { - // No explicit annotation on the field (nor an unusual default), and the aggregate - // alignment is irrelevant to us, so return an un-annotated pointer. - break :a .none; - } - break :a actual_field_align; + if (aggregate_ty.zigTypeTag(zcu) == .@"struct" and + aggregate_ty.structFieldIsComptime(field_index, zcu)) + { + // For `comptime` fields, just use exactly what was specified, or ABI alignment if nothing was specified. + return field_explicit_align; + } + const field_align = switch (field_explicit_align) { + .none => switch (ip.indexToKey(aggregate_ty.toIntern())) { + .struct_type, .tuple_type, .union_type => field_ty.abiAlignment(zcu), + .ptr_type => Type.usize.abiAlignment(zcu), + else => unreachable, + }, + else => |a| a, }; - var field_ptr_info = ptr_info; - field_ptr_info.flags.alignment = field_ptr_align; - field_ptr_info.child = field_ty.toIntern(); - return pt.ptrType(field_ptr_info); + if (aggregate_align.compareStrict(.lt, field_align)) { + // Underaligned aggregate; use that alignment. + assert(aggregate_ptr_align == aggregate_align); + return aggregate_align; + } + if (field_explicit_align == .none and field_align == field_ty.abiAlignment(zcu)) { + // No explicit annotation on the field (nor an unusual default), and the aggregate + // alignment is irrelevant to us, so return an un-annotated pointer. + return .none; + } + return field_align; } pub fn containerTypeName(ty: Type, ip: *const InternPool) struct { @@ -3356,8 +3340,7 @@ pub fn assertHasLayout(ty: Type, zcu: *const Zcu) void { } /// Recursively walks the type and marks for each subtype how many times it has been seen -fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void { - const zcu = pt.zcu; +fn collectSubtypes(ty: Type, zcu: *Zcu, visited: *std.array_hash_map.Auto(Type, u16)) error{OutOfMemory}!void { const ip = &zcu.intern_pool; 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 } switch (ip.indexToKey(ty.toIntern())) { - .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), pt, visited), - .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), pt, visited), - .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), pt, visited), - .opt_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited), + .ptr_type => try collectSubtypes(Type.fromInterned(ty.ptrInfo(zcu).child), zcu, visited), + .array_type => |array_type| try collectSubtypes(Type.fromInterned(array_type.child), zcu, visited), + .vector_type => |vector_type| try collectSubtypes(Type.fromInterned(vector_type.child), zcu, visited), + .opt_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited), .error_union_type => |error_union_type| { - try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), pt, visited); + try collectSubtypes(Type.fromInterned(error_union_type.error_set_type), zcu, visited); if (error_union_type.payload_type != .generic_poison_type) { - try collectSubtypes(Type.fromInterned(error_union_type.payload_type), pt, visited); + try collectSubtypes(Type.fromInterned(error_union_type.payload_type), zcu, visited); } }, .tuple_type => |tuple| { for (tuple.types.get(ip)) |field_ty| { - try collectSubtypes(Type.fromInterned(field_ty), pt, visited); + try collectSubtypes(Type.fromInterned(field_ty), zcu, visited); } }, .func_type => |fn_info| { const param_types = fn_info.param_types.get(&zcu.intern_pool); for (param_types) |param_ty| { if (param_ty != .generic_poison_type) { - try collectSubtypes(Type.fromInterned(param_ty), pt, visited); + try collectSubtypes(Type.fromInterned(param_ty), zcu, visited); } } if (fn_info.return_type != .generic_poison_type) { - try collectSubtypes(Type.fromInterned(fn_info.return_type), pt, visited); + try collectSubtypes(Type.fromInterned(fn_info.return_type), zcu, visited); } }, - .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), pt, visited), + .anyframe_type => |child| try collectSubtypes(Type.fromInterned(child), zcu, visited), // leaf types .undef, @@ -3432,7 +3415,7 @@ fn collectSubtypes(ty: Type, pt: Zcu.PerThread, visited: *std.array_hash_map.Aut } } -fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMemory}!Comparison.DedupeEntry { +fn shouldDedupeType(ty: Type, ctx: *Comparison, zcu: *Zcu) error{OutOfMemory}!Comparison.DedupeEntry { if (ctx.type_occurrences.get(ty)) |occ| { if (ctx.type_dedupe_cache.get(ty)) |cached| { return cached; @@ -3440,7 +3423,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe var discarding: std.Io.Writer.Discarding = .init(&.{}); - print(ty, &discarding.writer, pt, null) catch + print(ty, &discarding.writer, zcu, null) catch unreachable; // we are writing into a discarding writer, it should never fail const type_len: i32 = @intCast(discarding.count); @@ -3457,7 +3440,7 @@ fn shouldDedupeType(ty: Type, ctx: *Comparison, pt: Zcu.PerThread) error{OutOfMe break :b .{ .dedupe = .{ .index = ctx.placeholder_index - 1 } }; } else .dont_dedupe; - try ctx.type_dedupe_cache.put(pt.zcu.gpa, ty, entry); + try ctx.type_dedupe_cache.put(zcu.comp.gpa, ty, entry); return entry; } else { @@ -3488,38 +3471,37 @@ pub const Comparison = struct { dedupe: Placeholder, }; - pub fn init(types: []const Type, pt: Zcu.PerThread) error{OutOfMemory}!Comparison { + pub fn init(types: []const Type, zcu: *Zcu) error{OutOfMemory}!Comparison { var cmp: Comparison = .{ .type_occurrences = .empty, .type_dedupe_cache = .empty, .placeholder_index = 0, }; - errdefer cmp.deinit(pt); + errdefer cmp.deinit(zcu.comp.gpa); for (types) |ty| { - try collectSubtypes(ty, pt, &cmp.type_occurrences); + try collectSubtypes(ty, zcu, &cmp.type_occurrences); } return cmp; } - pub fn deinit(cmp: *Comparison, pt: Zcu.PerThread) void { - const gpa = pt.zcu.gpa; + pub fn deinit(cmp: *Comparison, gpa: Allocator) void { cmp.type_occurrences.deinit(gpa); cmp.type_dedupe_cache.deinit(gpa); } - pub fn fmtType(ctx: *Comparison, ty: Type, pt: Zcu.PerThread) Comparison.Formatter { - return .{ .ty = ty, .ctx = ctx, .pt = pt }; + pub fn fmtType(ctx: *Comparison, ty: Type, zcu: *Zcu) Comparison.Formatter { + return .{ .ty = ty, .ctx = ctx, .zcu = zcu }; } pub const Formatter = struct { ty: Type, ctx: *Comparison, - pt: Zcu.PerThread, + zcu: *Zcu, pub fn format(self: Comparison.Formatter, writer: anytype) error{WriteFailed}!void { - print(self.ty, writer, self.pt, self.ctx) catch return error.WriteFailed; + print(self.ty, writer, self.zcu, self.ctx) catch return error.WriteFailed; } }; }; diff --git a/src/Value.zig b/src/Value.zig index e5cabc90d9f058ee3a25538dde3a7cde5e88bfa6..51561b50c1e46b9ed4b6d127a383d1926eeab4e4 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -34,19 +34,19 @@ pub fn fmtDebug(val: Value) std.fmt.Alt(Value, dump) { return .{ .data = val }; } -pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Alt(print_value.FormatContext, print_value.format) { +pub fn fmtValue(val: Value, zcu: *Zcu) std.fmt.Alt(print_value.FormatContext, print_value.format) { return .{ .data = .{ .val = val, - .pt = pt, + .zcu = zcu, .opt_sema = null, .depth = 3, } }; } -pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Alt(print_value.FormatContext, print_value.formatSema) { +pub fn fmtValueSema(val: Value, sema: *Sema) std.fmt.Alt(print_value.FormatContext, print_value.formatSema) { return .{ .data = .{ .val = val, - .pt = pt, + .zcu = sema.pt.zcu, .opt_sema = sema, .depth = 3, } }; @@ -1890,167 +1890,233 @@ pub fn getOffsetPtr(ptr_val: Value, byte_off: u64, new_ty: Type, pt: Zcu.PerThre return Value.fromInterned(try pt.intern(.{ .ptr = ptr })); } -pub const PointerDeriveStep = union(enum) { - int: struct { - addr: u64, - ptr_ty: Type, - }, - nav_ptr: InternPool.Nav.Index, - uav_ptr: InternPool.Key.Ptr.BaseAddr.Uav, - comptime_alloc_ptr: struct { - idx: InternPool.ComptimeAllocIndex, - val: Value, - ptr_ty: Type, - }, - comptime_field_ptr: Value, - eu_payload_ptr: struct { - parent: *PointerDeriveStep, - /// This type will never be cast: it is provided for convenience. - result_ptr_ty: Type, - }, - opt_payload_ptr: struct { - parent: *PointerDeriveStep, - /// This type will never be cast: it is provided for convenience. - result_ptr_ty: Type, - }, - field_ptr: struct { - parent: *PointerDeriveStep, - field_idx: u32, - /// This type will never be cast: it is provided for convenience. - result_ptr_ty: Type, - }, - elem_ptr: struct { - parent: *PointerDeriveStep, - elem_idx: u64, - /// This type will never be cast: it is provided for convenience. - result_ptr_ty: Type, - }, - offset_and_cast: struct { - parent: *PointerDeriveStep, - byte_offset: u64, - new_ptr_ty: Type, +pub const PointerDerivation = struct { + elem_ty: Type, + /// TODO: investigate eliminating this field. We should *always* know the lengths of arrays + /// which are pointed to, so `.one` should be the only possible case! + size: Size, + @"align": InternPool.Alignment, + @"const": bool, + @"volatile": bool, + @"allowzero": bool, + + addr: union(enum) { + int: u64, + nav: InternPool.Nav.Index, + uav: Value, + comptime_field: Value, + comptime_alloc: struct { + idx: InternPool.ComptimeAllocIndex, + val: Value, + }, + eu_payload: struct { parent: *PointerDerivation }, + opt_payload: struct { parent: *PointerDerivation }, + field: struct { + parent: *PointerDerivation, + field_index: u32, + }, + elem: struct { + parent: *PointerDerivation, + elem_index: u64, + }, + offset_and_cast: struct { + parent: *PointerDerivation, + byte_offset: u64, + }, }, - pub fn ptrType(step: PointerDeriveStep, pt: Zcu.PerThread) !Type { - return switch (step) { - .int => |int| int.ptr_ty, - .nav_ptr => |nav| try pt.navPtrType(nav), - .uav_ptr => |uav| Type.fromInterned(uav.orig_ty), - .comptime_alloc_ptr => |info| info.ptr_ty, - .comptime_field_ptr => |val| try pt.singleConstPtrType(val.typeOf(pt.zcu)), - .offset_and_cast => |oac| oac.new_ptr_ty, - inline .eu_payload_ptr, .opt_payload_ptr, .field_ptr, .elem_ptr => |x| x.result_ptr_ty, - }; + pub const Size = enum { one, many }; + + pub fn fmtType(pd: PointerDerivation, zcu: *Zcu) FormatType { + return .{ .pd = pd, .zcu = zcu }; } + pub const FormatType = struct { + pd: PointerDerivation, + zcu: *Zcu, + pub fn format(ctx: FormatType, w: *Io.Writer) Io.Writer.Error!void { + const pd = ctx.pd; + switch (pd.size) { + .one => try w.writeByte('*'), + .many => try w.writeAll("[*]"), + } + if (pd.@"align".toByteUnits()) |align_bytes| { + try w.print("align({d}) ", .{align_bytes}); + } + if (pd.@"const") try w.writeAll("const "); + if (pd.@"volatile") try w.writeAll("volatile "); + if (pd.@"allowzero") try w.writeAll("allowzero "); + try pd.elem_ty.print(w, ctx.zcu, null); + } + }; }; /// Given a pointer value, get the sequence of steps to derive it, ideally by taking /// only field and element pointers with no casts. This can be used by codegen backends /// which prefer field/elem accesses when lowering constant pointer values. /// It is also used by the Value printing logic for pointers. -pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, opt_sema: ?*Sema) Allocator.Error!PointerDeriveStep { - const zcu = pt.zcu; +pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu, opt_sema: ?*Sema) Allocator.Error!PointerDerivation { const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr; - const base_derive: PointerDeriveStep = switch (ptr.base_addr) { - .int => return .{ .int = .{ - .addr = ptr.byte_offset, - .ptr_ty = Type.fromInterned(ptr.ty), - } }, - .nav => |nav| .{ .nav_ptr = nav }, + const ptr_ty_info: InternPool.Key.PtrType = info: { + var info = Type.fromInterned(ptr.ty).ptrInfo(zcu); + if (info.packed_offset.host_size != 0) { + // TODO: this function *should* handle packed pointers by returning the derivation of + // the backing int pointer. However, until https://github.com/ziglang/zig/issues/24061 + // is implemented, we don't have access to the backing type. For now, fudge things a + // little by pretending that this is a pointer to anyopaque. What could go wrong? + info.child = .anyopaque_type; + } + break :info info; + }; + const ptr_size: PointerDerivation.Size = switch (ptr_ty_info.flags.size) { + .one => .one, + .many, .c => .many, + .slice => unreachable, + }; + const base_derive: PointerDerivation = switch (ptr.base_addr) { + .int => return .{ + .elem_ty = .fromInterned(ptr_ty_info.child), + .size = ptr_size, + .@"align" = ptr_ty_info.flags.alignment, + .@"const" = ptr_ty_info.flags.is_const, + .@"volatile" = ptr_ty_info.flags.is_volatile, + .@"allowzero" = ptr_ty_info.flags.is_allowzero, + .addr = .{ .int = ptr.byte_offset }, + }, + .nav => |nav| base: { + const resolved = zcu.intern_pool.getNav(nav).resolved.?; + break :base .{ + .elem_ty = .fromInterned(resolved.type), + .size = .one, + .@"align" = resolved.@"align", + .@"const" = resolved.@"const", + .@"volatile" = false, + .@"allowzero" = false, + .addr = .{ .nav = nav }, + }; + }, .uav => |uav| base: { - // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be. - // TODO: fix this in the sites interning anon decls! - const const_ty = try pt.ptrType(info: { - var info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu); - info.flags.is_const = true; - break :info info; - }); - break :base .{ .uav_ptr = .{ - .val = uav.val, - .orig_ty = const_ty.toIntern(), - } }; + const orig_ty_info = Type.fromInterned(uav.orig_ty).ptrInfo(zcu); + break :base .{ + .elem_ty = .fromInterned(orig_ty_info.child), + .size = .one, + .@"align" = orig_ty_info.flags.alignment, + // A slight tweak: `orig_ty` here is sometimes not `const`, but it ought to be. + // TODO: fix this in the sites interning anon decls! + .@"const" = true, + .@"volatile" = orig_ty_info.flags.is_volatile, + .@"allowzero" = orig_ty_info.flags.is_allowzero, + + .addr = .{ .uav = .fromInterned(uav.val) }, + }; }, .comptime_alloc => |idx| base: { const sema = opt_sema.?; const alloc = sema.getComptimeAlloc(idx); - const val = try alloc.val.intern(pt, arena); - const ty = val.typeOf(zcu); - break :base .{ .comptime_alloc_ptr = .{ - .idx = idx, - .val = val, - .ptr_ty = try pt.ptrType(.{ - .child = ty.toIntern(), - .flags = .{ - .alignment = alloc.alignment, - }, - }), - } }; + const val = try alloc.val.intern(sema.pt, arena); + break :base .{ + .elem_ty = val.typeOf(zcu), + .size = .one, + .@"align" = alloc.alignment, + .@"const" = alloc.is_const, + .@"volatile" = false, + .@"allowzero" = false, + .addr = .{ .comptime_alloc = .{ + .idx = idx, + .val = val, + } }, + }; + }, + .comptime_field => |val| .{ + .elem_ty = Value.fromInterned(val).typeOf(zcu), + .size = .one, + .@"align" = .none, + .@"const" = true, + .@"volatile" = false, + .@"allowzero" = false, + .addr = .{ .comptime_field = .fromInterned(val) }, }, - .comptime_field => |val| .{ .comptime_field_ptr = Value.fromInterned(val) }, .eu_payload => |eu_ptr| base: { - const base_ptr = Value.fromInterned(eu_ptr); - const base_ptr_ty = base_ptr.typeOf(zcu); - const parent_step = try arena.create(PointerDeriveStep); - parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, pt, opt_sema); - break :base .{ .eu_payload_ptr = .{ - .parent = parent_step, - .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).errorUnionPayload(zcu)), - } }; + const parent_step = try arena.create(PointerDerivation); + parent_step.* = try pointerDerivation(.fromInterned(eu_ptr), arena, zcu, opt_sema); + break :base .{ + .elem_ty = parent_step.elem_ty.errorUnionPayload(zcu), + .size = .one, + .@"align" = parent_step.@"align", + .@"const" = parent_step.@"const", + .@"volatile" = parent_step.@"volatile", + .@"allowzero" = parent_step.@"allowzero", + .addr = .{ .eu_payload = .{ + .parent = parent_step, + } }, + }; }, .opt_payload => |opt_ptr| base: { - const base_ptr = Value.fromInterned(opt_ptr); - const base_ptr_ty = base_ptr.typeOf(zcu); - const parent_step = try arena.create(PointerDeriveStep); - parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, pt, opt_sema); - break :base .{ .opt_payload_ptr = .{ - .parent = parent_step, - .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).optionalChild(zcu)), - } }; + const parent_step = try arena.create(PointerDerivation); + parent_step.* = try pointerDerivation(.fromInterned(opt_ptr), arena, zcu, opt_sema); + break :base .{ + .elem_ty = parent_step.elem_ty.optionalChild(zcu), + .size = .one, + .@"align" = parent_step.@"align", + .@"const" = parent_step.@"const", + .@"volatile" = parent_step.@"volatile", + .@"allowzero" = parent_step.@"allowzero", + .addr = .{ .opt_payload = .{ + .parent = parent_step, + } }, + }; }, .field => |field| base: { - const base_ptr = Value.fromInterned(field.base); - const base_ptr_ty = try pt.ptrType(info: { - var info = base_ptr.typeOf(zcu).ptrInfo(zcu); - info.flags.size = .one; - break :info info; - }); - const parent_step = try arena.create(PointerDeriveStep); - parent_step.* = try pointerDerivation(base_ptr, arena, pt, opt_sema); - break :base .{ .field_ptr = .{ - .parent = parent_step, - .field_idx = @intCast(field.index), - .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field.index), pt), - } }; + const parent_step = try arena.create(PointerDerivation); + parent_step.* = try pointerDerivation(.fromInterned(field.base), arena, zcu, opt_sema); + break :base .{ + .elem_ty = if (parent_step.elem_ty.isSlice(zcu)) switch (field.index) { + Value.slice_ptr_index => parent_step.elem_ty.slicePtrFieldType(zcu), + Value.slice_len_index => .usize, + else => unreachable, + } else parent_step.elem_ty.fieldType(@intCast(field.index), zcu), + .size = .one, + .@"align" = parent_step.elem_ty.fieldPtrAlign(parent_step.@"align", @intCast(field.index), zcu), + .@"const" = parent_step.@"const", + .@"volatile" = parent_step.@"volatile", + .@"allowzero" = parent_step.@"allowzero", + .addr = .{ .field = .{ + .parent = parent_step, + .field_index = @intCast(field.index), + } }, + }; }, .arr_elem => |arr_elem| base: { - const parent_step = try arena.create(PointerDeriveStep); - parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, pt, opt_sema); - const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu); - const result_ptr_ty = try pt.ptrType(.{ - .child = parent_ptr_info.child, - .flags = flags: { - var flags = parent_ptr_info.flags; - flags.size = .one; - if (flags.alignment != .none) flags.alignment = .minStrict( - flags.alignment, - Type.fromInterned(parent_ptr_info.child).abiAlignment(zcu), - ); - break :flags flags; + const parent_step = try arena.create(PointerDerivation); + parent_step.* = try pointerDerivation(.fromInterned(arr_elem.base), arena, zcu, opt_sema); + break :base .{ + .elem_ty = parent_step.elem_ty, + .size = .many, + .@"align" = switch (parent_step.@"align") { + .none => .none, + else => |a| a.minStrict(parent_step.elem_ty.abiAlignment(zcu)), }, - }); - break :base .{ .elem_ptr = .{ - .parent = parent_step, - .elem_idx = arr_elem.index, - .result_ptr_ty = result_ptr_ty, - } }; + .@"const" = parent_step.@"const", + .@"volatile" = parent_step.@"volatile", + .@"allowzero" = parent_step.@"allowzero", + .addr = .{ .elem = .{ + .parent = parent_step, + .elem_index = arr_elem.index, + } }, + }; }, }; - if (ptr.byte_offset == 0 and ptr.ty == (try base_derive.ptrType(pt)).toIntern()) { + if (ptr.byte_offset == 0 and + ptr_ty_info.child == base_derive.elem_ty.toIntern() and + ptr_size == base_derive.size and + ptr_ty_info.flags.alignment == base_derive.@"align" and + ptr_ty_info.flags.is_const == base_derive.@"const" and + ptr_ty_info.flags.is_volatile == base_derive.@"volatile" and + ptr_ty_info.flags.is_allowzero == base_derive.@"allowzero") + { return base_derive; } - const ptr_ty_info = Type.fromInterned(ptr.ty).ptrInfo(zcu); const need_child: Type = .fromInterned(ptr_ty_info.child); if (need_child.comptimeOnly(zcu) or need_child.zigTypeTag(zcu) == .@"opaque" or @@ -2058,27 +2124,50 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op { // No refinement can happen - this pointer is presumably invalid. // Just offset it. - const parent = try arena.create(PointerDeriveStep); + const parent = try arena.create(PointerDerivation); parent.* = base_derive; - return .{ .offset_and_cast = .{ - .parent = parent, - .byte_offset = ptr.byte_offset, - .new_ptr_ty = Type.fromInterned(ptr.ty), - } }; + return .{ + .elem_ty = .fromInterned(ptr_ty_info.child), + .size = ptr_size, + .@"align" = ptr_ty_info.flags.alignment, + .@"const" = ptr_ty_info.flags.is_const, + .@"volatile" = ptr_ty_info.flags.is_volatile, + .@"allowzero" = ptr_ty_info.flags.is_allowzero, + .addr = .{ .offset_and_cast = .{ + .parent = parent, + .byte_offset = ptr.byte_offset, + } }, + }; } const need_bytes = need_child.abiSize(zcu); var cur_derive = base_derive; var cur_offset = ptr.byte_offset; + if (cur_derive.size == .many) { + const parent = try arena.create(PointerDerivation); + parent.* = cur_derive; + cur_derive = .{ + .elem_ty = parent.elem_ty, + .size = .one, + .@"align" = parent.@"align", + .@"const" = parent.@"const", + .@"volatile" = parent.@"volatile", + .@"allowzero" = parent.@"allowzero", + .addr = .{ .elem = .{ + .parent = parent, + .elem_index = 0, + } }, + }; + } + // Refine through fields and array elements as much as possible. if (need_bytes > 0) while (true) { - const cur_ty = (try cur_derive.ptrType(pt)).childType(zcu); - if (cur_ty.toIntern() == need_child.toIntern() and cur_offset == 0) { + if (cur_derive.elem_ty.toIntern() == need_child.toIntern() and cur_offset == 0) { break; } - switch (cur_ty.zigTypeTag(zcu)) { + switch (cur_derive.elem_ty.zigTypeTag(zcu)) { .noreturn, .type, .comptime_int, @@ -2105,71 +2194,105 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op .optional => { ptr_opt: { - if (!cur_ty.isPtrLikeOptional(zcu)) break :ptr_opt; + if (!cur_derive.elem_ty.isPtrLikeOptional(zcu)) break :ptr_opt; if (need_child.zigTypeTag(zcu) != .pointer) break :ptr_opt; switch (need_child.ptrSize(zcu)) { .one, .many => {}, .slice, .c => break :ptr_opt, } - const parent = try arena.create(PointerDeriveStep); + const parent = try arena.create(PointerDerivation); parent.* = cur_derive; - cur_derive = .{ .opt_payload_ptr = .{ - .parent = parent, - .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), cur_ty.optionalChild(zcu)), - } }; + cur_derive = .{ + .elem_ty = parent.elem_ty.optionalChild(zcu), + .size = .one, + .@"align" = parent.@"align", + .@"const" = parent.@"const", + .@"volatile" = parent.@"volatile", + .@"allowzero" = parent.@"allowzero", + .addr = .{ .opt_payload = .{ + .parent = parent, + } }, + }; continue; } break; }, .array => { - const elem_ty = cur_ty.childType(zcu); + const elem_ty = cur_derive.elem_ty.childType(zcu); const elem_size = elem_ty.abiSize(zcu); const start_idx = cur_offset / elem_size; const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size; + const start_off = start_idx * elem_size; if (end_idx == start_idx + 1 and ptr_ty_info.flags.size == .one) { - const parent = try arena.create(PointerDeriveStep); + const parent = try arena.create(PointerDerivation); parent.* = cur_derive; - cur_derive = .{ .elem_ptr = .{ - .parent = parent, - .elem_idx = start_idx, - .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty), - } }; - cur_offset -= start_idx * elem_size; + cur_derive = .{ + .elem_ty = elem_ty, + .size = .one, + .@"align" = switch (parent.@"align") { + .none => .none, + else => |a| a.offset(start_off), + }, + .@"const" = parent.@"const", + .@"volatile" = parent.@"volatile", + .@"allowzero" = parent.@"allowzero", + .addr = .{ .elem = .{ + .parent = parent, + .elem_index = start_idx, + } }, + }; + cur_offset -= start_off; } else { - // Go into the first element if needed, but don't go any deeper. - if (start_idx > 0) { - const parent = try arena.create(PointerDeriveStep); + // Go into the first element if the byte offsets line up neatly, but don't try + // to go any deeper. + if (start_idx > 0 and start_idx * elem_size == cur_offset) { + const parent = try arena.create(PointerDerivation); parent.* = cur_derive; - cur_derive = .{ .elem_ptr = .{ - .parent = parent, - .elem_idx = start_idx, - .result_ptr_ty = try pt.adjustPtrTypeChild(try parent.ptrType(pt), elem_ty), - } }; - cur_offset -= start_idx * elem_size; + cur_derive = .{ + .elem_ty = elem_ty, + .size = .one, + .@"align" = switch (parent.@"align") { + .none => .none, + else => |a| a.offset(start_off), + }, + .@"const" = parent.@"const", + .@"volatile" = parent.@"volatile", + .@"allowzero" = parent.@"allowzero", + .addr = .{ .elem = .{ + .parent = parent, + .elem_index = start_idx, + } }, + }; + cur_offset -= start_off; } break; } }, - .@"struct" => switch (cur_ty.containerLayout(zcu)) { + .@"struct" => switch (cur_derive.elem_ty.containerLayout(zcu)) { .auto, .@"packed" => break, - .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| { - const field_ty = cur_ty.fieldType(field_idx, zcu); - const start_off = cur_ty.structFieldOffset(field_idx, zcu); + .@"extern" => for (0..cur_derive.elem_ty.structFieldCount(zcu)) |field_idx| { + const field_ty = cur_derive.elem_ty.fieldType(field_idx, zcu); + const start_off = cur_derive.elem_ty.structFieldOffset(field_idx, zcu); const end_off = start_off + field_ty.abiSize(zcu); if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) { - const base_ptr_ty = try pt.ptrType(info: { - var info = (try cur_derive.ptrType(pt)).ptrInfo(zcu); - info.flags.size = .one; - break :info info; - }); - const parent = try arena.create(PointerDeriveStep); + const parent = try arena.create(PointerDerivation); parent.* = cur_derive; - cur_derive = .{ .field_ptr = .{ - .parent = parent, - .field_idx = @intCast(field_idx), - .result_ptr_ty = try base_ptr_ty.fieldPtrType(@intCast(field_idx), pt), - } }; + cur_derive = .{ + .elem_ty = field_ty, + .size = .one, + .@"align" = switch (parent.@"align") { + .none => .none, + else => |a| a.offset(start_off), + }, + .@"const" = parent.@"const", + .@"volatile" = parent.@"volatile", + .@"allowzero" = parent.@"allowzero", + .addr = .{ .field = .{ + .parent = parent, + .field_index = @intCast(field_idx), + } }, + }; cur_offset -= start_off; break; } @@ -2179,31 +2302,33 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, op }; if (cur_offset == 0) compatible: { - const src_ptr_ty_info = (try cur_derive.ptrType(pt)).ptrInfo(zcu); // We allow silently doing some "coercible" pointer things. // In particular, we only give up if cv qualifiers are *removed*. - if (src_ptr_ty_info.flags.is_const and !ptr_ty_info.flags.is_const) break :compatible; - if (src_ptr_ty_info.flags.is_volatile and !ptr_ty_info.flags.is_volatile) break :compatible; - if (src_ptr_ty_info.flags.is_allowzero and !ptr_ty_info.flags.is_allowzero) break :compatible; - // Everything else has to match exactly. - if (src_ptr_ty_info.child != ptr_ty_info.child) break :compatible; - if (src_ptr_ty_info.sentinel != ptr_ty_info.sentinel) break :compatible; - if (src_ptr_ty_info.packed_offset != ptr_ty_info.packed_offset) break :compatible; - if (src_ptr_ty_info.flags.size != ptr_ty_info.flags.size) break :compatible; - if (src_ptr_ty_info.flags.alignment != ptr_ty_info.flags.alignment) break :compatible; - if (src_ptr_ty_info.flags.address_space != ptr_ty_info.flags.address_space) break :compatible; - if (src_ptr_ty_info.flags.vector_index != ptr_ty_info.flags.vector_index) break :compatible; + if (cur_derive.@"const" and !ptr_ty_info.flags.is_const) break :compatible; + if (cur_derive.@"volatile" and !ptr_ty_info.flags.is_volatile) break :compatible; + if (cur_derive.@"allowzero" and !ptr_ty_info.flags.is_allowzero) break :compatible; + // Element type and alignment, however, have to match exactly. + if (cur_derive.elem_ty.toIntern() != ptr_ty_info.child) break :compatible; + if (cur_derive.size != ptr_size) break :compatible; + if (cur_derive.@"align" != ptr_ty_info.flags.alignment) break :compatible; return cur_derive; } - const parent = try arena.create(PointerDeriveStep); + const parent = try arena.create(PointerDerivation); parent.* = cur_derive; - return .{ .offset_and_cast = .{ - .parent = parent, - .byte_offset = cur_offset, - .new_ptr_ty = Type.fromInterned(ptr.ty), - } }; + return .{ + .elem_ty = .fromInterned(ptr_ty_info.child), + .size = ptr_size, + .@"align" = ptr_ty_info.flags.alignment, + .@"const" = ptr_ty_info.flags.is_const, + .@"volatile" = ptr_ty_info.flags.is_volatile, + .@"allowzero" = ptr_ty_info.flags.is_allowzero, + .addr = .{ .offset_and_cast = .{ + .parent = parent, + .byte_offset = cur_offset, + } }, + }; } const InterpretMode = enum { diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index a143fcd93f6caac80b87b4ed943e9262e113bbf4..63e887dc1dd3e441e40d3055cf08d03da2d20d82 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -3459,7 +3459,7 @@ fn analyzeFuncBodyInner( &inner_block, inner_block.nodeOffset(.zero), "cannot resolve inferred error set of {s} function type '{f}'", - .{ description, fn_ty.fmt(pt) }, + .{ description, fn_ty.fmt(zcu) }, ); } @@ -4575,6 +4575,6 @@ fn printVerboseAir( const zcu = pt.zcu; const ip = &zcu.intern_pool; try w.print("# Begin Function AIR: {f}:\n", .{fqn.fmt(ip)}); - try air.write(w, pt, liveness); + try air.write(w, zcu, liveness); try w.print("# End Function AIR: {f}\n\n", .{fqn.fmt(ip)}); } diff --git a/src/codegen.zig b/src/codegen.zig index 2213e7ee506d2156be699188d8d666c1c22d4e7b..d4828f4fc73027aa4e854bf55e002f855ccfe9b0 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -255,7 +255,6 @@ pub fn generateLazySymbol( ) link.EmitError!void { const tracy = trace(@src()); defer tracy.end(); - tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(pt) }); const comp = bin_file.comp; const zcu = pt.zcu; @@ -263,9 +262,11 @@ pub fn generateLazySymbol( const target = &comp.root_mod.resolved_target.result; const endian = target.cpu.arch.endian(); + tracy.addTextFmt("{t}, {f}", .{ lazy_sym.kind, Type.fromInterned(lazy_sym.ty).fmt(zcu) }); + log.debug("generateLazySymbol: kind = {s}, ty = {f}", .{ @tagName(lazy_sym.kind), - Type.fromInterned(lazy_sym.ty).fmt(pt), + Type.fromInterned(lazy_sym.ty).fmt(zcu), }); if (lazy_sym.kind == .code) { @@ -303,7 +304,7 @@ pub fn generateLazySymbol( } } else { return zcu.codegenFailType(lazy_sym.ty, "TODO implement generateLazySymbol for {s} {f}", .{ - @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt), + @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu), }); } } @@ -325,7 +326,7 @@ pub fn generateSymbol( const target = zcu.getTarget(); const endian = target.cpu.arch.endian(); - log.debug("generateSymbol: val = {f}", .{val.fmtValue(pt)}); + log.debug("generateSymbol: val = {f}", .{val.fmtValue(zcu)}); const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse { return zcu.comp.link_diags.fail("failed to generate symbol: type size overflow", .{}); @@ -733,7 +734,7 @@ fn lowerUavRef( const uav_ty = Type.fromInterned(ip.typeOf(uav_val)); const is_fn_body = uav_ty.zigTypeTag(zcu) == .@"fn"; - log.debug("lowerUavRef: ty = {f}", .{uav_ty.fmt(pt)}); + log.debug("lowerUavRef: ty = {f}", .{uav_ty.fmt(zcu)}); if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) { try w.splatByteAll(0xaa, ptr_width_bytes); @@ -876,7 +877,7 @@ pub fn lowerValue(pt: Zcu.PerThread, val: Value, target: *const std.Target) Allo const ip = &zcu.intern_pool; const ty = val.typeOf(zcu); - log.debug("lowerValue(@as({f}, {f}))", .{ ty.fmt(pt), val.fmtValue(pt) }); + log.debug("lowerValue(@as({f}, {f}))", .{ ty.fmt(zcu), val.fmtValue(zcu) }); if (val.isUndef(zcu)) return .undef; diff --git a/src/codegen/aarch64/Select.zig b/src/codegen/aarch64/Select.zig index 642c8ba765e21bac786b6e7d27addb24224c24a7..202793ebdc1a3284eed294988deccc9dfa8da12e 100644 --- a/src/codegen/aarch64/Select.zig +++ b/src/codegen/aarch64/Select.zig @@ -946,7 +946,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void isel: *Select, inst: Air.Inst.Index, pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { - fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt, null); + fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt.zcu, null); } } { return .{ .isel = it.isel, .inst = inst }; @@ -7974,11 +7974,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct { } fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter { - return ty.fmt(isel.pt); + return ty.fmt(isel.pt.zcu); } fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? { - return constant.fmtValue(isel.pt); + return constant.fmtValue(isel.pt.zcu); } fn block( diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 4cb12fdbcdfa42680cc44e305a89b6fd85a5f499..4e58ede308fcaefe9b58ee073b3f1b21eaba8e76 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -740,59 +740,57 @@ pub const DeclGen = struct { fn renderUav( dg: *DeclGen, w: *Writer, - uav: InternPool.Key.Ptr.BaseAddr.Uav, + uav_val: Value, + derivation: Value.PointerDerivation, location: ValueRenderLocation, ) Error!void { const pt = dg.pt; const zcu = pt.zcu; const ip = &zcu.intern_pool; - const uav_val = Value.fromInterned(uav.val); const uav_ty = uav_val.typeOf(zcu); // Render an undefined pointer if we have a pointer to a zero-bit or comptime type. - const ptr_ty: Type = .fromInterned(uav.orig_ty); - if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) { - try w.writeByte('('); - try dg.renderOpvPointer(w, ptr_ty, location); - return w.writeByte(')'); + if (!uav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) { + const target = zcu.getTarget(); + const alignment = switch (derivation.@"align") { + .none => derivation.elem_ty.abiAlignment(zcu), + else => |a| a, + }; + try w.writeAll("(("); + try dg.renderDerivedPointerType(w, derivation); + try w.print("){f})", .{fmtUnsignedIntLiteralSmall( + target, + .uintptr_t, + alignment.forward(undefPattern(u64) >> @intCast(64 - target.ptrBitWidth())), + location == .static_initializer, + 16, + .lower, + )}); + return; } - switch (ip.indexToKey(uav.val)) { + switch (ip.indexToKey(uav_val.toIntern())) { .func => unreachable, .@"extern" => unreachable, else => {}, } - // We shouldn't cast C function pointers as this is UB (when you call - // them). The analysis until now should ensure that the C function - // pointers are compatible. If they are not, then there is a bug - // somewhere and we should let the C compiler tell us about it. - const elem_ty = ptr_ty.childType(zcu); - const need_cast = elem_ty.toIntern() != uav_ty.toIntern() and - elem_ty.zigTypeTag(zcu) != .@"fn" or uav_ty.zigTypeTag(zcu) != .@"fn"; - if (need_cast) { - try w.writeAll("(("); - try dg.renderType(w, ptr_ty); - try w.writeByte(')'); - } try w.writeByte('&'); try renderUavName(w, uav_val); - if (need_cast) try w.writeByte(')'); // Indicate that the anon decl should be rendered to the output so that // our reference above is not undefined. - const ptr_type = ip.indexToKey(uav.orig_ty).ptr_type; - const gop = try dg.uavs.getOrPut(dg.gpa, uav.val); + const gop = try dg.uavs.getOrPut(dg.gpa, uav_val.toIntern()); if (!gop.found_existing) gop.value_ptr.* = .none; // If there is an explicit alignment, greater than the current one, use it. // Note that we intentionally start at `.none`, so `gop.value_ptr.*` is never // underaligned, so we don't need to worry about the `.none` case here. - if (ptr_type.flags.alignment != .none) { + if (derivation.@"align" != .none) { // Resolve the current alignment so we can choose the bigger one. const cur_alignment: Alignment = if (gop.value_ptr.* == .none) abi: { - break :abi Type.fromInterned(ptr_type.child).abiAlignment(zcu); + break :abi uav_ty.abiAlignment(zcu); } else gop.value_ptr.*; - gop.value_ptr.* = cur_alignment.maxStrict(ptr_type.flags.alignment); + gop.value_ptr.* = cur_alignment.maxStrict(derivation.@"align"); } } @@ -818,28 +816,14 @@ pub const DeclGen = struct { // Render an undefined pointer if we have a pointer to a zero-bit or comptime type. const nav_ty: Type = .fromInterned(ip.getNav(owner_nav).resolved.?.type); - const ptr_ty = try pt.navPtrType(owner_nav); if (nav_ty.zigTypeTag(zcu) != .@"opaque" and !nav_ty.isRuntimeFnOrHasRuntimeBits(zcu)) { try w.writeByte('('); - try dg.renderOpvPointer(w, ptr_ty, location); + try dg.renderOpvPointer(w, try pt.navPtrType(owner_nav), location); return w.writeByte(')'); } - // We shouldn't cast C function pointers as this is UB (when you call - // them). The analysis until now should ensure that the C function - // pointers are compatible. If they are not, then there is a bug - // somewhere and we should let the C compiler tell us about it. - const elem_ty = ptr_ty.childType(zcu); - const need_cast = elem_ty.toIntern() != nav_ty.toIntern() and - elem_ty.zigTypeTag(zcu) != .@"fn" or nav_ty.zigTypeTag(zcu) != .@"fn"; - if (need_cast) { - try w.writeAll("(("); - try dg.renderType(w, ptr_ty); - try w.writeByte(')'); - } try w.writeByte('&'); try renderNavName(w, owner_nav, ip); - if (need_cast) try w.writeByte(')'); } fn renderOpvPointer( @@ -865,92 +849,108 @@ pub const DeclGen = struct { fn renderPointer( dg: *DeclGen, w: *Writer, - derivation: Value.PointerDeriveStep, + derivation: Value.PointerDerivation, location: ValueRenderLocation, ) Error!void { const pt = dg.pt; const zcu = pt.zcu; - switch (derivation) { - .comptime_alloc_ptr, .comptime_field_ptr => unreachable, + switch (derivation.addr) { + .comptime_alloc, .comptime_field => unreachable, .int => |int| { - const addr_val = try pt.intValue(.usize, int.addr); + const addr_val = try pt.intValue(.usize, int); try w.writeByte('('); - try dg.renderType(w, int.ptr_ty); + try dg.renderDerivedPointerType(w, derivation); try w.print("){f}", .{try dg.fmtIntLiteralHex(addr_val, .other)}); }, - .nav_ptr => |nav| try dg.renderNav(w, nav, location), - .uav_ptr => |uav| try dg.renderUav(w, uav, location), + .nav => |nav| try dg.renderNav(w, nav, location), + .uav => |val| try dg.renderUav(w, val, derivation, location), - inline .eu_payload_ptr, .opt_payload_ptr => |info| { + inline .eu_payload, .opt_payload => |info| { try w.writeAll("&("); try dg.renderPointer(w, info.parent.*, location); try w.writeAll(")->payload"); }, - .field_ptr => |field| { - const parent_ptr_ty = try field.parent.ptrType(pt); - - switch (fieldLocation(parent_ptr_ty, field.result_ptr_ty, field.field_idx, zcu)) { + .field => |derived| { + switch (fieldLocation(derived.parent.elem_ty, derivation.elem_ty, derived.field_index, zcu)) { .begin => { try w.writeByte('('); - try dg.renderType(w, field.result_ptr_ty); + try dg.renderDerivedPointerType(w, derivation); try w.writeByte(')'); - try dg.renderPointer(w, field.parent.*, location); + try dg.renderPointer(w, derived.parent.*, location); }, .field => |name| { try w.writeAll("&("); - try dg.renderPointer(w, field.parent.*, location); + try dg.renderPointer(w, derived.parent.*, location); try w.writeAll(")->"); try dg.writeCValue(w, name); }, .byte_offset => |byte_offset| { try w.writeByte('('); - try dg.renderType(w, field.result_ptr_ty); + try dg.renderDerivedPointerType(w, derivation); try w.writeByte(')'); const offset_val = try pt.intValue(.usize, byte_offset); try w.writeAll("((char *)"); - try dg.renderPointer(w, field.parent.*, location); + try dg.renderPointer(w, derived.parent.*, location); try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)}); }, } }, - .elem_ptr => |elem| if (!(try elem.parent.ptrType(pt)).childType(zcu).hasRuntimeBits(zcu)) { + .elem => |derived| if (!derived.parent.elem_ty.hasRuntimeBits(zcu)) { // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer. try w.writeByte('('); - try dg.renderType(w, elem.result_ptr_ty); + try dg.renderDerivedPointerType(w, derivation); try w.writeByte(')'); - try dg.renderPointer(w, elem.parent.*, location); + try dg.renderPointer(w, derived.parent.*, location); } else { - const index_val = try pt.intValue(.usize, elem.elem_idx); + const index_val = try pt.intValue(.usize, derived.elem_index); try w.writeByte('('); // We want to do pointer arithmetic on a pointer to the element type, but the parent - // might be a pointer-to-array, in which case we must cast it. - if (elem.result_ptr_ty.toIntern() != (try elem.parent.ptrType(pt)).toIntern()) { - try w.writeByte('('); - try dg.renderType(w, elem.result_ptr_ty); - try w.writeByte(')'); - } - try dg.renderPointer(w, elem.parent.*, location); + // is a pointer-to-array, so we need to cast first. + try w.writeByte('('); + try dg.renderDerivedPointerType(w, derivation); + try w.writeByte(')'); + + try dg.renderPointer(w, derived.parent.*, location); try w.print(" + {f})", .{try dg.fmtIntLiteralDec(index_val, .other)}); }, - .offset_and_cast => |oac| { + .offset_and_cast => |derived| { try w.writeByte('('); - try dg.renderType(w, oac.new_ptr_ty); + try dg.renderDerivedPointerType(w, derivation); try w.writeByte(')'); - if (oac.byte_offset == 0) { - try dg.renderPointer(w, oac.parent.*, location); + if (derived.byte_offset == 0) { + try dg.renderPointer(w, derived.parent.*, location); } else { - const offset_val = try pt.intValue(.usize, oac.byte_offset); + const offset_val = try pt.intValue(.usize, derived.byte_offset); try w.writeAll("((char *)"); - try dg.renderPointer(w, oac.parent.*, location); + try dg.renderPointer(w, derived.parent.*, location); try w.print(" + {f})", .{try dg.fmtIntLiteralDec(offset_val, .other)}); } }, } } + fn renderDerivedPointerType( + dg: *DeclGen, + w: *Writer, + derivation: Value.PointerDerivation, + ) Error!void { + return dg.renderType(w, try dg.pt.ptrType(.{ + .child = derivation.elem_ty.toIntern(), + .flags = .{ + .size = switch (derivation.size) { + .one => .one, + .many => .many, + }, + .alignment = derivation.@"align", + .is_const = derivation.@"const", + .is_volatile = derivation.@"volatile", + .is_allowzero = derivation.@"allowzero", + }, + })); + } fn renderValueAsLvalue( dg: *DeclGen, @@ -1166,7 +1166,31 @@ pub const DeclGen = struct { try w.writeByte('}'); }, .ptr => { - const derivation = try val.pointerDerivation(dg.arena, pt, null); + // TODO: `Value.pointerDerivation` ought to do this for us, but it doesn't receive + // `pt`, so it actually *can't* until https://github.com/ziglang/zig/issues/24061 is + // implemented. + const non_packed_ptr: Value = non_packed_ptr: { + const ptr_info = val.typeOf(zcu).ptrInfo(zcu); + if (ptr_info.packed_offset.host_size == 0) { + break :non_packed_ptr val; + } + const backing_ty: Type = switch (ptr_info.flags.vector_index) { + _ => .fromInterned(ptr_info.child), + .none => try pt.intType( + .unsigned, + @intCast(ptr_info.packed_offset.host_size * 8), + ), + }; + const new_ptr_ty = try pt.ptrType(info: { + var info = ptr_info; + info.child = backing_ty.toIntern(); + info.packed_offset = .{ .host_size = 0, .bit_offset = 0 }; + info.flags.vector_index = .none; + break :info info; + }); + break :non_packed_ptr try pt.getCoerced(val, new_ptr_ty); + }; + const derivation = try non_packed_ptr.pointerDerivation(dg.arena, zcu, null); try w.writeByte('('); try dg.renderPointer(w, derivation, location); try w.writeByte(')'); @@ -5380,8 +5404,8 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue { } fn fieldLocation( - container_ptr_ty: Type, - field_ptr_ty: Type, + container_ty: Type, + field_ty: Type, field_index: u32, zcu: *Zcu, ) union(enum) { @@ -5390,27 +5414,22 @@ fn fieldLocation( byte_offset: u64, } { const ip = &zcu.intern_pool; - const container_ty: Type = .fromInterned(ip.indexToKey(container_ptr_ty.toIntern()).ptr_type.child); switch (ip.indexToKey(container_ty.toIntern())) { .struct_type => { const loaded_struct = ip.loadStructType(container_ty.toIntern()); return switch (loaded_struct.layout) { .auto, .@"extern" => if (!container_ty.hasRuntimeBits(zcu)) .begin - else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu)) + else if (!field_ty.hasRuntimeBits(zcu)) .{ .byte_offset = loaded_struct.field_offsets.get(ip)[field_index] } else .{ .field = .{ .identifier = loaded_struct.field_names.get(ip)[field_index].toSlice(ip) } }, - .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0) - .{ .byte_offset = @divExact(zcu.structPackedFieldBitOffset(loaded_struct, field_index) + - container_ptr_ty.ptrInfo(zcu).packed_offset.bit_offset, 8) } - else - .begin, + .@"packed" => .begin, }; }, .tuple_type => return if (!container_ty.hasRuntimeBits(zcu)) .begin - else if (!field_ptr_ty.childType(zcu).hasRuntimeBits(zcu)) + else if (!field_ty.hasRuntimeBits(zcu)) .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) } else .{ .field = .{ .field = field_index } }, @@ -5418,7 +5437,6 @@ fn fieldLocation( const loaded_union = ip.loadUnionType(container_ty.toIntern()); switch (loaded_union.layout) { .auto => { - const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); if (!field_ty.hasRuntimeBits(zcu)) { if (container_ty.unionHasAllZeroBitFieldTypes(zcu)) return .begin; return .{ .field = .{ .identifier = "payload" } }; @@ -5427,7 +5445,6 @@ fn fieldLocation( return .{ .field = .{ .payload_identifier = field_name.toSlice(ip) } }; }, .@"extern" => { - const field_ty: Type = .fromInterned(loaded_union.field_types.get(ip)[field_index]); if (!field_ty.hasRuntimeBits(zcu)) return .begin; const field_name = ip.loadEnumType(loaded_union.enum_tag_type).field_names.get(ip)[field_index]; return .{ .field = .{ .identifier = field_name.toSlice(ip) } }; @@ -5486,7 +5503,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue { try f.renderType(w, container_ptr_ty); try w.writeByte(')'); - switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, zcu)) { + switch (fieldLocation(container_ty, field_ptr_ty.childType(zcu), extra.field_index, zcu)) { .begin => try f.writeCValue(w, field_ptr_val, .other), .field => |field| { const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8); @@ -5537,7 +5554,12 @@ fn fieldPtr( try f.renderType(w, field_ptr_ty); try w.writeByte(')'); - switch (fieldLocation(container_ptr_ty, field_ptr_ty, field_index, zcu)) { + switch (fieldLocation( + container_ptr_ty.childType(zcu), + field_ptr_ty.childType(zcu), + field_index, + zcu, + )) { .begin => try f.writeCValue(w, container_ptr_val, .other), .field => |field| { try w.writeByte('&'); diff --git a/src/codegen/c/type/render_defs.zig b/src/codegen/c/type/render_defs.zig index 2ba76d64eda0073dc0cdb032d117fedf16fba0ae..e1a18240a7aa908dbd7f5877db07874c9755b5a1 100644 --- a/src/codegen/c/type/render_defs.zig +++ b/src/codegen/c/type/render_defs.zig @@ -28,7 +28,7 @@ pub fn defineAligned( }); if (!zcu.comp.config.root_strip) try w.print(" /* align({d}) {f} */", .{ alignment.toByteUnits().?, - ty.fmt(pt), + ty.fmt(zcu), }); try w.writeByte('\n'); } @@ -113,7 +113,7 @@ pub fn errunionDefineComplete( }); } if (!zcu.comp.config.root_strip) try w.print(" /* anyerror!{f} */", .{ - payload_ty.fmt(pt), + payload_ty.fmt(zcu), }); try w.writeByte('\n'); } @@ -159,7 +159,7 @@ pub fn defineIncomplete(ty: Type, w: *Writer, pt: Zcu.PerThread) Writer.Error!vo name_cty.fmtTypeName(zcu), }); if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{ - ty.fmt(pt), + ty.fmt(zcu), }); try w.writeByte('\n'); } @@ -337,7 +337,7 @@ pub fn defineComplete( else => return, }; if (!zcu.comp.config.root_strip) try w.print(" /* {f} */", .{ - ty.fmt(pt), + ty.fmt(zcu), }); try w.writeByte('\n'); if (check_cty) |cty| try writeStaticAssertTypeLayout(ty, cty, w, zcu); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index d6306efe283c597de97eb703da03f25440be6757..a8adfba6fc0c39da8db4226231dfd50387a123ec 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1354,6 +1354,7 @@ pub const Object = struct { /// /// `val` is always a type because `o.type_pool` only contains types. pub fn updateConstIncomplete(o: *Object, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void { + _ = pt; const zcu = o.zcu; assert(zcu.intern_pool.typeOf(val) == .type_type); @@ -1367,7 +1368,7 @@ pub const Object = struct { if (!o.builder.strip) { assert(val != .anyerror_type); const fwd_ref = o.debug_types.items[@backingInt(index)]; - const name_str = try o.builder.metadataStringFmt("{f}", .{ty.fmt(pt)}); + const name_str = try o.builder.metadataStringFmt("{f}", .{ty.fmt(zcu)}); // If `ty` is a function, use a dummy *function* type to prevent existing debug // subprograms from becoming ill-formed. const debug_incomplete_type = switch (ty.zigTypeTag(zcu)) { @@ -1458,7 +1459,7 @@ pub const Object = struct { const target = zcu.getTarget(); const ip = &zcu.intern_pool; - const name = try o.builder.metadataStringFmt("{f}", .{ty.fmt(pt)}); + const name = try o.builder.metadataStringFmt("{f}", .{ty.fmt(zcu)}); // lldb cannot handle non-byte-sized types, so in the logic below, bit sizes are padded up. // 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 { const debug_payload_type = try o.builder.debugUnionType( payload_name: { if (layout.tag_size == 0) break :payload_name name; - break :payload_name try o.builder.metadataStringFmt("{f}:Payload", .{ty.fmt(pt)}); + break :payload_name try o.builder.metadataStringFmt("{f}:Payload", .{ty.fmt(zcu)}); }, file, scope, diff --git a/src/codegen/loongarch/Select.zig b/src/codegen/loongarch/Select.zig index 278ca9dfc37ffddcefb3c84fcfd8a031e6c0837a..8ab2f7a9d2bd910ce8e57e4b4ed2f73a7ffb6bbd 100644 --- a/src/codegen/loongarch/Select.zig +++ b/src/codegen/loongarch/Select.zig @@ -3016,7 +3016,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) codegen.Error!void isel: *Select, inst: Air.Inst.Index, pub fn format(fmt_air: @This(), writer: *std.Io.Writer) std.Io.Writer.Error!void { - fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt, null); + fmt_air.isel.air.writeInst(writer, fmt_air.inst, fmt_air.isel.pt.zcu, null); } } { return .{ .isel = it.isel, .inst = inst }; @@ -5266,11 +5266,11 @@ fn fmtLoopLive(isel: *Select, loop_inst: Air.Inst.Index) struct { } fn fmtType(isel: *Select, ty: ZigType) ZigType.Formatter { - return ty.fmt(isel.pt); + return ty.fmt(isel.pt.zcu); } fn fmtConstant(isel: *Select, constant: Constant) @typeInfo(@TypeOf(Constant.fmtValue)).@"fn".return_type.? { - return constant.fmtValue(isel.pt); + return constant.fmtValue(isel.pt.zcu); } fn fmtRegisterSet(regs: RegisterSet) struct { diff --git a/src/codegen/riscv64/CodeGen.zig b/src/codegen/riscv64/CodeGen.zig index aeb1dde892769fe1270542079b778ed6487d0cdf..84e714fa11953fe023980ed079f3d90adf89dc49 100644 --- a/src/codegen/riscv64/CodeGen.zig +++ b/src/codegen/riscv64/CodeGen.zig @@ -1291,7 +1291,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void { switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) { .@"enum" => { const enum_ty = Type.fromInterned(lazy_sym.ty); - wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)}); + wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(zcu)}); const param_regs = abi.Registers.Integer.function_arg_regs; const ret_reg = param_regs[0]; @@ -1374,7 +1374,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void { }, else => return func.fail( "TODO implement {s} for {f}", - .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) }, + .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu) }, ), } } @@ -1911,7 +1911,7 @@ fn splitType(func: *Func, ty: Type) ![2]Type { else => return func.fail("TODO: splitType class {}", .{class}), }; } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts; - return func.fail("TODO implement splitType for {f}", .{ty.fmt(func.pt)}); + return func.fail("TODO implement splitType for {f}", .{ty.fmt(zcu)}); } /// Truncates the value in the register in place. @@ -2024,7 +2024,7 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex { const val_ty = ptr_ty.childType(zcu); return func.allocFrameIndex(FrameAlloc.init(.{ .size = math.cast(u32, val_ty.abiSize(zcu)) orelse { - return func.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)}); + return func.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(zcu)}); }, .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"), })); @@ -2164,7 +2164,7 @@ pub fn spillRegisters(func: *Func, comptime registers: []const Register) !void { /// allocated. A second call to `copyToTmpRegister` may return the same register. /// This can have a side effect of spilling instructions to the stack to free up a register. fn copyToTmpRegister(func: *Func, ty: Type, mcv: MCValue) !Register { - log.debug("copyToTmpRegister ty: {f}", .{ty.fmt(func.pt)}); + log.debug("copyToTmpRegister ty: {f}", .{ty.fmt(func.pt.zcu)}); const reg = try func.register_manager.allocReg(null, func.regTempClassForType(ty)); try func.genSetReg(ty, reg, mcv); return reg; @@ -2249,7 +2249,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void { break :result dst_mcv; } orelse return func.fail("TODO: implement airIntCast from {f} to {f}", .{ - src_ty.fmt(pt), dst_ty.fmt(pt), + src_ty.fmt(zcu), dst_ty.fmt(zcu), }); return func.finishAir(inst, result, .{ ty_op.operand, .none, .none }); @@ -2636,7 +2636,7 @@ fn genBinOp( .add_sat, => { if (bit_size != 64 or !is_unsigned) - return func.fail("TODO: genBinOp ty: {f}", .{lhs_ty.fmt(pt)}); + return func.fail("TODO: genBinOp ty: {f}", .{lhs_ty.fmt(zcu)}); const tmp_reg = try func.copyToTmpRegister(rhs_ty, .{ .register = rhs_reg }); const tmp_lock = func.register_manager.lockRegAssumeUnused(tmp_reg); @@ -4057,7 +4057,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void { } else { return func.fail( "TODO implement get_union_tag for ABI larger than 8 bytes and operand {}, tag {f}", - .{ frame_mcv, tag_ty.fmt(pt) }, + .{ frame_mcv, tag_ty.fmt(zcu) }, ); } }, @@ -4177,7 +4177,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void { switch (scalar_ty.zigTypeTag(zcu)) { .int => if (ty.zigTypeTag(zcu) == .vector) { - return func.fail("TODO implement airAbs for {f}", .{ty.fmt(pt)}); + return func.fail("TODO implement airAbs for {f}", .{ty.fmt(zcu)}); } else { const int_info = scalar_ty.intInfo(zcu); const int_bits = int_info.bits; @@ -4258,7 +4258,7 @@ fn airAbs(func: *Func, inst: Air.Inst.Index) !void { break :result return_mcv; }, - else => return func.fail("TODO: implement airAbs {f}", .{scalar_ty.fmt(pt)}), + else => return func.fail("TODO: implement airAbs {f}", .{scalar_ty.fmt(zcu)}), } break :result .unreach; @@ -4322,7 +4322,7 @@ fn airByteSwap(func: *Func, inst: Air.Inst.Index) !void { break :result dest_mcv; }, - else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(pt)}), + else => return func.fail("TODO: airByteSwap {f}", .{ty.fmt(zcu)}), } }; 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 { else => return func.fail("TODO: airUnaryMath Float {s}", .{@tagName(tag)}), } }, - else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(pt)}), + else => return func.fail("TODO: airUnaryMath ty: {f}", .{ty.fmt(zcu)}), } break :result MCValue{ .register = dst_reg }; @@ -4488,7 +4488,7 @@ fn load(func: *Func, dst_mcv: MCValue, ptr_mcv: MCValue, ptr_ty: Type) InnerErro const zcu = pt.zcu; const dst_ty = ptr_ty.childType(zcu); - log.debug("loading {}:{f} into {}", .{ ptr_mcv, ptr_ty.fmt(pt), dst_mcv }); + log.debug("loading {}:{f} into {}", .{ ptr_mcv, ptr_ty.fmt(zcu), dst_mcv }); switch (ptr_mcv) { .none, @@ -4541,7 +4541,7 @@ fn airStore(func: *Func, inst: Air.Inst.Index, safety: bool) !void { fn store(func: *Func, ptr_mcv: MCValue, src_mcv: MCValue, ptr_ty: Type) !void { const zcu = func.pt.zcu; const src_ty = ptr_ty.childType(zcu); - log.debug("storing {}:{f} in {}:{f}", .{ src_mcv, src_ty.fmt(func.pt), ptr_mcv, ptr_ty.fmt(func.pt) }); + log.debug("storing {}:{f} in {}:{f}", .{ src_mcv, src_ty.fmt(zcu), ptr_mcv, ptr_ty.fmt(zcu) }); switch (ptr_mcv) { .none => unreachable, @@ -7269,7 +7269,7 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void { const bit_size = dst_ty.bitSize(zcu); if (abi_size * 8 <= bit_size) break :result dst_mcv; - return func.fail("TODO: airBitCast {f} to {f}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) }); + return func.fail("TODO: airBitCast {f} to {f}", .{ src_ty.fmt(zcu), dst_ty.fmt(zcu) }); }; return func.finishAir(inst, result, .{ ty_op.operand, .none, .none }); } @@ -8085,7 +8085,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void { ); break :result .{ .load_frame = .{ .index = frame_index } }; }, - else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(pt)}), + else => return func.fail("TODO: airAggregate {f}", .{result_ty.fmt(zcu)}), } }; @@ -8279,7 +8279,7 @@ fn resolveCallingConventionValues( }; result.return_value = switch (ret_tracking_i) { - else => return func.fail("ty {f} took {} tracking return indices", .{ ret_ty.fmt(pt), ret_tracking_i }), + else => return func.fail("ty {f} took {} tracking return indices", .{ ret_ty.fmt(zcu), ret_tracking_i }), 1 => ret_tracking[0], 2 => InstTracking.init(.{ .register_pair = .{ ret_tracking[0].short.register, ret_tracking[1].short.register, @@ -8334,7 +8334,7 @@ fn resolveCallingConventionValues( else => return func.fail("TODO: C calling convention arg class {}", .{class}), } else { arg.* = switch (arg_mcv_i) { - else => return func.fail("ty {f} took {} tracking arg indices", .{ ty.fmt(pt), arg_mcv_i }), + else => return func.fail("ty {f} took {} tracking arg indices", .{ ty.fmt(zcu), arg_mcv_i }), 1 => arg_mcv[0], 2 => .{ .register_pair = .{ arg_mcv[0].register, arg_mcv[1].register } }, }; diff --git a/src/codegen/sparc64/CodeGen.zig b/src/codegen/sparc64/CodeGen.zig index a35ceb4fcbe8e18abd11ebef7c5852bca56b6bc3..fa1fa97202b53442e2c87cf8f9780ea1e05a9b06 100644 --- a/src/codegen/sparc64/CodeGen.zig +++ b/src/codegen/sparc64/CodeGen.zig @@ -985,7 +985,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) InnerError!void { switch (self.args[arg_index]) { .stack_offset => |off| { const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse { - return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(pt)}); + return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(zcu)}); }; const offset = off + abi_size; break :blk .{ .stack_offset = offset }; @@ -2722,7 +2722,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 { } const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse { - return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(pt)}); + return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(zcu)}); }; // TODO swap this for inst.ty.ptrAlign const abi_align = elem_ty.abiAlignment(zcu); @@ -2734,7 +2734,7 @@ fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue { const zcu = pt.zcu; const elem_ty = self.typeOfIndex(inst); const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse { - return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(pt)}); + return self.fail("type '{f}' too big to fit into stack frame", .{elem_ty.fmt(zcu)}); }; const abi_align = elem_ty.abiAlignment(zcu); self.stack_align = self.stack_align.max(abi_align); diff --git a/src/codegen/spirv/CodeGen.zig b/src/codegen/spirv/CodeGen.zig index fa304a7473a5b0777702830faf79293bc8a05a4f..24d5fac0c6357222e593a996d8cff7152f899e22 100644 --- a/src/codegen/spirv/CodeGen.zig +++ b/src/codegen/spirv/CodeGen.zig @@ -1297,8 +1297,8 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id { const ip = &zcu.intern_pool; log.debug("lowering constant: ty = {f}, val = {f}, key = {s}", .{ - ty.fmt(pt), - val.fmtValue(pt), + ty.fmt(zcu), + val.fmtValue(zcu), @tagName(ip.indexToKey(val.toIntern())), }); assert(!ty.isPtrAtRuntime(zcu)); @@ -1640,7 +1640,6 @@ fn constant(cg: *CodeGen, ty: Type, val: Value, repr: Repr) Error!Id { } fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id { - const pt = cg.pt; const zcu = cg.zcu; const gpa = cg.gpa; @@ -1653,32 +1652,64 @@ fn constantPtr(cg: *CodeGen, ptr_val: Value) !Id { var arena = std.heap.ArenaAllocator.init(gpa); defer arena.deinit(); - const derivation = try ptr_val.pointerDerivation(arena.allocator(), pt, null); - return cg.derivePtr(derivation); + // TODO: `Value.pointerDerivation` ought to do this for us, but it doesn't receive + // `pt`, so it actually *can't* until https://github.com/ziglang/zig/issues/24061 is + // implemented. + const non_packed_ptr_val: Value = non_packed_ptr: { + const ptr_info = ptr_val.typeOf(zcu).ptrInfo(zcu); + if (ptr_info.packed_offset.host_size == 0) { + break :non_packed_ptr ptr_val; + } + const backing_ty: Type = switch (ptr_info.flags.vector_index) { + _ => try cg.pt.vectorType(.{ + .child = ptr_info.child, + .len = ptr_info.packed_offset.host_size, + }), + .none => try cg.pt.intType( + .unsigned, + @intCast(ptr_info.packed_offset.host_size * 8), + ), + }; + const new_ptr_ty = try cg.pt.ptrType(info: { + var info = ptr_info; + info.child = backing_ty.toIntern(); + info.packed_offset = .{ .host_size = 0, .bit_offset = 0 }; + info.flags.vector_index = .none; + break :info info; + }); + break :non_packed_ptr try cg.pt.getCoerced(ptr_val, new_ptr_ty); + }; + + const derivation = try non_packed_ptr_val.pointerDerivation(arena.allocator(), zcu, null); + return cg.derivePtr(ptr_val.typeOf(zcu).ptrAddressSpace(zcu), derivation); } -fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { +fn derivePtr(cg: *CodeGen, @"addrspace": std.lang.AddressSpace, derivation: Value.PointerDerivation) !Id { const gpa = cg.gpa; - const pt = cg.pt; const zcu = cg.zcu; const target = zcu.getTarget(); - switch (derivation) { - .comptime_alloc_ptr, .comptime_field_ptr => unreachable, + + const result_ty_id = try cg.ptrType( + try cg.pointeeType(@"addrspace", derivation.elem_ty, false), + cg.storageClass(@"addrspace"), + ); + + switch (derivation.addr) { + .comptime_alloc, .comptime_field => unreachable, .int => |int| { if (target.os.tag != .opencl) { - if (int.ptr_ty.ptrAddressSpace(zcu) != .physical_storage_buffer) { + if (@"addrspace" != .physical_storage_buffer) { return cg.fail( "cannot cast integer to pointer with address space '{s}'", - .{@tagName(int.ptr_ty.ptrAddressSpace(zcu))}, + .{@tagName(@"addrspace")}, ); } } - const result_ty_id = try cg.resolveType(int.ptr_ty, .direct); // TODO: This can probably be an OpSpecConstantOp Bitcast, but // that is not implemented by Mesa yet. Therefore, just generate it // as a runtime operation. const result_ptr_id = cg.allocId(); - const value_id = try cg.constInt(.usize, int.addr); + const value_id = try cg.constInt(.usize, int); try cg.body.emit(gpa, .OpConvertUToPtr, .{ .id_result_type = result_ty_id, .id_result = result_ptr_id, @@ -1686,10 +1717,8 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { }); return result_ptr_id; }, - .nav_ptr => |nav_index| { + .nav => |nav_index| { const ip = &zcu.intern_pool; - const result_ptr_ty = try pt.navPtrType(nav_index); - const ty_id = try cg.resolveType(result_ptr_ty, .direct); const nav = ip.getNav(nav_index); const nav_ty: Type = .fromInterned(nav.resolved.?.type); @@ -1698,10 +1727,10 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { if (ip.isFunctionType(nav_ty.toIntern())) { if (is_extern) return try cg.resolveExternFn(nav_index); - return try cg.constUndef(ty_id); + return try cg.constUndef(result_ty_id); } if (!nav_ty.hasRuntimeBits(zcu) and nav_ty.zigTypeTag(zcu) != .spirv) { - return cg.constUndef(ty_id); + return cg.constUndef(result_ty_id); } if (!is_extern) { return cg.todo("pointer to constant '{f}'", .{nav.fqn.fmt(ip)}); @@ -1718,7 +1747,7 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { try cg.block_var_ids.put(gpa, var_id, {}); } - if (decl_ptr_ty_id == ty_id) return var_id; + if (decl_ptr_ty_id == result_ty_id) return var_id; switch (target.os.tag) { .vulkan, .opengl => return var_id, else => {}, @@ -1726,63 +1755,63 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { const casted_ptr_id = cg.allocId(); try cg.body.emit(gpa, .OpBitcast, .{ - .id_result_type = ty_id, + .id_result_type = result_ty_id, .id_result = casted_ptr_id, .operand = var_id, }); return casted_ptr_id; }, - .uav_ptr => |uav| { + .uav => |uav_val| { const ip = &zcu.intern_pool; - const result_ptr_ty: Type = .fromInterned(uav.orig_ty); - const ty_id = try cg.resolveType(result_ptr_ty, .direct); - const uav_ty: Type = .fromInterned(ip.typeOf(uav.val)); + const uav_ty = uav_val.typeOf(zcu); - switch (ip.indexToKey(uav.val)) { + switch (ip.indexToKey(uav_val.toIntern())) { .func => unreachable, // TODO .@"extern" => assert(!ip.isFunctionType(uav_ty.toIntern())), else => {}, } if (!uav_ty.hasRuntimeBits(zcu) and uav_ty.zigTypeTag(zcu) != .spirv) { - return cg.constUndef(ty_id); + return cg.constUndef(result_ty_id); } - if (cg.storageClass(result_ptr_ty.ptrAddressSpace(zcu)) != .function) { - return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(pt)}); + if (cg.storageClass(@"addrspace") != .function) { + return cg.todo("pointer to an anonymous constant of type '{f}'", .{uav_ty.fmt(zcu)}); } const uav_ty_id = try cg.resolveType(uav_ty, .indirect); const ptr_id = try cg.alloc(uav_ty_id, null); - const val_id = try cg.constant(uav_ty, .fromInterned(uav.val), .indirect); + const val_id = try cg.constant(uav_ty, uav_val, .indirect); try cg.body.emit(gpa, .OpStore, .{ .pointer = ptr_id, .object = val_id }); return ptr_id; }, - .eu_payload_ptr => @panic("TODO"), - .opt_payload_ptr => @panic("TODO"), - .field_ptr => |field| { - const parent_ptr_id = try cg.derivePtr(field.parent.*); - const parent_ptr_ty = try field.parent.ptrType(pt); - return cg.structFieldPtr(field.result_ptr_ty, parent_ptr_ty, parent_ptr_id, field.field_idx); - }, - .elem_ptr => |elem| { - const parent_ptr_id = try cg.derivePtr(elem.parent.*); - const parent_ptr_ty = try elem.parent.ptrType(pt); - const index_id = try cg.constInt(.usize, elem.elem_idx); - return cg.ptrElemPtr(parent_ptr_ty, parent_ptr_id, index_id); - }, - .offset_and_cast => |oac| { - const parent_ptr_id = try cg.derivePtr(oac.parent.*); - const parent_ptr_ty = try oac.parent.ptrType(pt); + .eu_payload => @panic("TODO"), + .opt_payload => @panic("TODO"), + .field => |derived| return cg.structFieldPtr( + @"addrspace", + result_ty_id, + derivation.elem_ty, + derived.parent.elem_ty, + try cg.derivePtr(@"addrspace", derived.parent.*), + derived.field_index, + ), + .elem => |derived| return cg.ptrElemPtr( + switch (derived.parent.size) { + .one => .single_array_ptr, + .many => .many_ptr, + }, + @"addrspace", + derived.parent.elem_ty, + try cg.derivePtr(@"addrspace", derived.parent.*), + try cg.constInt(.usize, derived.elem_index), + ), + .offset_and_cast => |derived| { + const parent_ptr_id = try cg.derivePtr(@"addrspace", derived.parent.*); - if (oac.new_ptr_ty.ptrInfo(zcu).flags.vector_index != .none) { - return parent_ptr_id; - } - - if (oac.byte_offset == 0) { + if (derived.byte_offset == 0) { var depth: u32 = 0; - var cur = parent_ptr_ty.childType(zcu); - const dst_child = oac.new_ptr_ty.childType(zcu); + var cur = derived.parent.elem_ty; + const dst_child = derivation.elem_ty; while (cur.toIntern() != dst_child.toIntern()) { switch (cur.zigTypeTag(zcu)) { .array => { @@ -1807,9 +1836,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { } if (cur.toIntern() == dst_child.toIntern()) { if (depth != 0) { - const as = oac.new_ptr_ty.ptrAddressSpace(zcu); - const child_ty_id = try cg.pointeeType(as, dst_child, false); - const result_ty_id = try cg.ptrType(child_ty_id, cg.storageClass(as)); const scratch_top = cg.id_scratch.items.len; defer cg.id_scratch.shrinkRetainingCapacity(scratch_top); const zero = try cg.constInt(.u32, 0); @@ -1820,7 +1846,6 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { return parent_ptr_id; } } - const result_ty_id = try cg.resolveType(oac.new_ptr_ty, .direct); if (target.os.tag == .opencl) { const result_ptr_id = cg.allocId(); try cg.body.emit(gpa, .OpBitcast, .{ @@ -1832,9 +1857,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { } } - return cg.fail("cannot cast pointer '{f}' to '{f}'", .{ - parent_ptr_ty.fmt(pt), - oac.new_ptr_ty.fmt(pt), + return cg.fail("cannot cast pointer '*{f}' to '*{f}'", .{ + derived.parent.elem_ty.fmt(zcu), + derivation.elem_ty.fmt(zcu), }); }, } @@ -1881,7 +1906,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { const ip = &zcu.intern_pool; const target = cg.zcu.getTarget(); - log.debug("resolveType: ty = {f}", .{ty.fmt(pt)}); + log.debug("resolveType: ty = {f}", .{ty.fmt(zcu)}); switch (ty.zigTypeTag(zcu)) { .noreturn => { @@ -1919,7 +1944,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { }; if (!supported) return cg.fail( "'{f}' is not supported on the current SPIR-V feature set", - .{ty.fmt(cg.pt)}, + .{ty.fmt(zcu)}, ); return try cg.floatType(bits); }, @@ -2047,7 +2072,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { null, .none, ); - try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)}); + try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)}); return result_id; }, .struct_type => ip.loadStructType(ty.toIntern()), @@ -2080,7 +2105,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { ty.toIntern(), ); - try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)}); + try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)}); return result_id; }, @@ -2134,7 +2159,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { } const result_id = try cg.structType(member_types[0..len], null, .none); - try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)}); + try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)}); return result_id; }, } @@ -2169,7 +2194,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { member_names[0..layout.total_fields], .none, ); - try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(cg.pt)}); + try cg.debugNameFmt(result_id, "{f}", .{ty.fmt(zcu)}); return result_id; }, .error_set => { @@ -2206,7 +2231,7 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { }, .@"opaque" => { if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{}); - return try cg.opaqueType("{f}", .{ty.fmt(cg.pt)}); + return try cg.opaqueType("{f}", .{ty.fmt(zcu)}); }, .spirv => { const spirv_type = ip.loadSpirvType(ty.toIntern()); @@ -6455,21 +6480,28 @@ fn airSliceElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { return try cg.load(slice_ty.childType(zcu), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(zcu) }); } -fn ptrElemPtr(cg: *CodeGen, ptr_ty: Type, ptr_id: Id, index_id: Id) !Id { - const zcu = cg.zcu; +fn ptrElemPtr( + cg: *CodeGen, + mode: enum { single_array_ptr, many_ptr }, + @"addrspace": std.lang.AddressSpace, + elem_ty: Type, + ptr_id: Id, + index_id: Id, +) !Id { // Construct new pointer type for the resulting pointer - const as = ptr_ty.ptrAddressSpace(zcu); - const is_single_ptr = ptr_ty.isSinglePointer(zcu); const elem_is_block = cg.block_var_ids.contains(ptr_id); - const elem_ty_id = try cg.pointeeType(as, ptr_ty.indexableElem(zcu), elem_is_block); - const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(as)); - if (is_single_ptr) { - // Pointer-to-array. In this case, the resulting pointer is not of the same type - // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain. - return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id}); - } else { - // Resulting pointer type is the same as the ptr_ty, so use ptrAccessChain - return cg.ptrAccessChain(elem_ptr_ty_id, ptr_id, index_id, &.{}); + const elem_ty_id = try cg.pointeeType(@"addrspace", elem_ty, elem_is_block); + const elem_ptr_ty_id = try cg.ptrType(elem_ty_id, cg.storageClass(@"addrspace")); + switch (mode) { + .single_array_ptr => { + // Pointer-to-array. In this case, the resulting pointer is not of the same type + // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain. + return cg.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id}); + }, + .many_ptr => { + // Resulting pointer type is the same as the ptr_ty, so use ptrAccessChain + return cg.ptrAccessChain(elem_ptr_ty_id, ptr_id, index_id, &.{}); + }, } } @@ -6483,13 +6515,19 @@ fn airPtrElemPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; const bin_op = cg.air.extraData(Air.Bin, ty_pl.payload).data; const src_ptr_ty = cg.typeOf(bin_op.lhs); - const elem_ty = src_ptr_ty.childType(zcu); + const elem_ty = src_ptr_ty.indexableElem(zcu); const ptr_id = try cg.resolve(bin_op.lhs); assert(elem_ty.hasRuntimeBits(zcu)); const index_id = try cg.resolve(bin_op.rhs); - return try cg.ptrElemPtr(src_ptr_ty, ptr_id, index_id); + return try cg.ptrElemPtr( + if (src_ptr_ty.isSinglePointer(zcu)) .single_array_ptr else .many_ptr, + src_ptr_ty.ptrAddressSpace(zcu), + elem_ty, + ptr_id, + index_id, + ); } fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { @@ -6551,7 +6589,13 @@ fn airPtrElemVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { const elem_ty = cg.typeOfIndex(inst); const ptr_id = try cg.resolve(bin_op.lhs); const index_id = try cg.resolve(bin_op.rhs); - const elem_ptr_id = try cg.ptrElemPtr(ptr_ty, ptr_id, index_id); + const elem_ptr_id = try cg.ptrElemPtr( + if (ptr_ty.isSinglePointer(zcu)) .single_array_ptr else .many_ptr, + ptr_ty.ptrAddressSpace(zcu), + elem_ty, + ptr_id, + index_id, + ); return try cg.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) }); } @@ -6845,66 +6889,44 @@ fn airFieldParentPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { fn structFieldPtr( cg: *CodeGen, - result_ptr_ty: Type, - object_ptr_ty: Type, + @"addrspace": std.lang.AddressSpace, + result_ptr_ty_id: Id, + field_ty: Type, + object_ty: Type, object_ptr: Id, field_index: u32, ) !Id { - const result_ty_id = try cg.resolveType(result_ptr_ty, .direct); - const zcu = cg.zcu; - const object_ty = object_ptr_ty.childType(zcu); switch (object_ty.zigTypeTag(zcu)) { .pointer => { assert(object_ty.isSlice(zcu)); - return cg.accessChain(result_ty_id, object_ptr, &.{field_index}); + return cg.accessChain(result_ptr_ty_id, object_ptr, &.{field_index}); }, .@"struct" => switch (object_ty.containerLayout(zcu)) { - .@"packed" => { - const byte_offset = codegen.fieldOffset(object_ptr_ty, result_ptr_ty, field_index, zcu); - if (byte_offset == 0) return object_ptr; - const usize_ty_id = try cg.resolveType(.usize, .direct); - const base_int = cg.allocId(); - try cg.body.emit(cg.gpa, .OpConvertPtrToU, .{ - .id_result_type = usize_ty_id, - .id_result = base_int, - .pointer = object_ptr, - }); - const offset_id = try cg.constInt(.usize, byte_offset); - const adjusted = try cg.buildBinary(.OpIAdd, .{ .ty = .usize, .value = .{ .singleton = base_int } }, .{ .ty = .usize, .value = .{ .singleton = offset_id } }); - const adjusted_id = try adjusted.materialize(cg); - const result_id = cg.allocId(); - try cg.body.emit(cg.gpa, .OpConvertUToPtr, .{ - .id_result_type = result_ty_id, - .id_result = result_id, - .integer_value = adjusted_id, - }); - return result_id; - }, + .@"packed" => unreachable, .auto, .@"extern" => { const member_index = cg.memberIndex(object_ty, field_index); - return try cg.accessChain(result_ty_id, object_ptr, &.{member_index}); + return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{member_index}); }, }, .@"union" => switch (object_ty.containerLayout(zcu)) { - .@"packed" => return cg.todo("implement field access for packed unions", .{}), + .@"packed" => unreachable, .auto => { - if (!result_ptr_ty.childType(zcu).hasRuntimeBits(zcu)) return try cg.constUndef(result_ty_id); - return try cg.accessChain(result_ty_id, object_ptr, &.{field_index}); + if (!field_ty.hasRuntimeBits(zcu)) return try cg.constUndef(result_ptr_ty_id); + return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{field_index}); }, .@"extern" => { const layout = cg.unionLayout(object_ty); if (!layout.has_payload) { // Asked to get a pointer to a zero-sized field. Just lower this // to undefined, there is no reason to make it be a valid pointer. - return try cg.constUndef(result_ty_id); + return try cg.constUndef(result_ptr_ty_id); } - const storage_class = cg.storageClass(object_ptr_ty.ptrAddressSpace(zcu)); - const field_ty = result_ptr_ty.childType(zcu); + const storage_class = cg.storageClass(@"addrspace"); if (field_ty.toIntern() == layout.payload_ty.toIntern()) { if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr; - return try cg.accessChain(result_ty_id, object_ptr, &.{layout.payload_index}); + return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{layout.payload_index}); } switch (zcu.getTarget().os.tag) { @@ -6913,7 +6935,7 @@ fn structFieldPtr( // type is structurally identical to the payload type (dedup will // unify them) the access chain typed as the field type is valid. if (object_ty.containerLayout(zcu) == .@"packed") return object_ptr; - return try cg.accessChain(result_ty_id, object_ptr, &.{layout.payload_index}); + return try cg.accessChain(result_ptr_ty_id, object_ptr, &.{layout.payload_index}); }, else => {}, } @@ -6927,7 +6949,7 @@ fn structFieldPtr( const active_pl_ptr_id = cg.allocId(); try cg.body.emit(cg.gpa, .OpBitcast, .{ - .id_result_type = result_ty_id, + .id_result_type = result_ptr_ty_id, .id_result = active_pl_ptr_id, .operand = pl_ptr_id, }); @@ -6971,7 +6993,14 @@ fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { const struct_ptr = try cg.resolve(struct_field.struct_operand); const struct_ptr_ty = cg.typeOf(struct_field.struct_operand); const result_ptr_ty = cg.typeOfIndex(inst); - return try cg.structFieldPtr(result_ptr_ty, struct_ptr_ty, struct_ptr, struct_field.field_index); + return try cg.structFieldPtr( + struct_ptr_ty.ptrAddressSpace(cg.zcu), + try cg.resolveType(result_ptr_ty, .direct), + result_ptr_ty.childType(cg.zcu), + struct_ptr_ty.childType(cg.zcu), + struct_ptr, + struct_field.field_index, + ); } fn 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) const struct_ptr = try cg.resolve(ty_op.operand); const struct_ptr_ty = cg.typeOf(ty_op.operand); const result_ptr_ty = cg.typeOfIndex(inst); - return try cg.structFieldPtr(result_ptr_ty, struct_ptr_ty, struct_ptr, field_index); + return try cg.structFieldPtr( + struct_ptr_ty.ptrAddressSpace(cg.zcu), + try cg.resolveType(result_ptr_ty, .direct), + result_ptr_ty.childType(cg.zcu), + struct_ptr_ty.childType(cg.zcu), + struct_ptr, + field_index, + ); } fn alloc(cg: *CodeGen, ty_id: Id, initializer: ?Id) !Id { diff --git a/src/codegen/wasm/CodeGen.zig b/src/codegen/wasm/CodeGen.zig index 6db24a407587e22d736169a154788ad6a340e63c..f3b10dc74e63b4f590bd9157b0f2ed97a84fd5bb 100644 --- a/src/codegen/wasm/CodeGen.zig +++ b/src/codegen/wasm/CodeGen.zig @@ -1154,7 +1154,7 @@ fn allocStack(cg: *CodeGen, ty: Type) !WValue { const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse { return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{ - ty.fmt(pt), ty.abiSize(zcu), + ty.fmt(zcu), ty.abiSize(zcu), }); }; const abi_align = ty.abiAlignment(zcu); @@ -1195,7 +1195,7 @@ fn allocStackPtr(cg: *CodeGen, inst: Air.Inst.Index) !WValue { const abi_alignment = ptr_ty.ptrAlignment(zcu); const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse { return cg.fail("Type {f} with ABI size of {d} exceeds stack frame size", .{ - pointee_ty.fmt(pt), pointee_ty.abiSize(zcu), + pointee_ty.fmt(zcu), pointee_ty.abiSize(zcu), }); }; 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) if (!arg_ty.hasRuntimeBits(zcu)) continue; const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse { - return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(pt)}); + return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(zcu)}); }; const arg_align = arg_ty.abiAlignment(zcu); @@ -2128,7 +2128,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.lang.CallModifier) const arg_val = try cg.resolveInst(arg); const arg_size = std.math.cast(u32, arg_ty.abiSize(zcu)) orelse { - return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(pt)}); + return cg.fail("argument type {f} too large for wasm varargs buffer", .{arg_ty.fmt(zcu)}); }; const arg_align = arg_ty.abiAlignment(zcu); @@ -5189,7 +5189,7 @@ fn lowerConstant(cg: *CodeGen, val: Value) InnerError!WValue { return .{ .imm32 = @intFromBool(!val.isNull(zcu)) }; }, .aggregate => switch (ip.indexToKey(ty.ip_index)) { - .array_type => return cg.fail("Wasm TODO: LowerConstant for {f}", .{ty.fmt(pt)}), + .array_type => return cg.fail("Wasm TODO: LowerConstant for {f}", .{ty.fmt(zcu)}), .vector_type => { assert(determineSimdStoreStrategy(ty, zcu, cg.target) == .direct); var buf: [16]u8 = undefined; @@ -5883,7 +5883,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { .@"packed" => unreachable, // legalize .expand_packed_agg_field_val else => result: { const offset = std.math.cast(u32, struct_ty.structFieldOffset(field_index, zcu)) orelse { - return cg.fail("Field type '{f}' too big to fit into stack frame", .{field_ty.fmt(pt)}); + return cg.fail("Field type '{f}' too big to fit into stack frame", .{field_ty.fmt(zcu)}); }; if (isByRef(field_ty, zcu, cg.target)) { 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 // a pointer to the stack value if (payload_ty.hasRuntimeBits(zcu)) { const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse { - return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(pt)}); + return cg.fail("Optional type {f} too big to fit into stack frame", .{optional_ty.fmt(zcu)}); }; try cg.emitMemBase(operand); 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 } const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse { - return cg.fail("Optional type {f} too big to fit into stack frame", .{opt_ty.fmt(pt)}); + return cg.fail("Optional type {f} too big to fit into stack frame", .{opt_ty.fmt(zcu)}); }; try cg.emitMemBase(operand); @@ -6412,7 +6412,7 @@ fn airWrapOptional(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { break :result operand; } const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse { - return cg.fail("Optional type {f} too big to fit into stack frame", .{op_ty.fmt(pt)}); + return cg.fail("Optional type {f} too big to fit into stack frame", .{op_ty.fmt(zcu)}); }; // Create optional type, set the non-null bit, and store the operand inside the optional type diff --git a/src/codegen/x86_64/CodeGen.zig b/src/codegen/x86_64/CodeGen.zig index e152d984948b4097dc2f7fec3847ba5e7d775672..6451928311a65002156b1ee407647369b15033c3 100644 --- a/src/codegen/x86_64/CodeGen.zig +++ b/src/codegen/x86_64/CodeGen.zig @@ -1174,7 +1174,7 @@ const FormatAirData = struct { inst: Air.Inst.Index, }; fn formatAir(data: FormatAirData, w: *Writer) Writer.Error!void { - data.self.air.writeInst(w, data.inst, data.self.pt, data.self.liveness); + data.self.air.writeInst(w, data.inst, data.self.pt.zcu, data.self.liveness); } fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Alt(FormatAirData, formatAir) { return .{ .data = .{ .self = self, .inst = inst } }; @@ -1185,14 +1185,15 @@ const FormatWipMirData = struct { inst: Mir.Inst.Index, }; fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void { + const zcu = data.self.pt.zcu; var lower: Lower = .{ .target = data.self.target, .allocator = data.self.gpa, .mir = data.self.getTmpMir(), .cc = .auto, .src_loc = switch (data.self.owner) { - .nav_index => |nav| data.self.pt.zcu.navSrcLoc(nav), - .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(data.self.pt.zcu) orelse .unneeded, + .nav_index => |nav| zcu.navSrcLoc(nav), + .lazy_sym => |lazy_sym| Type.fromInterned(lazy_sym.ty).srcLocOrNull(zcu) orelse .unneeded, }, }; var first = true; @@ -1215,7 +1216,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void { first = false; } if (first) { - const ip = &data.self.pt.zcu.intern_pool; + const ip = &zcu.intern_pool; const mir_inst = lower.mir.instructions.get(data.inst); try w.print(" | .{s}", .{@tagName(mir_inst.ops)}); switch (mir_inst.ops) { @@ -1264,7 +1265,7 @@ fn formatWipMir(data: FormatWipMirData, w: *Writer) Writer.Error!void { try w.print(" {f}", .{mem_op.fmt(.m)}); }, .pseudo_dbg_arg_val, .pseudo_dbg_var_val => try w.print(" {f}", .{ - Value.fromInterned(mir_inst.data.ip_index).fmtValue(data.self.pt), + Value.fromInterned(mir_inst.data.ip_index).fmtValue(zcu), }), } } @@ -4532,7 +4533,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -4544,7 +4545,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { .add_wrap => res[0].wrapInt(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), res[0].tracking(cg), }), else => |e| return e, @@ -13109,7 +13110,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -15283,7 +15284,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -15295,7 +15296,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { .sub_wrap => res[0].wrapInt(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), res[0].tracking(cg), }), else => |e| return e, @@ -22130,7 +22131,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -25067,7 +25068,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -26865,7 +26866,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -26874,7 +26875,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { res[0].wrapInt(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), res[0].tracking(cg), }), else => |e| return e, @@ -32090,7 +32091,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -33328,7 +33329,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -34785,7 +34786,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -36346,7 +36347,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -38038,7 +38039,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } })) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -39820,7 +39821,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -43333,7 +43334,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -43447,7 +43448,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -43576,7 +43577,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -47885,7 +47886,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -52188,7 +52189,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -53037,7 +53038,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_pl.ty.fmt(pt), + ty_pl.ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -53942,7 +53943,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_pl.ty.fmt(pt), + ty_pl.ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -57539,7 +57540,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_pl.ty.fmt(pt), + ty_pl.ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -60884,7 +60885,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_pl.ty.fmt(pt), + ty_pl.ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -61279,7 +61280,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -61842,8 +61843,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), - cg.typeOf(bin_op.rhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), + cg.typeOf(bin_op.rhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -62204,8 +62205,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), - cg.typeOf(bin_op.rhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), + cg.typeOf(bin_op.rhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -62216,7 +62217,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { .shl => res[0].wrapInt(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), res[0].tracking(cg), }), else => |e| return e, @@ -62383,7 +62384,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.rhs).fmt(pt), + cg.typeOf(bin_op.rhs).fmt(zcu), ops[1].tracking(cg), }), else => |e| return e, @@ -65640,7 +65641,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - lhs_ty.fmt(pt), + lhs_ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -67425,7 +67426,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), + ty_op.ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -70586,7 +70587,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(ty_op.operand).fmt(pt), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -70983,7 +70984,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(ty_op.operand).fmt(pt), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -71871,7 +71872,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(ty_op.operand).fmt(pt), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -72520,7 +72521,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), + ty_op.ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -75622,7 +75623,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), + ty_op.ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -76684,7 +76685,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -77534,7 +77535,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -79085,7 +79086,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(ty_op.operand).fmt(pt), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -80421,7 +80422,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -80961,7 +80962,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -81441,7 +81442,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -82016,7 +82017,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { for (&ops) |*op| op.wrapInt(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} wrap {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), op.tracking(cg), }), else => |e| return e, @@ -82028,7 +82029,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty.fmt(pt), + ty.fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -89107,7 +89108,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { error.SelectFailed => return cg.fail("failed to select {s} {s} {f} {f} {f}", .{ @tagName(air_tag), @tagName(vector_cmp.compareOperator()), - cg.typeOf(vector_cmp.lhs).fmt(pt), + cg.typeOf(vector_cmp.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -91699,8 +91700,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), - cg.typeOf(ty_op.operand).fmt(pt), + ty_op.ty.fmt(zcu), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -93374,8 +93375,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), - cg.typeOf(ty_op.operand).fmt(pt), + ty_op.ty.fmt(zcu), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -98132,8 +98133,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - dst_ty.fmt(pt), - src_ty.fmt(pt), + dst_ty.fmt(zcu), + src_ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -103798,8 +103799,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), - cg.typeOf(ty_op.operand).fmt(pt), + ty_op.ty.fmt(zcu), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -115168,8 +115169,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), - cg.typeOf(ty_op.operand).fmt(pt), + ty_op.ty.fmt(zcu), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -127059,8 +127060,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), - cg.typeOf(ty_op.operand).fmt(pt), + ty_op.ty.fmt(zcu), + cg.typeOf(ty_op.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -161250,7 +161251,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{ @tagName(air_tag), @tagName(reduce.operation), - cg.typeOf(reduce.operand).fmt(pt), + cg.typeOf(reduce.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -161261,7 +161262,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { error.SelectFailed => return cg.fail("failed to select {s}.{s} wrap {f} {f}", .{ @tagName(air_tag), @tagName(reduce.operation), - res_ty.fmt(pt), + res_ty.fmt(zcu), res[0].tracking(cg), }), else => |e| return e, @@ -168964,7 +168965,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { error.SelectFailed => return cg.fail("failed to select {s}.{s} {f} {f}", .{ @tagName(air_tag), @tagName(reduce.operation), - cg.typeOf(reduce.operand).fmt(pt), + cg.typeOf(reduce.operand).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -170804,7 +170805,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), + ty_op.ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -170820,8 +170821,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { ops[2] = ops[0].getByteLen(cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), - cg.typeOf(bin_op.rhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), + cg.typeOf(bin_op.rhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), }), @@ -170861,8 +170862,8 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), - cg.typeOf(bin_op.rhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), + cg.typeOf(bin_op.rhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), ops[2].tracking(cg), @@ -171042,7 +171043,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -171208,7 +171209,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -171310,7 +171311,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(un_op).fmt(pt), + cg.typeOf(un_op).fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -171408,7 +171409,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f}", .{ @tagName(air_tag), - ty_op.ty.fmt(pt), + ty_op.ty.fmt(zcu), ops[0].tracking(cg), }), else => |e| return e, @@ -171481,7 +171482,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { }, else => return cg.fail("failed to select {s} {f}", .{ @tagName(air_tag), - agg_ty.fmt(pt), + agg_ty.fmt(zcu), }), } try res.finish(inst, &.{}, &.{}, cg); @@ -172927,7 +172928,7 @@ fn genBody(cg: *CodeGen, body: []const Air.Inst.Index) InnerError!void { } }) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select {s} {f} {f} {f} {f}", .{ @tagName(air_tag), - cg.typeOf(bin_op.lhs).fmt(pt), + cg.typeOf(bin_op.lhs).fmt(zcu), ops[0].tracking(cg), ops[1].tracking(cg), ops[2].tracking(cg), @@ -173765,7 +173766,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void { switch (ip.indexToKey(lazy_sym.ty)) { .enum_type => { const enum_ty: Type = .fromInterned(lazy_sym.ty); - wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(pt)}); + wip_mir_log.debug("{f}.@tagName:", .{enum_ty.fmt(zcu)}); const ret_regs = abi.getCAbiIntReturnRegs(.auto)[0..2].*; 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 { }, .error_set_type => |error_set_type| { const err_ty: Type = .fromInterned(lazy_sym.ty); - wip_mir_log.debug("{f}.@errorCast:", .{err_ty.fmt(pt)}); + wip_mir_log.debug("{f}.@errorCast:", .{err_ty.fmt(zcu)}); const ret_reg = abi.getCAbiIntReturnRegs(.auto)[0]; const ret_lock = cg.register_manager.lockRegAssumeUnused(ret_reg); @@ -173871,7 +173872,7 @@ fn genLazy(cg: *CodeGen, lazy_sym: link.File.LazySymbol) InnerError!void { }, else => return cg.fail( "TODO implement {s} for {f}", - .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(pt) }, + .{ @tagName(lazy_sym.kind), Type.fromInterned(lazy_sym.ty).fmt(zcu) }, ), } try cg.resetTemps(@fromBackingInt(@intCast(0))); @@ -174080,7 +174081,7 @@ fn allocMemPtr(self: *CodeGen, inst: Air.Inst.Index) !FrameIndex { const val_ty = ptr_ty.childType(zcu); return self.allocFrameIndex(.init(.{ .size = std.math.cast(u32, val_ty.abiSize(zcu)) orelse { - return self.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(pt)}); + return self.fail("type '{f}' too big to fit into stack frame", .{val_ty.fmt(zcu)}); }, .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"), })); @@ -174098,7 +174099,7 @@ fn allocRegOrMemAdvanced(self: *CodeGen, ty: Type, inst: ?Air.Inst.Index, reg_ok const pt = self.pt; const zcu = pt.zcu; const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse { - return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(pt)}); + return self.fail("type '{f}' too big to fit into stack frame", .{ty.fmt(zcu)}); }; if (reg_ok) need_mem: { @@ -174592,9 +174593,9 @@ fn store( } fn genUnOpMir(self: *CodeGen, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void { - const pt = self.pt; - const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu)); - if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(pt) }); + const zcu = self.pt.zcu; + const abi_size: u32 = @intCast(dst_ty.abiSize(zcu)); + if (abi_size > 8) return self.fail("TODO implement {} for {f}", .{ mir_tag, dst_ty.fmt(zcu) }); switch (dst_mcv) { .none, .unreach, @@ -176294,7 +176295,7 @@ fn genCall(cg: *CodeGen, info: union(enum) { } }); dst.copyToMask(&src, cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{ - arg_ty.fmt(pt), + arg_ty.fmt(zcu), dst.tracking(cg), src.tracking(cg), }), @@ -176515,7 +176516,7 @@ fn genCall(cg: *CodeGen, info: union(enum) { var dst = try cg.tempInit(arg_ty, dst_arg); dst.copyToMask(&src, cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select arg {f} {f} {f}", .{ - arg_ty.fmt(pt), + arg_ty.fmt(zcu), dst.tracking(cg), src.tracking(cg), }), @@ -176640,9 +176641,10 @@ fn genCall(cg: *CodeGen, info: union(enum) { } fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void { + const zcu = cg.pt.zcu; const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op; - const ret_ty = cg.fn_type.fnReturnType(cg.pt.zcu); + const ret_ty = cg.fn_type.fnReturnType(zcu); switch (cg.ret_mcv.short) { .none => {}, .register => |reg| { @@ -176660,7 +176662,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void { var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short); dst.copyToMask(&src, cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select ret {f} {f} {f}", .{ - ret_ty.fmt(cg.pt), + ret_ty.fmt(zcu), dst.tracking(cg), src.tracking(cg), }), @@ -176706,6 +176708,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index, safety: bool) !void { } fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void { + const zcu = cg.pt.zcu; const un_op = cg.air.instructions.items(.data)[@backingInt(inst)].un_op; switch (cg.ret_mcv.short) { .none => {}, @@ -176716,13 +176719,13 @@ fn airRetLoad(cg: *CodeGen, inst: Air.Inst.Index) !void { => try cg.load(cg.ret_mcv.short, cg.typeOf(un_op), try cg.resolveInst(un_op)), .register_mask => { var ptr = try cg.tempFromOperand(un_op, true); - const ret_ty = ptr.typeOf(cg).childType(cg.pt.zcu); + const ret_ty = ptr.typeOf(cg).childType(zcu); var src = try ptr.load(ret_ty, .{}, cg); try ptr.die(cg); var dst = try cg.tempInit(ret_ty, cg.ret_mcv.short); dst.copyToMask(&src, cg) catch |err| switch (err) { error.SelectFailed => return cg.fail("failed to select ret_load {f} {f} {f}", .{ - ret_ty.fmt(cg.pt), + ret_ty.fmt(zcu), dst.tracking(cg), src.tracking(cg), }), @@ -176839,7 +176842,7 @@ fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !?Mir.Inst.Index { return try self.asmJccReloc(.z, undefined); }, else => return self.fail("TODO implement condbr when condition is {f} {s}", .{ - ty.fmt(self.pt), @tagName(mcv), + ty.fmt(self.pt.zcu), @tagName(mcv), }), } } @@ -178721,7 +178724,7 @@ fn moveStrategy(cg: *CodeGen, ty: Type, class: Register.Class, aligned: bool) !M }, .ip, .cr, .dr => {}, } - return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(pt)}); + return cg.fail("TODO moveStrategy for {f}", .{ty.fmt(zcu)}); } const CopyOptions = struct { @@ -178729,7 +178732,7 @@ const CopyOptions = struct { }; fn genCopy(self: *CodeGen, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: CopyOptions) InnerError!void { - const pt = self.pt; + const zcu = self.pt.zcu; const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null; 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 .register => |src_reg| switch (dst_regs[0].class()) { .general_purpose => switch (src_reg.class()) { else => unreachable, - .sse => if (ty.abiSize(pt.zcu) <= 16) { + .sse => if (ty.abiSize(zcu) <= 16) { if (self.hasFeature(.avx)) { try self.asmRegisterRegister(.{ .v_q, .mov }, dst_regs[0].to64(), src_reg.to128()); 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 }, .air_ref => |src_ref| return self.genCopy(ty, dst_mcv, try self.resolveInst(src_ref), opts), else => return self.fail("TODO implement genCopy for {s} of {f}", .{ - @tagName(src_mcv), ty.fmt(pt), + @tagName(src_mcv), ty.fmt(zcu), }), }; defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock); @@ -179249,7 +179252,7 @@ fn genSetReg( 80 => null, else => unreachable, }, - }) orelse return cg.fail("TODO implement genSetReg for {f}", .{ty.fmt(pt)}), + }) orelse return cg.fail("TODO implement genSetReg for {f}", .{ty.fmt(zcu)}), dst_alias, registerAlias(src_reg, @intCast(cg.unalignedSize(ty))), ), @@ -179360,7 +179363,7 @@ fn genSetReg( assert(!ty.optionalReprIsPayload(zcu)); break :first_ty opt_child; }, - else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, ty.fmt(pt) }), + else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, ty.fmt(zcu) }), }); const first_size: u31 = @intCast(first_ty.abiSize(zcu)); const frame_size = std.math.ceilPowerOfTwoAssert(u32, abi_size); @@ -179769,7 +179772,7 @@ fn genSetMem( ); }, else => return cg.fail("TODO implement genSetMem for {s} of {f}", .{ - @tagName(src_mcv), ty.fmt(pt), + @tagName(src_mcv), ty.fmt(zcu), }), }, .register_offset => |reg_off| { @@ -180329,7 +180332,7 @@ fn atomicOp( }, else => unreachable, }) orelse return self.fail("TODO implement atomicOp of {s} for {f}", .{ - @tagName(op), val_ty.fmt(pt), + @tagName(op), val_ty.fmt(zcu), }); try self.genSetReg(sse_reg, val_ty, .{ .register = .rax }, .{}); switch (mir_tag[0]) { @@ -180778,12 +180781,12 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void { else try self.copyToTmpRegister(pred_ty, pred_mcv) else - return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}), + return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}), else => unreachable, }, .register_mask => |pred_reg_mask| { if (pred_reg_mask.info.scalar.bitSize(self.target) != 8 * elem_abi_size) - return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}); + return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}); const mask_reg: Register = if (need_xmm0 and pred_reg_mask.reg.id() != comptime Register.xmm0.id()) mask_reg: { try self.register_manager.getKnownReg(.xmm0, null); @@ -180857,7 +180860,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void { else null else - null) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}); + null) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}); if (has_avx) { const rhs_alias = if (reuse_mcv.isRegister()) registerAlias(reuse_mcv.getReg().?, abi_size) @@ -181010,7 +181013,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void { else => unreachable, }), ); - } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}); + } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}); const elem_bits: u16 = @intCast(elem_abi_size * 8); if (!pred_fits_in_elem) if (self.hasFeature(.ssse3)) { const mask_len = elem_abi_size * vec_len; @@ -181039,7 +181042,7 @@ fn airSelect(self: *CodeGen, inst: Air.Inst.Index) !void { mask_alias, mask_mem, ); - } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}); + } else return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}); { const mask_elem_ty = try pt.intType(.unsigned, elem_bits); 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 { else => null, }, }, - }) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(pt)}); + }) orelse return self.fail("TODO implement airSelect for {f}", .{ty.fmt(zcu)}); if (has_avx) { const rhs_alias = if (rhs_mcv.isRegister()) registerAlias(rhs_mcv.getReg().?, abi_size) @@ -181466,7 +181469,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void { assert(classes.len == 1); unreachable; }, - else => return self.fail("TODO implement c_va_arg for {f} on SysV", .{promote_ty.fmt(pt)}), + else => return self.fail("TODO implement c_va_arg for {f} on SysV", .{promote_ty.fmt(zcu)}), } if (unused) break :result .unreach; @@ -181512,7 +181515,7 @@ fn airVaArg(self: *CodeGen, inst: Air.Inst.Index) !void { try self.genCopy(.usize, next_arg_ptr, .{ .register = next_arg_ptr_reg }, .{}); }, .memory => unreachable, - else => return self.fail("TODO implement c_va_arg for {f} on Win64", .{promote_ty.fmt(pt)}), + else => return self.fail("TODO implement c_va_arg for {f} on Win64", .{promote_ty.fmt(zcu)}), } if (unused) break :result .unreach; @@ -182299,7 +182302,7 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty if (abi_size == parts_size) return parts; if (classes[classes.len - 1] == .float and abi_size > parts_size and abi_size <= parts_size + 4) return parts; }; - return self.fail("TODO implement splitType({d}, {f})", .{ parts_len, ty.fmt(pt) }); + return self.fail("TODO implement splitType({d}, {f})", .{ parts_len, ty.fmt(zcu) }); } /// Truncates the value in the register in place. @@ -183183,6 +183186,7 @@ const Temp = struct { } fn store(ptr: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void { + const zcu = cg.pt.zcu; const val_ty = val.typeOf(cg); try ptr.toOffset(opts.disp, cg); while (try ptr.toLea(cg)) {} @@ -183194,7 +183198,7 @@ const Temp = struct { else => |mcv| std.debug.panic("{s}: {f}\n", .{ @src().fn_name, mcv }), .undef => if (opts.safe) { var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa }); - var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) }); + var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(zcu) }); try ptr.memset(&pat, &len, cg); try pat.die(cg); try len.die(cg); @@ -183248,12 +183252,12 @@ const Temp = struct { .register_offset => |val_reg_off| switch (val_reg_off.off) { 0 => try ptr.storeRegs(val_ty, &.{registerAlias( val_reg_off.reg, - @intCast(val_ty.abiSize(cg.pt.zcu)), + @intCast(val_ty.abiSize(zcu)), )}, cg), else => continue :val_to_gpr, }, .register_overflow => |val_reg_ov| { - const ip = &cg.pt.zcu.intern_pool; + const ip = &zcu.intern_pool; const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) { .tuple_type => |tuple_type| { const tuple_field_types = tuple_type.types.get(ip); @@ -183261,12 +183265,12 @@ const Temp = struct { break :first_ty tuple_field_types[0]; }, .opt_type => |opt_child| { - assert(!val_ty.optionalReprIsPayload(cg.pt.zcu)); + assert(!val_ty.optionalReprIsPayload(zcu)); break :first_ty opt_child; }, - else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }), + else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(zcu) }), }); - const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu)); + const first_size: u31 = @intCast(first_ty.abiSize(zcu)); try ptr.storeRegs(first_ty, &.{registerAlias(val_reg_ov.reg, first_size)}, cg); try ptr.toOffset(first_size, cg); try cg.asmSetccMemory( @@ -183277,7 +183281,7 @@ const Temp = struct { .lea_frame, .lea_nav, .lea_uav, .lea_lazy_sym => continue :val_to_gpr, .memory, .indirect, .load_frame, .load_nav, .load_uav, .load_lazy_sym => { var val_ptr = try cg.tempInit(.usize, val_mcv.address()); - try ptr.memcpy(&val_ptr, val_ty.abiSize(cg.pt.zcu), cg); + try ptr.memcpy(&val_ptr, val_ty.abiSize(zcu), cg); try val_ptr.die(cg); }, } @@ -183325,6 +183329,7 @@ const Temp = struct { } fn write(dst: *Temp, val: *Temp, opts: AccessOptions, cg: *CodeGen) InnerError!void { + const zcu = cg.pt.zcu; const val_ty = val.typeOf(cg); while (try dst.toBase(false, cg)) {} val_to_gpr: while (true) : (while (try dst.toBase(false, cg) or @@ -183337,7 +183342,7 @@ const Temp = struct { .undef => if (opts.safe) { var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp)); var pat = try cg.tempInit(.u8, .{ .immediate = 0xaa }); - var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(cg.pt.zcu) }); + var len = try cg.tempInit(.usize, .{ .immediate = val_ty.abiSize(zcu) }); try dst_ptr.memset(&pat, &len, cg); try dst_ptr.die(cg); try pat.die(cg); @@ -183364,7 +183369,7 @@ const Temp = struct { ), .register => |val_reg| try dst.writeReg(opts.disp, val_ty, registerAlias( val_reg, - @intCast(val_ty.abiSize(cg.pt.zcu)), + @intCast(val_ty.abiSize(zcu)), ), cg), inline .register_pair, .register_triple, @@ -183373,12 +183378,12 @@ const Temp = struct { .register_offset => |val_reg_off| switch (val_reg_off.off) { 0 => try dst.writeReg(opts.disp, val_ty, registerAlias( val_reg_off.reg, - @intCast(val_ty.abiSize(cg.pt.zcu)), + @intCast(val_ty.abiSize(zcu)), ), cg), else => continue :val_to_gpr, }, .register_overflow => |val_reg_ov| { - const ip = &cg.pt.zcu.intern_pool; + const ip = &zcu.intern_pool; const first_ty: Type = .fromInterned(first_ty: switch (ip.indexToKey(val_ty.toIntern())) { .tuple_type => |tuple_type| { const tuple_field_types = tuple_type.types.get(ip); @@ -183386,12 +183391,12 @@ const Temp = struct { break :first_ty tuple_field_types[0]; }, .opt_type => |opt_child| { - assert(!val_ty.optionalReprIsPayload(cg.pt.zcu)); + assert(!val_ty.optionalReprIsPayload(zcu)); break :first_ty opt_child; }, - else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(cg.pt) }), + else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, val_ty.fmt(zcu) }), }); - const first_size: u31 = @intCast(first_ty.abiSize(cg.pt.zcu)); + const first_size: u31 = @intCast(first_ty.abiSize(zcu)); try dst.writeReg(opts.disp, first_ty, registerAlias(val_reg_ov.reg, first_size), cg); try cg.asmSetccMemory( val_reg_ov.eflags, @@ -183406,7 +183411,7 @@ const Temp = struct { var dst_ptr = try cg.tempInit(.usize, dst.tracking(cg).short.address().offset(opts.disp)); var val_ptr = try cg.tempInit(.usize, val_mcv.address()); - try dst_ptr.memcpy(&val_ptr, val_ty.abiSize(cg.pt.zcu), cg); + try dst_ptr.memcpy(&val_ptr, val_ty.abiSize(zcu), cg); try dst_ptr.die(cg); try val_ptr.die(cg); }, @@ -183444,7 +183449,7 @@ const Temp = struct { assert(src_regs.len == @divCeil(int_info.bits, 64)); break :part_ty .u64; } else part_ty: switch (ip.indexToKey(src_ty.toIntern())) { - else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(cg.pt) }), + else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(zcu) }), .ptr_type => |ptr_info| { assert(ptr_info.flags.size == .slice); assert(src_regs.len == 2); @@ -183463,7 +183468,7 @@ const Temp = struct { }), }, .opt_type => |opt_child| switch (ip.indexToKey(opt_child)) { - else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(cg.pt) }), + else => std.debug.panic("{s}: {f}\n", .{ @src().fn_name, src_ty.fmt(zcu) }), .ptr_type => |ptr_info| { assert(ptr_info.flags.size == .slice); assert(src_regs.len == 2); @@ -189637,7 +189642,7 @@ fn resetTemps(cg: *CodeGen, from_index: Temp.Index) InnerError!void { any_valid = true; tracking_log.err("failed to kill {f}: {f}", .{ temp.toIndex(), - cg.temp_type[temp_index].fmt(cg.pt), + cg.temp_type[temp_index].fmt(cg.pt.zcu), }); } cg.temp_type[temp_index] = undefined; diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 754c3ad9a830078489427c9794455642527b7f20..cf7e1daa91014276e230bf6cd840278498e5eb12 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -5766,7 +5766,7 @@ fn flushImplib( try file_writer.interface.flush(); } -fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void { +fn reportUndefs(coff: *Coff) !void { const comp = coff.base.comp; const gpa = comp.gpa; const max_notes = 4; @@ -5887,14 +5887,8 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void { const ip = &comp.zcu.?.intern_pool; break :format ip.getNav(val.navIndex(coff)).fqn.fmt(ip); }, - .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(.{ - .zcu = coff.base.comp.zcu.?, - .tid = tid, - }), - inline .lazy_code, .lazy_const_data => Type.fromInterned(val.lazySymbol(coff).ty).fmt(.{ - .zcu = coff.base.comp.zcu.?, - .tid = tid, - }), + .uav => Value.fromInterned(val.uavValue(coff)).fmtValue(coff.base.comp.zcu.?), + inline .lazy_code, .lazy_const_data => Type.fromInterned(val.lazySymbol(coff).ty).fmt(coff.base.comp.zcu.?), else => unreachable, }, }); @@ -5927,7 +5921,7 @@ pub fn flush( const comp = coff.base.comp; - while (try coff.resolve(tid)) {} + while (try coff.resolve()) {} while (try coff.idle(tid)) {} // This has to occur after all other flushMoved / flushResized have resolved, @@ -5951,7 +5945,7 @@ pub fn flush( while (try coff.idle(tid)) {} if (coff.isImage()) - try coff.reportUndefs(tid); + try coff.reportUndefs(); if (comp.emit_implib) |implib_file| coff.flushImplib(implib_file) catch |err| @@ -5970,7 +5964,7 @@ pub fn flush( /// Runs a single "resolution" task. /// These are tasks that need to modify the node structure in some way. /// They must run in a defined order with respect to linker tasks. -fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { +fn resolve(coff: *Coff) !bool { const comp = coff.base.comp; task: { while (coff.section_merge_pending_index < coff.section_merges.count()) { @@ -6046,7 +6040,6 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { const si = coff.symbol_table.symbols.keys()[coff.symbol_table.pending_symbol_index]; const sym = si.get(coff); const sub_prog_node = coff.idleProgNode( - tid, coff.symbol_prog_node, if (sym.ni.unwrap()) |sym_ni| coff.getNode(sym_ni) @@ -6077,6 +6070,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { } pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { + _ = tid; // Idle tasks should not modify create / modify nodes, otherwise the output is not reproducible. coff.mf.nodes_lock.lock(); defer coff.mf.nodes_lock.unlock(); @@ -6087,7 +6081,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { if (coff.input_section_pending_index < coff.input_sections.items.len) { const isi: Node.InputSection.Index = @fromBackingInt(@intCast(coff.input_section_pending_index)); coff.input_section_pending_index += 1; - const sub_prog_node = coff.idleProgNode(tid, coff.input_prog_node, coff.getNode(isi.symbol(coff).node(coff))); + const sub_prog_node = coff.idleProgNode(coff.input_prog_node, coff.getNode(isi.symbol(coff).node(coff))); defer sub_prog_node.end(); coff.flushInputSection(isi) catch |err| switch (err) { else => |e| { @@ -6112,7 +6106,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { const clean_next_moved = ni.cleanNextMoved(&coff.mf); if (!clean_moved and !clean_resized and !clean_next_moved) continue; const sub_prog_node = - coff.idleProgNode(tid, coff.mf.update_prog_node, coff.getNode(ni)); + coff.idleProgNode(coff.mf.update_prog_node, coff.getNode(ni)); defer sub_prog_node.end(); if (clean_moved) try coff.flushMoved(ni); if (clean_resized) try coff.flushResized(ni); @@ -6120,7 +6114,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { } while (coff.pending_members.pop()) |pending_mi| { const sub_prog_node = coff.idleProgNode( - tid, coff.symbol_prog_node, coff.getNode(pending_mi.key.get(coff).content_ni), ); @@ -6131,7 +6124,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { if (coff.exports_complete and coff.export_table.pending_sort) { defer coff.export_table.pending_sort = false; const sub_prog_node = coff.idleProgNode( - tid, coff.synth_prog_node, coff.getNode(coff.export_table.ni), ); @@ -6150,7 +6142,6 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool { fn idleProgNode( coff: *Coff, - tid: Zcu.PerThread.Id, prog_node: std.Progress.Node, node: Node, ) std.Progress.Node { @@ -6173,10 +6164,7 @@ fn idleProgNode( break :name ip.getNav(nmi.navIndex(coff)).fqn.toSlice(ip); }, .uav => |umi| std.mem.print(&name, "{f}", .{ - Value.fromInterned(umi.uavValue(coff)).fmtValue(.{ - .zcu = coff.base.comp.zcu.?, - .tid = tid, - }), + Value.fromInterned(umi.uavValue(coff)).fmtValue(coff.base.comp.zcu.?), }) catch &name, .archive_member => |mi| &mi.get(coff).headerPtr(coff).name, }, 0); @@ -6185,7 +6173,7 @@ fn idleProgNode( fn genPending(coff: *Coff, pt: Zcu.PerThread) Error!void { const comp = pt.zcu.comp; while (coff.pending_uavs.pop()) |pending_uav| { - const sub_prog_node = coff.idleProgNode(pt.tid, coff.const_prog_node, .{ .uav = pending_uav.key }); + const sub_prog_node = coff.idleProgNode(coff.const_prog_node, .{ .uav = pending_uav.key }); defer sub_prog_node.end(); coff.genUav(pt, pending_uav.key, pending_uav.value.alignment) catch |err| switch (err) { else => |e| return e, @@ -6845,7 +6833,7 @@ fn genLazy(coff: *Coff, pt: Zcu.PerThread, lmr: Node.LazyMapRef) !void { const sub_prog_node = coff.synth_prog_node.start( std.mem.print(&name, "lazy {s} for {f}", .{ kind, - Type.fromInterned(lazy.ty).fmt(pt), + Type.fromInterned(lazy.ty).fmt(coff.base.comp.zcu.?), }) catch &name, 0, ); @@ -7461,14 +7449,14 @@ fn updateExportInner( switch (exp.exported) { .nav => |nav| log.debug("updateExports({f}) = {d}", .{ ip.getNav(nav).fqn.fmt(ip), exported_si }), .uav => |uav| log.debug("updateExports(@as({f}, {f})) = {d}", .{ - Type.fromInterned(ip.typeOf(uav)).fmt(pt), - Value.fromInterned(uav).fmtValue(pt), + Type.fromInterned(ip.typeOf(uav)).fmt(zcu), + Value.fromInterned(uav).fmtValue(zcu), exported_si, }), } try coff.genPending(pt); - while (try coff.resolve(pt.tid)) {} + while (try coff.resolve()) {} while (try coff.idle(pt.tid)) {} 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 try coff.printSection(w, name, sec.si); try w.writeAll("Symbol table:\n"); for (1..coff.symbols.items.len) |si| - try coff.printSymbol(w, tid, @fromBackingInt(@intCast(si))); + try coff.printSymbol(w, @fromBackingInt(@intCast(si))); return .enabled; } @@ -7648,7 +7636,6 @@ fn printSection(coff: *Coff, w: *Io.Writer, name: String, si: Symbol.Index) Io.W fn printSymbol( coff: *Coff, w: *Io.Writer, - tid: Zcu.PerThread.Id, si: Symbol.Index, ) Io.Writer.Error!void { const sym = si.get(coff); @@ -7687,7 +7674,7 @@ fn printSymbol( try w.print("G {f}\n", .{fmtGlobalName(coff, sym.gmi)}); } else { try w.writeAll("| "); - try coff.printNodeName(w, tid, coff.getNode(sym.ni.unwrap().?)); + try coff.printNodeName(w, coff.getNode(sym.ni.unwrap().?)); if (sym.flags.extra_tag == .isli) try w.print(" | {s}", .{sym.extra.isli.name(coff).toSlice(coff)}); try w.writeByte('\n'); @@ -7712,7 +7699,6 @@ fn globalNameEscape(data: FmtGlobalName, w: *std.Io.Writer) std.Io.Writer.Error! fn printNodeName( coff: *Coff, w: *std.Io.Writer, - tid: Zcu.PerThread.Id, node: Node, ) Io.Writer.Error!void { switch (node) { @@ -7754,7 +7740,7 @@ fn printNodeName( const ip = &zcu.intern_pool; const nav = ip.getNav(nmi.navIndex(coff)); try w.print("({f}, {f})", .{ - Type.fromInterned(ip.typeOf(nav.resolved.?.value)).fmt(.{ .zcu = zcu, .tid = tid }), + Type.fromInterned(ip.typeOf(nav.resolved.?.value)).fmt(zcu), nav.fqn.fmt(ip), }); }, @@ -7762,15 +7748,12 @@ fn printNodeName( const zcu = coff.base.comp.zcu.?; const val: Value = .fromInterned(umi.uavValue(coff)); try w.print("({f}, {f})", .{ - val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }), - val.fmtValue(.{ .zcu = zcu, .tid = tid }), + val.typeOf(zcu).fmt(zcu), + val.fmtValue(zcu), }); }, inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{ - Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(.{ - .zcu = coff.base.comp.zcu.?, - .tid = tid, - }), + Type.fromInterned(lmi.lazySymbol(coff).ty).fmt(coff.base.comp.zcu.?), }), .builtin => |si| { const sym = si.get(coff); @@ -7789,7 +7772,7 @@ pub fn printNode( const node = coff.getNode(ni); try w.splatByteAll(' ', indent); try w.writeAll(@tagName(node)); - try coff.printNodeName(w, tid, node); + try coff.printNodeName(w, node); { const mf_node = &coff.mf.nodes.items[@backingInt(ni)]; const off, const size = mf_node.location().resolve(&coff.mf); diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 8c4d2b669998e4a83d876185279822c1fcb8c862..a119e3d43062f7ddacd0c4f3fdcfcc3e4ec9dd18 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1036,7 +1036,7 @@ const Entry = struct { const val_unit, const val_entry = unit_and_entry; if (sec.getUnit(val_unit) == unit and unit.getEntry(val_entry) == entry) log.err("missing Value({f}({d}))", .{ - Value.fromInterned(val).fmtValue(.{ .tid = .main, .zcu = zcu }), + Value.fromInterned(val).fmtValue(zcu), @backingInt(val), }); } @@ -2120,9 +2120,10 @@ pub const WipNav = struct { wip_nav: *WipNav, val: Value, ) (UpdateError || Writer.Error)!void { - const ty = val.typeOf(wip_nav.pt.zcu); + const zcu = wip_nav.pt.zcu; + const ty = val.typeOf(zcu); const diw = &wip_nav.debug_info.writer; - const size = ty.abiSize(wip_nav.pt.zcu); + const size = ty.abiSize(zcu); try diw.writeUleb128(size); if (size == 0) return; const old_end = diw.end; @@ -2135,7 +2136,7 @@ pub const WipNav = struct { ); if (old_end + size != diw.end) { std.debug.print("{f} [{}]: {} != {}\n", .{ - ty.fmt(wip_nav.pt), + ty.fmt(zcu), ty.toIntern(), size, diw.end - old_end, @@ -3340,8 +3341,8 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde switch (value_index) { .generic_poison_type => log.debug("updateValueIncomplete(anytype)", .{}), else => log.debug("updateValueIncomplete(@as({f}, {f}))", .{ - val.typeOf(zcu).fmt(pt), - val.fmtValue(pt), + val.typeOf(zcu).fmt(zcu), + val.fmtValue(zcu), }), } @@ -3435,7 +3436,7 @@ fn updateConstIncompleteInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_inde else => |val_key| switch (val_key.typeOf()) { .type_type => { try wip_nav.abbrevCode(.generated_empty_struct_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try wip_nav.debug_info.writer.writeByte(@intFromBool(true)); }, else => |ty| { @@ -3509,8 +3510,8 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co switch (value_index) { .generic_poison_type => log.debug("updateValue(anytype)", .{}), else => log.debug("updateValue(@as({f}, {f}))", .{ - val.typeOf(zcu).fmt(pt), - val.fmtValue(pt), + val.typeOf(zcu).fmt(zcu), + val.fmtValue(zcu), }), } @@ -3551,7 +3552,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .int_type => |int_type| { try wip_nav.abbrevCode(.numeric_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeByte(switch (int_type.signedness) { inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)), }); @@ -3566,7 +3567,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .none => if (ptr_type.sentinel == .none) .ptr_type else .ptr_sentinel_type, else => if (ptr_type.sentinel == .none) .ptr_aligned_type else .ptr_aligned_sentinel_type, }); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); if (ptr_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(ptr_type.sentinel)); if (ptr_type.flags.alignment.toByteUnits()) |a| try diw.writeUleb128(a); 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 }, .slice => { try wip_nav.abbrevCode(.generated_struct_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeUleb128(val.toType().abiSize(zcu)); try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); try wip_nav.abbrevCode(.generated_field); @@ -3611,7 +3612,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .array_type => |array_type| { const array_child_type: Type = .fromInterned(array_type.child); try wip_nav.abbrevCode(if (array_type.sentinel == .none) .array_type else .array_sentinel_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); if (array_type.sentinel != .none) try wip_nav.blockValue(.fromInterned(array_type.sentinel)); try wip_nav.refType(array_child_type); try wip_nav.abbrevCode(.array_len); @@ -3621,7 +3622,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co }, .vector_type => |vector_type| { try wip_nav.abbrevCode(.vector_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try wip_nav.refType(.fromInterned(vector_type.child)); try wip_nav.abbrevCode(.array_len); try wip_nav.refType(.usize); @@ -3632,7 +3633,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co const opt_child_type: Type = .fromInterned(opt_child_type_index); const opt_repr = optRepr(opt_child_type, zcu); try wip_nav.abbrevCode(.generated_union_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeUleb128(val.toType().abiSize(zcu)); try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); switch (opt_repr) { @@ -3713,7 +3714,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co }; try wip_nav.abbrevCode(.generated_union_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); if (error_union_type.error_set_type != .generic_poison_type and error_union_type.payload_type != .generic_poison_type) { @@ -3785,7 +3786,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .bool, => { try wip_nav.abbrevCode(.numeric_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeByte(if (value_index == .bool_type) DW.ATE.boolean else if (val.toType().isRuntimeFloat()) @@ -3815,18 +3816,18 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .enum_literal, => { try wip_nav.abbrevCode(.void_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); }, .anyerror => unreachable, // already did early return above .adhoc_inferred_error_set => unreachable, }, .tuple_type => |tuple_type| if (tuple_type.types.len == 0) { try wip_nav.abbrevCode(.generated_empty_struct_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeByte(@intFromBool(false)); } else { try wip_nav.abbrevCode(.generated_struct_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try diw.writeUleb128(val.toType().abiSize(zcu)); try diw.writeUleb128(val.toType().abiAlignment(zcu).toByteUnits().?); var field_byte_offset: u64 = 0; @@ -4148,7 +4149,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co .func_type => |func_type| { const is_nullary = func_type.param_types.len == 0 and !func_type.is_var_args; try wip_nav.abbrevCode(if (is_nullary) .nullary_func_type else .func_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); const cc: DW.CC = cc: { if (zcu.getTarget().cCallingConvention()) |cc| { 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 }, .error_set_type => |error_set_type| { try wip_nav.abbrevCode(if (error_set_type.names.len == 0) .generated_empty_enum_type else .generated_enum_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try wip_nav.refType(.fromInterned(try pt.intern(.{ .int_type = .{ .signedness = .unsigned, .bits = zcu.errorSetBits(), @@ -4247,7 +4248,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co }, .inferred_error_set_type => |func| { try wip_nav.abbrevCode(.inferred_error_set_type); - try wip_nav.strpFmt("{f}", .{val.toType().fmt(pt)}); + try wip_nav.strpFmt("{f}", .{val.toType().fmt(zcu)}); try wip_nav.refType(.fromInterned(switch (ip.funcIesResolvedUnordered(func)) { .none => .anyerror_type, else => |ies| ies, diff --git a/src/link/Dwarf2.zig b/src/link/Dwarf2.zig index b88230d2eda8047475379734ad1a7b679bc42d92..8c61805ae6ca85c1514ef0045934a8b7022840bd 100644 --- a/src/link/Dwarf2.zig +++ b/src/link/Dwarf2.zig @@ -2516,7 +2516,7 @@ pub fn updateConst( ) link.Error!void { switch (val) { .generic_poison_type => log.debug("updateConst(anytype)", .{}), - else => log.debug("updateConst({f})", .{Value.fromInterned(val).fmtValue(pt)}), + else => log.debug("updateConst({f})", .{Value.fromInterned(val).fmtValue(pt.zcu)}), } dwarf.updateConstInner(pt, di_nw, val) catch |err| switch (err) { else => |e| return e, @@ -2538,7 +2538,7 @@ fn updateConstInner( try dwarf.abbrevCode(di_nw, .numeric_type); var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined; try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ - ty.fmt(pt), + ty.fmt(zcu), }) catch unreachable); try di_w.writeByte(switch (int_type.signedness) { .signed => DW.ATE.signed, @@ -2550,7 +2550,7 @@ fn updateConstInner( }, .ptr_type => |ptr_type| switch (ptr_type.flags.size) { .one, .many, .c => { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) { .none => .ptr_type, @@ -2585,7 +2585,7 @@ fn updateConstInner( }, .slice => { const ty: Type = .fromInterned(@"const"); - const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{ty.fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .generated_struct_type); try dwarf.strx(di_nw, name); @@ -2605,7 +2605,7 @@ fn updateConstInner( }, }, .array_type => |array_type| { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode( di_nw, @@ -2621,7 +2621,7 @@ fn updateConstInner( try di_w.writeUleb128(@backingInt(AbbrevCode.null)); }, .vector_type => |vector_type| { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .vector_type); try dwarf.strx(di_nw, name); @@ -2635,7 +2635,7 @@ fn updateConstInner( const opt_ty: Type = .fromInterned(@"const"); const opt_child_ty: Type = .fromInterned(opt_child_type_index); const opt_repr = optRepr(opt_child_ty, zcu); - const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .generated_union_type); try dwarf.strx(di_nw, name); @@ -2715,7 +2715,7 @@ fn updateConstInner( codegen.errUnionPayloadOffset(eu_payload_ty, zcu), }, }; - const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{eu_ty.fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .generated_union_type); @@ -2819,7 +2819,7 @@ fn updateConstInner( try dwarf.abbrevCode(di_nw, .void_type); var name_buf: ["@TypeOf(undefined)".len]u8 = undefined; try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ - ty.fmt(pt), + ty.fmt(zcu), }) catch unreachable); }, .anyerror => { @@ -2842,7 +2842,7 @@ fn updateConstInner( }, .tuple_type => |tuple_type| { const ty: Type = .fromInterned(@"const"); - const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{ty.fmt(zcu)}); defer zcu.gpa.free(name); if (tuple_type.types.len == 0) { try dwarf.abbrevCode(di_nw, .generated_empty_struct_type); @@ -3255,7 +3255,7 @@ fn updateConstInner( .spirv_type => unreachable, .func_type => |func_type| { const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args; - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type); try dwarf.strx(di_nw, name); @@ -3340,7 +3340,7 @@ fn updateConstInner( if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); }, .error_set_type => |error_set_type| { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode( di_nw, @@ -3358,7 +3358,7 @@ fn updateConstInner( if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); }, .inferred_error_set_type => |func| { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .inferred_error_set_type); try dwarf.strx(di_nw, name); @@ -3863,7 +3863,7 @@ pub fn updateConstIncomplete( di_nw: *link.MappedFile.Node.Writer, val: InternPool.Index, ) link.Error!void { - log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)}); + log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt.zcu)}); dwarf.updateConstIncompleteInner(pt, di_nw, val) catch |err| switch (err) { else => |e| return e, error.WriteFailed => return dwarf.reportWriteError(di_nw), @@ -4021,7 +4021,7 @@ fn updateConstIncompleteInner( }, else => |val_key| break :done switch (val_key.typeOf()) { .type_type => { - const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); + const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(zcu)}); defer zcu.gpa.free(name); try dwarf.abbrevCode(di_nw, .generated_empty_struct_type); try dwarf.strx(di_nw, name); @@ -4140,11 +4140,12 @@ pub fn genDecl( di_nw: *link.MappedFile.Node.Writer, instance: Decl.Instance, ) link.Error!void { + const zcu = pt.zcu; switch (instance) { .none => unreachable, - .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(pt)}), + .@"const" => |@"const"| log.debug("genDecl({f})", .{Value.fromInterned(@"const").fmtValue(zcu)}), .global => |global| log.debug("genDecl({f})", .{ - pt.zcu.intern_pool.getNav(global).fqn.fmt(&pt.zcu.intern_pool), + zcu.intern_pool.getNav(global).fqn.fmt(&zcu.intern_pool), }), } dwarf.genDeclInner(pt, di_nw, instance) catch |err| switch (err) { diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 551f4c626ddb3a0e819eb158a4290c271d5d34be..8bb2212f4af421de651ac0f7f7933aa99d5b61d4 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -1720,7 +1720,7 @@ fn updateLazySymbol( const name_str_index = blk: { const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{ @tagName(sym.kind), - Type.fromInterned(sym.ty).fmt(pt), + Type.fromInterned(sym.ty).fmt(zcu), }); defer gpa.free(name); break :blk try self.strtab.insert(gpa, name); @@ -2349,7 +2349,7 @@ fn checkUavAllocated(pt: Zcu.PerThread, index: InternPool.Index, meta: AvMetadat const uav = Value.fromInterned(index); const ty = uav.typeOf(zcu); log.err("UAV {f}({d}) assigned symbol {d} but not allocated!", .{ - ty.fmt(pt), + ty.fmt(zcu), index, meta.symbol_index, }); diff --git a/src/link/Elf2.zig b/src/link/Elf2.zig index 37d7dfe0499aeb8a9b80e983e6eb8785739eb75e..ddff228929c093864d7bf168e7909aa07d3e82e8 100644 --- a/src/link/Elf2.zig +++ b/src/link/Elf2.zig @@ -10328,6 +10328,8 @@ fn flushInner( } pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { + _ = tid; + // This function is called non-deterministically, and so must not affect the layout of any nodes. elf.mf.nodes_lock.lock(); defer elf.mf.nodes_lock.unlock(); @@ -10343,7 +10345,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index); elf.input_pending_index += 1; const idle_prog_node = - elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(ii.node(elf))); + elf.startIdleProgress(elf.input_prog_node, elf.getNode(ii.node(elf))); defer idle_prog_node.end(); elf.flushInput(ii) catch |err| switch (err) { else => |e| return e, @@ -10355,7 +10357,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index); elf.input_section_pending_index += 1; const idle_prog_node = - elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(isi.node(elf))); + elf.startIdleProgress(elf.input_prog_node, elf.getNode(isi.node(elf))); defer idle_prog_node.end(); elf.flushInputSection(isi) catch |err| switch (err) { else => |e| return e, @@ -10465,7 +10467,7 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { const clean_resized = ni.cleanResized(&elf.mf); const clean_next_moved = ni.cleanNextMoved(&elf.mf); if (!clean_moved and !clean_resized and !clean_next_moved) continue; - const idle_prog_node = elf.startIdleProgress(tid, elf.mf.update_prog_node, elf.getNode(ni)); + const idle_prog_node = elf.startIdleProgress(elf.mf.update_prog_node, elf.getNode(ni)); defer idle_prog_node.end(); if (clean_moved) try elf.flushMoved(ni); if (clean_resized) try elf.flushResized(ni); @@ -10483,7 +10485,6 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { fn startIdleProgress( elf: *Elf, - tid: Zcu.PerThread.Id, prog_node: std.Progress.Node, node: Node, ) std.Progress.Node { @@ -10508,7 +10509,7 @@ fn startIdleProgress( break :name ip.getNav(nmi.nav(elf)).fqn.toSlice(ip); }, .uav => |umi| std.mem.print(&name, "{f}", .{ - Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), + Value.fromInterned(umi.uavValue(elf)).fmtValue(elf.base.comp.zcu.?), }) catch &name, .debug_shared => |ss| switch (ss) { .debug_abbrev => "debug info abbrevs", @@ -10539,7 +10540,7 @@ fn startIdleProgress( .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) { .generic_poison_type => "anytype", else => |val| std.mem.print(&name, "debug info for {f}", .{ - Value.fromInterned(val).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), + Value.fromInterned(val).fmtValue(elf.base.comp.zcu.?), }) catch &name, }, .global_debug_info => |gi| { @@ -10571,10 +10572,11 @@ fn startIdleProgress( } fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void { + const zcu = elf.base.comp.zcu.?; while (elf.pending_uavs.pop()) |umi| { var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; const prog_name = std.mem.print(&prog_name_buf, "{f}", .{ - Value.fromInterned(umi.uavValue(elf)).fmtValue(pt), + Value.fromInterned(umi.uavValue(elf)).fmtValue(zcu), }) catch &prog_name_buf; const prog_node = elf.const_prog_node.start(prog_name, 0); defer prog_node.end(); @@ -10671,14 +10673,15 @@ fn genUav( } fn genLazy(elf: *Elf, pt: Zcu.PerThread, lmr: Node.LazyMapRef) link.Error!void { + const zcu = elf.base.comp.zcu.?; const lazy = lmr.lazySymbol(elf); if (lazy.ty == .anyerror_type) return; const lazy_ty: Type = .fromInterned(lazy.ty); var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; - const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(pt.zcu)) { - .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, + const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(zcu)) { + .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(zcu)}) catch &prog_name_buf, .error_set => switch (lmr.kind) { - .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, + .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(zcu)}) catch &prog_name_buf, .const_data => "@errorName(anyerror)", }, else => unreachable, @@ -12143,8 +12146,8 @@ fn updateExportInner( switch (@"export".exported) { .nav => |nav| log.debug("updateExports({f})", .{ip.getNav(nav).fqn.fmt(ip)}), .uav => |uav| log.debug("updateExports(@as({f}, {f}))", .{ - Type.fromInterned(ip.typeOf(uav)).fmt(pt), - Value.fromInterned(uav).fmtValue(pt), + Type.fromInterned(ip.typeOf(uav)).fmt(zcu), + Value.fromInterned(uav).fmtValue(zcu), }), } const exported_lsi: Symbol.LocalIndex = switch (@"export".exported) { @@ -12277,7 +12280,7 @@ pub fn printNode( const ip = &zcu.intern_pool; const nav = ip.getNav(nmi.nav(elf)); try w.print("({f}, {f})", .{ - Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }), + Type.fromInterned(nav.resolved.?.type).fmt(zcu), nav.fqn.fmt(ip), }); }, @@ -12285,15 +12288,12 @@ pub fn printNode( const zcu = elf.base.comp.zcu.?; const val: Value = .fromInterned(umi.uavValue(elf)); try w.print("({f}, {f})", .{ - val.typeOf(zcu).fmt(.{ .zcu = zcu, .tid = tid }), - val.fmtValue(.{ .zcu = zcu, .tid = tid }), + val.typeOf(zcu).fmt(zcu), + val.fmtValue(zcu), }); }, inline .lazy_code, .lazy_const_data => |lmi| try w.print("({f})", .{ - Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(.{ - .zcu = elf.base.comp.zcu.?, - .tid = tid, - }), + Type.fromInterned(lmi.lazySymbol(elf).ty).fmt(elf.base.comp.zcu.?), }), .debug_shared => |ss| try w.print("({})", .{ss}), .unit_frame, @@ -12308,7 +12308,7 @@ pub fn printNode( .const_debug_info => |cpi| switch (cpi.val(&elf.dwarf.const_pool)) { .generic_poison_type => try w.writeAll("(anytype)"), else => |val| try w.print("({f})", .{ - Value.fromInterned(val).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), + Value.fromInterned(val).fmtValue(elf.base.comp.zcu.?), }), }, .global_debug_info => |gi| { @@ -12317,11 +12317,11 @@ pub fn printNode( const nav = ip.getNav(gi.nav(&elf.dwarf)); try w.writeByte('('); if (nav.resolved) |resolved| try w.print("{f}, ", .{ - Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }), + Type.fromInterned(resolved.type).fmt(zcu), }); try w.print("{f}", .{nav.fqn.fmt(ip)}); if (nav.resolved) |resolved| try w.print(", {f}", .{ - Value.fromInterned(resolved.value).fmtValue(.{ .zcu = zcu, .tid = tid }), + Value.fromInterned(resolved.value).fmtValue(zcu), }); try w.writeByte(')'); }, @@ -12331,7 +12331,7 @@ pub fn printNode( const nav = ip.getNav(fi.nav(&elf.dwarf)); try w.writeByte('('); if (nav.resolved) |resolved| try w.print("{f}, ", .{ - Type.fromInterned(resolved.type).fmt(.{ .zcu = zcu, .tid = tid }), + Type.fromInterned(resolved.type).fmt(zcu), }); try w.print("{f})", .{nav.fqn.fmt(ip)}); }, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index a44846211834c8b96a52324ce218c7ea479de48f..017b5a1ab565b8b38c088dfecae29b4ad5f33b29 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -1330,7 +1330,7 @@ fn updateLazySymbol( const name_str = blk: { const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{f}", .{ @tagName(lazy_sym.kind), - Type.fromInterned(lazy_sym.ty).fmt(pt), + Type.fromInterned(lazy_sym.ty).fmt(zcu), }); defer gpa.free(name); break :blk try self.addString(gpa, name); diff --git a/src/print_value.zig b/src/print_value.zig index b659b53df4031797d4b8cf4212c7365ad0ca5f4f..60a4cd4d521b4d0e1913aca765ff14181ca8b481 100644 --- a/src/print_value.zig +++ b/src/print_value.zig @@ -10,28 +10,29 @@ const InternPool = @import("InternPool.zig"); const Allocator = std.mem.Allocator; const Target = std.Target; const Writer = std.Io.Writer; +const assert = std.debug.assert; const max_aggregate_items = 100; const max_string_len = 256; pub const FormatContext = struct { val: Value, - pt: Zcu.PerThread, + zcu: *Zcu, opt_sema: ?*Sema, depth: u8, }; pub fn formatSema(ctx: FormatContext, writer: *Writer) Writer.Error!void { const sema = ctx.opt_sema.?; - return print(ctx.val, writer, ctx.depth, ctx.pt, sema) catch |err| switch (err) { + return print(ctx.val, writer, ctx.depth, ctx.zcu, sema) catch |err| switch (err) { error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function error.WriteFailed => |e| return e, }; } pub fn format(ctx: FormatContext, writer: *Writer) Writer.Error!void { - std.debug.assert(ctx.opt_sema == null); - return print(ctx.val, writer, ctx.depth, ctx.pt, null) catch |err| switch (err) { + assert(ctx.opt_sema == null); + return print(ctx.val, writer, ctx.depth, ctx.zcu, null) catch |err| switch (err) { error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function error.WriteFailed => |e| return e, }; @@ -41,10 +42,9 @@ pub fn print( val: Value, writer: *Writer, level: u8, - pt: Zcu.PerThread, + zcu: *Zcu, opt_sema: ?*Sema, ) (Writer.Error || Allocator.Error)!void { - const zcu = pt.zcu; const ip = &zcu.intern_pool; switch (ip.indexToKey(val.toIntern())) { .int_type, @@ -64,7 +64,7 @@ pub fn print( .func_type, .error_set_type, .inferred_error_set_type, - => try Type.print(val.toType(), writer, pt, null), + => try Type.print(val.toType(), writer, zcu, null), .undef => try writer.writeAll("undefined"), .simple_value => |simple_value| switch (simple_value) { .void => try writer.writeAll("{}"), @@ -88,7 +88,7 @@ pub fn print( .err_name => |err_name| try writer.print("error.{f}", .{ err_name.fmt(ip), }), - .payload => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema), + .payload => |payload| try print(Value.fromInterned(payload), writer, level, zcu, opt_sema), }, .enum_literal => |enum_literal| try writer.print(".{f}", .{ enum_literal.fmt(ip), @@ -101,7 +101,7 @@ pub fn print( } try writer.writeAll("@fromBackingInt("); if (level == 0) return writer.writeAll("...)"); - try print(.fromInterned(enum_tag.int), writer, level - 1, pt, opt_sema); + try print(.fromInterned(enum_tag.int), writer, level - 1, zcu, opt_sema); try writer.writeAll(")"); }, .float => |float| switch (float.storage) { @@ -112,7 +112,7 @@ pub fn print( if (slice.len == .zero_usize) { return writer.writeAll("&.{}"); } - try print(.fromInterned(slice.ptr), writer, level, pt, opt_sema); + try print(.fromInterned(slice.ptr), writer, level, zcu, opt_sema); } else { const print_contents = switch (ip.getBackingAddrTag(slice.ptr).?) { .field, .arr_elem, .eu_payload, .opt_payload => unreachable, @@ -123,13 +123,13 @@ pub fn print( // TODO: eventually we want to load the slice as an array with `sema`, but that's // currently not possible without e.g. triggering compile errors. } - try printPtr(Value.fromInterned(slice.ptr), null, writer, level, pt, opt_sema); + try printPtr(Value.fromInterned(slice.ptr), null, writer, level, zcu, opt_sema); } try writer.writeAll("[0.."); if (level == 0) { try writer.writeAll("(...)"); } else { - try print(Value.fromInterned(slice.len), writer, level - 1, pt, opt_sema); + try print(Value.fromInterned(slice.len), writer, level - 1, zcu, opt_sema); } try writer.writeAll("]"); }, @@ -143,28 +143,28 @@ pub fn print( // TODO: eventually we want to load the pointer with `sema`, but that's // currently not possible without e.g. triggering compile errors. } - try printPtr(val, .rvalue, writer, level, pt, opt_sema); + try printPtr(val, .rvalue, writer, level, zcu, opt_sema); }, .opt => |opt| switch (opt.val) { .none => try writer.writeAll("null"), - else => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema), + else => |payload| try print(Value.fromInterned(payload), writer, level, zcu, opt_sema), }, - .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, pt, opt_sema), + .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, zcu, opt_sema), .un => |un| { if (level == 0) { try writer.writeAll(".{ ... }"); return; } if (un.tag == .none) { - const backing_ty = try val.typeOf(zcu).externUnionBackingType(pt); - try writer.print("@bitCast(@as({f}, ", .{backing_ty.fmt(pt)}); - try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema); + const backing_val: Value = .fromInterned(un.val); + try writer.print("@bitCast(@as({f}, ", .{backing_val.typeOf(zcu).fmt(zcu)}); + try print(backing_val, writer, level - 1, zcu, opt_sema); try writer.writeAll("))"); } else { try writer.writeAll(".{ "); - try print(Value.fromInterned(un.tag), writer, level - 1, pt, opt_sema); + try print(Value.fromInterned(un.tag), writer, level - 1, zcu, opt_sema); try writer.writeAll(" = "); - try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema); + try print(Value.fromInterned(un.val), writer, level - 1, zcu, opt_sema); try writer.writeAll(" }"); } }, @@ -173,35 +173,17 @@ pub fn print( return writer.writeAll(".{ ... }"); } const ty: Type = .fromInterned(bitpack.ty); - switch (ty.zigTypeTag(zcu)) { - .@"struct" => { - if (ty.structFieldCount(zcu) == 0) { - return writer.writeAll(".{}"); - } - try writer.writeAll(".{ "); - const max_len = @min(ty.structFieldCount(zcu), max_aggregate_items); - for (0..max_len) |i| { - if (i != 0) try writer.writeAll(", "); - const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?; - try writer.print(".{f} = ", .{field_name.fmt(ip)}); - try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema); - } - try writer.writeAll(" }"); - return; + switch (ty.backingIntMode(zcu)) { + .auto => { + try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(zcu)}); + try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema); + try writer.writeAll("))"); }, - .@"union" => switch (ty.backingIntMode(zcu)) { - .auto => { - try writer.print("@bitCast(@as({f}, ", .{ty.backingIntType(zcu).fmt(pt)}); - try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, pt, opt_sema); - try writer.writeAll("))"); - }, - .explicit => { - try writer.writeAll("@fromBackingInt("); - try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, pt, opt_sema); - try writer.writeAll(")"); - }, + .explicit => { + try writer.writeAll("@fromBackingInt("); + try print(.fromInterned(bitpack.backing_int_val), writer, level - 1, zcu, opt_sema); + try writer.writeAll(")"); }, - else => unreachable, } }, .memoized_call => unreachable, @@ -214,14 +196,13 @@ fn printAggregate( is_ref: bool, writer: *Writer, level: u8, - pt: Zcu.PerThread, + zcu: *Zcu, opt_sema: ?*Sema, ) (Writer.Error || Allocator.Error)!void { if (level == 0) { if (is_ref) try writer.writeByte('&'); return writer.writeAll(".{ ... }"); } - const zcu = pt.zcu; const ip = &zcu.intern_pool; const ty = Type.fromInterned(aggregate.ty); switch (ty.zigTypeTag(zcu)) { @@ -236,7 +217,7 @@ fn printAggregate( if (i != 0) try writer.writeAll(", "); const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?; try writer.print(".{f} = ", .{field_name.fmt(ip)}); - try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema); + try printFieldValue(val, i, writer, level - 1, zcu, opt_sema); } try writer.writeAll(" }"); return; @@ -285,7 +266,7 @@ fn printAggregate( 0 => try writer.writeAll(".{}"), 1 => { try writer.writeAll(".{"); - try print(try val.fieldValue(pt, 0), writer, level - 1, pt, opt_sema); + try printFieldValue(val, 0, writer, level - 1, zcu, opt_sema); try writer.writeByte('}'); }, else => { @@ -293,7 +274,7 @@ fn printAggregate( const max_len = @min(len, max_aggregate_items); for (0..max_len) |i| { if (i != 0) try writer.writeAll(", "); - try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema); + try printFieldValue(val, i, writer, level - 1, zcu, opt_sema); } if (len > max_aggregate_items) { try writer.writeAll(", ..."); @@ -303,16 +284,40 @@ fn printAggregate( } } +/// We cannot use `aggregate_val.fieldValue(...)` here because for some representations of aggregate +/// values the individual field values may not yet be in the `InternPool`. So, this function is the +/// equivalent of doing `print(try aggregate_val.fieldValue(...))`, which understands the optimized +/// value representations so does not need to intern new values. +fn printFieldValue( + aggregate_val: Value, + field_index: usize, + writer: *Writer, + level: u8, + zcu: *Zcu, + opt_sema: ?*Sema, +) (Writer.Error || Allocator.Error)!void { + const ip = &zcu.intern_pool; + switch (ip.indexToKey(aggregate_val.toIntern())) { + .undef => try writer.writeAll("undefined"), + .aggregate => |aggregate| switch (aggregate.storage) { + .bytes => |bytes| try writer.print("{d}", .{bytes.at(field_index, ip)}), + .elems => |elems| try print(.fromInterned(elems[field_index]), writer, level, zcu, opt_sema), + .repeated_elem => |elem| try print(.fromInterned(elem), writer, level, zcu, opt_sema), + }, + else => unreachable, + } +} + fn printPtr( ptr_val: Value, /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen. want_kind: ?PrintPtrKind, writer: *Writer, level: u8, - pt: Zcu.PerThread, + zcu: *Zcu, opt_sema: ?*Sema, ) (Writer.Error || Allocator.Error)!void { - const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) { + const ptr = switch (zcu.intern_pool.indexToKey(ptr_val.toIntern())) { .undef => return writer.writeAll("undefined"), .ptr => |ptr| ptr, else => unreachable, @@ -320,25 +325,25 @@ fn printPtr( if (ptr.base_addr == .uav) { // If the value is an aggregate, we can potentially print it more nicely. - switch (pt.zcu.intern_pool.indexToKey(ptr.base_addr.uav.val)) { + switch (zcu.intern_pool.indexToKey(ptr.base_addr.uav.val)) { .aggregate => |agg| return printAggregate( Value.fromInterned(ptr.base_addr.uav.val), agg, true, writer, level, - pt, + zcu, opt_sema, ), else => {}, } } - var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa); + var arena = std.heap.ArenaAllocator.init(zcu.gpa); defer arena.deinit(); - const derivation = try ptr_val.pointerDerivation(arena.allocator(), pt, opt_sema); + const derivation = try ptr_val.pointerDerivation(arena.allocator(), zcu, opt_sema); - _ = try printPtrDerivation(derivation, writer, pt, want_kind, .{ .print_val = .{ + _ = try printPtrDerivation(derivation, writer, zcu, want_kind, .{ .print_val = .{ .level = level, .opt_sema = opt_sema, } }, 20); @@ -349,9 +354,9 @@ const PrintPtrKind = enum { lvalue, rvalue }; /// Print the pointer defined by `derivation` as an lvalue or an rvalue. /// Returns the root derivation, which may be ignored. pub fn printPtrDerivation( - derivation: Value.PointerDeriveStep, + derivation: Value.PointerDerivation, writer: *Writer, - pt: Zcu.PerThread, + zcu: *Zcu, /// Whether to print `derivation` as an lvalue or rvalue. If `null`, the more concise option is chosen. /// If this is `.rvalue`, the result may look like `&foo`, so it's not necessarily valid to treat it as /// an atom -- e.g. `&foo.*` is distinct from `(&foo).*`. @@ -368,33 +373,36 @@ pub fn printPtrDerivation( /// The maximum recursion depth. We can never recurse infinitely here, but the depth can be arbitrary, /// so at this depth we just write "..." to prevent stack overflow. ptr_depth: u8, -) !Value.PointerDeriveStep { - const zcu = pt.zcu; +) !Value.PointerDerivation { const ip = &zcu.intern_pool; if (ptr_depth == 0) { - const root_step = root: switch (derivation) { - inline .eu_payload_ptr, - .opt_payload_ptr, - .field_ptr, - .elem_ptr, - .offset_and_cast, - => |step| continue :root step.parent.*, - else => |step| break :root step, - }; + var root_step = derivation; + while (true) { + switch (derivation.addr) { + inline .eu_payload, + .opt_payload, + .field, + .elem, + .offset_and_cast, + => |derived| root_step = derived.parent.*, + + .int, .nav, .uav, .comptime_alloc, .comptime_field => break, + } + } try writer.writeAll("..."); return root_step; } - const result_kind: PrintPtrKind = switch (derivation) { - .nav_ptr, - .uav_ptr, - .comptime_alloc_ptr, - .comptime_field_ptr, - .eu_payload_ptr, - .opt_payload_ptr, - .field_ptr, - .elem_ptr, + const result_kind: PrintPtrKind = switch (derivation.addr) { + .nav, + .uav, + .comptime_alloc, + .comptime_field, + .eu_payload, + .opt_payload, + .field, + .elem, => .lvalue, .offset_and_cast, @@ -409,33 +417,33 @@ pub fn printPtrDerivation( } // null if `derivation` is the root. - const root_or_null: ?Value.PointerDeriveStep = switch (derivation) { - .eu_payload_ptr => |info| root: { + const root_or_null: ?Value.PointerDerivation = switch (derivation.addr) { + .eu_payload => |info| root: { try writer.writeByte('('); - const root = try printPtrDerivation(info.parent.*, writer, pt, .lvalue, root_strat, ptr_depth - 1); + const root = try printPtrDerivation(info.parent.*, writer, zcu, .lvalue, root_strat, ptr_depth - 1); try writer.writeAll(" catch unreachable)"); break :root root; }, - .opt_payload_ptr => |info| root: { - const root = try printPtrDerivation(info.parent.*, writer, pt, .lvalue, root_strat, ptr_depth - 1); + .opt_payload => |info| root: { + const root = try printPtrDerivation(info.parent.*, writer, zcu, .lvalue, root_strat, ptr_depth - 1); try writer.writeAll(".?"); break :root root; }, - .field_ptr => |field| root: { - const root = try printPtrDerivation(field.parent.*, writer, pt, null, root_strat, ptr_depth - 1); - const agg_ty = (try field.parent.ptrType(pt)).childType(zcu); + .field => |derived| root: { + const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1); + const agg_ty = derived.parent.elem_ty; switch (agg_ty.zigTypeTag(zcu)) { - .@"struct" => if (agg_ty.structFieldName(field.field_idx, zcu).unwrap()) |field_name| { + .@"struct" => if (agg_ty.structFieldName(derived.field_index, zcu).unwrap()) |field_name| { try writer.print(".{f}", .{field_name.fmt(ip)}); } else { - try writer.print("[{d}]", .{field.field_idx}); + try writer.print("[{d}]", .{derived.field_index}); }, .@"union" => { const tag_ty = agg_ty.unionTagTypeHypothetical(zcu); - const field_name = tag_ty.enumFieldName(field.field_idx, zcu); + const field_name = tag_ty.enumFieldName(derived.field_index, zcu); try writer.print(".{f}", .{field_name.fmt(ip)}); }, - .pointer => switch (field.field_idx) { + .pointer => switch (derived.field_index) { Value.slice_ptr_index => try writer.writeAll(".ptr"), Value.slice_len_index => try writer.writeAll(".len"), else => unreachable, @@ -444,58 +452,49 @@ pub fn printPtrDerivation( } break :root root; }, - .elem_ptr => |elem| root: { - const root = try printPtrDerivation(elem.parent.*, writer, pt, null, root_strat, ptr_depth - 1); - try writer.print("[{d}]", .{elem.elem_idx}); + .elem => |derived| root: { + const root = try printPtrDerivation(derived.parent.*, writer, zcu, null, root_strat, ptr_depth - 1); + try writer.print("[{d}]", .{derived.elem_index}); break :root root; }, - .offset_and_cast => |oac| if (oac.byte_offset == 0) root: { - try writer.print("@as({f}, @ptrCast(", .{oac.new_ptr_ty.fmt(pt)}); - const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1); + .offset_and_cast => |derived| if (derived.byte_offset == 0) root: { + try writer.print("@as({f}, @ptrCast(", .{derivation.fmtType(zcu)}); + const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1); try writer.writeAll("))"); break :root root; } else root: { - try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{oac.new_ptr_ty.fmt(pt)}); - const root = try printPtrDerivation(oac.parent.*, writer, pt, .rvalue, root_strat, ptr_depth - 1); - try writer.print(") + {d}))", .{oac.byte_offset}); + try writer.print("@as({f}, @ptrFromInt(@intFromPtr(", .{derivation.fmtType(zcu)}); + const root = try printPtrDerivation(derived.parent.*, writer, zcu, .rvalue, root_strat, ptr_depth - 1); + try writer.print(") + {d}))", .{derived.byte_offset}); break :root root; }, - .int, .nav_ptr, .uav_ptr, .comptime_alloc_ptr, .comptime_field_ptr => null, + .int, .nav, .uav, .comptime_alloc, .comptime_field => null, }; if (root_or_null == null) switch (root_strat) { .str => |x| try writer.writeAll(x), - .print_val => |x| switch (derivation) { - .int => |int| try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ int.ptr_ty.fmt(pt), int.addr }), - .nav_ptr => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}), - .uav_ptr => |uav| { - const ty = Value.fromInterned(uav.val).typeOf(zcu); - try writer.print("@as({f}, ", .{ty.fmt(pt)}); - if (x.level == 0) { - try writer.writeAll("..."); - } else { - try print(Value.fromInterned(uav.val), writer, x.level - 1, pt, x.opt_sema); - } - try writer.writeByte(')'); + .print_val => |x| switch (derivation.addr) { + .int => |int| { + try writer.print("@as({f}, @ptrFromInt(0x{x}))", .{ derivation.fmtType(zcu), int }); }, - .comptime_alloc_ptr => |info| { - try writer.print("@as({f}, ", .{info.val.typeOf(zcu).fmt(pt)}); + .nav => |nav| try writer.print("{f}", .{ip.getNav(nav).fqn.fmt(ip)}), + .uav, .comptime_field => |val| { + try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)}); if (x.level == 0) { try writer.writeAll("..."); } else { - try print(info.val, writer, x.level - 1, pt, x.opt_sema); + try print(val, writer, x.level - 1, zcu, x.opt_sema); } try writer.writeByte(')'); }, - .comptime_field_ptr => |val| { - const ty = val.typeOf(zcu); - try writer.print("@as({f}, ", .{ty.fmt(pt)}); + .comptime_alloc => |info| { + try writer.print("@as({f}, ", .{derivation.elem_ty.fmt(zcu)}); if (x.level == 0) { try writer.writeAll("..."); } else { - try print(val, writer, x.level - 1, pt, x.opt_sema); + try print(info.val, writer, x.level - 1, zcu, x.opt_sema); } try writer.writeByte(')'); },