@@ -317,12 +317,12 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
317
317
llvm::DenseMap<std::pair<Type, void *>, DependentMemberType *>
318
318
DependentMemberTypes;
319
319
llvm::DenseMap<Type, DynamicSelfType *> DynamicSelfTypes;
320
- llvm::FoldingSet<EnumType> EnumTypes;
321
- llvm::FoldingSet<StructType> StructTypes;
322
- llvm::FoldingSet<ClassType> ClassTypes;
320
+ llvm::DenseMap<std::pair<EnumDecl*, Type>, EnumType*> EnumTypes;
321
+ llvm::DenseMap<std::pair<StructDecl*, Type>, StructType*> StructTypes;
322
+ llvm::DenseMap<std::pair<ClassDecl*, Type>, ClassType*> ClassTypes;
323
+ llvm::DenseMap<std::pair<ProtocolDecl*, Type>, ProtocolType*> ProtocolTypes;
323
324
llvm::FoldingSet<UnboundGenericType> UnboundGenericTypes;
324
325
llvm::FoldingSet<BoundGenericType> BoundGenericTypes;
325
- llvm::FoldingSet<ProtocolType> ProtocolTypes;
326
326
llvm::FoldingSet<ProtocolCompositionType> ProtocolCompositionTypes;
327
327
llvm::FoldingSet<LayoutConstraintInfo> LayoutConstraints;
328
328
@@ -2093,11 +2093,12 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
2093
2093
llvm::capacity_in_bytes (LValueTypes) +
2094
2094
llvm::capacity_in_bytes (InOutTypes) +
2095
2095
llvm::capacity_in_bytes (DependentMemberTypes) +
2096
+ llvm::capacity_in_bytes (EnumTypes) +
2097
+ llvm::capacity_in_bytes (StructTypes) +
2098
+ llvm::capacity_in_bytes (ClassTypes) +
2099
+ llvm::capacity_in_bytes (ProtocolTypes) +
2096
2100
llvm::capacity_in_bytes (DynamicSelfTypes);
2097
2101
// FunctionTypes ?
2098
- // EnumTypes ?
2099
- // StructTypes ?
2100
- // ClassTypes ?
2101
2102
// UnboundGenericTypes ?
2102
2103
// BoundGenericTypes ?
2103
2104
// NormalConformances ?
@@ -3362,80 +3363,47 @@ EnumType::EnumType(EnumDecl *TheDecl, Type Parent, const ASTContext &C,
3362
3363
: NominalType(TypeKind::Enum, &C, TheDecl, Parent, properties) { }
3363
3364
3364
3365
EnumType *EnumType::get (EnumDecl *D, Type Parent, const ASTContext &C) {
3365
- llvm::FoldingSetNodeID id;
3366
- EnumType::Profile (id, D, Parent);
3367
-
3368
3366
RecursiveTypeProperties properties;
3369
3367
if (Parent) properties |= Parent->getRecursiveProperties ();
3370
3368
auto arena = getArena (properties);
3371
3369
3372
- void *insertPos = nullptr ;
3373
- if (auto enumTy
3374
- = C.getImpl ().getArena (arena).EnumTypes .FindNodeOrInsertPos (id, insertPos))
3375
- return enumTy;
3376
-
3377
- auto enumTy = new (C, arena) EnumType (D, Parent, C, properties);
3378
- C.getImpl ().getArena (arena).EnumTypes .InsertNode (enumTy, insertPos);
3379
- return enumTy;
3380
- }
3381
-
3382
- void EnumType::Profile (llvm::FoldingSetNodeID &ID, EnumDecl *D, Type Parent) {
3383
- ID.AddPointer (D);
3384
- ID.AddPointer (Parent.getPointer ());
3370
+ auto *&known = C.getImpl ().getArena (arena).EnumTypes [{D, Parent}];
3371
+ if (!known) {
3372
+ known = new (C, arena) EnumType (D, Parent, C, properties);
3373
+ }
3374
+ return known;
3385
3375
}
3386
3376
3387
3377
StructType::StructType (StructDecl *TheDecl, Type Parent, const ASTContext &C,
3388
3378
RecursiveTypeProperties properties)
3389
3379
: NominalType(TypeKind::Struct, &C, TheDecl, Parent, properties) { }
3390
3380
3391
3381
StructType *StructType::get (StructDecl *D, Type Parent, const ASTContext &C) {
3392
- llvm::FoldingSetNodeID id;
3393
- StructType::Profile (id, D, Parent);
3394
-
3395
3382
RecursiveTypeProperties properties;
3396
3383
if (Parent) properties |= Parent->getRecursiveProperties ();
3397
3384
auto arena = getArena (properties);
3398
3385
3399
- void *insertPos = nullptr ;
3400
- if (auto structTy
3401
- = C.getImpl ().getArena (arena).StructTypes .FindNodeOrInsertPos (id, insertPos))
3402
- return structTy;
3403
-
3404
- auto structTy = new (C, arena) StructType (D, Parent, C, properties);
3405
- C.getImpl ().getArena (arena).StructTypes .InsertNode (structTy, insertPos);
3406
- return structTy;
3407
- }
3408
-
3409
- void StructType::Profile (llvm::FoldingSetNodeID &ID, StructDecl *D, Type Parent) {
3410
- ID.AddPointer (D);
3411
- ID.AddPointer (Parent.getPointer ());
3386
+ auto *&known = C.getImpl ().getArena (arena).StructTypes [{D, Parent}];
3387
+ if (!known) {
3388
+ known = new (C, arena) StructType (D, Parent, C, properties);
3389
+ }
3390
+ return known;
3412
3391
}
3413
3392
3414
3393
ClassType::ClassType (ClassDecl *TheDecl, Type Parent, const ASTContext &C,
3415
3394
RecursiveTypeProperties properties)
3416
3395
: NominalType(TypeKind::Class, &C, TheDecl, Parent, properties) { }
3417
3396
3418
3397
ClassType *ClassType::get (ClassDecl *D, Type Parent, const ASTContext &C) {
3419
- llvm::FoldingSetNodeID id;
3420
- ClassType::Profile (id, D, Parent);
3421
-
3422
3398
RecursiveTypeProperties properties;
3423
3399
if (Parent) properties |= Parent->getRecursiveProperties ();
3424
3400
auto arena = getArena (properties);
3425
3401
3426
- void *insertPos = nullptr ;
3427
- if (auto classTy
3428
- = C.getImpl ().getArena (arena).ClassTypes .FindNodeOrInsertPos (id, insertPos))
3429
- return classTy;
3430
-
3431
- auto classTy = new (C, arena) ClassType (D, Parent, C, properties);
3432
- C.getImpl ().getArena (arena).ClassTypes .InsertNode (classTy, insertPos);
3433
- return classTy;
3434
- }
3435
-
3436
- void ClassType::Profile (llvm::FoldingSetNodeID &ID, ClassDecl *D, Type Parent) {
3437
- ID.AddPointer (D);
3438
- ID.AddPointer (Parent.getPointer ());
3402
+ auto *&known = C.getImpl ().getArena (arena).ClassTypes [{D, Parent}];
3403
+ if (!known) {
3404
+ known = new (C, arena) ClassType (D, Parent, C, properties);
3405
+ }
3406
+ return known;
3439
3407
}
3440
3408
3441
3409
ProtocolCompositionType *
@@ -4171,35 +4139,22 @@ OptionalType *OptionalType::get(Type base) {
4171
4139
4172
4140
ProtocolType *ProtocolType::get (ProtocolDecl *D, Type Parent,
4173
4141
const ASTContext &C) {
4174
- llvm::FoldingSetNodeID id;
4175
- ProtocolType::Profile (id, D, Parent);
4176
-
4177
4142
RecursiveTypeProperties properties;
4178
4143
if (Parent) properties |= Parent->getRecursiveProperties ();
4179
4144
auto arena = getArena (properties);
4180
4145
4181
- void *insertPos = nullptr ;
4182
- if (auto protoTy
4183
- = C.getImpl ().getArena (arena).ProtocolTypes .FindNodeOrInsertPos (id, insertPos))
4184
- return protoTy;
4185
-
4186
- auto protoTy = new (C, arena) ProtocolType (D, Parent, C, properties);
4187
- C.getImpl ().getArena (arena).ProtocolTypes .InsertNode (protoTy, insertPos);
4188
-
4189
- return protoTy;
4146
+ auto *&known = C.getImpl ().getArena (arena).ProtocolTypes [{D, Parent}];
4147
+ if (!known) {
4148
+ known = new (C, arena) ProtocolType (D, Parent, C, properties);
4149
+ }
4150
+ return known;
4190
4151
}
4191
4152
4192
4153
ProtocolType::ProtocolType (ProtocolDecl *TheDecl, Type Parent,
4193
4154
const ASTContext &Ctx,
4194
4155
RecursiveTypeProperties properties)
4195
4156
: NominalType(TypeKind::Protocol, &Ctx, TheDecl, Parent, properties) { }
4196
4157
4197
- void ProtocolType::Profile (llvm::FoldingSetNodeID &ID, ProtocolDecl *D,
4198
- Type Parent) {
4199
- ID.AddPointer (D);
4200
- ID.AddPointer (Parent.getPointer ());
4201
- }
4202
-
4203
4158
LValueType *LValueType::get (Type objectTy) {
4204
4159
assert (!objectTy->hasError () &&
4205
4160
" cannot have ErrorType wrapped inside LValueType" );
0 commit comments