Skip to content

[5.9][Dependency Scanning] Do not add cross-import overlays that involve the main module being scanned #64685

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 29, 2023
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: 0 additions & 2 deletions lib/AST/ModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(ASTContext &ctx,
break;
}
case swift::ModuleDependencyKind::SwiftSource: {
auto *swiftSourceDep = getAsSwiftSourceModule();
assert(!swiftSourceDep->sourceFiles.empty());
return result;
}
case swift::ModuleDependencyKind::SwiftPlaceholder: {
Expand Down
8 changes: 8 additions & 0 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ static void discoverCrossImportOverlayDependencies(
// Modules explicitly imported. Only these can be secondary module.
llvm::SetVector<Identifier> newOverlays;
for (auto dep : allDependencies) {
// Do not look for overlays of main module under scan
if (dep.first == mainModuleName)
continue;

auto moduleName = dep.first;
auto dependencies = cache.findDependency(moduleName, dep.second).value();

Expand All @@ -413,8 +417,12 @@ static void discoverCrossImportOverlayDependencies(
instance.getASTContext(), moduleName);
if (overlayMap.empty())
continue;

std::for_each(allDependencies.begin(), allDependencies.end(),
[&](ModuleDependencyID Id) {
// Do not look for overlays of main module under scan
if (Id.first == mainModuleName)
return;
// check if any explicitly imported modules can serve as a
// secondary module, and add the overlay names to the
// dependencies list.
Expand Down
1 change: 1 addition & 0 deletions test/ScanDependencies/Inputs/CHeaders/ExtraCModules/SubE.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void funcEE(void);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SubE {
header "SubE.h"
export *
}
23 changes: 23 additions & 0 deletions test/ScanDependencies/no_main_module_cross_import.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/clang-module-cache
// 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
// Check the contents of the JSON output
// RUN: %FileCheck %s < %t/deps.json

// REQUIRES: executable_test
// REQUIRES: objc_interop

// Ordinarily, importing `E` and `SubE` triggers a cross-import of `_cross_import_E`, but not here, because we are building `SubE` Swift module itself.
import EWrapper
import SubE

// CHECK: "directDependencies": [
// CHECK-DAG: "swift": "EWrapper"
// CHECK-DAG: "clang": "SubE"
// CHECK-DAG: "swift": "Swift"
// CHECK-DAG: "swift": "SwiftOnoneSupport"
// CHECK-DAG: "swift": "_Concurrency"
// CHECK-DAG: "swift": "_StringProcessing"
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"

// CHECK-NOT: "swift": "_cross_import_E"