@@ -430,6 +430,7 @@ struct ASTContext::Implementation {
430
430
llvm::DenseMap<Type, InOutType*> InOutTypes;
431
431
llvm::DenseMap<std::pair<Type, void *>, DependentMemberType *>
432
432
DependentMemberTypes;
433
+ llvm::DenseMap<void *, PlaceholderType *> PlaceholderTypes;
433
434
llvm::DenseMap<Type, DynamicSelfType *> DynamicSelfTypes;
434
435
llvm::DenseMap<std::pair<EnumDecl*, Type>, EnumType*> EnumTypes;
435
436
llvm::DenseMap<std::pair<StructDecl*, Type>, StructType*> StructTypes;
@@ -3124,8 +3125,27 @@ Type ErrorType::get(Type originalType) {
3124
3125
3125
3126
Type PlaceholderType::get (ASTContext &ctx, Originator originator) {
3126
3127
assert (originator);
3127
- return new (ctx, AllocationArena::Permanent)
3128
+
3129
+ auto hasTypeVariables = [&]() -> bool {
3130
+ if (originator.is <TypeVariableType *>())
3131
+ return true ;
3132
+
3133
+ if (auto *depTy = originator.dyn_cast <DependentMemberType *>())
3134
+ return depTy->hasTypeVariable ();
3135
+
3136
+ return false ;
3137
+ }();
3138
+ auto arena = hasTypeVariables ? AllocationArena::ConstraintSolver
3139
+ : AllocationArena::Permanent;
3140
+
3141
+ auto &cache = ctx.getImpl ().getArena (arena).PlaceholderTypes ;
3142
+ auto &entry = cache[originator.getOpaqueValue ()];
3143
+ if (entry)
3144
+ return entry;
3145
+
3146
+ entry = new (ctx, arena)
3128
3147
PlaceholderType (ctx, originator, RecursiveTypeProperties::HasPlaceholder);
3148
+ return entry;
3129
3149
}
3130
3150
3131
3151
BuiltinIntegerType *BuiltinIntegerType::get (BuiltinIntegerWidth BitWidth,
0 commit comments