Skip to content

Commit 85d2d39

Browse files
committed
[Dependency Scanning] Do not add cross-import overlays that involve the main module being scanned
For example, when scanning a source module `Foo`, which, when depending on module `Bar` causes a cross-import overlay `_Foo_Bar` to be added, do not add this cross-import overlay when scanning `Foo` itself. For example, if `Foo` adds a dependency on `Bar` itself in its own dependency graph.
1 parent 6df1237 commit 85d2d39

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

lib/AST/ModuleLoader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(ASTContext &ctx,
211211
break;
212212
}
213213
case swift::ModuleDependencyKind::SwiftSource: {
214-
auto *swiftSourceDep = getAsSwiftSourceModule();
215-
assert(!swiftSourceDep->sourceFiles.empty());
216214
return result;
217215
}
218216
case swift::ModuleDependencyKind::SwiftPlaceholder: {

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ static void discoverCrossImportOverlayDependencies(
405405
// Modules explicitly imported. Only these can be secondary module.
406406
llvm::SetVector<Identifier> newOverlays;
407407
for (auto dep : allDependencies) {
408+
// Do not look for overlays of main module under scan
409+
if (dep.first == mainModuleName)
410+
continue;
411+
408412
auto moduleName = dep.first;
409413
auto dependencies = cache.findDependency(moduleName, dep.second).value();
410414

@@ -413,8 +417,12 @@ static void discoverCrossImportOverlayDependencies(
413417
instance.getASTContext(), moduleName);
414418
if (overlayMap.empty())
415419
continue;
420+
416421
std::for_each(allDependencies.begin(), allDependencies.end(),
417422
[&](ModuleDependencyID Id) {
423+
// Do not look for overlays of main module under scan
424+
if (Id.first == mainModuleName)
425+
return;
418426
// check if any explicitly imported modules can serve as a
419427
// secondary module, and add the overlay names to the
420428
// dependencies list.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void funcEE(void);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module SubE {
2+
header "SubE.h"
3+
export *
4+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/CHeaders/ExtraCModules -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -swift-version 4 -module-name SubE
4+
// Check the contents of the JSON output
5+
// RUN: %FileCheck %s < %t/deps.json
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: objc_interop
9+
10+
// Ordinarily, importing `E` and `SubE` triggers a cross-import of `_cross_import_E`, but not here, because we are building `SubE` Swift module itself.
11+
import EWrapper
12+
import SubE
13+
14+
// CHECK: "directDependencies": [
15+
// CHECK-DAG: "swift": "EWrapper"
16+
// CHECK-DAG: "clang": "SubE"
17+
// CHECK-DAG: "swift": "Swift"
18+
// CHECK-DAG: "swift": "SwiftOnoneSupport"
19+
// CHECK-DAG: "swift": "_Concurrency"
20+
// CHECK-DAG: "swift": "_StringProcessing"
21+
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
22+
23+
// CHECK-NOT: "swift": "_cross_import_E"

0 commit comments

Comments
 (0)