@@ -7054,51 +7054,18 @@ ValueWitnessRequest::evaluate(Evaluator &eval,
70547054 return known->second ;
70557055}
70567056
7057- // / A stripped-down version of Type::subst that only works on the protocol
7058- // / Self type wrapped in zero or more DependentMemberTypes.
7059- static Type
7060- recursivelySubstituteBaseType (ModuleDecl *module ,
7061- NormalProtocolConformance *conformance,
7062- DependentMemberType *depMemTy) {
7063- Type origBase = depMemTy->getBase ();
7064-
7065- // Recursive case.
7066- if (auto *depBase = origBase->getAs <DependentMemberType>()) {
7067- Type substBase = recursivelySubstituteBaseType (
7068- module , conformance, depBase);
7069- return depMemTy->substBaseType (module , substBase);
7070- }
7071-
7072- // Base case. The associated type's protocol should be either the
7073- // conformance protocol or an inherited protocol.
7074- auto *reqProto = depMemTy->getAssocType ()->getProtocol ();
7075- assert (origBase->isEqual (reqProto->getSelfInterfaceType ()));
7076-
7077- ProtocolConformance *reqConformance = conformance;
7078-
7079- // If we have an inherited protocol just look up the conformance.
7080- if (reqProto != conformance->getProtocol ()) {
7081- reqConformance = module ->lookupConformance (conformance->getType (), reqProto)
7082- .getConcrete ();
7083- }
7084-
7085- return reqConformance->getTypeWitness (depMemTy->getAssocType ());
7086- }
7087-
70887057ProtocolConformanceRef
70897058AssociatedConformanceRequest::evaluate (Evaluator &eval,
70907059 NormalProtocolConformance *conformance,
70917060 CanType origTy, ProtocolDecl *reqProto,
70927061 unsigned index) const {
70937062 auto *module = conformance->getDeclContext ()->getParentModule ();
7094- Type substTy;
70957063
7096- if (origTy->isEqual (conformance->getProtocol ()->getSelfInterfaceType ())) {
7097- substTy = conformance->getType ();
7098- } else {
7099- auto *depMemTy = origTy->castTo <DependentMemberType>();
7100- substTy = recursivelySubstituteBaseType (module , conformance, depMemTy);
7101- }
7064+ auto subMap = SubstitutionMap::getProtocolSubstitutions (
7065+ conformance->getProtocol (),
7066+ conformance->getType (),
7067+ ProtocolConformanceRef (conformance));
7068+ auto substTy = origTy.subst (subMap);
71027069
71037070 // Looking up a conformance for a contextual type and mapping the
71047071 // conformance context produces a more accurate result than looking
0 commit comments