@@ -971,10 +971,6 @@ using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencyInfo>;
971
971
using ModuleDependenciesKindMap =
972
972
std::unordered_map<ModuleDependencyKind, ModuleNameToDependencyMap,
973
973
ModuleDependencyKindHash>;
974
- using ModuleDependenciesKindRefMap =
975
- std::unordered_map<ModuleDependencyKind,
976
- llvm::StringMap<const ModuleDependencyInfo *>,
977
- ModuleDependencyKindHash>;
978
974
979
975
// MARK: SwiftDependencyTracker
980
976
// / Track swift dependency
@@ -1005,23 +1001,8 @@ class SwiftDependencyTracker {
1005
1001
1006
1002
// MARK: SwiftDependencyScanningService
1007
1003
// / A carrier of state shared among possibly multiple invocations of the
1008
- // / dependency scanner. Acts as a global cache of discovered module dependencies
1009
- // / and filesystem state. It is not to be queried directly, but is rather meant
1010
- // / to be wrapped in an instance of `ModuleDependenciesCache`, responsible for
1011
- // / recording new dependencies and answering cache queries in a given scan.
1004
+ // / dependency scanner.
1012
1005
class SwiftDependencyScanningService {
1013
- // / Global cache contents specific to a specific scanner invocation context
1014
- struct ContextSpecificGlobalCacheState {
1015
- // / All cached module dependencies, in the order in which they were
1016
- // / encountered.
1017
- std::vector<ModuleDependencyID> AllModules;
1018
-
1019
- // / Dependencies for modules that have already been computed.
1020
- // / This maps a dependency kind to a map of a module's name to a Dependency
1021
- // / object
1022
- ModuleDependenciesKindMap ModuleDependenciesMap;
1023
- };
1024
-
1025
1006
// / The CASOption created the Scanning Service if used.
1026
1007
std::optional<clang::CASOptions> CASOpts;
1027
1008
@@ -1046,27 +1027,9 @@ class SwiftDependencyScanningService {
1046
1027
clang::tooling::dependencies::DependencyScanningFilesystemSharedCache>
1047
1028
SharedFilesystemCache;
1048
1029
1049
- // / A map from a String representing the target triple of a scanner invocation
1050
- // / to the corresponding cached dependencies discovered so far when using this
1051
- // / triple.
1052
- llvm::StringMap<std::unique_ptr<ContextSpecificGlobalCacheState>>
1053
- ContextSpecificCacheMap;
1054
-
1055
- // / The context hashes used by scanners using this cache, in the order in
1056
- // / which they were used
1057
- std::vector<std::string> AllContextHashes;
1058
-
1059
1030
// / Shared state mutual-exclusivity lock
1060
1031
mutable llvm::sys::SmartMutex<true > ScanningServiceGlobalLock;
1061
1032
1062
- // / Retrieve the dependencies map that corresponds to the given dependency
1063
- // / kind.
1064
- ModuleNameToDependencyMap &getDependenciesMap (ModuleDependencyKind kind,
1065
- StringRef scanContextHash);
1066
- const ModuleNameToDependencyMap &
1067
- getDependenciesMap (ModuleDependencyKind kind,
1068
- StringRef scanContextHash) const ;
1069
-
1070
1033
public:
1071
1034
SwiftDependencyScanningService ();
1072
1035
SwiftDependencyScanningService (const SwiftDependencyScanningService &) =
@@ -1136,54 +1099,6 @@ class SwiftDependencyScanningService {
1136
1099
friend class ModuleDependenciesCache ;
1137
1100
friend class ModuleDependencyScanner ;
1138
1101
friend class ModuleDependencyScanningWorker ;
1139
- friend class ModuleDependenciesCacheDeserializer ;
1140
- friend class ModuleDependenciesCacheSerializer ;
1141
-
1142
- // / Configure the current state of the cache to respond to queries
1143
- // / for the specified scanning context hash.
1144
- void configureForContextHash (StringRef scanningContextHash);
1145
-
1146
- // / Return context hashes of all scanner invocations that have used
1147
- // / this cache instance.
1148
- const std::vector<std::string> &getAllContextHashes () const {
1149
- return AllContextHashes;
1150
- }
1151
-
1152
- // / Whether we have cached dependency information for the given module.
1153
- bool hasDependency (StringRef moduleName,
1154
- std::optional<ModuleDependencyKind> kind,
1155
- StringRef scanContextHash) const ;
1156
-
1157
- // / Return a pointer to the cache state of the specified context hash.
1158
- ContextSpecificGlobalCacheState *
1159
- getCacheForScanningContextHash (StringRef scanContextHash) const ;
1160
-
1161
- // / Look for module dependencies for a module with the given name
1162
- // /
1163
- // / \returns the cached result, or \c None if there is no cached entry.
1164
- std::optional<const ModuleDependencyInfo *>
1165
- findDependency (StringRef moduleName, std::optional<ModuleDependencyKind> kind,
1166
- StringRef scanContextHash) const ;
1167
-
1168
- // / Record dependencies for the given module.
1169
- const ModuleDependencyInfo *
1170
- recordDependency (StringRef moduleName, ModuleDependencyInfo dependencies,
1171
- StringRef scanContextHash);
1172
-
1173
- // / Update stored dependencies for the given module.
1174
- const ModuleDependencyInfo *
1175
- updateDependency (ModuleDependencyID moduleID,
1176
- ModuleDependencyInfo dependencies,
1177
- StringRef scanContextHash);
1178
-
1179
- // / Reference the list of all module dependency infos for a given scanning
1180
- // / context
1181
- const std::vector<ModuleDependencyID> &
1182
- getAllModules (StringRef scanningContextHash) const {
1183
- auto contextSpecificCache =
1184
- getCacheForScanningContextHash (scanningContextHash);
1185
- return contextSpecificCache->AllModules ;
1186
- }
1187
1102
};
1188
1103
1189
1104
// MARK: ModuleDependenciesCache
@@ -1195,11 +1110,10 @@ class SwiftDependencyScanningService {
1195
1110
class ModuleDependenciesCache {
1196
1111
private:
1197
1112
SwiftDependencyScanningService &globalScanningService;
1198
- // / References to data in the `globalScanningService` for module dependencies
1199
- ModuleDependenciesKindRefMap ModuleDependenciesMap;
1113
+ // / Discovered dependencies
1114
+ ModuleDependenciesKindMap ModuleDependenciesMap;
1200
1115
// / Set containing all of the Clang modules that have already been seen.
1201
- llvm::DenseSet<clang::tooling::dependencies::ModuleID>
1202
- alreadySeenClangModules;
1116
+ llvm::DenseSet<clang::tooling::dependencies::ModuleID> alreadySeenClangModules;
1203
1117
// / Name of the module under scan
1204
1118
std::string mainScanModuleName;
1205
1119
// / The context hash of the current scanning invocation
@@ -1223,6 +1137,11 @@ class ModuleDependenciesCache {
1223
1137
ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
1224
1138
1225
1139
public:
1140
+ // / Retrieve the dependencies map that corresponds to the given dependency
1141
+ // / kind.
1142
+ ModuleNameToDependencyMap &getDependenciesMap (ModuleDependencyKind kind);
1143
+ const ModuleNameToDependencyMap &getDependenciesMap (ModuleDependencyKind kind) const ;
1144
+
1226
1145
// / Whether we have cached dependency information for the given module.
1227
1146
bool hasDependency (const ModuleDependencyID &moduleID) const ;
1228
1147
// / Whether we have cached dependency information for the given module.
@@ -1283,13 +1202,7 @@ class ModuleDependenciesCache {
1283
1202
// / \returns the cached result, or \c None if there is no cached entry.
1284
1203
std::optional<const ModuleDependencyInfo *>
1285
1204
findDependency (StringRef moduleName,
1286
- std::optional<ModuleDependencyKind> kind) const ;
1287
-
1288
- // / Look for module dependencies for a module with the given name
1289
- // /
1290
- // / \returns the cached result, or \c None if there is no cached entry.
1291
- std::optional<const ModuleDependencyInfo *>
1292
- findDependency (StringRef moduleName) const ;
1205
+ std::optional<ModuleDependencyKind> kind = std::nullopt) const ;
1293
1206
1294
1207
// / Look for Swift module dependencies for a module with the given name
1295
1208
// /
@@ -1340,6 +1253,10 @@ class ModuleDependenciesCache {
1340
1253
const ArrayRef<ModuleDependencyID> dependencyIDs);
1341
1254
1342
1255
StringRef getMainModuleName () const { return mainScanModuleName; }
1256
+
1257
+ private:
1258
+ friend class ModuleDependenciesCacheDeserializer ;
1259
+ friend class ModuleDependenciesCacheSerializer ;
1343
1260
};
1344
1261
} // namespace swift
1345
1262
0 commit comments