Skip to content

[NFC] Unblock Lazy Member Loading For Import-As-Member #29090

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

Merged
merged 1 commit into from
Jan 9, 2020
Merged
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
34 changes: 22 additions & 12 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3010,7 +3010,7 @@ void ClangImporter::loadExtensions(NominalTypeDecl *nominal,
// FIXME: If we already looked at this for this generation,
// skip.

for (auto entry : table.lookupGlobalsAsMembers(effectiveClangContext)) {
for (auto entry : table.allGlobalsAsMembersInContext(effectiveClangContext)) {
// If the entry is not visible, skip it.
if (!isVisibleClangEntry(clangCtx, entry)) continue;

Expand Down Expand Up @@ -3763,17 +3763,6 @@ ClangImporter::Implementation::loadNamedMembers(
return None;
}

// Also bail out if there are any global-as-member mappings for this context;
// we can support some of them lazily but the full set of idioms seems
// prohibitively complex (also they're not stored in by-name lookup, for
// reasons unclear).
if (isa<ExtensionDecl>(D) && !checkedGlobalsAsMembers.insert(IDC).second) {
if (forEachLookupTable([&](SwiftLookupTable &table) -> bool {
return (!table.lookupGlobalsAsMembers(effectiveClangContext).empty());
}))
return None;
}

// There are 3 cases:
//
// - The decl is from a bridging header, CMO is Some(nullptr)
Expand Down Expand Up @@ -3823,6 +3812,27 @@ ClangImporter::Implementation::loadNamedMembers(
}
}

for (auto entry : table->lookupGlobalsAsMembers(SerializedSwiftName(N),
effectiveClangContext)) {
if (!entry.is<clang::NamedDecl *>()) continue;
auto member = entry.get<clang::NamedDecl *>();
if (!isVisibleClangEntry(clangCtx, member)) continue;

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

SmallVector<Decl*, 4> tmp;
insertMembersAndAlternates(member, tmp);
for (auto *TD : tmp) {
if (auto *V = dyn_cast<ValueDecl>(TD)) {
// Skip ValueDecls if they import under different names.
if (V->getBaseName() == N) {
Members.push_back(V);
}
}
}
}

if (N == DeclBaseName::createConstructor()) {
if (auto *classDecl = dyn_cast<ClassDecl>(D)) {
SmallVector<Decl *, 4> ctors;
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8544,7 +8544,7 @@ void ClangImporter::Implementation::loadAllMembersIntoExtension(
startedImportingEntity();

// Load the members.
for (auto entry : table->lookupGlobalsAsMembers(effectiveClangContext)) {
for (auto entry : table->allGlobalsAsMembersInContext(effectiveClangContext)) {
auto decl = entry.get<clang::NamedDecl *>();

// Only include members in the same submodule as this extension.
Expand Down
Loading