mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Lift nested type lookup fast-pathing up to FileUnit.
We use this to avoid circularity issues in serialization; we'd like to extend that to the Clang importer. This is only necessary because we can't look up a single member at a time, but it can still fix issues in the short term. This commit should have no effect on functionality.
This commit is contained in:
@@ -555,6 +555,18 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Directly look for a nested type declared within this module inside the
|
||||||
|
/// given nominal type (including any extensions).
|
||||||
|
///
|
||||||
|
/// This is a fast-path hack to avoid circular dependencies in deserialization
|
||||||
|
/// and the Clang importer.
|
||||||
|
///
|
||||||
|
/// Private and fileprivate types should not be returned by this lookup.
|
||||||
|
virtual TypeDecl *lookupNestedType(Identifier name,
|
||||||
|
const NominalTypeDecl *parent) const {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/// Find ValueDecls in the module and pass them to the given consumer object.
|
/// Find ValueDecls in the module and pass them to the given consumer object.
|
||||||
///
|
///
|
||||||
/// This does a simple local lookup, not recursively looking through imports.
|
/// This does a simple local lookup, not recursively looking through imports.
|
||||||
|
|||||||
@@ -603,7 +603,7 @@ public:
|
|||||||
|
|
||||||
/// Searches the module's nested type decls table for the given member of
|
/// Searches the module's nested type decls table for the given member of
|
||||||
/// the given type.
|
/// the given type.
|
||||||
TypeDecl *lookupNestedType(Identifier name, const ValueDecl *parent);
|
TypeDecl *lookupNestedType(Identifier name, const NominalTypeDecl *parent);
|
||||||
|
|
||||||
/// Searches the module's operators for one with the given name and fixity.
|
/// Searches the module's operators for one with the given name and fixity.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ public:
|
|||||||
|
|
||||||
virtual TypeDecl *lookupLocalType(StringRef MangledName) const override;
|
virtual TypeDecl *lookupLocalType(StringRef MangledName) const override;
|
||||||
|
|
||||||
|
virtual TypeDecl *
|
||||||
|
lookupNestedType(Identifier name,
|
||||||
|
const NominalTypeDecl *parent) const override;
|
||||||
|
|
||||||
virtual OperatorDecl *lookupOperator(Identifier name,
|
virtual OperatorDecl *lookupOperator(Identifier name,
|
||||||
DeclKind fixity) const override;
|
DeclKind fixity) const override;
|
||||||
|
|
||||||
|
|||||||
@@ -1319,9 +1319,7 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
|
|||||||
&blobData);
|
&blobData);
|
||||||
switch (recordID) {
|
switch (recordID) {
|
||||||
case XREF_TYPE_PATH_PIECE: {
|
case XREF_TYPE_PATH_PIECE: {
|
||||||
if (values.size() == 1) {
|
if (values.size() == 1 && isa<NominalTypeDecl>(values.front())) {
|
||||||
ModuleDecl *module = values.front()->getModuleContext();
|
|
||||||
|
|
||||||
// Fast path for nested types that avoids deserializing all
|
// Fast path for nested types that avoids deserializing all
|
||||||
// members of the parent type.
|
// members of the parent type.
|
||||||
IdentifierID IID;
|
IdentifierID IID;
|
||||||
@@ -1334,29 +1332,23 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
|
|||||||
"If you're seeing a crash here, try passing "
|
"If you're seeing a crash here, try passing "
|
||||||
"-Xfrontend -disable-serialization-nested-type-lookup-table"};
|
"-Xfrontend -disable-serialization-nested-type-lookup-table"};
|
||||||
|
|
||||||
|
auto *baseType = cast<NominalTypeDecl>(values.front());
|
||||||
TypeDecl *nestedType = nullptr;
|
TypeDecl *nestedType = nullptr;
|
||||||
if (onlyInNominal) {
|
if (onlyInNominal) {
|
||||||
// Only look in the file containing the type itself.
|
// Only look in the file containing the type itself.
|
||||||
const DeclContext *dc = values.front()->getDeclContext();
|
const DeclContext *dc = values.front()->getDeclContext();
|
||||||
auto *serializedFile =
|
auto *containingFile =
|
||||||
dyn_cast<SerializedASTFile>(dc->getModuleScopeContext());
|
dyn_cast<FileUnit>(dc->getModuleScopeContext());
|
||||||
if (serializedFile) {
|
if (containingFile) {
|
||||||
nestedType =
|
nestedType = containingFile->lookupNestedType(memberName, baseType);
|
||||||
serializedFile->File.lookupNestedType(memberName,
|
|
||||||
values.front());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fault in extensions, then ask every serialized AST in the module.
|
// Fault in extensions, then ask every serialized AST in the module.
|
||||||
(void)cast<NominalTypeDecl>(values.front())->getExtensions();
|
(void)baseType->getExtensions();
|
||||||
for (FileUnit *file : module->getFiles()) {
|
for (FileUnit *file : baseType->getModuleContext()->getFiles()) {
|
||||||
if (file == getFile())
|
if (file == getFile())
|
||||||
continue;
|
continue;
|
||||||
auto *serializedFile = dyn_cast<SerializedASTFile>(file);
|
nestedType = file->lookupNestedType(memberName, baseType);
|
||||||
if (!serializedFile)
|
|
||||||
continue;
|
|
||||||
nestedType =
|
|
||||||
serializedFile->File.lookupNestedType(memberName,
|
|
||||||
values.front());
|
|
||||||
if (nestedType)
|
if (nestedType)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1363,7 +1363,7 @@ TypeDecl *ModuleFile::lookupLocalType(StringRef MangledName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TypeDecl *ModuleFile::lookupNestedType(Identifier name,
|
TypeDecl *ModuleFile::lookupNestedType(Identifier name,
|
||||||
const ValueDecl *parent) {
|
const NominalTypeDecl *parent) {
|
||||||
PrettyStackTraceModuleFile stackEntry(*this);
|
PrettyStackTraceModuleFile stackEntry(*this);
|
||||||
|
|
||||||
if (!NestedTypeDecls)
|
if (!NestedTypeDecls)
|
||||||
|
|||||||
@@ -525,6 +525,12 @@ TypeDecl *SerializedASTFile::lookupLocalType(llvm::StringRef MangledName) const{
|
|||||||
return File.lookupLocalType(MangledName);
|
return File.lookupLocalType(MangledName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypeDecl *
|
||||||
|
SerializedASTFile::lookupNestedType(Identifier name,
|
||||||
|
const NominalTypeDecl *parent) const {
|
||||||
|
return File.lookupNestedType(name, parent);
|
||||||
|
}
|
||||||
|
|
||||||
OperatorDecl *SerializedASTFile::lookupOperator(Identifier name,
|
OperatorDecl *SerializedASTFile::lookupOperator(Identifier name,
|
||||||
DeclKind fixity) const {
|
DeclKind fixity) const {
|
||||||
return File.lookupOperator(name, fixity);
|
return File.lookupOperator(name, fixity);
|
||||||
|
|||||||
Reference in New Issue
Block a user