@@ -111,10 +111,24 @@ class PolymorphicConvention {
111111 FulfillmentMap Fulfillments;
112112
113113 GenericSignature::RequiredProtocols getRequiredProtocols (Type t) {
114+ // FIXME: We need to rework this to use archetypes instead of interface
115+ // types, or fix the bad interaction between interface type substitution
116+ // and concretized conformance requirements. Then we can remove the hack
117+ // from getReducedType() to handle this case, and also stop calling
118+ // getReducedType() here.
119+ t = Generics.getReducedType (t);
120+ if (!t->isTypeParameter ())
121+ return {};
122+
114123 return Generics->getRequiredProtocols (t);
115124 }
116125
117126 CanType getSuperclassBound (Type t) {
127+ // See above.
128+ t = Generics.getReducedType (t);
129+ if (!t->isTypeParameter ())
130+ return CanType ();
131+
118132 if (auto superclassTy = Generics->getSuperclassBound (t))
119133 return superclassTy->getCanonicalType ();
120134 return CanType ();
@@ -143,8 +157,6 @@ class PolymorphicConvention {
143157 }
144158
145159private:
146- void initGenerics ();
147-
148160 template <typename ...Args>
149161 void considerNewTypeSource (IsExact_t isExact, MetadataSource::Kind kind,
150162 CanType type, Args... args);
@@ -199,9 +211,8 @@ class PolymorphicConvention {
199211PolymorphicConvention::PolymorphicConvention (IRGenModule &IGM,
200212 CanSILFunctionType fnType,
201213 bool considerParameterSources = true )
202- : IGM(IGM), M(*IGM.getSwiftModule()), FnType(fnType){
203- initGenerics ();
204-
214+ : IGM(IGM), M(*IGM.getSwiftModule()), FnType(fnType),
215+ Generics(fnType->getInvocationGenericSignature ()) {
205216 auto rep = fnType->getRepresentation ();
206217
207218 if (fnType->isPseudogeneric ()) {
@@ -249,11 +260,8 @@ PolymorphicConvention::PolymorphicConvention(IRGenModule &IGM,
249260
250261void PolymorphicConvention::addPseudogenericFulfillments () {
251262 enumerateRequirements ([&](GenericRequirement reqt) {
252- auto archetype = Generics.getGenericEnvironment ()
253- ->mapTypeIntoContext (reqt.getTypeParameter ())
254- ->getAs <ArchetypeType>();
255- assert (archetype && " did not get an archetype by mapping param?" );
256- auto erasedTypeParam = archetype->getExistentialType ()->getCanonicalType ();
263+ auto erasedTypeParam = Generics->getExistentialType (reqt.getTypeParameter ())
264+ ->getCanonicalType ();
257265 Sources.emplace_back (MetadataSource::Kind::ErasedTypeMetadata,
258266 reqt.getTypeParameter (), erasedTypeParam);
259267
@@ -319,10 +327,6 @@ enumerateUnfulfilledRequirements(const RequirementCallback &callback) {
319327 });
320328}
321329
322- void PolymorphicConvention::initGenerics () {
323- Generics = FnType->getInvocationGenericSignature ();
324- }
325-
326330template <typename ...Args>
327331void PolymorphicConvention::considerNewTypeSource (IsExact_t isExact,
328332 MetadataSource::Kind kind,
0 commit comments