mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Request-ify ValueDecl::findImport().
To prevent performance regressions from calling `findImport()` more frequently, request-ify the computation. NFC. Prerequisite of rdar://16154294
This commit is contained in:
@@ -2572,6 +2572,38 @@ SourceFile::setImports(ArrayRef<AttributedImport<ImportedModule>> imports) {
|
||||
Imports = getASTContext().AllocateCopy(imports);
|
||||
}
|
||||
|
||||
std::optional<AttributedImport<ImportedModule>>
|
||||
SourceFile::findImport(const ModuleDecl *module) const {
|
||||
return evaluateOrDefault(getASTContext().evaluator,
|
||||
ImportDeclRequest{this, module}, std::nullopt);
|
||||
}
|
||||
|
||||
std::optional<AttributedImport<ImportedModule>>
|
||||
ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf,
|
||||
const ModuleDecl *module) const {
|
||||
auto &ctx = sf->getASTContext();
|
||||
auto imports = sf->getImports();
|
||||
|
||||
// Look to see if the owning module was directly imported.
|
||||
for (const auto &import : imports) {
|
||||
if (import.module.importedModule == module)
|
||||
return import;
|
||||
}
|
||||
|
||||
// Now look for transitive imports.
|
||||
auto &importCache = ctx.getImportCache();
|
||||
for (const auto &import : imports) {
|
||||
auto &importSet = importCache.getImportSet(import.module.importedModule);
|
||||
for (const auto &transitive : importSet.getTransitiveImports()) {
|
||||
if (transitive.importedModule == module) {
|
||||
return import;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool SourceFile::hasImportUsedPreconcurrency(
|
||||
AttributedImport<ImportedModule> import) const {
|
||||
return PreconcurrencyImportsUsed.count(import) != 0;
|
||||
|
||||
Reference in New Issue
Block a user