Skip to content

Commit 4a9fc98

Browse files
authored
Merge pull request #29093 from CodaFi/proteomics
[NFC] Clean the ClangImporter a bit
2 parents 939034a + a4105b1 commit 4a9fc98

File tree

2 files changed

+19
-51
lines changed

2 files changed

+19
-51
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,11 +4492,6 @@ namespace {
44924492
const clang::ObjCProtocolList &clangProtocols,
44934493
SmallVectorImpl<TypeLoc> &inheritedTypes);
44944494

4495-
/// Add conformances to the given Objective-C protocols to the
4496-
/// given declaration.
4497-
void addObjCProtocolConformances(Decl *decl,
4498-
ArrayRef<ProtocolDecl*> protocols);
4499-
45004495
// Returns None on error. Returns nullptr if there is no type param list to
45014496
// import or we suppress its import, as in the case of NSArray, NSSet, and
45024497
// NSDictionary.
@@ -4517,7 +4512,6 @@ namespace {
45174512
/// methods become class methods on NSObject).
45184513
void importMirroredProtocolMembers(const clang::ObjCContainerDecl *decl,
45194514
DeclContext *dc,
4520-
ArrayRef<ProtocolDecl *> protocols,
45214515
SmallVectorImpl<Decl *> &members);
45224516

45234517
void importNonOverriddenMirroredMethods(DeclContext *dc,
@@ -6860,22 +6854,7 @@ void SwiftDeclConverter::importObjCProtocols(
68606854
}
68616855
}
68626856

6863-
addObjCProtocolConformances(decl, protocols);
6864-
}
6865-
6866-
void SwiftDeclConverter::addObjCProtocolConformances(
6867-
Decl *decl, ArrayRef<ProtocolDecl *> protocols) {
6868-
// Nothing to do for protocols.
6869-
if (isa<ProtocolDecl>(decl)) return;
6870-
68716857
Impl.recordImportedProtocols(decl, protocols);
6872-
6873-
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
6874-
nominal->setConformanceLoader(&Impl, 0);
6875-
} else {
6876-
auto ext = cast<ExtensionDecl>(decl);
6877-
ext->setConformanceLoader(&Impl, 0);
6878-
}
68796858
}
68806859

