mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #75210 from slavapestov/optimize-is-weak-linked
AST: Optimize ModuleDecl::isImportedAsWeakLinked()
This commit is contained in:
@@ -3121,35 +3121,6 @@ bool SourceFile::isImportedAsSPI(const ValueDecl *targetDecl) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SourceFile::importsModuleAsWeakLinked(const ModuleDecl *module) const {
|
||||
for (auto &import : *Imports) {
|
||||
if (!import.options.contains(ImportFlags::WeakLinked))
|
||||
continue;
|
||||
|
||||
const ModuleDecl *importedModule = import.module.importedModule;
|
||||
if (module == importedModule)
|
||||
return true;
|
||||
|
||||
// Also check whether the target module is actually the underlyingClang
|
||||
// module for this @_weakLinked import.
|
||||
const ModuleDecl *clangModule =
|
||||
importedModule->getUnderlyingModuleIfOverlay();
|
||||
if (module == clangModule)
|
||||
return true;
|
||||
|
||||
// Traverse the exported modules of this weakly-linked module to ensure
|
||||
// that we weak-link declarations from its exported peers.
|
||||
SmallVector<ImportedModule, 8> reexportedModules;
|
||||
importedModule->getImportedModules(reexportedModules,
|
||||
ModuleDecl::ImportFilterKind::Exported);
|
||||
for (const ImportedModule &reexportedModule : reexportedModules) {
|
||||
if (module == reexportedModule.importedModule)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModuleDecl::isImportedAsSPI(const SpecializeAttr *attr,
|
||||
const ValueDecl *targetDecl) const {
|
||||
auto declSPIGroups = attr->getSPIGroups();
|
||||
@@ -3181,11 +3152,7 @@ bool ModuleDecl::isImportedAsSPI(Identifier spiGroup,
|
||||
}
|
||||
|
||||
bool ModuleDecl::isImportedAsWeakLinked(const ModuleDecl *module) const {
|
||||
for (auto file : getFiles()) {
|
||||
if (file->importsModuleAsWeakLinked(module))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getASTContext().getImportCache().isWeakImportedBy(module, this);
|
||||
}
|
||||
|
||||
bool Decl::isSPI() const {
|
||||
|
||||
Reference in New Issue
Block a user