@@ -971,10 +971,6 @@ using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencyInfo>;
971971using ModuleDependenciesKindMap =
972972 std::unordered_map<ModuleDependencyKind, ModuleNameToDependencyMap,
973973 ModuleDependencyKindHash>;
974- using ModuleDependenciesKindRefMap =
975- std::unordered_map<ModuleDependencyKind,
976- llvm::StringMap<const ModuleDependencyInfo *>,
977- ModuleDependencyKindHash>;
978974
979975// MARK: SwiftDependencyTracker
980976// / Track swift dependency
@@ -1005,23 +1001,8 @@ class SwiftDependencyTracker {
10051001
10061002// MARK: SwiftDependencyScanningService
10071003// / 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.
10121005class 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-
10251006 // / The CASOption created the Scanning Service if used.
10261007 std::optional<clang::CASOptions> CASOpts;
10271008
@@ -1046,27 +1027,9 @@ class SwiftDependencyScanningService {
10461027 clang::tooling::dependencies::DependencyScanningFilesystemSharedCache>
10471028 SharedFilesystemCache;
10481029
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-
10591030 // / Shared state mutual-exclusivity lock
10601031 mutable llvm::sys::SmartMutex<true > ScanningServiceGlobalLock;
10611032
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-
10701033public:
10711034 SwiftDependencyScanningService ();
10721035 SwiftDependencyScanningService (const SwiftDependencyScanningService &) =
@@ -1136,54 +1099,6 @@ class SwiftDependencyScanningService {
11361099 friend class ModuleDependenciesCache ;
11371100 friend class ModuleDependencyScanner ;
11381101 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- }
11871102};
11881103
11891104// MARK: ModuleDependenciesCache
@@ -1195,11 +1110,10 @@ class SwiftDependencyScanningService {
11951110class ModuleDependenciesCache {
11961111private:
11971112 SwiftDependencyScanningService &globalScanningService;
1198- // / References to data in the `globalScanningService` for module dependencies
1199- ModuleDependenciesKindRefMap ModuleDependenciesMap;
1113+ // / Discovered dependencies
1114+ ModuleDependenciesKindMap ModuleDependenciesMap;
12001115 // / 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;
12031117 // / Name of the module under scan
12041118 std::string mainScanModuleName;
12051119 // / The context hash of the current scanning invocation
@@ -1223,6 +1137,11 @@ class ModuleDependenciesCache {
12231137 ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
12241138
12251139public:
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+
12261145 // / Whether we have cached dependency information for the given module.
12271146 bool hasDependency (const ModuleDependencyID &moduleID) const ;
12281147 // / Whether we have cached dependency information for the given module.
@@ -1283,13 +1202,7 @@ class ModuleDependenciesCache {
12831202 // / \returns the cached result, or \c None if there is no cached entry.
12841203 std::optional<const ModuleDependencyInfo *>
12851204 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 ;
12931206
12941207 // / Look for Swift module dependencies for a module with the given name
12951208 // /
@@ -1340,6 +1253,10 @@ class ModuleDependenciesCache {
13401253 const ArrayRef<ModuleDependencyID> dependencyIDs);
13411254
13421255 StringRef getMainModuleName () const { return mainScanModuleName; }
1256+
1257+ private:
1258+ friend class ModuleDependenciesCacheDeserializer ;
1259+ friend class ModuleDependenciesCacheSerializer ;
13431260};
13441261} // namespace swift
13451262
0 commit comments