| ... | @@ -23,7 +23,7 @@ pub const Type = struct { | ... | @@ -23,7 +23,7 @@ pub const Type = struct { |
| 23 | } | 23 | } |
| 24 | | 24 | |
| 25 | pub fn zigTypeTagOrPoison(ty: Type, mod: *const Module) error{GenericPoison}!std.builtin.TypeId { | 25 | pub fn zigTypeTagOrPoison(ty: Type, mod: *const Module) error{GenericPoison}!std.builtin.TypeId { |
| 26 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 26 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 27 | .int_type => .Int, | 27 | .int_type => .Int, |
| 28 | .ptr_type => .Pointer, | 28 | .ptr_type => .Pointer, |
| 29 | .array_type => .Array, | 29 | .array_type => .Array, |
| ... | @@ -170,7 +170,7 @@ pub const Type = struct { | ... | @@ -170,7 +170,7 @@ pub const Type = struct { |
| 170 | | 170 | |
| 171 | /// Asserts the type is a pointer. | 171 | /// Asserts the type is a pointer. |
| 172 | pub fn ptrIsMutable(ty: Type, mod: *const Module) bool { | 172 | pub fn ptrIsMutable(ty: Type, mod: *const Module) bool { |
| 173 | return !mod.intern_pool.indexToKey(ty.ip_index).ptr_type.is_const; | 173 | return !mod.intern_pool.indexToKey(ty.toIntern()).ptr_type.is_const; |
| 174 | } | 174 | } |
| 175 | | 175 | |
| 176 | pub const ArrayInfo = struct { | 176 | pub const ArrayInfo = struct { |
| ... | @@ -199,26 +199,23 @@ pub const Type = struct { | ... | @@ -199,26 +199,23 @@ pub const Type = struct { |
| 199 | } | 199 | } |
| 200 | | 200 | |
| 201 | pub fn ptrInfo(ty: Type, mod: *const Module) Payload.Pointer.Data { | 201 | pub fn ptrInfo(ty: Type, mod: *const Module) Payload.Pointer.Data { |
| 202 | return Payload.Pointer.Data.fromKey(ptrInfoIp(mod.intern_pool, ty.ip_index)); | 202 | return Payload.Pointer.Data.fromKey(ptrInfoIp(mod.intern_pool, ty.toIntern())); |
| 203 | } | 203 | } |
| 204 | | 204 | |
| 205 | pub fn eql(a: Type, b: Type, mod: *const Module) bool { | 205 | pub fn eql(a: Type, b: Type, mod: *const Module) bool { |
| 206 | _ = mod; // TODO: remove this parameter | 206 | _ = mod; // TODO: remove this parameter |
| 207 | assert(a.ip_index != .none); | | |
| 208 | assert(b.ip_index != .none); | | |
| 209 | // The InternPool data structure hashes based on Key to make interned objects | 207 | // The InternPool data structure hashes based on Key to make interned objects |
| 210 | // unique. An Index can be treated simply as u32 value for the | 208 | // unique. An Index can be treated simply as u32 value for the |
| 211 | // purpose of Type/Value hashing and equality. | 209 | // purpose of Type/Value hashing and equality. |
| 212 | return a.ip_index == b.ip_index; | 210 | return a.toIntern() == b.toIntern(); |
| 213 | } | 211 | } |
| 214 | | 212 | |
| 215 | pub fn hash(ty: Type, mod: *const Module) u32 { | 213 | pub fn hash(ty: Type, mod: *const Module) u32 { |
| 216 | _ = mod; // TODO: remove this parameter | 214 | _ = mod; // TODO: remove this parameter |
| 217 | assert(ty.ip_index != .none); | | |
| 218 | // The InternPool data structure hashes based on Key to make interned objects | 215 | // The InternPool data structure hashes based on Key to make interned objects |
| 219 | // unique. An Index can be treated simply as u32 value for the | 216 | // unique. An Index can be treated simply as u32 value for the |
| 220 | // purpose of Type/Value hashing and equality. | 217 | // purpose of Type/Value hashing and equality. |
| 221 | return std.hash.uint32(@enumToInt(ty.ip_index)); | 218 | return std.hash.uint32(@enumToInt(ty.toIntern())); |
| 222 | } | 219 | } |
| 223 | | 220 | |
| 224 | pub fn format(ty: Type, comptime unused_fmt_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { | 221 | pub fn format(ty: Type, comptime unused_fmt_string: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| ... | @@ -280,7 +277,7 @@ pub const Type = struct { | ... | @@ -280,7 +277,7 @@ pub const Type = struct { |
| 280 | | 277 | |
| 281 | /// Prints a name suitable for `@typeName`. | 278 | /// Prints a name suitable for `@typeName`. |
| 282 | pub fn print(ty: Type, writer: anytype, mod: *Module) @TypeOf(writer).Error!void { | 279 | pub fn print(ty: Type, writer: anytype, mod: *Module) @TypeOf(writer).Error!void { |
| 283 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 280 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 284 | .int_type => |int_type| { | 281 | .int_type => |int_type| { |
| 285 | const sign_char: u8 = switch (int_type.signedness) { | 282 | const sign_char: u8 = switch (int_type.signedness) { |
| 286 | .signed => 'i', | 283 | .signed => 'i', |
| ... | @@ -520,10 +517,10 @@ pub const Type = struct { | ... | @@ -520,10 +517,10 @@ pub const Type = struct { |
| 520 | ignore_comptime_only: bool, | 517 | ignore_comptime_only: bool, |
| 521 | strat: AbiAlignmentAdvancedStrat, | 518 | strat: AbiAlignmentAdvancedStrat, |
| 522 | ) RuntimeBitsError!bool { | 519 | ) RuntimeBitsError!bool { |
| 523 | return switch (ty.ip_index) { | 520 | return switch (ty.toIntern()) { |
| 524 | // False because it is a comptime-only type. | 521 | // False because it is a comptime-only type. |
| 525 | .empty_struct_type => false, | 522 | .empty_struct_type => false, |
| 526 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 523 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 527 | .int_type => |int_type| int_type.bits != 0, | 524 | .int_type => |int_type| int_type.bits != 0, |
| 528 | .ptr_type => |ptr_type| { | 525 | .ptr_type => |ptr_type| { |
| 529 | // Pointers to zero-bit types still have a runtime address; however, pointers | 526 | // Pointers to zero-bit types still have a runtime address; however, pointers |
| ... | @@ -710,7 +707,7 @@ pub const Type = struct { | ... | @@ -710,7 +707,7 @@ pub const Type = struct { |
| 710 | /// readFrom/writeToMemory are supported only for types with a well- | 707 | /// readFrom/writeToMemory are supported only for types with a well- |
| 711 | /// defined memory layout | 708 | /// defined memory layout |
| 712 | pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool { | 709 | pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool { |
| 713 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 710 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 714 | .int_type, | 711 | .int_type, |
| 715 | .ptr_type, | 712 | .ptr_type, |
| 716 | .vector_type, | 713 | .vector_type, |
| ... | @@ -847,7 +844,7 @@ pub const Type = struct { | ... | @@ -847,7 +844,7 @@ pub const Type = struct { |
| 847 | } | 844 | } |
| 848 | | 845 | |
| 849 | pub fn isNoReturn(ty: Type, mod: *Module) bool { | 846 | pub fn isNoReturn(ty: Type, mod: *Module) bool { |
| 850 | return if (ty.ip_index != .none) mod.intern_pool.isNoReturn(ty.ip_index) else false; | 847 | return mod.intern_pool.isNoReturn(ty.toIntern()); |
| 851 | } | 848 | } |
| 852 | | 849 | |
| 853 | /// Returns 0 if the pointer is naturally aligned and the element type is 0-bit. | 850 | /// Returns 0 if the pointer is naturally aligned and the element type is 0-bit. |
| ... | @@ -856,7 +853,7 @@ pub const Type = struct { | ... | @@ -856,7 +853,7 @@ pub const Type = struct { |
| 856 | } | 853 | } |
| 857 | | 854 | |
| 858 | pub fn ptrAlignmentAdvanced(ty: Type, mod: *Module, opt_sema: ?*Sema) !u32 { | 855 | pub fn ptrAlignmentAdvanced(ty: Type, mod: *Module, opt_sema: ?*Sema) !u32 { |
| 859 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 856 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 860 | .ptr_type => |ptr_type| { | 857 | .ptr_type => |ptr_type| { |
| 861 | if (ptr_type.alignment.toByteUnitsOptional()) |a| { | 858 | if (ptr_type.alignment.toByteUnitsOptional()) |a| { |
| 862 | return @intCast(u32, a); | 859 | return @intCast(u32, a); |
| ... | @@ -873,7 +870,7 @@ pub const Type = struct { | ... | @@ -873,7 +870,7 @@ pub const Type = struct { |
| 873 | } | 870 | } |
| 874 | | 871 | |
| 875 | pub fn ptrAddressSpace(ty: Type, mod: *const Module) std.builtin.AddressSpace { | 872 | pub fn ptrAddressSpace(ty: Type, mod: *const Module) std.builtin.AddressSpace { |
| 876 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 873 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 877 | .ptr_type => |ptr_type| ptr_type.address_space, | 874 | .ptr_type => |ptr_type| ptr_type.address_space, |
| 878 | .opt_type => |child| mod.intern_pool.indexToKey(child).ptr_type.address_space, | 875 | .opt_type => |child| mod.intern_pool.indexToKey(child).ptr_type.address_space, |
| 879 | else => unreachable, | 876 | else => unreachable, |
| ... | @@ -923,9 +920,9 @@ pub const Type = struct { | ... | @@ -923,9 +920,9 @@ pub const Type = struct { |
| 923 | else => null, | 920 | else => null, |
| 924 | }; | 921 | }; |
| 925 | | 922 | |
| 926 | switch (ty.ip_index) { | 923 | switch (ty.toIntern()) { |
| 927 | .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 }, | 924 | .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 }, |
| 928 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 925 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 929 | .int_type => |int_type| { | 926 | .int_type => |int_type| { |
| 930 | if (int_type.bits == 0) return AbiAlignmentAdvanced{ .scalar = 0 }; | 927 | if (int_type.bits == 0) return AbiAlignmentAdvanced{ .scalar = 0 }; |
| 931 | return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(int_type.bits, target) }; | 928 | return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(int_type.bits, target) }; |
| ... | @@ -1040,7 +1037,7 @@ pub const Type = struct { | ... | @@ -1040,7 +1037,7 @@ pub const Type = struct { |
| 1040 | .sema => unreachable, // handled above | 1037 | .sema => unreachable, // handled above |
| 1041 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1038 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1042 | .ty = .comptime_int_type, | 1039 | .ty = .comptime_int_type, |
| 1043 | .storage = .{ .lazy_align = ty.ip_index }, | 1040 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1044 | } })).toValue() }, | 1041 | } })).toValue() }, |
| 1045 | }; | 1042 | }; |
| 1046 | if (struct_obj.layout == .Packed) { | 1043 | if (struct_obj.layout == .Packed) { |
| ... | @@ -1048,7 +1045,7 @@ pub const Type = struct { | ... | @@ -1048,7 +1045,7 @@ pub const Type = struct { |
| 1048 | .sema => |sema| try sema.resolveTypeLayout(ty), | 1045 | .sema => |sema| try sema.resolveTypeLayout(ty), |
| 1049 | .lazy => if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ | 1046 | .lazy => if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ |
| 1050 | .ty = .comptime_int_type, | 1047 | .ty = .comptime_int_type, |
| 1051 | .storage = .{ .lazy_align = ty.ip_index }, | 1048 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1052 | } })).toValue() }, | 1049 | } })).toValue() }, |
| 1053 | .eager => {}, | 1050 | .eager => {}, |
| 1054 | } | 1051 | } |
| ... | @@ -1062,7 +1059,7 @@ pub const Type = struct { | ... | @@ -1062,7 +1059,7 @@ pub const Type = struct { |
| 1062 | if (!(field.ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1059 | if (!(field.ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1063 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1060 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1064 | .ty = .comptime_int_type, | 1061 | .ty = .comptime_int_type, |
| 1065 | .storage = .{ .lazy_align = ty.ip_index }, | 1062 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1066 | } })).toValue() }, | 1063 | } })).toValue() }, |
| 1067 | else => |e| return e, | 1064 | else => |e| return e, |
| 1068 | })) continue; | 1065 | })) continue; |
| ... | @@ -1076,7 +1073,7 @@ pub const Type = struct { | ... | @@ -1076,7 +1073,7 @@ pub const Type = struct { |
| 1076 | .sema => unreachable, // handled above | 1073 | .sema => unreachable, // handled above |
| 1077 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1074 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1078 | .ty = .comptime_int_type, | 1075 | .ty = .comptime_int_type, |
| 1079 | .storage = .{ .lazy_align = ty.ip_index }, | 1076 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1080 | } })).toValue() }, | 1077 | } })).toValue() }, |
| 1081 | }, | 1078 | }, |
| 1082 | }; | 1079 | }; |
| ... | @@ -1106,7 +1103,7 @@ pub const Type = struct { | ... | @@ -1106,7 +1103,7 @@ pub const Type = struct { |
| 1106 | .sema => unreachable, // passed to abiAlignmentAdvanced above | 1103 | .sema => unreachable, // passed to abiAlignmentAdvanced above |
| 1107 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1104 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1108 | .ty = .comptime_int_type, | 1105 | .ty = .comptime_int_type, |
| 1109 | .storage = .{ .lazy_align = ty.ip_index }, | 1106 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1110 | } })).toValue() }, | 1107 | } })).toValue() }, |
| 1111 | }, | 1108 | }, |
| 1112 | } | 1109 | } |
| ... | @@ -1157,7 +1154,7 @@ pub const Type = struct { | ... | @@ -1157,7 +1154,7 @@ pub const Type = struct { |
| 1157 | if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1154 | if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1158 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1155 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1159 | .ty = .comptime_int_type, | 1156 | .ty = .comptime_int_type, |
| 1160 | .storage = .{ .lazy_align = ty.ip_index }, | 1157 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1161 | } })).toValue() }, | 1158 | } })).toValue() }, |
| 1162 | else => |e| return e, | 1159 | else => |e| return e, |
| 1163 | })) { | 1160 | })) { |
| ... | @@ -1179,7 +1176,7 @@ pub const Type = struct { | ... | @@ -1179,7 +1176,7 @@ pub const Type = struct { |
| 1179 | } | 1176 | } |
| 1180 | return .{ .val = (try mod.intern(.{ .int = .{ | 1177 | return .{ .val = (try mod.intern(.{ .int = .{ |
| 1181 | .ty = .comptime_int_type, | 1178 | .ty = .comptime_int_type, |
| 1182 | .storage = .{ .lazy_align = ty.ip_index }, | 1179 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1183 | } })).toValue() }; | 1180 | } })).toValue() }; |
| 1184 | }, | 1181 | }, |
| 1185 | } | 1182 | } |
| ... | @@ -1205,7 +1202,7 @@ pub const Type = struct { | ... | @@ -1205,7 +1202,7 @@ pub const Type = struct { |
| 1205 | if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1202 | if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1206 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1203 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1207 | .ty = .comptime_int_type, | 1204 | .ty = .comptime_int_type, |
| 1208 | .storage = .{ .lazy_align = ty.ip_index }, | 1205 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1209 | } })).toValue() }, | 1206 | } })).toValue() }, |
| 1210 | else => |e| return e, | 1207 | else => |e| return e, |
| 1211 | })) { | 1208 | })) { |
| ... | @@ -1217,7 +1214,7 @@ pub const Type = struct { | ... | @@ -1217,7 +1214,7 @@ pub const Type = struct { |
| 1217 | .scalar => |x| return AbiAlignmentAdvanced{ .scalar = @max(x, 1) }, | 1214 | .scalar => |x| return AbiAlignmentAdvanced{ .scalar = @max(x, 1) }, |
| 1218 | .val => return .{ .val = (try mod.intern(.{ .int = .{ | 1215 | .val => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1219 | .ty = .comptime_int_type, | 1216 | .ty = .comptime_int_type, |
| 1220 | .storage = .{ .lazy_align = ty.ip_index }, | 1217 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1221 | } })).toValue() }, | 1218 | } })).toValue() }, |
| 1222 | }, | 1219 | }, |
| 1223 | } | 1220 | } |
| ... | @@ -1249,7 +1246,7 @@ pub const Type = struct { | ... | @@ -1249,7 +1246,7 @@ pub const Type = struct { |
| 1249 | .sema => unreachable, // handled above | 1246 | .sema => unreachable, // handled above |
| 1250 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1247 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1251 | .ty = .comptime_int_type, | 1248 | .ty = .comptime_int_type, |
| 1252 | .storage = .{ .lazy_align = ty.ip_index }, | 1249 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1253 | } })).toValue() }, | 1250 | } })).toValue() }, |
| 1254 | }; | 1251 | }; |
| 1255 | if (union_obj.fields.count() == 0) { | 1252 | if (union_obj.fields.count() == 0) { |
| ... | @@ -1266,7 +1263,7 @@ pub const Type = struct { | ... | @@ -1266,7 +1263,7 @@ pub const Type = struct { |
| 1266 | if (!(field.ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1263 | if (!(field.ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1267 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1264 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1268 | .ty = .comptime_int_type, | 1265 | .ty = .comptime_int_type, |
| 1269 | .storage = .{ .lazy_align = ty.ip_index }, | 1266 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1270 | } })).toValue() }, | 1267 | } })).toValue() }, |
| 1271 | else => |e| return e, | 1268 | else => |e| return e, |
| 1272 | })) continue; | 1269 | })) continue; |
| ... | @@ -1280,7 +1277,7 @@ pub const Type = struct { | ... | @@ -1280,7 +1277,7 @@ pub const Type = struct { |
| 1280 | .sema => unreachable, // handled above | 1277 | .sema => unreachable, // handled above |
| 1281 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1278 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1282 | .ty = .comptime_int_type, | 1279 | .ty = .comptime_int_type, |
| 1283 | .storage = .{ .lazy_align = ty.ip_index }, | 1280 | .storage = .{ .lazy_align = ty.toIntern() }, |
| 1284 | } })).toValue() }, | 1281 | } })).toValue() }, |
| 1285 | }, | 1282 | }, |
| 1286 | }; | 1283 | }; |
| ... | @@ -1321,10 +1318,10 @@ pub const Type = struct { | ... | @@ -1321,10 +1318,10 @@ pub const Type = struct { |
| 1321 | ) Module.CompileError!AbiSizeAdvanced { | 1318 | ) Module.CompileError!AbiSizeAdvanced { |
| 1322 | const target = mod.getTarget(); | 1319 | const target = mod.getTarget(); |
| 1323 | | 1320 | |
| 1324 | switch (ty.ip_index) { | 1321 | switch (ty.toIntern()) { |
| 1325 | .empty_struct_type => return AbiSizeAdvanced{ .scalar = 0 }, | 1322 | .empty_struct_type => return AbiSizeAdvanced{ .scalar = 0 }, |
| 1326 | | 1323 | |
| 1327 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1324 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1328 | .int_type => |int_type| { | 1325 | .int_type => |int_type| { |
| 1329 | if (int_type.bits == 0) return AbiSizeAdvanced{ .scalar = 0 }; | 1326 | if (int_type.bits == 0) return AbiSizeAdvanced{ .scalar = 0 }; |
| 1330 | return AbiSizeAdvanced{ .scalar = intAbiSize(int_type.bits, target) }; | 1327 | return AbiSizeAdvanced{ .scalar = intAbiSize(int_type.bits, target) }; |
| ... | @@ -1343,7 +1340,7 @@ pub const Type = struct { | ... | @@ -1343,7 +1340,7 @@ pub const Type = struct { |
| 1343 | .sema, .eager => unreachable, | 1340 | .sema, .eager => unreachable, |
| 1344 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1341 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1345 | .ty = .comptime_int_type, | 1342 | .ty = .comptime_int_type, |
| 1346 | .storage = .{ .lazy_size = ty.ip_index }, | 1343 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1347 | } })).toValue() }, | 1344 | } })).toValue() }, |
| 1348 | }, | 1345 | }, |
| 1349 | } | 1346 | } |
| ... | @@ -1354,7 +1351,7 @@ pub const Type = struct { | ... | @@ -1354,7 +1351,7 @@ pub const Type = struct { |
| 1354 | .eager => null, | 1351 | .eager => null, |
| 1355 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1352 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1356 | .ty = .comptime_int_type, | 1353 | .ty = .comptime_int_type, |
| 1357 | .storage = .{ .lazy_size = ty.ip_index }, | 1354 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1358 | } })).toValue() }, | 1355 | } })).toValue() }, |
| 1359 | }; | 1356 | }; |
| 1360 | const elem_bits_u64 = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema); | 1357 | const elem_bits_u64 = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema); |
| ... | @@ -1365,7 +1362,7 @@ pub const Type = struct { | ... | @@ -1365,7 +1362,7 @@ pub const Type = struct { |
| 1365 | .scalar => |x| x, | 1362 | .scalar => |x| x, |
| 1366 | .val => return .{ .val = (try mod.intern(.{ .int = .{ | 1363 | .val => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1367 | .ty = .comptime_int_type, | 1364 | .ty = .comptime_int_type, |
| 1368 | .storage = .{ .lazy_size = ty.ip_index }, | 1365 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1369 | } })).toValue() }, | 1366 | } })).toValue() }, |
| 1370 | }; | 1367 | }; |
| 1371 | const result = std.mem.alignForwardGeneric(u32, total_bytes, alignment); | 1368 | const result = std.mem.alignForwardGeneric(u32, total_bytes, alignment); |
| ... | @@ -1385,7 +1382,7 @@ pub const Type = struct { | ... | @@ -1385,7 +1382,7 @@ pub const Type = struct { |
| 1385 | if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1382 | if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1386 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1383 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1387 | .ty = .comptime_int_type, | 1384 | .ty = .comptime_int_type, |
| 1388 | .storage = .{ .lazy_size = ty.ip_index }, | 1385 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1389 | } })).toValue() }, | 1386 | } })).toValue() }, |
| 1390 | else => |e| return e, | 1387 | else => |e| return e, |
| 1391 | })) { | 1388 | })) { |
| ... | @@ -1401,7 +1398,7 @@ pub const Type = struct { | ... | @@ -1401,7 +1398,7 @@ pub const Type = struct { |
| 1401 | .eager => unreachable, | 1398 | .eager => unreachable, |
| 1402 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1399 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1403 | .ty = .comptime_int_type, | 1400 | .ty = .comptime_int_type, |
| 1404 | .storage = .{ .lazy_size = ty.ip_index }, | 1401 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1405 | } })).toValue() }, | 1402 | } })).toValue() }, |
| 1406 | }, | 1403 | }, |
| 1407 | }; | 1404 | }; |
| ... | @@ -1489,7 +1486,7 @@ pub const Type = struct { | ... | @@ -1489,7 +1486,7 @@ pub const Type = struct { |
| 1489 | .sema => |sema| try sema.resolveTypeLayout(ty), | 1486 | .sema => |sema| try sema.resolveTypeLayout(ty), |
| 1490 | .lazy => if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ | 1487 | .lazy => if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ |
| 1491 | .ty = .comptime_int_type, | 1488 | .ty = .comptime_int_type, |
| 1492 | .storage = .{ .lazy_size = ty.ip_index }, | 1489 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1493 | } })).toValue() }, | 1490 | } })).toValue() }, |
| 1494 | .eager => {}, | 1491 | .eager => {}, |
| 1495 | } | 1492 | } |
| ... | @@ -1504,7 +1501,7 @@ pub const Type = struct { | ... | @@ -1504,7 +1501,7 @@ pub const Type = struct { |
| 1504 | return AbiSizeAdvanced{ .scalar = 0 }; | 1501 | return AbiSizeAdvanced{ .scalar = 0 }; |
| 1505 | if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ | 1502 | if (!struct_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ |
| 1506 | .ty = .comptime_int_type, | 1503 | .ty = .comptime_int_type, |
| 1507 | .storage = .{ .lazy_size = ty.ip_index }, | 1504 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1508 | } })).toValue() }; | 1505 | } })).toValue() }; |
| 1509 | }, | 1506 | }, |
| 1510 | .eager => {}, | 1507 | .eager => {}, |
| ... | @@ -1568,7 +1565,7 @@ pub const Type = struct { | ... | @@ -1568,7 +1565,7 @@ pub const Type = struct { |
| 1568 | .sema => |sema| try sema.resolveTypeLayout(ty), | 1565 | .sema => |sema| try sema.resolveTypeLayout(ty), |
| 1569 | .lazy => if (!union_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ | 1566 | .lazy => if (!union_obj.haveLayout()) return .{ .val = (try mod.intern(.{ .int = .{ |
| 1570 | .ty = .comptime_int_type, | 1567 | .ty = .comptime_int_type, |
| 1571 | .storage = .{ .lazy_size = ty.ip_index }, | 1568 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1572 | } })).toValue() }, | 1569 | } })).toValue() }, |
| 1573 | .eager => {}, | 1570 | .eager => {}, |
| 1574 | } | 1571 | } |
| ... | @@ -1589,7 +1586,7 @@ pub const Type = struct { | ... | @@ -1589,7 +1586,7 @@ pub const Type = struct { |
| 1589 | if (!(child_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { | 1586 | if (!(child_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) { |
| 1590 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1587 | error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1591 | .ty = .comptime_int_type, | 1588 | .ty = .comptime_int_type, |
| 1592 | .storage = .{ .lazy_size = ty.ip_index }, | 1589 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1593 | } })).toValue() }, | 1590 | } })).toValue() }, |
| 1594 | else => |e| return e, | 1591 | else => |e| return e, |
| 1595 | })) return AbiSizeAdvanced{ .scalar = 1 }; | 1592 | })) return AbiSizeAdvanced{ .scalar = 1 }; |
| ... | @@ -1605,7 +1602,7 @@ pub const Type = struct { | ... | @@ -1605,7 +1602,7 @@ pub const Type = struct { |
| 1605 | .eager => unreachable, | 1602 | .eager => unreachable, |
| 1606 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ | 1603 | .lazy => return .{ .val = (try mod.intern(.{ .int = .{ |
| 1607 | .ty = .comptime_int_type, | 1604 | .ty = .comptime_int_type, |
| 1608 | .storage = .{ .lazy_size = ty.ip_index }, | 1605 | .storage = .{ .lazy_size = ty.toIntern() }, |
| 1609 | } })).toValue() }, | 1606 | } })).toValue() }, |
| 1610 | }, | 1607 | }, |
| 1611 | }; | 1608 | }; |
| ... | @@ -1647,7 +1644,7 @@ pub const Type = struct { | ... | @@ -1647,7 +1644,7 @@ pub const Type = struct { |
| 1647 | | 1644 | |
| 1648 | const strat: AbiAlignmentAdvancedStrat = if (opt_sema) |sema| .{ .sema = sema } else .eager; | 1645 | const strat: AbiAlignmentAdvancedStrat = if (opt_sema) |sema| .{ .sema = sema } else .eager; |
| 1649 | | 1646 | |
| 1650 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1647 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1651 | .int_type => |int_type| return int_type.bits, | 1648 | .int_type => |int_type| return int_type.bits, |
| 1652 | .ptr_type => |ptr_type| switch (ptr_type.size) { | 1649 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 1653 | .Slice => return target.ptrBitWidth() * 2, | 1650 | .Slice => return target.ptrBitWidth() * 2, |
| ... | @@ -1820,7 +1817,7 @@ pub const Type = struct { | ... | @@ -1820,7 +1817,7 @@ pub const Type = struct { |
| 1820 | } | 1817 | } |
| 1821 | | 1818 | |
| 1822 | pub fn isSinglePointer(ty: Type, mod: *const Module) bool { | 1819 | pub fn isSinglePointer(ty: Type, mod: *const Module) bool { |
| 1823 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1820 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1824 | .ptr_type => |ptr_info| ptr_info.size == .One, | 1821 | .ptr_type => |ptr_info| ptr_info.size == .One, |
| 1825 | else => false, | 1822 | else => false, |
| 1826 | }; | 1823 | }; |
| ... | @@ -1833,33 +1830,27 @@ pub const Type = struct { | ... | @@ -1833,33 +1830,27 @@ pub const Type = struct { |
| 1833 | | 1830 | |
| 1834 | /// Returns `null` if `ty` is not a pointer. | 1831 | /// Returns `null` if `ty` is not a pointer. |
| 1835 | pub fn ptrSizeOrNull(ty: Type, mod: *const Module) ?std.builtin.Type.Pointer.Size { | 1832 | pub fn ptrSizeOrNull(ty: Type, mod: *const Module) ?std.builtin.Type.Pointer.Size { |
| 1836 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1833 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1837 | .ptr_type => |ptr_info| ptr_info.size, | 1834 | .ptr_type => |ptr_info| ptr_info.size, |
| 1838 | else => null, | 1835 | else => null, |
| 1839 | }; | 1836 | }; |
| 1840 | } | 1837 | } |
| 1841 | | 1838 | |
| 1842 | pub fn isSlice(ty: Type, mod: *const Module) bool { | 1839 | pub fn isSlice(ty: Type, mod: *const Module) bool { |
| 1843 | return switch (ty.ip_index) { | 1840 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1844 | .none => false, | 1841 | .ptr_type => |ptr_type| ptr_type.size == .Slice, |
| 1845 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1842 | else => false, |
| 1846 | .ptr_type => |ptr_type| ptr_type.size == .Slice, | | |
| 1847 | else => false, | | |
| 1848 | }, | | |
| 1849 | }; | 1843 | }; |
| 1850 | } | 1844 | } |
| 1851 | | 1845 | |
| 1852 | pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type { | 1846 | pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type { |
| 1853 | return mod.intern_pool.slicePtrType(ty.ip_index).toType(); | 1847 | return mod.intern_pool.slicePtrType(ty.toIntern()).toType(); |
| 1854 | } | 1848 | } |
| 1855 | | 1849 | |
| 1856 | pub fn isConstPtr(ty: Type, mod: *const Module) bool { | 1850 | pub fn isConstPtr(ty: Type, mod: *const Module) bool { |
| 1857 | return switch (ty.ip_index) { | 1851 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1858 | .none => false, | 1852 | .ptr_type => |ptr_type| ptr_type.is_const, |
| 1859 | else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1853 | else => false, |
| 1860 | .ptr_type => |ptr_type| ptr_type.is_const, | | |
| 1861 | else => false, | | |
| 1862 | }, | | |
| 1863 | }; | 1854 | }; |
| 1864 | } | 1855 | } |
| 1865 | | 1856 | |
| ... | @@ -1868,53 +1859,41 @@ pub const Type = struct { | ... | @@ -1868,53 +1859,41 @@ pub const Type = struct { |
| 1868 | } | 1859 | } |
| 1869 | | 1860 | |
| 1870 | pub fn isVolatilePtrIp(ty: Type, ip: InternPool) bool { | 1861 | pub fn isVolatilePtrIp(ty: Type, ip: InternPool) bool { |
| 1871 | return switch (ty.ip_index) { | 1862 | return switch (ip.indexToKey(ty.toIntern())) { |
| 1872 | .none => false, | 1863 | .ptr_type => |ptr_type| ptr_type.is_volatile, |
| 1873 | else => switch (ip.indexToKey(ty.ip_index)) { | 1864 | else => false, |
| 1874 | .ptr_type => |ptr_type| ptr_type.is_volatile, | | |
| 1875 | else => false, | | |
| 1876 | }, | | |
| 1877 | }; | 1865 | }; |
| 1878 | } | 1866 | } |
| 1879 | | 1867 | |
| 1880 | pub fn isAllowzeroPtr(ty: Type, mod: *const Module) bool { | 1868 | pub fn isAllowzeroPtr(ty: Type, mod: *const Module) bool { |
| 1881 | return switch (ty.ip_index) { | 1869 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1882 | .none => false, | 1870 | .ptr_type => |ptr_type| ptr_type.is_allowzero, |
| 1883 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1871 | .opt_type => true, |
| 1884 | .ptr_type => |ptr_type| ptr_type.is_allowzero, | 1872 | else => false, |
| 1885 | .opt_type => true, | | |
| 1886 | else => false, | | |
| 1887 | }, | | |
| 1888 | }; | 1873 | }; |
| 1889 | } | 1874 | } |
| 1890 | | 1875 | |
| 1891 | pub fn isCPtr(ty: Type, mod: *const Module) bool { | 1876 | pub fn isCPtr(ty: Type, mod: *const Module) bool { |
| 1892 | return switch (ty.ip_index) { | 1877 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1893 | .none => false, | 1878 | .ptr_type => |ptr_type| ptr_type.size == .C, |
| 1894 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1879 | else => false, |
| 1895 | .ptr_type => |ptr_type| ptr_type.size == .C, | | |
| 1896 | else => false, | | |
| 1897 | }, | | |
| 1898 | }; | 1880 | }; |
| 1899 | } | 1881 | } |
| 1900 | | 1882 | |
| 1901 | pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool { | 1883 | pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool { |
| 1902 | return switch (ty.ip_index) { | 1884 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1903 | .none => false, | 1885 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 1904 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1886 | .Slice => false, |
| 1905 | .ptr_type => |ptr_type| switch (ptr_type.size) { | 1887 | .One, .Many, .C => true, |
| 1906 | .Slice => false, | 1888 | }, |
| 1907 | .One, .Many, .C => true, | 1889 | .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) { |
| 1908 | }, | 1890 | .ptr_type => |p| switch (p.size) { |
| 1909 | .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) { | 1891 | .Slice, .C => false, |
| 1910 | .ptr_type => |p| switch (p.size) { | 1892 | .Many, .One => !p.is_allowzero, |
| 1911 | .Slice, .C => false, | | |
| 1912 | .Many, .One => !p.is_allowzero, | | |
| 1913 | }, | | |
| 1914 | else => false, | | |
| 1915 | }, | 1893 | }, |
| 1916 | else => false, | 1894 | else => false, |
| 1917 | }, | 1895 | }, |
| | 1896 | else => false, |
| 1918 | }; | 1897 | }; |
| 1919 | } | 1898 | } |
| 1920 | | 1899 | |
| ... | @@ -1929,22 +1908,19 @@ pub const Type = struct { | ... | @@ -1929,22 +1908,19 @@ pub const Type = struct { |
| 1929 | | 1908 | |
| 1930 | /// See also `isPtrLikeOptional`. | 1909 | /// See also `isPtrLikeOptional`. |
| 1931 | pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool { | 1910 | pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool { |
| 1932 | return switch (ty.ip_index) { | 1911 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1933 | .none => false, | 1912 | .opt_type => |child| switch (child.toType().zigTypeTag(mod)) { |
| 1934 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1913 | .Pointer => { |
| 1935 | .opt_type => |child| switch (child.toType().zigTypeTag(mod)) { | 1914 | const info = child.toType().ptrInfo(mod); |
| 1936 | .Pointer => { | 1915 | return switch (info.size) { |
| 1937 | const info = child.toType().ptrInfo(mod); | 1916 | .C => false, |
| 1938 | return switch (info.size) { | 1917 | else => !info.@"allowzero", |
| 1939 | .C => false, | 1918 | }; |
| 1940 | else => !info.@"allowzero", | | |
| 1941 | }; | | |
| 1942 | }, | | |
| 1943 | .ErrorSet => true, | | |
| 1944 | else => false, | | |
| 1945 | }, | 1919 | }, |
| | 1920 | .ErrorSet => true, |
| 1946 | else => false, | 1921 | else => false, |
| 1947 | }, | 1922 | }, |
| | 1923 | else => false, |
| 1948 | }; | 1924 | }; |
| 1949 | } | 1925 | } |
| 1950 | | 1926 | |
| ... | @@ -1952,19 +1928,16 @@ pub const Type = struct { | ... | @@ -1952,19 +1928,16 @@ pub const Type = struct { |
| 1952 | /// address value, using 0 for null. Note that this returns true for C pointers. | 1928 | /// address value, using 0 for null. Note that this returns true for C pointers. |
| 1953 | /// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`. | 1929 | /// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`. |
| 1954 | pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool { | 1930 | pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool { |
| 1955 | return switch (ty.ip_index) { | 1931 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1956 | .none => false, | 1932 | .ptr_type => |ptr_type| ptr_type.size == .C, |
| 1957 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1933 | .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) { |
| 1958 | .ptr_type => |ptr_type| ptr_type.size == .C, | 1934 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 1959 | .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) { | 1935 | .Slice, .C => false, |
| 1960 | .ptr_type => |ptr_type| switch (ptr_type.size) { | 1936 | .Many, .One => !ptr_type.is_allowzero, |
| 1961 | .Slice, .C => false, | | |
| 1962 | .Many, .One => !ptr_type.is_allowzero, | | |
| 1963 | }, | | |
| 1964 | else => false, | | |
| 1965 | }, | 1937 | }, |
| 1966 | else => false, | 1938 | else => false, |
| 1967 | }, | 1939 | }, |
| | 1940 | else => false, |
| 1968 | }; | 1941 | }; |
| 1969 | } | 1942 | } |
| 1970 | | 1943 | |
| ... | @@ -1976,7 +1949,7 @@ pub const Type = struct { | ... | @@ -1976,7 +1949,7 @@ pub const Type = struct { |
| 1976 | } | 1949 | } |
| 1977 | | 1950 | |
| 1978 | pub fn childTypeIp(ty: Type, ip: InternPool) Type { | 1951 | pub fn childTypeIp(ty: Type, ip: InternPool) Type { |
| 1979 | return ip.childType(ty.ip_index).toType(); | 1952 | return ip.childType(ty.toIntern()).toType(); |
| 1980 | } | 1953 | } |
| 1981 | | 1954 | |
| 1982 | /// For *[N]T, returns T. | 1955 | /// For *[N]T, returns T. |
| ... | @@ -1989,7 +1962,7 @@ pub const Type = struct { | ... | @@ -1989,7 +1962,7 @@ pub const Type = struct { |
| 1989 | /// For []T, returns T. | 1962 | /// For []T, returns T. |
| 1990 | /// For anyframe->T, returns T. | 1963 | /// For anyframe->T, returns T. |
| 1991 | pub fn elemType2(ty: Type, mod: *const Module) Type { | 1964 | pub fn elemType2(ty: Type, mod: *const Module) Type { |
| 1992 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1965 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 1993 | .ptr_type => |ptr_type| switch (ptr_type.size) { | 1966 | .ptr_type => |ptr_type| switch (ptr_type.size) { |
| 1994 | .One => ptr_type.elem_type.toType().shallowElemType(mod), | 1967 | .One => ptr_type.elem_type.toType().shallowElemType(mod), |
| 1995 | .Many, .C, .Slice => ptr_type.elem_type.toType(), | 1968 | .Many, .C, .Slice => ptr_type.elem_type.toType(), |
| ... | @@ -2023,7 +1996,7 @@ pub const Type = struct { | ... | @@ -2023,7 +1996,7 @@ pub const Type = struct { |
| 2023 | /// Asserts that the type is an optional. | 1996 | /// Asserts that the type is an optional. |
| 2024 | /// Note that for C pointers this returns the type unmodified. | 1997 | /// Note that for C pointers this returns the type unmodified. |
| 2025 | pub fn optionalChild(ty: Type, mod: *const Module) Type { | 1998 | pub fn optionalChild(ty: Type, mod: *const Module) Type { |
| 2026 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 1999 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2027 | .opt_type => |child| child.toType(), | 2000 | .opt_type => |child| child.toType(), |
| 2028 | .ptr_type => |ptr_type| b: { | 2001 | .ptr_type => |ptr_type| b: { |
| 2029 | assert(ptr_type.size == .C); | 2002 | assert(ptr_type.size == .C); |
| ... | @@ -2036,7 +2009,7 @@ pub const Type = struct { | ... | @@ -2036,7 +2009,7 @@ pub const Type = struct { |
| 2036 | /// Returns the tag type of a union, if the type is a union and it has a tag type. | 2009 | /// Returns the tag type of a union, if the type is a union and it has a tag type. |
| 2037 | /// Otherwise, returns `null`. | 2010 | /// Otherwise, returns `null`. |
| 2038 | pub fn unionTagType(ty: Type, mod: *Module) ?Type { | 2011 | pub fn unionTagType(ty: Type, mod: *Module) ?Type { |
| 2039 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2012 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2040 | .union_type => |union_type| switch (union_type.runtime_tag) { | 2013 | .union_type => |union_type| switch (union_type.runtime_tag) { |
| 2041 | .tagged => { | 2014 | .tagged => { |
| 2042 | const union_obj = mod.unionPtr(union_type.index); | 2015 | const union_obj = mod.unionPtr(union_type.index); |
| ... | @@ -2052,7 +2025,7 @@ pub const Type = struct { | ... | @@ -2052,7 +2025,7 @@ pub const Type = struct { |
| 2052 | /// Same as `unionTagType` but includes safety tag. | 2025 | /// Same as `unionTagType` but includes safety tag. |
| 2053 | /// Codegen should use this version. | 2026 | /// Codegen should use this version. |
| 2054 | pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type { | 2027 | pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type { |
| 2055 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2028 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2056 | .union_type => |union_type| { | 2029 | .union_type => |union_type| { |
| 2057 | if (!union_type.hasTag()) return null; | 2030 | if (!union_type.hasTag()) return null; |
| 2058 | const union_obj = mod.unionPtr(union_type.index); | 2031 | const union_obj = mod.unionPtr(union_type.index); |
| ... | @@ -2097,13 +2070,13 @@ pub const Type = struct { | ... | @@ -2097,13 +2070,13 @@ pub const Type = struct { |
| 2097 | } | 2070 | } |
| 2098 | | 2071 | |
| 2099 | pub fn unionGetLayout(ty: Type, mod: *Module) Module.Union.Layout { | 2072 | pub fn unionGetLayout(ty: Type, mod: *Module) Module.Union.Layout { |
| 2100 | const union_type = mod.intern_pool.indexToKey(ty.ip_index).union_type; | 2073 | const union_type = mod.intern_pool.indexToKey(ty.toIntern()).union_type; |
| 2101 | const union_obj = mod.unionPtr(union_type.index); | 2074 | const union_obj = mod.unionPtr(union_type.index); |
| 2102 | return union_obj.getLayout(mod, union_type.hasTag()); | 2075 | return union_obj.getLayout(mod, union_type.hasTag()); |
| 2103 | } | 2076 | } |
| 2104 | | 2077 | |
| 2105 | pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout { | 2078 | pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout { |
| 2106 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2079 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2107 | .struct_type => |struct_type| { | 2080 | .struct_type => |struct_type| { |
| 2108 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return .Auto; | 2081 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return .Auto; |
| 2109 | return struct_obj.layout; | 2082 | return struct_obj.layout; |
| ... | @@ -2119,19 +2092,19 @@ pub const Type = struct { | ... | @@ -2119,19 +2092,19 @@ pub const Type = struct { |
| 2119 | | 2092 | |
| 2120 | /// Asserts that the type is an error union. | 2093 | /// Asserts that the type is an error union. |
| 2121 | pub fn errorUnionPayload(ty: Type, mod: *Module) Type { | 2094 | pub fn errorUnionPayload(ty: Type, mod: *Module) Type { |
| 2122 | return mod.intern_pool.indexToKey(ty.ip_index).error_union_type.payload_type.toType(); | 2095 | return mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type.toType(); |
| 2123 | } | 2096 | } |
| 2124 | | 2097 | |
| 2125 | /// Asserts that the type is an error union. | 2098 | /// Asserts that the type is an error union. |
| 2126 | pub fn errorUnionSet(ty: Type, mod: *Module) Type { | 2099 | pub fn errorUnionSet(ty: Type, mod: *Module) Type { |
| 2127 | return mod.intern_pool.indexToKey(ty.ip_index).error_union_type.error_set_type.toType(); | 2100 | return mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.error_set_type.toType(); |
| 2128 | } | 2101 | } |
| 2129 | | 2102 | |
| 2130 | /// Returns false for unresolved inferred error sets. | 2103 | /// Returns false for unresolved inferred error sets. |
| 2131 | pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool { | 2104 | pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool { |
| 2132 | return switch (ty.ip_index) { | 2105 | return switch (ty.toIntern()) { |
| 2133 | .anyerror_type => false, | 2106 | .anyerror_type => false, |
| 2134 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2107 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2135 | .error_set_type => |error_set_type| error_set_type.names.len == 0, | 2108 | .error_set_type => |error_set_type| error_set_type.names.len == 0, |
| 2136 | .inferred_error_set_type => |index| { | 2109 | .inferred_error_set_type => |index| { |
| 2137 | const inferred_error_set = mod.inferredErrorSetPtr(index); | 2110 | const inferred_error_set = mod.inferredErrorSetPtr(index); |
| ... | @@ -2149,9 +2122,9 @@ pub const Type = struct { | ... | @@ -2149,9 +2122,9 @@ pub const Type = struct { |
| 2149 | /// Note that the result may be a false negative if the type did not get error set | 2122 | /// Note that the result may be a false negative if the type did not get error set |
| 2150 | /// resolution prior to this call. | 2123 | /// resolution prior to this call. |
| 2151 | pub fn isAnyError(ty: Type, mod: *Module) bool { | 2124 | pub fn isAnyError(ty: Type, mod: *Module) bool { |
| 2152 | return switch (ty.ip_index) { | 2125 | return switch (ty.toIntern()) { |
| 2153 | .anyerror_type => true, | 2126 | .anyerror_type => true, |
| 2154 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2127 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2155 | .inferred_error_set_type => |i| mod.inferredErrorSetPtr(i).is_anyerror, | 2128 | .inferred_error_set_type => |i| mod.inferredErrorSetPtr(i).is_anyerror, |
| 2156 | else => false, | 2129 | else => false, |
| 2157 | }, | 2130 | }, |
| ... | @@ -2194,9 +2167,9 @@ pub const Type = struct { | ... | @@ -2194,9 +2167,9 @@ pub const Type = struct { |
| 2194 | /// resolved yet. | 2167 | /// resolved yet. |
| 2195 | pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool { | 2168 | pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool { |
| 2196 | const ip = &mod.intern_pool; | 2169 | const ip = &mod.intern_pool; |
| 2197 | return switch (ty.ip_index) { | 2170 | return switch (ty.toIntern()) { |
| 2198 | .anyerror_type => true, | 2171 | .anyerror_type => true, |
| 2199 | else => switch (ip.indexToKey(ty.ip_index)) { | 2172 | else => switch (ip.indexToKey(ty.toIntern())) { |
| 2200 | .error_set_type => |error_set_type| { | 2173 | .error_set_type => |error_set_type| { |
| 2201 | // If the string is not interned, then the field certainly is not present. | 2174 | // If the string is not interned, then the field certainly is not present. |
| 2202 | const field_name_interned = ip.getString(name).unwrap() orelse return false; | 2175 | const field_name_interned = ip.getString(name).unwrap() orelse return false; |
| ... | @@ -2220,7 +2193,7 @@ pub const Type = struct { | ... | @@ -2220,7 +2193,7 @@ pub const Type = struct { |
| 2220 | } | 2193 | } |
| 2221 | | 2194 | |
| 2222 | pub fn arrayLenIp(ty: Type, ip: InternPool) u64 { | 2195 | pub fn arrayLenIp(ty: Type, ip: InternPool) u64 { |
| 2223 | return switch (ip.indexToKey(ty.ip_index)) { | 2196 | return switch (ip.indexToKey(ty.toIntern())) { |
| 2224 | .vector_type => |vector_type| vector_type.len, | 2197 | .vector_type => |vector_type| vector_type.len, |
| 2225 | .array_type => |array_type| array_type.len, | 2198 | .array_type => |array_type| array_type.len, |
| 2226 | .struct_type => |struct_type| { | 2199 | .struct_type => |struct_type| { |
| ... | @@ -2238,7 +2211,7 @@ pub const Type = struct { | ... | @@ -2238,7 +2211,7 @@ pub const Type = struct { |
| 2238 | } | 2211 | } |
| 2239 | | 2212 | |
| 2240 | pub fn vectorLen(ty: Type, mod: *const Module) u32 { | 2213 | pub fn vectorLen(ty: Type, mod: *const Module) u32 { |
| 2241 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2214 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2242 | .vector_type => |vector_type| vector_type.len, | 2215 | .vector_type => |vector_type| vector_type.len, |
| 2243 | .anon_struct_type => |tuple| @intCast(u32, tuple.types.len), | 2216 | .anon_struct_type => |tuple| @intCast(u32, tuple.types.len), |
| 2244 | else => unreachable, | 2217 | else => unreachable, |
| ... | @@ -2247,7 +2220,7 @@ pub const Type = struct { | ... | @@ -2247,7 +2220,7 @@ pub const Type = struct { |
| 2247 | | 2220 | |
| 2248 | /// Asserts the type is an array, pointer or vector. | 2221 | /// Asserts the type is an array, pointer or vector. |
| 2249 | pub fn sentinel(ty: Type, mod: *const Module) ?Value { | 2222 | pub fn sentinel(ty: Type, mod: *const Module) ?Value { |
| 2250 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2223 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2251 | .vector_type, | 2224 | .vector_type, |
| 2252 | .struct_type, | 2225 | .struct_type, |
| 2253 | .anon_struct_type, | 2226 | .anon_struct_type, |
| ... | @@ -2267,10 +2240,9 @@ pub const Type = struct { | ... | @@ -2267,10 +2240,9 @@ pub const Type = struct { |
| 2267 | | 2240 | |
| 2268 | /// Returns true if and only if the type is a fixed-width, signed integer. | 2241 | /// Returns true if and only if the type is a fixed-width, signed integer. |
| 2269 | pub fn isSignedInt(ty: Type, mod: *const Module) bool { | 2242 | pub fn isSignedInt(ty: Type, mod: *const Module) bool { |
| 2270 | return switch (ty.ip_index) { | 2243 | return switch (ty.toIntern()) { |
| 2271 | .c_char_type, .isize_type, .c_short_type, .c_int_type, .c_long_type, .c_longlong_type => true, | 2244 | .c_char_type, .isize_type, .c_short_type, .c_int_type, .c_long_type, .c_longlong_type => true, |
| 2272 | .none => false, | 2245 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2273 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | | |
| 2274 | .int_type => |int_type| int_type.signedness == .signed, | 2246 | .int_type => |int_type| int_type.signedness == .signed, |
| 2275 | else => false, | 2247 | else => false, |
| 2276 | }, | 2248 | }, |
| ... | @@ -2279,10 +2251,9 @@ pub const Type = struct { | ... | @@ -2279,10 +2251,9 @@ pub const Type = struct { |
| 2279 | | 2251 | |
| 2280 | /// Returns true if and only if the type is a fixed-width, unsigned integer. | 2252 | /// Returns true if and only if the type is a fixed-width, unsigned integer. |
| 2281 | pub fn isUnsignedInt(ty: Type, mod: *const Module) bool { | 2253 | pub fn isUnsignedInt(ty: Type, mod: *const Module) bool { |
| 2282 | return switch (ty.ip_index) { | 2254 | return switch (ty.toIntern()) { |
| 2283 | .usize_type, .c_ushort_type, .c_uint_type, .c_ulong_type, .c_ulonglong_type => true, | 2255 | .usize_type, .c_ushort_type, .c_uint_type, .c_ulong_type, .c_ulonglong_type => true, |
| 2284 | .none => false, | 2256 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2285 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | | |
| 2286 | .int_type => |int_type| int_type.signedness == .unsigned, | 2257 | .int_type => |int_type| int_type.signedness == .unsigned, |
| 2287 | else => false, | 2258 | else => false, |
| 2288 | }, | 2259 | }, |
| ... | @@ -2304,7 +2275,7 @@ pub const Type = struct { | ... | @@ -2304,7 +2275,7 @@ pub const Type = struct { |
| 2304 | const target = mod.getTarget(); | 2275 | const target = mod.getTarget(); |
| 2305 | var ty = starting_ty; | 2276 | var ty = starting_ty; |
| 2306 | | 2277 | |
| 2307 | while (true) switch (ty.ip_index) { | 2278 | while (true) switch (ty.toIntern()) { |
| 2308 | .anyerror_type => { | 2279 | .anyerror_type => { |
| 2309 | // TODO revisit this when error sets support custom int types | 2280 | // TODO revisit this when error sets support custom int types |
| 2310 | return .{ .signedness = .unsigned, .bits = 16 }; | 2281 | return .{ .signedness = .unsigned, .bits = 16 }; |
| ... | @@ -2320,7 +2291,7 @@ pub const Type = struct { | ... | @@ -2320,7 +2291,7 @@ pub const Type = struct { |
| 2320 | .c_ulong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) }, | 2291 | .c_ulong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) }, |
| 2321 | .c_longlong_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) }, | 2292 | .c_longlong_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) }, |
| 2322 | .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) }, | 2293 | .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) }, |
| 2323 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2294 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2324 | .int_type => |int_type| return int_type, | 2295 | .int_type => |int_type| return int_type, |
| 2325 | .struct_type => |struct_type| { | 2296 | .struct_type => |struct_type| { |
| 2326 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 2297 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| ... | @@ -2370,7 +2341,7 @@ pub const Type = struct { | ... | @@ -2370,7 +2341,7 @@ pub const Type = struct { |
| 2370 | } | 2341 | } |
| 2371 | | 2342 | |
| 2372 | pub fn isNamedInt(ty: Type) bool { | 2343 | pub fn isNamedInt(ty: Type) bool { |
| 2373 | return switch (ty.ip_index) { | 2344 | return switch (ty.toIntern()) { |
| 2374 | .usize_type, | 2345 | .usize_type, |
| 2375 | .isize_type, | 2346 | .isize_type, |
| 2376 | .c_char_type, | 2347 | .c_char_type, |
| ... | @@ -2390,7 +2361,7 @@ pub const Type = struct { | ... | @@ -2390,7 +2361,7 @@ pub const Type = struct { |
| 2390 | | 2361 | |
| 2391 | /// Returns `false` for `comptime_float`. | 2362 | /// Returns `false` for `comptime_float`. |
| 2392 | pub fn isRuntimeFloat(ty: Type) bool { | 2363 | pub fn isRuntimeFloat(ty: Type) bool { |
| 2393 | return switch (ty.ip_index) { | 2364 | return switch (ty.toIntern()) { |
| 2394 | .f16_type, | 2365 | .f16_type, |
| 2395 | .f32_type, | 2366 | .f32_type, |
| 2396 | .f64_type, | 2367 | .f64_type, |
| ... | @@ -2405,7 +2376,7 @@ pub const Type = struct { | ... | @@ -2405,7 +2376,7 @@ pub const Type = struct { |
| 2405 | | 2376 | |
| 2406 | /// Returns `true` for `comptime_float`. | 2377 | /// Returns `true` for `comptime_float`. |
| 2407 | pub fn isAnyFloat(ty: Type) bool { | 2378 | pub fn isAnyFloat(ty: Type) bool { |
| 2408 | return switch (ty.ip_index) { | 2379 | return switch (ty.toIntern()) { |
| 2409 | .f16_type, | 2380 | .f16_type, |
| 2410 | .f32_type, | 2381 | .f32_type, |
| 2411 | .f64_type, | 2382 | .f64_type, |
| ... | @@ -2422,7 +2393,7 @@ pub const Type = struct { | ... | @@ -2422,7 +2393,7 @@ pub const Type = struct { |
| 2422 | /// Asserts the type is a fixed-size float or comptime_float. | 2393 | /// Asserts the type is a fixed-size float or comptime_float. |
| 2423 | /// Returns 128 for comptime_float types. | 2394 | /// Returns 128 for comptime_float types. |
| 2424 | pub fn floatBits(ty: Type, target: Target) u16 { | 2395 | pub fn floatBits(ty: Type, target: Target) u16 { |
| 2425 | return switch (ty.ip_index) { | 2396 | return switch (ty.toIntern()) { |
| 2426 | .f16_type => 16, | 2397 | .f16_type => 16, |
| 2427 | .f32_type => 32, | 2398 | .f32_type => 32, |
| 2428 | .f64_type => 64, | 2399 | .f64_type => 64, |
| ... | @@ -2440,7 +2411,7 @@ pub const Type = struct { | ... | @@ -2440,7 +2411,7 @@ pub const Type = struct { |
| 2440 | } | 2411 | } |
| 2441 | | 2412 | |
| 2442 | pub fn fnReturnTypeIp(ty: Type, ip: InternPool) Type { | 2413 | pub fn fnReturnTypeIp(ty: Type, ip: InternPool) Type { |
| 2443 | return switch (ip.indexToKey(ty.ip_index)) { | 2414 | return switch (ip.indexToKey(ty.toIntern())) { |
| 2444 | .ptr_type => |ptr_type| ip.indexToKey(ptr_type.elem_type).func_type.return_type, | 2415 | .ptr_type => |ptr_type| ip.indexToKey(ptr_type.elem_type).func_type.return_type, |
| 2445 | .func_type => |func_type| func_type.return_type, | 2416 | .func_type => |func_type| func_type.return_type, |
| 2446 | else => unreachable, | 2417 | else => unreachable, |
| ... | @@ -2449,7 +2420,7 @@ pub const Type = struct { | ... | @@ -2449,7 +2420,7 @@ pub const Type = struct { |
| 2449 | | 2420 | |
| 2450 | /// Asserts the type is a function. | 2421 | /// Asserts the type is a function. |
| 2451 | pub fn fnCallingConvention(ty: Type, mod: *Module) std.builtin.CallingConvention { | 2422 | pub fn fnCallingConvention(ty: Type, mod: *Module) std.builtin.CallingConvention { |
| 2452 | return mod.intern_pool.indexToKey(ty.ip_index).func_type.cc; | 2423 | return mod.intern_pool.indexToKey(ty.toIntern()).func_type.cc; |
| 2453 | } | 2424 | } |
| 2454 | | 2425 | |
| 2455 | pub fn isValidParamType(self: Type, mod: *const Module) bool { | 2426 | pub fn isValidParamType(self: Type, mod: *const Module) bool { |
| ... | @@ -2468,11 +2439,11 @@ pub const Type = struct { | ... | @@ -2468,11 +2439,11 @@ pub const Type = struct { |
| 2468 | | 2439 | |
| 2469 | /// Asserts the type is a function. | 2440 | /// Asserts the type is a function. |
| 2470 | pub fn fnIsVarArgs(ty: Type, mod: *Module) bool { | 2441 | pub fn fnIsVarArgs(ty: Type, mod: *Module) bool { |
| 2471 | return mod.intern_pool.indexToKey(ty.ip_index).func_type.is_var_args; | 2442 | return mod.intern_pool.indexToKey(ty.toIntern()).func_type.is_var_args; |
| 2472 | } | 2443 | } |
| 2473 | | 2444 | |
| 2474 | pub fn isNumeric(ty: Type, mod: *const Module) bool { | 2445 | pub fn isNumeric(ty: Type, mod: *const Module) bool { |
| 2475 | return switch (ty.ip_index) { | 2446 | return switch (ty.toIntern()) { |
| 2476 | .f16_type, | 2447 | .f16_type, |
| 2477 | .f32_type, | 2448 | .f32_type, |
| 2478 | .f64_type, | 2449 | .f64_type, |
| ... | @@ -2494,9 +2465,7 @@ pub const Type = struct { | ... | @@ -2494,9 +2465,7 @@ pub const Type = struct { |
| 2494 | .c_ulonglong_type, | 2465 | .c_ulonglong_type, |
| 2495 | => true, | 2466 | => true, |
| 2496 | | 2467 | |
| 2497 | .none => false, | 2468 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2498 | | | |
| 2499 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | | |
| 2500 | .int_type => true, | 2469 | .int_type => true, |
| 2501 | else => false, | 2470 | else => false, |
| 2502 | }, | 2471 | }, |
| ... | @@ -2508,10 +2477,10 @@ pub const Type = struct { | ... | @@ -2508,10 +2477,10 @@ pub const Type = struct { |
| 2508 | pub fn onePossibleValue(starting_type: Type, mod: *Module) !?Value { | 2477 | pub fn onePossibleValue(starting_type: Type, mod: *Module) !?Value { |
| 2509 | var ty = starting_type; | 2478 | var ty = starting_type; |
| 2510 | | 2479 | |
| 2511 | while (true) switch (ty.ip_index) { | 2480 | while (true) switch (ty.toIntern()) { |
| 2512 | .empty_struct_type => return Value.empty_struct, | 2481 | .empty_struct_type => return Value.empty_struct, |
| 2513 | | 2482 | |
| 2514 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2483 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2515 | .int_type => |int_type| { | 2484 | .int_type => |int_type| { |
| 2516 | if (int_type.bits == 0) { | 2485 | if (int_type.bits == 0) { |
| 2517 | return try mod.intValue(ty, 0); | 2486 | return try mod.intValue(ty, 0); |
| ... | @@ -2530,13 +2499,13 @@ pub const Type = struct { | ... | @@ -2530,13 +2499,13 @@ pub const Type = struct { |
| 2530 | | 2499 | |
| 2531 | inline .array_type, .vector_type => |seq_type| { | 2500 | inline .array_type, .vector_type => |seq_type| { |
| 2532 | if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{ | 2501 | if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{ |
| 2533 | .ty = ty.ip_index, | 2502 | .ty = ty.toIntern(), |
| 2534 | .storage = .{ .elems = &.{} }, | 2503 | .storage = .{ .elems = &.{} }, |
| 2535 | } })).toValue(); | 2504 | } })).toValue(); |
| 2536 | if (try seq_type.child.toType().onePossibleValue(mod)) |opv| { | 2505 | if (try seq_type.child.toType().onePossibleValue(mod)) |opv| { |
| 2537 | return (try mod.intern(.{ .aggregate = .{ | 2506 | return (try mod.intern(.{ .aggregate = .{ |
| 2538 | .ty = ty.ip_index, | 2507 | .ty = ty.toIntern(), |
| 2539 | .storage = .{ .repeated_elem = opv.ip_index }, | 2508 | .storage = .{ .repeated_elem = opv.toIntern() }, |
| 2540 | } })).toValue(); | 2509 | } })).toValue(); |
| 2541 | } | 2510 | } |
| 2542 | return null; | 2511 | return null; |
| ... | @@ -2612,7 +2581,7 @@ pub const Type = struct { | ... | @@ -2612,7 +2581,7 @@ pub const Type = struct { |
| 2612 | // This TODO is repeated in the redundant implementation of | 2581 | // This TODO is repeated in the redundant implementation of |
| 2613 | // one-possible-value logic in Sema.zig. | 2582 | // one-possible-value logic in Sema.zig. |
| 2614 | const empty = try mod.intern(.{ .aggregate = .{ | 2583 | const empty = try mod.intern(.{ .aggregate = .{ |
| 2615 | .ty = ty.ip_index, | 2584 | .ty = ty.toIntern(), |
| 2616 | .storage = .{ .elems = &.{} }, | 2585 | .storage = .{ .elems = &.{} }, |
| 2617 | } }); | 2586 | } }); |
| 2618 | return empty.toValue(); | 2587 | return empty.toValue(); |
| ... | @@ -2625,7 +2594,7 @@ pub const Type = struct { | ... | @@ -2625,7 +2594,7 @@ pub const Type = struct { |
| 2625 | // In this case the struct has all comptime-known fields and | 2594 | // In this case the struct has all comptime-known fields and |
| 2626 | // therefore has one possible value. | 2595 | // therefore has one possible value. |
| 2627 | return (try mod.intern(.{ .aggregate = .{ | 2596 | return (try mod.intern(.{ .aggregate = .{ |
| 2628 | .ty = ty.ip_index, | 2597 | .ty = ty.toIntern(), |
| 2629 | .storage = .{ .elems = tuple.values }, | 2598 | .storage = .{ .elems = tuple.values }, |
| 2630 | } })).toValue(); | 2599 | } })).toValue(); |
| 2631 | }, | 2600 | }, |
| ... | @@ -2637,9 +2606,9 @@ pub const Type = struct { | ... | @@ -2637,9 +2606,9 @@ pub const Type = struct { |
| 2637 | const only_field = union_obj.fields.values()[0]; | 2606 | const only_field = union_obj.fields.values()[0]; |
| 2638 | const val_val = (try only_field.ty.onePossibleValue(mod)) orelse return null; | 2607 | const val_val = (try only_field.ty.onePossibleValue(mod)) orelse return null; |
| 2639 | const only = try mod.intern(.{ .un = .{ | 2608 | const only = try mod.intern(.{ .un = .{ |
| 2640 | .ty = ty.ip_index, | 2609 | .ty = ty.toIntern(), |
| 2641 | .tag = tag_val.ip_index, | 2610 | .tag = tag_val.toIntern(), |
| 2642 | .val = val_val.ip_index, | 2611 | .val = val_val.toIntern(), |
| 2643 | } }); | 2612 | } }); |
| 2644 | return only.toValue(); | 2613 | return only.toValue(); |
| 2645 | }, | 2614 | }, |
| ... | @@ -2650,8 +2619,8 @@ pub const Type = struct { | ... | @@ -2650,8 +2619,8 @@ pub const Type = struct { |
| 2650 | | 2619 | |
| 2651 | if (try enum_type.tag_ty.toType().onePossibleValue(mod)) |int_opv| { | 2620 | if (try enum_type.tag_ty.toType().onePossibleValue(mod)) |int_opv| { |
| 2652 | const only = try mod.intern(.{ .enum_tag = .{ | 2621 | const only = try mod.intern(.{ .enum_tag = .{ |
| 2653 | .ty = ty.ip_index, | 2622 | .ty = ty.toIntern(), |
| 2654 | .int = int_opv.ip_index, | 2623 | .int = int_opv.toIntern(), |
| 2655 | } }); | 2624 | } }); |
| 2656 | return only.toValue(); | 2625 | return only.toValue(); |
| 2657 | } | 2626 | } |
| ... | @@ -2663,7 +2632,7 @@ pub const Type = struct { | ... | @@ -2663,7 +2632,7 @@ pub const Type = struct { |
| 2663 | 1 => { | 2632 | 1 => { |
| 2664 | if (enum_type.values.len == 0) { | 2633 | if (enum_type.values.len == 0) { |
| 2665 | const only = try mod.intern(.{ .enum_tag = .{ | 2634 | const only = try mod.intern(.{ .enum_tag = .{ |
| 2666 | .ty = ty.ip_index, | 2635 | .ty = ty.toIntern(), |
| 2667 | .int = try mod.intern(.{ .int = .{ | 2636 | .int = try mod.intern(.{ .int = .{ |
| 2668 | .ty = enum_type.tag_ty, | 2637 | .ty = enum_type.tag_ty, |
| 2669 | .storage = .{ .u64 = 0 }, | 2638 | .storage = .{ .u64 = 0 }, |
| ... | @@ -2705,10 +2674,10 @@ pub const Type = struct { | ... | @@ -2705,10 +2674,10 @@ pub const Type = struct { |
| 2705 | /// TODO merge these implementations together with the "advanced" pattern seen | 2674 | /// TODO merge these implementations together with the "advanced" pattern seen |
| 2706 | /// elsewhere in this file. | 2675 | /// elsewhere in this file. |
| 2707 | pub fn comptimeOnly(ty: Type, mod: *Module) bool { | 2676 | pub fn comptimeOnly(ty: Type, mod: *Module) bool { |
| 2708 | return switch (ty.ip_index) { | 2677 | return switch (ty.toIntern()) { |
| 2709 | .empty_struct_type => false, | 2678 | .empty_struct_type => false, |
| 2710 | | 2679 | |
| 2711 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2680 | else => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2712 | .int_type => false, | 2681 | .int_type => false, |
| 2713 | .ptr_type => |ptr_type| { | 2682 | .ptr_type => |ptr_type| { |
| 2714 | const child_ty = ptr_type.elem_type.toType(); | 2683 | const child_ty = ptr_type.elem_type.toType(); |
| ... | @@ -2880,8 +2849,7 @@ pub const Type = struct { | ... | @@ -2880,8 +2849,7 @@ pub const Type = struct { |
| 2880 | | 2849 | |
| 2881 | /// Returns null if the type has no namespace. | 2850 | /// Returns null if the type has no namespace. |
| 2882 | pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex { | 2851 | pub fn getNamespaceIndex(ty: Type, mod: *Module) Module.Namespace.OptionalIndex { |
| 2883 | if (ty.ip_index == .none) return .none; | 2852 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2884 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | | |
| 2885 | .opaque_type => |opaque_type| opaque_type.namespace.toOptional(), | 2853 | .opaque_type => |opaque_type| opaque_type.namespace.toOptional(), |
| 2886 | .struct_type => |struct_type| struct_type.namespace, | 2854 | .struct_type => |struct_type| struct_type.namespace, |
| 2887 | .union_type => |union_type| mod.unionPtr(union_type.index).namespace.toOptional(), | 2855 | .union_type => |union_type| mod.unionPtr(union_type.index).namespace.toOptional(), |
| ... | @@ -2900,8 +2868,8 @@ pub const Type = struct { | ... | @@ -2900,8 +2868,8 @@ pub const Type = struct { |
| 2900 | pub fn minInt(ty: Type, mod: *Module) !Value { | 2868 | pub fn minInt(ty: Type, mod: *Module) !Value { |
| 2901 | const scalar = try minIntScalar(ty.scalarType(mod), mod); | 2869 | const scalar = try minIntScalar(ty.scalarType(mod), mod); |
| 2902 | return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{ | 2870 | return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{ |
| 2903 | .ty = ty.ip_index, | 2871 | .ty = ty.toIntern(), |
| 2904 | .storage = .{ .repeated_elem = scalar.ip_index }, | 2872 | .storage = .{ .repeated_elem = scalar.toIntern() }, |
| 2905 | } })).toValue() else scalar; | 2873 | } })).toValue() else scalar; |
| 2906 | } | 2874 | } |
| 2907 | | 2875 | |
| ... | @@ -2929,8 +2897,8 @@ pub const Type = struct { | ... | @@ -2929,8 +2897,8 @@ pub const Type = struct { |
| 2929 | pub fn maxInt(ty: Type, mod: *Module, dest_ty: Type) !Value { | 2897 | pub fn maxInt(ty: Type, mod: *Module, dest_ty: Type) !Value { |
| 2930 | const scalar = try maxIntScalar(ty.scalarType(mod), mod, dest_ty); | 2898 | const scalar = try maxIntScalar(ty.scalarType(mod), mod, dest_ty); |
| 2931 | return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{ | 2899 | return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{ |
| 2932 | .ty = ty.ip_index, | 2900 | .ty = ty.toIntern(), |
| 2933 | .storage = .{ .repeated_elem = scalar.ip_index }, | 2901 | .storage = .{ .repeated_elem = scalar.toIntern() }, |
| 2934 | } })).toValue() else scalar; | 2902 | } })).toValue() else scalar; |
| 2935 | } | 2903 | } |
| 2936 | | 2904 | |
| ... | @@ -2971,7 +2939,7 @@ pub const Type = struct { | ... | @@ -2971,7 +2939,7 @@ pub const Type = struct { |
| 2971 | | 2939 | |
| 2972 | /// Asserts the type is an enum or a union. | 2940 | /// Asserts the type is an enum or a union. |
| 2973 | pub fn intTagType(ty: Type, mod: *Module) !Type { | 2941 | pub fn intTagType(ty: Type, mod: *Module) !Type { |
| 2974 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2942 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2975 | .union_type => |union_type| mod.unionPtr(union_type.index).tag_ty.intTagType(mod), | 2943 | .union_type => |union_type| mod.unionPtr(union_type.index).tag_ty.intTagType(mod), |
| 2976 | .enum_type => |enum_type| enum_type.tag_ty.toType(), | 2944 | .enum_type => |enum_type| enum_type.tag_ty.toType(), |
| 2977 | else => unreachable, | 2945 | else => unreachable, |
| ... | @@ -2979,21 +2947,18 @@ pub const Type = struct { | ... | @@ -2979,21 +2947,18 @@ pub const Type = struct { |
| 2979 | } | 2947 | } |
| 2980 | | 2948 | |
| 2981 | pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool { | 2949 | pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool { |
| 2982 | return switch (ty.ip_index) { | 2950 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2983 | .none => false, | 2951 | .enum_type => |enum_type| switch (enum_type.tag_mode) { |
| 2984 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2952 | .nonexhaustive => true, |
| 2985 | .enum_type => |enum_type| switch (enum_type.tag_mode) { | 2953 | .auto, .explicit => false, |
| 2986 | .nonexhaustive => true, | | |
| 2987 | .auto, .explicit => false, | | |
| 2988 | }, | | |
| 2989 | else => false, | | |
| 2990 | }, | 2954 | }, |
| | 2955 | else => false, |
| 2991 | }; | 2956 | }; |
| 2992 | } | 2957 | } |
| 2993 | | 2958 | |
| 2994 | // Asserts that `ty` is an error set and not `anyerror`. | 2959 | // Asserts that `ty` is an error set and not `anyerror`. |
| 2995 | pub fn errorSetNames(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { | 2960 | pub fn errorSetNames(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { |
| 2996 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 2961 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 2997 | .error_set_type => |x| x.names, | 2962 | .error_set_type => |x| x.names, |
| 2998 | .inferred_error_set_type => |index| { | 2963 | .inferred_error_set_type => |index| { |
| 2999 | const inferred_error_set = mod.inferredErrorSetPtr(index); | 2964 | const inferred_error_set = mod.inferredErrorSetPtr(index); |
| ... | @@ -3006,22 +2971,22 @@ pub const Type = struct { | ... | @@ -3006,22 +2971,22 @@ pub const Type = struct { |
| 3006 | } | 2971 | } |
| 3007 | | 2972 | |
| 3008 | pub fn enumFields(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { | 2973 | pub fn enumFields(ty: Type, mod: *Module) []const InternPool.NullTerminatedString { |
| 3009 | return mod.intern_pool.indexToKey(ty.ip_index).enum_type.names; | 2974 | return mod.intern_pool.indexToKey(ty.toIntern()).enum_type.names; |
| 3010 | } | 2975 | } |
| 3011 | | 2976 | |
| 3012 | pub fn enumFieldCount(ty: Type, mod: *Module) usize { | 2977 | pub fn enumFieldCount(ty: Type, mod: *Module) usize { |
| 3013 | return mod.intern_pool.indexToKey(ty.ip_index).enum_type.names.len; | 2978 | return mod.intern_pool.indexToKey(ty.toIntern()).enum_type.names.len; |
| 3014 | } | 2979 | } |
| 3015 | | 2980 | |
| 3016 | pub fn enumFieldName(ty: Type, field_index: usize, mod: *Module) [:0]const u8 { | 2981 | pub fn enumFieldName(ty: Type, field_index: usize, mod: *Module) [:0]const u8 { |
| 3017 | const ip = &mod.intern_pool; | 2982 | const ip = &mod.intern_pool; |
| 3018 | const field_name = ip.indexToKey(ty.ip_index).enum_type.names[field_index]; | 2983 | const field_name = ip.indexToKey(ty.toIntern()).enum_type.names[field_index]; |
| 3019 | return ip.stringToSlice(field_name); | 2984 | return ip.stringToSlice(field_name); |
| 3020 | } | 2985 | } |
| 3021 | | 2986 | |
| 3022 | pub fn enumFieldIndex(ty: Type, field_name: []const u8, mod: *Module) ?u32 { | 2987 | pub fn enumFieldIndex(ty: Type, field_name: []const u8, mod: *Module) ?u32 { |
| 3023 | const ip = &mod.intern_pool; | 2988 | const ip = &mod.intern_pool; |
| 3024 | const enum_type = ip.indexToKey(ty.ip_index).enum_type; | 2989 | const enum_type = ip.indexToKey(ty.toIntern()).enum_type; |
| 3025 | // If the string is not interned, then the field certainly is not present. | 2990 | // If the string is not interned, then the field certainly is not present. |
| 3026 | const field_name_interned = ip.getString(field_name).unwrap() orelse return null; | 2991 | const field_name_interned = ip.getString(field_name).unwrap() orelse return null; |
| 3027 | return enum_type.nameIndex(ip, field_name_interned); | 2992 | return enum_type.nameIndex(ip, field_name_interned); |
| ... | @@ -3032,9 +2997,9 @@ pub const Type = struct { | ... | @@ -3032,9 +2997,9 @@ pub const Type = struct { |
| 3032 | /// declaration order, or `null` if `enum_tag` does not match any field. | 2997 | /// declaration order, or `null` if `enum_tag` does not match any field. |
| 3033 | pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 { | 2998 | pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 { |
| 3034 | const ip = &mod.intern_pool; | 2999 | const ip = &mod.intern_pool; |
| 3035 | const enum_type = ip.indexToKey(ty.ip_index).enum_type; | 3000 | const enum_type = ip.indexToKey(ty.toIntern()).enum_type; |
| 3036 | const int_tag = switch (ip.indexToKey(enum_tag.ip_index)) { | 3001 | const int_tag = switch (ip.indexToKey(enum_tag.toIntern())) { |
| 3037 | .int => enum_tag.ip_index, | 3002 | .int => enum_tag.toIntern(), |
| 3038 | .enum_tag => |info| info.int, | 3003 | .enum_tag => |info| info.int, |
| 3039 | else => unreachable, | 3004 | else => unreachable, |
| 3040 | }; | 3005 | }; |
| ... | @@ -3043,7 +3008,7 @@ pub const Type = struct { | ... | @@ -3043,7 +3008,7 @@ pub const Type = struct { |
| 3043 | } | 3008 | } |
| 3044 | | 3009 | |
| 3045 | pub fn structFields(ty: Type, mod: *Module) Module.Struct.Fields { | 3010 | pub fn structFields(ty: Type, mod: *Module) Module.Struct.Fields { |
| 3046 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3011 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3047 | .struct_type => |struct_type| { | 3012 | .struct_type => |struct_type| { |
| 3048 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return .{}; | 3013 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return .{}; |
| 3049 | assert(struct_obj.haveFieldTypes()); | 3014 | assert(struct_obj.haveFieldTypes()); |
| ... | @@ -3054,7 +3019,7 @@ pub const Type = struct { | ... | @@ -3054,7 +3019,7 @@ pub const Type = struct { |
| 3054 | } | 3019 | } |
| 3055 | | 3020 | |
| 3056 | pub fn structFieldName(ty: Type, field_index: usize, mod: *Module) []const u8 { | 3021 | pub fn structFieldName(ty: Type, field_index: usize, mod: *Module) []const u8 { |
| 3057 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3022 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3058 | .struct_type => |struct_type| { | 3023 | .struct_type => |struct_type| { |
| 3059 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3024 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3060 | assert(struct_obj.haveFieldTypes()); | 3025 | assert(struct_obj.haveFieldTypes()); |
| ... | @@ -3069,7 +3034,7 @@ pub const Type = struct { | ... | @@ -3069,7 +3034,7 @@ pub const Type = struct { |
| 3069 | } | 3034 | } |
| 3070 | | 3035 | |
| 3071 | pub fn structFieldCount(ty: Type, mod: *Module) usize { | 3036 | pub fn structFieldCount(ty: Type, mod: *Module) usize { |
| 3072 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3037 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3073 | .struct_type => |struct_type| { | 3038 | .struct_type => |struct_type| { |
| 3074 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return 0; | 3039 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return 0; |
| 3075 | assert(struct_obj.haveFieldTypes()); | 3040 | assert(struct_obj.haveFieldTypes()); |
| ... | @@ -3082,7 +3047,7 @@ pub const Type = struct { | ... | @@ -3082,7 +3047,7 @@ pub const Type = struct { |
| 3082 | | 3047 | |
| 3083 | /// Supports structs and unions. | 3048 | /// Supports structs and unions. |
| 3084 | pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type { | 3049 | pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type { |
| 3085 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3050 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3086 | .struct_type => |struct_type| { | 3051 | .struct_type => |struct_type| { |
| 3087 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3052 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3088 | return struct_obj.fields.values()[index].ty; | 3053 | return struct_obj.fields.values()[index].ty; |
| ... | @@ -3097,7 +3062,7 @@ pub const Type = struct { | ... | @@ -3097,7 +3062,7 @@ pub const Type = struct { |
| 3097 | } | 3062 | } |
| 3098 | | 3063 | |
| 3099 | pub fn structFieldAlign(ty: Type, index: usize, mod: *Module) u32 { | 3064 | pub fn structFieldAlign(ty: Type, index: usize, mod: *Module) u32 { |
| 3100 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3065 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3101 | .struct_type => |struct_type| { | 3066 | .struct_type => |struct_type| { |
| 3102 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3067 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3103 | assert(struct_obj.layout != .Packed); | 3068 | assert(struct_obj.layout != .Packed); |
| ... | @@ -3115,7 +3080,7 @@ pub const Type = struct { | ... | @@ -3115,7 +3080,7 @@ pub const Type = struct { |
| 3115 | } | 3080 | } |
| 3116 | | 3081 | |
| 3117 | pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value { | 3082 | pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value { |
| 3118 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3083 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3119 | .struct_type => |struct_type| { | 3084 | .struct_type => |struct_type| { |
| 3120 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3085 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3121 | return struct_obj.fields.values()[index].default_val; | 3086 | return struct_obj.fields.values()[index].default_val; |
| ... | @@ -3131,7 +3096,7 @@ pub const Type = struct { | ... | @@ -3131,7 +3096,7 @@ pub const Type = struct { |
| 3131 | } | 3096 | } |
| 3132 | | 3097 | |
| 3133 | pub fn structFieldValueComptime(ty: Type, mod: *Module, index: usize) !?Value { | 3098 | pub fn structFieldValueComptime(ty: Type, mod: *Module, index: usize) !?Value { |
| 3134 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3099 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3135 | .struct_type => |struct_type| { | 3100 | .struct_type => |struct_type| { |
| 3136 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3101 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3137 | const field = struct_obj.fields.values()[index]; | 3102 | const field = struct_obj.fields.values()[index]; |
| ... | @@ -3154,7 +3119,7 @@ pub const Type = struct { | ... | @@ -3154,7 +3119,7 @@ pub const Type = struct { |
| 3154 | } | 3119 | } |
| 3155 | | 3120 | |
| 3156 | pub fn structFieldIsComptime(ty: Type, index: usize, mod: *Module) bool { | 3121 | pub fn structFieldIsComptime(ty: Type, index: usize, mod: *Module) bool { |
| 3157 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3122 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3158 | .struct_type => |struct_type| { | 3123 | .struct_type => |struct_type| { |
| 3159 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3124 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3160 | if (struct_obj.layout == .Packed) return false; | 3125 | if (struct_obj.layout == .Packed) return false; |
| ... | @@ -3167,7 +3132,7 @@ pub const Type = struct { | ... | @@ -3167,7 +3132,7 @@ pub const Type = struct { |
| 3167 | } | 3132 | } |
| 3168 | | 3133 | |
| 3169 | pub fn packedStructFieldByteOffset(ty: Type, field_index: usize, mod: *Module) u32 { | 3134 | pub fn packedStructFieldByteOffset(ty: Type, field_index: usize, mod: *Module) u32 { |
| 3170 | const struct_type = mod.intern_pool.indexToKey(ty.ip_index).struct_type; | 3135 | const struct_type = mod.intern_pool.indexToKey(ty.toIntern()).struct_type; |
| 3171 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3136 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3172 | assert(struct_obj.layout == .Packed); | 3137 | assert(struct_obj.layout == .Packed); |
| 3173 | comptime assert(Type.packed_struct_layout_version == 2); | 3138 | comptime assert(Type.packed_struct_layout_version == 2); |
| ... | @@ -3229,7 +3194,7 @@ pub const Type = struct { | ... | @@ -3229,7 +3194,7 @@ pub const Type = struct { |
| 3229 | /// Get an iterator that iterates over all the struct field, returning the field and | 3194 | /// Get an iterator that iterates over all the struct field, returning the field and |
| 3230 | /// offset of that field. Asserts that the type is a non-packed struct. | 3195 | /// offset of that field. Asserts that the type is a non-packed struct. |
| 3231 | pub fn iterateStructOffsets(ty: Type, mod: *Module) StructOffsetIterator { | 3196 | pub fn iterateStructOffsets(ty: Type, mod: *Module) StructOffsetIterator { |
| 3232 | const struct_type = mod.intern_pool.indexToKey(ty.ip_index).struct_type; | 3197 | const struct_type = mod.intern_pool.indexToKey(ty.toIntern()).struct_type; |
| 3233 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3198 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3234 | assert(struct_obj.haveLayout()); | 3199 | assert(struct_obj.haveLayout()); |
| 3235 | assert(struct_obj.layout != .Packed); | 3200 | assert(struct_obj.layout != .Packed); |
| ... | @@ -3238,7 +3203,7 @@ pub const Type = struct { | ... | @@ -3238,7 +3203,7 @@ pub const Type = struct { |
| 3238 | | 3203 | |
| 3239 | /// Supports structs and unions. | 3204 | /// Supports structs and unions. |
| 3240 | pub fn structFieldOffset(ty: Type, index: usize, mod: *Module) u64 { | 3205 | pub fn structFieldOffset(ty: Type, index: usize, mod: *Module) u64 { |
| 3241 | switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3206 | switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3242 | .struct_type => |struct_type| { | 3207 | .struct_type => |struct_type| { |
| 3243 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3208 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3244 | assert(struct_obj.haveLayout()); | 3209 | assert(struct_obj.haveLayout()); |
| ... | @@ -3296,7 +3261,7 @@ pub const Type = struct { | ... | @@ -3296,7 +3261,7 @@ pub const Type = struct { |
| 3296 | } | 3261 | } |
| 3297 | | 3262 | |
| 3298 | pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { | 3263 | pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc { |
| 3299 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3264 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3300 | .struct_type => |struct_type| { | 3265 | .struct_type => |struct_type| { |
| 3301 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; | 3266 | const struct_obj = mod.structPtrUnwrap(struct_type.index).?; |
| 3302 | return struct_obj.srcLoc(mod); | 3267 | return struct_obj.srcLoc(mod); |
| ... | @@ -3316,7 +3281,7 @@ pub const Type = struct { | ... | @@ -3316,7 +3281,7 @@ pub const Type = struct { |
| 3316 | } | 3281 | } |
| 3317 | | 3282 | |
| 3318 | pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index { | 3283 | pub fn getOwnerDeclOrNull(ty: Type, mod: *Module) ?Module.Decl.Index { |
| 3319 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3284 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3320 | .struct_type => |struct_type| { | 3285 | .struct_type => |struct_type| { |
| 3321 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return null; | 3286 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return null; |
| 3322 | return struct_obj.owner_decl; | 3287 | return struct_obj.owner_decl; |
| ... | @@ -3332,33 +3297,30 @@ pub const Type = struct { | ... | @@ -3332,33 +3297,30 @@ pub const Type = struct { |
| 3332 | } | 3297 | } |
| 3333 | | 3298 | |
| 3334 | pub fn isGenericPoison(ty: Type) bool { | 3299 | pub fn isGenericPoison(ty: Type) bool { |
| 3335 | return ty.ip_index == .generic_poison_type; | 3300 | return ty.toIntern() == .generic_poison_type; |
| 3336 | } | 3301 | } |
| 3337 | | 3302 | |
| 3338 | pub fn isTuple(ty: Type, mod: *Module) bool { | 3303 | pub fn isTuple(ty: Type, mod: *Module) bool { |
| 3339 | return switch (ty.ip_index) { | 3304 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3340 | .none => false, | 3305 | .struct_type => |struct_type| { |
| 3341 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3306 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return false; |
| 3342 | .struct_type => |struct_type| { | 3307 | return struct_obj.is_tuple; |
| 3343 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return false; | | |
| 3344 | return struct_obj.is_tuple; | | |
| 3345 | }, | | |
| 3346 | .anon_struct_type => |anon_struct| anon_struct.names.len == 0, | | |
| 3347 | else => false, | | |
| 3348 | }, | 3308 | }, |
| | 3309 | .anon_struct_type => |anon_struct| anon_struct.names.len == 0, |
| | 3310 | else => false, |
| 3349 | }; | 3311 | }; |
| 3350 | } | 3312 | } |
| 3351 | | 3313 | |
| 3352 | pub fn isAnonStruct(ty: Type, mod: *Module) bool { | 3314 | pub fn isAnonStruct(ty: Type, mod: *Module) bool { |
| 3353 | if (ty.ip_index == .empty_struct_type) return true; | 3315 | if (ty.toIntern() == .empty_struct_type) return true; |
| 3354 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3316 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3355 | .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0, | 3317 | .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0, |
| 3356 | else => false, | 3318 | else => false, |
| 3357 | }; | 3319 | }; |
| 3358 | } | 3320 | } |
| 3359 | | 3321 | |
| 3360 | pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool { | 3322 | pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool { |
| 3361 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3323 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3362 | .struct_type => |struct_type| { | 3324 | .struct_type => |struct_type| { |
| 3363 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return false; | 3325 | const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return false; |
| 3364 | return struct_obj.is_tuple; | 3326 | return struct_obj.is_tuple; |
| ... | @@ -3369,14 +3331,14 @@ pub const Type = struct { | ... | @@ -3369,14 +3331,14 @@ pub const Type = struct { |
| 3369 | } | 3331 | } |
| 3370 | | 3332 | |
| 3371 | pub fn isSimpleTuple(ty: Type, mod: *Module) bool { | 3333 | pub fn isSimpleTuple(ty: Type, mod: *Module) bool { |
| 3372 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3334 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3373 | .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0, | 3335 | .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0, |
| 3374 | else => false, | 3336 | else => false, |
| 3375 | }; | 3337 | }; |
| 3376 | } | 3338 | } |
| 3377 | | 3339 | |
| 3378 | pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool { | 3340 | pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool { |
| 3379 | return switch (mod.intern_pool.indexToKey(ty.ip_index)) { | 3341 | return switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 3380 | .anon_struct_type => true, | 3342 | .anon_struct_type => true, |
| 3381 | else => false, | 3343 | else => false, |
| 3382 | }; | 3344 | }; |