Skip to content

[Dependency Scanner] Move the Clang scanning shared state out into local (per-scan) cache. #60776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,6 @@ class GlobalModuleDependenciesCache {
/// The triples used by scanners using this cache, in the order in which they were used
std::vector<std::string> AllTriples;

/// Additional information needed for Clang dependency scanning.
ClangModuleDependenciesCacheImpl *clangImpl = nullptr;

/// Function that will delete \c clangImpl properly.
void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *) = nullptr;

/// Free up the storage associated with the Clang implementation.
void destroyClangImpl() {
if (this->clangImplDeleter)
this->clangImplDeleter(this->clangImpl);
}

/// Retrieve the dependencies map that corresponds to the given dependency
/// kind.
llvm::StringMap<ModuleDependenciesVector> &
Expand All @@ -540,7 +528,7 @@ class GlobalModuleDependenciesCache {
GlobalModuleDependenciesCache &
operator=(const GlobalModuleDependenciesCache &) = delete;

virtual ~GlobalModuleDependenciesCache() { destroyClangImpl(); }
virtual ~GlobalModuleDependenciesCache() {}

void configureForTriple(std::string triple);

Expand All @@ -553,19 +541,6 @@ class GlobalModuleDependenciesCache {
/// wrapped in an instance of `ModuleDependenciesCache`.
friend class ModuleDependenciesCache;

/// Set the Clang-specific implementation data.
virtual void
setClangImpl(ClangModuleDependenciesCacheImpl *clangImpl,
void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *)) {
destroyClangImpl();

this->clangImpl = clangImpl;
this->clangImplDeleter = clangImplDeleter;
}

/// Retrieve the Clang-specific implementation data;
ClangModuleDependenciesCacheImpl *getClangImpl() const { return clangImpl; }

/// Whether we have cached dependency information for the given module.
bool hasDependencies(StringRef moduleName,
ModuleLookupSpecifics details) const;
Expand Down Expand Up @@ -632,6 +607,18 @@ class ModuleDependenciesCache {
/// the current scanning action.
ModuleDependenciesKindRefMap ModuleDependenciesMap;

/// Additional information needed for Clang dependency scanning.
ClangModuleDependenciesCacheImpl *clangImpl = nullptr;

/// Function that will delete \c clangImpl properly.
void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *) = nullptr;

/// Free up the storage associated with the Clang implementation.
void destroyClangImpl() {
if (this->clangImplDeleter)
this->clangImplDeleter(this->clangImpl);
}

/// Retrieve the dependencies map that corresponds to the given dependency
/// kind.
llvm::StringMap<const ModuleDependencies *> &
Expand All @@ -654,19 +641,22 @@ class ModuleDependenciesCache {
ModuleDependenciesCache(GlobalModuleDependenciesCache &globalCache);
ModuleDependenciesCache(const ModuleDependenciesCache &) = delete;
ModuleDependenciesCache &operator=(const ModuleDependenciesCache &) = delete;
virtual ~ModuleDependenciesCache() {}
virtual ~ModuleDependenciesCache() { destroyClangImpl(); }

public:
/// Set the Clang-specific implementation data.
void
setClangImpl(ClangModuleDependenciesCacheImpl *clangImpl,
void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *)) {
globalCache.setClangImpl(clangImpl, clangImplDeleter);
destroyClangImpl();

this->clangImpl = clangImpl;
this->clangImplDeleter = clangImplDeleter;
}

/// Retrieve the Clang-specific implementation data;
ClangModuleDependenciesCacheImpl *getClangImpl() const {
return globalCache.getClangImpl();
return clangImpl;
}

/// Whether we have cached dependency information for the given module.
Expand Down