Skip to content

Commit 7c0c092

Browse files
committed
Eagerly update a protocol's "has missing required members" flag.
Rather than plumbing a "has missing required members" flag all the way through the LazyResolver's loadAllMembers and its implementations, just eagerly update the "has missing required members" flag in the Clang importer when it happens. More NFC cleanup.
1 parent 1092704 commit 7c0c092

File tree

6 files changed

+34
-42
lines changed

6 files changed

+34
-42
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ class alignas(void*) LazyMemberLoader {
129129
/// Populates the given vector with all member decls for \p D.
130130
///
131131
/// The implementation should add the members to D.
132-
///
133-
/// \param[out] hasMissingRequiredMembers If present, set to true if any
134-
/// members failed to import and were non-optional protocol requirements.
135132
virtual void
136-
loadAllMembers(Decl *D, uint64_t contextData,
137-
bool *hasMissingRequiredMembers = nullptr) {
133+
loadAllMembers(Decl *D, uint64_t contextData) {
138134
llvm_unreachable("unimplemented");
139135
}
140136

include/swift/Serialization/ModuleFile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ class ModuleFile : public LazyMemberLoader {
589589
void verify() const;
590590

591591
virtual void loadAllMembers(Decl *D,
592-
uint64_t contextData,
593-
bool *ignored) override;
592+
uint64_t contextData) override;
594593

595594
virtual void
596595
loadAllConformances(const Decl *D, uint64_t contextData,

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,7 @@ void IterableDeclContext::loadAllMembers() const {
803803
break;
804804
}
805805

806-
bool hasMissingRequiredMembers = false;
807-
resolver->loadAllMembers(const_cast< Decl *>(container), contextData,
808-
&hasMissingRequiredMembers);
809-
810-
if (hasMissingRequiredMembers)
811-
if (auto proto = dyn_cast<ProtocolDecl>(this))
812-
const_cast<ProtocolDecl *>(proto)->setHasMissingRequirements(true);
806+
resolver->loadAllMembers(const_cast< Decl *>(container), contextData);
813807

814808
--NumUnloadedLazyIterableDeclContexts;
815809
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,8 +4201,7 @@ namespace {
42014201
/// list of corresponding Swift members.
42024202
void importObjCMembers(const clang::ObjCContainerDecl *decl,
42034203
DeclContext *swiftContext,
4204-
SmallVectorImpl<Decl *> &members,
4205-
bool &hasMissingRequiredMember) {
4204+
SmallVectorImpl<Decl *> &members) {
42064205
llvm::SmallPtrSet<Decl *, 4> knownMembers;
42074206
for (auto m = decl->decls_begin(), mEnd = decl->decls_end();
42084207
m != mEnd; ++m) {
@@ -4211,18 +4210,7 @@ namespace {
42114210
continue;
42124211

42134212
auto member = Impl.importDecl(nd);
4214-
if (!member) {
4215-
if (auto method = dyn_cast<clang::ObjCMethodDecl>(nd)) {
4216-
if (method->getImplementationControl() ==
4217-
clang::ObjCMethodDecl::Required)
4218-
hasMissingRequiredMember = true;
4219-
} else if (auto prop = dyn_cast<clang::ObjCPropertyDecl>(nd)) {
4220-
if (prop->getPropertyImplementation() ==
4221-
clang::ObjCPropertyDecl::Required)
4222-
hasMissingRequiredMember = true;
4223-
}
4224-
continue;
4225-
}
4213+
if (!member) continue;
42264214

42274215
if (auto objcMethod = dyn_cast<clang::ObjCMethodDecl>(nd)) {
42284216
// If there is a alternate declaration for this member, add it.
@@ -5421,8 +5409,32 @@ ClangImporter::Implementation::importDeclImpl(const clang::NamedDecl *ClangDecl,
54215409
Result = converter.Visit(ClangDecl);
54225410
HadForwardDeclaration = converter.hadForwardDeclaration();
54235411
}
5424-
if (!Result)
5412+
if (!Result) {
5413+
// If we couldn't import this Objective-C entity, determine
5414+
// whether it was a required member of a protocol.
5415+
bool hasMissingRequiredMember = false;
5416+
if (auto clangProto
5417+
= dyn_cast<clang::ObjCProtocolDecl>(ClangDecl->getDeclContext())) {
5418+
if (auto method = dyn_cast<clang::ObjCMethodDecl>(ClangDecl)) {
5419+
if (method->getImplementationControl()
5420+
== clang::ObjCMethodDecl::Required)
5421+
hasMissingRequiredMember = true;
5422+
} else if (auto prop = dyn_cast<clang::ObjCPropertyDecl>(ClangDecl)) {
5423+
if (prop->getPropertyImplementation()
5424+
== clang::ObjCPropertyDecl::Required)
5425+
hasMissingRequiredMember = true;
5426+
}
5427+
5428+
if (hasMissingRequiredMember) {
5429+
// Mark the protocol as having missing requirements.
5430+
if (auto proto = cast_or_null<ProtocolDecl>(importDecl(clangProto))) {
5431+
proto->setHasMissingRequirements(true);
5432+
}
5433+
}
5434+
}
5435+
54255436
return nullptr;
5437+
}
54265438

54275439
// Finalize the imported declaration.
54285440
auto finalizeDecl = [&](Decl *result) {
@@ -5917,8 +5929,7 @@ createUnavailableDecl(Identifier name, DeclContext *dc, Type type,
59175929

59185930

59195931
void
5920-
ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t unused,
5921-
bool *hasMissingRequiredMembers) {
5932+
ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t unused) {
59225933
assert(D->hasClangNode());
59235934
auto clangDecl = cast<clang::ObjCContainerDecl>(D->getClangDecl());
59245935

@@ -5945,12 +5956,7 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t unused,
59455956
ImportingEntityRAII Importing(*this);
59465957

59475958
SmallVector<Decl *, 16> members;
5948-
bool scratch;
5949-
if (!hasMissingRequiredMembers)
5950-
hasMissingRequiredMembers = &scratch;
5951-
*hasMissingRequiredMembers = false;
5952-
converter.importObjCMembers(clangDecl, DC,
5953-
members, *hasMissingRequiredMembers);
5959+
converter.importObjCMembers(clangDecl, DC, members);
59545960

59555961
protos = takeImportedProtocols(D);
59565962
if (auto clangClass = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl)) {

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
12561256
}
12571257

12581258
virtual void
1259-
loadAllMembers(Decl *D, uint64_t unused,
1260-
bool *hasMissingRequiredMembers) override;
1259+
loadAllMembers(Decl *D, uint64_t unused) override;
12611260

12621261
void
12631262
loadAllConformances(

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,9 +3919,7 @@ Type ModuleFile::getType(TypeID TID) {
39193919
return typeOrOffset;
39203920
}
39213921

3922-
void ModuleFile::loadAllMembers(Decl *D,
3923-
uint64_t contextData,
3924-
bool *) {
3922+
void ModuleFile::loadAllMembers(Decl *D, uint64_t contextData) {
39253923
PrettyStackTraceDecl trace("loading members for", D);
39263924

39273925
BCOffsetRAII restoreOffset(DeclTypeCursor);

0 commit comments

Comments
 (0)