[Dependency Scanning] Add Link Libraries to the dependency scanner cache serialization format

This commit is contained in:
Artem Chikin
2024-12-03 10:51:42 -08:00
parent a46e33143a
commit 6fdb788b7e
5 changed files with 400 additions and 241 deletions

View File

@@ -73,6 +73,7 @@ using FileIDArrayIDField = IdentifierIDField;
using ContextHashIDField = IdentifierIDField; using ContextHashIDField = IdentifierIDField;
using ModuleCacheKeyIDField = IdentifierIDField; using ModuleCacheKeyIDField = IdentifierIDField;
using ImportArrayIDField = IdentifierIDField; using ImportArrayIDField = IdentifierIDField;
using LinkLibrariesArrayIDField = IdentifierIDField;
using FlagIDArrayIDField = IdentifierIDField; using FlagIDArrayIDField = IdentifierIDField;
using DependencyIDArrayIDField = IdentifierIDField; using DependencyIDArrayIDField = IdentifierIDField;
using AuxiliaryFilesArrayIDField = IdentifierIDField; using AuxiliaryFilesArrayIDField = IdentifierIDField;
@@ -85,12 +86,15 @@ const unsigned GRAPH_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
/// zero or more IDENTIFIER records that contain various strings seen in the graph /// zero or more IDENTIFIER records that contain various strings seen in the graph
/// (e.g. file names or compiler flags), followed by zero or more IDENTIFIER_ARRAY records /// (e.g. file names or compiler flags), followed by zero or more IDENTIFIER_ARRAY records
/// which are arrays of identifiers seen in the graph (e.g. list of source files or list of compile flags), /// which are arrays of identifiers seen in the graph (e.g. list of source files or list of compile flags),
/// followed by zero or more LINK_LIBRARY_NODE records along with associated
///
/// followed by zero or more MODULE_NODE, *_DETAILS_NODE pairs of records. /// followed by zero or more MODULE_NODE, *_DETAILS_NODE pairs of records.
namespace graph_block { namespace graph_block {
enum { enum {
METADATA = 1, METADATA = 1,
MODULE_NODE, MODULE_NODE,
LINK_LIBRARY_NODE, LINK_LIBRARY_NODE,
LINK_LIBRARY_ARRAY_NODE,
SOURCE_LOCATION_NODE, SOURCE_LOCATION_NODE,
IMPORT_STATEMENT_NODE, IMPORT_STATEMENT_NODE,
SWIFT_INTERFACE_MODULE_DETAILS_NODE, SWIFT_INTERFACE_MODULE_DETAILS_NODE,
@@ -129,6 +133,9 @@ using IdentifierNodeLayout = BCRecordLayout<IDENTIFIER_NODE, BCBlob>;
using IdentifierArrayLayout = using IdentifierArrayLayout =
BCRecordLayout<IDENTIFIER_ARRAY_NODE, IdentifierIDArryField>; BCRecordLayout<IDENTIFIER_ARRAY_NODE, IdentifierIDArryField>;
using LinkLibraryArrayLayout =
BCRecordLayout<LINK_LIBRARY_ARRAY_NODE, IdentifierIDArryField>;
using LinkLibraryLayout = using LinkLibraryLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID BCRecordLayout<LINK_LIBRARY_NODE, // ID
IdentifierIDField, // libraryName IdentifierIDField, // libraryName
@@ -157,12 +164,11 @@ using ImportStatementLayout =
// - SwiftPlaceholderModuleDetails // - SwiftPlaceholderModuleDetails
// - ClangModuleDetails // - ClangModuleDetails
using ModuleInfoLayout = using ModuleInfoLayout =
BCRecordLayout<MODULE_NODE, // ID BCRecordLayout<MODULE_NODE, // ID
IdentifierIDField, // moduleName IdentifierIDField, // moduleName
ContextHashIDField, // contextHash ImportArrayIDField, // moduleImports
ImportArrayIDField, // moduleImports ImportArrayIDField, // optionalModuleImports
ImportArrayIDField, // optionalModuleImports LinkLibrariesArrayIDField, // linkLibraries
// ACTODO: LinkLibrariesArrayIDField, // linkLibraries
DependencyIDArrayIDField, // importedSwiftModules DependencyIDArrayIDField, // importedSwiftModules
DependencyIDArrayIDField, // importedClangModules DependencyIDArrayIDField, // importedClangModules
DependencyIDArrayIDField, // crossImportOverlayModules DependencyIDArrayIDField, // crossImportOverlayModules
@@ -211,6 +217,7 @@ using SwiftBinaryModuleDetailsLayout =
FileIDField, // moduleDocPath FileIDField, // moduleDocPath
FileIDField, // moduleSourceInfoPath FileIDField, // moduleSourceInfoPath
FileIDField, // headerImport FileIDField, // headerImport
FileIDField, // definingInterfacePath
IdentifierIDField, // headerModuleDependencies IdentifierIDField, // headerModuleDependencies
FileIDArrayIDField, // headerSourceFiles FileIDArrayIDField, // headerSourceFiles
IsFrameworkField, // isFramework IsFrameworkField, // isFramework

View File

@@ -44,16 +44,17 @@ bool ModuleDependencyInfo::isTextualSwiftModule() const {
return isSwiftInterfaceModule() || isSwiftSourceModule(); return isSwiftInterfaceModule() || isSwiftSourceModule();
} }
ModuleDependencyKind &operator++(ModuleDependencyKind &e) { namespace {
if (e == ModuleDependencyKind::LastKind) { ModuleDependencyKind &operator++(ModuleDependencyKind &e) {
llvm_unreachable( if (e == ModuleDependencyKind::LastKind) {
"Attempting to increment last enum value on ModuleDependencyKind"); llvm_unreachable(
"Attempting to increment last enum value on ModuleDependencyKind");
}
e = ModuleDependencyKind(
static_cast<std::underlying_type<ModuleDependencyKind>::type>(e) + 1);
return e;
} }
e = ModuleDependencyKind(
static_cast<std::underlying_type<ModuleDependencyKind>::type>(e) + 1);
return e;
} }
bool ModuleDependencyInfo::isSwiftInterfaceModule() const { bool ModuleDependencyInfo::isSwiftInterfaceModule() const {
return isa<SwiftInterfaceModuleDependenciesStorage>(storage.get()); return isa<SwiftInterfaceModuleDependenciesStorage>(storage.get());
} }

View File

@@ -24,12 +24,26 @@ using namespace swift;
using namespace dependencies; using namespace dependencies;
using namespace module_dependency_cache_serialization; using namespace module_dependency_cache_serialization;
namespace {
ModuleDependencyKind &operator++(ModuleDependencyKind &e) {
if (e == ModuleDependencyKind::LastKind) {
llvm_unreachable(
"Attempting to increment last enum value on ModuleDependencyKind");
}
e = ModuleDependencyKind(
static_cast<std::underlying_type<ModuleDependencyKind>::type>(e) + 1);
return e;
}
}
// MARK: Deserialization // MARK: Deserialization
namespace swift { namespace swift {
class ModuleDependenciesCacheDeserializer { class ModuleDependenciesCacheDeserializer {
std::vector<std::string> Identifiers; std::vector<std::string> Identifiers;
std::vector<std::vector<uint64_t>> ArraysOfIdentifierIDs; std::vector<std::vector<uint64_t>> ArraysOfIdentifierIDs;
std::vector<LinkLibrary> LinkLibraries;
std::vector<std::vector<uint64_t>> ArraysOfLinkLibraryIDs;
llvm::BitstreamCursor Cursor; llvm::BitstreamCursor Cursor;
SmallVector<uint64_t, 64> Scratch; SmallVector<uint64_t, 64> Scratch;
StringRef BlobData; StringRef BlobData;
@@ -38,10 +52,12 @@ class ModuleDependenciesCacheDeserializer {
bool readSignature(); bool readSignature();
bool enterGraphBlock(); bool enterGraphBlock();
bool readMetadata(); bool readMetadata();
bool readLinkLibraries();
bool readGraph(ModuleDependenciesCache &cache); bool readGraph(ModuleDependenciesCache &cache);
std::optional<std::string> getIdentifier(unsigned n); std::optional<std::string> getIdentifier(unsigned n);
std::optional<std::vector<std::string>> getStringArray(unsigned n); std::optional<std::vector<std::string>> getStringArray(unsigned n);
std::optional<std::vector<LinkLibrary>> getLinkLibraryArray(unsigned n);
std::optional<std::vector<ModuleDependencyID>> std::optional<std::vector<ModuleDependencyID>>
getModuleDependencyIDArray(unsigned n); getModuleDependencyIDArray(unsigned n);
@@ -155,7 +171,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
bool hasCurrentModule = false; bool hasCurrentModule = false;
std::string currentModuleName; std::string currentModuleName;
unsigned currentContextHashID;
std::vector<ScannerImportStatementInfo> currentModuleImports; std::vector<ScannerImportStatementInfo> currentModuleImports;
std::vector<ScannerImportStatementInfo> currentOptionalModuleImports; std::vector<ScannerImportStatementInfo> currentOptionalModuleImports;
@@ -163,6 +178,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
std::vector<ModuleDependencyID> importedClangDependenciesIDs; std::vector<ModuleDependencyID> importedClangDependenciesIDs;
std::vector<ModuleDependencyID> crossImportOverlayDependenciesIDs; std::vector<ModuleDependencyID> crossImportOverlayDependenciesIDs;
std::vector<ModuleDependencyID> swiftOverlayDependenciesIDs; std::vector<ModuleDependencyID> swiftOverlayDependenciesIDs;
std::vector<LinkLibrary> linkLibraries;
std::vector<std::string> auxiliaryFiles; std::vector<std::string> auxiliaryFiles;
while (!Cursor.AtEndOfStream()) { while (!Cursor.AtEndOfStream()) {
@@ -208,18 +224,44 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
break; break;
} }
case LINK_LIBRARY_NODE: {
unsigned libraryIdentifierID;
bool isFramework, shouldForceLoad;
LinkLibraryLayout::readRecord(Scratch,
libraryIdentifierID,
isFramework, shouldForceLoad);
auto libraryIdentifier = getIdentifier(libraryIdentifierID);
if (!libraryIdentifier)
llvm::report_fatal_error("Bad link library identifier");
LinkLibraries.push_back(LinkLibrary(libraryIdentifier.value(),
isFramework ? LibraryKind::Framework : LibraryKind::Library,
shouldForceLoad));
break;
}
case LINK_LIBRARY_ARRAY_NODE: {
ArrayRef<uint64_t> identifierIDs;
LinkLibraryArrayLayout::readRecord(Scratch, identifierIDs);
ArraysOfLinkLibraryIDs.push_back(identifierIDs.vec());
break;
}
case MODULE_NODE: { case MODULE_NODE: {
hasCurrentModule = true; hasCurrentModule = true;
unsigned moduleNameID, contextHashID, unsigned moduleNameID,
moduleImportsArrayID, optionalModuleImportsArrayID, moduleImportsArrayID, optionalModuleImportsArrayID,
linkLibraryArrayID,
importedSwiftDependenciesIDsArrayID, importedSwiftDependenciesIDsArrayID,
importedClangDependenciesIDsArrayID, importedClangDependenciesIDsArrayID,
crossImportOverlayDependenciesIDsArrayID, crossImportOverlayDependenciesIDsArrayID,
swiftOverlayDependenciesIDsArrayID, swiftOverlayDependenciesIDsArrayID,
moduleCacheKeyID, AuxiliaryFilesArrayID; moduleCacheKeyID, AuxiliaryFilesArrayID;
ModuleInfoLayout::readRecord(Scratch, moduleNameID, contextHashID,
ModuleInfoLayout::readRecord(Scratch, moduleNameID,
moduleImportsArrayID, moduleImportsArrayID,
optionalModuleImportsArrayID, optionalModuleImportsArrayID,
linkLibraryArrayID,
importedSwiftDependenciesIDsArrayID, importedSwiftDependenciesIDsArrayID,
importedClangDependenciesIDsArrayID, importedClangDependenciesIDsArrayID,
crossImportOverlayDependenciesIDsArrayID, crossImportOverlayDependenciesIDsArrayID,
@@ -229,10 +271,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
if (!moduleName) if (!moduleName)
llvm::report_fatal_error("Bad module name"); llvm::report_fatal_error("Bad module name");
currentModuleName = *moduleName; currentModuleName = *moduleName;
currentContextHashID = contextHashID;
auto importStrings = getStringArray(moduleImportsArrayID); auto importStrings = getStringArray(moduleImportsArrayID);
auto optionalImportStrings = getStringArray(optionalModuleImportsArrayID); auto optionalImportStrings = getStringArray(optionalModuleImportsArrayID);
// ACTODO: Proper import infos.
currentModuleImports.clear();
currentOptionalModuleImports.clear();
if (importStrings.has_value()) if (importStrings.has_value())
for (const auto &is : importStrings.value()) for (const auto &is : importStrings.value())
currentModuleImports.push_back(is); currentModuleImports.push_back(is);
@@ -264,6 +307,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
if (!optionalSwiftOverlayDependenciesIDs) if (!optionalSwiftOverlayDependenciesIDs)
llvm::report_fatal_error("Bad Swift Overlay dependencies: no qualified dependencies"); llvm::report_fatal_error("Bad Swift Overlay dependencies: no qualified dependencies");
swiftOverlayDependenciesIDs = optionalSwiftOverlayDependenciesIDs.value(); swiftOverlayDependenciesIDs = optionalSwiftOverlayDependenciesIDs.value();
auto optionalLinkLibraries = getLinkLibraryArray(linkLibraryArrayID);
if (!optionalLinkLibraries)
llvm::report_fatal_error("Bad Link Libraries info");
linkLibraries = *optionalLinkLibraries;
break; break;
} }
@@ -330,11 +378,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
if (!userModuleVersion) if (!userModuleVersion)
llvm::report_fatal_error("Bad userModuleVersion"); llvm::report_fatal_error("Bad userModuleVersion");
// TODO: LinkLibraries, MacroDependencies // TODO: MacroDependencies
// Form the dependencies storage object // Form the dependencies storage object
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule( auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
outputModulePath.value(), optionalSwiftInterfaceFile.value(), outputModulePath.value(), optionalSwiftInterfaceFile.value(),
compiledCandidatesRefs, buildCommandRefs, {}, extraPCMRefs, compiledCandidatesRefs, buildCommandRefs, linkLibraries, extraPCMRefs,
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey, *contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey,
*userModuleVersion); *userModuleVersion);
@@ -403,11 +451,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
if (!hasCurrentModule) if (!hasCurrentModule)
llvm::report_fatal_error( llvm::report_fatal_error(
"Unexpected SWIFT_SOURCE_MODULE_DETAILS_NODE record"); "Unexpected SWIFT_SOURCE_MODULE_DETAILS_NODE record");
// Expected context hash ID is 0
if (currentContextHashID)
llvm::report_fatal_error(
"Unexpected context hash on MODULE_NODE corresponding to a "
"SWIFT_SOURCE_MODULE_DETAILS_NODE record");
unsigned extraPCMArgsArrayID, bridgingHeaderFileID, sourceFilesArrayID, unsigned extraPCMArgsArrayID, bridgingHeaderFileID, sourceFilesArrayID,
bridgingSourceFilesArrayID, bridgingModuleDependenciesArrayID, bridgingSourceFilesArrayID, bridgingModuleDependenciesArrayID,
CASFileSystemRootID, CASFileSystemRootID,
@@ -514,16 +557,15 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
llvm::report_fatal_error( llvm::report_fatal_error(
"Unexpected SWIFT_BINARY_MODULE_DETAILS_NODE record"); "Unexpected SWIFT_BINARY_MODULE_DETAILS_NODE record");
unsigned compiledModulePathID, moduleDocPathID, moduleSourceInfoPathID, unsigned compiledModulePathID, moduleDocPathID, moduleSourceInfoPathID,
headerImportID, headerImportID, definingInterfacePathID,
headerModuleDependenciesArrayID, headerModuleDependenciesArrayID,
headerImportsSourceFilesArrayID, isFramework, isStatic, headerImportsSourceFilesArrayID, isFramework, isStatic,
moduleCacheKeyID, userModuleVersionID; moduleCacheKeyID, userModuleVersionID;
SwiftBinaryModuleDetailsLayout::readRecord( SwiftBinaryModuleDetailsLayout::readRecord(
Scratch, compiledModulePathID, moduleDocPathID, Scratch, compiledModulePathID, moduleDocPathID,
moduleSourceInfoPathID, moduleSourceInfoPathID, headerImportID, definingInterfacePathID,
headerImportID, headerModuleDependenciesArrayID, headerModuleDependenciesArrayID, headerImportsSourceFilesArrayID,
headerImportsSourceFilesArrayID, isFramework, isStatic, isFramework, isStatic, moduleCacheKeyID, userModuleVersionID);
moduleCacheKeyID, userModuleVersionID);
auto compiledModulePath = getIdentifier(compiledModulePathID); auto compiledModulePath = getIdentifier(compiledModulePathID);
if (!compiledModulePath) if (!compiledModulePath)
@@ -543,13 +585,16 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
auto headerImport = getIdentifier(headerImportID); auto headerImport = getIdentifier(headerImportID);
if (!headerImport) if (!headerImport)
llvm::report_fatal_error("Bad binary direct dependencies: no header import"); llvm::report_fatal_error("Bad binary direct dependencies: no header import");
auto definingInterfacePath = getIdentifier(definingInterfacePathID);
if (!definingInterfacePath)
llvm::report_fatal_error("Bad binary direct dependencies: no defining interface path");
// TODO: LinkLibraries, DefiningModulePath
// Form the dependencies storage object // Form the dependencies storage object
auto moduleDep = ModuleDependencyInfo::forSwiftBinaryModule( auto moduleDep = ModuleDependencyInfo::forSwiftBinaryModule(
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath, *compiledModulePath, *moduleDocPath, *moduleSourceInfoPath,
currentModuleImports, currentOptionalModuleImports, {}, currentModuleImports, currentOptionalModuleImports, linkLibraries,
*headerImport, "", isFramework, isStatic, *moduleCacheKey, *userModuleVersion); *headerImport, *definingInterfacePath, isFramework, isStatic,
*moduleCacheKey, *userModuleVersion);
// Add imports of this module // Add imports of this module
for (const auto &moduleName : currentModuleImports) for (const auto &moduleName : currentModuleImports)
@@ -665,11 +710,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
if (!moduleCacheKey) if (!moduleCacheKey)
llvm::report_fatal_error("Bad moduleCacheKey"); llvm::report_fatal_error("Bad moduleCacheKey");
// TODO: LinkLibraries
// Form the dependencies storage object // Form the dependencies storage object
auto moduleDep = ModuleDependencyInfo::forClangModule( auto moduleDep = ModuleDependencyInfo::forClangModule(
*pcmOutputPath, *mappedPCMPath, *moduleMapPath, *contextHash, *pcmOutputPath, *mappedPCMPath, *moduleMapPath, *contextHash,
*commandLineArgs, *fileDependencies, *capturedPCMArgs, {}, *commandLineArgs, *fileDependencies, *capturedPCMArgs, linkLibraries,
*rootFileSystemID, *clangIncludeTreeRoot, *moduleCacheKey, isSystem); *rootFileSystemID, *clangIncludeTreeRoot, *moduleCacheKey, isSystem);
// Add imports of this module // Add imports of this module
@@ -747,6 +791,27 @@ ModuleDependenciesCacheDeserializer::getStringArray(unsigned n) {
return result; return result;
} }
std::optional<std::vector<LinkLibrary>>
ModuleDependenciesCacheDeserializer::getLinkLibraryArray(unsigned n) {
if (n == 0)
return std::vector<LinkLibrary>();
--n;
if (n >= ArraysOfLinkLibraryIDs.size())
return std::nullopt;
auto &llIDs = ArraysOfLinkLibraryIDs[n];
auto IDtoLLMap = [this](unsigned index) {
return LinkLibraries[index];
};
std::vector<LinkLibrary> result;
result.reserve(llIDs.size());
std::transform(llIDs.begin(), llIDs.end(),
std::back_inserter(result), IDtoLLMap);
return result;
}
std::optional<std::vector<ModuleDependencyID>> std::optional<std::vector<ModuleDependencyID>>
ModuleDependenciesCacheDeserializer::getModuleDependencyIDArray(unsigned n) { ModuleDependenciesCacheDeserializer::getModuleDependencyIDArray(unsigned n) {
auto encodedIdentifierStringArray = getStringArray(n); auto encodedIdentifierStringArray = getStringArray(n);
@@ -806,7 +871,6 @@ enum ModuleIdentifierArrayKind : uint8_t {
Empty = 0, Empty = 0,
DependencyImports, DependencyImports,
OptionalDependencyImports, OptionalDependencyImports,
DependencyHeaders,
ImportedSwiftDependenciesIDs, ImportedSwiftDependenciesIDs,
ImportedClangDependenciesIDs, ImportedClangDependenciesIDs,
CrossImportOverlayDependenciesIDs, CrossImportOverlayDependenciesIDs,
@@ -858,12 +922,16 @@ class ModuleDependenciesCacheSerializer {
llvm::StringMap<unsigned, llvm::BumpPtrAllocator> IdentifierIDs; llvm::StringMap<unsigned, llvm::BumpPtrAllocator> IdentifierIDs;
std::unordered_map<ModuleDependencyID, std::unordered_map<ModuleDependencyID,
llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>> llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>>
ArrayIDs; IdentifierArrayIDsMap;
unsigned LastIdentifierID = 0; unsigned LastIdentifierID = 0;
unsigned LastArrayID = 0; unsigned LastIdentifierArrayID = 0;
std::vector<StringRef> Identifiers; std::vector<StringRef> Identifiers;
std::vector<std::vector<unsigned>> ArraysOfIdentifiers; std::vector<std::vector<unsigned>> ArraysOfIdentifiers;
std::unordered_map<ModuleDependencyID,
unsigned>
LinkLibraryArrayIDsMap;
llvm::BitstreamWriter &Out; llvm::BitstreamWriter &Out;
/// A reusable buffer for emitting records. /// A reusable buffer for emitting records.
@@ -882,8 +950,9 @@ class ModuleDependenciesCacheSerializer {
void addDependencyIDArray(ModuleDependencyID moduleID, void addDependencyIDArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind, ModuleIdentifierArrayKind arrayKind,
const ArrayRef<ModuleDependencyID> vec); const ArrayRef<ModuleDependencyID> vec);
unsigned getArrayID(ModuleDependencyID moduleID, unsigned getIdentifierArrayID(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const; ModuleIdentifierArrayKind arrayKind) const;
unsigned getLinkLibrariesArrayID(ModuleDependencyID moduleID) const;
template <typename Layout> template <typename Layout>
void registerRecordAbbr() { void registerRecordAbbr() {
@@ -908,6 +977,11 @@ class ModuleDependenciesCacheSerializer {
void writeIdentifiers(); void writeIdentifiers();
void writeArraysOfIdentifiers(); void writeArraysOfIdentifiers();
void writeLinkLibraries(const ModuleDependenciesCache &cache);
unsigned writeLinkLibraryInfos(ModuleDependencyID moduleID,
const ModuleDependencyInfo &dependencyInfo);
void writeLinkLibraryInfoArray(unsigned startIndex, unsigned count);
void writeModuleInfo(ModuleDependencyID moduleID, void writeModuleInfo(ModuleDependencyID moduleID,
const ModuleDependencyInfo &dependencyInfo); const ModuleDependencyInfo &dependencyInfo);
@@ -958,6 +1032,8 @@ void ModuleDependenciesCacheSerializer::writeBlockInfoBlock() {
BLOCK_RECORD(graph_block, IDENTIFIER_NODE); BLOCK_RECORD(graph_block, IDENTIFIER_NODE);
BLOCK_RECORD(graph_block, IDENTIFIER_ARRAY_NODE); BLOCK_RECORD(graph_block, IDENTIFIER_ARRAY_NODE);
BLOCK_RECORD(graph_block, LINK_LIBRARY_NODE);
BLOCK_RECORD(graph_block, LINK_LIBRARY_ARRAY_NODE);
BLOCK_RECORD(graph_block, MODULE_NODE); BLOCK_RECORD(graph_block, MODULE_NODE);
BLOCK_RECORD(graph_block, SWIFT_INTERFACE_MODULE_DETAILS_NODE); BLOCK_RECORD(graph_block, SWIFT_INTERFACE_MODULE_DETAILS_NODE);
BLOCK_RECORD(graph_block, SWIFT_SOURCE_MODULE_DETAILS_NODE); BLOCK_RECORD(graph_block, SWIFT_SOURCE_MODULE_DETAILS_NODE);
@@ -997,24 +1073,77 @@ void ModuleDependenciesCacheSerializer::writeArraysOfIdentifiers() {
} }
} }
void ModuleDependenciesCacheSerializer::writeLinkLibraries(const ModuleDependenciesCache &cache) {
unsigned lastLLIndex = 0;
std::map<ModuleDependencyID, std::pair<unsigned, unsigned>> moduleLLArrayMap;
for (auto kind = ModuleDependencyKind::FirstKind;
kind != ModuleDependencyKind::LastKind; ++kind) {
auto modMap = cache.getDependenciesMap(kind);
for (const auto &entry : modMap) {
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
auto optionalDependencyInfo = cache.findDependency(moduleID);
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
auto dependencyInfo = optionalDependencyInfo.value();
unsigned numLLs = writeLinkLibraryInfos(moduleID, *dependencyInfo);
moduleLLArrayMap.insert({moduleID, std::make_pair(lastLLIndex, numLLs)});
lastLLIndex += numLLs;
}
}
unsigned lastLLArrayIndex = 1;
for (auto kind = ModuleDependencyKind::FirstKind;
kind != ModuleDependencyKind::LastKind; ++kind) {
auto modMap = cache.getDependenciesMap(kind);
for (const auto &entry : modMap) {
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
auto entries = moduleLLArrayMap.at(moduleID);
if (entries.second == 0)
continue;
writeLinkLibraryInfoArray(entries.first, entries.second);
LinkLibraryArrayIDsMap.insert({moduleID, lastLLArrayIndex++});
}
}
}
unsigned ModuleDependenciesCacheSerializer::writeLinkLibraryInfos(
ModuleDependencyID moduleID,
const ModuleDependencyInfo &dependencyInfo) {
using namespace graph_block;
for (auto &linkLibrary : dependencyInfo.getLinkLibraries()) {
LinkLibraryLayout::emitRecord(Out, ScratchRecord, AbbrCodes[LinkLibraryLayout::Code],
getIdentifier(linkLibrary.getName().str()),
linkLibrary.getKind() == LibraryKind::Framework,
linkLibrary.shouldForceLoad());
}
return dependencyInfo.getLinkLibraries().size();
}
void ModuleDependenciesCacheSerializer::writeLinkLibraryInfoArray(
unsigned startIndex, unsigned count) {
using namespace graph_block;
std::vector<unsigned> vec(count);
std::iota(vec.begin(), vec.end(), startIndex);
LinkLibraryArrayLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[LinkLibraryArrayLayout::Code], vec);
}
void ModuleDependenciesCacheSerializer::writeModuleInfo( void ModuleDependenciesCacheSerializer::writeModuleInfo(
ModuleDependencyID moduleID, ModuleDependencyID moduleID,
const ModuleDependencyInfo &dependencyInfo) { const ModuleDependencyInfo &dependencyInfo) {
using namespace graph_block; using namespace graph_block;
// TODO: Eliminate per-module context hash
auto contextHashStrID = 0;
ModuleInfoLayout::emitRecord( ModuleInfoLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[ModuleInfoLayout::Code], Out, ScratchRecord, AbbrCodes[ModuleInfoLayout::Code],
getIdentifier(moduleID.ModuleName), contextHashStrID, getIdentifier(moduleID.ModuleName),
getArrayID(moduleID, ModuleIdentifierArrayKind::DependencyImports), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::DependencyImports),
getArrayID(moduleID, ModuleIdentifierArrayKind::OptionalDependencyImports), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::OptionalDependencyImports),
getArrayID(moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs), getLinkLibrariesArrayID(moduleID),
getArrayID(moduleID, ModuleIdentifierArrayKind::ImportedClangDependenciesIDs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::ImportedClangDependenciesIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs),
getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs),
getIdentifier(dependencyInfo.getModuleCacheKey()), getIdentifier(dependencyInfo.getModuleCacheKey()),
getArrayID(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs)); getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs));
switch (dependencyInfo.getKind()) { switch (dependencyInfo.getKind()) {
case swift::ModuleDependencyKind::SwiftInterface: { case swift::ModuleDependencyKind::SwiftInterface: {
@@ -1032,16 +1161,16 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
SwiftInterfaceModuleDetailsLayout::emitRecord( SwiftInterfaceModuleDetailsLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code], Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code],
outputModulePathFileId, swiftInterfaceFileId, outputModulePathFileId, swiftInterfaceFileId,
getArrayID(moduleID, getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::CompiledModuleCandidates), ModuleIdentifierArrayKind::CompiledModuleCandidates),
getArrayID(moduleID, ModuleIdentifierArrayKind::BuildCommandLine), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::BuildCommandLine),
getArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
getIdentifier(swiftTextDeps->contextHash), getIdentifier(swiftTextDeps->contextHash),
swiftTextDeps->isFramework, swiftTextDeps->isStatic, swiftTextDeps->isFramework, swiftTextDeps->isStatic,
bridgingHeaderFileId, bridgingHeaderFileId,
getArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID, getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies), ModuleIdentifierArrayKind::BridgingModuleDependencies),
getIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID), getIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftTextDeps->textualModuleDetails getIdentifier(swiftTextDeps->textualModuleDetails
@@ -1060,18 +1189,18 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
: 0; : 0;
SwiftSourceModuleDetailsLayout::emitRecord( SwiftSourceModuleDetailsLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code], Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code],
getArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
bridgingHeaderFileId, bridgingHeaderFileId,
getArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID, getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies), ModuleIdentifierArrayKind::BridgingModuleDependencies),
getIdentifier( getIdentifier(
swiftSourceDeps->textualModuleDetails.CASFileSystemRootID), swiftSourceDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftSourceDeps->textualModuleDetails getIdentifier(swiftSourceDeps->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID), .CASBridgingHeaderIncludeTreeRootID),
getArrayID(moduleID, ModuleIdentifierArrayKind::BuildCommandLine), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::BuildCommandLine),
getArrayID(moduleID, getIdentifierArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingHeaderBuildCommandLine)); ModuleIdentifierArrayKind::BridgingHeaderBuildCommandLine));
break; break;
} }
@@ -1083,9 +1212,10 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifier(swiftBinDeps->compiledModulePath), getIdentifier(swiftBinDeps->compiledModulePath),
getIdentifier(swiftBinDeps->moduleDocPath), getIdentifier(swiftBinDeps->moduleDocPath),
getIdentifier(swiftBinDeps->sourceInfoPath), getIdentifier(swiftBinDeps->sourceInfoPath),
getArrayID(moduleID, ModuleIdentifierArrayKind::DependencyHeaders), getIdentifier(swiftBinDeps->headerImport),
getArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputModuleDependencies), getIdentifier(swiftBinDeps->definingModuleInterfacePath),
getArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputModuleDependencies),
getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles),
swiftBinDeps->isFramework, swiftBinDeps->isStatic, swiftBinDeps->isFramework, swiftBinDeps->isStatic,
getIdentifier(swiftBinDeps->moduleCacheKey), getIdentifier(swiftBinDeps->moduleCacheKey),
getIdentifier(swiftBinDeps->userModuleVersion)); getIdentifier(swiftBinDeps->userModuleVersion));
@@ -1112,9 +1242,9 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifier(clangDeps->mappedPCMPath), getIdentifier(clangDeps->mappedPCMPath),
getIdentifier(clangDeps->moduleMapFile), getIdentifier(clangDeps->moduleMapFile),
getIdentifier(clangDeps->contextHash), getIdentifier(clangDeps->contextHash),
getArrayID(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine),
getArrayID(moduleID, ModuleIdentifierArrayKind::FileDependencies), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::FileDependencies),
getArrayID(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs), getIdentifierArrayID(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs),
getIdentifier(clangDeps->CASFileSystemRootID), getIdentifier(clangDeps->CASFileSystemRootID),
getIdentifier(clangDeps->CASClangIncludeTreeRootID), getIdentifier(clangDeps->CASClangIncludeTreeRootID),
getIdentifier(clangDeps->moduleCacheKey), clangDeps->IsSystem); getIdentifier(clangDeps->moduleCacheKey), clangDeps->IsSystem);
@@ -1166,21 +1296,21 @@ void ModuleDependenciesCacheSerializer::addDependencyIDArray(ModuleDependencyID
void ModuleDependenciesCacheSerializer::addStringArray(ModuleDependencyID moduleID, void ModuleDependenciesCacheSerializer::addStringArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind, ModuleIdentifierArrayKind arrayKind,
const std::vector<std::string> &vec) { const std::vector<std::string> &vec) {
if (ArrayIDs.find(moduleID) != ArrayIDs.end()) { if (IdentifierArrayIDsMap.find(moduleID) != IdentifierArrayIDsMap.end()) {
// Already have arrays for this module // Already have arrays for this module
llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>::iterator iter; llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>::iterator iter;
bool isNew; bool isNew;
std::tie(iter, isNew) = std::tie(iter, isNew) =
ArrayIDs[moduleID].insert({arrayKind, LastArrayID + 1}); IdentifierArrayIDsMap[moduleID].insert({arrayKind, LastIdentifierArrayID + 1});
if (!isNew) if (!isNew)
return; return;
} else { } else {
// Do not yet have any arrays for this module // Do not yet have any arrays for this module
ArrayIDs[moduleID] = llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>(); IdentifierArrayIDsMap[moduleID] = llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>();
ArrayIDs[moduleID].insert({arrayKind, LastArrayID + 1}); IdentifierArrayIDsMap[moduleID].insert({arrayKind, LastIdentifierArrayID + 1});
} }
++LastArrayID; ++LastIdentifierArrayID;
// Add in the individual identifiers in the array // Add in the individual identifiers in the array
std::vector<unsigned> identifierIDs; std::vector<unsigned> identifierIDs;
@@ -1193,178 +1323,185 @@ void ModuleDependenciesCacheSerializer::addStringArray(ModuleDependencyID module
return; return;
} }
unsigned ModuleDependenciesCacheSerializer::getArrayID(ModuleDependencyID moduleID, unsigned ModuleDependenciesCacheSerializer::getIdentifierArrayID(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const { ModuleIdentifierArrayKind arrayKind) const {
auto iter = ArrayIDs.find(moduleID); auto iter = IdentifierArrayIDsMap.find(moduleID);
assert(iter != ArrayIDs.end()); assert(iter != IdentifierArrayIDsMap.end());
auto &innerMap = iter->second; auto &innerMap = iter->second;
auto arrayIter = innerMap.find(arrayKind); auto arrayIter = innerMap.find(arrayKind);
assert(arrayIter != innerMap.end()); assert(arrayIter != innerMap.end());
return arrayIter->second; return arrayIter->second;
} }
unsigned ModuleDependenciesCacheSerializer::getLinkLibrariesArrayID(ModuleDependencyID moduleID) const {
auto iter = LinkLibraryArrayIDsMap.find(moduleID);
if (iter == LinkLibraryArrayIDsMap.end())
return 0;
return iter->second;
}
void ModuleDependenciesCacheSerializer::collectStringsAndArrays( void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
const ModuleDependenciesCache &cache) { const ModuleDependenciesCache &cache) {
addIdentifier(cache.scannerContextHash); addIdentifier(cache.scannerContextHash);
// TODO: Serialize *all* modules for (auto kind = ModuleDependencyKind::FirstKind;
for (auto &moduleID : cache.getAllDependencies({cache.mainScanModuleName, kind != ModuleDependencyKind::LastKind; ++kind) {
ModuleDependencyKind::SwiftSource})) { auto modMap = cache.getDependenciesMap(kind);
auto optionalDependencyInfo = for (const auto &entry : modMap) {
cache.findDependency(moduleID.ModuleName, moduleID.Kind); ModuleDependencyID moduleID = {entry.getKey().str(), kind};
assert(optionalDependencyInfo.has_value() && "Expected dependency info."); auto optionalDependencyInfo = cache.findDependency(moduleID);
auto dependencyInfo = optionalDependencyInfo.value(); assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
// Add the module's name auto dependencyInfo = optionalDependencyInfo.value();
addIdentifier(moduleID.ModuleName); // Add the module's name
addIdentifier(moduleID.ModuleName);
// Map import infos to their respective module identifiers // Map import infos to their respective module identifiers
auto importInfoArrayToIdentifier = auto importInfoArrayToIdentifier =
[](const auto &importInfo) -> std::string { [](const auto &importInfo) -> std::string {
return importInfo.importIdentifier; return importInfo.importIdentifier;
}; };
// Add the module's dependencies for (const auto &ll : dependencyInfo->getLinkLibraries())
std::vector<std::string> importIdentifiers; addIdentifier(ll.getName().str());
llvm::transform(dependencyInfo->getModuleImports(),
std::back_inserter(importIdentifiers),
importInfoArrayToIdentifier);
std::vector<std::string> optionalImportIdentifiers;
llvm::transform(dependencyInfo->getOptionalModuleImports(),
std::back_inserter(optionalImportIdentifiers),
importInfoArrayToIdentifier);
addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports, // Add the module's imports
importIdentifiers); std::vector<std::string> importIdentifiers;
addStringArray(moduleID, ModuleIdentifierArrayKind::OptionalDependencyImports, llvm::transform(dependencyInfo->getModuleImports(),
optionalImportIdentifiers); std::back_inserter(importIdentifiers),
importInfoArrayToIdentifier);
ModuleDependencyIDSetVector allDependencies; std::vector<std::string> optionalImportIdentifiers;
if (dependencyInfo->isSwiftModule()) { llvm::transform(dependencyInfo->getOptionalModuleImports(),
auto swiftImportedDepsRef = dependencyInfo->getImportedSwiftDependencies(); std::back_inserter(optionalImportIdentifiers),
auto headerClangDepsRef = dependencyInfo->getHeaderClangDependencies(); importInfoArrayToIdentifier);
auto overlayDependenciesRef = dependencyInfo->getSwiftOverlayDependencies();
allDependencies.insert(swiftImportedDepsRef.begin(),
swiftImportedDepsRef.end());
allDependencies.insert(headerClangDepsRef.begin(),
headerClangDepsRef.end());
allDependencies.insert(overlayDependenciesRef.begin(),
overlayDependenciesRef.end());
}
if (dependencyInfo->isSwiftSourceModule()) { addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports,
auto crossImportOverlayDepsRef = dependencyInfo->getCrossImportOverlayDependencies(); importIdentifiers);
allDependencies.insert(crossImportOverlayDepsRef.begin(), addStringArray(moduleID, ModuleIdentifierArrayKind::OptionalDependencyImports,
crossImportOverlayDepsRef.end()); optionalImportIdentifiers);
}
auto clangImportedDepsRef = dependencyInfo->getImportedClangDependencies(); addDependencyIDArray(moduleID,
allDependencies.insert(clangImportedDepsRef.begin(), ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs,
clangImportedDepsRef.end()); dependencyInfo->getImportedSwiftDependencies());
addDependencyIDArray(moduleID,
ModuleIdentifierArrayKind::ImportedClangDependenciesIDs,
dependencyInfo->getImportedClangDependencies());
addDependencyIDArray(moduleID,
ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs,
dependencyInfo->getCrossImportOverlayDependencies());
addDependencyIDArray(moduleID,
ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs,
dependencyInfo->getSwiftOverlayDependencies());
std::vector<std::string> clangHeaderDependencyNames; addStringArray(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs,
for (const auto &headerDepID : dependencyInfo->getAuxiliaryFiles());
dependencyInfo->getHeaderClangDependencies())
clangHeaderDependencyNames.push_back(headerDepID.ModuleName);
// Add the dependency-kind-specific data std::vector<std::string> clangHeaderDependencyNames;
switch (dependencyInfo->getKind()) { for (const auto &headerDepID :
case swift::ModuleDependencyKind::SwiftInterface: { dependencyInfo->getHeaderClangDependencies())
auto swiftTextDeps = dependencyInfo->getAsSwiftInterfaceModule(); clangHeaderDependencyNames.push_back(headerDepID.ModuleName);
assert(swiftTextDeps);
addIdentifier(swiftTextDeps->moduleOutputPath); // Add the dependency-kind-specific data
addIdentifier(swiftTextDeps->swiftInterfaceFile); switch (dependencyInfo->getKind()) {
addStringArray(moduleID, case swift::ModuleDependencyKind::SwiftInterface: {
ModuleIdentifierArrayKind::CompiledModuleCandidates, auto swiftTextDeps = dependencyInfo->getAsSwiftInterfaceModule();
swiftTextDeps->compiledModuleCandidates); assert(swiftTextDeps);
addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine, addIdentifier(swiftTextDeps->moduleOutputPath);
swiftTextDeps->textualModuleDetails.buildCommandLine); addIdentifier(swiftTextDeps->swiftInterfaceFile);
addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs, addStringArray(moduleID,
swiftTextDeps->textualModuleDetails.extraPCMArgs); ModuleIdentifierArrayKind::CompiledModuleCandidates,
addIdentifier(swiftTextDeps->contextHash); swiftTextDeps->compiledModuleCandidates);
if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile.has_value()) addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
addIdentifier(swiftTextDeps->textualModuleDetails.bridgingHeaderFile swiftTextDeps->textualModuleDetails.buildCommandLine);
.value()); addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles, swiftTextDeps->textualModuleDetails.extraPCMArgs);
std::vector<std::string>()); addIdentifier(swiftTextDeps->contextHash);
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles, if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile.has_value())
swiftTextDeps->textualModuleDetails.bridgingSourceFiles); addIdentifier(swiftTextDeps->textualModuleDetails.bridgingHeaderFile
addStringArray( .value());
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies, addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
clangHeaderDependencyNames); std::vector<std::string>());
addIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID); addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
addIdentifier(swiftTextDeps->textualModuleDetails swiftTextDeps->textualModuleDetails.bridgingSourceFiles);
.CASBridgingHeaderIncludeTreeRootID); addStringArray(
addIdentifier(swiftTextDeps->moduleCacheKey); moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
break; clangHeaderDependencyNames);
} addIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID);
case swift::ModuleDependencyKind::SwiftBinary: { addIdentifier(swiftTextDeps->textualModuleDetails
auto swiftBinDeps = dependencyInfo->getAsSwiftBinaryModule(); .CASBridgingHeaderIncludeTreeRootID);
assert(swiftBinDeps); addIdentifier(swiftTextDeps->moduleCacheKey);
addIdentifier(swiftBinDeps->compiledModulePath); break;
addIdentifier(swiftBinDeps->moduleDocPath); }
addIdentifier(swiftBinDeps->sourceInfoPath); case swift::ModuleDependencyKind::SwiftBinary: {
addIdentifier(swiftBinDeps->moduleCacheKey); auto swiftBinDeps = dependencyInfo->getAsSwiftBinaryModule();
addIdentifier(swiftBinDeps->headerImport); assert(swiftBinDeps);
addStringArray(moduleID, ModuleIdentifierArrayKind::HeaderInputModuleDependencies, addIdentifier(swiftBinDeps->compiledModulePath);
clangHeaderDependencyNames); addIdentifier(swiftBinDeps->moduleDocPath);
addStringArray(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles, addIdentifier(swiftBinDeps->sourceInfoPath);
swiftBinDeps->headerSourceFiles); addIdentifier(swiftBinDeps->moduleCacheKey);
break; addIdentifier(swiftBinDeps->headerImport);
} addIdentifier(swiftBinDeps->userModuleVersion);
case swift::ModuleDependencyKind::SwiftPlaceholder: { addStringArray(moduleID, ModuleIdentifierArrayKind::HeaderInputModuleDependencies,
auto swiftPHDeps = dependencyInfo->getAsPlaceholderDependencyModule(); clangHeaderDependencyNames);
assert(swiftPHDeps); addStringArray(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles,
addIdentifier(swiftPHDeps->compiledModulePath); swiftBinDeps->headerSourceFiles);
addIdentifier(swiftPHDeps->moduleDocPath); break;
addIdentifier(swiftPHDeps->sourceInfoPath); }
break; case swift::ModuleDependencyKind::SwiftPlaceholder: {
} auto swiftPHDeps = dependencyInfo->getAsPlaceholderDependencyModule();
case swift::ModuleDependencyKind::SwiftSource: { assert(swiftPHDeps);
auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule(); addIdentifier(swiftPHDeps->compiledModulePath);
assert(swiftSourceDeps); addIdentifier(swiftPHDeps->moduleDocPath);
addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs, addIdentifier(swiftPHDeps->sourceInfoPath);
swiftSourceDeps->textualModuleDetails.extraPCMArgs); break;
if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile }
.has_value()) case swift::ModuleDependencyKind::SwiftSource: {
auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule();
assert(swiftSourceDeps);
addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
swiftSourceDeps->textualModuleDetails.extraPCMArgs);
if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile
.has_value())
addIdentifier(
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value());
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
swiftSourceDeps->sourceFiles);
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles);
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
clangHeaderDependencyNames);
addStringArray(
moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
swiftSourceDeps->textualModuleDetails.buildCommandLine);
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingHeaderBuildCommandLine,
swiftSourceDeps->bridgingHeaderBuildCommandLine);
addIdentifier( addIdentifier(
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value()); swiftSourceDeps->textualModuleDetails.CASFileSystemRootID);
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles, break;
swiftSourceDeps->sourceFiles); }
addStringArray( case swift::ModuleDependencyKind::Clang: {
moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles, auto clangDeps = dependencyInfo->getAsClangModule();
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles); assert(clangDeps);
addStringArray( addIdentifier(clangDeps->pcmOutputPath);
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies, addIdentifier(clangDeps->mappedPCMPath);
clangHeaderDependencyNames); addIdentifier(clangDeps->moduleMapFile);
addStringArray( addIdentifier(clangDeps->contextHash);
moduleID, ModuleIdentifierArrayKind::BuildCommandLine, addStringArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine,
swiftSourceDeps->textualModuleDetails.buildCommandLine); clangDeps->buildCommandLine);
addStringArray( addStringArray(moduleID, ModuleIdentifierArrayKind::FileDependencies,
moduleID, ModuleIdentifierArrayKind::BridgingHeaderBuildCommandLine, clangDeps->fileDependencies);
swiftSourceDeps->bridgingHeaderBuildCommandLine); addStringArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs,
addIdentifier( clangDeps->capturedPCMArgs);
swiftSourceDeps->textualModuleDetails.CASFileSystemRootID); addIdentifier(clangDeps->CASFileSystemRootID);
break; addIdentifier(clangDeps->CASClangIncludeTreeRootID);
} addIdentifier(clangDeps->moduleCacheKey);
case swift::ModuleDependencyKind::Clang: { break;
auto clangDeps = dependencyInfo->getAsClangModule(); }
assert(clangDeps); default:
addIdentifier(clangDeps->pcmOutputPath); llvm_unreachable("Unhandled dependency kind.");
addIdentifier(clangDeps->mappedPCMPath); }
addIdentifier(clangDeps->moduleMapFile);
addIdentifier(clangDeps->contextHash);
addStringArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine,
clangDeps->buildCommandLine);
addStringArray(moduleID, ModuleIdentifierArrayKind::FileDependencies,
clangDeps->fileDependencies);
addStringArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs,
clangDeps->capturedPCMArgs);
addIdentifier(clangDeps->CASFileSystemRootID);
addIdentifier(clangDeps->CASClangIncludeTreeRootID);
addIdentifier(clangDeps->moduleCacheKey);
break;
}
default:
llvm_unreachable("Unhandled dependency kind.");
} }
} }
} }
@@ -1385,8 +1522,9 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
registerRecordAbbr<IdentifierNodeLayout>(); registerRecordAbbr<IdentifierNodeLayout>();
registerRecordAbbr<IdentifierArrayLayout>(); registerRecordAbbr<IdentifierArrayLayout>();
registerRecordAbbr<LinkLibraryLayout>(); registerRecordAbbr<LinkLibraryLayout>();
registerRecordAbbr<SourceLocationLayout>(); registerRecordAbbr<LinkLibraryArrayLayout>();
registerRecordAbbr<ImportStatementLayout>(); // registerRecordAbbr<SourceLocationLayout>();
// registerRecordAbbr<ImportStatementLayout>();
registerRecordAbbr<ModuleInfoLayout>(); registerRecordAbbr<ModuleInfoLayout>();
registerRecordAbbr<SwiftSourceModuleDetailsLayout>(); registerRecordAbbr<SwiftSourceModuleDetailsLayout>();
registerRecordAbbr<SwiftInterfaceModuleDetailsLayout>(); registerRecordAbbr<SwiftInterfaceModuleDetailsLayout>();
@@ -1407,13 +1545,16 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
// Write the arrays // Write the arrays
writeArraysOfIdentifiers(); writeArraysOfIdentifiers();
// Write all the arrays of link library infos for this graph
writeLinkLibraries(cache);
// Write the core graph // Write the core graph
// TODO: Serialize *all* modules for (auto kind = ModuleDependencyKind::FirstKind;
for (auto &moduleID : cache.getAllDependencies({cache.mainScanModuleName, kind != ModuleDependencyKind::LastKind; ++kind) {
ModuleDependencyKind::SwiftSource})) { auto modMap = cache.getDependenciesMap(kind);
auto dependencyInfo = cache.findDependency(moduleID.ModuleName, moduleID.Kind); for (const auto &modInfo : modMap) {
assert(dependencyInfo.has_value() && "Expected dependency info."); writeModuleInfo({modInfo.getKey().str(), kind}, modInfo.second);
writeModuleInfo(moduleID, **dependencyInfo); }
} }
return; return;
} }

