[Dependency Scanning] Modernize and revive the module dependencies cache serialization format

This format has gotten stale and been not in use for many months. This commit restores primary functionality of the format.
This commit is contained in:
Artem Chikin
2024-11-21 14:54:00 -08:00
parent 06e7b6f3a7
commit a46e33143a
9 changed files with 163 additions and 154 deletions

View File

@@ -475,17 +475,6 @@ swiftscan_source_location_get_line_number(swiftscan_source_location_t source_loc
SWIFTSCAN_PUBLIC int64_t
swiftscan_source_location_get_column_number(swiftscan_source_location_t source_location);
//=== Scanner Cache Operations --------------------------------------------===//
// The following operations expose an implementation detail of the dependency
// scanner: its module dependencies cache. This is done in order
// to allow clients to perform incremental dependency scans by having the
// scanner's state be serializable and re-usable.
/// For the specified \c scanner instance, reset its internal state, ensuring subsequent
/// scanning queries are done "from-scratch".
SWIFTSCAN_PUBLIC void
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
/// An entry point to invoke the compiler via a library call.
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);

View File

@@ -770,6 +770,15 @@ public:
storage->linkLibraries.assign(linkLibraries.begin(), linkLibraries.end());
}
const ArrayRef<std::string> getAuxiliaryFiles() const {
return storage->auxiliaryFiles;
}
void
setAuxiliaryFiles(const ArrayRef<std::string> auxiliaryFiles) {
storage->auxiliaryFiles.assign(auxiliaryFiles.begin(), auxiliaryFiles.end());
}
bool isStaticLibrary() const {
if (auto *detail = getAsSwiftInterfaceModule())
return detail->isStatic;

View File

@@ -108,8 +108,6 @@ public:
const llvm::StringSet<> &PlaceholderModules,
StringRef WorkingDirectory);
/// Discard the tool's current `SharedCache` and start anew.
void resetCache();
/// Query diagnostics consumed so far.
std::vector<DependencyScanDiagnosticCollector::ScannerDiagnosticInfo> getDiagnostics();
/// Discared the collection of diagnostics encountered so far.

View File

