[Dependency Scanning] Attempt to lookup optional transitive dependencies of binary module dependencies. Instead of simply pretending they do not exist, do a best-effort lookup

This commit is contained in:
Artem Chikin
2023-09-13 13:57:20 -07:00
parent c2ba21e334
commit 52da0b02fa
7 changed files with 74 additions and 10 deletions

View File

@@ -457,6 +457,15 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework) {
if (!binaryModuleImports)
return binaryModuleImports.getError();
// Lookup optional imports of this module also
auto binaryModuleOptionalImports = getImportsOfModule(
modulePath, ModuleLoadingBehavior::Optional, isFramework,
isRequiredOSSAModules(), Ctx.LangOpts.SDKName, Ctx.LangOpts.PackageName,
Ctx.SourceMgr.getFileSystem().get(),
Ctx.SearchPathOpts.DeserializedPathRecoverer);
if (!binaryModuleOptionalImports)
return binaryModuleImports.getError();
auto importedModuleSet = binaryModuleImports.get().moduleImports;
std::vector<std::string> importedModuleNames;
importedModuleNames.reserve(importedModuleSet.size());
@@ -475,11 +484,17 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework) {
return N.str();
});
auto &importedOptionalModuleSet = binaryModuleOptionalImports.get().moduleImports;
std::vector<std::string> importedOptionalModuleNames;
for (const auto optionalImportedModule : importedOptionalModuleSet.keys())
if (!importedModuleSet.contains(optionalImportedModule))
importedOptionalModuleNames.push_back(optionalImportedModule.str());
// Map the set of dependencies over to the "module dependencies".
auto dependencies = ModuleDependencyInfo::forSwiftBinaryModule(
modulePath.str(), moduleDocPath, sourceInfoPath,
importedModuleNames, importedHeaders, isFramework,
/*module-cache-key*/ "");
importedModuleNames, importedOptionalModuleNames,
importedHeaders, isFramework, /*module-cache-key*/ "");
return std::move(dependencies);
}