@@ -7054,51 +7054,18 @@ ValueWitnessRequest::evaluate(Evaluator &eval,
7054
7054
return known->second ;
7055
7055
}
7056
7056
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
-
7088
7057
ProtocolConformanceRef
7089
7058
AssociatedConformanceRequest::evaluate (Evaluator &eval,
7090
7059
NormalProtocolConformance *conformance,
7091
7060
CanType origTy, ProtocolDecl *reqProto,
7092
7061
unsigned index) const {
7093
7062
auto *module = conformance->getDeclContext ()->getParentModule ();
7094
- Type substTy;
7095
7063
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);
7102
7069
7103
7070
// Looking up a conformance for a contextual type and mapping the
7104
7071
// conformance context produces a more accurate result than looking
0 commit comments