@@ -57,6 +57,12 @@ using IsFrameworkField = BCFixed<1>;
using IsSystemField = BCFixed<1>;
/// A bit that indicates whether or not a module is that of a static archive
using IsStaticField = BCFixed<1>;
/// A bit taht indicates whether or not a link library is a force-load one
using IsForceLoadField = BCFixed<1>;
/// Source location fields
using LineNumberField = BCFixed<32>;
using ColumnNumberField = BCFixed<32>;
/// Arrays of various identifiers, distinguished for readability
using IdentifierIDArryField = llvm::BCArray<IdentifierIDField>;
@@ -65,9 +71,12 @@ using ModuleIDArryField = llvm::BCArray<IdentifierIDField>;
/// Identifiers used to refer to the above arrays
using FileIDArrayIDField = IdentifierIDField;
using ContextHashIDField = IdentifierIDField;
using ModuleCacheKeyIDField = IdentifierIDField;
using ImportArrayIDField = IdentifierIDField;
using FlagIDArrayIDField = IdentifierIDField;
using DependencyIDArrayIDField = IdentifierIDField;
using AuxiliaryFilesArrayIDField = IdentifierIDField;
using SourceLocationIDArrayIDField = IdentifierIDField;
/// The ID of the top-level block containing the dependency graph
const unsigned GRAPH_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
@@ -81,6 +90,9 @@ namespace graph_block {
enum {
METADATA = 1,
MODULE_NODE,
LINK_LIBRARY_NODE,
SOURCE_LOCATION_NODE,
IMPORT_STATEMENT_NODE,
SWIFT_INTERFACE_MODULE_DETAILS_NODE,
SWIFT_SOURCE_MODULE_DETAILS_NODE,
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
@@ -117,6 +129,26 @@ using IdentifierNodeLayout = BCRecordLayout<IDENTIFIER_NODE, BCBlob>;
using IdentifierArrayLayout =
BCRecordLayout<IDENTIFIER_ARRAY_NODE, IdentifierIDArryField>;
using LinkLibraryLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID
IdentifierIDField, // libraryName
IsFrameworkField, // isFramework
IsForceLoadField // forceLoad
>;
using SourceLocationLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID
IdentifierIDField, // bufferIdentifier
LineNumberField, // lineNumber
ColumnNumberField // columnNumber
>;
using ImportStatementLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID
IdentifierIDField, // importIdentifier
SourceLocationIDArrayIDField // importLocations
>;
// After the array records, we have a sequence of Module info
// records, each of which is followed by one of:
// - SwiftInterfaceModuleDetails
@@ -130,7 +162,14 @@ using ModuleInfoLayout =
ContextHashIDField, // contextHash
ImportArrayIDField, // moduleImports
ImportArrayIDField, // optionalModuleImports
DependencyIDArrayIDField // resolvedDirectModuleDependencies
// ACTODO: LinkLibrariesArrayIDField, // linkLibraries
DependencyIDArrayIDField, // importedSwiftModules
DependencyIDArrayIDField, // importedClangModules
DependencyIDArrayIDField, // crossImportOverlayModules
DependencyIDArrayIDField, // swiftOverlayDependencies
ModuleCacheKeyIDField, // moduleCacheKey
AuxiliaryFilesArrayIDField // auxiliaryFiles
// ACTODO: MacroDependenciesArrayIDField, // macroDependencies
>;
using SwiftInterfaceModuleDetailsLayout =
@@ -147,7 +186,6 @@ using SwiftInterfaceModuleDetailsLayout =
FileIDArrayIDField, // sourceFiles
FileIDArrayIDField, // bridgingSourceFiles
IdentifierIDField, // bridgingModuleDependencies
DependencyIDArrayIDField, // swiftOverlayDependencies
IdentifierIDField, // CASFileSystemRootID
IdentifierIDField, // bridgingHeaderIncludeTree
IdentifierIDField, // moduleCacheKey
@@ -161,7 +199,6 @@ using SwiftSourceModuleDetailsLayout =
FileIDArrayIDField, // sourceFiles
FileIDArrayIDField, // bridgingSourceFiles
FileIDArrayIDField, // bridgingModuleDependencies
DependencyIDArrayIDField, // swiftOverlayDependencies
IdentifierIDField, // CASFileSystemRootID
IdentifierIDField, // bridgingHeaderIncludeTree
FlagIDArrayIDField, // buildCommandLine
@@ -173,7 +210,6 @@ using SwiftBinaryModuleDetailsLayout =
FileIDField, // compiledModulePath
FileIDField, // moduleDocPath
FileIDField, // moduleSourceInfoPath
DependencyIDArrayIDField, // swiftOverlayDependencies
FileIDField, // headerImport
IdentifierIDField, // headerModuleDependencies
FileIDArrayIDField, // headerSourceFiles
@@ -220,7 +256,7 @@ bool readInterModuleDependenciesCache(llvm::StringRef path,
/// Returns true if there was an error.
bool writeInterModuleDependenciesCache(DiagnosticEngine &diags,
llvm::vfs::OutputBackend &backend,
llvm::StringRef path,
llvm::StringRef outputPath,
const ModuleDependenciesCache &cache);
/// Tries to write out the given dependency cache with the given

View File

@@ -356,11 +356,6 @@ DependencyScanningTool::getDependencies(
return BatchScanResults;
}
void DependencyScanningTool::resetCache() {
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
ScanningService.reset(new SwiftDependencyScanningService());
}
std::vector<
DependencyScanDiagnosticCollector::ScannerDiagnosticInfo>
DependencyScanningTool::getDiagnostics() {

View File

@@ -158,7 +158,12 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
unsigned currentContextHashID;
std::vector<ScannerImportStatementInfo> currentModuleImports;
std::vector<ScannerImportStatementInfo> currentOptionalModuleImports;
std::vector<ModuleDependencyID> currentModuleDependencyIDs;
std::vector<ModuleDependencyID> importedSwiftDependenciesIDs;
std::vector<ModuleDependencyID> importedClangDependenciesIDs;
std::vector<ModuleDependencyID> crossImportOverlayDependenciesIDs;
std::vector<ModuleDependencyID> swiftOverlayDependenciesIDs;
std::vector<std::string> auxiliaryFiles;
while (!Cursor.AtEndOfStream()) {
auto entry = cantFail(Cursor.advance(), "Advance bitstream cursor");
@@ -207,32 +212,58 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
hasCurrentModule = true;
unsigned moduleNameID, contextHashID,
moduleImportsArrayID, optionalModuleImportsArrayID,
moduleDependencyIDArrayID;
importedSwiftDependenciesIDsArrayID,
importedClangDependenciesIDsArrayID,
crossImportOverlayDependenciesIDsArrayID,
swiftOverlayDependenciesIDsArrayID,
moduleCacheKeyID, AuxiliaryFilesArrayID;
ModuleInfoLayout::readRecord(Scratch, moduleNameID, contextHashID,
moduleImportsArrayID,
optionalModuleImportsArrayID,
moduleDependencyIDArrayID);
importedSwiftDependenciesIDsArrayID,
importedClangDependenciesIDsArrayID,
crossImportOverlayDependenciesIDsArrayID,
swiftOverlayDependenciesIDsArrayID,
moduleCacheKeyID, AuxiliaryFilesArrayID);
auto moduleName = getIdentifier(moduleNameID);
if (!moduleName)
llvm::report_fatal_error("Bad module name");
currentModuleName = *moduleName;
currentContextHashID = contextHashID;
auto importStrings = getStringArray(moduleImportsArrayID);
auto optionalImportStrings = getStringArray(optionalModuleImportsArrayID);
if (importStrings.has_value()) {
if (importStrings.has_value())
for (const auto &is : importStrings.value())
currentModuleImports.push_back(is);
}
if (optionalImportStrings.has_value()) {
if (optionalImportStrings.has_value())
for (const auto &ois : optionalImportStrings.value())
currentOptionalModuleImports.push_back(ois);
}
auto optionalCurrentModuleDependencyIDs = getModuleDependencyIDArray(moduleDependencyIDArrayID);
if (!optionalCurrentModuleDependencyIDs)
llvm::report_fatal_error("Bad direct dependencies: no qualified dependencies");
currentModuleDependencyIDs = optionalCurrentModuleDependencyIDs.value();
auto optionalAuxiliaryFiles = getStringArray(AuxiliaryFilesArrayID);
if (optionalAuxiliaryFiles.has_value())
for (const auto &af : optionalAuxiliaryFiles.value())
auxiliaryFiles.push_back(af);
auto optionalImportedSwiftDependenciesIDs = getModuleDependencyIDArray(importedSwiftDependenciesIDsArrayID);
if (!optionalImportedSwiftDependenciesIDs)
llvm::report_fatal_error("Bad direct Swift dependencies: no qualified dependencies");
importedSwiftDependenciesIDs = optionalImportedSwiftDependenciesIDs.value();
auto optionalImportedClangDependenciesIDs = getModuleDependencyIDArray(importedClangDependenciesIDsArrayID);
if (!optionalImportedClangDependenciesIDs)
llvm::report_fatal_error("Bad direct Clang dependencies: no qualified dependencies");
importedClangDependenciesIDs = optionalImportedClangDependenciesIDs.value();
auto optionalCrossImportOverlayDependenciesIDs = getModuleDependencyIDArray(crossImportOverlayDependenciesIDsArrayID);
if (!optionalCrossImportOverlayDependenciesIDs)
llvm::report_fatal_error("Bad Cross-Import Overlay dependencies: no qualified dependencies");
crossImportOverlayDependenciesIDs = optionalCrossImportOverlayDependenciesIDs.value();
auto optionalSwiftOverlayDependenciesIDs = getModuleDependencyIDArray(swiftOverlayDependenciesIDsArrayID);
if (!optionalSwiftOverlayDependenciesIDs)
llvm::report_fatal_error("Bad Swift Overlay dependencies: no qualified dependencies");
swiftOverlayDependenciesIDs = optionalSwiftOverlayDependenciesIDs.value();
break;
}
@@ -244,7 +275,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
bridgingModuleDependenciesArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID,
userModuleVersionID;
SwiftInterfaceModuleDetailsLayout::readRecord(
@@ -252,7 +283,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
bridgingModuleDependenciesArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID, userModuleVersionID);
auto outputModulePath = getIdentifier(outputPathFileID);
@@ -315,16 +346,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
moduleDep.addOptionalModuleImport(moduleName.importIdentifier);
// Add qualified dependencies of this module
std::vector<ModuleDependencyID> swiftDeps;
std::vector<ModuleDependencyID> clangDeps;
for (const auto &mID : currentModuleDependencyIDs) {
if (mID.Kind == ModuleDependencyKind::Clang)
clangDeps.push_back(mID);
else
swiftDeps.push_back(mID);
}
moduleDep.setImportedSwiftDependencies(swiftDeps);
moduleDep.setImportedClangDependencies(clangDeps);
moduleDep.setImportedSwiftDependencies(importedSwiftDependenciesIDs);
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
moduleDep.setCrossImportOverlayDependencies(crossImportOverlayDependenciesIDs);
moduleDep.setSwiftOverlayDependencies(swiftOverlayDependenciesIDs);
moduleDep.setAuxiliaryFiles(auxiliaryFiles);
// Add bridging header file path
if (bridgingHeaderFileID != 0) {
@@ -360,12 +386,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
bridgingModuleDepIDs.push_back(ModuleDependencyID{mod, ModuleDependencyKind::Clang});
moduleDep.setHeaderClangDependencies(bridgingModuleDepIDs);
// Add Swift overlay dependencies
auto overlayModuleDependencyIDs = getModuleDependencyIDArray(overlayDependencyIDArrayID);
if (!overlayModuleDependencyIDs.has_value())
llvm::report_fatal_error("Bad overlay dependencies: no qualified dependencies");
moduleDep.setSwiftOverlayDependencies(overlayModuleDependencyIDs.value());
// Add bridging header include tree
auto bridgingHeaderIncludeTree =
getIdentifier(bridgingHeaderIncludeTreeID);
@@ -390,13 +410,13 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
"SWIFT_SOURCE_MODULE_DETAILS_NODE record");
unsigned extraPCMArgsArrayID, bridgingHeaderFileID, sourceFilesArrayID,
bridgingSourceFilesArrayID, bridgingModuleDependenciesArrayID,
overlayDependencyIDArrayID, CASFileSystemRootID,
CASFileSystemRootID,
bridgingHeaderIncludeTreeID, buildCommandLineArrayID,
bridgingHeaderBuildCommandLineArrayID;
SwiftSourceModuleDetailsLayout::readRecord(
Scratch, extraPCMArgsArrayID, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
bridgingModuleDependenciesArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID,
buildCommandLineArrayID, bridgingHeaderBuildCommandLineArrayID);
@@ -429,13 +449,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
*rootFileSystemID, buildCommandRefs, bridgingHeaderBuildCommandRefs,
extraPCMRefs);
// Add dependencies of this module
// Add imports of this module
for (const auto &moduleName : currentModuleImports)
moduleDep.addModuleImport(moduleName.importIdentifier);
// Add optional imports of this module
for (const auto &moduleName : currentOptionalModuleImports)
moduleDep.addOptionalModuleImport(moduleName.importIdentifier);
// Add qualified dependencies of this module
moduleDep.setImportedSwiftDependencies(importedSwiftDependenciesIDs);
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
moduleDep.setCrossImportOverlayDependencies(crossImportOverlayDependenciesIDs);
moduleDep.setSwiftOverlayDependencies(swiftOverlayDependenciesIDs);
// Add bridging header file path
if (bridgingHeaderFileID != 0) {
auto bridgingHeaderFile = getIdentifier(bridgingHeaderFileID);
@@ -470,12 +496,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
headerDependencyIDs.push_back({mod, ModuleDependencyKind::Clang});
moduleDep.setHeaderClangDependencies(headerDependencyIDs);
// Add Swift overlay dependencies
auto overlayModuleDependencyIDs = getModuleDependencyIDArray(overlayDependencyIDArrayID);
if (!overlayModuleDependencyIDs.has_value())
llvm::report_fatal_error("Bad overlay dependencies: no qualified dependencies");
moduleDep.setSwiftOverlayDependencies(overlayModuleDependencyIDs.value());
// Add bridging header include tree
auto bridgingHeaderIncludeTree =
getIdentifier(bridgingHeaderIncludeTreeID);
@@ -494,13 +514,13 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
llvm::report_fatal_error(
"Unexpected SWIFT_BINARY_MODULE_DETAILS_NODE record");
unsigned compiledModulePathID, moduleDocPathID, moduleSourceInfoPathID,
overlayDependencyIDArrayID, headerImportID,
headerImportID,
headerModuleDependenciesArrayID,
headerImportsSourceFilesArrayID, isFramework, isStatic,
moduleCacheKeyID, userModuleVersionID;
SwiftBinaryModuleDetailsLayout::readRecord(
Scratch, compiledModulePathID, moduleDocPathID,
moduleSourceInfoPathID, overlayDependencyIDArrayID,
moduleSourceInfoPathID,
headerImportID, headerModuleDependenciesArrayID,
headerImportsSourceFilesArrayID, isFramework, isStatic,
moduleCacheKeyID, userModuleVersionID);
@@ -531,6 +551,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
currentModuleImports, currentOptionalModuleImports, {},
*headerImport, "", isFramework, isStatic, *moduleCacheKey, *userModuleVersion);
// Add imports of this module
for (const auto &moduleName : currentModuleImports)
moduleDep.addModuleImport(moduleName.importIdentifier);
// Add optional imports of this module
for (const auto &moduleName : currentOptionalModuleImports)
moduleDep.addOptionalModuleImport(moduleName.importIdentifier);
// Add qualified dependencies of this module
moduleDep.setImportedSwiftDependencies(importedSwiftDependenciesIDs);
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
moduleDep.setCrossImportOverlayDependencies(crossImportOverlayDependenciesIDs);
moduleDep.setSwiftOverlayDependencies(swiftOverlayDependenciesIDs);
auto headerModuleDependencies = getStringArray(headerModuleDependenciesArrayID);
if (!headerModuleDependencies)
llvm::report_fatal_error("Bad binary direct dependencies: no header import module dependencies");
@@ -549,12 +582,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
for (const auto &depSource : *headerImportsSourceFiles)
moduleDep.addHeaderSourceFile(depSource);
// Add Swift overlay dependencies
auto overlayModuleDependencyIDs = getModuleDependencyIDArray(overlayDependencyIDArrayID);
if (!overlayModuleDependencyIDs.has_value())
llvm::report_fatal_error("Bad overlay dependencies: no qualified dependencies");
moduleDep.setSwiftOverlayDependencies(*overlayModuleDependencyIDs);
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
break;
@@ -583,6 +610,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
auto moduleDep = ModuleDependencyInfo::forPlaceholderSwiftModuleStub(
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath);
// Add dependencies of this module
for (const auto &moduleName : currentModuleImports)
moduleDep.addModuleImport(moduleName.importIdentifier);
@@ -644,12 +672,11 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
*commandLineArgs, *fileDependencies, *capturedPCMArgs, {},
*rootFileSystemID, *clangIncludeTreeRoot, *moduleCacheKey, isSystem);
// Add dependencies of this module
// Add imports of this module
for (const auto &moduleName : currentModuleImports)
moduleDep.addModuleImport(moduleName.importIdentifier);
// Add optional imports of this module
for (const auto &moduleName : currentOptionalModuleImports)
moduleDep.addOptionalModuleImport(moduleName.importIdentifier);
// Add qualified dependencies of this module
moduleDep.setImportedClangDependencies(importedClangDependenciesIDs);
cache.recordDependency(currentModuleName, std::move(moduleDep));
hasCurrentModule = false;
@@ -780,7 +807,11 @@ enum ModuleIdentifierArrayKind : uint8_t {
DependencyImports,
OptionalDependencyImports,
DependencyHeaders,
QualifiedModuleDependencyIDs,
ImportedSwiftDependenciesIDs,
ImportedClangDependenciesIDs,
CrossImportOverlayDependenciesIDs,
SwiftOverlayDependenciesIDs,
AuxiliaryFileIDs,
CompiledModuleCandidates,
BuildCommandLine,
ExtraPCMArgs,
@@ -789,7 +820,6 @@ enum ModuleIdentifierArrayKind : uint8_t {
BridgingModuleDependencies,
HeaderInputDependencySourceFiles,
HeaderInputModuleDependencies,
SwiftOverlayDependencyIDs,
BridgingHeaderBuildCommandLine,
NonPathCommandLine,
FileDependencies,
@@ -851,7 +881,7 @@ class ModuleDependenciesCacheSerializer {
const std::vector<std::string> &vec);
void addDependencyIDArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<ModuleDependencyID> &vec);
const ArrayRef<ModuleDependencyID> vec);
unsigned getArrayID(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind) const;
@@ -979,7 +1009,12 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifier(moduleID.ModuleName), contextHashStrID,
getArrayID(moduleID, ModuleIdentifierArrayKind::DependencyImports),
getArrayID(moduleID, ModuleIdentifierArrayKind::OptionalDependencyImports),
getArrayID(moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs));
getArrayID(moduleID, ModuleIdentifierArrayKind::ImportedSwiftDependenciesIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::ImportedClangDependenciesIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::CrossImportOverlayDependenciesIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependenciesIDs),
getIdentifier(dependencyInfo.getModuleCacheKey()),
getArrayID(moduleID, ModuleIdentifierArrayKind::AuxiliaryFileIDs));
switch (dependencyInfo.getKind()) {
case swift::ModuleDependencyKind::SwiftInterface: {
@@ -1008,8 +1043,6 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies),
getArrayID(moduleID,
ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs),
getIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftTextDeps->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID),
@@ -1033,8 +1066,6 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getArrayID(moduleID, ModuleIdentifierArrayKind::BridgingSourceFiles),
getArrayID(moduleID,
ModuleIdentifierArrayKind::BridgingModuleDependencies),
getArrayID(moduleID,
ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs),
getIdentifier(
swiftSourceDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftSourceDeps->textualModuleDetails
@@ -1052,7 +1083,6 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifier(swiftBinDeps->compiledModulePath),
getIdentifier(swiftBinDeps->moduleDocPath),
getIdentifier(swiftBinDeps->sourceInfoPath),
getArrayID(moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs),
getArrayID(moduleID, ModuleIdentifierArrayKind::DependencyHeaders),
getArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputModuleDependencies),
getArrayID(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles),
@@ -1125,7 +1155,7 @@ unsigned ModuleDependenciesCacheSerializer::getIdentifier(const std::string &str
void ModuleDependenciesCacheSerializer::addDependencyIDArray(ModuleDependencyID moduleID,
ModuleIdentifierArrayKind arrayKind,
const std::vector<ModuleDependencyID> &vec) {
const ArrayRef<ModuleDependencyID> vec) {
std::vector<std::string> encodedDependencyIDs;
for (const auto &moduleID : vec)
encodedDependencyIDs.push_back(createEncodedModuleKindAndName(moduleID));
@@ -1230,10 +1260,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
allDependencies.insert(clangImportedDepsRef.begin(),
clangImportedDepsRef.end());
addDependencyIDArray(
moduleID, ModuleIdentifierArrayKind::QualifiedModuleDependencyIDs,
allDependencies.getArrayRef());
std::vector<std::string> clangHeaderDependencyNames;
for (const auto &headerDepID :
dependencyInfo->getHeaderClangDependencies())
@@ -1264,9 +1290,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
clangHeaderDependencyNames);
addDependencyIDArray(
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs,
swiftTextDeps->swiftOverlayDependencies);
addIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID);
addIdentifier(swiftTextDeps->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID);
@@ -1285,9 +1308,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
clangHeaderDependencyNames);
addStringArray(moduleID, ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles,
swiftBinDeps->headerSourceFiles);
addDependencyIDArray(
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs,
swiftBinDeps->swiftOverlayDependencies);
break;
}
case swift::ModuleDependencyKind::SwiftPlaceholder: {
@@ -1315,9 +1335,6 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
addStringArray(
moduleID, ModuleIdentifierArrayKind::BridgingModuleDependencies,
clangHeaderDependencyNames);
addDependencyIDArray(
moduleID, ModuleIdentifierArrayKind::SwiftOverlayDependencyIDs,
swiftSourceDeps->swiftOverlayDependencies);
addStringArray(
moduleID, ModuleIdentifierArrayKind::BuildCommandLine,
swiftSourceDeps->textualModuleDetails.buildCommandLine);
@@ -1367,6 +1384,9 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
registerRecordAbbr<MetadataLayout>();
registerRecordAbbr<IdentifierNodeLayout>();
registerRecordAbbr<IdentifierArrayLayout>();
registerRecordAbbr<LinkLibraryLayout>();
registerRecordAbbr<SourceLocationLayout>();
registerRecordAbbr<ImportStatementLayout>();
registerRecordAbbr<ModuleInfoLayout>();
registerRecordAbbr<SwiftSourceModuleDetailsLayout>();
registerRecordAbbr<SwiftInterfaceModuleDetailsLayout>();
@@ -1413,10 +1433,10 @@ bool swift::dependencies::module_dependency_cache_serialization::
PrettyStackTraceStringAction stackTrace(
"saving inter-module dependency graph", path);
return withOutputPath(diags, backend, path, [&](llvm::raw_ostream &out) {
SmallVector<char, 0> Buffer;
llvm::BitstreamWriter Writer{Buffer};
writeInterModuleDependenciesCache(Writer, cache);
out.write(Buffer.data(), Buffer.size());
SmallVector<char, 0> buffer;
llvm::BitstreamWriter writer{buffer};
writeInterModuleDependenciesCache(writer, cache);
out.write(buffer.data(), buffer.size());
out.flush();
return false;
});

View File

@@ -1275,66 +1275,36 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
}
} // namespace
static void serializeDependencyCache(CompilerInstance &instance,
const ModuleDependenciesCache &cache) {
const FrontendOptions &opts = instance.getInvocation().getFrontendOptions();
ASTContext &Context = instance.getASTContext();
auto savePath = opts.SerializedDependencyScannerCachePath;
module_dependency_cache_serialization::writeInterModuleDependenciesCache(
Context.Diags, instance.getOutputBackend(), savePath, cache);
if (opts.EmitDependencyScannerCacheRemarks) {
Context.Diags.diagnose(SourceLoc(), diag::remark_save_cache, savePath);
}
}
static void deserializeDependencyCache(CompilerInstance &instance,
ModuleDependenciesCache &cache) {
const FrontendOptions &opts = instance.getInvocation().getFrontendOptions();
ASTContext &Context = instance.getASTContext();
auto loadPath = opts.SerializedDependencyScannerCachePath;
if (module_dependency_cache_serialization::readInterModuleDependenciesCache(
loadPath, cache)) {
Context.Diags.diagnose(SourceLoc(), diag::warn_scanner_deserialize_failed,
loadPath);
} else if (opts.EmitDependencyScannerCacheRemarks) {
Context.Diags.diagnose(SourceLoc(), diag::remark_reuse_cache, loadPath);
}
}
bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
ASTContext &Context = instance.getASTContext();
const FrontendOptions &opts = instance.getInvocation().getFrontendOptions();
std::string path = opts.InputsAndOutputs.getSingleOutputFilename();
bool swift::dependencies::scanDependencies(CompilerInstance &CI) {
ASTContext &ctx = CI.getASTContext();
const FrontendOptions &opts = CI.getInvocation().getFrontendOptions();
std::string depGraphOutputPath = opts.InputsAndOutputs.getSingleOutputFilename();
// `-scan-dependencies` invocations use a single new instance
// of a module cache
SwiftDependencyScanningService *service = Context.Allocate<SwiftDependencyScanningService>();
SwiftDependencyScanningService *service = ctx.Allocate<SwiftDependencyScanningService>();
ModuleDependenciesCache cache(
*service, instance.getMainModule()->getNameStr().str(),
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
instance.getInvocation().getModuleScanningHash());
*service, CI.getMainModule()->getNameStr().str(),
CI.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
CI.getInvocation().getModuleScanningHash());
if (opts.ReuseDependencyScannerCache)
deserializeDependencyCache(instance, cache);
// ACTODO: Deserialize cache
if (service->setupCachingDependencyScanningService(instance))
if (service->setupCachingDependencyScanningService(CI))
return true;
// Execute scan
llvm::ErrorOr<swiftscan_dependency_graph_t> dependenciesOrErr =
performModuleScan(instance, nullptr, cache);
performModuleScan(CI, nullptr, cache);
// Serialize the dependency cache if -serialize-dependency-scan-cache
// is specified
if (opts.SerializeDependencyScannerCache)
serializeDependencyCache(instance, cache);
// ACTODO: Serialize cache
if (dependenciesOrErr.getError())
return true;
auto dependencies = std::move(*dependenciesOrErr);
if (writeJSONToOutput(Context.Diags, instance.getOutputBackend(), path,
if (writeJSONToOutput(ctx.Diags, CI.getOutputBackend(), depGraphOutputPath,
dependencies))
return true;
@@ -1342,7 +1312,7 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
// FIXME: We shouldn't need this, but it's masking bugs in our scanning
// logic where we don't create a fresh context when scanning Swift interfaces
// that includes their own command-line flags.
Context.Diags.resetHadAnyError();
ctx.Diags.resetHadAnyError();
return false;
}

View File

@@ -143,13 +143,6 @@ void swiftscan_dependency_set_dispose(swiftscan_dependency_set_t *set) {
}
}
//=== Scanner Cache Operations --------------------------------------------===//
void swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner) {
DependencyScanningTool *ScanningTool = unwrap(scanner);
ScanningTool->resetCache();
}
//=== Scanner Functions ---------------------------------------------------===//
swiftscan_scanner_t swiftscan_scanner_create(void) {

View File

@@ -77,7 +77,6 @@ swiftscan_compiler_supported_arguments_query
swiftscan_compiler_supported_features_query
swiftscan_compiler_target_info_query
swiftscan_compiler_target_info_query_v2
swiftscan_scanner_cache_reset
swiftscan_scanner_diagnostics_query
swiftscan_scanner_diagnostics_reset
swiftscan_diagnostic_get_message