@@ -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,9 +493,6 @@ 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
497
// / Global cache contents specific to a specific scanner invocation context
505
498
struct ContextSpecificGlobalCacheState {
@@ -508,9 +501,7 @@ class GlobalModuleDependenciesCache {
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,7 +513,7 @@ 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.
@@ -536,9 +527,9 @@ class GlobalModuleDependenciesCache {
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,8 +539,6 @@ class GlobalModuleDependenciesCache {
548
539
operator =(const GlobalModuleDependenciesCache &) = delete ;
549
540
virtual ~GlobalModuleDependenciesCache () {}
550
541
551
- void configureForContextHash (std::string scanningContextHash);
552
-
553
542
const std::vector<std::string>& getAllContextHashes () const {
554
543
return AllContextHashes;
555
544
}
@@ -558,38 +547,34 @@ class GlobalModuleDependenciesCache {
558
547
// / Enforce clients not being allowed to query this cache directly, it must be
559
548
// / wrapped in an instance of `ModuleDependenciesCache`.
560
549
friend class ModuleDependenciesCache ;
550
+ friend class ModuleDependenciesCacheDeserializer ;
551
+ friend class ModuleDependenciesCacheSerializer ;
552
+
553
+ // / Configure the current state of the cache to respond to queries
554
+ // / for the specified scanning context hash.
555
+ void configureForContextHash (std::string scanningContextHash);
561
556
562
557
// / Whether we have cached dependency information for the given module.
563
558
bool hasDependencies (StringRef moduleName,
564
- ModuleLookupSpecifics details) const ;
565
-
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 ;
559
+ Optional<ModuleDependenciesKind> kind) const ;
572
560
573
561
// / Return a pointer to the context-specific cache state of the current scanning action.
574
562
ContextSpecificGlobalCacheState* getCurrentCache () const ;
575
563
576
564
// / Return a pointer to the cache state of the specified context hash.
577
565
ContextSpecificGlobalCacheState* getCacheForScanningContextHash (StringRef scanningContextHash) const ;
578
566
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.
583
- // /
584
- // / \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
567
// / Look for source-based module dependency details
590
568
Optional<ModuleDependencies>
591
569
findSourceModuleDependency (StringRef moduleName) const ;
592
570
571
+ // / Look for module dependencies for a module with the given name
572
+ // /
573
+ // / \returns the cached result, or \c None if there is no cached entry.
574
+ Optional<ModuleDependencies>
575
+ findDependencies (StringRef moduleName,
576
+ Optional<ModuleDependenciesKind> kind) const ;
577
+
593
578
// / Record dependencies for the given module.
594
579
const ModuleDependencies *recordDependencies (StringRef moduleName,
595
580
ModuleDependencies dependencies);
@@ -616,8 +601,7 @@ class GlobalModuleDependenciesCache {
616
601
// / scanning action, and wraps an instance of a `GlobalModuleDependenciesCache`
617
602
// / which may carry cached scanning information from prior scanning actions.
618
603
// / 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.
604
+ // / the current scanning action (with their values stored in the global Cache).
621
605
class ModuleDependenciesCache {
622
606
private:
623
607
GlobalModuleDependenciesCache &globalCache;
@@ -629,11 +613,13 @@ class ModuleDependenciesCache {
629
613
630
614
// / Name of the module under scan
631
615
StringRef mainScanModuleName;
616
+ // / The context hash of the current scanning invocation
617
+ std::string scannerContextHash;
618
+
632
619
// / Set containing all of the Clang modules that have already been seen.
633
620
llvm::StringSet<> alreadySeenClangModules;
634
621
// / The Clang dependency scanner tool
635
622
clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
636
-
637
623
// / Discovered Clang modules are only cached locally.
638
624
llvm::StringMap<ModuleDependenciesVector> clangModuleDependencies;
639
625
@@ -646,25 +632,26 @@ class ModuleDependenciesCache {
646
632
647
633
// / Local cache results lookup, only for modules which were discovered during
648
634
// / the current scanner invocation.
649
- bool hasDependencies (StringRef moduleName,
650
- Optional<ModuleDependenciesKind> kind) const ;
635
+ bool hasDependenciesLocalOnly (StringRef moduleName,
636
+ Optional<ModuleDependenciesKind> kind) const ;
651
637
652
638
// / Local cache results lookup, only for modules which were discovered during
653
639
// / the current scanner invocation.
654
640
Optional<const ModuleDependencies *>
655
- findDependencies (StringRef moduleName,
656
- Optional<ModuleDependenciesKind> kind) const ;
641
+ findDependenciesLocalOnly (StringRef moduleName,
642
+ Optional<ModuleDependenciesKind> kind) const ;
657
643
658
644
public:
659
645
ModuleDependenciesCache (GlobalModuleDependenciesCache &globalCache,
660
- StringRef mainScanModuleName);
646
+ std::string mainScanModuleName,
647
+ std::string scanningContextHash);
661
648
ModuleDependenciesCache (const ModuleDependenciesCache &) = delete ;
662
649
ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
663
650
664
651
public:
665
652
// / Whether we have cached dependency information for the given module.
666
653
bool hasDependencies (StringRef moduleName,
667
- ModuleLookupSpecifics details ) const ;
654
+ Optional<ModuleDependenciesKind> kind ) const ;
668
655
669
656
// / Produce a reference to the Clang scanner tool associated with this cache
670
657
clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
@@ -674,24 +661,12 @@ class ModuleDependenciesCache {
674
661
return alreadySeenClangModules;
675
662
}
676
663
677
- // / Look for module dependencies for a module with the given name given
678
- // / current search paths.
664
+ // / Look for module dependencies for a module with the given name
679
665
// /
680
666
// / \returns the cached result, or \c None if there is no cached entry.
681
667
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
- }
668
+ findDependencies (StringRef moduleName,
669
+ Optional<ModuleDependenciesKind> kind) const ;
695
670
696
671
// / Record dependencies for the given module.
697
672
void recordDependencies (StringRef moduleName,
0 commit comments