3939#include " llvm/Support/VirtualFileSystem.h"
4040#include < string>
4141#include < unordered_map>
42+ #include < unordered_set>
4243#include < vector>
4344
4445namespace swift {
@@ -86,17 +87,38 @@ enum class ModuleDependencyKind : int8_t {
8687 LastKind = SwiftPlaceholder + 1
8788};
8889
89- using ModuleDependencyID = std::pair<std::string, ModuleDependencyKind>;
90- using ModuleDependencyIDSetVector =
91- llvm::SetVector<ModuleDependencyID, std::vector<ModuleDependencyID>,
92- std::set<ModuleDependencyID>>;
90+ // / This is used to identify a specific module.
91+ struct ModuleDependencyID {
92+ std::string ModuleName;
93+ ModuleDependencyKind Kind;
94+ bool operator ==(const ModuleDependencyID &Other) const {
95+ return std::tie (ModuleName, Kind) ==
96+ std::tie (Other.ModuleName , Other.Kind );
97+ }
98+ bool operator <(const ModuleDependencyID& Other) const {
99+ return std::tie (ModuleName, Kind) <
100+ std::tie (Other.ModuleName , Other.Kind );
101+ }
102+ };
93103
94104struct ModuleDependencyKindHash {
95105 std::size_t operator ()(ModuleDependencyKind k) const {
96106 using UnderlyingType = std::underlying_type<ModuleDependencyKind>::type;
97107 return std::hash<UnderlyingType>{}(static_cast <UnderlyingType>(k));
98108 }
99109};
110+ struct ModuleDependencyIDHash {
111+ std::size_t operator ()(ModuleDependencyID id) const {
112+ return llvm::hash_combine (id.ModuleName , id.Kind );
113+ }
114+ };
115+
116+ using ModuleDependencyIDSet =
117+ std::unordered_set<ModuleDependencyID,
118+ ModuleDependencyIDHash>;
119+ using ModuleDependencyIDSetVector =
120+ llvm::SetVector<ModuleDependencyID, std::vector<ModuleDependencyID>,
121+ std::set<ModuleDependencyID>>;
100122
101123namespace dependencies {
102124 std::string createEncodedModuleKindAndName (ModuleDependencyID id);
@@ -750,6 +772,7 @@ class ModuleDependencyInfo {
750772 collectCrossImportOverlayNames (ASTContext &ctx, StringRef moduleName) const ;
751773};
752774
775+ using ModuleDependencyVector = llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1 >;
753776using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencyInfo>;
754777using ModuleDependenciesKindMap =
755778 std::unordered_map<ModuleDependencyKind,
@@ -861,6 +884,7 @@ class SwiftDependencyScanningService {
861884 }
862885
863886 bool usingCachingFS () const { return !UseClangIncludeTree && (bool )CacheFS; }
887+ llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> getCachingFS () const { return CacheFS; }
864888
865889 llvm::cas::CachingOnDiskFileSystem &getSharedCachingFS () const {
866890 assert (CacheFS && " Expect CachingOnDiskFileSystem" );
@@ -895,9 +919,10 @@ class SwiftDependencyScanningService {
895919 // / Enforce clients not being allowed to query this cache directly, it must be
896920 // / wrapped in an instance of `ModuleDependenciesCache`.
897921 friend class ModuleDependenciesCache ;
922+ friend class ModuleDependencyScanner ;
923+ friend class ModuleDependencyScanningWorker ;
898924 friend class ModuleDependenciesCacheDeserializer ;
899925 friend class ModuleDependenciesCacheSerializer ;
900- friend class DependencyScanningTool ;
901926
902927 // / Configure the current state of the cache to respond to queries
903928 // / for the specified scanning context hash.
@@ -964,8 +989,6 @@ class ModuleDependenciesCache {
964989 std::string scannerContextHash;
965990 // / The location of where the built modules will be output to
966991 std::string moduleOutputPath;
967- // / The Clang dependency scanner tool
968- clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
969992
970993 // / Retrieve the dependencies map that corresponds to the given dependency
971994 // / kind.
@@ -987,23 +1010,29 @@ class ModuleDependenciesCache {
9871010 bool hasDependency (StringRef moduleName,
9881011 llvm::Optional<ModuleDependencyKind> kind) const ;
9891012
990- // / Produce a reference to the Clang scanner tool associated with this cache
991- clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
992- return clangScanningTool;
993- }
9941013 SwiftDependencyScanningService &getScanService () {
9951014 return globalScanningService;
9961015 }
997- llvm::DenseSet<clang::tooling::dependencies::ModuleID>& getAlreadySeenClangModules () {
1016+ const llvm::DenseSet<clang::tooling::dependencies::ModuleID>& getAlreadySeenClangModules () const {
9981017 return alreadySeenClangModules;
9991018 }
10001019 void addSeenClangModule (clang::tooling::dependencies::ModuleID newModule) {
10011020 alreadySeenClangModules.insert (newModule);
10021021 }
1003- std::string getModuleOutputPath () {
1022+ std::string getModuleOutputPath () const {
10041023 return moduleOutputPath;
10051024 }
10061025
1026+ // / Query all dependencies, direct and Swift overlay.
1027+ std::vector<ModuleDependencyID>
1028+ getAllDependencies (const ModuleDependencyID &moduleID) const ;
1029+
1030+ // / Look for module dependencies for a module with the given ID
1031+ // /
1032+ // / \returns the cached result, or \c None if there is no cached entry.
1033+ llvm::Optional<const ModuleDependencyInfo *>
1034+ findDependency (const ModuleDependencyID moduleID) const ;
1035+
10071036 // / Look for module dependencies for a module with the given name
10081037 // /
10091038 // / \returns the cached result, or \c None if there is no cached entry.
@@ -1015,6 +1044,9 @@ class ModuleDependenciesCache {
10151044 void recordDependency (StringRef moduleName,
10161045 ModuleDependencyInfo dependencies);
10171046
1047+ // / Record dependencies for the given module collection.
1048+ void recordDependencies (ModuleDependencyVector moduleDependencies);
1049+
10181050 // / Update stored dependencies for the given module.
10191051 void updateDependency (ModuleDependencyID moduleID,
10201052 ModuleDependencyInfo dependencies);
@@ -1039,12 +1071,8 @@ class ModuleDependenciesCache {
10391071namespace std {
10401072template <>
10411073struct hash <swift::ModuleDependencyID> {
1042- using UnderlyingKindType = std::underlying_type<swift::ModuleDependencyKind>::type;
10431074 std::size_t operator ()(const swift::ModuleDependencyID &id) const {
1044- auto underlyingKindValue = static_cast <UnderlyingKindType>(id.second );
1045-
1046- return (hash<string>()(id.first ) ^
1047- (hash<UnderlyingKindType>()(underlyingKindValue)));
1075+ return llvm::hash_combine (id.ModuleName , id.Kind );
10481076 }
10491077};
10501078} // namespace std
0 commit comments