Skip to content

Commit d36806b

Browse files
committed
SILGen: Small cleanup, NFC
1 parent 5285a95 commit d36806b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ static CanSILFunctionType getDynamicMethodLoweredType(SILGenFunction &gen,
113113

114114
static bool canUseStaticDispatch(SILGenFunction &gen,
115115
SILDeclRef constant) {
116+
if (constant.isForeign)
117+
return false;
118+
116119
auto *funcDecl = cast<AbstractFunctionDecl>(constant.getDecl());
117120
auto thisModule = gen.SGM.M.getSwiftModule();
118121
return funcDecl->isFinal() || (thisModule == funcDecl->getModuleContext());
@@ -335,6 +338,9 @@ class Callee {
335338
SILDeclRef name,
336339
CanAnyFunctionType substFormalType,
337340
SILLocation l) {
341+
while (auto *UI = dyn_cast<UpcastInst>(selfValue))
342+
selfValue = UI->getOperand();
343+
338344
return Callee(Kind::SuperMethod, gen, selfValue, name,
339345
substFormalType, l);
340346
}
@@ -1292,14 +1298,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
12921298
setSelfParam(ArgumentSource(arg, RValue(SGF, apply, superFormalType, super)),
12931299
apply);
12941300

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)) {
13011302
// ObjC super calls require dynamic dispatch.
1302-
setCallee(Callee::forSuperMethod(SGF, Input, constant,
1303+
setCallee(Callee::forSuperMethod(SGF, super.getValue(), constant,
13031304
getSubstFnType(), fn));
13041305
} else {
13051306
// Native Swift super calls to final methods are direct.
@@ -4371,16 +4372,12 @@ static Callee getBaseAccessorFunctionRef(SILGenFunction &gen,
43714372
// perform a dynamic dispatch.
43724373
auto self = selfValue.forceAndPeekRValue(gen).peekScalarValue();
43734374
if (!isSuper)
4374-
return Callee::forClassMethod(gen, self, constant, substAccessorType,
4375-
loc);
4375+
return Callee::forClassMethod(gen, self, constant, substAccessorType, loc);
43764376

43774377
// If this is a "super." dispatch, we do a dynamic dispatch for objc methods
43784378
// 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);
43844381

43854382
return Callee::forDirect(gen, constant, substAccessorType, loc);
43864383
}

0 commit comments

Comments
 (0)