[ExplicitModule] Teach scanner emit loaded module trace

During explicit module build, teach dependency scanner to emit the
module trace file instead of each following compile job command. This
reduces the duplicated info, and allows supporting fully cached build
that only loads module from CAS thus cannot produce the path to the
original module file on disk.

rdar://170007480
This commit is contained in:
Steven Wu
2026-02-12 15:41:05 -08:00
parent 43a53f40d0
commit 7fdf642819
19 changed files with 425 additions and 143 deletions

View File

@@ -553,14 +553,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
"Unexpected SWIFT_TEXTUAL_MODULE_DETAILS_NODE record");
unsigned outputPathFileID, interfaceFileID,
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
contextHashID, isFramework, isStatic,
contextHashID, isFramework, isStatic, isStrictMemorySafety,
bridgingHeaderFileID, sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, CASFileSystemRootID,
bridgingHeaderIncludeTreeID, moduleCacheKeyID, userModuleVersionID;
SwiftInterfaceModuleDetailsLayout::readRecord(
Scratch, outputPathFileID, interfaceFileID,
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
contextHashID, isFramework, isStatic,
contextHashID, isFramework, isStatic, isStrictMemorySafety,
bridgingHeaderFileID, sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, CASFileSystemRootID,
bridgingHeaderIncludeTreeID, moduleCacheKeyID, userModuleVersionID);
@@ -606,9 +606,9 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
// Form the dependencies storage object
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
*optionalSwiftInterfaceFile, compiledCandidatesRefs,
buildCommandRefs, importStatements, optionalImportStatements,
linkLibraries, isFramework, isStatic, *rootFileSystemID,
*optionalSwiftInterfaceFile, compiledCandidatesRefs, buildCommandRefs,
importStatements, optionalImportStatements, linkLibraries,
isFramework, isStatic, isStrictMemorySafety, *rootFileSystemID,
*moduleCacheKey, *userModuleVersion);
moduleDep.setOutputPathAndHash(*outputModulePath, *contextHash);
@@ -629,13 +629,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
"Unexpected SWIFT_SOURCE_MODULE_DETAILS_NODE record");
unsigned bridgingHeaderFileID, sourceFilesArrayID,
bridgingSourceFilesArrayID, bridgingModuleDependenciesArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID,
buildCommandLineArrayID, bridgingHeaderBuildCommandLineArrayID,
chainedBridgingHeaderPathID, chainedBridgingHeaderContentID;
dependencyOnlyImportsID, CASFileSystemRootID,
bridgingHeaderIncludeTreeID, buildCommandLineArrayID,
bridgingHeaderBuildCommandLineArrayID, chainedBridgingHeaderPathID,
chainedBridgingHeaderContentID;
SwiftSourceModuleDetailsLayout::readRecord(
Scratch, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, CASFileSystemRootID,
Scratch, bridgingHeaderFileID, sourceFilesArrayID,
bridgingSourceFilesArrayID, bridgingModuleDependenciesArrayID,
dependencyOnlyImportsID, CASFileSystemRootID,
bridgingHeaderIncludeTreeID, buildCommandLineArrayID,
bridgingHeaderBuildCommandLineArrayID, chainedBridgingHeaderPathID,
chainedBridgingHeaderContentID);
@@ -669,6 +670,13 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
for (const auto &file : *sourceFiles)
moduleDep.addSourceFile(file);
// Add dependency only imports.
auto depOnlyImports = getStringArray(dependencyOnlyImportsID);
if (!dependencyOnlyImportsID)
llvm::report_fatal_error("Bad dependency only imports");
for (const auto &mod : *depOnlyImports)
moduleDep.addDependencyOnlyImport(mod);
// Add chained bridging header.
auto chainedBridgingHeaderPath =
getIdentifier(chainedBridgingHeaderPathID);
@@ -696,14 +704,15 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
unsigned compiledModulePathID, moduleDocPathID, moduleSourceInfoPathID,
headerImportID, definingInterfacePathID, searchPathArrayID,
headerModuleDependenciesArrayID, headerImportsSourceFilesArrayID,
isFramework, isStatic, isBuiltWithCxxInterop, moduleCacheKeyID,
userModuleVersionID;
isFramework, isStatic, isBuiltWithCxxInterop, isResilient,
isStrictMemorySafety, moduleCacheKeyID, userModuleVersionID;
SwiftBinaryModuleDetailsLayout::readRecord(
Scratch, compiledModulePathID, moduleDocPathID,
moduleSourceInfoPathID, headerImportID, definingInterfacePathID,
headerModuleDependenciesArrayID, headerImportsSourceFilesArrayID,
searchPathArrayID, isFramework, isStatic, isBuiltWithCxxInterop,
moduleCacheKeyID, userModuleVersionID);
isResilient, isStrictMemorySafety, moduleCacheKeyID,
userModuleVersionID);
auto compiledModulePath = getIdentifier(compiledModulePathID);
if (!compiledModulePath)
@@ -738,7 +747,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath,
importStatements, optionalImportStatements, linkLibraries,
*searchPaths, *headerImport, *definingInterfacePath, isFramework,
isStatic, isBuiltWithCxxInterop, *moduleCacheKey, *userModuleVersion);
isStatic, isBuiltWithCxxInterop, isResilient, isStrictMemorySafety,
*moduleCacheKey, *userModuleVersion);
addCommonDependencyInfo(moduleDep);
addSwiftCommonDependencyInfo(moduleDep);
@@ -1069,6 +1079,7 @@ enum ModuleIdentifierArrayKind : uint8_t {
NonPathCommandLine,
FileDependencies,
VisibleClangModulesFromLookup,
DependencyOnlyImports,
LastArrayKind
};
@@ -1610,7 +1621,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::BuildCommandLine),
getIdentifier(swiftTextDeps->contextHash), swiftTextDeps->isFramework,
swiftTextDeps->isStatic, bridgingHeaderFileId,
swiftTextDeps->isStatic, swiftTextDeps->isStrictMemorySafety,
bridgingHeaderFileId,
getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingSourceFiles),
@@ -1639,6 +1651,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
ModuleIdentifierArrayKind::BridgingSourceFiles),
getIdentifierArrayID(
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies),
getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::DependencyOnlyImports),
getIdentifier(
swiftSourceDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftSourceDeps->textualModuleDetails
@@ -1667,9 +1681,9 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifierArrayID(
moduleID,
ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles),
getSearchPathArrayID(moduleID),
swiftBinDeps->isFramework, swiftBinDeps->isStatic,
swiftBinDeps->isBuiltWithCxxInterop,
getSearchPathArrayID(moduleID), swiftBinDeps->isFramework,
swiftBinDeps->isStatic, swiftBinDeps->isBuiltWithCxxInterop,
swiftBinDeps->isResilient, swiftBinDeps->isStrictMemorySafety,
getIdentifier(swiftBinDeps->moduleCacheKey),
getIdentifier(swiftBinDeps->userModuleVersion));
break;
@@ -1953,6 +1967,9 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
addStringArray(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies,
clangHeaderDependencyNames);
addStringArray(moduleID,
ModuleIdentifierArrayKind::DependencyOnlyImports,
dependencyInfo->getDependencyOnlyImports());
addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
swiftSourceDeps->textualModuleDetails.buildCommandLine);
addStringArray(