@@ -67,24 +67,22 @@ ProtocolDecl *ProtocolConformanceRef::getProtocol() const {
6767}
6868
6969ProtocolConformanceRef
70- ProtocolConformanceRef::subst (Type origType,
71- SubstitutionMap subMap,
70+ ProtocolConformanceRef::subst (SubstitutionMap subMap,
7271 SubstOptions options) const {
7372 InFlightSubstitutionViaSubMap IFS (subMap, options);
74- return subst (origType, IFS);
73+ return subst (IFS);
7574}
7675
7776ProtocolConformanceRef
78- ProtocolConformanceRef::subst (Type origType,
79- TypeSubstitutionFn subs,
77+ ProtocolConformanceRef::subst (TypeSubstitutionFn subs,
8078 LookupConformanceFn conformances,
8179 SubstOptions options) const {
8280 InFlightSubstitution IFS (subs, conformances, options);
83- return subst (origType, IFS);
81+ return subst (IFS);
8482}
8583
8684ProtocolConformanceRef
87- ProtocolConformanceRef::subst (Type origType, InFlightSubstitution &IFS) const {
85+ ProtocolConformanceRef::subst (InFlightSubstitution &IFS) const {
8886 if (isInvalid ())
8987 return *this ;
9088
@@ -93,36 +91,28 @@ ProtocolConformanceRef::subst(Type origType, InFlightSubstitution &IFS) const {
9391 if (isPack ())
9492 return getPack ()->subst (IFS);
9593
96- ASSERT (isAbstract ());
97- auto *proto = getProtocol ();
94+ auto *abstract = getAbstract ();
95+ auto origType = abstract->getType ();
96+ auto *proto = abstract->getProtocol ();
9897
9998 // If the type is an opaque archetype, the conformance will remain abstract,
10099 // unless we're specifically substituting opaque types.
101- if (origType->getAs <OpaqueTypeArchetypeType>()) {
102- if (!IFS.shouldSubstituteOpaqueArchetypes ()) {
103- return forAbstract (origType.subst (IFS), proto);
104- }
100+ if (origType->is <OpaqueTypeArchetypeType>() &&
101+ !IFS.shouldSubstituteOpaqueArchetypes ()) {
102+ return forAbstract (origType.subst (IFS), proto);
105103 }
106104
107- // FIXME: Handle local archetypes as above!
108-
109- // Otherwise, compute the substituted type.
110- auto substType = origType.subst (IFS);
111-
112- // If the type is an existential, it must be self-conforming.
113- // FIXME: This feels like it's in the wrong place.
114- if (substType->isExistentialType ()) {
115- auto optConformance =
116- lookupConformance (substType, proto, /* allowMissing=*/ true );
117- if (optConformance)
118- return optConformance;
119-
120- return ProtocolConformanceRef::forInvalid ();
105+ // If the type is a local archetype, the conformance will remain abstract,
106+ // unless we're specifically substituting local types.
107+ if (origType->is <LocalArchetypeType>() &&
108+ !IFS.shouldSubstituteLocalArchetypes ()) {
109+ return forAbstract (origType.subst (IFS), proto);
121110 }
122111
123112 // Local conformance lookup into the substitution map.
124113 // FIXME: Pack element level?
125- return IFS.lookupConformance (origType->getCanonicalType (), substType, proto,
114+ return IFS.lookupConformance (origType->getCanonicalType (),
115+ origType.subst (IFS), proto,
126116 /* level=*/ 0 );
127117}
128118
0 commit comments