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