Skip to content

Commit 518ab9f

Browse files
committed
[NFC] Unblock Lazy Member Loading For Import-As-Member
Lazy member loading had an antagonistic relationship with the import-as-member facilities. The member tables were stored in a hash map that is keyed by serialized declaration context. While this was good for importing the entire member set of a given extension, it's in the complete wrong order for lazy member loading, which wants the same data keyed by base name. Given that it is annoying to redo the globals-as-member tables to support one use case or the other, coupled with the fact that optimizing for one use-case automatically pessimizes the other, just take a page from rdar://18696086 and store the same information twice in two separate formats each optimized for the task at hand. Preliminary benchmarks indicate that this leads to a 5% reduction in Clang-Imported entities which will drastically speed up most apps that use Dispatch and CoreGraphics.
1 parent 6e7521a commit 518ab9f

File tree

4 files changed

+320
-89
lines changed

4 files changed

+320
-89
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ void ClangImporter::loadExtensions(NominalTypeDecl *nominal,
30103010
// FIXME: If we already looked at this for this generation,
30113011
// skip.
30123012

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

@@ -3763,17 +3763,6 @@ ClangImporter::Implementation::loadNamedMembers(
37633763
return None;
37643764
}
37653765

3766-
// Also bail out if there are any global-as-member mappings for this context;
3767-
// we can support some of them lazily but the full set of idioms seems
3768-
// prohibitively complex (also they're not stored in by-name lookup, for
3769-
// reasons unclear).
3770-
if (isa<ExtensionDecl>(D) && !checkedGlobalsAsMembers.insert(IDC).second) {
3771-
if (forEachLookupTable([&](SwiftLookupTable &table) -> bool {
3772-
return (!table.lookupGlobalsAsMembers(effectiveClangContext).empty());
3773-
}))
3774-
return None;
3775-
}
3776-
37773766
// There are 3 cases:
37783767
//
37793768
// - The decl is from a bridging header, CMO is Some(nullptr)
@@ -3823,6 +3812,27 @@ ClangImporter::Implementation::loadNamedMembers(
38233812
}
38243813
}
38253814

3815+
for (auto entry : table->lookupGlobalsAsMembers(SerializedSwiftName(N),
3816+
effectiveClangContext)) {
3817+
if (!entry.is<clang::NamedDecl *>()) continue;
3818+
auto member = entry.get<clang::NamedDecl *>();
3819+
if (!isVisibleClangEntry(clangCtx, member)) continue;
3820+
3821+
// Skip Decls from different clang::DeclContexts
3822+
if (member->getDeclContext() != CDC) continue;
3823+
3824+
SmallVector<Decl*, 4> tmp;
3825+
insertMembersAndAlternates(member, tmp);
3826+
for (auto *TD : tmp) {
3827+
if (auto *V = dyn_cast<ValueDecl>(TD)) {
3828+
// Skip ValueDecls if they import under different names.
3829+
if (V->getBaseName() == N) {
3830+
Members.push_back(V);
3831+
}
3832+
}
3833+
}
3834+
}
3835+
38263836
if (N == DeclBaseName::createConstructor()) {
38273837
if (auto *classDecl = dyn_cast<ClassDecl>(D)) {
38283838
SmallVector<Decl *, 4> ctors;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8544,7 +8544,7 @@ void ClangImporter::Implementation::loadAllMembersIntoExtension(
85448544
startedImportingEntity();
85458545

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

85508550
// Only include members in the same submodule as this extension.

0 commit comments

Comments
 (0)