Skip to content

Commit 148fb36

Browse files
committed
[Dependency Scanning] Unique collected cross-import overlay files with a set
Resolves rdar://146141228
1 parent 0997a7e commit 148fb36

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
@@ -990,7 +990,7 @@ class ModuleDependencyInfo {
990990
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
991991
collectCrossImportOverlayNames(
992992
ASTContext &ctx, StringRef moduleName,
993-
std::vector<std::pair<std::string, std::string>> &overlayFiles) const;
993+
std::set<std::pair<std::string, std::string>> &overlayFiles) const;
994994
};
995995

996996
using ModuleDependencyVector =

lib/AST/ModuleLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void ModuleLoader::findOverlayFiles(SourceLoc diagLoc, ModuleDecl *module,
202202
llvm::StringMap<llvm::SmallSetVector<Identifier, 4>>
203203
ModuleDependencyInfo::collectCrossImportOverlayNames(
204204
ASTContext &ctx, StringRef moduleName,
205-
std::vector<std::pair<std::string, std::string>> &overlayFiles) const {
205+
std::set<std::pair<std::string, std::string>> &overlayFiles) const {
206206
using namespace llvm::sys;
207207
using namespace file_types;
208208
std::optional<std::string> modulePath;
@@ -254,7 +254,7 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(
254254
ModuleDecl::collectCrossImportOverlay(ctx, file, moduleName,
255255
bystandingModule);
256256
result[bystandingModule] = std::move(overlayNames);
257-
overlayFiles.push_back({moduleName.str(), file.str()});
257+
overlayFiles.insert({moduleName.str(), file.str()});
258258
});
259259
return result;
260260
}

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ ModuleDependencyScanner::getNamedSwiftModuleDependencyInfo(
586586
static void discoverCrossImportOverlayFiles(
587587
StringRef mainModuleName, ModuleDependenciesCache &cache,
588588
ASTContext &scanASTContext, llvm::SetVector<Identifier> &newOverlays,
589-
std::vector<std::pair<std::string, std::string>> &overlayFiles) {
589+
std::set<std::pair<std::string, std::string>> &overlayFiles) {
590590
auto mainModuleInfo = cache.findKnownDependency(ModuleDependencyID{
591591
mainModuleName.str(), ModuleDependencyKind::SwiftSource});
592592

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

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)