SILOptimizer: Don't devirtualize witness method calls to tuple conformances that might vanish

This commit is contained in:
Slava Pestov
2023-09-08 15:56:16 -04:00
parent 9c2557dcc3
commit bd2a020a53
3 changed files with 31 additions and 7 deletions

View File

@@ -1146,6 +1146,15 @@ static bool canDevirtualizeWitnessMethod(ApplySite applySite, bool isMandatory)
auto *wmi = cast<WitnessMethodInst>(applySite.getCallee());
// Handle vanishing tuples: don't devirtualize a call to a tuple conformance
// if the lookup type can possibly be unwrapped after substitution.
if (auto tupleType = dyn_cast<TupleType>(wmi->getLookupType())) {
if (tupleType->containsPackExpansionType() &&
tupleType->getNumScalarElements() <= 1) {
return false;
}
}
std::tie(f, wt) = applySite.getModule().lookUpFunctionInWitnessTable(
wmi->getConformance(), wmi->getMember(), SILModule::LinkingMode::LinkAll);