@@ -113,6 +113,9 @@ static CanSILFunctionType getDynamicMethodLoweredType(SILGenFunction &gen,
113
113
114
114
static bool canUseStaticDispatch (SILGenFunction &gen,
115
115
SILDeclRef constant) {
116
+ if (constant.isForeign )
117
+ return false ;
118
+
116
119
auto *funcDecl = cast<AbstractFunctionDecl>(constant.getDecl ());
117
120
auto thisModule = gen.SGM .M .getSwiftModule ();
118
121
return funcDecl->isFinal () || (thisModule == funcDecl->getModuleContext ());
@@ -335,6 +338,9 @@ class Callee {
335
338
SILDeclRef name,
336
339
CanAnyFunctionType substFormalType,
337
340
SILLocation l) {
341
+ while (auto *UI = dyn_cast<UpcastInst>(selfValue))
342
+ selfValue = UI->getOperand ();
343
+
338
344
return Callee (Kind::SuperMethod, gen, selfValue, name,
339
345
substFormalType, l);
340
346
}
@@ -1292,14 +1298,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1292
1298
setSelfParam (ArgumentSource (arg, RValue (SGF, apply, superFormalType, super)),
1293
1299
apply);
1294
1300
1295
- if (constant.isForeign || !canUseStaticDispatch (SGF, constant)) {
1296
- // All Objective-C methods and
1297
- // non-final native Swift methods use dynamic dispatch.
1298
- SILValue Input = super.getValue ();
1299
- while (auto *UI = dyn_cast<UpcastInst>(Input))
1300
- Input = UI->getOperand ();
1301
+ if (!canUseStaticDispatch (SGF, constant)) {
1301
1302
// ObjC super calls require dynamic dispatch.
1302
- setCallee (Callee::forSuperMethod (SGF, Input , constant,
1303
+ setCallee (Callee::forSuperMethod (SGF, super. getValue () , constant,
1303
1304
getSubstFnType (), fn));
1304
1305
} else {
1305
1306
// Native Swift super calls to final methods are direct.
@@ -4371,16 +4372,12 @@ static Callee getBaseAccessorFunctionRef(SILGenFunction &gen,
4371
4372
// perform a dynamic dispatch.
4372
4373
auto self = selfValue.forceAndPeekRValue (gen).peekScalarValue ();
4373
4374
if (!isSuper)
4374
- return Callee::forClassMethod (gen, self, constant, substAccessorType,
4375
- loc);
4375
+ return Callee::forClassMethod (gen, self, constant, substAccessorType, loc);
4376
4376
4377
4377
// If this is a "super." dispatch, we do a dynamic dispatch for objc methods
4378
4378
// or non-final native Swift methods.
4379
- while (auto *upcast = dyn_cast<UpcastInst>(self))
4380
- self = upcast->getOperand ();
4381
-
4382
- if (constant.isForeign || !canUseStaticDispatch (gen, constant))
4383
- return Callee::forSuperMethod (gen, self, constant, substAccessorType,loc);
4379
+ if (!canUseStaticDispatch (gen, constant))
4380
+ return Callee::forSuperMethod (gen, self, constant, substAccessorType, loc);
4384
4381
4385
4382
return Callee::forDirect (gen, constant, substAccessorType, loc);
4386
4383
}
0 commit comments