@@ -457,10 +457,6 @@ struct ASTContext::Implementation {
457
457
// / The single-parameter generic signature with no constraints, <T>.
458
458
CanGenericSignature SingleGenericParameterSignature;
459
459
460
- // / The existential signature <T : P> for each P.
461
- llvm::DenseMap<std::pair<CanType, const GenericSignatureImpl *>, CanGenericSignature>
462
- ExistentialSignatures;
463
-
464
460
// / The element signature for a generic signature, which contains a clone
465
461
// / of the context generic signature with new type parameters and requirements
466
462
// / for opened pack elements in the given shape equivalence class.
@@ -851,7 +847,6 @@ void ASTContext::Implementation::dump(llvm::raw_ostream &os) const {
851
847
SIZE_AND_BYTES (AssociativityCache);
852
848
SIZE_AND_BYTES (DelayedConformanceDiags);
853
849
SIZE_AND_BYTES (LazyContexts);
854
- SIZE_AND_BYTES (ExistentialSignatures);
855
850
SIZE_AND_BYTES (ElementSignatures);
856
851
SIZE_AND_BYTES (Overrides);
857
852
SIZE_AND_BYTES (DefaultWitnesses);
@@ -5342,22 +5337,21 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
5342
5337
5343
5338
CanOpenedArchetypeType OpenedArchetypeType::get (CanType existential,
5344
5339
std::optional<UUID> knownID) {
5345
- assert (existential->isExistentialType ());
5346
- assert (!existential->hasTypeParameter ());
5347
-
5348
- auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext (
5349
- GenericSignature (), existential->getASTContext ());
5340
+ auto &ctx = existential->getASTContext ();
5341
+ auto existentialSig = ctx.getOpenedExistentialSignature (existential);
5350
5342
5351
5343
if (!knownID)
5352
5344
knownID = UUID::fromTime ();
5353
5345
5354
5346
auto *genericEnv = GenericEnvironment::forOpenedExistential (
5355
- existential, *knownID);
5347
+ existentialSig.OpenedSig ,
5348
+ existentialSig.Shape ,
5349
+ existentialSig.Generalization ,
5350
+ *knownID);
5356
5351
5357
- // Map the interface type into that environment.
5358
- auto result = genericEnv->mapTypeIntoContext (interfaceType)
5359
- ->castTo <OpenedArchetypeType>();
5360
- return CanOpenedArchetypeType (result);
5352
+ return cast<OpenedArchetypeType>(
5353
+ genericEnv->mapTypeIntoContext (existentialSig.SelfType )
5354
+ ->getCanonicalType ());
5361
5355
}
5362
5356
5363
5357
Type OpenedArchetypeType::getAny (Type existential) {
@@ -5547,8 +5541,10 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
5547
5541
GenericEnvironment *
5548
5542
GenericEnvironment::forOpenedExistential (Type existential, UUID uuid) {
5549
5543
auto &ctx = existential->getASTContext ();
5550
- auto signature = ctx.getOpenedExistentialSignature (existential, GenericSignature ());
5551
- return forOpenedExistential (signature, existential, SubstitutionMap (), uuid);
5544
+ auto existentialSig = ctx.getOpenedExistentialSignature (existential);
5545
+ return forOpenedExistential (existentialSig.OpenedSig ,
5546
+ existentialSig.Shape ,
5547
+ existentialSig.Generalization , uuid);
5552
5548
}
5553
5549
5554
5550
// / Create a new generic environment for an opened archetype.
@@ -6136,83 +6132,51 @@ CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
6136
6132
return canonicalSig;
6137
6133
}
6138
6134
6139
- Type OpenedArchetypeType::getSelfInterfaceTypeFromContext (GenericSignature parentSig,
6140
- ASTContext &ctx) {
6141
- return GenericTypeParamType::get (/* isParameterPack=*/ false ,
6142
- parentSig.getNextDepth (), /* index=*/ 0 ,
6143
- ctx);
6144
- }
6145
-
6146
- CanGenericSignature
6147
- ASTContext::getOpenedExistentialSignature (Type type, GenericSignature parentSig) {
6148
- assert (type->isExistentialType ());
6149
-
6150
- if (auto existential = type->getAs <ExistentialType>())
6151
- type = existential->getConstraintType ();
6152
-
6153
- const CanType constraint = type->getCanonicalType ();
6154
-
6155
- auto canParentSig = parentSig.getCanonicalSignature ();
6156
- auto key = std::make_pair (constraint, canParentSig.getPointer ());
6157
- auto found = getImpl ().ExistentialSignatures .find (key);
6158
- if (found != getImpl ().ExistentialSignatures .end ())
6159
- return found->second ;
6160
-
6161
- LocalArchetypeRequirementCollector collector (*this , canParentSig);
6162
- collector.addOpenedExistential (type);
6163
- auto genericSig = buildGenericSignature (
6164
- *this , collector.OuterSig , collector.Params , collector.Requirements ,
6165
- /* allowInverses=*/ true ).getCanonicalSignature ();
6166
-
6167
- auto result = getImpl ().ExistentialSignatures .insert (
6168
- std::make_pair (key, genericSig));
6169
- ASSERT (result.second );
6170
-
6171
- return genericSig;
6172
- }
6173
-
6174
6135
OpenedExistentialSignature
6175
6136
ASTContext::getOpenedExistentialSignature (Type type) {
6176
6137
assert (type->isExistentialType ());
6177
6138
6178
- if (auto existential = type->getAs <ExistentialType>())
6179
- type = existential->getConstraintType ();
6180
-
6181
- const CanType constraint = type->getCanonicalType ();
6139
+ auto canType = type->getCanonicalType ();
6182
6140
6183
6141
// The constraint type might contain type variables.
6184
- auto properties = constraint ->getRecursiveProperties ();
6142
+ auto properties = canType ->getRecursiveProperties ();
6185
6143
auto arena = getArena (properties);
6186
6144
6187
6145
// Check the cache.
6188
6146
const auto &sigs = getImpl ().getArena (arena).ExistentialSignatures ;
6189
- auto found = sigs.find (constraint );
6147
+ auto found = sigs.find (canType );
6190
6148
if (found != sigs.end ())
6191
6149
return found->second ;
6192
6150
6193
6151
OpenedExistentialSignature existentialSig;
6194
6152
6195
6153
// Generalize the existential type, to move type variables and primary
6196
6154
// archetypes into the substitution map.
6197
- auto gen = ExistentialTypeGeneralization::get (constraint);
6155
+ auto gen = ExistentialTypeGeneralization::get (canType);
6156
+
6198
6157
existentialSig.Shape = gen.Shape ->getCanonicalType ();
6199
6158
existentialSig.Generalization = gen.Generalization ;
6200
6159
6201
6160
// Now, we have an existential type written with type parameters only.
6202
6161
// Open the generalization signature by adding a new generic parameter
6203
6162
// for `Self`.
6204
6163
auto parentSig = gen.Generalization .getGenericSignature ();
6205
- existentialSig.OpenedSig =
6206
- getOpenedExistentialSignature (gen.Shape , parentSig);
6164
+ auto canParentSig = parentSig.getCanonicalSignature ();
6165
+
6166
+ LocalArchetypeRequirementCollector collector (*this , canParentSig);
6167
+ collector.addOpenedExistential (gen.Shape );
6168
+ existentialSig.OpenedSig = buildGenericSignature (
6169
+ *this , collector.OuterSig , collector.Params , collector.Requirements ,
6170
+ /* allowInverses=*/ true ).getCanonicalSignature ();
6207
6171
6208
6172
// Stash the `Self` type.
6209
6173
existentialSig.SelfType =
6210
- OpenedArchetypeType::getSelfInterfaceTypeFromContext (parentSig, * this )
6174
+ existentialSig. OpenedSig . getGenericParams (). back ( )
6211
6175
->getCanonicalType ();
6212
6176
6213
6177
// Cache the result.
6214
6178
auto result = getImpl ().getArena (arena).ExistentialSignatures .insert (
6215
- std::make_pair (constraint , existentialSig));
6179
+ std::make_pair (canType , existentialSig));
6216
6180
ASSERT (result.second );
6217
6181
6218
6182
return existentialSig;
0 commit comments