Skip to content

Commit 6ba379f

Browse files
committed
ClangImporter: Refactor loadObjCMethods() to not call CollectMultipleMethodsInGlobalPool()
Let's try calling ObjCInterface::lookupMethod() instead. This also eliminates an order dependency between selector conflict checking and protocol member mirroring, which fixes a diagnostics regression once lazy loading is enabled for mirrored protocol members.
1 parent 7e7b6e8 commit 6ba379f

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,33 +3031,25 @@ void ClangImporter::loadObjCMethods(
30313031

30323032
// Collect the set of visible Objective-C methods with this selector.
30333033
clang::Selector clangSelector = Impl.exportSelector(selector);
3034-
SmallVector<clang::ObjCMethodDecl *, 4> objcMethods;
3035-
auto &sema = Impl.Instance->getSema();
3036-
sema.CollectMultipleMethodsInGlobalPool(clangSelector, objcMethods,
3037-
isInstanceMethod,
3038-
/*CheckTheOther=*/false);
30393034

3040-
// Check whether this method is in the class we care about.
3041-
SmallVector<AbstractFunctionDecl *, 4> foundMethods;
3042-
for (auto objcMethod : objcMethods) {
3043-
// Find the owner of this method and determine whether it is the class
3044-
// we're looking for.
3045-
if (objcMethod->getClassInterface() != objcClass)
3046-
continue;
3035+
AbstractFunctionDecl *method = nullptr;
3036+
auto *objcMethod = objcClass->lookupMethod(
3037+
clangSelector, isInstanceMethod,
3038+
/*shallowCategoryLookup=*/false,
3039+
/*followSuper=*/false);
30473040

3041+
if (objcMethod) {
30483042
// If we found a property accessor, import the property.
30493043
if (objcMethod->isPropertyAccessor())
30503044
(void)Impl.importDecl(objcMethod->findPropertyDecl(true),
30513045
Impl.CurrentVersion);
30523046

3053-
if (auto method = dyn_cast_or_null<AbstractFunctionDecl>(
3054-
Impl.importDecl(objcMethod, Impl.CurrentVersion))) {
3055-
foundMethods.push_back(method);
3056-
}
3047+
method = dyn_cast_or_null<AbstractFunctionDecl>(
3048+
Impl.importDecl(objcMethod, Impl.CurrentVersion));
30573049
}
30583050

30593051
// If we didn't find anything, we're done.
3060-
if (foundMethods.empty())
3052+
if (method == nullptr)
30613053
return;
30623054

30633055
// If we did find something, it might be a duplicate of something we found
@@ -3066,10 +3058,9 @@ void ClangImporter::loadObjCMethods(
30663058
// FIXME: We shouldn't need to do this.
30673059
llvm::SmallPtrSet<AbstractFunctionDecl *, 4> known;
30683060
known.insert(methods.begin(), methods.end());
3069-
for (auto method : foundMethods) {
3070-
if (known.insert(method).second)
3071-
methods.push_back(method);
3072-
}
3061+
3062+
if (known.insert(method).second)
3063+
methods.push_back(method);
30733064
}
30743065

30753066
void

test/ClangImporter/objc_init_redundant.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import Foundation
1010
extension NSObject {
1111
@objc convenience init() { self.init() } // expected-error{{initializer 'init()' with Objective-C selector 'init' conflicts with previous declaration with the same Objective-C selector}}
1212
// CHECK: objc_init_redundant.swift:[[@LINE-1]]:21: error: initializer 'init()' with Objective-C selector 'init' conflicts
13-
// CHECK: ObjectiveC.NSObject{{.*}}note: 'init' previously declared here
13+
// CHECK: ObjectiveC.NSObject:{{.*}}note: 'init' previously declared here
1414
}
1515

1616
extension NSObject {
1717
@objc(class) func foo() { } // expected-error{{method 'foo()' with Objective-C selector 'class' conflicts with method 'class()' with the same Objective-C selector}}
1818
// CHECK: objc_init_redundant.swift:[[@LINE-1]]:21: error: method 'foo()' with Objective-C selector 'class' conflicts
19-
// CHECK: ObjectiveC.NSObject{{.*}}note: method 'class()' declared here
19+
// CHECK: ObjectiveC.NSObject:{{.*}}note: method 'class()' declared here
2020
}
2121

0 commit comments

Comments
 (0)