@@ -1140,7 +1140,7 @@ static bool isNonGenericThunkOfGenericExternalFunction(SILFunction *thunk) {
11401140 return false ;
11411141}
11421142
1143- static bool canDevirtualizeWitnessMethod (ApplySite applySite) {
1143+ static bool canDevirtualizeWitnessMethod (ApplySite applySite, bool isMandatory ) {
11441144 SILFunction *f;
11451145 SILWitnessTable *wt;
11461146
@@ -1183,7 +1183,7 @@ static bool canDevirtualizeWitnessMethod(ApplySite applySite) {
11831183 // ```
11841184 // In the defining module, the generic conformance can be specialized (which is not
11851185 // possible in the client module, because it's not inlinable).
1186- if (isNonGenericThunkOfGenericExternalFunction (f)) {
1186+ if (!isMandatory && isNonGenericThunkOfGenericExternalFunction (f)) {
11871187 return false ;
11881188 }
11891189
@@ -1237,8 +1237,9 @@ static bool canDevirtualizeWitnessMethod(ApplySite applySite) {
12371237// / of a function_ref, returning the new apply.
12381238std::pair<ApplySite, bool >
12391239swift::tryDevirtualizeWitnessMethod (ApplySite applySite,
1240- OptRemark::Emitter *ore) {
1241- if (!canDevirtualizeWitnessMethod (applySite))
1240+ OptRemark::Emitter *ore,
1241+ bool isMandatory) {
1242+ if (!canDevirtualizeWitnessMethod (applySite, isMandatory))
12421243 return {ApplySite (), false };
12431244
12441245 SILFunction *f;
@@ -1262,7 +1263,7 @@ swift::tryDevirtualizeWitnessMethod(ApplySite applySite,
12621263// / Return the new apply and true if the CFG was also modified.
12631264std::pair<ApplySite, bool >
12641265swift::tryDevirtualizeApply (ApplySite applySite, ClassHierarchyAnalysis *cha,
1265- OptRemark::Emitter *ore) {
1266+ OptRemark::Emitter *ore, bool isMandatory ) {
12661267 LLVM_DEBUG (llvm::dbgs () << " Trying to devirtualize: "
12671268 << *applySite.getInstruction ());
12681269
@@ -1272,7 +1273,7 @@ swift::tryDevirtualizeApply(ApplySite applySite, ClassHierarchyAnalysis *cha,
12721273 // %9 = apply %8<Self = CodeUnit?>(%6#1) : ...
12731274 //
12741275 if (isa<WitnessMethodInst>(applySite.getCallee ()))
1275- return tryDevirtualizeWitnessMethod (applySite, ore);
1276+ return tryDevirtualizeWitnessMethod (applySite, ore, isMandatory );
12761277
12771278 // TODO: check if we can also de-virtualize partial applies of class methods.
12781279 FullApplySite fas = FullApplySite::isa (applySite.getInstruction ());
@@ -1344,7 +1345,7 @@ bool swift::canDevirtualizeApply(FullApplySite applySite,
13441345 // %9 = apply %8<Self = CodeUnit?>(%6#1) : ...
13451346 //
13461347 if (isa<WitnessMethodInst>(applySite.getCallee ()))
1347- return canDevirtualizeWitnessMethod (applySite);
1348+ return canDevirtualizeWitnessMethod (applySite, /* isMandatory */ false );
13481349
13491350 // / Optimize a class_method and alloc_ref pair into a direct function
13501351 // / reference:
0 commit comments