mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Use ImportCache to simplify SourceFile::isImportedImplementationOnly()
This commit is contained in:
@@ -1611,20 +1611,7 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
|
|||||||
if (!hasImplementationOnlyImports())
|
if (!hasImplementationOnlyImports())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto isImportedBy = [](const ModuleDecl *dest, const ModuleDecl *src) {
|
auto &imports = getASTContext().getImportCache();
|
||||||
// Fast path.
|
|
||||||
if (dest == src) return true;
|
|
||||||
|
|
||||||
// Walk the transitive imports, respecting visibility.
|
|
||||||
// This return true if the search *didn't* short-circuit, and it short
|
|
||||||
// circuits if we found `dest`, so we need to invert the sense before
|
|
||||||
// returning.
|
|
||||||
return !const_cast<ModuleDecl*>(src)
|
|
||||||
->forAllVisibleModules({}, [dest](ModuleDecl::ImportedModule im) {
|
|
||||||
// Continue searching as long as we haven't found `dest` yet.
|
|
||||||
return im.second != dest;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Look at the imports of this source file.
|
// Look at the imports of this source file.
|
||||||
for (auto &desc : Imports) {
|
for (auto &desc : Imports) {
|
||||||
@@ -1634,12 +1621,12 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
|
|||||||
|
|
||||||
// If the module is imported this way, it's not imported
|
// If the module is imported this way, it's not imported
|
||||||
// implementation-only.
|
// implementation-only.
|
||||||
if (isImportedBy(module, desc.module.second))
|
if (imports.isImportedBy(module, desc.module.second))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now check this file's enclosing module in case there are re-exports.
|
// Now check this file's enclosing module in case there are re-exports.
|
||||||
return !isImportedBy(module, getParentModule());
|
return !imports.isImportedBy(module, getParentModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleDecl::clearLookupCache() {
|
void ModuleDecl::clearLookupCache() {
|
||||||
|
|||||||
Reference in New Issue
Block a user