[Dependency Scanning] Do not track source module dependencies separately in SwiftDependencyScanningService

Instead, treat them like any other module that is specific to the scanning context hash of the scan it originates from.
Otherwise we may actually have simultaneous scans happening for the same source module but with different context hashes, and the current scheme leads to collisions.
This commit is contained in:
Artem Chikin
2023-03-30 11:27:08 -07:00
parent 76c5e4f1ae
commit e8895f721a
3 changed files with 21 additions and 115 deletions

View File

@@ -386,7 +386,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
for (const auto &mod : *bridgingModuleDeps)
moduleDep.addBridgingModuleDependency(mod, alreadyAdded);
cache.recordSourceDependency(currentModuleName, std::move(moduleDep));
cache.recordDependency(currentModuleName, std::move(moduleDep),
getContextHash());
hasCurrentModule = false;
break;
}
@@ -991,37 +992,9 @@ unsigned ModuleDependenciesCacheSerializer::getArrayID(ModuleDependencyID module
void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
const SwiftDependencyScanningService &cache) {
for (auto &moduleID : cache.getAllSourceModules()) {
assert(moduleID.second == ModuleDependencyKind::SwiftSource &&
"Expected source-based dependency");
auto optionalDependencyInfo =
cache.findSourceModuleDependency(moduleID.first);
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
auto dependencyInfo = optionalDependencyInfo.value();
// Add the module's name
addIdentifier(moduleID.first);
// Add the module's dependencies
addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports,
dependencyInfo->getModuleImports());
addDependencyIDArray(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs,
dependencyInfo->getModuleDependencies());
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,
swiftSourceDeps->textualModuleDetails.bridgingModuleDependencies);
}
for (auto &contextHash : cache.getAllContextHashes()) {
addIdentifier(contextHash);
for (auto &moduleID : cache.getAllNonSourceModules(contextHash)) {
for (auto &moduleID : cache.getAllModules(contextHash)) {
auto optionalDependencyInfo = cache.findDependency(moduleID.first,
moduleID.second,
contextHash);
@@ -1078,6 +1051,21 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
addIdentifier(swiftPHDeps->sourceInfoPath);
break;
}
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,
swiftSourceDeps->textualModuleDetails.bridgingModuleDependencies);
break;
}
case swift::ModuleDependencyKind::Clang: {
auto clangDeps = dependencyInfo->getAsClangModule();
assert(clangDeps);
@@ -1135,17 +1123,8 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
writeArraysOfIdentifiers();
// Write the core graph
// First, write the source modules we've encountered
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);
}
// 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)) {
for (auto &moduleID : cache.getAllModules(contextHash)) {
auto dependencyInfo = cache.findDependency(moduleID.first,
moduleID.second,
contextHash);