68816860
Optional<GenericParamList *> SwiftDeclConverter::importObjCGenericParams(
@@ -6940,22 +6919,18 @@ Optional<GenericParamList *> SwiftDeclConverter::importObjCGenericParams(
69406919

69416920
void SwiftDeclConverter::importMirroredProtocolMembers(
69426921
const clang::ObjCContainerDecl *decl, DeclContext *dc,
6943-
ArrayRef<ProtocolDecl *> protocols, SmallVectorImpl<Decl *> &members) {
6922+
SmallVectorImpl<Decl *> &members) {
69446923
assert(dc);
69456924
const clang::ObjCInterfaceDecl *interfaceDecl = nullptr;
69466925
const ClangModuleUnit *declModule;
69476926
const ClangModuleUnit *interfaceModule;
69486927

6949-
// 'protocols' is, for some reason, the full recursive expansion of
6950-
// the protocol hierarchy, so there's no need to recursively descend
6951-
// into inherited protocols.
6952-
69536928
// Try to import only the most specific methods with a particular name.
69546929
// We use a MapVector to get deterministic iteration order later.
69556930
llvm::MapVector<clang::Selector, std::vector<MirroredMethodEntry>>
69566931
methodsByName;
69576932

6958-
for (auto proto : protocols) {
6933+
for (auto proto : Impl.getImportedProtocols(dc->getAsDecl())) {
69596934
auto clangProto =
69606935
cast_or_null<clang::ObjCProtocolDecl>(proto->getClangDecl());
69616936
if (!clangProto)
@@ -8600,20 +8575,6 @@ bool ClangImporter::Implementation::addMemberAndAlternatesToExtension(
86008575
return true;
86018576
}
86028577

8603-
static ExtensionDecl *
8604-
figureOutTheDeclarationContextToImportInto(Decl *D, DeclContext *&DC,
8605-
IterableDeclContext *&IDC) {
8606-
if (auto *nominal = dyn_cast<NominalTypeDecl>(D)) {
8607-
DC = nominal;
8608-
IDC = nominal;
8609-
return nullptr;
8610-
}
8611-
ExtensionDecl *ext = cast<ExtensionDecl>(D);
8612-
DC = ext;
8613-
IDC = ext;
8614-
return ext;
8615-
}
8616-
86178578
static void loadMembersOfBaseImportedFromClang(ExtensionDecl *ext) {
86188579
const NominalTypeDecl *base = ext->getExtendedNominal();
86198580
auto *clangBase = base->getClangDecl();
@@ -8635,19 +8596,18 @@ void ClangImporter::Implementation::loadAllMembersOfObjcContainer(
86358596
Instance->getSourceManager(),
86368597
"loading members for");
86378598

8638-
DeclContext *DC;
8639-
IterableDeclContext *IDC;
8640-
if (ExtensionDecl *ext =
8641-
figureOutTheDeclarationContextToImportInto(D, DC, IDC)) {
8642-
// If the base is also imported from Clang, load its members first.
8599+
assert(isa<ExtensionDecl>(D) || isa<NominalTypeDecl>(D));
8600+
if (auto *ext = dyn_cast<ExtensionDecl>(D)) {
8601+
// If the extended type is also imported from Clang, load its members first.
86438602
loadMembersOfBaseImportedFromClang(ext);
86448603
}
86458604

86468605
startedImportingEntity();
86478606

86488607
SmallVector<Decl *, 16> members;
8649-
collectMembersToAdd(objcContainer, D, DC, members);
8608+
collectMembersToAdd(objcContainer, D, cast<DeclContext>(D), members);
86508609

8610+
auto *IDC = cast<IterableDeclContext>(D);
86518611
for (auto member : members) {
86528612
if (!isa<AccessorDecl>(member))
86538613
IDC->addMember(member);
@@ -8701,8 +8661,6 @@ void ClangImporter::Implementation::collectMembersToAdd(
87018661
}
87028662

87038663
SwiftDeclConverter converter(*this, CurrentVersion);
8704-
8705-
auto protos = getImportedProtocols(D);
87068664
if (auto clangClass = dyn_cast<clang::ObjCInterfaceDecl>(objcContainer)) {
87078665
objcContainer = clangClass = clangClass->getDefinition();
87088666
importInheritedConstructors(clangClass, cast<ClassDecl>(D), members);
@@ -8713,7 +8671,7 @@ void ClangImporter::Implementation::collectMembersToAdd(
87138671
// Import mirrored declarations for protocols to which this category
87148672
// or extension conforms.
87158673
// FIXME: This is supposed to be a short-term hack.
8716-
converter.importMirroredProtocolMembers(objcContainer, DC, protos, members);
8674+
converter.importMirroredProtocolMembers(objcContainer, DC, members);
87178675
}
87188676

87198677
void ClangImporter::Implementation::loadAllConformances(

lib/ClangImporter/ImporterImpl.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,12 +1180,22 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
11801180
///
11811181
/// FIXME: This is all a hack; we should have lazier deserialization
11821182
/// of protocols separate from their conformances.
1183-
void recordImportedProtocols(const Decl *decl,
1183+
void recordImportedProtocols(Decl *decl,
11841184
ArrayRef<ProtocolDecl *> protocols) {
1185+
// Nothing to do for protocols.
1186+
if (isa<ProtocolDecl>(decl)) return;
1187+
11851188
if (protocols.empty())
11861189
return;
11871190

11881191
ImportedProtocols[decl] = SwiftContext.AllocateCopy(protocols);
1192+
1193+
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
1194+
nominal->setConformanceLoader(this, 0);
1195+
} else {
1196+
auto ext = cast<ExtensionDecl>(decl);
1197+
ext->setConformanceLoader(this, 0);
1198+
}
11891199
}
11901200

11911201
/// Retrieve the imported protocols for the given declaration.

0 commit comments

Comments
 (0)