mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Dependency Scanning] Miscellaneous fixes to import statement info serialization
- Deserialization of binary module dependencies was still relying on stale code (e.g. 'currentModuleImports', 'currentOptionalModuleImports') from serialized import strings, instead of the now in-use import infos. - Imports without a source location (e.g. implicit imports of stdlib) were not getting serialized at all - Optional import arrays were not being written out at all
This commit is contained in:
@@ -218,9 +218,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
|
|
||||||
bool hasCurrentModule = false;
|
bool hasCurrentModule = false;
|
||||||
std::string currentModuleName;
|
std::string currentModuleName;
|
||||||
std::vector<ScannerImportStatementInfo> currentModuleImports;
|
|
||||||
std::vector<ScannerImportStatementInfo> currentOptionalModuleImports;
|
|
||||||
|
|
||||||
std::vector<ModuleDependencyID> importedSwiftDependenciesIDs;
|
std::vector<ModuleDependencyID> importedSwiftDependenciesIDs;
|
||||||
std::vector<ModuleDependencyID> importedClangDependenciesIDs;
|
std::vector<ModuleDependencyID> importedClangDependenciesIDs;
|
||||||
std::vector<ModuleDependencyID> crossImportOverlayDependenciesIDs;
|
std::vector<ModuleDependencyID> crossImportOverlayDependenciesIDs;
|
||||||
@@ -235,18 +232,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
std::vector<std::string> auxiliaryFiles;
|
std::vector<std::string> auxiliaryFiles;
|
||||||
|
|
||||||
auto addCommonDependencyInfo =
|
auto addCommonDependencyInfo =
|
||||||
[¤tModuleImports, ¤tOptionalModuleImports,
|
[&importedClangDependenciesIDs, &auxiliaryFiles,
|
||||||
&importedClangDependenciesIDs, &auxiliaryFiles,
|
|
||||||
¯oDependencies](ModuleDependencyInfo &moduleDep) {
|
¯oDependencies](ModuleDependencyInfo &moduleDep) {
|
||||||
// Add imports of this module
|
|
||||||
for (const auto &moduleName : currentModuleImports)
|
|
||||||
moduleDep.addModuleImport(moduleName.importIdentifier,
|
|
||||||
moduleName.isExported);
|
|
||||||
// Add optional imports of this module
|
|
||||||
for (const auto &moduleName : currentOptionalModuleImports)
|
|
||||||
moduleDep.addOptionalModuleImport(moduleName.importIdentifier,
|
|
||||||
moduleName.isExported);
|
|
||||||
|
|
||||||
// Add qualified dependencies of this module
|
// Add qualified dependencies of this module
|
||||||
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
|
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
|
||||||
|
|
||||||
@@ -297,7 +284,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error("Bad bridging module dependencies");
|
llvm::report_fatal_error("Bad bridging module dependencies");
|
||||||
llvm::StringSet<> alreadyAdded;
|
llvm::StringSet<> alreadyAdded;
|
||||||
std::vector<ModuleDependencyID> bridgingModuleDepIDs;
|
std::vector<ModuleDependencyID> bridgingModuleDepIDs;
|
||||||
for (const auto &mod : bridgingModuleDeps.value())
|
for (const auto &mod : *bridgingModuleDeps)
|
||||||
bridgingModuleDepIDs.push_back(
|
bridgingModuleDepIDs.push_back(
|
||||||
ModuleDependencyID{mod, ModuleDependencyKind::Clang});
|
ModuleDependencyID{mod, ModuleDependencyKind::Clang});
|
||||||
moduleDep.setHeaderClangDependencies(bridgingModuleDepIDs);
|
moduleDep.setHeaderClangDependencies(bridgingModuleDepIDs);
|
||||||
@@ -364,7 +351,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error("Bad link library identifier");
|
llvm::report_fatal_error("Bad link library identifier");
|
||||||
|
|
||||||
LinkLibraries.emplace_back(
|
LinkLibraries.emplace_back(
|
||||||
libraryIdentifier.value(),
|
*libraryIdentifier,
|
||||||
isFramework ? LibraryKind::Framework
|
isFramework ? LibraryKind::Framework
|
||||||
: LibraryKind::Library,
|
: LibraryKind::Library,
|
||||||
isStatic, shouldForceLoad);
|
isStatic, shouldForceLoad);
|
||||||
@@ -395,8 +382,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error("Bad macro dependency: no executable path");
|
llvm::report_fatal_error("Bad macro dependency: no executable path");
|
||||||
|
|
||||||
MacroDependencies.push_back(
|
MacroDependencies.push_back(
|
||||||
{macroModuleName.value(),
|
{*macroModuleName,
|
||||||
MacroPluginDependency{libraryPath.value(), executablePath.value()}});
|
MacroPluginDependency{*libraryPath, *executablePath}});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,10 +409,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
if (!bufferIdentifier)
|
if (!bufferIdentifier)
|
||||||
llvm::report_fatal_error(
|
llvm::report_fatal_error(
|
||||||
"Bad import statement info: no buffer identifier");
|
"Bad import statement info: no buffer identifier");
|
||||||
ImportStatements.push_back(ScannerImportStatementInfo(
|
if (bufferIdentifier->empty())
|
||||||
importIdentifier.value(), isExported,
|
ImportStatements.push_back(ScannerImportStatementInfo(
|
||||||
ScannerImportStatementInfo::ImportDiagnosticLocationInfo(
|
*importIdentifier, isExported));
|
||||||
bufferIdentifier.value(), lineNumber, columnNumber)));
|
else
|
||||||
|
ImportStatements.push_back(ScannerImportStatementInfo(
|
||||||
|
*importIdentifier, isExported,
|
||||||
|
ScannerImportStatementInfo::ImportDiagnosticLocationInfo(
|
||||||
|
*bufferIdentifier, lineNumber, columnNumber)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,18 +461,16 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
getImportStatementInfoArray(moduleImportsArrayID);
|
getImportStatementInfoArray(moduleImportsArrayID);
|
||||||
if (!optionalImportStatementInfos)
|
if (!optionalImportStatementInfos)
|
||||||
llvm::report_fatal_error("Bad direct Swift dependencies: no imports");
|
llvm::report_fatal_error("Bad direct Swift dependencies: no imports");
|
||||||
importStatements = optionalImportStatementInfos.value();
|
importStatements = *optionalImportStatementInfos;
|
||||||
|
|
||||||
auto optionalOptionalImportStatementInfos =
|
auto optionalOptionalImportStatementInfos =
|
||||||
getOptionalImportStatementInfoArray(optionalImportsArrayID);
|
getOptionalImportStatementInfoArray(optionalImportsArrayID);
|
||||||
if (!optionalOptionalImportStatementInfos)
|
if (optionalOptionalImportStatementInfos)
|
||||||
llvm::report_fatal_error(
|
optionalImportStatements = *optionalOptionalImportStatementInfos;
|
||||||
"Bad direct Swift dependencies: no optional imports");
|
|
||||||
optionalImportStatements = optionalOptionalImportStatementInfos.value();
|
|
||||||
|
|
||||||
auto optionalAuxiliaryFiles = getStringArray(AuxiliaryFilesArrayID);
|
auto optionalAuxiliaryFiles = getStringArray(AuxiliaryFilesArrayID);
|
||||||
if (optionalAuxiliaryFiles.has_value())
|
if (optionalAuxiliaryFiles)
|
||||||
for (const auto &af : optionalAuxiliaryFiles.value())
|
for (const auto &af : *optionalAuxiliaryFiles)
|
||||||
auxiliaryFiles.push_back(af);
|
auxiliaryFiles.push_back(af);
|
||||||
|
|
||||||
auto optionalImportedSwiftDependenciesIDs =
|
auto optionalImportedSwiftDependenciesIDs =
|
||||||
@@ -490,7 +479,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error(
|
llvm::report_fatal_error(
|
||||||
"Bad direct Swift dependencies: no qualified dependencies");
|
"Bad direct Swift dependencies: no qualified dependencies");
|
||||||
importedSwiftDependenciesIDs =
|
importedSwiftDependenciesIDs =
|
||||||
optionalImportedSwiftDependenciesIDs.value();
|
*optionalImportedSwiftDependenciesIDs;
|
||||||
|
|
||||||
auto optionalImportedClangDependenciesIDs =
|
auto optionalImportedClangDependenciesIDs =
|
||||||
getModuleDependencyIDArray(importedClangDependenciesIDsArrayID);
|
getModuleDependencyIDArray(importedClangDependenciesIDsArrayID);
|
||||||
@@ -498,7 +487,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error(
|
llvm::report_fatal_error(
|
||||||
"Bad direct Clang dependencies: no qualified dependencies");
|
"Bad direct Clang dependencies: no qualified dependencies");
|
||||||
importedClangDependenciesIDs =
|
importedClangDependenciesIDs =
|
||||||
optionalImportedClangDependenciesIDs.value();
|
*optionalImportedClangDependenciesIDs;
|
||||||
|
|
||||||
auto optionalCrossImportOverlayDependenciesIDs =
|
auto optionalCrossImportOverlayDependenciesIDs =
|
||||||
getModuleDependencyIDArray(crossImportOverlayDependenciesIDsArrayID);
|
getModuleDependencyIDArray(crossImportOverlayDependenciesIDsArrayID);
|
||||||
@@ -506,14 +495,14 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
llvm::report_fatal_error(
|
llvm::report_fatal_error(
|
||||||
"Bad Cross-Import Overlay dependencies: no qualified dependencies");
|
"Bad Cross-Import Overlay dependencies: no qualified dependencies");
|
||||||
crossImportOverlayDependenciesIDs =
|
crossImportOverlayDependenciesIDs =
|
||||||
optionalCrossImportOverlayDependenciesIDs.value();
|
*optionalCrossImportOverlayDependenciesIDs;
|
||||||
|
|
||||||
auto optionalSwiftOverlayDependenciesIDs =
|
auto optionalSwiftOverlayDependenciesIDs =
|
||||||
getModuleDependencyIDArray(swiftOverlayDependenciesIDsArrayID);
|
getModuleDependencyIDArray(swiftOverlayDependenciesIDsArrayID);
|
||||||
if (!optionalSwiftOverlayDependenciesIDs)
|
if (!optionalSwiftOverlayDependenciesIDs)
|
||||||
llvm::report_fatal_error(
|
llvm::report_fatal_error(
|
||||||
"Bad Swift Overlay dependencies: no qualified dependencies");
|
"Bad Swift Overlay dependencies: no qualified dependencies");
|
||||||
swiftOverlayDependenciesIDs = optionalSwiftOverlayDependenciesIDs.value();
|
swiftOverlayDependenciesIDs = *optionalSwiftOverlayDependenciesIDs;
|
||||||
|
|
||||||
auto optionalLinkLibraries = getLinkLibraryArray(linkLibraryArrayID);
|
auto optionalLinkLibraries = getLinkLibraryArray(linkLibraryArrayID);
|
||||||
if (!optionalLinkLibraries)
|
if (!optionalLinkLibraries)
|
||||||
@@ -587,7 +576,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
|
|
||||||
// Form the dependencies storage object
|
// Form the dependencies storage object
|
||||||
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
|
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
|
||||||
optionalSwiftInterfaceFile.value(), compiledCandidatesRefs,
|
*optionalSwiftInterfaceFile, compiledCandidatesRefs,
|
||||||
buildCommandRefs, importStatements, optionalImportStatements,
|
buildCommandRefs, importStatements, optionalImportStatements,
|
||||||
linkLibraries, isFramework, isStatic, *rootFileSystemID,
|
linkLibraries, isFramework, isStatic, *rootFileSystemID,
|
||||||
*moduleCacheKey, *userModuleVersion);
|
*moduleCacheKey, *userModuleVersion);
|
||||||
@@ -711,7 +700,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
|
|||||||
// 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, linkLibraries,
|
importStatements, optionalImportStatements, linkLibraries,
|
||||||
*headerImport, *definingInterfacePath, isFramework, isStatic,
|
*headerImport, *definingInterfacePath, isFramework, isStatic,
|
||||||
*moduleCacheKey, *userModuleVersion);
|
*moduleCacheKey, *userModuleVersion);
|
||||||
|
|
||||||
@@ -984,7 +973,7 @@ ModuleDependenciesCacheDeserializer::getOptionalImportStatementInfoArray(
|
|||||||
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);
|
||||||
if (encodedIdentifierStringArray.has_value()) {
|
if (encodedIdentifierStringArray) {
|
||||||
static const std::string textualPrefix("swiftTextual");
|
static const std::string textualPrefix("swiftTextual");
|
||||||
static const std::string binaryPrefix("swiftBinary");
|
static const std::string binaryPrefix("swiftBinary");
|
||||||
static const std::string placeholderPrefix("swiftPlaceholder");
|
static const std::string placeholderPrefix("swiftPlaceholder");
|
||||||
@@ -1288,8 +1277,8 @@ void ModuleDependenciesCacheSerializer::writeLinkLibraries(
|
|||||||
for (const auto &entry : modMap) {
|
for (const auto &entry : modMap) {
|
||||||
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
||||||
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
||||||
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
|
assert(optionalDependencyInfo && "Expected dependency info.");
|
||||||
auto dependencyInfo = optionalDependencyInfo.value();
|
auto dependencyInfo = *optionalDependencyInfo;
|
||||||
unsigned numLLs = writeLinkLibraryInfos(*dependencyInfo);
|
unsigned numLLs = writeLinkLibraryInfos(*dependencyInfo);
|
||||||
moduleLLArrayMap.insert({moduleID, std::make_pair(lastLLIndex, numLLs)});
|
moduleLLArrayMap.insert({moduleID, std::make_pair(lastLLIndex, numLLs)});
|
||||||
lastLLIndex += numLLs;
|
lastLLIndex += numLLs;
|
||||||
@@ -1343,8 +1332,8 @@ void ModuleDependenciesCacheSerializer::writeMacroDependencies(
|
|||||||
for (const auto &entry : modMap) {
|
for (const auto &entry : modMap) {
|
||||||
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
||||||
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
||||||
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
|
assert(optionalDependencyInfo && "Expected dependency info.");
|
||||||
auto dependencyInfo = optionalDependencyInfo.value();
|
auto dependencyInfo = *optionalDependencyInfo;
|
||||||
unsigned numMDs = writeMacroDependencies(*dependencyInfo);
|
unsigned numMDs = writeMacroDependencies(*dependencyInfo);
|
||||||
moduleMacroDepArrayMap.insert(
|
moduleMacroDepArrayMap.insert(
|
||||||
{moduleID, std::make_pair(lastMDIndex, numMDs)});
|
{moduleID, std::make_pair(lastMDIndex, numMDs)});
|
||||||
@@ -1399,11 +1388,11 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfos(
|
|||||||
for (auto kind = ModuleDependencyKind::FirstKind;
|
for (auto kind = ModuleDependencyKind::FirstKind;
|
||||||
kind != ModuleDependencyKind::LastKind; ++kind) {
|
kind != ModuleDependencyKind::LastKind; ++kind) {
|
||||||
auto modMap = cache.getDependenciesMap(kind);
|
auto modMap = cache.getDependenciesMap(kind);
|
||||||
for (const auto &entry : modMap) {
|
for (const auto &entry : modMap.keys()) {
|
||||||
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
ModuleDependencyID moduleID = {entry.str(), kind};
|
||||||
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
||||||
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
|
assert(optionalDependencyInfo && "Expected dependency info.");
|
||||||
auto dependencyInfo = optionalDependencyInfo.value();
|
auto dependencyInfo = *optionalDependencyInfo;
|
||||||
|
|
||||||
auto numImportInfos =
|
auto numImportInfos =
|
||||||
writeImportStatementInfos(*dependencyInfo, /* optional */ false);
|
writeImportStatementInfos(*dependencyInfo, /* optional */ false);
|
||||||
@@ -1414,22 +1403,28 @@ void ModuleDependenciesCacheSerializer::writeImportStatementInfos(
|
|||||||
auto numOptionalImportInfos =
|
auto numOptionalImportInfos =
|
||||||
writeImportStatementInfos(*dependencyInfo, /* optional */ true);
|
writeImportStatementInfos(*dependencyInfo, /* optional */ true);
|
||||||
optionalImportInfoArrayMap.insert(
|
optionalImportInfoArrayMap.insert(
|
||||||
{moduleID, std::make_pair(lastImportInfoIndex, numImportInfos)});
|
{moduleID, std::make_pair(lastImportInfoIndex, numOptionalImportInfos)});
|
||||||
lastImportInfoIndex += numOptionalImportInfos;
|
lastImportInfoIndex += numOptionalImportInfos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned lastImportInfoArrayIndex = 1;
|
unsigned lastImportInfoArrayIndex = 1;
|
||||||
|
unsigned lastOptionalImportInfoArrayIndex = 1;
|
||||||
for (auto kind = ModuleDependencyKind::FirstKind;
|
for (auto kind = ModuleDependencyKind::FirstKind;
|
||||||
kind != ModuleDependencyKind::LastKind; ++kind) {
|
kind != ModuleDependencyKind::LastKind; ++kind) {
|
||||||
auto modMap = cache.getDependenciesMap(kind);
|
auto modMap = cache.getDependenciesMap(kind);
|
||||||
for (const auto &entry : modMap) {
|
for (const auto &entry : modMap.keys()) {
|
||||||
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
ModuleDependencyID moduleID = {entry.str(), kind};
|
||||||
auto entries = importInfoArrayMap.at(moduleID);
|
auto entries = importInfoArrayMap.at(moduleID);
|
||||||
if (entries.second == 0)
|
if (entries.second != 0) {
|
||||||
continue;
|
writeImportStatementInfosArray(entries.first, entries.second);
|
||||||
writeImportStatementInfosArray(entries.first, entries.second);
|
ImportInfosArrayIDsMap.insert({moduleID, lastImportInfoArrayIndex++});
|
||||||
ImportInfosArrayIDsMap.insert({moduleID, lastImportInfoArrayIndex++});
|
}
|
||||||
|
auto optionalEntries = optionalImportInfoArrayMap.at(moduleID);
|
||||||
|
if (optionalEntries.second != 0) {
|
||||||
|
writeImportStatementInfosArray(optionalEntries.first, optionalEntries.second);
|
||||||
|
OptionalImportInfosArrayIDsMap.insert({moduleID, lastOptionalImportInfoArrayIndex++});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1440,22 +1435,31 @@ unsigned ModuleDependenciesCacheSerializer::writeImportStatementInfos(
|
|||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
auto emitImportStatementInfo = [this, &count](const auto &importInfo,
|
auto emitImportStatementInfo = [this, &count](const auto &importInfo,
|
||||||
bool isOptional) {
|
bool isOptional) {
|
||||||
for (auto &importLoc : importInfo.importLocations) {
|
if (importInfo.importLocations.empty()) {
|
||||||
ImportStatementLayout::emitRecord(
|
ImportStatementLayout::emitRecord(
|
||||||
Out, ScratchRecord, AbbrCodes[ImportStatementLayout::Code],
|
Out, ScratchRecord, AbbrCodes[ImportStatementLayout::Code],
|
||||||
getIdentifier(importInfo.importIdentifier),
|
getIdentifier(importInfo.importIdentifier),
|
||||||
getIdentifier(importLoc.bufferIdentifier), importLoc.lineNumber,
|
0, 0, 0, isOptional, importInfo.isExported);
|
||||||
importLoc.columnNumber, isOptional, importInfo.isExported);
|
|
||||||
count++;
|
count++;
|
||||||
|
} else {
|
||||||
|
for (auto &importLoc : importInfo.importLocations) {
|
||||||
|
ImportStatementLayout::emitRecord(
|
||||||
|
Out, ScratchRecord, AbbrCodes[ImportStatementLayout::Code],
|
||||||
|
getIdentifier(importInfo.importIdentifier),
|
||||||
|
getIdentifier(importLoc.bufferIdentifier), importLoc.lineNumber,
|
||||||
|
importLoc.columnNumber, isOptional, importInfo.isExported);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto &importInfo : dependencyInfo.getModuleImports())
|
if (!optional) {
|
||||||
emitImportStatementInfo(importInfo, false);
|
for (auto &importInfo : dependencyInfo.getModuleImports())
|
||||||
|
emitImportStatementInfo(importInfo, false);
|
||||||
for (auto &importInfo : dependencyInfo.getOptionalModuleImports())
|
} else {
|
||||||
emitImportStatementInfo(importInfo, true);
|
for (auto &importInfo : dependencyInfo.getOptionalModuleImports())
|
||||||
|
emitImportStatementInfo(importInfo, true);
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1500,8 +1504,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
|
|||||||
getIdentifier(swiftTextDeps->swiftInterfaceFile);
|
getIdentifier(swiftTextDeps->swiftInterfaceFile);
|
||||||
unsigned bridgingHeaderFileId =
|
unsigned bridgingHeaderFileId =
|
||||||
swiftTextDeps->textualModuleDetails.bridgingHeaderFile
|
swiftTextDeps->textualModuleDetails.bridgingHeaderFile
|
||||||
? getIdentifier(swiftTextDeps->textualModuleDetails
|
? getIdentifier(*(swiftTextDeps->textualModuleDetails
|
||||||
.bridgingHeaderFile.value())
|
.bridgingHeaderFile))
|
||||||
: 0;
|
: 0;
|
||||||
SwiftInterfaceModuleDetailsLayout::emitRecord(
|
SwiftInterfaceModuleDetailsLayout::emitRecord(
|
||||||
Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code],
|
Out, ScratchRecord, AbbrCodes[SwiftInterfaceModuleDetailsLayout::Code],
|
||||||
@@ -1529,8 +1533,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
|
|||||||
assert(swiftSourceDeps);
|
assert(swiftSourceDeps);
|
||||||
unsigned bridgingHeaderFileId =
|
unsigned bridgingHeaderFileId =
|
||||||
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile
|
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile
|
||||||
? getIdentifier(swiftSourceDeps->textualModuleDetails
|
? getIdentifier(*(swiftSourceDeps->textualModuleDetails
|
||||||
.bridgingHeaderFile.value())
|
.bridgingHeaderFile))
|
||||||
: 0;
|
: 0;
|
||||||
SwiftSourceModuleDetailsLayout::emitRecord(
|
SwiftSourceModuleDetailsLayout::emitRecord(
|
||||||
Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code],
|
Out, ScratchRecord, AbbrCodes[SwiftSourceModuleDetailsLayout::Code],
|
||||||
@@ -1732,20 +1736,14 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
|
|||||||
for (auto kind = ModuleDependencyKind::FirstKind;
|
for (auto kind = ModuleDependencyKind::FirstKind;
|
||||||
kind != ModuleDependencyKind::LastKind; ++kind) {
|
kind != ModuleDependencyKind::LastKind; ++kind) {
|
||||||
auto modMap = cache.getDependenciesMap(kind);
|
auto modMap = cache.getDependenciesMap(kind);
|
||||||
for (const auto &entry : modMap) {
|
for (const auto &entry : modMap.keys()) {
|
||||||
ModuleDependencyID moduleID = {entry.getKey().str(), kind};
|
ModuleDependencyID moduleID = {entry.str(), kind};
|
||||||
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
auto optionalDependencyInfo = cache.findDependency(moduleID);
|
||||||
assert(optionalDependencyInfo.has_value() && "Expected dependency info.");
|
assert(optionalDependencyInfo && "Expected dependency info.");
|
||||||
auto dependencyInfo = optionalDependencyInfo.value();
|
auto dependencyInfo = *optionalDependencyInfo;
|
||||||
// Add the module's name
|
// Add the module's name
|
||||||
addIdentifier(moduleID.ModuleName);
|
addIdentifier(moduleID.ModuleName);
|
||||||
|
|
||||||
// Map import infos to their respective module identifiers
|
|
||||||
auto importInfoArrayToIdentifier =
|
|
||||||
[](const auto &importInfo) -> std::string {
|
|
||||||
return importInfo.importIdentifier;
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto &ll : dependencyInfo->getLinkLibraries())
|
for (const auto &ll : dependencyInfo->getLinkLibraries())
|
||||||
addIdentifier(ll.getName().str());
|
addIdentifier(ll.getName().str());
|
||||||
|
|
||||||
@@ -1754,22 +1752,18 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
|
|||||||
addIdentifier(md.second.LibraryPath);
|
addIdentifier(md.second.LibraryPath);
|
||||||
addIdentifier(md.second.ExecutablePath);
|
addIdentifier(md.second.ExecutablePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &ii : dependencyInfo->getModuleImports()) {
|
||||||
|
addIdentifier(ii.importIdentifier);
|
||||||
|
for (const auto &il : ii.importLocations)
|
||||||
|
addIdentifier(il.bufferIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the module's imports
|
for (const auto &oii : dependencyInfo->getOptionalModuleImports()) {
|
||||||
std::vector<std::string> importIdentifiers;
|
addIdentifier(oii.importIdentifier);
|
||||||
llvm::transform(dependencyInfo->getModuleImports(),
|
for (const auto &oil : oii.importLocations)
|
||||||
std::back_inserter(importIdentifiers),
|
addIdentifier(oil.bufferIdentifier);
|
||||||
importInfoArrayToIdentifier);
|
}
|
||||||
std::vector<std::string> optionalImportIdentifiers;
|
|
||||||
llvm::transform(dependencyInfo->getOptionalModuleImports(),
|
|
||||||
std::back_inserter(optionalImportIdentifiers),
|
|
||||||
importInfoArrayToIdentifier);
|
|
||||||
|
|
||||||
addStringArray(moduleID, ModuleIdentifierArrayKind::DependencyImports,
|
|
||||||
importIdentifiers);
|
|
||||||
addStringArray(moduleID,
|
|
||||||
ModuleIdentifierArrayKind::OptionalDependencyImports,
|
|
||||||
optionalImportIdentifiers);
|
|
||||||
|
|
||||||
addDependencyIDArray(
|
addDependencyIDArray(
|
||||||
moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs,
|
moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs,
|
||||||
@@ -1806,9 +1800,9 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
|
|||||||
addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
|
addStringArray(moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
|
||||||
swiftTextDeps->textualModuleDetails.buildCommandLine);
|
swiftTextDeps->textualModuleDetails.buildCommandLine);
|
||||||
addIdentifier(swiftTextDeps->contextHash);
|
addIdentifier(swiftTextDeps->contextHash);
|
||||||
if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile.has_value())
|
if (swiftTextDeps->textualModuleDetails.bridgingHeaderFile)
|
||||||
addIdentifier(
|
addIdentifier(
|
||||||
swiftTextDeps->textualModuleDetails.bridgingHeaderFile.value());
|
*(swiftTextDeps->textualModuleDetails.bridgingHeaderFile));
|
||||||
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
|
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
|
||||||
std::vector<std::string>());
|
std::vector<std::string>());
|
||||||
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
|
addStringArray(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles,
|
||||||
@@ -1855,10 +1849,9 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
|
|||||||
case swift::ModuleDependencyKind::SwiftSource: {
|
case swift::ModuleDependencyKind::SwiftSource: {
|
||||||
auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule();
|
auto swiftSourceDeps = dependencyInfo->getAsSwiftSourceModule();
|
||||||
assert(swiftSourceDeps);
|
assert(swiftSourceDeps);
|
||||||
if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile
|
if (swiftSourceDeps->textualModuleDetails.bridgingHeaderFile)
|
||||||
.has_value())
|
|
||||||
addIdentifier(
|
addIdentifier(
|
||||||
swiftSourceDeps->textualModuleDetails.bridgingHeaderFile.value());
|
*(swiftSourceDeps->textualModuleDetails.bridgingHeaderFile));
|
||||||
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
|
addStringArray(moduleID, ModuleIdentifierArrayKind::SourceFiles,
|
||||||
swiftSourceDeps->sourceFiles);
|
swiftSourceDeps->sourceFiles);
|
||||||
addStringArray(
|
addStringArray(
|
||||||
|
|||||||
29
test/ScanDependencies/serialized_imports.swift
Normal file
29
test/ScanDependencies/serialized_imports.swift
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// REQUIRES: objc_interop
|
||||||
|
// RUN: %empty-directory(%t)
|
||||||
|
// RUN: %empty-directory(%t/module-cache)
|
||||||
|
|
||||||
|
// Run the scanner once, emitting the serialized scanner cache
|
||||||
|
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -Rdependency-scan-cache -serialize-dependency-scan-cache -load-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -enable-cross-import-overlays 2>&1 | %FileCheck %s -check-prefix CHECK-REMARK-SAVE
|
||||||
|
// RUN: llvm-bcanalyzer --dump %t/cache.moddepcache > %t/cache.moddepcache.initial.dump.txt
|
||||||
|
|
||||||
|
// Run the scanner again, but now re-using previously-serialized cache
|
||||||
|
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -Rdependency-scan-cache -serialize-dependency-scan-cache -load-dependency-scan-cache -dependency-scan-cache-path %t/cache.moddepcache -module-cache-path %t/module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -enable-cross-import-overlays 2>&1 | %FileCheck %s -check-prefix CHECK-REMARK-LOAD
|
||||||
|
// RUN: llvm-bcanalyzer --dump %t/cache.moddepcache > %t/cache.moddepcache.dump.txt
|
||||||
|
|
||||||
|
// Ensure that the initial scan, and the secondary scan which just re-used the initial scan's results report
|
||||||
|
// the same number of import statement nodes, ensuring that serialization-deserialization did not affect
|
||||||
|
// the import sets
|
||||||
|
//
|
||||||
|
// RUN: grep "IMPORT_STATEMENT_NODE" %t/cache.moddepcache.initial.dump.txt | wc -l > %t/initial_scan_import_count.txt
|
||||||
|
// RUN: grep "IMPORT_STATEMENT_NODE" %t/cache.moddepcache.dump.txt | wc -l > %t/secondary_scan_import_count.txt
|
||||||
|
// RUN: diff %t/initial_scan_import_count.txt %t/secondary_scan_import_count.txt
|
||||||
|
|
||||||
|
// CHECK-REMARK-SAVE: remark: Incremental module scan: Failed to load module scanning dependency cache from:
|
||||||
|
// CHECK-REMARK-SAVE: remark: Incremental module scan: Serializing module scanning dependency cache to:
|
||||||
|
// CHECK-REMARK-LOAD: remark: Incremental module scan: Re-using serialized module scanning dependency cache from:
|
||||||
|
|
||||||
|
import E
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user