Skip to content

Commit e7785e1

Browse files
committed
AST: Duplicate combineSubstitutionMaps() inside getOverrideSubstitutions()
1 parent 4538b1b commit e7785e1

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,35 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass,
539539
if (auto derivedClassSig = derivedClass->getGenericSignature())
540540
origDepth = derivedClassSig.getGenericParams().back()->getDepth() + 1;
541541

542-
SubstitutionMap origSubMap;
543-
if (derivedSig)
544-
origSubMap = derivedSig->getIdentitySubstitutionMap();
545-
546-
return combineSubstitutionMaps(baseSubMap, origSubMap,
547-
CombineSubstitutionMaps::AtDepth,
548-
baseDepth, origDepth,
549-
baseSig);
542+
auto &ctx = baseSig->getASTContext();
543+
544+
return get(
545+
baseSig,
546+
[&](SubstitutableType *type) -> Type {
547+
if (auto gp = type->getAs<GenericTypeParamType>()) {
548+
if (gp->getDepth() >= baseDepth) {
549+
assert(gp->getDepth() == baseDepth);
550+
auto substGP = GenericTypeParamType::get(gp->isTypeSequence(),
551+
gp->getDepth() + origDepth - baseDepth,
552+
gp->getIndex(), ctx);
553+
return derivedSig->getSugaredType(substGP);
554+
}
555+
}
556+
557+
return Type(type).subst(baseSubMap);
558+
},
559+
[&](CanType type, Type substType, ProtocolDecl *proto) {
560+
if (type->getRootGenericParam()->getDepth() >= baseDepth)
561+
return ProtocolConformanceRef(proto);
562+
563+
if (auto conformance = baseSubMap.lookupConformance(type, proto))
564+
return conformance;
565+
566+
if (substType->isTypeParameter())
567+
return ProtocolConformanceRef(proto);
568+
569+
return proto->getParentModule()->lookupConformance(substType, proto);
570+
});
550571
}
551572

552573
SubstitutionMap

0 commit comments

Comments
 (0)