View File

@@ -713,9 +713,6 @@ ModuleDependencyScanner::resolveAllClangModuleDependencies(
} else { } else {
// We need to query the Clang dependency scanner for this module's // We need to query the Clang dependency scanner for this module's
// unresolved imports // unresolved imports
auto moduleDependencyInfo = cache.findKnownDependency(moduleID);
// Figure out which imports have already been resolved to module dependencies
llvm::StringSet<> resolvedImportIdentifiers; llvm::StringSet<> resolvedImportIdentifiers;
for (const auto &resolvedDep : moduleDependencyInfo.getImportedSwiftDependencies()) for (const auto &resolvedDep : moduleDependencyInfo.getImportedSwiftDependencies())
resolvedImportIdentifiers.insert(resolvedDep.ModuleName); resolvedImportIdentifiers.insert(resolvedDep.ModuleName);

View File

@@ -1287,7 +1287,14 @@ bool swift::dependencies::scanDependencies(CompilerInstance &CI) {
CI.getInvocation().getFrontendOptions().ExplicitModulesOutputPath, CI.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
CI.getInvocation().getModuleScanningHash()); CI.getInvocation().getModuleScanningHash());
// ACTODO: Deserialize cache // Load the dependency cache if -reuse-dependency-scan-cache
// is specified
if (opts.ReuseDependencyScannerCache) {
auto cachePath = opts.SerializedDependencyScannerCachePath;
module_dependency_cache_serialization::readInterModuleDependenciesCache(cachePath, cache);
if (opts.EmitDependencyScannerCacheRemarks)
ctx.Diags.diagnose(SourceLoc(), diag::remark_reuse_cache, cachePath);
}
if (service->setupCachingDependencyScanningService(CI)) if (service->setupCachingDependencyScanningService(CI))
return true; return true;
@@ -1298,7 +1305,13 @@ bool swift::dependencies::scanDependencies(CompilerInstance &CI) {
// Serialize the dependency cache if -serialize-dependency-scan-cache // Serialize the dependency cache if -serialize-dependency-scan-cache
// is specified // is specified
// ACTODO: Serialize cache if (opts.SerializeDependencyScannerCache) {
auto savePath = opts.SerializedDependencyScannerCachePath;
module_dependency_cache_serialization::writeInterModuleDependenciesCache(
ctx.Diags, CI.getOutputBackend(), savePath, cache);
if (opts.EmitDependencyScannerCacheRemarks)
ctx.Diags.diagnose(SourceLoc(), diag::remark_save_cache, savePath);
}
if (dependenciesOrErr.getError()) if (dependenciesOrErr.getError())
return true; return true;