@@ -35,6 +35,7 @@ class ClangModuleDependenciesCacheImpl;
3535class SourceFile ;
3636class ASTContext ;
3737class Identifier ;
38+ class CompilerInstance ;
3839
3940// / Which kind of module dependencies we are looking for.
4041enum class ModuleDependenciesKind : int8_t {
@@ -501,34 +502,40 @@ class GlobalModuleDependenciesCache {
501502 std::vector<ModuleDependencyID> AllModules;
502503
503504 // / Dependencies for modules that have already been computed.
504- // / This maps a dependency kind to a map of a module's name to a Dependency object
505+ // / This maps a dependency kind to a map of a module's name to a Dependency
506+ // / object
505507 ModuleDependenciesKindMap ModuleDependenciesMap;
506508 };
507509
508- // / The 'persistent' Clang dependency scanner service
509- clang::tooling::dependencies::DependencyScanningService clangScanningService;
510+ // / The persistent Clang dependency scanner service
511+ clang::tooling::dependencies::DependencyScanningService ClangScanningService;
512+ // / The global file system cache.
513+ Optional<
514+ clang::tooling::dependencies::DependencyScanningFilesystemSharedCache>
515+ SharedFilesystemCache;
510516
511- // / All cached Swift source module dependencies, in the order in which they were encountered
517+ // / All cached Swift source module dependencies, in the order in which they
518+ // / were encountered
512519 std::vector<ModuleDependencyID> AllSourceModules;
513-
514- // / Dependencies for all Swift source-based modules discovered. Each one is the main
515- // / module of a prior invocation of the scanner.
520+ // / Dependencies for all Swift source-based modules discovered. Each one is
521+ // / the main module of a prior invocation of the scanner.
516522 ModuleNameToDependencyMap SwiftSourceModuleDependenciesMap;
517523
518- // / A map from a String representing the target triple of a scanner invocation to the corresponding
519- // / cached dependencies discovered so far when using this triple.
520- llvm::StringMap<std::unique_ptr<ContextSpecificGlobalCacheState>> ContextSpecificCacheMap;
524+ // / A map from a String representing the target triple of a scanner invocation
525+ // / to the corresponding cached dependencies discovered so far when using this
526+ // / triple.
527+ llvm::StringMap<std::unique_ptr<ContextSpecificGlobalCacheState>>
528+ ContextSpecificCacheMap;
521529
522530 // / The current context hash configuration
523531 Optional<std::string> CurrentContextHash;
524-
525- // / The context hashes used by scanners using this cache, in the order in which they were used
532+ // / The context hashes used by scanners using this cache, in the order in
533+ // / which they were used
526534 std::vector<std::string> AllContextHashes;
527535
528536 // / Retrieve the dependencies map that corresponds to the given dependency
529537 // / kind.
530- ModuleNameToDependencyMap &
531- getDependenciesMap (ModuleDependenciesKind kind);
538+ ModuleNameToDependencyMap &getDependenciesMap (ModuleDependenciesKind kind);
532539 const ModuleNameToDependencyMap &
533540 getDependenciesMap (ModuleDependenciesKind kind) const ;
534541
@@ -539,6 +546,16 @@ class GlobalModuleDependenciesCache {
539546 operator =(const GlobalModuleDependenciesCache &) = delete ;
540547 virtual ~GlobalModuleDependenciesCache () {}
541548
549+ // / Query the service's filesystem cache
550+ clang::tooling::dependencies::DependencyScanningFilesystemSharedCache &
551+ getSharedFilesystemCache () {
552+ assert (SharedFilesystemCache && " Expected a shared cache" );
553+ return *SharedFilesystemCache;
554+ }
555+
556+ // / Wrap the filesystem on the specified `CompilerInstance` with a
557+ // / caching `DependencyScanningWorkerFilesystem`
558+ void overlaySharedFilesystemCacheForCompilation (CompilerInstance &Instance);
542559private:
543560 // / Enforce clients not being allowed to query this cache directly, it must be
544561 // / wrapped in an instance of `ModuleDependenciesCache`.
@@ -552,19 +569,21 @@ class GlobalModuleDependenciesCache {
552569
553570 // / Return context hashes of all scanner invocations that have used
554571 // / this cache instance.
555- const std::vector<std::string>& getAllContextHashes () const {
572+ const std::vector<std::string> & getAllContextHashes () const {
556573 return AllContextHashes;
557574 }
558575
559576 // / Whether we have cached dependency information for the given module.
560577 bool hasDependencies (StringRef moduleName,
561578 Optional<ModuleDependenciesKind> kind) const ;
562579
563- // / Return a pointer to the context-specific cache state of the current scanning action.
564- ContextSpecificGlobalCacheState* getCurrentCache () const ;
580+ // / Return a pointer to the context-specific cache state of the current
581+ // / scanning action.
582+ ContextSpecificGlobalCacheState *getCurrentCache () const ;
565583
566584 // / Return a pointer to the cache state of the specified context hash.
567- ContextSpecificGlobalCacheState* getCacheForScanningContextHash (StringRef scanningContextHash) const ;
585+ ContextSpecificGlobalCacheState *
586+ getCacheForScanningContextHash (StringRef scanningContextHash) const ;
568587
569588 // / Look for source-based module dependency details
570589 Optional<ModuleDependencies>
@@ -585,10 +604,13 @@ class GlobalModuleDependenciesCache {
585604 const ModuleDependencies *updateDependencies (ModuleDependencyID moduleID,
586605 ModuleDependencies dependencies);
587606
588- // / Reference the list of all module dependencies that are not source-based modules
589- // / (i.e. interface dependencies, binary dependencies, clang dependencies).
590- const std::vector<ModuleDependencyID> &getAllNonSourceModules (StringRef scanningContextHash) const {
591- auto contextSpecificCache = getCacheForScanningContextHash (scanningContextHash);
607+ // / Reference the list of all module dependencies that are not source-based
608+ // / modules (i.e. interface dependencies, binary dependencies, clang
609+ // / dependencies).
610+ const std::vector<ModuleDependencyID> &
611+ getAllNonSourceModules (StringRef scanningContextHash) const {
612+ auto contextSpecificCache =
613+ getCacheForScanningContextHash (scanningContextHash);
592614 return contextSpecificCache->AllModules ;
593615 }
594616
0 commit comments