SIL: Clean up getMethodDispatch()

This commit is contained in:
Slava Pestov
2018-01-04 17:53:42 -08:00
parent d1f1c682bc
commit 4737b28001

View File

@@ -30,9 +30,6 @@ using namespace swift;
/// Get the method dispatch mechanism for a method.
MethodDispatch
swift::getMethodDispatch(AbstractFunctionDecl *method) {
// Final methods can be statically referenced.
if (method->isFinal())
return MethodDispatch::Static;
// Some methods are forced to be statically dispatched.
if (method->hasForcedStaticDispatch())
return MethodDispatch::Static;
@@ -41,23 +38,23 @@ swift::getMethodDispatch(AbstractFunctionDecl *method) {
if (method->isImportAsMember())
return MethodDispatch::Static;
// If this declaration is in a class but not marked final, then it is
// always dynamically dispatched.
auto dc = method->getDeclContext();
if (isa<ClassDecl>(dc))
return MethodDispatch::Class;
// Class extension methods are only dynamically dispatched if they're
// dispatched by objc_msgSend, which happens if they're foreign or dynamic.
if (dc->getAsClassOrClassExtensionContext()) {
if (method->hasClangNode())
return MethodDispatch::Class;
if (auto fd = dyn_cast<FuncDecl>(method)) {
if (fd->isAccessor() && fd->getAccessorStorageDecl()->hasClangNode())
return MethodDispatch::Class;
}
if (method->isDynamic())
return MethodDispatch::Class;
// Final methods can be statically referenced.
if (method->isFinal())
return MethodDispatch::Static;
// Members defined directly inside a class are dynamically dispatched.
if (isa<ClassDecl>(dc))
return MethodDispatch::Class;
// Imported class methods are dynamically dispatched.
if (method->isObjC() && method->hasClangNode())
return MethodDispatch::Class;
}
// Otherwise, it can be referenced statically.