Do not build Swift interface files into binary modules when performing a canImport query.

We should hold off actually building the binary module file until it is imported.
`canImport` queries can happen, for example, during dependency scanning, when we do not wish to have the scanner tool execute any module builds.

Resolves rdar://82603098
This commit is contained in:
Artem Chikin
2021-09-01 16:06:21 -07:00
parent 1907a820ea
commit 1b7d55582d
9 changed files with 50 additions and 22 deletions

View File

@@ -1083,7 +1083,7 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer,
bool IsFramework) {
bool skipBuildingInterface, bool IsFramework) {
// If running in OnlySerialized mode, ModuleInterfaceLoader
// should not have been constructed at all.
@@ -1111,6 +1111,16 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
InPath = PrivateInPath;
}
// If we've been told to skip building interfaces, we are done here and do
// not need to have the module actually built. For example, if we are
// currently answering a `canImport` query, it is enough to have found
// the interface.
if (skipBuildingInterface) {
if (ModuleInterfacePath)
*ModuleInterfacePath = InPath;
return std::error_code();
}
// Create an instance of the Impl to do the heavy lifting.
auto ModuleName = ModuleID.Item.str();
ModuleInterfaceLoaderImpl Impl(
@@ -1711,7 +1721,7 @@ bool ExplicitSwiftModuleLoader::findModule(ImportPath::Element ModuleID,
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer,
bool &IsFramework, bool &IsSystemModule) {
bool skipBuildingInterface, bool &IsFramework, bool &IsSystemModule) {
StringRef moduleName = ModuleID.Item.str();
auto it = Impl.ExplicitModuleMap.find(moduleName);
// If no explicit module path is given matches the name, return with an
@@ -1783,7 +1793,7 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer,
bool IsFramework) {
bool skipBuildingInterface, bool IsFramework) {
llvm_unreachable("Not supported in the Explicit Swift Module Loader.");
return std::make_error_code(std::errc::not_supported);
}