[Dependency Scanning] Optionally, resolve direct dependencies of a module using only the ModuleDependenciesCache.

This speeds up contexts where we need to resolve dependencies after the main scanning action is complete.
For example: libSwiftScan binary graph generation and cycle detection.

This is necessary because ordinarily, ModuleDependenciesCache must be queried on a per-loader basis.
For example, we first search for Swift modules with the SerializedModuleLoaderBase, at which point we check the cache for previously-found Swift modules. If cache is not hit, we search the filesystem.
Then we search for Clang moduels with the ClangLoader, at which point we check the cache for previously-found Clang modules. If cache is not hit, we search the filesystem.

This change allows to eliminate a bunch of filesystem searching in step (1) when we know we have completed the scan and no longer need to be concerned with the correctness of the cache contents.
This commit is contained in:
Artem Chikin
2021-01-11 14:50:14 -08:00
parent 7e6536d983
commit 8ecdfcbfd5
3 changed files with 36 additions and 16 deletions

View File

@@ -1533,15 +1533,35 @@ void ASTContext::addModuleInterfaceChecker(
Optional<ModuleDependencies> ASTContext::getModuleDependencies(
StringRef moduleName, bool isUnderlyingClangModule,
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate) {
for (auto &loader : getImpl().ModuleLoaders) {
if (isUnderlyingClangModule &&
loader.get() != getImpl().TheClangModuleLoader)
continue;
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate,
bool cacheOnly) {
// Retrieve the dependencies for this module.
if (cacheOnly) {
// Check whether we've cached this result.
if (!isUnderlyingClangModule) {
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftTextual))
return found;
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftTextual))
return found;
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftPlaceholder))
return found;
}
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::Clang))
return found;
} else {
for (auto &loader : getImpl().ModuleLoaders) {
if (isUnderlyingClangModule &&
loader.get() != getImpl().TheClangModuleLoader)
continue;
if (auto dependencies = loader->getModuleDependencies(moduleName, cache,
delegate))
return dependencies;
if (auto dependencies = loader->getModuleDependencies(moduleName, cache,
delegate))
return dependencies;
}
}
return None;