Skip to content

Commit 7a46674

Browse files
committed
[Dependency Scanning] Unique collected cross-import overlay files with a set
Resolves rdar://146141228
1 parent 7b081ca commit 7a46674

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ class ModuleDependencyInfo {
966966
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
967967
collectCrossImportOverlayNames(
968968
ASTContext &ctx, StringRef moduleName,
969-
std::vector<std::pair<std::string, std::string>> &overlayFiles) const;
969+
std::set<std::pair<std::string, std::string>> &overlayFiles) const;
970970
};
971971

972972
using ModuleDependencyVector =

lib/AST/ModuleLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void ModuleLoader::findOverlayFiles(SourceLoc diagLoc, ModuleDecl *module,
208208
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
209209
ModuleDependencyInfo::collectCrossImportOverlayNames(
210210
ASTContext &ctx, StringRef moduleName,
211-
std::vector<std::pair<std::string, std::string>> &overlayFiles) const {
211+
std::set<std::pair<std::string, std::string>> &overlayFiles) const {
212212
using namespace llvm::sys;
213213
using namespace file_types;
214214
std::optional<std::string> modulePath;
@@ -260,7 +260,7 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(
260260
ModuleDecl::collectCrossImportOverlay(ctx, file, moduleName,
261261
bystandingModule);
262262
result[bystandingModule] = std::move(overlayNames);
263-
overlayFiles.push_back({moduleName.str(), file.str()});
263+
overlayFiles.insert({moduleName.str(), file.str()});
264264
});
265265
return result;
266266
}

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ ModuleDependencyScanner::getNamedSwiftModuleDependencyInfo(
556556
static void discoverCrossImportOverlayFiles(
557557
StringRef mainModuleName, ModuleDependenciesCache &cache,
558558
ASTContext &scanASTContext, llvm::SetVector<Identifier> &newOverlays,
559-
std::vector<std::pair<std::string, std::string>> &overlayFiles) {
559+
std::set<std::pair<std::string, std::string>> &overlayFiles) {
560560
auto mainModuleInfo = cache.findKnownDependency(ModuleDependencyID{
561561
mainModuleName.str(), ModuleDependencyKind::SwiftSource});
562562

@@ -1275,7 +1275,7 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies(
12751275
llvm::function_ref<void(ModuleDependencyID)> action) {
12761276
// Modules explicitly imported. Only these can be secondary module.
12771277
llvm::SetVector<Identifier> newOverlays;
1278-
std::vector<std::pair<std::string, std::string>> overlayFiles;
1278+
std::set<std::pair<std::string, std::string>> overlayFiles;
12791279
discoverCrossImportOverlayFiles(mainModuleName, cache, ScanASTContext,
12801280
newOverlays, overlayFiles);
12811281

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/module-cache)
3+
// RUN: split-file %s %t
4+
5+
// 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
6+
// 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
7+
8+
// Check the contents of the JSON output
9+
// RUN: %validate-json %t/deps.json | %FileCheck %s
10+
11+
//--- A.swift
12+
import E
13+
import SubE
14+
15+
//--- B.swift
16+
import E
17+
import SubE
18+
19+
// CHECK: "swift": "_cross_import_E"
20+
// CHECK-COUNT-1: -swift-module-cross-import

0 commit comments

Comments
 (0)