Skip to content

Commit b654bc3

Browse files
committed
Force load all members of iterable contexts in the DWARF Importer
The DWARF Importer does not yet know how to answer a request at the level of a single member. All the tests that saw this as an observable behavior were actually seeing a complete cache fill from lazy member loading an initializer fail over to flushing the member table and rebuilding it by forcing all the members. Given that the cache flush is something we're trying to avoid in general, this is obviously undesirable behavior. Now that we're no longer flushing the cache for initializers, the DWARF Importer needs to simulate the old behavior and completely deserialize members of loaded types. This pessimization is justified anyways, considering if you're loading from DWARF, you're probably about to print the type and its fields anyways.
1 parent a1b4514 commit b654bc3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
128128
return decl;
129129
}
130130

131+
// This function exists to defeat the lazy member importing mechanism. The
132+
// DWARFImporter is not capable of loading individual members, so it cannot
133+
// benefit from this optimization yet anyhow. Besides, if you're importing a
134+
// type here, you more than likely want to dump it and its fields. Loading all
135+
// members populates lookup tables in the Clang Importer and ensures the
136+
// absence of cache-fill-related side effects.
137+
static void forceLoadAllMembers(IterableDeclContext *IDC) {
138+
if (!IDC) return;
139+
IDC->loadAllMembers();
140+
}
141+
131142
void ClangImporter::Implementation::lookupValueDWARF(
132143
DeclName name, NLKind lookupKind, Identifier inModule,
133144
SmallVectorImpl<ValueDecl *> &results) {
@@ -150,8 +161,10 @@ void ClangImporter::Implementation::lookupValueDWARF(
150161
continue;
151162

152163
if (swiftDecl->getFullName().matchesRef(name) &&
153-
swiftDecl->getDeclContext()->isModuleScopeContext())
164+
swiftDecl->getDeclContext()->isModuleScopeContext()) {
165+
forceLoadAllMembers(dyn_cast<IterableDeclContext>(swiftDecl));
154166
results.push_back(swiftDecl);
167+
}
155168
}
156169
}
157170

@@ -174,8 +187,10 @@ void ClangImporter::Implementation::lookupTypeDeclDWARF(
174187
Decl *importedDecl = cast_or_null<ValueDecl>(
175188
importDeclReal(namedDecl->getMostRecentDecl(), CurrentVersion));
176189

177-
if (auto *importedType = dyn_cast_or_null<TypeDecl>(importedDecl))
190+
if (auto *importedType = dyn_cast_or_null<TypeDecl>(importedDecl)) {
191+
forceLoadAllMembers(dyn_cast<IterableDeclContext>(importedType));
178192
receiver(importedType);
193+
}
179194
}
180195
}
181196

0 commit comments

Comments
 (0)