| author | |
| committer | |
| log | ee695c8ef40ae7cecb4b9a77c8a6dcbe53d4f013 |
| tree | 91fbc76758cd5b2630c0f7f846e1b5fc7146369b |
| parent | a58ceb3d554a9565a6cc0443f6384149ae2b3145 |
| parent | f84a4953d29ffc2bdc94fa353cac685430e6bbe4 |
| signature |
Type,Value: mark `ResolveStrat` parameter of type queries as `comptime`9 files changed, 183 insertions(+), 135 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 | } |
| 2333 | 2333 | ||
| ... | @@ -2912,7 +2912,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2912,7 +2912,7 @@ fn createAnonymousDeclTypeNamed( |
| 2912 | // in turn helps to avoid unreasonably long symbol names for namespaced | 2912 | // 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( |
| 3242 | 3242 | ||
| 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 location | 22005 | // 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 incorrect | 22026 | _ = 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", .{}); |
| ... | @@ -23194,12 +23194,12 @@ fn ptrCastFull( | ... | @@ -23194,12 +23194,12 @@ fn ptrCastFull( |
| 23194 | return sema.failWithOwnedErrorMsg(block, msg: { | 23194 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23195 | const msg = if (src_info.sentinel == .none) blk: { | 23195 | const msg = if (src_info.sentinel == .none) blk: { |
| 23196 | break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{ | 23196 | break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{ |
| 23197 | Value.fromInterned(dest_info.sentinel).fmtValue(pt, sema), | 23197 | Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema), |
| 23198 | }); | 23198 | }); |
| 23199 | } else blk: { | 23199 | } else blk: { |
| 23200 | break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ | 23200 | break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ |
| 23201 | Value.fromInterned(src_info.sentinel).fmtValue(pt, sema), | 23201 | Value.fromInterned(src_info.sentinel).fmtValueSema(pt, sema), |
| 23202 | Value.fromInterned(dest_info.sentinel).fmtValue(pt, sema), | 23202 | Value.fromInterned(dest_info.sentinel).fmtValueSema(pt, sema), |
| 23203 | }); | 23203 | }); |
| 23204 | }; | 23204 | }; |
| 23205 | errdefer msg.destroy(sema.gpa); | 23205 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -25692,10 +25692,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25692,10 +25692,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25692 | const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{}); | 25692 | const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{}); |
| 25693 | errdefer msg.destroy(sema.gpa); | 25693 | errdefer msg.destroy(sema.gpa); |
| 25694 | try sema.errNote(dest_src, msg, "length {} here", .{ | 25694 | try sema.errNote(dest_src, msg, "length {} here", .{ |
| 25695 | dest_len_val.fmtValue(pt, sema), | 25695 | dest_len_val.fmtValueSema(pt, sema), |
| 25696 | }); | 25696 | }); |
| 25697 | try sema.errNote(src_src, msg, "length {} here", .{ | 25697 | try sema.errNote(src_src, msg, "length {} here", .{ |
| 25698 | src_len_val.fmtValue(pt, sema), | 25698 | src_len_val.fmtValueSema(pt, sema), |
| 25699 | }); | 25699 | }); |
| 25700 | break :msg msg; | 25700 | break :msg msg; |
| 25701 | }; | 25701 | }; |
| ... | @@ -29563,7 +29563,7 @@ fn coerceExtra( | ... | @@ -29563,7 +29563,7 @@ fn coerceExtra( |
| 29563 | // comptime-known integer to other number | 29563 | // comptime-known integer to other number |
| 29564 | if (!(try sema.intFitsInType(val, dest_ty, null))) { | 29564 | if (!(try sema.intFitsInType(val, dest_ty, null))) { |
| 29565 | if (!opts.report_err) return error.NotCoercible; | 29565 | if (!opts.report_err) return error.NotCoercible; |
| 29566 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(pt), val.fmtValue(pt, sema) }); | 29566 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) }); |
| 29567 | } | 29567 | } |
| 29568 | return switch (zcu.intern_pool.indexToKey(val.toIntern())) { | 29568 | return switch (zcu.intern_pool.indexToKey(val.toIntern())) { |
| 29569 | .undef => try pt.undefRef(dest_ty), | 29569 | .undef => try pt.undefRef(dest_ty), |
| ... | @@ -29608,7 +29608,7 @@ fn coerceExtra( | ... | @@ -29608,7 +29608,7 @@ fn coerceExtra( |
| 29608 | block, | 29608 | block, |
| 29609 | inst_src, | 29609 | inst_src, |
| 29610 | "type '{}' cannot represent float value '{}'", | 29610 | "type '{}' cannot represent float value '{}'", |
| 29611 | .{ dest_ty.fmt(pt), val.fmtValue(pt, sema) }, | 29611 | .{ dest_ty.fmt(pt), val.fmtValueSema(pt, sema) }, |
| 29612 | ); | 29612 | ); |
| 29613 | } | 29613 | } |
| 29614 | return Air.internedToRef(result_val.toIntern()); | 29614 | return Air.internedToRef(result_val.toIntern()); |
| ... | @@ -30026,11 +30026,11 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -30026,11 +30026,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30026 | .array_sentinel => |sentinel| { | 30026 | .array_sentinel => |sentinel| { |
| 30027 | if (sentinel.actual.toIntern() != .unreachable_value) { | 30027 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 30028 | try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ | 30028 | try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ |
| 30029 | sentinel.actual.fmtValue(pt, sema), sentinel.wanted.fmtValue(pt, sema), | 30029 | sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema), |
| 30030 | }); | 30030 | }); |
| 30031 | } else { | 30031 | } else { |
| 30032 | try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{ | 30032 | try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{ |
| 30033 | sentinel.wanted.fmtValue(pt, sema), | 30033 | sentinel.wanted.fmtValueSema(pt, sema), |
| 30034 | }); | 30034 | }); |
| 30035 | } | 30035 | } |
| 30036 | break; | 30036 | break; |
| ... | @@ -30152,11 +30152,11 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -30152,11 +30152,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30152 | .ptr_sentinel => |sentinel| { | 30152 | .ptr_sentinel => |sentinel| { |
| 30153 | if (sentinel.actual.toIntern() != .unreachable_value) { | 30153 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 30154 | try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ | 30154 | try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ |
| 30155 | sentinel.actual.fmtValue(pt, sema), sentinel.wanted.fmtValue(pt, sema), | 30155 | sentinel.actual.fmtValueSema(pt, sema), sentinel.wanted.fmtValueSema(pt, sema), |
| 30156 | }); | 30156 | }); |
| 30157 | } else { | 30157 | } else { |
| 30158 | try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{ | 30158 | try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{ |
| 30159 | sentinel.wanted.fmtValue(pt, sema), | 30159 | sentinel.wanted.fmtValueSema(pt, sema), |
| 30160 | }); | 30160 | }); |
| 30161 | } | 30161 | } |
| 30162 | break; | 30162 | break; |
| ... | @@ -31412,7 +31412,7 @@ fn coerceEnumToUnion( | ... | @@ -31412,7 +31412,7 @@ fn coerceEnumToUnion( |
| 31412 | if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| { | 31412 | if (try sema.resolveDefinedValue(block, inst_src, enum_tag)) |val| { |
| 31413 | const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse { | 31413 | const field_index = union_ty.unionTagFieldIndex(val, pt.zcu) orelse { |
| 31414 | return sema.fail(block, inst_src, "union '{}' has no tag with value '{}'", .{ | 31414 | return sema.fail(block, inst_src, "union '{}' has no tag with value '{}'", .{ |
| 31415 | union_ty.fmt(pt), val.fmtValue(pt, sema), | 31415 | union_ty.fmt(pt), val.fmtValueSema(pt, sema), |
| 31416 | }); | 31416 | }); |
| 31417 | }; | 31417 | }; |
| 31418 | 31418 | ||
| ... | @@ -32644,8 +32644,8 @@ fn analyzeSlice( | ... | @@ -32644,8 +32644,8 @@ fn analyzeSlice( |
| 32644 | msg, | 32644 | msg, |
| 32645 | "expected '{}', found '{}'", | 32645 | "expected '{}', found '{}'", |
| 32646 | .{ | 32646 | .{ |
| 32647 | Value.zero_comptime_int.fmtValue(pt, sema), | 32647 | Value.zero_comptime_int.fmtValueSema(pt, sema), |
| 32648 | start_value.fmtValue(pt, sema), | 32648 | start_value.fmtValueSema(pt, sema), |
| 32649 | }, | 32649 | }, |
| 32650 | ); | 32650 | ); |
| 32651 | break :msg msg; | 32651 | break :msg msg; |
| ... | @@ -32660,8 +32660,8 @@ fn analyzeSlice( | ... | @@ -32660,8 +32660,8 @@ fn analyzeSlice( |
| 32660 | msg, | 32660 | msg, |
| 32661 | "expected '{}', found '{}'", | 32661 | "expected '{}', found '{}'", |
| 32662 | .{ | 32662 | .{ |
| 32663 | Value.one_comptime_int.fmtValue(pt, sema), | 32663 | Value.one_comptime_int.fmtValueSema(pt, sema), |
| 32664 | end_value.fmtValue(pt, sema), | 32664 | end_value.fmtValueSema(pt, sema), |
| 32665 | }, | 32665 | }, |
| 32666 | ); | 32666 | ); |
| 32667 | break :msg msg; | 32667 | break :msg msg; |
| ... | @@ -32674,7 +32674,7 @@ fn analyzeSlice( | ... | @@ -32674,7 +32674,7 @@ fn analyzeSlice( |
| 32674 | block, | 32674 | block, |
| 32675 | end_src, | 32675 | end_src, |
| 32676 | "end index {} out of bounds for slice of single-item pointer", | 32676 | "end index {} out of bounds for slice of single-item pointer", |
| 32677 | .{end_value.fmtValue(pt, sema)}, | 32677 | .{end_value.fmtValueSema(pt, sema)}, |
| 32678 | ); | 32678 | ); |
| 32679 | } | 32679 | } |
| 32680 | } | 32680 | } |
| ... | @@ -32769,8 +32769,8 @@ fn analyzeSlice( | ... | @@ -32769,8 +32769,8 @@ fn analyzeSlice( |
| 32769 | end_src, | 32769 | end_src, |
| 32770 | "end index {} out of bounds for array of length {}{s}", | 32770 | "end index {} out of bounds for array of length {}{s}", |
| 32771 | .{ | 32771 | .{ |
| 32772 | end_val.fmtValue(pt, sema), | 32772 | end_val.fmtValueSema(pt, sema), |
| 32773 | len_val.fmtValue(pt, sema), | 32773 | len_val.fmtValueSema(pt, sema), |
| 32774 | sentinel_label, | 32774 | sentinel_label, |
| 32775 | }, | 32775 | }, |
| 32776 | ); | 32776 | ); |
| ... | @@ -32814,7 +32814,7 @@ fn analyzeSlice( | ... | @@ -32814,7 +32814,7 @@ fn analyzeSlice( |
| 32814 | end_src, | 32814 | end_src, |
| 32815 | "end index {} out of bounds for slice of length {d}{s}", | 32815 | "end index {} out of bounds for slice of length {d}{s}", |
| 32816 | .{ | 32816 | .{ |
| 32817 | end_val.fmtValue(pt, sema), | 32817 | end_val.fmtValueSema(pt, sema), |
| 32818 | try slice_val.sliceLen(pt), | 32818 | try slice_val.sliceLen(pt), |
| 32819 | sentinel_label, | 32819 | sentinel_label, |
| 32820 | }, | 32820 | }, |
| ... | @@ -32874,8 +32874,8 @@ fn analyzeSlice( | ... | @@ -32874,8 +32874,8 @@ fn analyzeSlice( |
| 32874 | start_src, | 32874 | start_src, |
| 32875 | "start index {} is larger than end index {}", | 32875 | "start index {} is larger than end index {}", |
| 32876 | .{ | 32876 | .{ |
| 32877 | start_val.fmtValue(pt, sema), | 32877 | start_val.fmtValueSema(pt, sema), |
| 32878 | end_val.fmtValue(pt, sema), | 32878 | end_val.fmtValueSema(pt, sema), |
| 32879 | }, | 32879 | }, |
| 32880 | ); | 32880 | ); |
| 32881 | } | 32881 | } |
| ... | @@ -32912,8 +32912,8 @@ fn analyzeSlice( | ... | @@ -32912,8 +32912,8 @@ fn analyzeSlice( |
| 32912 | const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); | 32912 | const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); |
| 32913 | errdefer msg.destroy(sema.gpa); | 32913 | errdefer msg.destroy(sema.gpa); |
| 32914 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ | 32914 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ |
| 32915 | expected_sentinel.fmtValue(pt, sema), | 32915 | expected_sentinel.fmtValueSema(pt, sema), |
| 32916 | actual_sentinel.fmtValue(pt, sema), | 32916 | actual_sentinel.fmtValueSema(pt, sema), |
| 32917 | }); | 32917 | }); |
| 32918 | 32918 | ||
| 32919 | break :msg msg; | 32919 | break :msg msg; |
| ... | @@ -36656,7 +36656,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L | ... | @@ -36656,7 +36656,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L |
| 36656 | .offset = .{ .container_field_value = @intCast(gop.index) }, | 36656 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| 36657 | }; | 36657 | }; |
| 36658 | const msg = msg: { | 36658 | const msg = msg: { |
| 36659 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(pt, &sema)}); | 36659 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValueSema(pt, &sema)}); |
| 36660 | errdefer msg.destroy(gpa); | 36660 | errdefer msg.destroy(gpa); |
| 36661 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); | 36661 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); |
| 36662 | break :msg msg; | 36662 | break :msg msg; |
| ... | @@ -37888,7 +37888,7 @@ fn intFromFloatScalar( | ... | @@ -37888,7 +37888,7 @@ fn intFromFloatScalar( |
| 37888 | block, | 37888 | block, |
| 37889 | src, | 37889 | src, |
| 37890 | "fractional component prevents float value '{}' from coercion to type '{}'", | 37890 | "fractional component prevents float value '{}' from coercion to type '{}'", |
| 37891 | .{ val.fmtValue(pt, sema), int_ty.fmt(pt) }, | 37891 | .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) }, |
| 37892 | ); | 37892 | ); |
| 37893 | 37893 | ||
| 37894 | const float = val.toFloat(f128, pt); | 37894 | const float = val.toFloat(f128, pt); |
| ... | @@ -37910,7 +37910,7 @@ fn intFromFloatScalar( | ... | @@ -37910,7 +37910,7 @@ fn intFromFloatScalar( |
| 37910 | 37910 | ||
| 37911 | if (!(try sema.intFitsInType(cti_result, int_ty, null))) { | 37911 | if (!(try sema.intFitsInType(cti_result, int_ty, null))) { |
| 37912 | return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{ | 37912 | return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{ |
| 37913 | val.fmtValue(pt, sema), int_ty.fmt(pt), | 37913 | val.fmtValueSema(pt, sema), int_ty.fmt(pt), |
| 37914 | }); | 37914 | }); |
| 37915 | } | 37915 | } |
| 37916 | return pt.getCoerced(cti_result, int_ty); | 37916 | return pt.getCoerced(cti_result, int_ty); |
src/Type.zig+23-19| ... | @@ -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 |
| 194 | 194 | ||
| 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); |
| 360 | 360 | ||
| 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("}"); |
| ... | @@ -478,7 +478,7 @@ pub fn hasRuntimeBitsAdvanced( | ... | @@ -478,7 +478,7 @@ pub fn hasRuntimeBitsAdvanced( |
| 478 | ty: Type, | 478 | ty: Type, |
| 479 | pt: Zcu.PerThread, | 479 | pt: Zcu.PerThread, |
| 480 | ignore_comptime_only: bool, | 480 | ignore_comptime_only: bool, |
| 481 | strat: ResolveStratLazy, | 481 | comptime strat: ResolveStratLazy, |
| 482 | ) RuntimeBitsError!bool { | 482 | ) RuntimeBitsError!bool { |
| 483 | const mod = pt.zcu; | 483 | const mod = pt.zcu; |
| 484 | const ip = &mod.intern_pool; | 484 | const ip = &mod.intern_pool; |
| ... | @@ -792,7 +792,7 @@ pub fn fnHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool { | ... | @@ -792,7 +792,7 @@ pub fn fnHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool { |
| 792 | /// Determines whether a function type has runtime bits, i.e. whether a | 792 | /// Determines whether a function type has runtime bits, i.e. whether a |
| 793 | /// function with this type can exist at runtime. | 793 | /// function with this type can exist at runtime. |
| 794 | /// Asserts that `ty` is a function type. | 794 | /// Asserts that `ty` is a function type. |
| 795 | pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) SemaError!bool { | 795 | pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool { |
| 796 | const fn_info = pt.zcu.typeToFunc(ty).?; | 796 | const fn_info = pt.zcu.typeToFunc(ty).?; |
| 797 | if (fn_info.is_generic) return false; | 797 | if (fn_info.is_generic) return false; |
| 798 | if (fn_info.is_var_args) return true; | 798 | if (fn_info.is_var_args) return true; |
| ... | @@ -824,7 +824,7 @@ pub fn ptrAlignment(ty: Type, pt: Zcu.PerThread) Alignment { | ... | @@ -824,7 +824,7 @@ pub fn ptrAlignment(ty: Type, pt: Zcu.PerThread) Alignment { |
| 824 | return ptrAlignmentAdvanced(ty, pt, .normal) catch unreachable; | 824 | return ptrAlignmentAdvanced(ty, pt, .normal) catch unreachable; |
| 825 | } | 825 | } |
| 826 | 826 | ||
| 827 | pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) !Alignment { | 827 | pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment { |
| 828 | return switch (pt.zcu.intern_pool.indexToKey(ty.toIntern())) { | 828 | return switch (pt.zcu.intern_pool.indexToKey(ty.toIntern())) { |
| 829 | .ptr_type => |ptr_type| { | 829 | .ptr_type => |ptr_type| { |
| 830 | if (ptr_type.flags.alignment != .none) | 830 | if (ptr_type.flags.alignment != .none) |
| ... | @@ -891,7 +891,7 @@ pub const ResolveStrat = enum { | ... | @@ -891,7 +891,7 @@ pub const ResolveStrat = enum { |
| 891 | /// This should typically be used from semantic analysis. | 891 | /// This should typically be used from semantic analysis. |
| 892 | sema, | 892 | sema, |
| 893 | 893 | ||
| 894 | pub fn toLazy(strat: ResolveStrat) ResolveStratLazy { | 894 | pub inline fn toLazy(strat: ResolveStrat) ResolveStratLazy { |
| 895 | return switch (strat) { | 895 | return switch (strat) { |
| 896 | .normal => .eager, | 896 | .normal => .eager, |
| 897 | .sema => .sema, | 897 | .sema => .sema, |
| ... | @@ -908,7 +908,7 @@ pub const ResolveStrat = enum { | ... | @@ -908,7 +908,7 @@ pub const ResolveStrat = enum { |
| 908 | pub fn abiAlignmentAdvanced( | 908 | pub fn abiAlignmentAdvanced( |
| 909 | ty: Type, | 909 | ty: Type, |
| 910 | pt: Zcu.PerThread, | 910 | pt: Zcu.PerThread, |
| 911 | strat: ResolveStratLazy, | 911 | comptime strat: ResolveStratLazy, |
| 912 | ) SemaError!AbiAlignmentAdvanced { | 912 | ) SemaError!AbiAlignmentAdvanced { |
| 913 | const mod = pt.zcu; | 913 | const mod = pt.zcu; |
| 914 | const target = mod.getTarget(); | 914 | const target = mod.getTarget(); |
| ... | @@ -932,7 +932,9 @@ pub fn abiAlignmentAdvanced( | ... | @@ -932,7 +932,9 @@ pub fn abiAlignmentAdvanced( |
| 932 | if (vector_type.len == 0) return .{ .scalar = .@"1" }; | 932 | if (vector_type.len == 0) return .{ .scalar = .@"1" }; |
| 933 | switch (mod.comp.getZigBackend()) { | 933 | switch (mod.comp.getZigBackend()) { |
| 934 | else => { | 934 | else => { |
| 935 | const elem_bits: u32 = @intCast(try Type.fromInterned(vector_type.child).bitSizeAdvanced(pt, .sema)); | 935 | // This is fine because the child type of a vector always has a bit-size known |
| 936 | // without needing any type resolution. | ||
| 937 | const elem_bits: u32 = @intCast(Type.fromInterned(vector_type.child).bitSize(pt)); | ||
| 936 | if (elem_bits == 0) return .{ .scalar = .@"1" }; | 938 | if (elem_bits == 0) return .{ .scalar = .@"1" }; |
| 937 | const bytes = ((elem_bits * vector_type.len) + 7) / 8; | 939 | const bytes = ((elem_bits * vector_type.len) + 7) / 8; |
| 938 | const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes); | 940 | const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes); |
| ... | @@ -1130,7 +1132,7 @@ pub fn abiAlignmentAdvanced( | ... | @@ -1130,7 +1132,7 @@ pub fn abiAlignmentAdvanced( |
| 1130 | fn abiAlignmentAdvancedErrorUnion( | 1132 | fn abiAlignmentAdvancedErrorUnion( |
| 1131 | ty: Type, | 1133 | ty: Type, |
| 1132 | pt: Zcu.PerThread, | 1134 | pt: Zcu.PerThread, |
| 1133 | strat: ResolveStratLazy, | 1135 | comptime strat: ResolveStratLazy, |
| 1134 | payload_ty: Type, | 1136 | payload_ty: Type, |
| 1135 | ) SemaError!AbiAlignmentAdvanced { | 1137 | ) SemaError!AbiAlignmentAdvanced { |
| 1136 | // This code needs to be kept in sync with the equivalent switch prong | 1138 | // This code needs to be kept in sync with the equivalent switch prong |
| ... | @@ -1167,7 +1169,7 @@ fn abiAlignmentAdvancedErrorUnion( | ... | @@ -1167,7 +1169,7 @@ fn abiAlignmentAdvancedErrorUnion( |
| 1167 | fn abiAlignmentAdvancedOptional( | 1169 | fn abiAlignmentAdvancedOptional( |
| 1168 | ty: Type, | 1170 | ty: Type, |
| 1169 | pt: Zcu.PerThread, | 1171 | pt: Zcu.PerThread, |
| 1170 | strat: ResolveStratLazy, | 1172 | comptime strat: ResolveStratLazy, |
| 1171 | ) SemaError!AbiAlignmentAdvanced { | 1173 | ) SemaError!AbiAlignmentAdvanced { |
| 1172 | const mod = pt.zcu; | 1174 | const mod = pt.zcu; |
| 1173 | const target = mod.getTarget(); | 1175 | const target = mod.getTarget(); |
| ... | @@ -1231,7 +1233,7 @@ const AbiSizeAdvanced = union(enum) { | ... | @@ -1231,7 +1233,7 @@ const AbiSizeAdvanced = union(enum) { |
| 1231 | pub fn abiSizeAdvanced( | 1233 | pub fn abiSizeAdvanced( |
| 1232 | ty: Type, | 1234 | ty: Type, |
| 1233 | pt: Zcu.PerThread, | 1235 | pt: Zcu.PerThread, |
| 1234 | strat: ResolveStratLazy, | 1236 | comptime strat: ResolveStratLazy, |
| 1235 | ) SemaError!AbiSizeAdvanced { | 1237 | ) SemaError!AbiSizeAdvanced { |
| 1236 | const mod = pt.zcu; | 1238 | const mod = pt.zcu; |
| 1237 | const target = mod.getTarget(); | 1239 | const target = mod.getTarget(); |
| ... | @@ -1505,7 +1507,7 @@ pub fn abiSizeAdvanced( | ... | @@ -1505,7 +1507,7 @@ pub fn abiSizeAdvanced( |
| 1505 | fn abiSizeAdvancedOptional( | 1507 | fn abiSizeAdvancedOptional( |
| 1506 | ty: Type, | 1508 | ty: Type, |
| 1507 | pt: Zcu.PerThread, | 1509 | pt: Zcu.PerThread, |
| 1508 | strat: ResolveStratLazy, | 1510 | comptime strat: ResolveStratLazy, |
| 1509 | ) SemaError!AbiSizeAdvanced { | 1511 | ) SemaError!AbiSizeAdvanced { |
| 1510 | const mod = pt.zcu; | 1512 | const mod = pt.zcu; |
| 1511 | const child_ty = ty.optionalChild(mod); | 1513 | const child_ty = ty.optionalChild(mod); |
| ... | @@ -1680,7 +1682,7 @@ pub fn bitSize(ty: Type, pt: Zcu.PerThread) u64 { | ... | @@ -1680,7 +1682,7 @@ pub fn bitSize(ty: Type, pt: Zcu.PerThread) u64 { |
| 1680 | pub fn bitSizeAdvanced( | 1682 | pub fn bitSizeAdvanced( |
| 1681 | ty: Type, | 1683 | ty: Type, |
| 1682 | pt: Zcu.PerThread, | 1684 | pt: Zcu.PerThread, |
| 1683 | strat: ResolveStrat, | 1685 | comptime strat: ResolveStrat, |
| 1684 | ) SemaError!u64 { | 1686 | ) SemaError!u64 { |
| 1685 | const mod = pt.zcu; | 1687 | const mod = pt.zcu; |
| 1686 | const target = mod.getTarget(); | 1688 | const target = mod.getTarget(); |
| ... | @@ -2739,7 +2741,7 @@ pub fn comptimeOnly(ty: Type, pt: Zcu.PerThread) bool { | ... | @@ -2739,7 +2741,7 @@ pub fn comptimeOnly(ty: Type, pt: Zcu.PerThread) bool { |
| 2739 | 2741 | ||
| 2740 | /// `generic_poison` will return false. | 2742 | /// `generic_poison` will return false. |
| 2741 | /// May return false negatives when structs and unions are having their field types resolved. | 2743 | /// May return false negatives when structs and unions are having their field types resolved. |
| 2742 | pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) SemaError!bool { | 2744 | pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool { |
| 2743 | const mod = pt.zcu; | 2745 | const mod = pt.zcu; |
| 2744 | const ip = &mod.intern_pool; | 2746 | const ip = &mod.intern_pool; |
| 2745 | return switch (ty.toIntern()) { | 2747 | return switch (ty.toIntern()) { |
| ... | @@ -2829,7 +2831,8 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se | ... | @@ -2829,7 +2831,8 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se |
| 2829 | .no, .wip => false, | 2831 | .no, .wip => false, |
| 2830 | .yes => true, | 2832 | .yes => true, |
| 2831 | .unknown => { | 2833 | .unknown => { |
| 2832 | assert(strat == .sema); | 2834 | // Inlined `assert` so that the resolution calls below are not statically reachable. |
| 2835 | if (strat != .sema) unreachable; | ||
| 2833 | 2836 | ||
| 2834 | if (struct_type.flagsUnordered(ip).field_types_wip) { | 2837 | if (struct_type.flagsUnordered(ip).field_types_wip) { |
| 2835 | struct_type.setRequiresComptime(ip, .unknown); | 2838 | struct_type.setRequiresComptime(ip, .unknown); |
| ... | @@ -2874,7 +2877,8 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se | ... | @@ -2874,7 +2877,8 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se |
| 2874 | .no, .wip => return false, | 2877 | .no, .wip => return false, |
| 2875 | .yes => return true, | 2878 | .yes => return true, |
| 2876 | .unknown => { | 2879 | .unknown => { |
| 2877 | assert(strat == .sema); | 2880 | // Inlined `assert` so that the resolution calls below are not statically reachable. |
| 2881 | if (strat != .sema) unreachable; | ||
| 2878 | 2882 | ||
| 2879 | if (union_type.flagsUnordered(ip).status == .field_types_wip) { | 2883 | if (union_type.flagsUnordered(ip).status == .field_types_wip) { |
| 2880 | union_type.setRequiresComptime(ip, .unknown); | 2884 | union_type.setRequiresComptime(ip, .unknown); |
| ... | @@ -3198,7 +3202,7 @@ pub fn structFieldAlign(ty: Type, index: usize, pt: Zcu.PerThread) Alignment { | ... | @@ -3198,7 +3202,7 @@ pub fn structFieldAlign(ty: Type, index: usize, pt: Zcu.PerThread) Alignment { |
| 3198 | return ty.structFieldAlignAdvanced(index, pt, .normal) catch unreachable; | 3202 | return ty.structFieldAlignAdvanced(index, pt, .normal) catch unreachable; |
| 3199 | } | 3203 | } |
| 3200 | 3204 | ||
| 3201 | pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, strat: ResolveStrat) !Alignment { | 3205 | pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment { |
| 3202 | const ip = &pt.zcu.intern_pool; | 3206 | const ip = &pt.zcu.intern_pool; |
| 3203 | switch (ip.indexToKey(ty.toIntern())) { | 3207 | switch (ip.indexToKey(ty.toIntern())) { |
| 3204 | .struct_type => { | 3208 | .struct_type => { |
src/Value.zig+31-21| ... | @@ -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 | } |
| 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 | 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 | } |
| 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 | return .{ .data = ctx }; | 62 | return .{ .data = ctx }; |
| 54 | } | 63 | } |
| 55 | 64 | ||
| ... | @@ -178,7 +187,7 @@ pub fn toBigIntAdvanced( | ... | @@ -178,7 +187,7 @@ pub fn toBigIntAdvanced( |
| 178 | val: Value, | 187 | val: Value, |
| 179 | space: *BigIntSpace, | 188 | space: *BigIntSpace, |
| 180 | pt: Zcu.PerThread, | 189 | pt: Zcu.PerThread, |
| 181 | strat: ResolveStrat, | 190 | comptime strat: ResolveStrat, |
| 182 | ) Module.CompileError!BigIntConst { | 191 | ) Module.CompileError!BigIntConst { |
| 183 | return switch (val.toIntern()) { | 192 | return switch (val.toIntern()) { |
| 184 | .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(), | 193 | .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(), |
| ... | @@ -240,7 +249,7 @@ pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 { | ... | @@ -240,7 +249,7 @@ pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 { |
| 240 | 249 | ||
| 241 | /// If the value fits in a u64, return it, otherwise null. | 250 | /// If the value fits in a u64, return it, otherwise null. |
| 242 | /// Asserts not undefined. | 251 | /// Asserts not undefined. |
| 243 | pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, strat: ResolveStrat) !?u64 { | 252 | pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !?u64 { |
| 244 | const mod = pt.zcu; | 253 | const mod = pt.zcu; |
| 245 | return switch (val.toIntern()) { | 254 | return switch (val.toIntern()) { |
| 246 | .undef => unreachable, | 255 | .undef => unreachable, |
| ... | @@ -1042,7 +1051,7 @@ pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order { | ... | @@ -1042,7 +1051,7 @@ pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order { |
| 1042 | pub fn orderAgainstZeroAdvanced( | 1051 | pub fn orderAgainstZeroAdvanced( |
| 1043 | lhs: Value, | 1052 | lhs: Value, |
| 1044 | pt: Zcu.PerThread, | 1053 | pt: Zcu.PerThread, |
| 1045 | strat: ResolveStrat, | 1054 | comptime strat: ResolveStrat, |
| 1046 | ) Module.CompileError!std.math.Order { | 1055 | ) Module.CompileError!std.math.Order { |
| 1047 | return switch (lhs.toIntern()) { | 1056 | return switch (lhs.toIntern()) { |
| 1048 | .bool_false => .eq, | 1057 | .bool_false => .eq, |
| ... | @@ -1081,7 +1090,7 @@ pub fn order(lhs: Value, rhs: Value, pt: Zcu.PerThread) std.math.Order { | ... | @@ -1081,7 +1090,7 @@ pub fn order(lhs: Value, rhs: Value, pt: Zcu.PerThread) std.math.Order { |
| 1081 | } | 1090 | } |
| 1082 | 1091 | ||
| 1083 | /// Asserts the value is comparable. | 1092 | /// Asserts the value is comparable. |
| 1084 | pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, strat: ResolveStrat) !std.math.Order { | 1093 | pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !std.math.Order { |
| 1085 | const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(pt, strat); | 1094 | const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(pt, strat); |
| 1086 | const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(pt, strat); | 1095 | const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(pt, strat); |
| 1087 | switch (lhs_against_zero) { | 1096 | switch (lhs_against_zero) { |
| ... | @@ -1119,7 +1128,7 @@ pub fn compareHeteroAdvanced( | ... | @@ -1119,7 +1128,7 @@ pub fn compareHeteroAdvanced( |
| 1119 | op: std.math.CompareOperator, | 1128 | op: std.math.CompareOperator, |
| 1120 | rhs: Value, | 1129 | rhs: Value, |
| 1121 | pt: Zcu.PerThread, | 1130 | pt: Zcu.PerThread, |
| 1122 | strat: ResolveStrat, | 1131 | comptime strat: ResolveStrat, |
| 1123 | ) !bool { | 1132 | ) !bool { |
| 1124 | if (lhs.pointerDecl(pt.zcu)) |lhs_decl| { | 1133 | if (lhs.pointerDecl(pt.zcu)) |lhs_decl| { |
| 1125 | if (rhs.pointerDecl(pt.zcu)) |rhs_decl| { | 1134 | if (rhs.pointerDecl(pt.zcu)) |rhs_decl| { |
| ... | @@ -1199,7 +1208,7 @@ pub fn compareAllWithZeroAdvancedExtra( | ... | @@ -1199,7 +1208,7 @@ pub fn compareAllWithZeroAdvancedExtra( |
| 1199 | lhs: Value, | 1208 | lhs: Value, |
| 1200 | op: std.math.CompareOperator, | 1209 | op: std.math.CompareOperator, |
| 1201 | pt: Zcu.PerThread, | 1210 | pt: Zcu.PerThread, |
| 1202 | strat: ResolveStrat, | 1211 | comptime strat: ResolveStrat, |
| 1203 | ) Module.CompileError!bool { | 1212 | ) Module.CompileError!bool { |
| 1204 | const mod = pt.zcu; | 1213 | const mod = pt.zcu; |
| 1205 | if (lhs.isInf(mod)) { | 1214 | if (lhs.isInf(mod)) { |
| ... | @@ -1505,7 +1514,7 @@ pub fn floatFromIntAdvanced( | ... | @@ -1505,7 +1514,7 @@ pub fn floatFromIntAdvanced( |
| 1505 | int_ty: Type, | 1514 | int_ty: Type, |
| 1506 | float_ty: Type, | 1515 | float_ty: Type, |
| 1507 | pt: Zcu.PerThread, | 1516 | pt: Zcu.PerThread, |
| 1508 | strat: ResolveStrat, | 1517 | comptime strat: ResolveStrat, |
| 1509 | ) !Value { | 1518 | ) !Value { |
| 1510 | const mod = pt.zcu; | 1519 | const mod = pt.zcu; |
| 1511 | if (int_ty.zigTypeTag(mod) == .Vector) { | 1520 | if (int_ty.zigTypeTag(mod) == .Vector) { |
| ... | @@ -1523,7 +1532,7 @@ pub fn floatFromIntAdvanced( | ... | @@ -1523,7 +1532,7 @@ pub fn floatFromIntAdvanced( |
| 1523 | return floatFromIntScalar(val, float_ty, pt, strat); | 1532 | return floatFromIntScalar(val, float_ty, pt, strat); |
| 1524 | } | 1533 | } |
| 1525 | 1534 | ||
| 1526 | pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) !Value { | 1535 | pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Value { |
| 1527 | const mod = pt.zcu; | 1536 | const mod = pt.zcu; |
| 1528 | return switch (mod.intern_pool.indexToKey(val.toIntern())) { | 1537 | return switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 1529 | .undef => try pt.undefValue(float_ty), | 1538 | .undef => try pt.undefValue(float_ty), |
| ... | @@ -4071,7 +4080,7 @@ pub const PointerDeriveStep = union(enum) { | ... | @@ -4071,7 +4080,7 @@ pub const PointerDeriveStep = union(enum) { |
| 4071 | }; | 4080 | }; |
| 4072 | 4081 | ||
| 4073 | pub fn pointerDerivation(ptr_val: Value, arena: Allocator, pt: Zcu.PerThread) Allocator.Error!PointerDeriveStep { | 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 | 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 backends | 4090 | /// 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. |
| 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 | 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/Zcu/PerThread.zig+2-2| ... | @@ -3163,7 +3163,7 @@ pub fn unionFieldNormalAlignmentAdvanced( | ... | @@ -3163,7 +3163,7 @@ pub fn unionFieldNormalAlignmentAdvanced( |
| 3163 | pt: Zcu.PerThread, | 3163 | pt: Zcu.PerThread, |
| 3164 | loaded_union: InternPool.LoadedUnionType, | 3164 | loaded_union: InternPool.LoadedUnionType, |
| 3165 | field_index: u32, | 3165 | field_index: u32, |
| 3166 | strat: Type.ResolveStrat, | 3166 | comptime strat: Type.ResolveStrat, |
| 3167 | ) Zcu.SemaError!InternPool.Alignment { | 3167 | ) Zcu.SemaError!InternPool.Alignment { |
| 3168 | const ip = &pt.zcu.intern_pool; | 3168 | const ip = &pt.zcu.intern_pool; |
| 3169 | assert(loaded_union.flagsUnordered(ip).layout != .@"packed"); | 3169 | assert(loaded_union.flagsUnordered(ip).layout != .@"packed"); |
| ... | @@ -3191,7 +3191,7 @@ pub fn structFieldAlignmentAdvanced( | ... | @@ -3191,7 +3191,7 @@ pub fn structFieldAlignmentAdvanced( |
| 3191 | explicit_alignment: InternPool.Alignment, | 3191 | explicit_alignment: InternPool.Alignment, |
| 3192 | field_ty: Type, | 3192 | field_ty: Type, |
| 3193 | layout: std.builtin.Type.ContainerLayout, | 3193 | layout: std.builtin.Type.ContainerLayout, |
| 3194 | strat: Type.ResolveStrat, | 3194 | comptime strat: Type.ResolveStrat, |
| 3195 | ) Zcu.SemaError!InternPool.Alignment { | 3195 | ) Zcu.SemaError!InternPool.Alignment { |
| 3196 | assert(layout != .@"packed"); | 3196 | assert(layout != .@"packed"); |
| 3197 | if (explicit_alignment != .none) return explicit_alignment; | 3197 | if (explicit_alignment != .none) return explicit_alignment; |
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 { |
| 17975 | 17975 | ||
| 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(); |
| 190 | 190 | ||
| 191 | log.debug("generateSymbol: val = {}", .{val.fmtValue(pt, null)}); | 191 | log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)}); |
| 192 | 192 | ||
| 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)}); |
| 842 | 842 | ||
| 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)}); |
| 947 | 947 | ||
| 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); |
| 987 | 987 | ||
| 988 | log.debug("genTypedValue: val = {}", .{val.fmtValue(pt, null)}); | 988 | log.debug("genTypedValue: val = {}", .{val.fmtValue(pt)}); |
| 989 | 989 | ||
| 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; |
| 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 | 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 | }; |
| 22 | 22 | ||
| 23 | pub fn format( | 23 | pub 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 function | 33 | 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 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 | 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's | 145 | // 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's | 164 | // 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 | } |
| 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 | 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 |
| 286 | 313 | ||
| 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 | } |
| 292 | 319 | ||
| 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. |
| 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 | 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 | } |