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