@@ -5342,22 +5342,21 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
5342
5342
5343
5343
CanOpenedArchetypeType OpenedArchetypeType::get (CanType existential,
5344
5344
std::optional<UUID> knownID) {
5345
- assert (existential->isExistentialType ());
5346
- assert (!existential->hasTypeParameter ());
5347
-
5348
- auto interfaceType = OpenedArchetypeType::getSelfInterfaceTypeFromContext (
5349
- GenericSignature (), existential->getASTContext ());
5345
+ auto &ctx = existential->getASTContext ();
5346
+ auto existentialSig = ctx.getOpenedExistentialSignature (existential);
5350
5347
5351
5348
if (!knownID)
5352
5349
knownID = UUID::fromTime ();
5353
5350
5354
5351
auto *genericEnv = GenericEnvironment::forOpenedExistential (
5355
- existential, *knownID);
5352
+ existentialSig.OpenedSig ,
5353
+ existentialSig.Shape ,
5354
+ existentialSig.Generalization ,
5355
+ *knownID);
5356
5356
5357
- // Map the interface type into that environment.
5358
- auto result = genericEnv->mapTypeIntoContext (interfaceType)
5359
- ->castTo <OpenedArchetypeType>();
5360
- return CanOpenedArchetypeType (result);
5357
+ return cast<OpenedArchetypeType>(
5358
+ genericEnv->mapTypeIntoContext (existentialSig.SelfType )
5359
+ ->getCanonicalType ());
5361
5360
}
5362
5361
5363
5362
Type OpenedArchetypeType::getAny (Type existential) {
@@ -5547,8 +5546,10 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
5547
5546
GenericEnvironment *
5548
5547
GenericEnvironment::forOpenedExistential (Type existential, UUID uuid) {
5549
5548
auto &ctx = existential->getASTContext ();
5550
- auto signature = ctx.getOpenedExistentialSignature (existential, GenericSignature ());
5551
- return forOpenedExistential (signature, existential, SubstitutionMap (), uuid);
5549
+ auto existentialSig = ctx.getOpenedExistentialSignature (existential);
5550
+ return forOpenedExistential (existentialSig.OpenedSig ,
5551
+ existentialSig.Shape ,
5552
+ existentialSig.Generalization , uuid);
5552
5553
}
5553
5554
5554
5555
// / Create a new generic environment for an opened archetype.
@@ -6175,26 +6176,24 @@ OpenedExistentialSignature
6175
6176
ASTContext::getOpenedExistentialSignature (Type type) {
6176
6177
assert (type->isExistentialType ());
6177
6178
6178
- if (auto existential = type->getAs <ExistentialType>())
6179
- type = existential->getConstraintType ();
6180
-
6181
- const CanType constraint = type->getCanonicalType ();
6179
+ auto canType = type->getCanonicalType ();
6182
6180
6183
6181
// The constraint type might contain type variables.
6184
- auto properties = constraint ->getRecursiveProperties ();
6182
+ auto properties = canType ->getRecursiveProperties ();
6185
6183
auto arena = getArena (properties);
6186
6184
6187
6185
// Check the cache.
6188
6186
const auto &sigs = getImpl ().getArena (arena).ExistentialSignatures ;
6189
- auto found = sigs.find (constraint );
6187
+ auto found = sigs.find (canType );
6190
6188
if (found != sigs.end ())
6191
6189
return found->second ;
6192
6190
6193
6191
OpenedExistentialSignature existentialSig;
6194
6192
6195
6193
// Generalize the existential type, to move type variables and primary
6196
6194
// archetypes into the substitution map.
6197
- auto gen = ExistentialTypeGeneralization::get (constraint);
6195
+ auto gen = ExistentialTypeGeneralization::get (canType);
6196
+
6198
6197
existentialSig.Shape = gen.Shape ->getCanonicalType ();
6199
6198
existentialSig.Generalization = gen.Generalization ;
6200
6199
@@ -6212,7 +6211,7 @@ ASTContext::getOpenedExistentialSignature(Type type) {
6212
6211
6213
6212
// Cache the result.
6214
6213
auto result = getImpl ().getArena (arena).ExistentialSignatures .insert (
6215
- std::make_pair (constraint , existentialSig));
6214
+ std::make_pair (canType , existentialSig));
6216
6215
ASSERT (result.second );
6217
6216
6218
6217
return existentialSig;
0 commit comments