mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user