Skip to content

[Dependency Scanning] Unique collected cross-import overlay files with a set #79809

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
Mar 10, 2025
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
2 changes: 1 addition & 1 deletion include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class ModuleDependencyInfo {
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
collectCrossImportOverlayNames(
ASTContext &ctx, StringRef moduleName,
std::vector<std::pair<std::string, std::string>> &overlayFiles) const;
std::set<std::pair<std::string, std::string>> &overlayFiles) const;
};

using ModuleDependencyVector =
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void ModuleLoader::findOverlayFiles(SourceLoc diagLoc, ModuleDecl *module,
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
ModuleDependencyInfo::collectCrossImportOverlayNames(
ASTContext &ctx, StringRef moduleName,
std::vector<std::pair<std::string, std::string>> &overlayFiles) const {
std::set<std::pair<std::string, std::string>> &overlayFiles) const {
using namespace llvm::sys;
using namespace file_types;
std::optional<std::string> modulePath;
Expand Down Expand Up @@ -254,7 +254,7 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(
ModuleDecl::collectCrossImportOverlay(ctx, file, moduleName,
bystandingModule);
result[bystandingModule] = std::move(overlayNames);
overlayFiles.push_back({moduleName.str(), file.str()});
overlayFiles.insert({moduleName.str(), file.str()});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectCrossImportOverlay is not exactly cheap. Can we skip if we know the entry is in the set already?

});
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/DependencyScan/ModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ ModuleDependencyScanner::getNamedSwiftModuleDependencyInfo(
static void discoverCrossImportOverlayFiles(
StringRef mainModuleName, ModuleDependenciesCache &cache,
ASTContext &scanASTContext, llvm::SetVector<Identifier> &newOverlays,
std::vector<std::pair<std::string, std::string>> &overlayFiles) {
std::set<std::pair<std::string, std::string>> &overlayFiles) {
auto mainModuleInfo = cache.findKnownDependency(ModuleDependencyID{
mainModuleName.str(), ModuleDependencyKind::SwiftSource});

Expand Down Expand Up @@ -1354,7 +1354,7 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies(
llvm::function_ref<void(ModuleDependencyID)> action) {
// Modules explicitly imported. Only these can be secondary module.
llvm::SetVector<Identifier> newOverlays;
std::vector<std::pair<std::string, std::string>> overlayFiles;
std::set<std::pair<std::string, std::string>> overlayFiles;
discoverCrossImportOverlayFiles(mainModuleName, cache, ScanASTContext,
newOverlays, overlayFiles);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/module-cache)
// RUN: split-file %s %t

// Run a dependency scan on a source file that imports both constituents of a cross-import overlay to ensure the cross-import overlay dependency is registered
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/module-cache %t/A.swift %t/B.swift -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -I %S/Inputs/CHeaders/ExtraCModules -module-name FineGrainedCrossImportTestModule -enable-cross-import-overlays

// Check the contents of the JSON output
// RUN: %validate-json %t/deps.json | %FileCheck %s

//--- A.swift
import E
import SubE

//--- B.swift
import E
import SubE

// CHECK: "swift": "_cross_import_E"
// CHECK-COUNT-1: -swift-module-cross-import