Serialize explicit module dependencies in swift module files

For clients, such as the debugger, who do not have access the full
output of the dependency scanner, it is a huger performance and
correctness improvement if each explicitly built Swift module not just
serialized all its Clang .pcm dependencies (via the serialized Clang
compiler invocation) but also its direct Swift module dependencies.

This patch changes the Swift module format to store the absolute path
or cas cache key for each dependency in the INPUT block, and makes
sure the deserialization makes these available to the ESML.

rdar://150969755
This commit is contained in:
Adrian Prantl
2025-09-18 16:54:54 -07:00
parent cb7ddbe9ea
commit c91211a5d2
20 changed files with 148 additions and 62 deletions

View File

@@ -2304,8 +2304,8 @@ bool ExplicitSwiftModuleLoader::findModule(
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer,
bool IsCanImportLookup, bool isTestableDependencyLookup,
bool &IsFramework, bool &IsSystemModule) {
std::string *cacheKey, bool IsCanImportLookup,
bool isTestableDependencyLookup, bool &IsFramework, bool &IsSystemModule) {
// Find a module with an actual, physical name on disk, in case
// -module-alias is used (otherwise same).
//
@@ -2473,6 +2473,12 @@ ExplicitSwiftModuleLoader::create(ASTContext &ctx,
return result;
}
void ExplicitSwiftModuleLoader::addExplicitModulePath(StringRef name,
std::string path) {
ExplicitSwiftModuleInputInfo entry(path, {}, {}, {});
Impl.ExplicitModuleMap.try_emplace(name, std::move(entry));
}
struct ExplicitCASModuleLoader::Implementation {
ASTContext &Ctx;
llvm::BumpPtrAllocator Allocator;
@@ -2660,8 +2666,8 @@ bool ExplicitCASModuleLoader::findModule(
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer,
bool IsCanImportLookup, bool IsTestableDependencyLookup,
bool &IsFramework, bool &IsSystemModule) {
std::string *CacheKey, bool IsCanImportLookup,
bool IsTestableDependencyLookup, bool &IsFramework, bool &IsSystemModule) {
// Find a module with an actual, physical name on disk, in case
// -module-alias is used (otherwise same).
//
@@ -2681,6 +2687,8 @@ bool ExplicitCASModuleLoader::findModule(
// Set IsFramework bit according to the moduleInfo
IsFramework = moduleInfo.isFramework;
IsSystemModule = moduleInfo.isSystem;
if (CacheKey && moduleInfo.moduleCacheKey)
*CacheKey = *moduleInfo.moduleCacheKey;
// Fallback check for module cache key passed on command-line as module path.
std::string moduleCASID = moduleInfo.moduleCacheKey