mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Dependency Scanner] Refactor the global scanning service to no longer maintain scanner cache state
Instead, each scan's 'ModuleDependenciesCache' will hold all of the data corresponding to discovered module dependencies. The initial design presumed the possibility of sharing a global scanning cache amongs different scanner invocations, possibly even different concurrent scanner invocations. This change also deprecates two libSwiftScan entry-points: 'swiftscan_scanner_cache_load' and 'swiftscan_scanner_cache_serialize'. They never ended up getting used, and since this code has been largely stale, we are confident they have not otherwise had users, and they do not fit with this design. A follow-up change will re-introduce moduele dependency cache serialization on a per-query basis and bring the binary format up-to-date.
This commit is contained in:
@@ -971,10 +971,6 @@ using ModuleNameToDependencyMap = llvm::StringMap<ModuleDependencyInfo>;
|
||||
using ModuleDependenciesKindMap =
|
||||
std::unordered_map<ModuleDependencyKind, ModuleNameToDependencyMap,
|
||||
ModuleDependencyKindHash>;
|
||||
using ModuleDependenciesKindRefMap =
|
||||
std::unordered_map<ModuleDependencyKind,
|
||||
llvm::StringMap<const ModuleDependencyInfo *>,
|
||||
ModuleDependencyKindHash>;
|
||||
|
||||
// MARK: SwiftDependencyTracker
|
||||
/// Track swift dependency
|
||||
@@ -1005,23 +1001,8 @@ private:
|
||||
|
||||
// MARK: SwiftDependencyScanningService
|
||||
/// A carrier of state shared among possibly multiple invocations of the
|
||||
/// dependency scanner. Acts as a global cache of discovered module dependencies
|
||||
/// and filesystem state. It is not to be queried directly, but is rather meant
|
||||
/// to be wrapped in an instance of `ModuleDependenciesCache`, responsible for
|
||||
/// recording new dependencies and answering cache queries in a given scan.
|
||||
/// dependency scanner.
|
||||
class SwiftDependencyScanningService {
|
||||
/// Global cache contents specific to a specific scanner invocation context
|
||||
struct ContextSpecificGlobalCacheState {
|
||||
/// All cached module dependencies, in the order in which they were
|
||||
/// encountered.
|
||||
std::vector<ModuleDependencyID> AllModules;
|
||||
|
||||
/// Dependencies for modules that have already been computed.
|
||||
/// This maps a dependency kind to a map of a module's name to a Dependency
|
||||
/// object
|
||||
ModuleDependenciesKindMap ModuleDependenciesMap;
|
||||
};
|
||||
|
||||
/// The CASOption created the Scanning Service if used.
|
||||
std::optional<clang::CASOptions> CASOpts;
|
||||
|
||||
@@ -1046,27 +1027,9 @@ class SwiftDependencyScanningService {
|
||||
clang::tooling::dependencies::DependencyScanningFilesystemSharedCache>
|
||||
SharedFilesystemCache;
|
||||
|
||||
/// A map from a String representing the target triple of a scanner invocation
|
||||
/// to the corresponding cached dependencies discovered so far when using this
|
||||
/// triple.
|
||||
llvm::StringMap<std::unique_ptr<ContextSpecificGlobalCacheState>>
|
||||
ContextSpecificCacheMap;
|
||||
|
||||
/// The context hashes used by scanners using this cache, in the order in
|
||||
/// which they were used
|
||||
std::vector<std::string> AllContextHashes;
|
||||
|
||||
/// Shared state mutual-exclusivity lock
|
||||
mutable llvm::sys::SmartMutex<true> ScanningServiceGlobalLock;
|
||||
|
||||
/// Retrieve the dependencies map that corresponds to the given dependency
|
||||
/// kind.
|
||||
ModuleNameToDependencyMap &getDependenciesMap(ModuleDependencyKind kind,
|
||||
StringRef scanContextHash);
|
||||
const ModuleNameToDependencyMap &
|
||||
getDependenciesMap(ModuleDependencyKind kind,
|
||||
StringRef scanContextHash) const;
|
||||
|
||||
public:
|
||||
SwiftDependencyScanningService();
|
||||
SwiftDependencyScanningService(const SwiftDependencyScanningService &) =
|
||||
@@ -1136,54 +1099,6 @@ private:
|
||||
friend class ModuleDependenciesCache;
|
||||
friend class ModuleDependencyScanner;
|
||||
friend class ModuleDependencyScanningWorker;
|
||||
friend class ModuleDependenciesCacheDeserializer;
|
||||
friend class ModuleDependenciesCacheSerializer;
|
||||
|
||||
/// Configure the current state of the cache to respond to queries
|
||||
/// for the specified scanning context hash.
|
||||
void configureForContextHash(StringRef scanningContextHash);
|
||||
|
||||
/// Return context hashes of all scanner invocations that have used
|
||||
/// this cache instance.
|
||||
const std::vector<std::string> &getAllContextHashes() const {
|
||||
return AllContextHashes;
|
||||
}
|
||||
|
||||
/// Whether we have cached dependency information for the given module.
|
||||
bool hasDependency(StringRef moduleName,
|
||||
std::optional<ModuleDependencyKind> kind,
|
||||
StringRef scanContextHash) const;
|
||||
|
||||
/// Return a pointer to the cache state of the specified context hash.
|
||||
ContextSpecificGlobalCacheState *
|
||||
getCacheForScanningContextHash(StringRef scanContextHash) const;
|
||||
|
||||
/// Look for module dependencies for a module with the given name
|
||||
///
|
||||
/// \returns the cached result, or \c None if there is no cached entry.
|
||||
std::optional<const ModuleDependencyInfo *>
|
||||
findDependency(StringRef moduleName, std::optional<ModuleDependencyKind> kind,
|
||||
StringRef scanContextHash) const;
|
||||
|
||||
/// Record dependencies for the given module.
|
||||
const ModuleDependencyInfo *
|
||||
recordDependency(StringRef moduleName, ModuleDependencyInfo dependencies,
|
||||
StringRef scanContextHash);
|
||||
|
||||
/// Update stored dependencies for the given module.
|
||||
const ModuleDependencyInfo *
|
||||
updateDependency(ModuleDependencyID moduleID,
|
||||
ModuleDependencyInfo dependencies,
|
||||
StringRef scanContextHash);
|
||||
|
||||
/// Reference the list of all module dependency infos for a given scanning
|
||||
/// context
|
||||
const std::vector<ModuleDependencyID> &
|
||||
getAllModules(StringRef scanningContextHash) const {
|
||||
auto contextSpecificCache =
|
||||
getCacheForScanningContextHash(scanningContextHash);
|
||||
return contextSpecificCache->AllModules;
|
||||
}
|
||||
};
|
||||
|
||||
// MARK: ModuleDependenciesCache
|
||||
@@ -1195,11 +1110,10 @@ private:
|
||||
class ModuleDependenciesCache {
|
||||
private:
|
||||
SwiftDependencyScanningService &globalScanningService;
|
||||
/// References to data in the `globalScanningService` for module dependencies
|
||||
ModuleDependenciesKindRefMap ModuleDependenciesMap;
|
||||
/// Discovered dependencies
|
||||
ModuleDependenciesKindMap ModuleDependenciesMap;
|
||||
/// Set containing all of the Clang modules that have already been seen.
|
||||
llvm::DenseSet<clang::tooling::dependencies::ModuleID>
|
||||
alreadySeenClangModules;
|
||||
llvm::DenseSet<clang::tooling::dependencies::ModuleID> alreadySeenClangModules;
|
||||
/// Name of the module under scan
|
||||
std::string mainScanModuleName;
|
||||
/// The context hash of the current scanning invocation
|
||||
@@ -1223,6 +1137,11 @@ public:
|
||||
ModuleDependenciesCache &operator=(const ModuleDependenciesCache &) = delete;
|
||||
|
||||
public:
|
||||
/// Retrieve the dependencies map that corresponds to the given dependency
|
||||
/// kind.
|
||||
ModuleNameToDependencyMap &getDependenciesMap(ModuleDependencyKind kind);
|
||||
const ModuleNameToDependencyMap &getDependenciesMap(ModuleDependencyKind kind) const;
|
||||
|
||||
/// Whether we have cached dependency information for the given module.
|
||||
bool hasDependency(const ModuleDependencyID &moduleID) const;
|
||||
/// Whether we have cached dependency information for the given module.
|
||||
@@ -1283,13 +1202,7 @@ public:
|
||||
/// \returns the cached result, or \c None if there is no cached entry.
|
||||
std::optional<const ModuleDependencyInfo *>
|
||||
findDependency(StringRef moduleName,
|
||||
std::optional<ModuleDependencyKind> kind) const;
|
||||
|
||||
/// Look for module dependencies for a module with the given name
|
||||
///
|
||||
/// \returns the cached result, or \c None if there is no cached entry.
|
||||
std::optional<const ModuleDependencyInfo *>
|
||||
findDependency(StringRef moduleName) const;
|
||||
std::optional<ModuleDependencyKind> kind = std::nullopt) const;
|
||||
|
||||
/// Look for Swift module dependencies for a module with the given name
|
||||
///
|
||||
@@ -1340,6 +1253,10 @@ public:
|
||||
const ArrayRef<ModuleDependencyID> dependencyIDs);
|
||||
|
||||
StringRef getMainModuleName() const { return mainScanModuleName; }
|
||||
|
||||
private:
|
||||
friend class ModuleDependenciesCacheDeserializer;
|
||||
friend class ModuleDependenciesCacheSerializer;
|
||||
};
|
||||
} // namespace swift
|
||||
|
||||
|
||||
Reference in New Issue
Block a user