39
39
#include " llvm/Support/VirtualFileSystem.h"
40
40
#include < string>
41
41
#include < unordered_map>
42
+ #include < unordered_set>
42
43
#include < vector>
43
44
44
45
namespace swift {
@@ -86,17 +87,38 @@ enum class ModuleDependencyKind : int8_t {
86
87
LastKind = SwiftPlaceholder + 1
87
88
};
88
89
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
+ };
93
103
94
104
struct ModuleDependencyKindHash {
95
105
std::size_t operator ()(ModuleDependencyKind k) const {
96
106
using UnderlyingType = std::underlying_type<ModuleDependencyKind>::type;
97
107
return std::hash<UnderlyingType>{}(static_cast <UnderlyingType>(k));
98
108
}
99
109
};
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>>;
100
122
101
123
namespace dependencies {
102
124
std::string createEncodedModuleKindAndName (ModuleDependencyID id);
@@ -750,6 +772,7 @@ class ModuleDependencyInfo {
750
772
collectCrossImportOverlayNames (ASTContext &ctx, StringRef moduleName) const ;
751
773
};
752
774
775
+ using ModuleDependencyVector = llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1 >;
753
776
using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencyInfo>;
754
777
using ModuleDependenciesKindMap =
755
778
std::unordered_map<ModuleDependencyKind,
@@ -861,6 +884,7 @@ class SwiftDependencyScanningService {
861
884
}
862
885
863
886
bool usingCachingFS () const { return !UseClangIncludeTree && (bool )CacheFS; }
887
+ llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> getCachingFS () const { return CacheFS; }
864
888
865
889
llvm::cas::CachingOnDiskFileSystem &getSharedCachingFS () const {
866
890
assert (CacheFS && " Expect CachingOnDiskFileSystem" );
@@ -895,9 +919,10 @@ class SwiftDependencyScanningService {
895
919
// / Enforce clients not being allowed to query this cache directly, it must be
896
920
// / wrapped in an instance of `ModuleDependenciesCache`.
897
921
friend class ModuleDependenciesCache ;
922
+ friend class ModuleDependencyScanner ;
923
+ friend class ModuleDependencyScanningWorker ;
898
924
friend class ModuleDependenciesCacheDeserializer ;
899
925
friend class ModuleDependenciesCacheSerializer ;
900
- friend class DependencyScanningTool ;
901
926
902
927
// / Configure the current state of the cache to respond to queries
903
928
// / for the specified scanning context hash.
@@ -964,8 +989,6 @@ class ModuleDependenciesCache {
964
989
std::string scannerContextHash;
965
990
// / The location of where the built modules will be output to
966
991
std::string moduleOutputPath;
967
- // / The Clang dependency scanner tool
968
- clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
969
992
970
993
// / Retrieve the dependencies map that corresponds to the given dependency
971
994
// / kind.
@@ -987,23 +1010,29 @@ class ModuleDependenciesCache {
987
1010
bool hasDependency (StringRef moduleName,
988
1011
llvm::Optional<ModuleDependencyKind> kind) const ;
989
1012
990
- // / Produce a reference to the Clang scanner tool associated with this cache
991
- clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
992
- return clangScanningTool;
993
- }
994
1013
SwiftDependencyScanningService &getScanService () {
995
1014
return globalScanningService;
996
1015
}
997
- llvm::DenseSet<clang::tooling::dependencies::ModuleID>& getAlreadySeenClangModules () {
1016
+ const llvm::DenseSet<clang::tooling::dependencies::ModuleID>& getAlreadySeenClangModules () const {
998
1017
return alreadySeenClangModules;
999
1018
}
1000
1019
void addSeenClangModule (clang::tooling::dependencies::ModuleID newModule) {
1001
1020
alreadySeenClangModules.insert (newModule);
1002
1021
}
1003
- std::string getModuleOutputPath () {
1022
+ std::string getModuleOutputPath () const {
1004
1023
return moduleOutputPath;
1005
1024
}
1006
1025
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
+
1007
1036
// / Look for module dependencies for a module with the given name
1008
1037
// /
1009
1038
// / \returns the cached result, or \c None if there is no cached entry.
@@ -1015,6 +1044,9 @@ class ModuleDependenciesCache {
1015
1044
void recordDependency (StringRef moduleName,
1016
1045
ModuleDependencyInfo dependencies);
1017
1046
1047
+ // / Record dependencies for the given module collection.
1048
+ void recordDependencies (ModuleDependencyVector moduleDependencies);
1049
+
1018
1050
// / Update stored dependencies for the given module.
1019
1051
void updateDependency (ModuleDependencyID moduleID,
1020
1052
ModuleDependencyInfo dependencies);
@@ -1039,12 +1071,8 @@ class ModuleDependenciesCache {
1039
1071
namespace std {
1040
1072
template <>
1041
1073
struct hash <swift::ModuleDependencyID> {
1042
- using UnderlyingKindType = std::underlying_type<swift::ModuleDependencyKind>::type;
1043
1074
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 );
1048
1076
}
1049
1077
};
1050
1078
} // namespace std
0 commit comments