@@ -457,10 +457,6 @@ struct ASTContext::Implementation {
457457 // / The single-parameter generic signature with no constraints, <T>.
458458 CanGenericSignature SingleGenericParameterSignature;
459459
460- // / The existential signature <T : P> for each P.
461- llvm::DenseMap<std::pair<CanType, const GenericSignatureImpl *>, CanGenericSignature>
462- ExistentialSignatures;
463-
464460 // / The element signature for a generic signature, which contains a clone
465461 // / of the context generic signature with new type parameters and requirements
466462 // / for opened pack elements in the given shape equivalence class.
@@ -851,7 +847,6 @@ void ASTContext::Implementation::dump(llvm::raw_ostream &os) const {
851847 SIZE_AND_BYTES (AssociativityCache);
852848 SIZE_AND_BYTES (DelayedConformanceDiags);
853849 SIZE_AND_BYTES (LazyContexts);
854- SIZE_AND_BYTES (ExistentialSignatures);
855850 SIZE_AND_BYTES (ElementSignatures);
856851 SIZE_AND_BYTES (Overrides);
857852 SIZE_AND_BYTES (DefaultWitnesses);
@@ -5342,22 +5337,21 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
53425337
53435338CanOpenedArchetypeType OpenedArchetypeType::get (CanType existential,
53445339 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);
53505342
53515343 if (!knownID)
53525344 knownID = UUID::fromTime ();
53535345
53545346 auto *genericEnv = GenericEnvironment::forOpenedExistential (
5355- existential, *knownID);
5347+ existentialSig.OpenedSig ,
5348+ existentialSig.Shape ,
5349+ existentialSig.Generalization ,
5350+ *knownID);
53565351
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 ());
53615355}
53625356
53635357Type OpenedArchetypeType::getAny (Type existential) {
@@ -5547,8 +5541,10 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
55475541GenericEnvironment *
55485542GenericEnvironment::forOpenedExistential (Type existential, UUID uuid) {
55495543 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);
55525548}
55535549
55545550// / Create a new generic environment for an opened archetype.
@@ -6136,83 +6132,51 @@ CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
61366132 return canonicalSig;
61376133}
61386134
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-
61746135OpenedExistentialSignature
61756136ASTContext::getOpenedExistentialSignature (Type type) {
61766137 assert (type->isExistentialType ());
61776138
6178- if (auto existential = type->getAs <ExistentialType>())
6179- type = existential->getConstraintType ();
6180-
6181- const CanType constraint = type->getCanonicalType ();
6139+ auto canType = type->getCanonicalType ();
61826140
61836141 // The constraint type might contain type variables.
6184- auto properties = constraint ->getRecursiveProperties ();
6142+ auto properties = canType ->getRecursiveProperties ();
61856143 auto arena = getArena (properties);
61866144
61876145 // Check the cache.
61886146 const auto &sigs = getImpl ().getArena (arena).ExistentialSignatures ;
6189- auto found = sigs.find (constraint );
6147+ auto found = sigs.find (canType );
61906148 if (found != sigs.end ())
61916149 return found->second ;
61926150
61936151 OpenedExistentialSignature existentialSig;
61946152
61956153 // Generalize the existential type, to move type variables and primary
61966154 // archetypes into the substitution map.
6197- auto gen = ExistentialTypeGeneralization::get (constraint);
6155+ auto gen = ExistentialTypeGeneralization::get (canType);
6156+
61986157 existentialSig.Shape = gen.Shape ->getCanonicalType ();
61996158 existentialSig.Generalization = gen.Generalization ;
62006159
62016160 // Now, we have an existential type written with type parameters only.
62026161 // Open the generalization signature by adding a new generic parameter
62036162 // for `Self`.
62046163 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 ();
62076171
62086172 // Stash the `Self` type.
62096173 existentialSig.SelfType =
6210- OpenedArchetypeType::getSelfInterfaceTypeFromContext (parentSig, * this )
6174+ existentialSig. OpenedSig . getGenericParams (). back ( )
62116175 ->getCanonicalType ();
62126176
62136177 // Cache the result.
62146178 auto result = getImpl ().getArena (arena).ExistentialSignatures .insert (
6215- std::make_pair (constraint , existentialSig));
6179+ std::make_pair (canType , existentialSig));
62166180 ASSERT (result.second );
62176181
62186182 return existentialSig;
0 commit comments