Skip to content

ClangImporter: Don't force loading of all superclass members in loadNamedMembers() #29348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3726,21 +3726,32 @@ void ClangImporter::Implementation::lookupAllObjCMembers(
// deserialized before loading the named member of this class. This allows the
// decl members table to be warmed up and enables the correct identification of
// overrides.
//
// FIXME: Very low hanging fruit: Loading everything is extremely wasteful. We
// should be able to just load the name lazy member loading is asking for.
static void ensureSuperclassMembersAreLoaded(const ClassDecl *CD) {
static void loadNamedMemberOfSuperclassIfNeeded(const ClassDecl *CD,
DeclBaseName name) {
if (!CD)
return;

CD = CD->getSuperclassDecl();
if (!CD || !CD->hasClangNode())
if (!CD)
return;

CD->loadAllMembers();

for (auto *ED : const_cast<ClassDecl *>(CD)->getExtensions())
ED->loadAllMembers();
auto &ctx = CD->getASTContext();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can actually be replaced with a call to (void) CD->lookupDirect(name). I'm going to test and benchmark both versions before checking this in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.


if (CD->hasClangNode() && CD->hasLazyMembers()) {
auto ci = ctx.getOrCreateLazyIterableContextData(
CD, /*lazyLoader=*/nullptr);
if (true || !ci->loader->loadNamedMembers(CD, name, ci->memberData))
CD->loadAllMembers();
}

for (auto *ED : const_cast<ClassDecl *>(CD)->getExtensions()) {
if (ED->hasClangNode() && ED->hasLazyMembers()) {
auto ci = ctx.getOrCreateLazyIterableContextData(
ED, /*lazyLoader=*/nullptr);
if (true || !ci->loader->loadNamedMembers(ED, name, ci->memberData))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat debugging trick, but we oughta get these out before this is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that wasn't supposed to be in there. It works without the 'true ||' too.

ED->loadAllMembers();
}
}
}

Optional<TinyPtrVector<ValueDecl *>>
Expand Down Expand Up @@ -3793,7 +3804,7 @@ ClangImporter::Implementation::loadNamedMembers(

assert(isa<clang::ObjCContainerDecl>(CD) || isa<clang::NamespaceDecl>(CD));

ensureSuperclassMembersAreLoaded(dyn_cast<ClassDecl>(D));
loadNamedMemberOfSuperclassIfNeeded(dyn_cast<ClassDecl>(D), N);

TinyPtrVector<ValueDecl *> Members;
for (auto entry : table->lookup(SerializedSwiftName(N),
Expand Down Expand Up @@ -3823,7 +3834,7 @@ ClangImporter::Implementation::loadNamedMembers(
auto member = entry.get<clang::NamedDecl *>();
if (!isVisibleClangEntry(clangCtx, member)) continue;

// Skip Decls from different clang::DeclContexts
// Skip Decls from different clang::DeclContexts
if (member->getDeclContext() != CDC) continue;

SmallVector<Decl*, 4> tmp;
Expand Down
2 changes: 2 additions & 0 deletions test/IRGen/Inputs/usr/include/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module SRoA {

module ObjectiveC {
header "BridgeTestObjectiveC.h"
export *
}

module CoreCooling {
Expand All @@ -17,6 +18,7 @@ module CoreCooling {

module Foundation {
header "BridgeTestFoundation.h"
export *
}

module CoreFoundation {
Expand Down