[Dependency Scanning] Refactor the scanner to resolve unqualified module imports

This changes the scanner's behavior to "resolve" a discovered module's dependencies to a set of Module IDs: module name + module kind (swift textual, swift binary, clang, etc.).

The 'ModuleDependencyInfo' objects that are stored in the dependency scanner's cache now carry a set of kind-qualified ModuleIDs for their dependencies, in addition to unqualified imported module names of their dependencies.

Previously, the scanner's internal state would cache a module dependnecy as having its own set of dependencies which were stored as names of imported modules. This led to a design where any time we needed to process the dependency downstream from its discovery (e.g. cycle detection, graph construction), we had to query the ASTContext to resolve this dependency's imports, which shouldn't be necessary. Now, upon discovery, we "resolve" a discovered dependency by executing a lookup for each of its imported module names (this operation happens regardless of this patch) and store a fully-resolved set of dependencies in the dependency module info.

Moreover, looking up a given module dependency by name (via `ASTContext`'s `getModuleDependencies`) would result in iterating over the scanner's module "loaders" and querying each for the module name. The corresponding modules would then check the scanner's cache for a respective discovered module, and if no such module is found the "loader" would search the filesystem.

This meant that in practice, we searched the filesystem on many occasions where we actually had cached the required dependency, as follows:
Suppose we had previously discovered a Clang module "foo" and cached its dependency info.
-> ASTContext.getModuleDependencies("foo")
--> (1) Swift Module "Loader" checks caches for a Swift module "foo" and doesn't find one, so it searches the filesystem for "foo" and fails to find one.
--> (2) Clang Module "Loader" checks caches for a Clang module "foo", finds one and returns it to the client.

This means that we were always searching the filesystem in (1) even if we knew that to be futile.
With this change, queries to `ASTContext`'s `getModuleDependencies` will always check all the caches first, and only delegate to the scanner "loaders" if no cached dependency is found. The loaders are then no longer in the business of checking the cached contents.

To handle cases in the scanner where we must only lookup either a Swift-only module or a Clang-only module, this patch splits 'getModuleDependencies' into an alrady-existing 'getSwiftModuleDependencies' and a newly-added 'getClangModuleDependencies'.
This commit is contained in:
Artem Chikin
2022-12-19 10:58:05 -08:00
parent a6e056ba7e
commit 12477b7b79
22 changed files with 688 additions and 749 deletions

View File

@@ -39,7 +39,8 @@ class ModuleDependenciesCacheDeserializer {
bool readGraph(SwiftDependencyScanningService &cache);
llvm::Optional<std::string> getIdentifier(unsigned n);
llvm::Optional<std::vector<std::string>> getArray(unsigned n);
llvm::Optional<std::vector<std::string>> getStringArray(unsigned n);
llvm::Optional<std::vector<ModuleDependencyID>> getModuleDependencyIDArray(unsigned n);
public:
ModuleDependenciesCacheDeserializer(llvm::MemoryBufferRef Data) : Cursor(Data) {}
@@ -152,7 +153,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
bool hasCurrentModule = false;
std::string currentModuleName;
unsigned currentContextHashID;
llvm::Optional<std::vector<std::string>> currentModuleDependencies;
llvm::Optional<std::vector<std::string>> currentModuleImports;
llvm::Optional<std::vector<ModuleDependencyID>> currentModuleDependencyIDs;
auto getContextHash = [&]() {
assert(currentContextHashID &&
@@ -208,17 +210,22 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
case MODULE_NODE: {
hasCurrentModule = true;
unsigned moduleNameID, contextHashID, moduleDependenciesArrayID;
unsigned moduleNameID, contextHashID,
moduleImportsArrayID, moduleDependencyIDArrayID;
ModuleInfoLayout::readRecord(Scratch, moduleNameID, contextHashID,
moduleDependenciesArrayID);
moduleImportsArrayID,
moduleDependencyIDArrayID);
auto moduleName = getIdentifier(moduleNameID);
if (!moduleName)
llvm::report_fatal_error("Bad module name");
currentModuleName = *moduleName;
currentContextHashID = contextHashID;
currentModuleDependencies = getArray(moduleDependenciesArrayID);
if (!currentModuleDependencies)
llvm::report_fatal_error("Bad direct dependencies");
currentModuleImports = getStringArray(moduleImportsArrayID);
currentModuleDependencyIDs = getModuleDependencyIDArray(moduleDependencyIDArrayID);
if (!currentModuleImports)
llvm::report_fatal_error("Bad direct dependencies: no imports");
if (!currentModuleDependencyIDs)
llvm::report_fatal_error("Bad direct dependencies: no qualified dependencies");
break;
}
@@ -247,13 +254,13 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
llvm::report_fatal_error("Bad swift interface file path");
optionalSwiftInterfaceFile = *swiftInterfaceFile;
}
auto compiledModuleCandidates = getArray(compiledModuleCandidatesArrayID);
auto compiledModuleCandidates = getStringArray(compiledModuleCandidatesArrayID);
if (!compiledModuleCandidates)
llvm::report_fatal_error("Bad compiled module candidates");
auto commandLine = getArray(buildCommandLineArrayID);
auto commandLine = getStringArray(buildCommandLineArrayID);
if (!commandLine)
llvm::report_fatal_error("Bad command line");
auto extraPCMArgs = getArray(extraPCMArgsArrayID);
auto extraPCMArgs = getStringArray(extraPCMArgsArrayID);
if (!extraPCMArgs)
llvm::report_fatal_error("Bad PCM Args set");
auto contextHash = getIdentifier(contextHashID);
@@ -274,9 +281,12 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
optionalSwiftInterfaceFile.value(), *compiledModuleCandidates,
buildCommandRefs, extraPCMRefs, *contextHash, isFramework);
// Add dependencies of this module
for (const auto &moduleName : *currentModuleDependencies)
moduleDep.addModuleDependency(moduleName);
// Add imports of this module
for (const auto &moduleName : *currentModuleImports)
moduleDep.addModuleImport(moduleName);
// Add qualified dependencies of this module
moduleDep.resolveDependencies(*currentModuleDependencyIDs);
// Add bridging header file path
if (bridgingHeaderFileID != 0) {
@@ -288,28 +298,28 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
}
// Add bridging source files
auto bridgingSourceFiles = getArray(bridgingSourceFilesArrayID);
auto bridgingSourceFiles = getStringArray(bridgingSourceFilesArrayID);
if (!bridgingSourceFiles)
llvm::report_fatal_error("Bad bridging source files");
for (const auto &file : *bridgingSourceFiles)
moduleDep.addBridgingSourceFile(file);
// Add source files
auto sourceFiles = getArray(sourceFilesArrayID);
auto sourceFiles = getStringArray(sourceFilesArrayID);
if (!sourceFiles)
llvm::report_fatal_error("Bad bridging source files");
for (const auto &file : *sourceFiles)
moduleDep.addSourceFile(file);
// Add bridging module dependencies
auto bridgingModuleDeps = getArray(bridgingModuleDependenciesArrayID);
auto bridgingModuleDeps = getStringArray(bridgingModuleDependenciesArrayID);
if (!bridgingModuleDeps)
llvm::report_fatal_error("Bad bridging module dependencies");
llvm::StringSet<> alreadyAdded;
for (const auto &mod : *bridgingModuleDeps)
moduleDep.addBridgingModuleDependency(mod, alreadyAdded);
cache.recordDependencies(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
}
@@ -330,7 +340,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID);
auto extraPCMArgs = getArray(extraPCMArgsArrayID);
auto extraPCMArgs = getStringArray(extraPCMArgsArrayID);
if (!extraPCMArgs)
llvm::report_fatal_error("Bad PCM Args set");
std::vector<StringRef> extraPCMRefs;
@@ -341,8 +351,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
auto moduleDep = ModuleDependencyInfo::forSwiftSourceModule(extraPCMRefs);
// Add dependencies of this module
for (const auto &moduleName : *currentModuleDependencies)
moduleDep.addModuleDependency(moduleName);
for (const auto &moduleName : *currentModuleImports)
moduleDep.addModuleImport(moduleName);
// Add bridging header file path
if (bridgingHeaderFileID != 0) {
@@ -354,28 +364,28 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
}
// Add bridging source files
auto bridgingSourceFiles = getArray(bridgingSourceFilesArrayID);
auto bridgingSourceFiles = getStringArray(bridgingSourceFilesArrayID);
if (!bridgingSourceFiles)
llvm::report_fatal_error("Bad bridging source files");
for (const auto &file : *bridgingSourceFiles)
moduleDep.addBridgingSourceFile(file);
// Add source files
auto sourceFiles = getArray(sourceFilesArrayID);
auto sourceFiles = getStringArray(sourceFilesArrayID);
if (!sourceFiles)
llvm::report_fatal_error("Bad bridging source files");
for (const auto &file : *sourceFiles)
moduleDep.addSourceFile(file);
// Add bridging module dependencies
auto bridgingModuleDeps = getArray(bridgingModuleDependenciesArrayID);
auto bridgingModuleDeps = getStringArray(bridgingModuleDependenciesArrayID);
if (!bridgingModuleDeps)
llvm::report_fatal_error("Bad bridging module dependencies");
llvm::StringSet<> alreadyAdded;
for (const auto &mod : *bridgingModuleDeps)
moduleDep.addBridgingModuleDependency(mod, alreadyAdded);
cache.recordDependencies(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
}
@@ -406,10 +416,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath,
isFramework);
// Add dependencies of this module
for (const auto &moduleName : *currentModuleDependencies)
moduleDep.addModuleDependency(moduleName);
for (const auto &moduleName : *currentModuleImports)
moduleDep.addModuleImport(moduleName);
cache.recordDependencies(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
}
@@ -438,10 +448,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
auto moduleDep = ModuleDependencyInfo::forPlaceholderSwiftModuleStub(
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath);
// Add dependencies of this module
for (const auto &moduleName : *currentModuleDependencies)
moduleDep.addModuleDependency(moduleName);
for (const auto &moduleName : *currentModuleImports)
moduleDep.addModuleImport(moduleName);
cache.recordDependencies(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
}
@@ -465,13 +475,13 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
auto contextHash = getIdentifier(contextHashID);
if (!contextHash)
llvm::report_fatal_error("Bad context hash");
auto commandLineArgs = getArray(commandLineArrayID);
auto commandLineArgs = getStringArray(commandLineArrayID);
if (!commandLineArgs)
llvm::report_fatal_error("Bad command line");
auto fileDependencies = getArray(fileDependenciesArrayID);
auto fileDependencies = getStringArray(fileDependenciesArrayID);
if (!fileDependencies)
llvm::report_fatal_error("Bad file dependencies");
auto capturedPCMArgs = getArray(capturedPCMArgsArrayID);
auto capturedPCMArgs = getStringArray(capturedPCMArgsArrayID);
if (!capturedPCMArgs)
llvm::report_fatal_error("Bad captured PCM Args");
@@ -481,10 +491,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
*capturedPCMArgs);
// Add dependencies of this module
for (const auto &moduleName : *currentModuleDependencies)
moduleDep.addModuleDependency(moduleName);
for (const auto &moduleName : *currentModuleImports)
moduleDep.addModuleImport(moduleName);
cache.recordDependencies(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
}
@@ -528,7 +538,7 @@ llvm::Optional<std::string> ModuleDependenciesCacheDeserializer::getIdentifier(u
return Identifiers[n];
}
llvm::Optional<std::vector<std::string>> ModuleDependenciesCacheDeserializer::getArray(unsigned n) {
llvm::Optional<std::vector<std::string>> ModuleDependenciesCacheDeserializer::getStringArray(unsigned n) {
if (n == 0)
return std::vector<std::string>();
@@ -551,6 +561,37 @@ llvm::Optional<std::vector<std::string>> ModuleDependenciesCacheDeserializer::ge
return result;
}
llvm::Optional<std::vector<ModuleDependencyID>> ModuleDependenciesCacheDeserializer::getModuleDependencyIDArray(unsigned n) {
auto encodedIdentifierStringArray = getStringArray(n);
if (encodedIdentifierStringArray.has_value()) {
static const std::string textualPrefix("swiftTextual");
static const std::string binaryPrefix("swiftBinary");
static const std::string placeholderPrefix("swiftPlaceholder");
static const std::string clangPrefix("clang");
std::vector<ModuleDependencyID> result;
for (const auto &encodedIdentifierString : *encodedIdentifierStringArray) {
ModuleDependencyID id;
if (!encodedIdentifierString.compare(0, textualPrefix.size(), textualPrefix)) {
auto moduleName = encodedIdentifierString.substr(textualPrefix.size() + 1);
id = {moduleName, ModuleDependencyKind::SwiftInterface};
} else if (!encodedIdentifierString.compare(0, binaryPrefix.size(), binaryPrefix)) {
auto moduleName = encodedIdentifierString.substr(binaryPrefix.size() + 1);
id = {moduleName, ModuleDependencyKind::SwiftBinary};
} else if (!encodedIdentifierString.compare(0, placeholderPrefix.size(), placeholderPrefix)) {
auto moduleName = encodedIdentifierString.substr(placeholderPrefix.size() + 1);
id = {moduleName, ModuleDependencyKind::SwiftPlaceholder};
} else {
auto moduleName = encodedIdentifierString.substr(clangPrefix.size() + 1);
id = {moduleName, ModuleDependencyKind::Clang};
}
result.push_back(id);
}
return result;
}
return None;
}
bool swift::dependencies::module_dependency_cache_serialization::
readInterModuleDependenciesCache(llvm::MemoryBuffer &buffer,
SwiftDependencyScanningService &cache) {
@@ -576,7 +617,8 @@ bool swift::dependencies::module_dependency_cache_serialization::
/// array ID for a given module.
enum ModuleIdentifierArrayKind : uint8_t {
Empty = 0,
DirectDependencies,
DependencyImports,
QualifiedModuleDependencyIDs,
CompiledModuleCandidates,
BuildCommandLine,
ExtraPCMArgs,
@@ -651,11 +693,14 @@ class ModuleDependenciesCacheSerializer {
unsigned getIdentifier(const std::string &str) const;
// Returns the array ID of the added array
void addArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<std::string> &vec);
unsigned getArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const;
void addStringArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<std::string> &vec);
void addDependencyIDArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<ModuleDependencyID> &vec);
unsigned getArrayID(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const;
template <typename Layout>
void registerRecordAbbr() {
@@ -779,7 +824,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
ModuleInfoLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[ModuleInfoLayout::Code],
getIdentifier(moduleID.first), contextHashStrID,
getArray(moduleID, ModuleIdentifierArrayKind::DirectDependencies));
getArrayID(moduleID, ModuleIdentifierArrayKind::DependencyImports),
getArrayID(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs));
switch (dependencyInfo.getKind()) {
case swift::ModuleDependencyKind::SwiftInterface: {
@@ -799,15 +845,15 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code],
outputModulePathFileId,
swiftInterfaceFileId,
getArray(moduleID, ModuleIdentifierArrayKind::CompiledModuleCandidates),
getArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine),
getArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
getIdentifier(swiftTextDeps->contextHash), swiftTextDeps->isFramework,
getArrayID(moduleID, ModuleIdentifierArrayKind::CompiledModuleCandidates),
getArrayID(moduleID, ModuleIdentifierArrayKind::BuildCommandLine),
getArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
getIdentifier(swiftTextDeps->contextHash),
swiftTextDeps->isFramework,
bridgingHeaderFileId,
getArray(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArray(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies));
getArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies));
break;
}
case swift::ModuleDependencyKind::SwiftSource: {
@@ -822,12 +868,11 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
: 0;
SwiftSourceModuleDetailsLayout::emitRecord(
Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code],
getArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
getArrayID(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs),
bridgingHeaderFileId,
getArray(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArray(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies));
getArrayID(moduleID, ModuleIdentifierArrayKind::SourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies));
break;
}
case swift::ModuleDependencyKind::SwiftBinary: {
@@ -864,9 +909,9 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
getIdentifier(clangDeps->pcmOutputPath),
getIdentifier(clangDeps->moduleMapFile),
getIdentifier(clangDeps->contextHash),
getArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine),
getArray(moduleID, ModuleIdentifierArrayKind::FileDependencies),
getArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs));
getArrayID(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine),
getArrayID(moduleID, ModuleIdentifierArrayKind::FileDependencies),
getArrayID(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs));
break;
}
@@ -902,9 +947,20 @@ unsigned ModuleDependenciesCacheSerializer::getIdentifier(const std::string &str
return iter->second;
}
void ModuleDependenciesCacheSerializer::addArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<std::string> &vec) {
void ModuleDependenciesCacheSerializer::addDependencyIDArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<ModuleDependencyID> &vec) {
std::vector<std::string> encodedDependencyIDs;
for (const auto &moduleID : vec)
encodedDependencyIDs.push_back(createEncodedModuleKindAndName(moduleID));
addStringArray(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs,
encodedDependencyIDs);
return;
}
void ModuleDependenciesCacheSerializer::addStringArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<std::string> &vec) {
if (ArrayIDs.find(moduleID) != ArrayIDs.end()) {
// Already have arrays for this module
llvm::DenseMap<ModuleIdentifierArrayKind, unsigned>::iterator iter;
@@ -932,8 +988,8 @@ void ModuleDependenciesCacheSerializer::addArray(ModuleDependencyID moduleID,
return;
}
unsigned ModuleDependenciesCacheSerializer::getArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const {
unsigned ModuleDependenciesCacheSerializer::getArrayID(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const {
auto iter = ArrayIDs.find(moduleID);
assert(iter != ArrayIDs.end());
auto &innerMap = iter->second;
@@ -954,35 +1010,37 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
// Add the module's name
addIdentifier(moduleID.first);
// Add the module's dependencies
addArray(moduleID, ModuleIdentifierArrayKind::DirectDependencies,
dependencyInfo.getModuleDependencies());
auto swiftSourceDeps = dependencyInfo.getAsSwiftSourceModule();
addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports,
dependencyInfo->getModuleImports());
addDependencyIDArray(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs,
dependencyInfo->getModuleDependencies());
auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule();
assert(swiftSourceDeps);
addArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
swiftSourceDeps->textualModuleDetails.extraPCMArgs);
addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
swiftSourceDeps->textualModuleDetails.extraPCMArgs);
if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.has_value())
addIdentifier(
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value());
addArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
swiftSourceDeps->sourceFiles);
addArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles);
addArray(moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
swiftSourceDeps->textualModuleDetails.bridgingModuleDependencies);
addIdentifier(swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value());
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
swiftSourceDeps->sourceFiles);
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles);
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
swiftSourceDeps->textualModuleDetails.bridgingModuleDependencies);
}
for (auto &contextHash : cache.getAllContextHashes()) {
addIdentifier(contextHash);
for (auto &moduleID : cache.getAllNonSourceModules(contextHash)) {
auto dependencyInfo = cache.findDependencies(moduleID.first, moduleID.second);
assert(dependencyInfo.has_value() && "Expected dependency info.");
auto optionalDependencyInfo = cache.findDependency(moduleID.first, moduleID.second);
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
auto dependencyInfo = optionalDependencyInfo.getValue();
// Add the module's name
addIdentifier(moduleID.first);
// Add the module's dependencies
addArray(moduleID, ModuleIdentifierArrayKind::DirectDependencies,
dependencyInfo->getModuleDependencies());
addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports,
dependencyInfo->getModuleImports());
addDependencyIDArray(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs,
dependencyInfo->getModuleDependencies());
// Add the dependency-kind-specific data
switch (dependencyInfo->getKind()) {
@@ -991,22 +1049,22 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
assert(swiftTextDeps);
addIdentifier(swiftTextDeps->moduleOutputPath);
addIdentifier(swiftTextDeps->swiftInterfaceFile);
addArray(moduleID,
addStringArray(moduleID,
ModuleIdentifierArrayKind::CompiledModuleCandidates,
swiftTextDeps->compiledModuleCandidates);
addArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
swiftTextDeps->buildCommandLine);
addArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
addStringArray(moduleID, ModuleIdentifierArrayKind::ExtraPCMArgs,
swiftTextDeps->textualModuleDetails.extraPCMArgs);
addIdentifier(swiftTextDeps->contextHash);
if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile.has_value())
addIdentifier(swiftTextDeps->textualModuleDetails.bridgingHeaderFile
.value());
addArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
std::vector<std::string>());
addArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
swiftTextDeps->textualModuleDetails.bridgingSourceFiles);
addArray(
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
swiftTextDeps->textualModuleDetails.bridgingModuleDependencies);
break;
@@ -1033,11 +1091,11 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
addIdentifier(clangDeps->pcmOutputPath);
addIdentifier(clangDeps->moduleMapFile);
addIdentifier(clangDeps->contextHash);
addArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine,
addStringArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine,
clangDeps->nonPathCommandLine);
addArray(moduleID, ModuleIdentifierArrayKind::FileDependencies,
addStringArray(moduleID, ModuleIdentifierArrayKind::FileDependencies,
clangDeps->fileDependencies);
addArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs,
addStringArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs,
clangDeps->capturedPCMArgs);
break;
}
@@ -1088,17 +1146,16 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
for (auto &moduleID : cache.getAllSourceModules()) {
auto dependencyInfo = cache.findSourceModuleDependency(moduleID.first);
assert(dependencyInfo.has_value() && "Expected dependency info.");
writeModuleInfo(moduleID, llvm::Optional<std::string>(),
dependencyInfo.value());
writeModuleInfo(moduleID, llvm::Optional<std::string>(), **dependencyInfo);
}
// Write all non-source modules, for each of the context hashes this scanner
// has been used with
for (auto &contextHash : cache.getAllContextHashes()) {
for (auto &moduleID : cache.getAllNonSourceModules(contextHash)) {
auto dependencyInfo = cache.findDependencies(moduleID.first, moduleID.second);
auto dependencyInfo = cache.findDependency(moduleID.first, moduleID.second);
assert(dependencyInfo.has_value() && "Expected dependency info.");
writeModuleInfo(moduleID, contextHash, *dependencyInfo);
writeModuleInfo(moduleID, contextHash, **dependencyInfo);
}
}