@@ -392,47 +392,35 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
392
392
return std::error_code ();
393
393
}
394
394
395
- llvm::ErrorOr<ModuleDependencyInfo> SerializedModuleLoaderBase::scanModuleFile (
396
- Twine modulePath, bool isFramework) {
397
- // Open the module file
398
- auto &fs = *Ctx.SourceMgr .getFileSystem ();
399
- auto moduleBuf = fs.getBufferForFile (modulePath);
395
+ llvm::ErrorOr<llvm::StringSet<>>
396
+ SerializedModuleLoaderBase::getModuleImportsOfModule (
397
+ Twine modulePath, ModuleLoadingBehavior transitiveBehavior,
398
+ bool isFramework, bool isRequiredOSSAModules, StringRef SDKName,
399
+ StringRef packageName, llvm::vfs::FileSystem *fileSystem,
400
+ PathObfuscator &recoverer) {
401
+ auto moduleBuf = fileSystem->getBufferForFile (modulePath);
400
402
if (!moduleBuf)
401
403
return moduleBuf.getError ();
402
404
405
+ llvm::StringSet<> importedModuleNames;
403
406
// Load the module file without validation.
404
407
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
405
408
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load (
406
409
" " , " " , std::move (moduleBuf.get ()), nullptr , nullptr , isFramework,
407
- isRequiredOSSAModules (), Ctx.LangOpts .SDKName ,
408
- Ctx.SearchPathOpts .DeserializedPathRecoverer , loadedModuleFile);
410
+ isRequiredOSSAModules, SDKName, recoverer, loadedModuleFile);
409
411
410
- const std::string moduleDocPath;
411
- const std::string sourceInfoPath;
412
- // Map the set of dependencies over to the "module dependencies".
413
- auto dependencies = ModuleDependencyInfo::forSwiftBinaryModule (modulePath.str (),
414
- moduleDocPath,
415
- sourceInfoPath,
416
- isFramework);
417
- llvm::StringSet<> addedModuleNames;
418
412
for (const auto &dependency : loadedModuleFile->getDependencies ()) {
419
413
// FIXME: Record header dependency?
420
414
if (dependency.isHeader ())
421
415
continue ;
422
416
423
- // Some transitive dependencies of binary modules are not required to be
424
- // imported during normal builds.
425
- // TODO: This is worth revisiting for debugger purposes where
426
- // loading the module is optional, and implementation-only imports
427
- // from modules with testing enabled where the dependency is
428
- // optional.
429
- ModuleLoadingBehavior transitiveBehavior =
430
- loadedModuleFile->getTransitiveLoadingBehavior (dependency,
431
- /* debuggerMode*/ false ,
432
- /* isPartialModule*/ false ,
433
- /* package*/ Ctx.LangOpts .PackageName ,
434
- loadedModuleFile->isTestable ());
435
- if (transitiveBehavior != ModuleLoadingBehavior::Required)
417
+ ModuleLoadingBehavior dependencyTransitiveBehavior =
418
+ loadedModuleFile->getTransitiveLoadingBehavior (
419
+ dependency,
420
+ /* debuggerMode*/ false ,
421
+ /* isPartialModule*/ false , packageName,
422
+ loadedModuleFile->isTestable ());
423
+ if (dependencyTransitiveBehavior != transitiveBehavior)
436
424
continue ;
437
425
438
426
// Find the top-level module name.
@@ -442,9 +430,40 @@ llvm::ErrorOr<ModuleDependencyInfo> SerializedModuleLoaderBase::scanModuleFile(
442
430
if (dotPos != std::string::npos)
443
431
moduleName = moduleName.slice (0 , dotPos);
444
432
445
- dependencies. addModuleImport (moduleName, &addedModuleNames );
433
+ importedModuleNames. insert (moduleName);
446
434
}
447
435
436
+ return importedModuleNames;
437
+ }
438
+
439
+ llvm::ErrorOr<ModuleDependencyInfo>
440
+ SerializedModuleLoaderBase::scanModuleFile (Twine modulePath, bool isFramework) {
441
+ const std::string moduleDocPath;
442
+ const std::string sourceInfoPath;
443
+ // Map the set of dependencies over to the "module dependencies".
444
+ auto dependencies = ModuleDependencyInfo::forSwiftBinaryModule (
445
+ modulePath.str (), moduleDocPath, sourceInfoPath, isFramework);
446
+ // Some transitive dependencies of binary modules are not required to be
447
+ // imported during normal builds.
448
+ // TODO: This is worth revisiting for debugger purposes where
449
+ // loading the module is optional, and implementation-only imports
450
+ // from modules with testing enabled where the dependency is
451
+ // optional.
452
+ ModuleLoadingBehavior transitiveLoadingBehavior =
453
+ ModuleLoadingBehavior::Required;
454
+ auto importedModuleNames = getModuleImportsOfModule (
455
+ modulePath, transitiveLoadingBehavior, isFramework,
456
+ isRequiredOSSAModules (), Ctx.LangOpts .SDKName , Ctx.LangOpts .PackageName ,
457
+ Ctx.SourceMgr .getFileSystem ().get (),
458
+ Ctx.SearchPathOpts .DeserializedPathRecoverer );
459
+ if (!importedModuleNames)
460
+ return importedModuleNames.getError ();
461
+
462
+ llvm::StringSet<> addedModuleNames;
463
+ for (const auto &importedModuleName : *importedModuleNames)
464
+ dependencies.addModuleImport (importedModuleName.getKey (),
465
+ &addedModuleNames);
466
+
448
467
return std::move (dependencies);
449
468
}
450
469
0 commit comments