| author | |
| committer | |
| log | f84a4953d29ffc2bdc94fa353cac685430e6bbe4 |
| tree | 9e7e0c705451b464979cb8330e6b87de67ae1085 |
| parent | 67cd14dbdbf2ce435a2bd81dc82d167b99fad6e3 |
| signature |
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 | 2318 | if (int_ty.zigTypeTag(zcu) == .Vector) { |
| 2319 | 2319 | const msg = msg: { |
| 2320 | 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 | 2323 | errdefer msg.destroy(sema.gpa); |
| 2324 | 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 | 2327 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2328 | 2328 | } |
| 2329 | 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 | } |
| 2333 | 2333 | |
| ... | ... | @@ -2912,7 +2912,7 @@ fn createAnonymousDeclTypeNamed( |
| 2912 | 2912 | // in turn helps to avoid unreasonably long symbol names for namespaced |
| 2913 | 2913 | // symbols. Such names should ideally be human-readable, and additionally, |
| 2914 | 2914 | // some tooling may not support very long symbol names. |
| 2915 | try writer.print("{}", .{Value.fmtValueFull(.{ | |
| 2915 | try writer.print("{}", .{Value.fmtValueSemaFull(.{ | |
| 2916 | 2916 | .val = arg_val, |
| 2917 | 2917 | .pt = pt, |
| 2918 | 2918 | .opt_sema = sema, |
| ... | ... | @@ -3202,7 +3202,7 @@ fn zirEnumDecl( |
| 3202 | 3202 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3203 | 3203 | }; |
| 3204 | 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 | 3206 | errdefer msg.destroy(gpa); |
| 3207 | 3207 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3208 | 3208 | break :msg msg; |
| ... | ... | @@ -3224,7 +3224,7 @@ fn zirEnumDecl( |
| 3224 | 3224 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3225 | 3225 | }; |
| 3226 | 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 | 3228 | errdefer msg.destroy(gpa); |
| 3229 | 3229 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3230 | 3230 | break :msg msg; |
| ... | ... | @@ -3242,7 +3242,7 @@ fn zirEnumDecl( |
| 3242 | 3242 | |
| 3243 | 3243 | if (tag_overflow) { |
| 3244 | 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 | 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 | 4430 | .input_index = len_idx, |
| 4431 | 4431 | } }); |
| 4432 | 4432 | try sema.errNote(a_src, msg, "length {} here", .{ |
| 4433 | v.fmtValue(pt, sema), | |
| 4433 | v.fmtValueSema(pt, sema), | |
| 4434 | 4434 | }); |
| 4435 | 4435 | try sema.errNote(arg_src, msg, "length {} here", .{ |
| 4436 | arg_val.fmtValue(pt, sema), | |
| 4436 | arg_val.fmtValueSema(pt, sema), | |
| 4437 | 4437 | }); |
| 4438 | 4438 | break :msg msg; |
| 4439 | 4439 | }; |
| ... | ... | @@ -5853,7 +5853,7 @@ fn zirCompileLog( |
| 5853 | 5853 | const arg_ty = sema.typeOf(arg); |
| 5854 | 5854 | if (try sema.resolveValueResolveLazy(arg)) |val| { |
| 5855 | 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 | 5858 | } else { |
| 5859 | 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 | 8949 | return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern()); |
| 8950 | 8950 | } |
| 8951 | 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 | 8955 | if (int_val.isUndef(mod)) { |
| ... | ... | @@ -8957,7 +8957,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8957 | 8957 | } |
| 8958 | 8958 | if (!(try sema.enumHasInt(dest_ty, int_val))) { |
| 8959 | 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 | 8963 | return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern()); |
| ... | ... | @@ -14067,7 +14067,7 @@ fn zirShl( |
| 14067 | 14067 | const rhs_elem = try rhs_val.elemValue(pt, i); |
| 14068 | 14068 | if (rhs_elem.compareHetero(.gte, bit_value, pt)) { |
| 14069 | 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 | 14071 | i, |
| 14072 | 14072 | scalar_ty.fmt(pt), |
| 14073 | 14073 | }); |
| ... | ... | @@ -14075,7 +14075,7 @@ fn zirShl( |
| 14075 | 14075 | } |
| 14076 | 14076 | } else if (rhs_val.compareHetero(.gte, bit_value, pt)) { |
| 14077 | 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 | 14079 | scalar_ty.fmt(pt), |
| 14080 | 14080 | }); |
| 14081 | 14081 | } |
| ... | ... | @@ -14086,14 +14086,14 @@ fn zirShl( |
| 14086 | 14086 | const rhs_elem = try rhs_val.elemValue(pt, i); |
| 14087 | 14087 | if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), pt)) { |
| 14088 | 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 | 14090 | i, |
| 14091 | 14091 | }); |
| 14092 | 14092 | } |
| 14093 | 14093 | } |
| 14094 | 14094 | } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) { |
| 14095 | 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 | 14233 | const rhs_elem = try rhs_val.elemValue(pt, i); |
| 14234 | 14234 | if (rhs_elem.compareHetero(.gte, bit_value, pt)) { |
| 14235 | 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 | 14237 | i, |
| 14238 | 14238 | scalar_ty.fmt(pt), |
| 14239 | 14239 | }); |
| ... | ... | @@ -14241,7 +14241,7 @@ fn zirShr( |
| 14241 | 14241 | } |
| 14242 | 14242 | } else if (rhs_val.compareHetero(.gte, bit_value, pt)) { |
| 14243 | 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 | 14245 | scalar_ty.fmt(pt), |
| 14246 | 14246 | }); |
| 14247 | 14247 | } |
| ... | ... | @@ -14252,14 +14252,14 @@ fn zirShr( |
| 14252 | 14252 | const rhs_elem = try rhs_val.elemValue(pt, i); |
| 14253 | 14253 | if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(mod), 0), pt)) { |
| 14254 | 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 | 14256 | i, |
| 14257 | 14257 | }); |
| 14258 | 14258 | } |
| 14259 | 14259 | } |
| 14260 | 14260 | } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) { |
| 14261 | 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 | 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 | 15190 | block, |
| 15191 | 15191 | src, |
| 15192 | 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 | 21359 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| 21360 | 21360 | const msg = msg: { |
| 21361 | 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 | 21364 | errdefer msg.destroy(sema.gpa); |
| 21365 | 21365 | try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{}); |
| ... | ... | @@ -22005,7 +22005,7 @@ fn reifyEnum( |
| 22005 | 22005 | // TODO: better source location |
| 22006 | 22006 | return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{ |
| 22007 | 22007 | field_name.fmt(ip), |
| 22008 | field_value_val.fmtValue(pt, sema), | |
| 22008 | field_value_val.fmtValueSema(pt, sema), | |
| 22009 | 22009 | tag_ty.fmt(pt), |
| 22010 | 22010 | }); |
| 22011 | 22011 | } |
| ... | ... | @@ -22021,7 +22021,7 @@ fn reifyEnum( |
| 22021 | 22021 | break :msg msg; |
| 22022 | 22022 | }, |
| 22023 | 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 | 22025 | errdefer msg.destroy(gpa); |
| 22026 | 22026 | _ = conflict.prev_field_idx; // TODO: this note is incorrect |
| 22027 | 22027 | try sema.errNote(src, msg, "other enum tag value here", .{}); |
| ... | ... | @@ -23193,12 +23193,12 @@ fn ptrCastFull( |
| 23193 | 23193 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23194 | 23194 | const msg = if (src_info.sentinel == .none) blk: { |
| 23195 | 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 | 23198 | } else blk: { |
| 23199 | 23199 | break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ |
| 23200 | Value.fromInterned(src_info.sentinel).fmtValue(pt, sema), | |
| 23201 | Value.fromInterned(dest_info.sentinel).fmtValue(pt, sema), | |
| 23200 | Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema), | |
| 23201 | Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema), | |
| 23202 | 23202 | }); |
| 23203 | 23203 | }; |
| 23204 | 23204 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -25691,10 +25691,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25691 | 25691 | const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{}); |
| 25692 | 25692 | errdefer msg.destroy(sema.gpa); |
| 25693 | 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 | 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 | 25699 | break :msg msg; |
| 25700 | 25700 | }; |
| ... | ... | @@ -29560,7 +29560,7 @@ fn coerceExtra( |
| 29560 | 29560 | // comptime-known integer to other number |
| 29561 | 29561 | if (!(try sema.intFitsInType(val, dest_ty, null))) { |
| 29562 | 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 | 29565 | return switch (zcu.intern_pool.indexToKey(val.toIntern())) { |
| 29566 | 29566 | .undef => try pt.undefRef(dest_ty), |
| ... | ... | @@ -29605,7 +29605,7 @@ fn coerceExtra( |
| 29605 | 29605 | block, |
| 29606 | 29606 | inst_src, |
| 29607 | 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 | 29611 | return Air.internedToRef(result_val.toIntern()); |
| ... | ... | @@ -30003,11 +30003,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30003 | 30003 | .array_sentinel => |sentinel| { |
| 30004 | 30004 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 30005 | 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 | 30008 | } else { |
| 30009 | 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 | 30013 | break; |
| ... | ... | @@ -30129,11 +30129,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30129 | 30129 | .ptr_sentinel => |sentinel| { |
| 30130 | 30130 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 30131 | 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 | 30134 | } else { |
| 30135 | 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 | 30139 | break; |
| ... | ... | @@ -31379,7 +31379,7 @@ fn coerceEnumToUnion( |
| 31379 | 31379 | if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| { |
| 31380 | 31380 | const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse { |
| 31381 | 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 | }; |
| 31385 | 31385 | |
| ... | ... | @@ -32611,8 +32611,8 @@ fn analyzeSlice( |
| 32611 | 32611 | msg, |
| 32612 | 32612 | "expected '{}', found '{}'", |
| 32613 | 32613 | .{ |
| 32614 | Value.zero_comptime_int.fmtValue(pt, sema), | |
| 32615 | start_value.fmtValue(pt, sema), | |
| 32614 | Value.zero_comptime_int.fmtValueSema(pt, sema), | |
| 32615 | start_value.fmtValueSema(pt, sema), | |
| 32616 | 32616 | }, |
| 32617 | 32617 | ); |
| 32618 | 32618 | break :msg msg; |
| ... | ... | @@ -32627,8 +32627,8 @@ fn analyzeSlice( |
| 32627 | 32627 | msg, |
| 32628 | 32628 | "expected '{}', found '{}'", |
| 32629 | 32629 | .{ |
| 32630 | Value.one_comptime_int.fmtValue(pt, sema), | |
| 32631 | end_value.fmtValue(pt, sema), | |
| 32630 | Value.one_comptime_int.fmtValueSema(pt, sema), | |
| 32631 | end_value.fmtValueSema(pt, sema), | |
| 32632 | 32632 | }, |
| 32633 | 32633 | ); |
| 32634 | 32634 | break :msg msg; |
| ... | ... | @@ -32641,7 +32641,7 @@ fn analyzeSlice( |
| 32641 | 32641 | block, |
| 32642 | 32642 | end_src, |
| 32643 | 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 | 32736 | end_src, |
| 32737 | 32737 | "end index {} out of bounds for array of length {}{s}", |
| 32738 | 32738 | .{ |
| 32739 | end_val.fmtValue(pt, sema), | |
| 32740 | len_val.fmtValue(pt, sema), | |
| 32739 | end_val.fmtValueSema(pt, sema), | |
| 32740 | len_val.fmtValueSema(pt, sema), | |
| 32741 | 32741 | sentinel_label, |
| 32742 | 32742 | }, |
| 32743 | 32743 | ); |
| ... | ... | @@ -32781,7 +32781,7 @@ fn analyzeSlice( |
| 32781 | 32781 | end_src, |
| 32782 | 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 | 32785 | try slice_val.sliceLen(pt), |
| 32786 | 32786 | sentinel_label, |
| 32787 | 32787 | }, |
| ... | ... | @@ -32841,8 +32841,8 @@ fn analyzeSlice( |
| 32841 | 32841 | start_src, |
| 32842 | 32842 | "start index {} is larger than end index {}", |
| 32843 | 32843 | .{ |
| 32844 | start_val.fmtValue(pt, sema), | |
| 32845 | end_val.fmtValue(pt, sema), | |
| 32844 | start_val.fmtValueSema(pt, sema), | |
| 32845 | end_val.fmtValueSema(pt, sema), | |
| 32846 | 32846 | }, |
| 32847 | 32847 | ); |
| 32848 | 32848 | } |
| ... | ... | @@ -32879,8 +32879,8 @@ fn analyzeSlice( |
| 32879 | 32879 | const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); |
| 32880 | 32880 | errdefer msg.destroy(sema.gpa); |
| 32881 | 32881 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ |
| 32882 | expected_sentinel.fmtValue(pt, sema), | |
| 32883 | actual_sentinel.fmtValue(pt, sema), | |
| 32882 | expected_sentinel.fmtValueSema(pt, sema), | |
| 32883 | actual_sentinel.fmtValueSema(pt, sema), | |
| 32884 | 32884 | }); |
| 32885 | 32885 | |
| 32886 | 32886 | break :msg msg; |
| ... | ... | @@ -36623,7 +36623,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L |
| 36623 | 36623 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| 36624 | 36624 | }; |
| 36625 | 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 | 36627 | errdefer msg.destroy(gpa); |
| 36628 | 36628 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); |
| 36629 | 36629 | break :msg msg; |
| ... | ... | @@ -37855,7 +37855,7 @@ fn intFromFloatScalar( |
| 37855 | 37855 | block, |
| 37856 | 37856 | src, |
| 37857 | 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 | ); |
| 37860 | 37860 | |
| 37861 | 37861 | const float = val.toFloat(f128, pt); |
| ... | ... | @@ -37877,7 +37877,7 @@ fn intFromFloatScalar( |
| 37877 | 37877 | |
| 37878 | 37878 | if (!(try sema.intFitsInType(cti_result, int_ty, null))) { |
| 37879 | 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 | 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 | 194 | |
| 195 | 195 | if (info.sentinel != .none) switch (info.flags.size) { |
| 196 | 196 | .One, .C => unreachable, |
| 197 | .Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(pt, null)}), | |
| 198 | .Slice => 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)}), | |
| 199 | 199 | } else switch (info.flags.size) { |
| 200 | 200 | .One => try writer.writeAll("*"), |
| 201 | 201 | .Many => try writer.writeAll("[*]"), |
| ... | ... | @@ -241,7 +241,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error |
| 241 | 241 | } else { |
| 242 | 242 | try writer.print("[{d}:{}]", .{ |
| 243 | 243 | array_type.len, |
| 244 | Value.fromInterned(array_type.sentinel).fmtValue(pt, null), | |
| 244 | Value.fromInterned(array_type.sentinel).fmtValue(pt), | |
| 245 | 245 | }); |
| 246 | 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 | 359 | try print(Type.fromInterned(field_ty), writer, pt); |
| 360 | 360 | |
| 361 | 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 | 365 | try writer.writeAll("}"); |
src/Value.zig+23-13| ... | ... | @@ -40,16 +40,25 @@ pub fn fmtDebug(val: Value) std.fmt.Formatter(dump) { |
| 40 | 40 | return .{ .data = val }; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | pub fn fmtValue(val: Value, pt: Zcu.PerThread, opt_sema: ?*Sema) std.fmt.Formatter(print_value.format) { | |
| 43 | pub fn fmtValue(val: Value, pt: Zcu.PerThread) std.fmt.Formatter(print_value.format) { | |
| 44 | 44 | return .{ .data = .{ |
| 45 | 45 | .val = val, |
| 46 | 46 | .pt = pt, |
| 47 | .opt_sema = opt_sema, | |
| 47 | .opt_sema = null, | |
| 48 | 48 | .depth = 3, |
| 49 | 49 | } }; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | pub fn fmtValueFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.format) { | |
| 52 | pub 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 | ||
| 61 | pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_value.formatSema) { | |
| 53 | 62 | return .{ .data = ctx }; |
| 54 | 63 | } |
| 55 | 64 | |
| ... | ... | @@ -4071,7 +4080,7 @@ pub const PointerDeriveStep = union(enum) { |
| 4071 | 4080 | }; |
| 4072 | 4081 | |
| 4073 | 4082 | pub 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 | 4084 | error.OutOfMemory => |e| return e, |
| 4076 | 4085 | error.AnalysisFail => unreachable, |
| 4077 | 4086 | }; |
| ... | ... | @@ -4081,7 +4090,7 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Al |
| 4081 | 4090 | /// only field and element pointers with no casts. This can be used by codegen backends |
| 4082 | 4091 | /// which prefer field/elem accesses when lowering constant pointer values. |
| 4083 | 4092 | /// It is also used by the Value printing logic for pointers. |
| 4084 | pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, opt_sema: ?*Sema) !PointerDeriveStep { | |
| 4093 | pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread, comptime have_sema: bool, sema: if (have_sema) *Sema else void) !PointerDeriveStep { | |
| 4085 | 4094 | const zcu = pt.zcu; |
| 4086 | 4095 | const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr; |
| 4087 | 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 | 4113 | } }; |
| 4105 | 4114 | }, |
| 4106 | 4115 | .comptime_alloc => |idx| base: { |
| 4107 | const alloc = opt_sema.?.getComptimeAlloc(idx); | |
| 4108 | const val = try alloc.val.intern(pt, opt_sema.?.arena); | |
| 4116 | if (!have_sema) unreachable; | |
| 4117 | const alloc = sema.getComptimeAlloc(idx); | |
| 4118 | const val = try alloc.val.intern(pt, sema.arena); | |
| 4109 | 4119 | const ty = val.typeOf(zcu); |
| 4110 | 4120 | break :base .{ .comptime_alloc_ptr = .{ |
| 4111 | 4121 | .val = val, |
| ... | ... | @@ -4122,7 +4132,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh |
| 4122 | 4132 | const base_ptr = Value.fromInterned(eu_ptr); |
| 4123 | 4133 | const base_ptr_ty = base_ptr.typeOf(zcu); |
| 4124 | 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 | 4136 | break :base .{ .eu_payload_ptr = .{ |
| 4127 | 4137 | .parent = parent_step, |
| 4128 | 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 | 4142 | const base_ptr = Value.fromInterned(opt_ptr); |
| 4133 | 4143 | const base_ptr_ty = base_ptr.typeOf(zcu); |
| 4134 | 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 | 4146 | break :base .{ .opt_payload_ptr = .{ |
| 4137 | 4147 | .parent = parent_step, |
| 4138 | 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 | 4153 | const base_ptr_ty = base_ptr.typeOf(zcu); |
| 4144 | 4154 | const agg_ty = base_ptr_ty.childType(zcu); |
| 4145 | 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) }, | |
| 4147 | .Union => .{ agg_ty.unionFieldTypeByIndex(@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) }, | |
| 4157 | .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) }, | |
| 4148 | 4158 | .Pointer => .{ switch (field.index) { |
| 4149 | 4159 | Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu), |
| 4150 | 4160 | Value.slice_len_index => Type.usize, |
| ... | ... | @@ -4167,7 +4177,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh |
| 4167 | 4177 | }, |
| 4168 | 4178 | }); |
| 4169 | 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 | 4181 | break :base .{ .field_ptr = .{ |
| 4172 | 4182 | .parent = parent_step, |
| 4173 | 4183 | .field_idx = @intCast(field.index), |
| ... | ... | @@ -4176,7 +4186,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh |
| 4176 | 4186 | }, |
| 4177 | 4187 | .arr_elem => |arr_elem| base: { |
| 4178 | 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 | 4190 | const parent_ptr_info = (try parent_step.ptrType(pt)).ptrInfo(zcu); |
| 4181 | 4191 | const result_ptr_ty = try pt.ptrType(.{ |
| 4182 | 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 | 17975 | |
| 17976 | 17976 | break :result null; |
| 17977 | 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), | |
| 17979 | Value.fromInterned(extra.mask).fmtValue(pt, null), | |
| 17978 | lhs_ty.fmt(pt), rhs_ty.fmt(pt), dst_ty.fmt(pt), | |
| 17979 | Value.fromInterned(extra.mask).fmtValue(pt), | |
| 17980 | 17980 | }); |
| 17981 | 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 | 188 | const target = mod.getTarget(); |
| 189 | 189 | const endian = target.cpu.arch.endian(); |
| 190 | 190 | |
| 191 | log.debug("generateSymbol: val = {}", .{val.fmtValue(pt, null)}); | |
| 191 | log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)}); | |
| 192 | 192 | |
| 193 | 193 | if (val.isUndefDeep(mod)) { |
| 194 | 194 | const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow; |
| ... | ... | @@ -838,7 +838,7 @@ fn genDeclRef( |
| 838 | 838 | const zcu = pt.zcu; |
| 839 | 839 | const ip = &zcu.intern_pool; |
| 840 | 840 | const ty = val.typeOf(zcu); |
| 841 | log.debug("genDeclRef: val = {}", .{val.fmtValue(pt, null)}); | |
| 841 | log.debug("genDeclRef: val = {}", .{val.fmtValue(pt)}); | |
| 842 | 842 | |
| 843 | 843 | const ptr_decl = zcu.declPtr(ptr_decl_index); |
| 844 | 844 | const namespace = zcu.namespacePtr(ptr_decl.src_namespace); |
| ... | ... | @@ -943,7 +943,7 @@ fn genUnnamedConst( |
| 943 | 943 | owner_decl_index: InternPool.DeclIndex, |
| 944 | 944 | ) CodeGenError!GenResult { |
| 945 | 945 | const gpa = lf.comp.gpa; |
| 946 | log.debug("genUnnamedConst: val = {}", .{val.fmtValue(pt, null)}); | |
| 946 | log.debug("genUnnamedConst: val = {}", .{val.fmtValue(pt)}); | |
| 947 | 947 | |
| 948 | 948 | const local_sym_index = lf.lowerUnnamedConst(pt, val, owner_decl_index) catch |err| { |
| 949 | 949 | return GenResult.fail(gpa, src_loc, "lowering unnamed constant failed: {s}", .{@errorName(err)}); |
| ... | ... | @@ -985,7 +985,7 @@ pub fn genTypedValue( |
| 985 | 985 | const ip = &zcu.intern_pool; |
| 986 | 986 | const ty = val.typeOf(zcu); |
| 987 | 987 | |
| 988 | log.debug("genTypedValue: val = {}", .{val.fmtValue(pt, null)}); | |
| 988 | log.debug("genTypedValue: val = {}", .{val.fmtValue(pt)}); | |
| 989 | 989 | |
| 990 | 990 | if (val.isUndef(zcu)) |
| 991 | 991 | return GenResult.mcv(.undef); |
src/codegen/spirv.zig+1-1| ... | ... | @@ -892,7 +892,7 @@ const DeclGen = struct { |
| 892 | 892 | const result_ty_id = try self.resolveType(ty, repr); |
| 893 | 893 | const ip = &mod.intern_pool; |
| 894 | 894 | |
| 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 | 896 | if (val.isUndefDeep(mod)) { |
| 897 | 897 | return self.spv.constUndef(result_ty_id); |
| 898 | 898 | } |
src/print_air.zig+1-1| ... | ... | @@ -957,7 +957,7 @@ const Writer = struct { |
| 957 | 957 | const ty = Type.fromInterned(pt.zcu.intern_pool.indexToKey(ip_index).typeOf()); |
| 958 | 958 | try s.print("<{}, {}>", .{ |
| 959 | 959 | ty.fmt(pt), |
| 960 | Value.fromInterned(ip_index).fmtValue(pt, null), | |
| 960 | Value.fromInterned(ip_index).fmtValue(pt), | |
| 961 | 961 | }); |
| 962 | 962 | } else { |
| 963 | 963 | return w.writeInstIndex(s, operand.toIndex().?, dies); |
src/print_value.zig+69-35| ... | ... | @@ -20,18 +20,35 @@ pub const FormatContext = struct { |
| 20 | 20 | depth: u8, |
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | pub fn format( | |
| 23 | pub fn formatSema( | |
| 24 | 24 | ctx: FormatContext, |
| 25 | 25 | comptime fmt: []const u8, |
| 26 | 26 | options: std.fmt.FormatOptions, |
| 27 | 27 | writer: anytype, |
| 28 | 28 | ) !void { |
| 29 | 29 | _ = options; |
| 30 | const sema = ctx.opt_sema.?; | |
| 30 | 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 | 33 | error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function |
| 33 | 34 | error.ComptimeBreak, error.ComptimeReturn => unreachable, |
| 34 | error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully | |
| 35 | error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `sema` more fully | |
| 36 | else => |e| return e, | |
| 37 | }; | |
| 38 | } | |
| 39 | ||
| 40 | pub 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 | 52 | else => |e| return e, |
| 36 | 53 | }; |
| 37 | 54 | } |
| ... | ... | @@ -42,7 +59,8 @@ pub fn print( |
| 42 | 59 | level: u8, |
| 43 | 60 | pt: Zcu.PerThread, |
| 44 | 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 | 64 | ) (@TypeOf(writer).Error || Zcu.CompileError)!void { |
| 47 | 65 | const mod = pt.zcu; |
| 48 | 66 | const ip = &mod.intern_pool; |
| ... | ... | @@ -80,11 +98,11 @@ pub fn print( |
| 80 | 98 | }), |
| 81 | 99 | .int => |int| switch (int.storage) { |
| 82 | 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 | 102 | const a = (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, .sema)).scalar; |
| 85 | 103 | try writer.print("{}", .{a.toByteUnits() orelse 0}); |
| 86 | 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 | 106 | const s = (try Type.fromInterned(ty).abiSizeAdvanced(pt, .sema)).scalar; |
| 89 | 107 | try writer.print("{}", .{s}); |
| 90 | 108 | } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}), |
| ... | ... | @@ -96,7 +114,7 @@ pub fn print( |
| 96 | 114 | .err_name => |err_name| try writer.print("error.{}", .{ |
| 97 | 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 | 119 | .enum_literal => |enum_literal| try writer.print(".{}", .{ |
| 102 | 120 | enum_literal.fmt(ip), |
| ... | ... | @@ -110,7 +128,7 @@ pub fn print( |
| 110 | 128 | return writer.writeAll("@enumFromInt(...)"); |
| 111 | 129 | } |
| 112 | 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 | 132 | try writer.writeAll(")"); |
| 115 | 133 | }, |
| 116 | 134 | .empty_enum_value => try writer.writeAll("(empty enum value)"), |
| ... | ... | @@ -124,15 +142,15 @@ pub fn print( |
| 124 | 142 | .decl, .int => false, |
| 125 | 143 | }; |
| 126 | 144 | if (print_contents) { |
| 127 | // TODO: eventually we want to load the slice as an array with `opt_sema`, but that's | |
| 145 | // TODO: eventually we want to load the slice as an array with `sema`, but that's | |
| 128 | 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 | 149 | try writer.writeAll("[0.."); |
| 132 | 150 | if (level == 0) { |
| 133 | 151 | try writer.writeAll("(...)"); |
| 134 | 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 | 155 | try writer.writeAll("]"); |
| 138 | 156 | }, |
| ... | ... | @@ -143,16 +161,16 @@ pub fn print( |
| 143 | 161 | .decl, .int => false, |
| 144 | 162 | }; |
| 145 | 163 | if (print_contents) { |
| 146 | // TODO: eventually we want to load the pointer with `opt_sema`, but that's | |
| 164 | // TODO: eventually we want to load the pointer with `sema`, but that's | |
| 147 | 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 | 169 | .opt => |opt| switch (opt.val) { |
| 152 | 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 | 174 | .un => |un| { |
| 157 | 175 | if (level == 0) { |
| 158 | 176 | try writer.writeAll(".{ ... }"); |
| ... | ... | @@ -161,13 +179,13 @@ pub fn print( |
| 161 | 179 | if (un.tag == .none) { |
| 162 | 180 | const backing_ty = try val.typeOf(mod).unionBackingType(pt); |
| 163 | 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 | 183 | try writer.writeAll("))"); |
| 166 | 184 | } else { |
| 167 | 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 | 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 | 189 | try writer.writeAll(" }"); |
| 172 | 190 | } |
| 173 | 191 | }, |
| ... | ... | @@ -182,7 +200,8 @@ fn printAggregate( |
| 182 | 200 | writer: anytype, |
| 183 | 201 | level: u8, |
| 184 | 202 | pt: Zcu.PerThread, |
| 185 | opt_sema: ?*Sema, | |
| 203 | comptime have_sema: bool, | |
| 204 | sema: if (have_sema) *Sema else void, | |
| 186 | 205 | ) (@TypeOf(writer).Error || Zcu.CompileError)!void { |
| 187 | 206 | if (level == 0) { |
| 188 | 207 | if (is_ref) try writer.writeByte('&'); |
| ... | ... | @@ -203,7 +222,7 @@ fn printAggregate( |
| 203 | 222 | if (i != 0) try writer.writeAll(", "); |
| 204 | 223 | const field_name = ty.structFieldName(@intCast(i), zcu).unwrap().?; |
| 205 | 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 | 227 | try writer.writeAll(" }"); |
| 209 | 228 | return; |
| ... | ... | @@ -253,7 +272,7 @@ fn printAggregate( |
| 253 | 272 | const max_len = @min(len, max_aggregate_items); |
| 254 | 273 | for (0..max_len) |i| { |
| 255 | 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 | 277 | if (len > max_aggregate_items) { |
| 259 | 278 | try writer.writeAll(", ..."); |
| ... | ... | @@ -261,7 +280,14 @@ fn printAggregate( |
| 261 | 280 | return writer.writeAll(" }"); |
| 262 | 281 | } |
| 263 | 282 | |
| 264 | fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_sema: ?*Sema) (@TypeOf(writer).Error || Zcu.CompileError)!void { | |
| 283 | fn 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 | 291 | const ptr = switch (pt.zcu.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 266 | 292 | .undef => return writer.writeAll("undefined"), |
| 267 | 293 | .ptr => |ptr| ptr, |
| ... | ... | @@ -278,7 +304,8 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s |
| 278 | 304 | writer, |
| 279 | 305 | level, |
| 280 | 306 | pt, |
| 281 | opt_sema, | |
| 307 | have_sema, | |
| 308 | sema, | |
| 282 | 309 | ), |
| 283 | 310 | else => {}, |
| 284 | 311 | } |
| ... | ... | @@ -286,12 +313,19 @@ fn printPtr(ptr_val: Value, writer: anytype, level: u8, pt: Zcu.PerThread, opt_s |
| 286 | 313 | |
| 287 | 314 | var arena = std.heap.ArenaAllocator.init(pt.zcu.gpa); |
| 288 | 315 | defer arena.deinit(); |
| 289 | const derivation = try ptr_val.pointerDerivationAdvanced(arena.allocator(), pt, opt_sema); | |
| 290 | try printPtrDerivation(derivation, writer, level, pt, opt_sema); | |
| 316 | const derivation = try ptr_val.pointerDerivationAdvanced(arena.allocator(), pt, have_sema, sema); | |
| 317 | try printPtrDerivation(derivation, writer, level, pt, have_sema, sema); | |
| 291 | 318 | } |
| 292 | 319 | |
| 293 | 320 | /// Print `derivation` as an lvalue, i.e. such that writing `&` before this gives the pointer value. |
| 294 | fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, level: u8, pt: Zcu.PerThread, opt_sema: ?*Sema) (@TypeOf(writer).Error || Zcu.CompileError)!void { | |
| 321 | fn 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 | 329 | const zcu = pt.zcu; |
| 296 | 330 | const ip = &zcu.intern_pool; |
| 297 | 331 | switch (derivation) { |
| ... | ... | @@ -305,31 +339,31 @@ fn printPtrDerivation(derivation: Value.PointerDeriveStep, writer: anytype, leve |
| 305 | 339 | .anon_decl_ptr => |anon| { |
| 306 | 340 | const ty = Value.fromInterned(anon.val).typeOf(zcu); |
| 307 | 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 | 343 | try writer.writeByte(')'); |
| 310 | 344 | }, |
| 311 | 345 | .comptime_alloc_ptr => |info| { |
| 312 | 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 | 348 | try writer.writeByte(')'); |
| 315 | 349 | }, |
| 316 | 350 | .comptime_field_ptr => |val| { |
| 317 | 351 | const ty = val.typeOf(zcu); |
| 318 | 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 | 354 | try writer.writeByte(')'); |
| 321 | 355 | }, |
| 322 | 356 | .eu_payload_ptr => |info| { |
| 323 | 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 | 359 | try writer.writeAll(" catch unreachable)"); |
| 326 | 360 | }, |
| 327 | 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 | 363 | try writer.writeAll(".?"); |
| 330 | 364 | }, |
| 331 | 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 | 367 | const agg_ty = (try field.parent.ptrType(pt)).childType(zcu); |
| 334 | 368 | switch (agg_ty.zigTypeTag(zcu)) { |
| 335 | 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 | 385 | } |
| 352 | 386 | }, |
| 353 | 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 | 389 | try writer.print("[{d}]", .{elem.elem_idx}); |
| 356 | 390 | }, |
| 357 | 391 | .offset_and_cast => |oac| if (oac.byte_offset == 0) { |
| 358 | 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 | 394 | try writer.writeAll("))"); |
| 361 | 395 | } else { |
| 362 | 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 | 398 | try writer.print(") + {d}))", .{oac.byte_offset}); |
| 365 | 399 | }, |
| 366 | 400 | } |