Skip to content

Commit 0b1d3df

Browse files
committed
Revert "[NFC] Serialize ObjC selectors for protocols"
This reverts commit dcb1d66. # Conflicts: # lib/Serialization/ModuleFormat.h
1 parent b746e3b commit 0b1d3df

File tree

12 files changed

+30
-40
lines changed

12 files changed

+30
-40
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ class ModuleLoader {
226226
virtual void loadExtensions(NominalTypeDecl *nominal,
227227
unsigned previousGeneration) { }
228228

229-
/// Load the methods within the given type that produce
229+
/// Load the methods within the given class that produce
230230
/// Objective-C class or instance methods with the given selector.
231231
///
232-
/// \param typeDecl The type in which we are searching for @objc methods.
233-
/// The search only considers this type and its extensions; not any
232+
/// \param classDecl The class in which we are searching for @objc methods.
233+
/// The search only considers this class and its extensions; not any
234234
/// superclasses.
235235
///
236236
/// \param selector The selector to search for.
@@ -246,7 +246,7 @@ class ModuleLoader {
246246
/// selector and are instance/class methods as requested. This list will be
247247
/// extended with any methods found in subsequent generations.
248248
virtual void loadObjCMethods(
249-
NominalTypeDecl *typeDecl,
249+
ClassDecl *classDecl,
250250
ObjCSelector selector,
251251
bool isInstanceMethod,
252252
unsigned previousGeneration,

include/swift/ClangImporter/ClangImporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class ClangImporter final : public ClangModuleLoader {
309309
unsigned previousGeneration) override;
310310

311311
virtual void loadObjCMethods(
312-
NominalTypeDecl *typeDecl,
312+
ClassDecl *classDecl,
313313
ObjCSelector selector,
314314
bool isInstanceMethod,
315315
unsigned previousGeneration,

include/swift/Sema/SourceLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SourceLoader : public ModuleLoader {
8585
unsigned previousGeneration) override;
8686

8787
virtual void loadObjCMethods(
88-
NominalTypeDecl *typeDecl,
88+
ClassDecl *classDecl,
8989
ObjCSelector selector,
9090
bool isInstanceMethod,
9191
unsigned previousGeneration,

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
190190
unsigned previousGeneration) override;
191191

192192
virtual void loadObjCMethods(
193-
NominalTypeDecl *typeDecl,
193+
ClassDecl *classDecl,
194194
ObjCSelector selector,
195195
bool isInstanceMethod,
196196
unsigned previousGeneration,

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,12 +1925,24 @@ void ASTContext::loadObjCMethods(
19251925
PrettyStackTraceSelector stackTraceSelector("looking for", selector);
19261926
PrettyStackTraceDecl stackTraceDecl("...in", tyDecl);
19271927

1928+
// @objc protocols cannot have @objc extension members, so if we've recorded
1929+
// everything in the protocol definition, we've recorded everything. And we
1930+
// only ever use the ObjCSelector version of `NominalTypeDecl::lookupDirect()`
1931+
// on protocols in primary file typechecking, so we don't care about protocols
1932+
// that need to be loaded from files.
1933+
// TODO: Rework `ModuleLoader::loadObjCMethods()` to support protocols too if
1934+
// selector-based `NominalTypeDecl::lookupDirect()` ever needs to work
1935+
// in more situations.
1936+
ClassDecl *classDecl = dyn_cast<ClassDecl>(tyDecl);
1937+
if (!classDecl)
1938+
return;
1939+
19281940
for (auto &loader : getImpl().ModuleLoaders) {
19291941
// Ignore the Clang importer if we've been asked for Swift-only results.
19301942
if (swiftOnly && loader.get() == getClangModuleLoader())
19311943
continue;
19321944

1933-
loader->loadObjCMethods(tyDecl, selector, isInstanceMethod,
1945+
loader->loadObjCMethods(classDecl, selector, isInstanceMethod,
19341946
previousGeneration, methods);
19351947
}
19361948
}

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,24 +1310,7 @@ class swift::ObjCMethodLookupTable
13101310
: public llvm::DenseMap<std::pair<ObjCSelector, char>,
13111311
StoredObjCMethods>,
13121312
public ASTAllocated<ObjCMethodLookupTable>
1313-
{
1314-
SWIFT_DEBUG_DUMP {
1315-
llvm::errs() << "ObjCMethodLookupTable:\n";
1316-
for (auto pair : *this) {
1317-
auto selector = pair.getFirst().first;
1318-
auto isInstanceMethod = pair.getFirst().second;
1319-
auto &methods = pair.getSecond();
1320-
1321-
llvm::errs() << " \"" << (isInstanceMethod ? "-" : "+") << selector
1322-
<< "\":\n";
1323-
for (auto method : methods.Methods) {
1324-
llvm::errs() << " - \"";
1325-
method->dumpRef(llvm::errs());
1326-
llvm::errs() << "\"\n";
1327-
}
1328-
}
1329-
}
1330-
};
1313+
{};
13311314

13321315
MemberLookupTable::MemberLookupTable(ASTContext &ctx) {
13331316
// Register a cleanup with the ASTContext to call the lookup table

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,16 +3435,11 @@ void ClangImporter::loadExtensions(NominalTypeDecl *nominal,
34353435
}
34363436

34373437
void ClangImporter::loadObjCMethods(
3438-
NominalTypeDecl *typeDecl,
3438+
ClassDecl *classDecl,
34393439
ObjCSelector selector,
34403440
bool isInstanceMethod,
34413441
unsigned previousGeneration,
34423442
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) {
3443-
// TODO: We don't currently need to load methods from imported ObjC protocols.
3444-
auto classDecl = dyn_cast<ClassDecl>(typeDecl);
3445-
if (!classDecl)
3446-
return;
3447-
34483443
const auto *objcClass =
34493444
dyn_cast_or_null<clang::ObjCInterfaceDecl>(classDecl->getClangDecl());
34503445
if (!objcClass)

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void ModuleFile::loadExtensions(NominalTypeDecl *nominal) {
613613
}
614614

615615
void ModuleFile::loadObjCMethods(
616-
NominalTypeDecl *typeDecl,
616+
ClassDecl *classDecl,
617617
ObjCSelector selector,
618618
bool isInstanceMethod,
619619
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) {
@@ -627,7 +627,7 @@ void ModuleFile::loadObjCMethods(
627627
return;
628628
}
629629

630-
std::string ownerName = Mangle::ASTMangler().mangleNominalType(typeDecl);
630+
std::string ownerName = Mangle::ASTMangler().mangleNominalType(classDecl);
631631
auto results = *known;
632632
for (const auto &result : results) {
633633
// If the method is the wrong kind (instance vs. class), skip it.

lib/Serialization/ModuleFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class ModuleFile
631631
///
632632
/// \param methods The list of @objc methods in this class that have this
633633
/// selector and are instance/class methods as requested.
634-
void loadObjCMethods(NominalTypeDecl *typeDecl,
634+
void loadObjCMethods(ClassDecl *classDecl,
635635
ObjCSelector selector,
636636
bool isInstanceMethod,
637637
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 697; // change local type mangling
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 698; // revert selector table changes
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,10 +5533,10 @@ static void collectInterestingNestedDeclarations(
55335533
if (isLocal)
55345534
return;
55355535

5536-
if (auto owningType = func->getDeclContext()->getSelfNominalTypeDecl()) {
5536+
if (auto owningClass = func->getDeclContext()->getSelfClassDecl()) {
55375537
if (func->isObjC()) {
55385538
Mangle::ASTMangler mangler;
5539-
std::string ownerName = mangler.mangleNominalType(owningType);
5539+
std::string ownerName = mangler.mangleNominalType(owningClass);
55405540
assert(!ownerName.empty() && "Mangled type came back empty!");
55415541

55425542
objcMethods[func->getObjCSelector()].push_back(

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,15 +1320,15 @@ void SerializedModuleLoaderBase::loadExtensions(NominalTypeDecl *nominal,
13201320
}
13211321

13221322
void SerializedModuleLoaderBase::loadObjCMethods(
1323-
NominalTypeDecl *typeDecl,
1323+
ClassDecl *classDecl,
13241324
ObjCSelector selector,
13251325
bool isInstanceMethod,
13261326
unsigned previousGeneration,
13271327
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods) {
13281328
for (auto &modulePair : LoadedModuleFiles) {
13291329
if (modulePair.second <= previousGeneration)
13301330
continue;
1331-
modulePair.first->loadObjCMethods(typeDecl, selector, isInstanceMethod,
1331+
modulePair.first->loadObjCMethods(classDecl, selector, isInstanceMethod,
13321332
methods);
13331333
}
13341334
}

0 commit comments

Comments
 (0)