[Dependency Scanning] Have 'ModuleDependnecyScanner' hold a reference to a dependency cache, instead of passing it around

This commit is contained in:
Artem Chikin
2025-10-15 15:06:29 -07:00
parent 50cea0af11
commit 1584287b73
3 changed files with 123 additions and 122 deletions

View File

@@ -216,13 +216,14 @@ private:
class ModuleDependencyScanner {
public:
ModuleDependencyScanner(SwiftDependencyScanningService &ScanningService,
ModuleDependenciesCache &Cache,
const CompilerInvocation &ScanCompilerInvocation,
const SILOptions &SILOptions,
ASTContext &ScanASTContext,
DependencyTracker &DependencyTracker,
std::shared_ptr<llvm::cas::ObjectStore> CAS,
std::shared_ptr<llvm::cas::ActionCache> ActionCache,
DiagnosticEngine &diags, bool ParallelScan);
DiagnosticEngine &Diagnostics, bool ParallelScan);
/// Identify the scanner invocation's main module's dependencies
llvm::ErrorOr<ModuleDependencyInfo>
@@ -231,8 +232,7 @@ public:
/// Resolve module dependencies of the given module, computing a full
/// transitive closure dependency graph.
std::vector<ModuleDependencyID>
performDependencyScan(ModuleDependencyID rootModuleID,
ModuleDependenciesCache &cache);
performDependencyScan(ModuleDependencyID rootModuleID);
/// How many filesystem lookups were performed by the scanner
unsigned getNumLookups() { return NumLookups; }
@@ -275,47 +275,46 @@ private:
/// that have one
ModuleDependencyIDSetVector
resolveImportedModuleDependencies(
const ModuleDependencyID &rootModuleID, ModuleDependenciesCache &cache);
const ModuleDependencyID &rootModuleID);
void resolveSwiftModuleDependencies(
const ModuleDependencyID &rootModuleID, ModuleDependenciesCache &cache,
const ModuleDependencyID &rootModuleID,
ModuleDependencyIDSetVector &discoveredSwiftModules);
void resolveAllClangModuleDependencies(
ArrayRef<ModuleDependencyID> swiftModules, ModuleDependenciesCache &cache,
ArrayRef<ModuleDependencyID> swiftModules,
ModuleDependencyIDSetVector &discoveredClangModules);
void resolveHeaderDependencies(
ArrayRef<ModuleDependencyID> swiftModules, ModuleDependenciesCache &cache,
ArrayRef<ModuleDependencyID> swiftModules,
ModuleDependencyIDSetVector &discoveredHeaderDependencyClangModules);
void resolveSwiftOverlayDependencies(
ArrayRef<ModuleDependencyID> swiftModules, ModuleDependenciesCache &cache,
ArrayRef<ModuleDependencyID> swiftModules,
ModuleDependencyIDSetVector &discoveredDependencies);
/// Resolve all of a given module's imports to a Swift module, if one exists.
void resolveSwiftImportsForModule(
const ModuleDependencyID &moduleID, ModuleDependenciesCache &cache,
const ModuleDependencyID &moduleID,
ModuleDependencyIDSetVector &importedSwiftDependencies);
/// If a module has a bridging header or other header inputs, execute a
/// dependency scan on it and record the dependencies.
void resolveHeaderDependenciesForModule(
const ModuleDependencyID &moduleID, ModuleDependenciesCache &cache,
const ModuleDependencyID &moduleID,
ModuleDependencyIDSetVector &headerClangModuleDependencies);
/// Resolve all module dependencies comprised of Swift overlays
/// of this module's Clang module dependencies.
void resolveSwiftOverlayDependenciesForModule(
const ModuleDependencyID &moduleID, ModuleDependenciesCache &cache,
const ModuleDependencyID &moduleID,
ModuleDependencyIDSetVector &swiftOverlayDependencies);
/// Identify all cross-import overlay module dependencies of the
/// source module under scan and apply an action for each.
void resolveCrossImportOverlayDependencies(
StringRef mainModuleName, ModuleDependenciesCache &cache,
StringRef mainModuleName,
llvm::function_ref<void(ModuleDependencyID)> action);
/// Perform Bridging Header Chaining.
llvm::Error
performBridgingHeaderChaining(const ModuleDependencyID &rootModuleID,
ModuleDependenciesCache &cache,
ModuleDependencyIDSetVector &allModules);
/// Bridge Clang dependency scanner's dependency node
@@ -351,7 +350,6 @@ private:
void performParallelClangModuleLookup(
const ImportStatementInfoMap &unresolvedImportsMap,
const ImportStatementInfoMap &unresolvedOptionalImportsMap,
ModuleDependenciesCache &cache,
BatchClangModuleLookupResult &result);
/// Given a result of a batch Clang module dependency lookup,
@@ -371,7 +369,6 @@ private:
const ImportStatementInfoMap &unresolvedImportsMap,
const ImportStatementInfoMap &unresolvedOptionalImportsMap,
ArrayRef<ModuleDependencyID> swiftModuleDependents,
ModuleDependenciesCache &cache,
ModuleDependencyIDSetVector &allDiscoveredClangModules,
std::vector<std::pair<ModuleDependencyID, ScannerImportStatementInfo>>
&failedToResolveImports,
@@ -381,7 +378,6 @@ private:
/// Re-query some failed-to-resolve Clang imports from cache
/// in chance they were brought in as transitive dependencies.
void reQueryMissedModulesFromCache(
ModuleDependenciesCache &cache,
const std::vector<
std::pair<ModuleDependencyID, ScannerImportStatementInfo>>
&failedToResolveImports,
@@ -395,8 +391,7 @@ private:
/// the module, if one is found.
std::optional<std::pair<ModuleDependencyID, std::string>>
attemptToFindResolvingSerializedSearchPath(
const ScannerImportStatementInfo &moduleImport,
const ModuleDependenciesCache &cache);
const ScannerImportStatementInfo &moduleImport);
private:
const CompilerInvocation &ScanCompilerInvocation;
@@ -407,6 +402,9 @@ private:
std::string ModuleOutputPath;
/// The location of where the explicitly-built SDK modules will be output to
std::string SDKModuleOutputPath;
/// Reference to a module dependency cache
ModuleDependenciesCache &DependencyCache;
/// The available pool of workers for filesystem module search
unsigned NumThreads;