@@ -55,7 +55,7 @@ Alignment IRGenModule::getCappedAlignment(Alignment align) {
55
55
return std::min (align, Alignment (MaximumAlignment));
56
56
}
57
57
58
- llvm::DenseMap<TypeBase*, TypeCacheEntry > &
58
+ llvm::DenseMap<TypeBase *, const TypeInfo * > &
59
59
TypeConverter::Types_t::getCacheFor (bool isDependent, bool completelyFragile) {
60
60
if (completelyFragile) {
61
61
return (isDependent
@@ -1128,12 +1128,13 @@ GenericEnvironment *IRGenModule::getGenericEnvironment() {
1128
1128
1129
1129
// / Add a temporary forward declaration for a type. This will live
1130
1130
// / only until a proper mapping is added.
1131
- void TypeConverter::addForwardDecl (TypeBase *key, llvm::Type *type ) {
1131
+ void TypeConverter::addForwardDecl (TypeBase *key) {
1132
1132
assert (key->isCanonical ());
1133
1133
assert (!key->hasTypeParameter ());
1134
1134
auto &Cache = Types.getCacheFor (/* isDependent*/ false , CompletelyFragile);
1135
- assert (!Cache.count (key) && " entry already exists for type!" );
1136
- Cache.insert (std::make_pair (key, type));
1135
+ auto result = Cache.insert (std::make_pair (key, nullptr ));
1136
+ assert (result.second && " entry already exists for type!" );
1137
+ (void ) result;
1137
1138
}
1138
1139
1139
1140
const TypeInfo &IRGenModule::getWitnessTablePtrTypeInfo () {
@@ -1322,17 +1323,9 @@ llvm::Type *IRGenModule::getStorageType(SILType T) {
1322
1323
return getStorageTypeForLowered (T.getASTType ());
1323
1324
}
1324
1325
1325
- // / Get the storage type for the given type. Note that, unlike
1326
- // / fetching the type info and asking it for the storage type, this
1327
- // / operation will succeed for forward-declarations.
1326
+ // / Get the storage type for the given type.
1328
1327
llvm::Type *IRGenModule::getStorageTypeForLowered (CanType T) {
1329
- // TODO: we can avoid creating entries for some obvious cases here.
1330
- auto entry = Types.getTypeEntry (T);
1331
- if (auto ti = entry.dyn_cast <const TypeInfo*>()) {
1332
- return ti->getStorageType ();
1333
- } else {
1334
- return entry.get <llvm::Type*>();
1335
- }
1328
+ return Types.getTypeEntry (T)->getStorageType ();
1336
1329
}
1337
1330
1338
1331
// / Get the type information for the given type, which may not have
@@ -1370,9 +1363,7 @@ const TypeInfo &IRGenModule::getTypeInfoForLowered(CanType T) {
1370
1363
1371
1364
// /
1372
1365
const TypeInfo &TypeConverter::getCompleteTypeInfo (CanType T) {
1373
- auto entry = getTypeEntry (T);
1374
- assert (entry.is <const TypeInfo*>() && " getting TypeInfo recursively!" );
1375
- return *entry.get <const TypeInfo*>();
1366
+ return *getTypeEntry (T);
1376
1367
}
1377
1368
1378
1369
ArchetypeType *TypeConverter::getExemplarArchetype (ArchetypeType *t) {
@@ -1428,7 +1419,7 @@ void TypeConverter::popCompletelyFragile() {
1428
1419
CompletelyFragile = false ;
1429
1420
}
1430
1421
1431
- TypeCacheEntry TypeConverter::getTypeEntry (CanType canonicalTy) {
1422
+ const TypeInfo * TypeConverter::getTypeEntry (CanType canonicalTy) {
1432
1423
// Cache this entry in the dependent or independent cache appropriate to it.
1433
1424
auto &Cache = Types.getCacheFor (canonicalTy->hasTypeParameter (),
1434
1425
CompletelyFragile);
@@ -1471,10 +1462,8 @@ TypeCacheEntry TypeConverter::getTypeEntry(CanType canonicalTy) {
1471
1462
1472
1463
// Cache the entry under the original type and the exemplar type, so that
1473
1464
// we can avoid relowering equivalent types.
1474
- auto insertEntry = [&](TypeCacheEntry &entry) {
1475
- assert (entry == TypeCacheEntry () ||
1476
- (entry.is <llvm::Type*>() &&
1477
- entry.get <llvm::Type*>() == convertedTI->getStorageType ()));
1465
+ auto insertEntry = [&](const TypeInfo *&entry) {
1466
+ assert (entry == nullptr );
1478
1467
entry = convertedTI;
1479
1468
};
1480
1469
insertEntry (Cache[canonicalTy.getPointer ()]);
@@ -1711,10 +1700,10 @@ TypeConverter::convert##Name##StorageType(Name##StorageType *refType) { \
1711
1700
}
1712
1701
#include " swift/AST/ReferenceStorage.def"
1713
1702
1714
- static void overwriteForwardDecl (llvm::DenseMap<TypeBase*, TypeCacheEntry > &cache,
1703
+ static void overwriteForwardDecl (llvm::DenseMap<TypeBase *, const TypeInfo * > &cache,
1715
1704
TypeBase *key, const TypeInfo *result) {
1716
1705
assert (cache.count (key) && " no forward declaration?" );
1717
- assert (cache[key]. is <llvm::Type*>() && " overwriting real entry!" );
1706
+ assert (cache[key] == nullptr && " overwriting real entry!" );
1718
1707
cache[key] = result;
1719
1708
}
1720
1709
@@ -1863,7 +1852,7 @@ const TypeInfo *TypeConverter::convertAnyNominalType(CanType type,
1863
1852
auto &Cache = Types.getCacheFor (/* isDependent*/ false , CompletelyFragile);
1864
1853
auto entry = Cache.find (key);
1865
1854
if (entry != Cache.end ())
1866
- return entry->second . get < const TypeInfo *>() ;
1855
+ return entry->second ;
1867
1856
1868
1857
switch (decl->getKind ()) {
1869
1858
#define NOMINAL_TYPE_DECL (ID, PARENT )
0 commit comments