Skip to content

Commit 289d03f

Browse files
Merge pull request #72908 from cachemeifyoucan/eng/PR-allow-binary-testable-module-no-interface
[ScanDependency] Allow importing binary testable module when no interface
2 parents b8c6442 + 90a1586 commit 289d03f

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ class SerializedModuleLoaderBase : public ModuleLoader {
163163
}
164164

165165
/// Scan the given serialized module file to determine dependencies.
166-
llvm::ErrorOr<ModuleDependencyInfo>
167-
scanModuleFile(Twine modulePath, bool isFramework, bool isTestableImport);
166+
llvm::ErrorOr<ModuleDependencyInfo> scanModuleFile(Twine modulePath,
167+
bool isFramework,
168+
bool isTestableImport,
169+
bool hasInterface);
168170

169171
struct BinaryModuleImports {
170172
llvm::StringSet<> moduleImports;

lib/Serialization/ScanningLoaders.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ std::error_code SwiftModuleScanner::findModuleFilesInDirectory(
5757
if (fs.exists(ModPath)) {
5858
// The module file will be loaded directly.
5959
auto dependencies =
60-
scanModuleFile(ModPath, IsFramework, isTestableDependencyLookup);
60+
scanModuleFile(ModPath, IsFramework, isTestableDependencyLookup,
61+
/*hasInterface=*/false);
6162
if (dependencies) {
6263
this->dependencies = std::move(dependencies.get());
6364
return std::error_code();
@@ -159,8 +160,9 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
159160
!Ctx.SearchPathOpts.NoScannerModuleValidation) {
160161
assert(compiledCandidates.size() == 1 &&
161162
"Should only have 1 candidate module");
162-
auto BinaryDep = scanModuleFile(compiledCandidates[0], isFramework,
163-
isTestableImport);
163+
auto BinaryDep =
164+
scanModuleFile(compiledCandidates[0], isFramework,
165+
isTestableImport, /*hasInterface=*/true);
164166
if (BinaryDep) {
165167
Result = *BinaryDep;
166168
return std::error_code();

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ SerializedModuleLoaderBase::getImportsOfModule(
431431

432432
llvm::ErrorOr<ModuleDependencyInfo>
433433
SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework,
434-
bool isTestableImport) {
434+
bool isTestableImport,
435+
bool hasInterface) {
435436
const std::string moduleDocPath;
436437
const std::string sourceInfoPath;
437438

@@ -455,7 +456,10 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework,
455456
return std::make_error_code(std::errc::no_such_file_or_directory);
456457
}
457458

458-
if (loadedModuleFile->isTestable() && !isTestableImport) {
459+
// If the module file has interface file and not testable imported, don't
460+
// import the testable module because it contains more interfaces than
461+
// needed and can pull in more dependencies.
462+
if (loadedModuleFile->isTestable() && !isTestableImport && hasInterface) {
459463
if (Ctx.LangOpts.EnableModuleLoadingRemarks)
460464
Ctx.Diags.diagnose(SourceLoc(), diag::skip_module_testable,
461465
modulePath.str());

test/ScanDependencies/testable-dependencies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -enable-testing \
5757
// RUN: -o %t/deps5.json -I %t/regular -swift-version 5 -Rmodule-loading
5858

59-
/// Regular import a testable module with no interface, this is a dependency scanning error.
59+
/// Regular import a testable module with no interface, will try to import binary module but fail to look up the dependency.
6060
// RUN: rm %t/testable/A.swiftinterface
6161
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -module-name Test %t/main.swift \
6262
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -enable-testing \
6363
// RUN: -o %t/deps6.json -I %t/testable -swift-version 5 -Rmodule-loading 2>&1 | %FileCheck %s --check-prefix ERROR
64-
// ERROR: error: Unable to find module dependency: 'A'
64+
// ERROR: error: Unable to find module dependency: 'B'
6565

6666
//--- main.swift
6767
import A

0 commit comments

Comments
 (0)