Skip to content

[Dependency Scanning] Optionally, resolve direct dependencies of a module using only the ModuleDependenciesCache. #35356

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
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ class ASTContext final {
StringRef moduleName,
bool isUnderlyingClangModule,
ModuleDependenciesCache &cache,
InterfaceSubContextDelegate &delegate);
InterfaceSubContextDelegate &delegate,
bool cacheOnly = false);

/// Retrieve the module dependencies for the Swift module with the given name.
Optional<ModuleDependencies> getSwiftModuleDependencies(
Expand Down
36 changes: 28 additions & 8 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,15 +1533,35 @@ void ASTContext::addModuleInterfaceChecker(

Optional<ModuleDependencies> ASTContext::getModuleDependencies(
StringRef moduleName, bool isUnderlyingClangModule,
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate) {
for (auto &loader : getImpl().ModuleLoaders) {
if (isUnderlyingClangModule &&
loader.get() != getImpl().TheClangModuleLoader)
continue;
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate,
bool cacheOnly) {
// Retrieve the dependencies for this module.
if (cacheOnly) {
// Check whether we've cached this result.
if (!isUnderlyingClangModule) {
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftTextual))
return found;
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftTextual))
return found;
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::SwiftPlaceholder))
return found;
}
if (auto found = cache.findDependencies(moduleName,
ModuleDependenciesKind::Clang))
return found;
} else {
for (auto &loader : getImpl().ModuleLoaders) {
if (isUnderlyingClangModule &&
loader.get() != getImpl().TheClangModuleLoader)
continue;

if (auto dependencies = loader->getModuleDependencies(moduleName, cache,
delegate))
return dependencies;
if (auto dependencies = loader->getModuleDependencies(moduleName, cache,
delegate))
return dependencies;
}
}

return None;
Expand Down
13 changes: 6 additions & 7 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static void findAllImportedClangModules(ASTContext &ctx, StringRef moduleName,
static std::vector<ModuleDependencyID>
resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
ModuleDependenciesCache &cache,
InterfaceSubContextDelegate &ASTDelegate) {
InterfaceSubContextDelegate &ASTDelegate,
bool cacheOnly = false) {
auto &ctx = instance.getASTContext();
auto knownDependencies = *cache.findDependencies(module.first, module.second);
auto isSwift = knownDependencies.isSwiftTextualModule();
Expand All @@ -163,10 +164,8 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
for (auto dependsOn : knownDependencies.getModuleDependencies()) {
// Figure out what kind of module we need.
bool onlyClangModule = !isSwift || module.first == dependsOn;

// Retrieve the dependencies for this module.
if (auto found = ctx.getModuleDependencies(dependsOn, onlyClangModule,
cache, ASTDelegate)) {
cache, ASTDelegate, cacheOnly)) {
result.insert({dependsOn, found->getKind()});
}
}
Expand Down Expand Up @@ -209,7 +208,7 @@ resolveDirectDependencies(CompilerInstance &instance, ModuleDependencyID module,
// directly depends on these.
for (const auto &clangDep : allClangModules) {
if (auto found = ctx.getModuleDependencies(
clangDep, /*onlyClangModule=*/false, cache, ASTDelegate)) {
clangDep, /*onlyClangModule=*/false, cache, ASTDelegate, cacheOnly)) {
// ASTContext::getModuleDependencies returns dependencies for a module
// with a given name. This Clang module may have the same name as the
// Swift module we are resolving, so we need to make sure we don't add a
Expand Down Expand Up @@ -761,7 +760,7 @@ generateFullDependencyGraph(CompilerInstance &instance,
// DirectDependencies
auto directDependencies = resolveDirectDependencies(
instance, ModuleDependencyID(module.first, module.second), cache,
ASTDelegate);
ASTDelegate, /*cacheOnly*/ true);

// Generate a swiftscan_clang_details_t object based on the dependency kind
auto getModuleDetails = [&]() -> swiftscan_module_details_t {
Expand Down Expand Up @@ -871,7 +870,7 @@ static bool diagnoseCycle(CompilerInstance &instance,
auto &lastOpen = openSet.back();
auto beforeSize = openSet.size();
for (auto dep :
resolveDirectDependencies(instance, lastOpen, cache, astDelegate)) {
resolveDirectDependencies(instance, lastOpen, cache, astDelegate, /*cacheOnly*/ true)) {
if (closeSet.count(dep))
continue;
if (openSet.insert(dep)) {
Expand Down