@@ -76,12 +76,6 @@ struct ModuleDependenciesKindHash {
7676 }
7777};
7878
79- // / Details of a given module used for dependency scanner cache queries.
80- struct ModuleLookupSpecifics {
81- Optional<ModuleDependenciesKind> kind;
82- llvm::StringSet<> currentSearchPaths;
83- };
84-
8579// / Base class for the variant storage of ModuleDependencies.
8680// /
8781// / This class is mostly an implementation detail for \c ModuleDependencies.
@@ -331,6 +325,7 @@ class ModuleDependencies {
331325 : storage(std::move(storage)) { }
332326
333327public:
328+ ModuleDependencies () = default ;
334329 ModuleDependencies (const ModuleDependencies &other)
335330 : storage(other.storage->clone ()) { }
336331 ModuleDependencies (ModuleDependencies &&other) = default;
@@ -481,9 +476,10 @@ class ModuleDependencies {
481476
482477using ModuleDependencyID = std::pair<std::string, ModuleDependenciesKind>;
483478using ModuleDependenciesVector = llvm::SmallVector<ModuleDependencies, 1 >;
479+ using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencies>;
484480using ModuleDependenciesKindMap =
485481 std::unordered_map<ModuleDependenciesKind,
486- llvm::StringMap<ModuleDependenciesVector> ,
482+ ModuleNameToDependencyMap ,
487483 ModuleDependenciesKindHash>;
488484using ModuleDependenciesKindRefMap =
489485 std::unordered_map<ModuleDependenciesKind,
@@ -497,20 +493,15 @@ using ModuleDependenciesKindRefMap =
497493// / `DependencyScanningTool`). It is not to be queried directly, but is rather
498494// / meant to be wrapped in an instance of `ModuleDependenciesCache`, responsible
499495// / for recording new dependencies and answering cache queries in a given scan.
500- // / Queries to this cache must be disambiguated with a set of search paths to
501- // / ensure that the returned cached dependency was one that can be found in the
502- // / current scanning action's filesystem view.
503496class GlobalModuleDependenciesCache {
504- // / Global cache contents specific to a target-triple specified on a scanner invocation
505- struct TargetSpecificGlobalCacheState {
497+ // / Global cache contents specific to a specific scanner invocation context
498+ struct ContextSpecificGlobalCacheState {
506499 // / All cached module dependencies, in the order in which they were
507500 // / encountered.
508501 std::vector<ModuleDependencyID> AllModules;
509502
510503 // / Dependencies for modules that have already been computed.
511- // / This maps a dependency kind to a map of a module's name to a vector of Dependency objects,
512- // / which correspond to instances of the same module that may have been found
513- // / in different sets of search paths.
504+ // / This maps a dependency kind to a map of a module's name to a Dependency object
514505 ModuleDependenciesKindMap ModuleDependenciesMap;
515506 };
516507
@@ -522,23 +513,23 @@ class GlobalModuleDependenciesCache {
522513
523514 // / Dependencies for all Swift source-based modules discovered. Each one is the main
524515 // / module of a prior invocation of the scanner.
525- llvm::StringMap<ModuleDependencies> SwiftSourceModuleDependenciesMap;
516+ ModuleNameToDependencyMap SwiftSourceModuleDependenciesMap;
526517
527518 // / A map from a String representing the target triple of a scanner invocation to the corresponding
528519 // / cached dependencies discovered so far when using this triple.
529- llvm::StringMap<std::unique_ptr<TargetSpecificGlobalCacheState >> TargetSpecificCacheMap ;
520+ llvm::StringMap<std::unique_ptr<ContextSpecificGlobalCacheState >> ContextSpecificCacheMap ;
530521
531- // / The current target triple cache configuration
532- Optional<std::string> CurrentTriple ;
522+ // / The current context hash configuration
523+ Optional<std::string> CurrentContextHash ;
533524
534- // / The triples used by scanners using this cache, in the order in which they were used
535- std::vector<std::string> AllTriples ;
525+ // / The context hashes used by scanners using this cache, in the order in which they were used
526+ std::vector<std::string> AllContextHashes ;
536527
537528 // / Retrieve the dependencies map that corresponds to the given dependency
538529 // / kind.
539- llvm::StringMap<ModuleDependenciesVector> &
530+ ModuleNameToDependencyMap &
540531 getDependenciesMap (ModuleDependenciesKind kind);
541- const llvm::StringMap<ModuleDependenciesVector> &
532+ const ModuleNameToDependencyMap &
542533 getDependenciesMap (ModuleDependenciesKind kind) const ;
543534
544535public:
@@ -548,47 +539,43 @@ class GlobalModuleDependenciesCache {
548539 operator =(const GlobalModuleDependenciesCache &) = delete ;
549540 virtual ~GlobalModuleDependenciesCache () {}
550541
551- void configureForTriple (std::string triple);
552-
553- const std::vector<std::string>& getAllTriples () const {
554- return AllTriples;
555- }
556-
557542private:
558543 // / Enforce clients not being allowed to query this cache directly, it must be
559544 // / wrapped in an instance of `ModuleDependenciesCache`.
560545 friend class ModuleDependenciesCache ;
546+ friend class ModuleDependenciesCacheDeserializer ;
547+ friend class ModuleDependenciesCacheSerializer ;
548+
549+ // / Configure the current state of the cache to respond to queries
550+ // / for the specified scanning context hash.
551+ void configureForContextHash (std::string scanningContextHash);
552+
553+ // / Return context hashes of all scanner invocations that have used
554+ // / this cache instance.
555+ const std::vector<std::string>& getAllContextHashes () const {
556+ return AllContextHashes;
557+ }
561558
562559 // / Whether we have cached dependency information for the given module.
563560 bool hasDependencies (StringRef moduleName,
564- ModuleLookupSpecifics details ) const ;
561+ Optional<ModuleDependenciesKind> kind ) const ;
565562
566- // / Look for module dependencies for a module with the given name given
567- // / current search paths.
568- // /
569- // / \returns the cached result, or \c None if there is no cached entry.
570- Optional<ModuleDependencies>
571- findDependencies (StringRef moduleName, ModuleLookupSpecifics details) const ;
563+ // / Return a pointer to the context-specific cache state of the current scanning action.
564+ ContextSpecificGlobalCacheState* getCurrentCache () const ;
572565
573- // / Return a pointer to the target-specific cache state of the current triple configuration .
574- TargetSpecificGlobalCacheState* getCurrentCache ( ) const ;
566+ // / Return a pointer to the cache state of the specified context hash .
567+ ContextSpecificGlobalCacheState* getCacheForScanningContextHash (StringRef scanningContextHash ) const ;
575568
576- // / Return a pointer to the target-specific cache state of the specified triple configuration.
577- TargetSpecificGlobalCacheState* getCacheForTriple (StringRef triple) const ;
569+ // / Look for source-based module dependency details
570+ Optional<ModuleDependencies>
571+ findSourceModuleDependency (StringRef moduleName) const ;
578572
579- public:
580- // / Look for module dependencies for a module with the given name.
581- // / This method has a deliberately-obtuse name to indicate that it is not to
582- // / be used for general queries.
573+ // / Look for module dependencies for a module with the given name
583574 // /
584575 // / \returns the cached result, or \c None if there is no cached entry.
585- Optional<ModuleDependenciesVector>
586- findAllDependenciesIrrespectiveOfSearchPaths (
587- StringRef moduleName, Optional<ModuleDependenciesKind> kind) const ;
588-
589- // / Look for source-based module dependency details
590576 Optional<ModuleDependencies>
591- findSourceModuleDependency (StringRef moduleName) const ;
577+ findDependencies (StringRef moduleName,
578+ Optional<ModuleDependenciesKind> kind) const ;
592579
593580 // / Record dependencies for the given module.
594581 const ModuleDependencies *recordDependencies (StringRef moduleName,
@@ -600,9 +587,9 @@ class GlobalModuleDependenciesCache {
600587
601588 // / Reference the list of all module dependencies that are not source-based modules
602589 // / (i.e. interface dependencies, binary dependencies, clang dependencies).
603- const std::vector<ModuleDependencyID> &getAllNonSourceModules (StringRef triple ) const {
604- auto targetSpecificCache = getCacheForTriple (triple );
605- return targetSpecificCache ->AllModules ;
590+ const std::vector<ModuleDependencyID> &getAllNonSourceModules (StringRef scanningContextHash ) const {
591+ auto contextSpecificCache = getCacheForScanningContextHash (scanningContextHash );
592+ return contextSpecificCache ->AllModules ;
606593 }
607594
608595 // / Return the list of all source-based modules discovered by this cache
@@ -616,8 +603,7 @@ class GlobalModuleDependenciesCache {
616603// / scanning action, and wraps an instance of a `GlobalModuleDependenciesCache`
617604// / which may carry cached scanning information from prior scanning actions.
618605// / This cache maintains a store of references to all dependencies found within
619- // / the current scanning action (with their values stored in the global Cache),
620- // / since these do not require clients to disambiguate them with search paths.
606+ // / the current scanning action (with their values stored in the global Cache).
621607class ModuleDependenciesCache {
622608private:
623609 GlobalModuleDependenciesCache &globalCache;
@@ -628,12 +614,14 @@ class ModuleDependenciesCache {
628614 ModuleDependenciesKindRefMap ModuleDependenciesMap;
629615
630616 // / Name of the module under scan
631- StringRef mainScanModuleName;
617+ std::string mainScanModuleName;
618+ // / The context hash of the current scanning invocation
619+ std::string scannerContextHash;
620+
632621 // / Set containing all of the Clang modules that have already been seen.
633622 llvm::StringSet<> alreadySeenClangModules;
634623 // / The Clang dependency scanner tool
635624 clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
636-
637625 // / Discovered Clang modules are only cached locally.
638626 llvm::StringMap<ModuleDependenciesVector> clangModuleDependencies;
639627
@@ -646,25 +634,26 @@ class ModuleDependenciesCache {
646634
647635 // / Local cache results lookup, only for modules which were discovered during
648636 // / the current scanner invocation.
649- bool hasDependencies (StringRef moduleName,
650- Optional<ModuleDependenciesKind> kind) const ;
637+ bool hasDependenciesLocalOnly (StringRef moduleName,
638+ Optional<ModuleDependenciesKind> kind) const ;
651639
652640 // / Local cache results lookup, only for modules which were discovered during
653641 // / the current scanner invocation.
654642 Optional<const ModuleDependencies *>
655- findDependencies (StringRef moduleName,
656- Optional<ModuleDependenciesKind> kind) const ;
643+ findDependenciesLocalOnly (StringRef moduleName,
644+ Optional<ModuleDependenciesKind> kind) const ;
657645
658646public:
659647 ModuleDependenciesCache (GlobalModuleDependenciesCache &globalCache,
660- StringRef mainScanModuleName);
648+ std::string mainScanModuleName,
649+ std::string scanningContextHash);
661650 ModuleDependenciesCache (const ModuleDependenciesCache &) = delete ;
662651 ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
663652
664653public:
665654 // / Whether we have cached dependency information for the given module.
666655 bool hasDependencies (StringRef moduleName,
667- ModuleLookupSpecifics details ) const ;
656+ Optional<ModuleDependenciesKind> kind ) const ;
668657
669658 // / Produce a reference to the Clang scanner tool associated with this cache
670659 clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
@@ -674,24 +663,12 @@ class ModuleDependenciesCache {
674663 return alreadySeenClangModules;
675664 }
676665
677- // / Look for module dependencies for a module with the given name given
678- // / current search paths.
666+ // / Look for module dependencies for a module with the given name
679667 // /
680668 // / \returns the cached result, or \c None if there is no cached entry.
681669 Optional<ModuleDependencies>
682- findDependencies (StringRef moduleName, ModuleLookupSpecifics details) const ;
683-
684- // / Look for module dependencies for a module with the given name.
685- // / This method has a deliberately-obtuse name to indicate that it is not to
686- // / be used for general queries.
687- // /
688- // / \returns the cached result, or \c None if there is no cached entry.
689- Optional<ModuleDependenciesVector>
690- findAllDependenciesIrrespectiveOfSearchPaths (
691- StringRef moduleName, Optional<ModuleDependenciesKind> kind) const {
692- return globalCache.findAllDependenciesIrrespectiveOfSearchPaths (moduleName,
693- kind);
694- }
670+ findDependencies (StringRef moduleName,
671+ Optional<ModuleDependenciesKind> kind) const ;
695672
696673 // / Record dependencies for the given module.
697674 void recordDependencies (StringRef moduleName,
0 commit comments