diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-02-27 10:06:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-27 10:06:26 -0800 |
commit | d2e66625bcdc09953c007cf1e9f80d38a18719f3 (patch) | |
tree | 5f017aa4da737e21a5d500cd94f0e4a406da74dc /clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp | |
parent | f6bfa33cdb1482df0e2f23413fbe809afbc28830 (diff) | |
download | llvm-d2e66625bcdc09953c007cf1e9f80d38a18719f3.zip llvm-d2e66625bcdc09953c007cf1e9f80d38a18719f3.tar.gz llvm-d2e66625bcdc09953c007cf1e9f80d38a18719f3.tar.bz2 |
[clang][deps] Propagate the entire service (#128959)
Shared state between dependency scanning workers is managed by the
dependency scanning service.
Right now, the members are individually threaded through the worker,
action, and collector. This makes any change to the service and its
members a very laborious process. Moreover, this situation causes
frequent merge conflicts in our downstream repo where the service does
have some extra members that need to be passed around.
To ease the maintenance burden, this PR starts passing a reference to
the entire service.
Diffstat (limited to 'clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp')
-rw-r--r-- | clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 7da3ec7..36b75c1 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -295,7 +295,8 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs( // TODO: Verify this works fine when modulemap for module A is eagerly // loaded from A.pcm, and module map passed on the command line contains // definition of a submodule: "explicit module A.Private { ... }". - if (EagerLoadModules && DepModuleMapFiles.contains(*ModuleMapEntry)) + if (Service.shouldEagerLoadModules() && + DepModuleMapFiles.contains(*ModuleMapEntry)) continue; // Don't report module map file of the current module unless it also @@ -345,7 +346,7 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles( void ModuleDepCollector::addModuleMapFiles( CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const { - if (EagerLoadModules) + if (Service.shouldEagerLoadModules()) return; // Only pcm is needed for eager load. for (const ModuleID &MID : ClangModuleDeps) { @@ -360,7 +361,7 @@ void ModuleDepCollector::addModuleFiles( for (const ModuleID &MID : ClangModuleDeps) { std::string PCMPath = Controller.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile); - if (EagerLoadModules) + if (Service.shouldEagerLoadModules()) CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath)); else CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert( @@ -373,7 +374,7 @@ void ModuleDepCollector::addModuleFiles( for (const ModuleID &MID : ClangModuleDeps) { std::string PCMPath = Controller.lookupModuleOutput(MID, ModuleOutputKind::ModuleFile); - if (EagerLoadModules) + if (Service.shouldEagerLoadModules()) CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath)); else CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert( @@ -551,8 +552,8 @@ static std::string getModuleContextHash(const ModuleDeps &MD, void ModuleDepCollector::associateWithContextHash( const CowCompilerInvocation &CI, bool IgnoreCWD, ModuleDeps &Deps) { Deps.ID.ContextHash = - getModuleContextHash(Deps, CI, EagerLoadModules, IgnoreCWD, - ScanInstance.getVirtualFileSystem()); + getModuleContextHash(Deps, CI, Service.shouldEagerLoadModules(), + IgnoreCWD, ScanInstance.getVirtualFileSystem()); bool Inserted = ModuleDepsByID.insert({Deps.ID, &Deps}).second; (void)Inserted; assert(Inserted && "duplicate module mapping"); @@ -656,7 +657,7 @@ void ModuleDepCollectorPP::EndOfMainFile() { MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts); - if (MDC.IsStdModuleP1689Format) + if (MDC.Service.getFormat() == ScanningOutputFormat::P1689) MDC.Consumer.handleProvidedAndRequiredStdCXXModules( MDC.ProvidedStdCXXModule, MDC.RequiredStdCXXModules); @@ -753,21 +754,23 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) { CowCompilerInvocation CI = MDC.getInvocationAdjustedForModuleBuildWithoutOutputs( MD, [&](CowCompilerInvocation &BuildInvocation) { - if (any(MDC.OptimizeArgs & (ScanningOptimizations::HeaderSearch | - ScanningOptimizations::VFS))) + if (any(MDC.Service.getOptimizeArgs() & + (ScanningOptimizations::HeaderSearch | + ScanningOptimizations::VFS))) optimizeHeaderSearchOpts(BuildInvocation.getMutHeaderSearchOpts(), *MDC.ScanInstance.getASTReader(), *MF, MDC.PrebuiltModuleVFSMap, - MDC.OptimizeArgs); + MDC.Service.getOptimizeArgs()); - if (any(MDC.OptimizeArgs & ScanningOptimizations::SystemWarnings)) + if (any(MDC.Service.getOptimizeArgs() & + ScanningOptimizations::SystemWarnings)) optimizeDiagnosticOpts( BuildInvocation.getMutDiagnosticOpts(), BuildInvocation.getFrontendOpts().IsSystemModule); - IgnoreCWD = - any(MDC.OptimizeArgs & ScanningOptimizations::IgnoreCWD) && - isSafeToIgnoreCWD(BuildInvocation); + IgnoreCWD = any(MDC.Service.getOptimizeArgs() & + ScanningOptimizations::IgnoreCWD) && + isSafeToIgnoreCWD(BuildInvocation); if (IgnoreCWD) { llvm::ErrorOr<std::string> CWD = MDC.ScanInstance.getVirtualFileSystem() @@ -870,19 +873,17 @@ void ModuleDepCollectorPP::addAffectingClangModule( } ModuleDepCollector::ModuleDepCollector( + DependencyScanningService &Service, std::unique_ptr<DependencyOutputOptions> Opts, CompilerInstance &ScanInstance, DependencyConsumer &C, DependencyActionController &Controller, CompilerInvocation OriginalCI, - PrebuiltModuleVFSMapT PrebuiltModuleVFSMap, - ScanningOptimizations OptimizeArgs, bool EagerLoadModules, - bool IsStdModuleP1689Format) - : ScanInstance(ScanInstance), Consumer(C), Controller(Controller), + PrebuiltModuleVFSMapT PrebuiltModuleVFSMap) + : Service(Service), ScanInstance(ScanInstance), Consumer(C), + Controller(Controller), PrebuiltModuleVFSMap(std::move(PrebuiltModuleVFSMap)), Opts(std::move(Opts)), CommonInvocation( - makeCommonInvocationForModuleBuild(std::move(OriginalCI))), - OptimizeArgs(OptimizeArgs), EagerLoadModules(EagerLoadModules), - IsStdModuleP1689Format(IsStdModuleP1689Format) {} + makeCommonInvocationForModuleBuild(std::move(OriginalCI))) {} void ModuleDepCollector::attachToPreprocessor(Preprocessor &PP) { PP.addPPCallbacks(std::make_unique<ModuleDepCollectorPP>(*this)); @@ -914,7 +915,7 @@ static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path, } void ModuleDepCollector::addFileDep(StringRef Path) { - if (IsStdModuleP1689Format) { + if (Service.getFormat() == ScanningOutputFormat::P1689) { // Within P1689 format, we don't want all the paths to be absolute path // since it may violate the traditional make style dependencies info. FileDeps.emplace_back(Path); |