@@ -76,12 +76,6 @@ struct ModuleDependenciesKindHash {
76
76
}
77
77
};
78
78
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
-
85
79
// / Base class for the variant storage of ModuleDependencies.
86
80
// /
87
81
// / This class is mostly an implementation detail for \c ModuleDependencies.
@@ -331,6 +325,7 @@ class ModuleDependencies {
331
325
: storage(std::move(storage)) { }
332
326
333
327
public:
328
+ ModuleDependencies () = default ;
334
329
ModuleDependencies (const ModuleDependencies &other)
335
330
: storage(other.storage->clone ()) { }
336
331
ModuleDependencies (ModuleDependencies &&other) = default;
@@ -481,9 +476,10 @@ class ModuleDependencies {
481
476
482
477
using ModuleDependencyID = std::pair<std::string, ModuleDependenciesKind>;
483
478
using ModuleDependenciesVector = llvm::SmallVector<ModuleDependencies, 1 >;
479
+ using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencies>;
484
480
using ModuleDependenciesKindMap =
485
481
std::unordered_map<ModuleDependenciesKind,
486
- llvm::StringMap<ModuleDependenciesVector> ,
482
+ ModuleNameToDependencyMap ,
487
483
ModuleDependenciesKindHash>;
488
484
using ModuleDependenciesKindRefMap =
489
485
std::unordered_map<ModuleDependenciesKind,
@@ -497,20 +493,15 @@ using ModuleDependenciesKindRefMap =
497
493
// / `DependencyScanningTool`). It is not to be queried directly, but is rather
498
494
// / meant to be wrapped in an instance of `ModuleDependenciesCache`, responsible
499
495
// / 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.
503
496
class 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 {
506
499
// / All cached module dependencies, in the order in which they were
507
500
// / encountered.
508
501
std::vector<ModuleDependencyID> AllModules;
509
502
510
503
// / 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
514
505
ModuleDependenciesKindMap ModuleDependenciesMap;
515
506
};
516
507
@@ -522,23 +513,23 @@ class GlobalModuleDependenciesCache {
522
513
523
514
// / Dependencies for all Swift source-based modules discovered. Each one is the main
524
515
// / module of a prior invocation of the scanner.
525
- llvm::StringMap<ModuleDependencies> SwiftSourceModuleDependenciesMap;
516
+ ModuleNameToDependencyMap SwiftSourceModuleDependenciesMap;
526
517
527
518
// / A map from a String representing the target triple of a scanner invocation to the corresponding
528
519
// / 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 ;
530
521
531
- // / The current target triple cache configuration
532
- Optional<std::string> CurrentTriple ;
522
+ // / The current context hash configuration
523
+ Optional<std::string> CurrentContextHash ;
533
524
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 ;
536
527
537
528
// / Retrieve the dependencies map that corresponds to the given dependency
538
529
// / kind.
539
- llvm::StringMap<ModuleDependenciesVector> &
530
+ ModuleNameToDependencyMap &
540
531
getDependenciesMap (ModuleDependenciesKind kind);
541
- const llvm::StringMap<ModuleDependenciesVector> &
532
+ const ModuleNameToDependencyMap &
542
533
getDependenciesMap (ModuleDependenciesKind kind) const ;
543
534
544
535
public:
@@ -548,47 +539,43 @@ class GlobalModuleDependenciesCache {
548
539
operator =(const GlobalModuleDependenciesCache &) = delete ;
549
540
virtual ~GlobalModuleDependenciesCache () {}
550
541
551
- void configureForTriple (std::string triple);
552
-
553
- const std::vector<std::string>& getAllTriples () const {
554
- return AllTriples;
555
- }
556
-
557
542
private:
558
543
// / Enforce clients not being allowed to query this cache directly, it must be
559
544
// / wrapped in an instance of `ModuleDependenciesCache`.
560
545
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
+ }
561
558
562
559
// / Whether we have cached dependency information for the given module.
563
560
bool hasDependencies (StringRef moduleName,
564
- ModuleLookupSpecifics details ) const ;
561
+ Optional<ModuleDependenciesKind> kind ) const ;
565
562
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 ;
572
565
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 ;
575
568
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 ;
578
572
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
583
574
// /
584
575
// / \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
590
576
Optional<ModuleDependencies>
591
- findSourceModuleDependency (StringRef moduleName) const ;
577
+ findDependencies (StringRef moduleName,
578
+ Optional<ModuleDependenciesKind> kind) const ;
592
579
593
580
// / Record dependencies for the given module.
594
581
const ModuleDependencies *recordDependencies (StringRef moduleName,
@@ -600,9 +587,9 @@ class GlobalModuleDependenciesCache {
600
587
601
588
// / Reference the list of all module dependencies that are not source-based modules
602
589
// / (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 ;
606
593
}
607
594
608
595
// / Return the list of all source-based modules discovered by this cache
@@ -616,8 +603,7 @@ class GlobalModuleDependenciesCache {
616
603
// / scanning action, and wraps an instance of a `GlobalModuleDependenciesCache`
617
604
// / which may carry cached scanning information from prior scanning actions.
618
605
// / 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).
621
607
class ModuleDependenciesCache {
622
608
private:
623
609
GlobalModuleDependenciesCache &globalCache;
@@ -628,12 +614,14 @@ class ModuleDependenciesCache {
628
614
ModuleDependenciesKindRefMap ModuleDependenciesMap;
629
615
630
616
// / 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
+
632
621
// / Set containing all of the Clang modules that have already been seen.
633
622
llvm::StringSet<> alreadySeenClangModules;
634
623
// / The Clang dependency scanner tool
635
624
clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
636
-
637
625
// / Discovered Clang modules are only cached locally.
638
626
llvm::StringMap<ModuleDependenciesVector> clangModuleDependencies;
639
627
@@ -646,25 +634,26 @@ class ModuleDependenciesCache {
646
634
647
635
// / Local cache results lookup, only for modules which were discovered during
648
636
// / the current scanner invocation.
649
- bool hasDependencies (StringRef moduleName,
650
- Optional<ModuleDependenciesKind> kind) const ;
637
+ bool hasDependenciesLocalOnly (StringRef moduleName,
638
+ Optional<ModuleDependenciesKind> kind) const ;
651
639
652
640
// / Local cache results lookup, only for modules which were discovered during
653
641
// / the current scanner invocation.
654
642
Optional<const ModuleDependencies *>
655
- findDependencies (StringRef moduleName,
656
- Optional<ModuleDependenciesKind> kind) const ;
643
+ findDependenciesLocalOnly (StringRef moduleName,
644
+ Optional<ModuleDependenciesKind> kind) const ;
657
645
658
646
public:
659
647
ModuleDependenciesCache (GlobalModuleDependenciesCache &globalCache,
660
- StringRef mainScanModuleName);
648
+ std::string mainScanModuleName,
649
+ std::string scanningContextHash);
661
650
ModuleDependenciesCache (const ModuleDependenciesCache &) = delete ;
662
651
ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
663
652
664
653
public:
665
654
// / Whether we have cached dependency information for the given module.
666
655
bool hasDependencies (StringRef moduleName,
667
- ModuleLookupSpecifics details ) const ;
656
+ Optional<ModuleDependenciesKind> kind ) const ;
668
657
669
658
// / Produce a reference to the Clang scanner tool associated with this cache
670
659
clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
@@ -674,24 +663,12 @@ class ModuleDependenciesCache {
674
663
return alreadySeenClangModules;
675
664
}
676
665
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
679
667
// /
680
668
// / \returns the cached result, or \c None if there is no cached entry.
681
669
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 ;
695
672
696
673
// / Record dependencies for the given module.
697
674
void recordDependencies (StringRef moduleName,
0 commit comments