Skip to content

Commit e3ce039

Browse files
committed
Remove SubstitutionMap::removeType().
1 parent f9d9dcf commit e3ce039

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class SubstitutionMap {
6565

6666
void addParent(CanType type, CanType parent,
6767
AssociatedTypeDecl *assocType);
68-
69-
void removeType(CanType type);
7068
};
7169

7270
} // end namespace swift

lib/AST/SubstitutionMap.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,3 @@ addParent(CanType type, CanType parent, AssociatedTypeDecl *assocType) {
118118
assert(type && parent && assocType);
119119
parentMap[type.getPointer()].push_back(std::make_pair(parent, assocType));
120120
}
121-
122-
void SubstitutionMap::removeType(CanType type) {
123-
subMap.erase(type.getPointer());
124-
conformanceMap.erase(type.getPointer());
125-
parentMap.erase(type.getPointer());
126-
}

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,36 @@ getSubstitutionsForCallee(SILModule &M,
437437

438438
auto origSubs = AI.getSubstitutions();
439439

440-
// Decompose the original substitution using the derived method signature.
441-
origCalleeSig->getSubstitutionMap(origSubs, subMap);
442-
443-
// Drop any generic parameters that come from the derived class, leaving
444-
// only generic parameters of the method itself.
445-
if (auto derivedClassSig = calleeClassDecl->getGenericSignatureOfContext()) {
446-
for (auto depTy : derivedClassSig->getAllDependentTypes()) {
447-
subMap.removeType(depTy->getCanonicalType());
448-
}
440+
// Add generic parameters from the method itself, ignoring any generic
441+
// parameters from the derived class.
442+
unsigned minDepth = 0;
443+
if (auto derivedClassSig = calleeClassDecl->getGenericSignatureOfContext())
444+
minDepth = derivedClassSig->getGenericParams().back()->getDepth() + 1;
445+
446+
for (auto depTy : origCalleeSig->getAllDependentTypes()) {
447+
// Grab the next substitution.
448+
auto sub = origSubs.front();
449+
origSubs = origSubs.slice(1);
450+
451+
// If the dependent type doesn't contain any generic parameter with
452+
// a depth of at least the minimum, skip this type.
453+
auto canTy = depTy->getCanonicalType();
454+
auto hasInnerGenericParameter = [minDepth](Type type) -> bool {
455+
if (auto gp = type->getAs<GenericTypeParamType>()) {
456+
return gp->getDepth() >= minDepth;
457+
}
458+
return false;
459+
};
460+
461+
if (!Type(canTy.getPointer()).findIf(hasInnerGenericParameter))
462+
continue;
463+
464+
// Otherwise, record the replacement and conformances for the mapped
465+
// type.
466+
subMap.addSubstitution(canTy, sub.getReplacement());
467+
subMap.addConformances(canTy, sub.getConformances());
449468
}
469+
assert(origSubs.empty());
450470
}
451471

452472
// Add any generic substitutions for the base class.

0 commit comments

Comments
 (0)