authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-16 11:37:53+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-16 11:38:21+01:00
logf84a4953d29ffc2bdc94fa353cac685430e6bbe4
tree9e7e0c705451b464979cb8330e6b87de67ae1085
parent67cd14dbdbf2ce435a2bd81dc82d167b99fad6e3
signaturelock-open Commit is signed but in an unrecognized format.

Value: eliminate static recursion loop from value printing


8 files changed, 154 insertions(+), 110 deletions(-)

src/Sema.zig+50-50
...@@ -2318,7 +2318,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2318,7 +2318,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2318 if (int_ty.zigTypeTag(zcu) == .Vector) {2318 if (int_ty.zigTypeTag(zcu) == .Vector) {
2319 const msg = msg: {2319 const msg = msg: {
2320 const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{2320 const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{
2321 int_ty.fmt(pt), val.fmtValue(pt, sema),2321 int_ty.fmt(pt), val.fmtValueSema(pt, sema),
2322 });2322 });
2323 errdefer msg.destroy(sema.gpa);2323 errdefer msg.destroy(sema.gpa);
2324 try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index});2324 try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index});
...@@ -2327,7 +2327,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2327,7 +2327,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2327 return sema.failWithOwnedErrorMsg(block, msg);2327 return sema.failWithOwnedErrorMsg(block, msg);
2328 }2328 }
2329 return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{2329 return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{
2330 int_ty.fmt(pt), val.fmtValue(pt, sema),2330 int_ty.fmt(pt), val.fmtValueSema(pt, sema),
2331 });2331 });
2332}2332}
23332333
...@@ -2912,7 +2912,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2912,7 +2912,7 @@ fn createAnonymousDeclTypeNamed(
2912 // in turn helps to avoid unreasonably long symbol names for namespaced2912 // in turn helps to avoid unreasonably long symbol names for namespaced
2913 // symbols. Such names should ideally be human-readable, and additionally,2913 // symbols. Such names should ideally be human-readable, and additionally,
2914 // some tooling may not support very long symbol names.2914 // some tooling may not support very long symbol names.
2915 try writer.print("{}", .{Value.fmtValueFull(.{2915 try writer.print("{}", .{Value.fmtValueSemaFull(.{
2916 .val = arg_val,2916 .val = arg_val,
2917 .pt = pt,2917 .pt = pt,
2918 .opt_sema = sema,2918 .opt_sema = sema,
...@@ -3202,7 +3202,7 @@ fn zirEnumDecl(...@@ -3202,7 +3202,7 @@ fn zirEnumDecl(
3202 .offset = .{ .container_field_value = conflict.prev_field_idx },3202 .offset = .{ .container_field_value = conflict.prev_field_idx },
3203 };3203 };
3204 const msg = msg: {3204 const msg = msg: {
3205 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(pt, sema)});3205 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValueSema(pt, sema)});
3206 errdefer msg.destroy(gpa);3206 errdefer msg.destroy(gpa);
3207 try sema.errNote(other_field_src, msg, "other occurrence here", .{});3207 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
3208 break :msg msg;3208 break :msg msg;
...@@ -3224,7 +3224,7 @@ fn zirEnumDecl(...@@ -3224,7 +3224,7 @@ fn zirEnumDecl(
3224 .offset = .{ .container_field_value = conflict.prev_field_idx },3224 .offset = .{ .container_field_value = conflict.prev_field_idx },
3225 };3225 };
3226 const msg = msg: {3226 const msg = msg: {
3227 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(pt, sema)});3227 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValueSema(pt, sema)});
3228 errdefer msg.destroy(gpa);3228 errdefer msg.destroy(gpa);
3229 try sema.errNote(other_field_src, msg, "other occurrence here", .{});3229 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
3230 break :msg msg;3230 break :msg msg;
...@@ -3242,7 +3242,7 @@ fn zirEnumDecl(...@@ -3242,7 +3242,7 @@ fn zirEnumDecl(
32423242
3243 if (tag_overflow) {3243 if (tag_overflow) {
3244 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{3244 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{
3245 last_tag_val.?.fmtValue(pt, sema), int_tag_ty.fmt(pt),3245 last_tag_val.?.fmtValueSema(pt, sema), int_tag_ty.fmt(pt),
3246 });3246 });
3247 return sema.failWithOwnedErrorMsg(block, msg);3247 return sema.failWithOwnedErrorMsg(block, msg);
3248 }3248 }
...@@ -4430,10 +4430,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4430,10 +4430,10 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4430 .input_index = len_idx,4430 .input_index = len_idx,
4431 } });4431 } });
4432 try sema.errNote(a_src, msg, "length {} here", .{4432 try sema.errNote(a_src, msg, "length {} here", .{
4433 v.fmtValue(pt, sema),4433 v.fmtValueSema(pt, sema),
4434 });4434 });
4435 try sema.errNote(arg_src, msg, "length {} here", .{4435 try sema.errNote(arg_src, msg, "length {} here", .{
4436 arg_val.fmtValue(pt, sema),4436 arg_val.fmtValueSema(pt, sema),
4437 });4437 });
4438 break :msg msg;4438 break :msg msg;
4439 };4439 };
...@@ -5853,7 +5853,7 @@ fn zirCompileLog(...@@ -5853,7 +5853,7 @@ fn zirCompileLog(
5853 const arg_ty = sema.typeOf(arg);5853 const arg_ty = sema.typeOf(arg);
5854 if (try sema.resolveValueResolveLazy(arg)) |val| {5854 if (try sema.resolveValueResolveLazy(arg)) |val| {
5855 try writer.print("@as({}, {})", .{5855 try writer.print("@as({}, {})", .{
5856 arg_ty.fmt(pt), val.fmtValue(pt, sema),5856 arg_ty.fmt(pt), val.fmtValueSema(pt, sema),
5857 });5857 });
5858 } else {5858 } else {
5859 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(pt)});5859 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(pt)});
...@@ -8949,7 +8949,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8949,7 +8949,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8949 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());8949 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
8950 }8950 }
8951 return sema.fail(block, src, "int value '{}' out of range of non-exhaustive enum '{}'", .{8951 return sema.fail(block, src, "int value '{}' out of range of non-exhaustive enum '{}'", .{
8952 int_val.fmtValue(pt, sema), dest_ty.fmt(pt),8952 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),
8953 });8953 });
8954 }8954 }
8955 if (int_val.isUndef(mod)) {8955 if (int_val.isUndef(mod)) {
...@@ -8957,7 +8957,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8957,7 +8957,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8957 }8957 }
8958 if (!(try sema.enumHasInt(dest_ty, int_val))) {8958 if (!(try sema.enumHasInt(dest_ty, int_val))) {
8959 return sema.fail(block, src, "enum '{}' has no tag with value '{}'", .{8959 return sema.fail(block, src, "enum '{}' has no tag with value '{}'", .{
8960 dest_ty.fmt(pt), int_val.fmtValue(pt, sema),8960 dest_ty.fmt(pt), int_val.fmtValueSema(pt, sema),
8961 });8961 });
8962 }8962 }
8963 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());8963 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
...@@ -14067,7 +14067,7 @@ fn zirShl(...@@ -14067,7 +14067,7 @@ fn zirShl(
14067 const rhs_elem = try rhs_val.elemValue(pt, i);14067 const rhs_elem = try rhs_val.elemValue(pt, i);
14068 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {14068 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {
14069 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{14069 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
14070 rhs_elem.fmtValue(pt, sema),14070 rhs_elem.fmtValueSema(pt, sema),
14071 i,14071 i,
14072 scalar_ty.fmt(pt),14072 scalar_ty.fmt(pt),
14073 });14073 });
...@@ -14075,7 +14075,7 @@ fn zirShl(...@@ -14075,7 +14075,7 @@ fn zirShl(
14075 }14075 }
14076 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {14076 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {
14077 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{14077 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
14078 rhs_val.fmtValue(pt, sema),14078 rhs_val.fmtValueSema(pt, sema),
14079 scalar_ty.fmt(pt),14079 scalar_ty.fmt(pt),
14080 });14080 });
14081 }14081 }
...@@ -14086,14 +14086,14 @@ fn zirShl(...@@ -14086,14 +14086,14 @@ fn zirShl(
14086 const rhs_elem = try rhs_val.elemValue(pt, i);14086 const rhs_elem = try rhs_val.elemValue(pt, i);
14087 if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), pt)) {14087 if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), pt)) {
14088 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{14088 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
14089 rhs_elem.fmtValue(pt, sema),14089 rhs_elem.fmtValueSema(pt, sema),
14090 i,14090 i,
14091 });14091 });
14092 }14092 }
14093 }14093 }
14094 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {14094 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {
14095 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{14095 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
14096 rhs_val.fmtValue(pt, sema),14096 rhs_val.fmtValueSema(pt, sema),
14097 });14097 });
14098 }14098 }
14099 }14099 }
...@@ -14233,7 +14233,7 @@ fn zirShr(...@@ -14233,7 +14233,7 @@ fn zirShr(
14233 const rhs_elem = try rhs_val.elemValue(pt, i);14233 const rhs_elem = try rhs_val.elemValue(pt, i);
14234 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {14234 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {
14235 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{14235 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
14236 rhs_elem.fmtValue(pt, sema),14236 rhs_elem.fmtValueSema(pt, sema),
14237 i,14237 i,
14238 scalar_ty.fmt(pt),14238 scalar_ty.fmt(pt),
14239 });14239 });
...@@ -14241,7 +14241,7 @@ fn zirShr(...@@ -14241,7 +14241,7 @@ fn zirShr(
14241 }14241 }
14242 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {14242 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {
14243 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{14243 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
14244 rhs_val.fmtValue(pt, sema),14244 rhs_val.fmtValueSema(pt, sema),
14245 scalar_ty.fmt(pt),14245 scalar_ty.fmt(pt),
14246 });14246 });
14247 }14247 }
...@@ -14252,14 +14252,14 @@ fn zirShr(...@@ -14252,14 +14252,14 @@ fn zirShr(
14252 const rhs_elem = try rhs_val.elemValue(pt, i);14252 const rhs_elem = try rhs_val.elemValue(pt, i);
14253 if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(mod), 0), pt)) {14253 if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(mod), 0), pt)) {
14254 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{14254 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
14255 rhs_elem.fmtValue(pt, sema),14255 rhs_elem.fmtValueSema(pt, sema),
14256 i,14256 i,
14257 });14257 });
14258 }14258 }
14259 }14259 }
14260 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {14260 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {
14261 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{14261 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
14262 rhs_val.fmtValue(pt, sema),14262 rhs_val.fmtValueSema(pt, sema),
14263 });14263 });
14264 }14264 }
14265 if (maybe_lhs_val) |lhs_val| {14265 if (maybe_lhs_val) |lhs_val| {
...@@ -15190,7 +15190,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15190,7 +15190,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15190 block,15190 block,
15191 src,15191 src,
15192 "ambiguous coercion of division operands '{}' and '{}'; non-zero remainder '{}'",15192 "ambiguous coercion of division operands '{}' and '{}'; non-zero remainder '{}'",
15193 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValue(pt, sema) },15193 .{ lhs_ty.fmt(pt), rhs_ty.fmt(pt), rem.fmtValueSema(pt, sema) },
15194 );15194 );
15195 }15195 }
15196 }15196 }
...@@ -21359,7 +21359,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21359,7 +21359,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21359 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {21359 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
21360 const msg = msg: {21360 const msg = msg: {
21361 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{21361 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{
21362 val.fmtValue(pt, sema), mod.declPtr(enum_decl_index).name.fmt(ip),21362 val.fmtValueSema(pt, sema), mod.declPtr(enum_decl_index).name.fmt(ip),
21363 });21363 });
21364 errdefer msg.destroy(sema.gpa);21364 errdefer msg.destroy(sema.gpa);
21365 try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{});21365 try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{});
...@@ -22005,7 +22005,7 @@ fn reifyEnum(...@@ -22005,7 +22005,7 @@ fn reifyEnum(
22005 // TODO: better source location22005 // TODO: better source location
22006 return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{22006 return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{
22007 field_name.fmt(ip),22007 field_name.fmt(ip),
22008 field_value_val.fmtValue(pt, sema),22008 field_value_val.fmtValueSema(pt, sema),
22009 tag_ty.fmt(pt),22009 tag_ty.fmt(pt),
22010 });22010 });
22011 }22011 }
...@@ -22021,7 +22021,7 @@ fn reifyEnum(...@@ -22021,7 +22021,7 @@ fn reifyEnum(
22021 break :msg msg;22021 break :msg msg;
22022 },22022 },
22023 .value => msg: {22023 .value => msg: {
22024 const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(pt, sema)});22024 const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValueSema(pt, sema)});
22025 errdefer msg.destroy(gpa);22025 errdefer msg.destroy(gpa);
22026 _ = conflict.prev_field_idx; // TODO: this note is incorrect22026 _ = conflict.prev_field_idx; // TODO: this note is incorrect
22027 try sema.errNote(src, msg, "other enum tag value here", .{});22027 try sema.errNote(src, msg, "other enum tag value here", .{});
...@@ -23193,12 +23193,12 @@ fn ptrCastFull(...@@ -23193,12 +23193,12 @@ fn ptrCastFull(
23193 return sema.failWithOwnedErrorMsg(block, msg: {23193 return sema.failWithOwnedErrorMsg(block, msg: {
23194 const msg = if (src_info.sentinel == .none) blk: {23194 const msg = if (src_info.sentinel == .none) blk: {
23195 break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{23195 break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{
23196 Value.fromInterned(dest_info.sentinel).fmtValue(pt, sema),23196 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
23197 });23197 });
23198 } else blk: {23198 } else blk: {
23199 break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{23199 break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
23200 Value.fromInterned(src_info.sentinel).fmtValue(pt, sema),23200 Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema),
23201 Value.fromInterned(dest_info.sentinel).fmtValue(pt, sema),23201 Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema),
23202 });23202 });
23203 };23203 };
23204 errdefer msg.destroy(sema.gpa);23204 errdefer msg.destroy(sema.gpa);
...@@ -25691,10 +25691,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25691,10 +25691,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25691 const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{});25691 const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{});
25692 errdefer msg.destroy(sema.gpa);25692 errdefer msg.destroy(sema.gpa);
25693 try sema.errNote(dest_src, msg, "length {} here", .{25693 try sema.errNote(dest_src, msg, "length {} here", .{
25694 dest_len_val.fmtValue(pt, sema),25694 dest_len_val.fmtValueSema(pt, sema),
25695 });25695 });
25696 try sema.errNote(src_src, msg, "length {} here", .{25696 try sema.errNote(src_src, msg, "length {} here", .{
25697 src_len_val.fmtValue(pt, sema),25697 src_len_val.fmtValueSema(pt, sema),
25698 });25698 });
25699 break :msg msg;25699 break :msg msg;
25700 };25700 };
...@@ -29560,7 +29560,7 @@ fn coerceExtra(...@@ -29560,7 +29560,7 @@ fn coerceExtra(
29560 // comptime-known integer to other number29560 // comptime-known integer to other number
29561 if (!(try sema.intFitsInType(val, dest_ty, null))) {29561 if (!(try sema.intFitsInType(val, dest_ty, null))) {
29562 if (!opts.report_err) return error.NotCoercible;29562 if (!opts.report_err) return error.NotCoercible;
29563 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(pt), val.fmtValue(pt, sema) });29563 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) });
29564 }29564 }
29565 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {29565 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
29566 .undef => try pt.undefRef(dest_ty),29566 .undef => try pt.undefRef(dest_ty),
...@@ -29605,7 +29605,7 @@ fn coerceExtra(...@@ -29605,7 +29605,7 @@ fn coerceExtra(
29605 block,29605 block,
29606 inst_src,29606 inst_src,
29607 "type '{}' cannot represent float value '{}'",29607 "type '{}' cannot represent float value '{}'",
29608 .{ dest_ty.fmt(pt), val.fmtValue(pt, sema) },29608 .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) },
29609 );29609 );
29610 }29610 }
29611 return Air.internedToRef(result_val.toIntern());29611 return Air.internedToRef(result_val.toIntern());
...@@ -30003,11 +30003,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -30003,11 +30003,11 @@ const InMemoryCoercionResult = union(enum) {
30003 .array_sentinel => |sentinel| {30003 .array_sentinel => |sentinel| {
30004 if (sentinel.actual.toIntern() != .unreachable_value) {30004 if (sentinel.actual.toIntern() != .unreachable_value) {
30005 try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{30005 try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
30006 sentinel.actual.fmtValue(pt, sema), sentinel.wanted.fmtValue(pt, sema),30006 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
30007 });30007 });
30008 } else {30008 } else {
30009 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{30009 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{
30010 sentinel.wanted.fmtValue(pt, sema),30010 sentinel.wanted.fmtValueSema(pt, sema),
30011 });30011 });
30012 }30012 }
30013 break;30013 break;
...@@ -30129,11 +30129,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -30129,11 +30129,11 @@ const InMemoryCoercionResult = union(enum) {
30129 .ptr_sentinel => |sentinel| {30129 .ptr_sentinel => |sentinel| {
30130 if (sentinel.actual.toIntern() != .unreachable_value) {30130 if (sentinel.actual.toIntern() != .unreachable_value) {
30131 try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{30131 try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
30132 sentinel.actual.fmtValue(pt, sema), sentinel.wanted.fmtValue(pt, sema),30132 sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema),
30133 });30133 });
30134 } else {30134 } else {
30135 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{30135 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{
30136 sentinel.wanted.fmtValue(pt, sema),30136 sentinel.wanted.fmtValueSema(pt, sema),
30137 });30137 });
30138 }30138 }
30139 break;30139 break;
...@@ -31379,7 +31379,7 @@ fn coerceEnumToUnion(...@@ -31379,7 +31379,7 @@ fn coerceEnumToUnion(
31379 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {31379 if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| {
31380 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {31380 const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse {
31381 return sema.fail(block, inst_src, "union '{}' has no tag with value '{}'", .{31381 return sema.fail(block, inst_src, "union '{}' has no tag with value '{}'", .{
31382 union_ty.fmt(pt), val.fmtValue(pt, sema),31382 union_ty.fmt(pt), val.fmtValueSema(pt, sema),
31383 });31383 });
31384 };31384 };
3138531385
...@@ -32611,8 +32611,8 @@ fn analyzeSlice(...@@ -32611,8 +32611,8 @@ fn analyzeSlice(
32611 msg,32611 msg,
32612 "expected '{}', found '{}'",32612 "expected '{}', found '{}'",
32613 .{32613 .{
32614 Value.zero_comptime_int.fmtValue(pt, sema),32614 Value.zero_comptime_int.fmtValueSema(pt, sema),
32615 start_value.fmtValue(pt, sema),32615 start_value.fmtValueSema(pt, sema),
32616 },32616 },
32617 );32617 );
32618 break :msg msg;32618 break :msg msg;
...@@ -32627,8 +32627,8 @@ fn analyzeSlice(...@@ -32627,8 +32627,8 @@ fn analyzeSlice(
32627 msg,32627 msg,
32628 "expected '{}', found '{}'",32628 "expected '{}', found '{}'",
32629 .{32629 .{
32630 Value.one_comptime_int.fmtValue(pt, sema),32630 Value.one_comptime_int.fmtValueSema(pt, sema),
32631 end_value.fmtValue(pt, sema),32631 end_value.fmtValueSema(pt, sema),
32632 },32632 },
32633 );32633 );
32634 break :msg msg;32634 break :msg msg;
...@@ -32641,7 +32641,7 @@ fn analyzeSlice(...@@ -32641,7 +32641,7 @@ fn analyzeSlice(
32641 block,32641 block,
32642 end_src,32642 end_src,
32643 "end index {} out of bounds for slice of single-item pointer",32643 "end index {} out of bounds for slice of single-item pointer",
32644 .{end_value.fmtValue(pt, sema)},32644 .{end_value.fmtValueSema(pt, sema)},
32645 );32645 );
32646 }32646 }
32647 }32647 }
...@@ -32736,8 +32736,8 @@ fn analyzeSlice(...@@ -32736,8 +32736,8 @@ fn analyzeSlice(
32736 end_src,32736 end_src,
32737 "end index {} out of bounds for array of length {}{s}",32737 "end index {} out of bounds for array of length {}{s}",
32738 .{32738 .{
32739 end_val.fmtValue(pt, sema),32739 end_val.fmtValueSema(pt, sema),
32740 len_val.fmtValue(pt, sema),32740 len_val.fmtValueSema(pt, sema),
32741 sentinel_label,32741 sentinel_label,
32742 },32742 },
32743 );32743 );
...@@ -32781,7 +32781,7 @@ fn analyzeSlice(...@@ -32781,7 +32781,7 @@ fn analyzeSlice(
32781 end_src,32781 end_src,
32782 "end index {} out of bounds for slice of length {d}{s}",32782 "end index {} out of bounds for slice of length {d}{s}",
32783 .{32783 .{
32784 end_val.fmtValue(pt, sema),32784 end_val.fmtValueSema(pt, sema),
32785 try slice_val.sliceLen(pt),32785 try slice_val.sliceLen(pt),
32786 sentinel_label,32786 sentinel_label,
32787 },32787 },
...@@ -32841,8 +32841,8 @@ fn analyzeSlice(...@@ -32841,8 +32841,8 @@ fn analyzeSlice(
32841 start_src,32841 start_src,
32842 "start index {} is larger than end index {}",32842 "start index {} is larger than end index {}",
32843 .{32843 .{
32844 start_val.fmtValue(pt, sema),32844 start_val.fmtValueSema(pt, sema),
32845 end_val.fmtValue(pt, sema),32845 end_val.fmtValueSema(pt, sema),
32846 },32846 },
32847 );32847 );
32848 }32848 }
...@@ -32879,8 +32879,8 @@ fn analyzeSlice(...@@ -32879,8 +32879,8 @@ fn analyzeSlice(
32879 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});32879 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
32880 errdefer msg.destroy(sema.gpa);32880 errdefer msg.destroy(sema.gpa);
32881 try sema.errNote(src, msg, "expected '{}', found '{}'", .{32881 try sema.errNote(src, msg, "expected '{}', found '{}'", .{
32882 expected_sentinel.fmtValue(pt, sema),32882 expected_sentinel.fmtValueSema(pt, sema),
32883 actual_sentinel.fmtValue(pt, sema),32883 actual_sentinel.fmtValueSema(pt, sema),
32884 });32884 });
3288532885
32886 break :msg msg;32886 break :msg msg;
...@@ -36623,7 +36623,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L...@@ -36623,7 +36623,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
36623 .offset = .{ .container_field_value = @intCast(gop.index) },36623 .offset = .{ .container_field_value = @intCast(gop.index) },
36624 };36624 };
36625 const msg = msg: {36625 const msg = msg: {
36626 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(pt, &sema)});36626 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValueSema(pt, &sema)});
36627 errdefer msg.destroy(gpa);36627 errdefer msg.destroy(gpa);
36628 try sema.errNote(other_value_src, msg, "other occurrence here", .{});36628 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
36629 break :msg msg;36629 break :msg msg;
...@@ -37855,7 +37855,7 @@ fn intFromFloatScalar(...@@ -37855,7 +37855,7 @@ fn intFromFloatScalar(
37855 block,37855 block,
37856 src,37856 src,
37857 "fractional component prevents float value '{}' from coercion to type '{}'",37857 "fractional component prevents float value '{}' from coercion to type '{}'",
37858 .{ val.fmtValue(pt, sema), int_ty.fmt(pt) },37858 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
37859 );37859 );
3786037860
37861 const float = val.toFloat(f128, pt);37861 const float = val.toFloat(f128, pt);
...@@ -37877,7 +37877,7 @@ fn intFromFloatScalar(...@@ -37877,7 +37877,7 @@ fn intFromFloatScalar(
3787737877
37878 if (!(try sema.intFitsInType(cti_result, int_ty, null))) {37878 if (!(try sema.intFitsInType(cti_result, int_ty, null))) {
37879 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{37879 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{
37880 val.fmtValue(pt, sema), int_ty.fmt(pt),37880 val.fmtValueSema(pt, sema), int_ty.fmt(pt),
37881 });37881 });
37882 }37882 }
37883 return pt.getCoerced(cti_result, int_ty);37883 return pt.getCoerced(cti_result, int_ty);
src/Type.zig+4-4
...@@ -194,8 +194,8 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -194,8 +194,8 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
194194
195 if (info.sentinel != .none) switch (info.flags.size) {195 if (info.sentinel != .none) switch (info.flags.size) {
196 .One, .C => unreachable,196 .One, .C => unreachable,
197 .Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt, null)}),197 .Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
198 .Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt, null)}),198 .Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt)}),
199 } else switch (info.flags.size) {199 } else switch (info.flags.size) {
200 .One => try writer.writeAll("*"),200 .One => try writer.writeAll("*"),
201 .Many => try writer.writeAll("[*]"),201 .Many => try writer.writeAll("[*]"),
...@@ -241,7 +241,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -241,7 +241,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
241 } else {241 } else {
242 try writer.print("[{d}:{}]", .{242 try writer.print("[{d}:{}]", .{
243 array_type.len,243 array_type.len,
244 Value.fromInterned(array_type.sentinel).fmtValue(pt, null),244 Value.fromInterned(array_type.sentinel).fmtValue(pt),
245 });245 });
246 try print(Type.fromInterned(array_type.child), writer, pt);246 try print(Type.fromInterned(array_type.child), writer, pt);
247 }247 }
...@@ -359,7 +359,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -359,7 +359,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
359 try print(Type.fromInterned(field_ty), writer, pt);359 try print(Type.fromInterned(field_ty), writer, pt);
360360
361 if (val != .none) {361 if (val != .none) {
362 try writer.print(" = {}", .{Value.fromInterned(val).fmtValue(pt, null)});362 try writer.print(" = {}", .{Value.fromInterned(val).fmtValue(pt)});
363 }363 }
364 }364 }
365 try writer.writeAll("}");365 try writer.writeAll("}");
src/Value.zig+23-13
...@@ -40,16 +40,25 @@ pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) {...@@ -40,16 +40,25 @@ pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) {
40 return .{ .data = val };40 return .{ .data = val };
41}41}
4242
43pub fn fmtValue(val: Value, pt: Zcu.PerThread, opt_sema: ?*Sema) std.fmt.Formatter(print_value.format) {43pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.format) {
44 return .{ .data = .{44 return .{ .data = .{
45 .val = val,45 .val = val,
46 .pt = pt,46 .pt = pt,
47 .opt_sema = opt_sema,47 .opt_sema = null,
48 .depth = 3,48 .depth = 3,
49 } };49 } };
50}50}
5151
52pub fn fmtValueFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.format) {52pub fn fmtValueSema(val: Value, pt: Zcu.PerThread, sema: *Sema) std.fmt.Formatter(print_value.formatSema) {
53 return .{ .data = .{
54 .val = val,
55 .pt = pt,
56 .opt_sema = sema,
57 .depth = 3,
58 } };
59}
60
61pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.formatSema) {
53 return .{ .data = ctx };62 return .{ .data = ctx };
54}63}
5564
...@@ -4071,7 +4080,7 @@ pub const PointerDeriveStep = union(enum) {...@@ -4071,7 +4080,7 @@ pub const PointerDeriveStep = union(enum) {
4071};4080};
40724081
4073pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Allocator.Error!PointerDeriveStep {4082pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Allocator.Error!PointerDeriveStep {
4074 return ptr_val.pointerDerivationAdvanced(arena, pt, null) catch |err| switch (err) {4083 return ptr_val.pointerDerivationAdvanced(arena, pt, false, {}) catch |err| switch (err) {
4075 error.OutOfMemory => |e| return e,4084 error.OutOfMemory => |e| return e,
4076 error.AnalysisFail => unreachable,4085 error.AnalysisFail => unreachable,
4077 };4086 };
...@@ -4081,7 +4090,7 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Al...@@ -4081,7 +4090,7 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Al
4081/// only field and element pointers with no casts. This can be used by codegen backends4090/// only field and element pointers with no casts. This can be used by codegen backends
4082/// which prefer field/elem accesses when lowering constant pointer values.4091/// which prefer field/elem accesses when lowering constant pointer values.
4083/// It is also used by the Value printing logic for pointers.4092/// It is also used by the Value printing logic for pointers.
4084pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, opt_sema: ?*Sema) !PointerDeriveStep {4093pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, comptime have_sema: bool, sema: if (have_sema) *Sema else void) !PointerDeriveStep {
4085 const zcu = pt.zcu;4094 const zcu = pt.zcu;
4086 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;4095 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
4087 const base_derive: PointerDeriveStep = switch (ptr.base_addr) {4096 const base_derive: PointerDeriveStep = switch (ptr.base_addr) {
...@@ -4104,8 +4113,9 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4104,8 +4113,9 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4104 } };4113 } };
4105 },4114 },
4106 .comptime_alloc => |idx| base: {4115 .comptime_alloc => |idx| base: {
4107 const alloc = opt_sema.?.getComptimeAlloc(idx);4116 if (!have_sema) unreachable;
4108 const val = try alloc.val.intern(pt, opt_sema.?.arena);4117 const alloc = sema.getComptimeAlloc(idx);
4118 const val = try alloc.val.intern(pt, sema.arena);
4109 const ty = val.typeOf(zcu);4119 const ty = val.typeOf(zcu);
4110 break :base .{ .comptime_alloc_ptr = .{4120 break :base .{ .comptime_alloc_ptr = .{
4111 .val = val,4121 .val = val,
...@@ -4122,7 +4132,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4122,7 +4132,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4122 const base_ptr = Value.fromInterned(eu_ptr);4132 const base_ptr = Value.fromInterned(eu_ptr);
4123 const base_ptr_ty = base_ptr.typeOf(zcu);4133 const base_ptr_ty = base_ptr.typeOf(zcu);
4124 const parent_step = try arena.create(PointerDeriveStep);4134 const parent_step = try arena.create(PointerDeriveStep);
4125 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(eu_ptr), arena, pt, opt_sema);4135 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(eu_ptr), arena, pt, have_sema, sema);
4126 break :base .{ .eu_payload_ptr = .{4136 break :base .{ .eu_payload_ptr = .{
4127 .parent = parent_step,4137 .parent = parent_step,
4128 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).errorUnionPayload(zcu)),4138 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).errorUnionPayload(zcu)),
...@@ -4132,7 +4142,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4132,7 +4142,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4132 const base_ptr = Value.fromInterned(opt_ptr);4142 const base_ptr = Value.fromInterned(opt_ptr);
4133 const base_ptr_ty = base_ptr.typeOf(zcu);4143 const base_ptr_ty = base_ptr.typeOf(zcu);
4134 const parent_step = try arena.create(PointerDeriveStep);4144 const parent_step = try arena.create(PointerDeriveStep);
4135 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(opt_ptr), arena, pt, opt_sema);4145 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(opt_ptr), arena, pt, have_sema, sema);
4136 break :base .{ .opt_payload_ptr = .{4146 break :base .{ .opt_payload_ptr = .{
4137 .parent = parent_step,4147 .parent = parent_step,
4138 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).optionalChild(zcu)),4148 .result_ptr_ty = try pt.adjustPtrTypeChild(base_ptr_ty, base_ptr_ty.childType(zcu).optionalChild(zcu)),
...@@ -4143,8 +4153,8 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4143,8 +4153,8 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4143 const base_ptr_ty = base_ptr.typeOf(zcu);4153 const base_ptr_ty = base_ptr.typeOf(zcu);
4144 const agg_ty = base_ptr_ty.childType(zcu);4154 const agg_ty = base_ptr_ty.childType(zcu);
4145 const field_ty, const field_align = switch (agg_ty.zigTypeTag(zcu)) {4155 const field_ty, const field_align = switch (agg_ty.zigTypeTag(zcu)) {
4146 .Struct => .{ agg_ty.structFieldType(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, .sema) },4156 .Struct => .{ agg_ty.structFieldType(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) },
4147 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, .sema) },4157 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) },
4148 .Pointer => .{ switch (field.index) {4158 .Pointer => .{ switch (field.index) {
4149 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),4159 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),
4150 Value.slice_len_index => Type.usize,4160 Value.slice_len_index => Type.usize,
...@@ -4167,7 +4177,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4167,7 +4177,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4167 },4177 },
4168 });4178 });
4169 const parent_step = try arena.create(PointerDeriveStep);4179 const parent_step = try arena.create(PointerDeriveStep);
4170 parent_step.* = try pointerDerivationAdvanced(base_ptr, arena, pt, opt_sema);4180 parent_step.* = try pointerDerivationAdvanced(base_ptr, arena, pt, have_sema, sema);
4171 break :base .{ .field_ptr = .{4181 break :base .{ .field_ptr = .{
4172 .parent = parent_step,4182 .parent = parent_step,
4173 .field_idx = @intCast(field.index),4183 .field_idx = @intCast(field.index),
...@@ -4176,7 +4186,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4176,7 +4186,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4176 },4186 },
4177 .arr_elem => |arr_elem| base: {4187 .arr_elem => |arr_elem| base: {
4178 const parent_step = try arena.create(PointerDeriveStep);4188 const parent_step = try arena.create(PointerDeriveStep);
4179 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(arr_elem.base), arena, pt, opt_sema);4189 parent_step.* = try pointerDerivationAdvanced(Value.fromInterned(arr_elem.base), arena, pt, have_sema, sema);
4180 const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu);4190 const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu);
4181 const result_ptr_ty = try pt.ptrType(.{4191 const result_ptr_ty = try pt.ptrType(.{
4182 .child = parent_ptr_info.child,4192 .child = parent_ptr_info.child,
src/arch/x86_64/CodeGen.zig+2-2
...@@ -17975,8 +17975,8 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -17975,8 +17975,8 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1797517975
17976 break :result null;17976 break :result null;
17977 }) orelse return self.fail("TODO implement airShuffle from {} and {} to {} with {}", .{17977 }) orelse return self.fail("TODO implement airShuffle from {} and {} to {} with {}", .{
17978 lhs_ty.fmt(pt), rhs_ty.fmt(pt), dst_ty.fmt(pt),17978 lhs_ty.fmt(pt), rhs_ty.fmt(pt), dst_ty.fmt(pt),
17979 Value.fromInterned(extra.mask).fmtValue(pt, null),17979 Value.fromInterned(extra.mask).fmtValue(pt),
17980 });17980 });
17981 return self.finishAir(inst, result, .{ extra.a, extra.b, .none });17981 return self.finishAir(inst, result, .{ extra.a, extra.b, .none });
17982}17982}
src/codegen.zig+4-4
...@@ -188,7 +188,7 @@ pub fn generateSymbol(...@@ -188,7 +188,7 @@ pub fn generateSymbol(
188 const target = mod.getTarget();188 const target = mod.getTarget();
189 const endian = target.cpu.arch.endian();189 const endian = target.cpu.arch.endian();
190190
191 log.debug("generateSymbol: val = {}", .{val.fmtValue(pt, null)});191 log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)});
192192
193 if (val.isUndefDeep(mod)) {193 if (val.isUndefDeep(mod)) {
194 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;194 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
...@@ -838,7 +838,7 @@ fn genDeclRef(...@@ -838,7 +838,7 @@ fn genDeclRef(
838 const zcu = pt.zcu;838 const zcu = pt.zcu;
839 const ip = &zcu.intern_pool;839 const ip = &zcu.intern_pool;
840 const ty = val.typeOf(zcu);840 const ty = val.typeOf(zcu);
841 log.debug("genDeclRef: val = {}", .{val.fmtValue(pt, null)});841 log.debug("genDeclRef: val = {}", .{val.fmtValue(pt)});
842842
843 const ptr_decl = zcu.declPtr(ptr_decl_index);843 const ptr_decl = zcu.declPtr(ptr_decl_index);
844 const namespace = zcu.namespacePtr(ptr_decl.src_namespace);844 const namespace = zcu.namespacePtr(ptr_decl.src_namespace);
...@@ -943,7 +943,7 @@ fn genUnnamedConst(...@@ -943,7 +943,7 @@ fn genUnnamedConst(
943 owner_decl_index: InternPool.DeclIndex,943 owner_decl_index: InternPool.DeclIndex,
944) CodeGenError!GenResult {944) CodeGenError!GenResult {
945 const gpa = lf.comp.gpa;945 const gpa = lf.comp.gpa;
946 log.debug("genUnnamedConst: val = {}", .{val.fmtValue(pt, null)});946 log.debug("genUnnamedConst: val = {}", .{val.fmtValue(pt)});
947947
948 const local_sym_index = lf.lowerUnnamedConst(pt, val, owner_decl_index) catch |err| {948 const local_sym_index = lf.lowerUnnamedConst(pt, val, owner_decl_index) catch |err| {
949 return GenResult.fail(gpa, src_loc, "lowering unnamed constant failed: {s}", .{@errorName(err)});949 return GenResult.fail(gpa, src_loc, "lowering unnamed constant failed: {s}", .{@errorName(err)});
...@@ -985,7 +985,7 @@ pub fn genTypedValue(...@@ -985,7 +985,7 @@ pub fn genTypedValue(
985 const ip = &zcu.intern_pool;985 const ip = &zcu.intern_pool;
986 const ty = val.typeOf(zcu);986 const ty = val.typeOf(zcu);
987987
988 log.debug("genTypedValue: val = {}", .{val.fmtValue(pt, null)});988 log.debug("genTypedValue: val = {}", .{val.fmtValue(pt)});
989989
990 if (val.isUndef(zcu))990 if (val.isUndef(zcu))
991 return GenResult.mcv(.undef);991 return GenResult.mcv(.undef);
src/codegen/spirv.zig+1-1
...@@ -892,7 +892,7 @@ const DeclGen = struct {...@@ -892,7 +892,7 @@ const DeclGen = struct {
892 const result_ty_id = try self.resolveType(ty, repr);892 const result_ty_id = try self.resolveType(ty, repr);
893 const ip = &mod.intern_pool;893 const ip = &mod.intern_pool;
894894
895 log.debug("lowering constant: ty = {}, val = {}", .{ ty.fmt(pt), val.fmtValue(pt, null) });895 log.debug("lowering constant: ty = {}, val = {}", .{ ty.fmt(pt), val.fmtValue(pt) });
896 if (val.isUndefDeep(mod)) {896 if (val.isUndefDeep(mod)) {
897 return self.spv.constUndef(result_ty_id);897 return self.spv.constUndef(result_ty_id);
898 }898 }
src/print_air.zig+1-1
...@@ -957,7 +957,7 @@ const Writer = struct {...@@ -957,7 +957,7 @@ const Writer = struct {
957 const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf());957 const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf());
958 try s.print("<{}, {}>", .{958 try s.print("<{}, {}>", .{
959 ty.fmt(pt),959 ty.fmt(pt),
960 Value.fromInterned(ip_index).fmtValue(pt, null),960 Value.fromInterned(ip_index).fmtValue(pt),
961 });961 });
962 } else {962 } else {
963 return w.writeInstIndex(s, operand.toIndex().?, dies);963 return w.writeInstIndex(s, operand.toIndex().?, dies);
src/print_value.zig+69-35
...@@ -20,18 +20,35 @@ pub const FormatContext = struct {...@@ -20,18 +20,35 @@ pub const FormatContext = struct {
20 depth: u8,20 depth: u8,
21};21};
2222
23pub fn format(23pub fn formatSema(
24 ctx: FormatContext,24 ctx: FormatContext,
25 comptime fmt: []const u8,25 comptime fmt: []const u8,
26 options: std.fmt.FormatOptions,26 options: std.fmt.FormatOptions,
27 writer: anytype,27 writer: anytype,
28) !void {28) !void {
29 _ = options;29 _ = options;
30 const sema = ctx.opt_sema.?;
30 comptime std.debug.assert(fmt.len == 0);31 comptime std.debug.assert(fmt.len == 0);
31 return print(ctx.val, writer, ctx.depth, ctx.pt, ctx.opt_sema) catch |err| switch (err) {32 return print(ctx.val, writer, ctx.depth, ctx.pt, true, sema) catch |err| switch (err) {
32 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
33 error.ComptimeBreak, error.ComptimeReturn => unreachable,34 error.ComptimeBreak, error.ComptimeReturn => unreachable,
34 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully35 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `sema` more fully
36 else => |e| return e,
37 };
38}
39
40pub fn format(
41 ctx: FormatContext,
42 comptime fmt: []const u8,
43 options: std.fmt.FormatOptions,
44 writer: anytype,
45) !void {
46 _ = options;
47 std.debug.assert(ctx.opt_sema == null);
48 comptime std.debug.assert(fmt.len == 0);
49 return print(ctx.val, writer, ctx.depth, ctx.pt, false, {}) catch |err| switch (err) {
50 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
51 error.ComptimeBreak, error.ComptimeReturn, error.AnalysisFail => unreachable,
35 else => |e| return e,52 else => |e| return e,
36 };53 };
37}54}
...@@ -42,7 +59,8 @@ pub fn print(...@@ -42,7 +59,8 @@ pub fn print(
42 level: u8,59 level: u8,
43 pt: Zcu.PerThread,60 pt: Zcu.PerThread,
44 /// If this `Sema` is provided, we will recurse through pointers where possible to provide friendly output.61 /// If this `Sema` is provided, we will recurse through pointers where possible to provide friendly output.
45 opt_sema: ?*Sema,62 comptime have_sema: bool,
63 sema: if (have_sema) *Sema else void,
46) (@TypeOf(writer).Error || Zcu.CompileError)!void {64) (@TypeOf(writer).Error || Zcu.CompileError)!void {
47 const mod = pt.zcu;65 const mod = pt.zcu;
48 const ip = &mod.intern_pool;66 const ip = &mod.intern_pool;
...@@ -80,11 +98,11 @@ pub fn print(...@@ -80,11 +98,11 @@ pub fn print(
80 }),98 }),
81 .int => |int| switch (int.storage) {99 .int => |int| switch (int.storage) {
82 inline .u64, .i64, .big_int => |x| try writer.print("{}", .{x}),100 inline .u64, .i64, .big_int => |x| try writer.print("{}", .{x}),
83 .lazy_align => |ty| if (opt_sema != null) {101 .lazy_align => |ty| if (have_sema) {
84 const a = (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, .sema)).scalar;102 const a = (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, .sema)).scalar;
85 try writer.print("{}", .{a.toByteUnits() orelse 0});103 try writer.print("{}", .{a.toByteUnits() orelse 0});
86 } else try writer.print("@alignOf({})", .{Type.fromInterned(ty).fmt(pt)}),104 } else try writer.print("@alignOf({})", .{Type.fromInterned(ty).fmt(pt)}),
87 .lazy_size => |ty| if (opt_sema != null) {105 .lazy_size => |ty| if (have_sema) {
88 const s = (try Type.fromInterned(ty).abiSizeAdvanced(pt, .sema)).scalar;106 const s = (try Type.fromInterned(ty).abiSizeAdvanced(pt, .sema)).scalar;
89 try writer.print("{}", .{s});107 try writer.print("{}", .{s});
90 } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}),108 } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}),
...@@ -96,7 +114,7 @@ pub fn print(...@@ -96,7 +114,7 @@ pub fn print(
96 .err_name => |err_name| try writer.print("error.{}", .{114 .err_name => |err_name| try writer.print("error.{}", .{
97 err_name.fmt(ip),115 err_name.fmt(ip),
98 }),116 }),
99 .payload => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema),117 .payload => |payload| try print(Value.fromInterned(payload), writer, level, pt, have_sema, sema),
100 },118 },
101 .enum_literal => |enum_literal| try writer.print(".{}", .{119 .enum_literal => |enum_literal| try writer.print(".{}", .{
102 enum_literal.fmt(ip),120 enum_literal.fmt(ip),
...@@ -110,7 +128,7 @@ pub fn print(...@@ -110,7 +128,7 @@ pub fn print(
110 return writer.writeAll("@enumFromInt(...)");128 return writer.writeAll("@enumFromInt(...)");
111 }129 }
112 try writer.writeAll("@enumFromInt(");130 try writer.writeAll("@enumFromInt(");
113 try print(Value.fromInterned(enum_tag.int), writer, level - 1, pt, opt_sema);131 try print(Value.fromInterned(enum_tag.int), writer, level - 1, pt, have_sema, sema);
114 try writer.writeAll(")");132 try writer.writeAll(")");
115 },133 },
116 .empty_enum_value => try writer.writeAll("(empty enum value)"),134 .empty_enum_value => try writer.writeAll("(empty enum value)"),
...@@ -124,15 +142,15 @@ pub fn print(...@@ -124,15 +142,15 @@ pub fn print(
124 .decl, .int => false,142 .decl, .int => false,
125 };143 };
126 if (print_contents) {144 if (print_contents) {
127 // TODO: eventually we want to load the slice as an array with `opt_sema`, but that's145 // TODO: eventually we want to load the slice as an array with `sema`, but that's
128 // currently not possible without e.g. triggering compile errors.146 // currently not possible without e.g. triggering compile errors.
129 }147 }
130 try printPtr(Value.fromInterned(slice.ptr), writer, level, pt, opt_sema);148 try printPtr(Value.fromInterned(slice.ptr), writer, level, pt, have_sema, sema);
131 try writer.writeAll("[0..");149 try writer.writeAll("[0..");
132 if (level == 0) {150 if (level == 0) {
133 try writer.writeAll("(...)");151 try writer.writeAll("(...)");
134 } else {152 } else {
135 try print(Value.fromInterned(slice.len), writer, level - 1, pt, opt_sema);153 try print(Value.fromInterned(slice.len), writer, level - 1, pt, have_sema, sema);
136 }154 }
137 try writer.writeAll("]");155 try writer.writeAll("]");
138 },156 },
...@@ -143,16 +161,16 @@ pub fn print(...@@ -143,16 +161,16 @@ pub fn print(
143 .decl, .int => false,161 .decl, .int => false,
144 };162 };
145 if (print_contents) {163 if (print_contents) {
146 // TODO: eventually we want to load the pointer with `opt_sema`, but that's164 // TODO: eventually we want to load the pointer with `sema`, but that's
147 // currently not possible without e.g. triggering compile errors.165 // currently not possible without e.g. triggering compile errors.
148 }166 }
149 try printPtr(val, writer, level, pt, opt_sema);167 try printPtr(val, writer, level, pt, have_sema, sema);
150 },168 },
151 .opt => |opt| switch (opt.val) {169 .opt => |opt| switch (opt.val) {
152 .none => try writer.writeAll("null"),170 .none => try writer.writeAll("null"),
153 else => |payload| try print(Value.fromInterned(payload), writer, level, pt, opt_sema),171 else => |payload| try print(Value.fromInterned(payload), writer, level, pt, have_sema, sema),
154 },172 },
155 .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, pt, opt_sema),173 .aggregate => |aggregate| try printAggregate(val, aggregate, false, writer, level, pt, have_sema, sema),
156 .un => |un| {174 .un => |un| {
157 if (level == 0) {175 if (level == 0) {
158 try writer.writeAll(".{ ... }");176 try writer.writeAll(".{ ... }");
...@@ -161,13 +179,13 @@ pub fn print(...@@ -161,13 +179,13 @@ pub fn print(
161 if (un.tag == .none) {179 if (un.tag == .none) {
162 const backing_ty = try val.typeOf(mod).unionBackingType(pt);180 const backing_ty = try val.typeOf(mod).unionBackingType(pt);
163 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});181 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});
164 try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema);182 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);
165 try writer.writeAll("))");183 try writer.writeAll("))");
166 } else {184 } else {
167 try writer.writeAll(".{ ");185 try writer.writeAll(".{ ");
168 try print(Value.fromInterned(un.tag), writer, level - 1, pt, opt_sema);186 try print(Value.fromInterned(un.tag), writer, level - 1, pt, have_sema, sema);
169 try writer.writeAll(" = ");187 try writer.writeAll(" = ");
170 try print(Value.fromInterned(un.val), writer, level - 1, pt, opt_sema);188 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);
171 try writer.writeAll(" }");189 try writer.writeAll(" }");
172 }190 }
173 },191 },
...@@ -182,7 +200,8 @@ fn printAggregate(...@@ -182,7 +200,8 @@ fn printAggregate(
182 writer: anytype,200 writer: anytype,
183 level: u8,201 level: u8,
184 pt: Zcu.PerThread,202 pt: Zcu.PerThread,
185 opt_sema: ?*Sema,203 comptime have_sema: bool,
204 sema: if (have_sema) *Sema else void,
186) (@TypeOf(writer).Error || Zcu.CompileError)!void {205) (@TypeOf(writer).Error || Zcu.CompileError)!void {
187 if (level == 0) {206 if (level == 0) {
188 if (is_ref) try writer.writeByte('&');207 if (is_ref) try writer.writeByte('&');
...@@ -203,7 +222,7 @@ fn printAggregate(...@@ -203,7 +222,7 @@ fn printAggregate(
203 if (i != 0) try writer.writeAll(", ");222 if (i != 0) try writer.writeAll(", ");
204 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;223 const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?;
205 try writer.print(".{i} = ", .{field_name.fmt(ip)});224 try writer.print(".{i} = ", .{field_name.fmt(ip)});
206 try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema);225 try print(try val.fieldValue(pt, i), writer, level - 1, pt, have_sema, sema);
207 }226 }
208 try writer.writeAll(" }");227 try writer.writeAll(" }");
209 return;228 return;
...@@ -253,7 +272,7 @@ fn printAggregate(...@@ -253,7 +272,7 @@ fn printAggregate(
253 const max_len = @min(len, max_aggregate_items);272 const max_len = @min(len, max_aggregate_items);
254 for (0..max_len) |i| {273 for (0..max_len) |i| {
255 if (i != 0) try writer.writeAll(", ");274 if (i != 0) try writer.writeAll(", ");
256 try print(try val.fieldValue(pt, i), writer, level - 1, pt, opt_sema);275 try print(try val.fieldValue(pt, i), writer, level - 1, pt, have_sema, sema);
257 }276 }
258 if (len > max_aggregate_items) {277 if (len > max_aggregate_items) {
259 try writer.writeAll(", ...");278 try writer.writeAll(", ...");
...@@ -261,7 +280,14 @@ fn printAggregate(...@@ -261,7 +280,14 @@ fn printAggregate(
261 return writer.writeAll(" }");280 return writer.writeAll(" }");
262}281}
263282
264fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_sema: ?*Sema) (@TypeOf(writer).Error || Zcu.CompileError)!void {283fn printPtr(
284 ptr_val: Value,
285 writer: anytype,
286 level: u8,
287 pt: Zcu.PerThread,
288 comptime have_sema: bool,
289 sema: if (have_sema) *Sema else void,
290) (@TypeOf(writer).Error || Zcu.CompileError)!void {
265 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {291 const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
266 .undef => return writer.writeAll("undefined"),292 .undef => return writer.writeAll("undefined"),
267 .ptr => |ptr| ptr,293 .ptr => |ptr| ptr,
...@@ -278,7 +304,8 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s...@@ -278,7 +304,8 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s
278 writer,304 writer,
279 level,305 level,
280 pt,306 pt,
281 opt_sema,307 have_sema,
308 sema,
282 ),309 ),
283 else => {},310 else => {},
284 }311 }
...@@ -286,12 +313,19 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s...@@ -286,12 +313,19 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s
286313
287 var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa);314 var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa);
288 defer arena.deinit();315 defer arena.deinit();
289 const derivation = try ptr_val.pointerDerivationAdvanced(arena.allocator(), pt, opt_sema);316 const derivation = try ptr_val.pointerDerivationAdvanced(arena.allocator(), pt, have_sema, sema);
290 try printPtrDerivation(derivation, writer, level, pt, opt_sema);317 try printPtrDerivation(derivation, writer, level, pt, have_sema, sema);
291}318}
292319
293/// Print `derivation` as an lvalue, i.e. such that writing `&` before this gives the pointer value.320/// Print `derivation` as an lvalue, i.e. such that writing `&` before this gives the pointer value.
294fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, level: u8, pt: Zcu.PerThread, opt_sema: ?*Sema) (@TypeOf(writer).Error || Zcu.CompileError)!void {321fn printPtrDerivation(
322 derivation: Value.PointerDeriveStep,
323 writer: anytype,
324 level: u8,
325 pt: Zcu.PerThread,
326 comptime have_sema: bool,
327 sema: if (have_sema) *Sema else void,
328) (@TypeOf(writer).Error || Zcu.CompileError)!void {
295 const zcu = pt.zcu;329 const zcu = pt.zcu;
296 const ip = &zcu.intern_pool;330 const ip = &zcu.intern_pool;
297 switch (derivation) {331 switch (derivation) {
...@@ -305,31 +339,31 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve...@@ -305,31 +339,31 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve
305 .anon_decl_ptr => |anon| {339 .anon_decl_ptr => |anon| {
306 const ty = Value.fromInterned(anon.val).typeOf(zcu);340 const ty = Value.fromInterned(anon.val).typeOf(zcu);
307 try writer.print("@as({}, ", .{ty.fmt(pt)});341 try writer.print("@as({}, ", .{ty.fmt(pt)});
308 try print(Value.fromInterned(anon.val), writer, level - 1, pt, opt_sema);342 try print(Value.fromInterned(anon.val), writer, level - 1, pt, have_sema, sema);
309 try writer.writeByte(')');343 try writer.writeByte(')');
310 },344 },
311 .comptime_alloc_ptr => |info| {345 .comptime_alloc_ptr => |info| {
312 try writer.print("@as({}, ", .{info.val.typeOf(zcu).fmt(pt)});346 try writer.print("@as({}, ", .{info.val.typeOf(zcu).fmt(pt)});
313 try print(info.val, writer, level - 1, pt, opt_sema);347 try print(info.val, writer, level - 1, pt, have_sema, sema);
314 try writer.writeByte(')');348 try writer.writeByte(')');
315 },349 },
316 .comptime_field_ptr => |val| {350 .comptime_field_ptr => |val| {
317 const ty = val.typeOf(zcu);351 const ty = val.typeOf(zcu);
318 try writer.print("@as({}, ", .{ty.fmt(pt)});352 try writer.print("@as({}, ", .{ty.fmt(pt)});
319 try print(val, writer, level - 1, pt, opt_sema);353 try print(val, writer, level - 1, pt, have_sema, sema);
320 try writer.writeByte(')');354 try writer.writeByte(')');
321 },355 },
322 .eu_payload_ptr => |info| {356 .eu_payload_ptr => |info| {
323 try writer.writeByte('(');357 try writer.writeByte('(');
324 try printPtrDerivation(info.parent.*, writer, level, pt, opt_sema);358 try printPtrDerivation(info.parent.*, writer, level, pt, have_sema, sema);
325 try writer.writeAll(" catch unreachable)");359 try writer.writeAll(" catch unreachable)");
326 },360 },
327 .opt_payload_ptr => |info| {361 .opt_payload_ptr => |info| {
328 try printPtrDerivation(info.parent.*, writer, level, pt, opt_sema);362 try printPtrDerivation(info.parent.*, writer, level, pt, have_sema, sema);
329 try writer.writeAll(".?");363 try writer.writeAll(".?");
330 },364 },
331 .field_ptr => |field| {365 .field_ptr => |field| {
332 try printPtrDerivation(field.parent.*, writer, level, pt, opt_sema);366 try printPtrDerivation(field.parent.*, writer, level, pt, have_sema, sema);
333 const agg_ty = (try field.parent.ptrType(pt)).childType(zcu);367 const agg_ty = (try field.parent.ptrType(pt)).childType(zcu);
334 switch (agg_ty.zigTypeTag(zcu)) {368 switch (agg_ty.zigTypeTag(zcu)) {
335 .Struct => if (agg_ty.structFieldName(field.field_idx, zcu).unwrap()) |field_name| {369 .Struct => if (agg_ty.structFieldName(field.field_idx, zcu).unwrap()) |field_name| {
...@@ -351,16 +385,16 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve...@@ -351,16 +385,16 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve
351 }385 }
352 },386 },
353 .elem_ptr => |elem| {387 .elem_ptr => |elem| {
354 try printPtrDerivation(elem.parent.*, writer, level, pt, opt_sema);388 try printPtrDerivation(elem.parent.*, writer, level, pt, have_sema, sema);
355 try writer.print("[{d}]", .{elem.elem_idx});389 try writer.print("[{d}]", .{elem.elem_idx});
356 },390 },
357 .offset_and_cast => |oac| if (oac.byte_offset == 0) {391 .offset_and_cast => |oac| if (oac.byte_offset == 0) {
358 try writer.print("@as({}, @ptrCast(", .{oac.new_ptr_ty.fmt(pt)});392 try writer.print("@as({}, @ptrCast(", .{oac.new_ptr_ty.fmt(pt)});
359 try printPtrDerivation(oac.parent.*, writer, level, pt, opt_sema);393 try printPtrDerivation(oac.parent.*, writer, level, pt, have_sema, sema);
360 try writer.writeAll("))");394 try writer.writeAll("))");
361 } else {395 } else {
362 try writer.print("@as({}, @ptrFromInt(@intFromPtr(", .{oac.new_ptr_ty.fmt(pt)});396 try writer.print("@as({}, @ptrFromInt(@intFromPtr(", .{oac.new_ptr_ty.fmt(pt)});
363 try printPtrDerivation(oac.parent.*, writer, level, pt, opt_sema);397 try printPtrDerivation(oac.parent.*, writer, level, pt, have_sema, sema);
364 try writer.print(") + {d}))", .{oac.byte_offset});398 try writer.print(") + {d}))", .{oac.byte_offset});
365 },399 },
366 }400 }