[Serialization] Fast lookup of nested types in modules with overlays (#20024)

Previously, the fast path for nested types only worked when the nested
type was defined in a Swift module or a Clang module without an
overlay; this is because it was originally designed to fix circularity
issues when merging partial modules for a single target. By having a
Swift overlay module pass through requests for nested types to the
underlying Clang module, we get the fast-path behavior in more cases.
(The one case where it /won't/ kick in is if the overlay has a nested
type that shadows a nested type from the Clang module, but that's
probably pretty rare!)
This commit is contained in:
Jordan Rose
2018-10-24 18:56:55 -07:00
committed by GitHub
parent 1c0778bb5b
commit 14d4235b57
10 changed files with 96 additions and 30 deletions

View File

@@ -1575,26 +1575,30 @@ TypeDecl *ModuleFile::lookupNestedType(Identifier name,
const NominalTypeDecl *parent) {
PrettyStackTraceModuleFile stackEntry(*this);
if (!NestedTypeDecls)
return nullptr;
if (NestedTypeDecls) {
auto iter = NestedTypeDecls->find(name);
if (iter != NestedTypeDecls->end()) {
for (std::pair<DeclID, DeclID> entry : *iter) {
assert(entry.first);
auto declOrOffset = Decls[entry.first - 1];
if (!declOrOffset.isComplete())
continue;
auto iter = NestedTypeDecls->find(name);
if (iter == NestedTypeDecls->end())
return nullptr;
auto data = *iter;
for (std::pair<DeclID, DeclID> entry : data) {
assert(entry.first);
auto declOrOffset = Decls[entry.first - 1];
if (!declOrOffset.isComplete())
continue;
Decl *decl = declOrOffset;
if (decl != parent)
continue;
return cast<TypeDecl>(getDecl(entry.second));
Decl *decl = declOrOffset;
if (decl != parent)
continue;
return cast<TypeDecl>(getDecl(entry.second));
}
}
}
if (!ShadowedModule)
return nullptr;
for (FileUnit *file : ShadowedModule->getFiles())
if (auto *nestedType = file->lookupNestedType(name, parent))
return nestedType;
return nullptr;
}