@@ -5342,22 +5342,21 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
53425342
53435343CanOpenedArchetypeType OpenedArchetypeType::get (CanType existential,
53445344 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);
53505347
53515348 if (!knownID)
53525349 knownID = UUID::fromTime ();
53535350
53545351 auto *genericEnv = GenericEnvironment::forOpenedExistential (
5355- existential, *knownID);
5352+ existentialSig.OpenedSig ,
5353+ existentialSig.Shape ,
5354+ existentialSig.Generalization ,
5355+ *knownID);
53565356
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 ());
53615360}
53625361
53635362Type OpenedArchetypeType::getAny (Type existential) {
@@ -5547,8 +5546,10 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
55475546GenericEnvironment *
55485547GenericEnvironment::forOpenedExistential (Type existential, UUID uuid) {
55495548 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);
55525553}
55535554
55545555// / Create a new generic environment for an opened archetype.
@@ -6175,26 +6176,24 @@ OpenedExistentialSignature
61756176ASTContext::getOpenedExistentialSignature (Type type) {
61766177 assert (type->isExistentialType ());
61776178
6178- if (auto existential = type->getAs <ExistentialType>())
6179- type = existential->getConstraintType ();
6180-
6181- const CanType constraint = type->getCanonicalType ();
6179+ auto canType = type->getCanonicalType ();
61826180
61836181 // The constraint type might contain type variables.
6184- auto properties = constraint ->getRecursiveProperties ();
6182+ auto properties = canType ->getRecursiveProperties ();
61856183 auto arena = getArena (properties);
61866184
61876185 // Check the cache.
61886186 const auto &sigs = getImpl ().getArena (arena).ExistentialSignatures ;
6189- auto found = sigs.find (constraint );
6187+ auto found = sigs.find (canType );
61906188 if (found != sigs.end ())
61916189 return found->second ;
61926190
61936191 OpenedExistentialSignature existentialSig;
61946192
61956193 // Generalize the existential type, to move type variables and primary
61966194 // archetypes into the substitution map.
6197- auto gen = ExistentialTypeGeneralization::get (constraint);
6195+ auto gen = ExistentialTypeGeneralization::get (canType);
6196+
61986197 existentialSig.Shape = gen.Shape ->getCanonicalType ();
61996198 existentialSig.Generalization = gen.Generalization ;
62006199
@@ -6212,7 +6211,7 @@ ASTContext::getOpenedExistentialSignature(Type type) {
62126211
62136212 // Cache the result.
62146213 auto result = getImpl ().getArena (arena).ExistentialSignatures .insert (
6215- std::make_pair (constraint , existentialSig));
6214+ std::make_pair (canType , existentialSig));
62166215 ASSERT (result.second );
62176216
62186217 return existentialSig;
0 commit comments