@@ -80,8 +80,7 @@ std::error_code SwiftModuleScanner::findModuleFilesInDirectory(
8080 InPath = PrivateInPath;
8181 }
8282 }
83- auto dependencies =
84- scanInterfaceFile (InPath, IsFramework, isTestableDependencyLookup);
83+ auto dependencies = scanInterfaceFile (InPath, IsFramework);
8584 if (dependencies) {
8685 this ->dependencies = std::move (dependencies.get ());
8786 return std::error_code ();
@@ -148,7 +147,7 @@ static std::vector<std::string> getCompiledCandidates(ASTContext &ctx,
148147
149148llvm::ErrorOr<ModuleDependencyInfo>
150149SwiftModuleScanner::scanInterfaceFile (Twine moduleInterfacePath,
151- bool isFramework, bool isTestableImport ) {
150+ bool isFramework) {
152151 // Create a module filename.
153152 // FIXME: Query the module interface loader to determine an appropriate
154153 // name for the module, which includes an appropriate hash.
@@ -242,64 +241,6 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
242241 &alreadyAddedModules);
243242 }
244243
245- // For a `@testable` direct dependency, read in the dependencies
246- // from an adjacent binary module, for completeness.
247- if (isTestableImport) {
248- auto adjacentBinaryModule = std::find_if (
249- compiledCandidates.begin (), compiledCandidates.end (),
250- [moduleInterfacePath](const std::string &candidate) {
251- return llvm::sys::path::parent_path (candidate) ==
252- llvm::sys::path::parent_path (moduleInterfacePath.str ());
253- });
254- if (adjacentBinaryModule != compiledCandidates.end ()) {
255- // Required modules.
256- auto adjacentBinaryModuleRequiredImports = getImportsOfModule (
257- *adjacentBinaryModule, ModuleLoadingBehavior::Required,
258- isFramework, isRequiredOSSAModules (),
259- isRequiredNoncopyableGenerics (),
260- Ctx.LangOpts .SDKName ,
261- Ctx.LangOpts .PackageName , Ctx.SourceMgr .getFileSystem ().get (),
262- Ctx.SearchPathOpts .DeserializedPathRecoverer );
263- if (!adjacentBinaryModuleRequiredImports)
264- return adjacentBinaryModuleRequiredImports.getError ();
265- auto adjacentBinaryModuleRequiredModuleImports =
266- (*adjacentBinaryModuleRequiredImports).moduleImports ;
267- #ifndef NDEBUG
268- // Verify that the set of required modules read out from the binary
269- // module is a super-set of module imports identified in the
270- // textual interface.
271- for (const auto &requiredImport : Result->getModuleImports ()) {
272- assert (
273- adjacentBinaryModuleRequiredModuleImports.contains (
274- requiredImport) &&
275- " Expected adjacent binary module's import set to contain all "
276- " textual interface imports." );
277- }
278- #endif
279-
280- for (const auto &requiredImport :
281- adjacentBinaryModuleRequiredModuleImports)
282- Result->addModuleImport (requiredImport.getKey (),
283- &alreadyAddedModules);
284-
285- // Optional modules. Will be looked-up on a best-effort basis
286- auto adjacentBinaryModuleOptionalImports = getImportsOfModule (
287- *adjacentBinaryModule, ModuleLoadingBehavior::Optional,
288- isFramework, isRequiredOSSAModules (),
289- isRequiredNoncopyableGenerics (), Ctx.LangOpts .SDKName ,
290- Ctx.LangOpts .PackageName , Ctx.SourceMgr .getFileSystem ().get (),
291- Ctx.SearchPathOpts .DeserializedPathRecoverer );
292- if (!adjacentBinaryModuleOptionalImports)
293- return adjacentBinaryModuleOptionalImports.getError ();
294- auto adjacentBinaryModuleOptionalModuleImports =
295- (*adjacentBinaryModuleOptionalImports).moduleImports ;
296- for (const auto &optionalImport :
297- adjacentBinaryModuleOptionalModuleImports)
298- Result->addOptionalModuleImport (optionalImport.getKey (),
299- &alreadyAddedModules);
300- }
301- }
302-
303244 return std::error_code ();
304245 });
305246
@@ -324,6 +265,10 @@ ModuleDependencyVector SerializedModuleLoaderBase::getModuleDependencies(
324265 if (CacheFS)
325266 tracker = SwiftDependencyTracker (*CacheFS, mapper);
326267
268+ // Do not load interface module if it is testable import.
269+ ModuleLoadingMode MLM =
270+ isTestableDependencyLookup ? ModuleLoadingMode::OnlySerialized : LoadMode;
271+
327272 // Instantiate dependency scanning "loaders".
328273 SmallVector<std::unique_ptr<SwiftModuleScanner>, 2 > scanners;
329274 // Placeholder dependencies must be resolved first, to prevent the
@@ -332,11 +277,10 @@ ModuleDependencyVector SerializedModuleLoaderBase::getModuleDependencies(
332277 // dependency graph of the placeholder dependency module itself.
333278 // FIXME: submodules?
334279 scanners.push_back (std::make_unique<PlaceholderSwiftModuleScanner>(
335- Ctx, LoadMode, moduleId,
336- Ctx.SearchPathOpts .PlaceholderDependencyModuleMap , delegate,
337- moduleOutputPath, tracker));
280+ Ctx, MLM, moduleId, Ctx.SearchPathOpts .PlaceholderDependencyModuleMap ,
281+ delegate, moduleOutputPath, tracker));
338282 scanners.push_back (std::make_unique<SwiftModuleScanner>(
339- Ctx, LoadMode , moduleId, delegate, moduleOutputPath,
283+ Ctx, MLM , moduleId, delegate, moduleOutputPath,
340284 SwiftModuleScanner::MDS_plain, tracker));
341285
342286 // Check whether there is a module with this name that we can import.
0 commit comments