Skip to content

Commit a46e331

Browse files
committed
[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.
1 parent 06e7b6f commit a46e331

File tree

9 files changed

+164
-155
lines changed

9 files changed

+164
-155
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,6 @@ swiftscan_source_location_get_line_number(swiftscan_source_location_t source_loc
475475
SWIFTSCAN_PUBLIC int64_t
476476
swiftscan_source_location_get_column_number(swiftscan_source_location_t source_location);
477477

478-
//=== Scanner Cache Operations --------------------------------------------===//
479-
// The following operations expose an implementation detail of the dependency
480-
// scanner: its module dependencies cache. This is done in order
481-
// to allow clients to perform incremental dependency scans by having the
482-
// scanner's state be serializable and re-usable.
483-
484-
/// For the specified \c scanner instance, reset its internal state, ensuring subsequent
485-
/// scanning queries are done "from-scratch".
486-
SWIFTSCAN_PUBLIC void
487-
swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
488-
489478
/// An entry point to invoke the compiler via a library call.
490479
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);
491480

include/swift/AST/ModuleDependencies.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,15 @@ class ModuleDependencyInfo {
769769
setLinkLibraries(const ArrayRef<LinkLibrary> linkLibraries) {
770770
storage->linkLibraries.assign(linkLibraries.begin(), linkLibraries.end());
771771
}
772+
773+
const ArrayRef<std::string> getAuxiliaryFiles() const {
774+
return storage->auxiliaryFiles;
775+
}
776+
777+
void
778+
setAuxiliaryFiles(const ArrayRef<std::string> auxiliaryFiles) {
779+
storage->auxiliaryFiles.assign(auxiliaryFiles.begin(), auxiliaryFiles.end());
780+
}
772781

773782
bool isStaticLibrary() const {
774783
if (auto *detail = getAsSwiftInterfaceModule())

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class DependencyScanningTool {
108108
const llvm::StringSet<> &PlaceholderModules,
109109
StringRef WorkingDirectory);
110110

111-
/// Discard the tool's current `SharedCache` and start anew.
112-
void resetCache();
113111
/// Query diagnostics consumed so far.
114112
std::vector<DependencyScanDiagnosticCollector::ScannerDiagnosticInfo> getDiagnostics();
115113
/// Discared the collection of diagnostics encountered so far.

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ using IsFrameworkField = BCFixed<1>;
5757
using IsSystemField = BCFixed<1>;
5858
/// A bit that indicates whether or not a module is that of a static archive
5959
using IsStaticField = BCFixed<1>;
60+
/// A bit taht indicates whether or not a link library is a force-load one
61+
using IsForceLoadField = BCFixed<1>;
62+
63+
/// Source location fields
64+
using LineNumberField = BCFixed<32>;
65+
using ColumnNumberField = BCFixed<32>;
6066

6167
/// Arrays of various identifiers, distinguished for readability
6268
using IdentifierIDArryField = llvm::BCArray<IdentifierIDField>;
@@ -65,9 +71,12 @@ using ModuleIDArryField = llvm::BCArray<IdentifierIDField>;
6571
/// Identifiers used to refer to the above arrays
6672
using FileIDArrayIDField = IdentifierIDField;
6773
using ContextHashIDField = IdentifierIDField;
74+
using ModuleCacheKeyIDField = IdentifierIDField;
6875
using ImportArrayIDField = IdentifierIDField;
6976
using FlagIDArrayIDField = IdentifierIDField;
7077
using DependencyIDArrayIDField = IdentifierIDField;
78+
using AuxiliaryFilesArrayIDField = IdentifierIDField;
79+
using SourceLocationIDArrayIDField = IdentifierIDField;
7180

7281
/// The ID of the top-level block containing the dependency graph
7382
const unsigned GRAPH_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
@@ -81,6 +90,9 @@ namespace graph_block {
8190
enum {
8291
METADATA = 1,
8392
MODULE_NODE,
93+
LINK_LIBRARY_NODE,
94+
SOURCE_LOCATION_NODE,
95+
IMPORT_STATEMENT_NODE,
8496
SWIFT_INTERFACE_MODULE_DETAILS_NODE,
8597
SWIFT_SOURCE_MODULE_DETAILS_NODE,
8698
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
@@ -117,6 +129,26 @@ using IdentifierNodeLayout = BCRecordLayout<IDENTIFIER_NODE, BCBlob>;
117129
using IdentifierArrayLayout =
118130
BCRecordLayout<IDENTIFIER_ARRAY_NODE, IdentifierIDArryField>;
119131

132+
using LinkLibraryLayout =
133+
BCRecordLayout<LINK_LIBRARY_NODE, // ID
134+
IdentifierIDField, // libraryName
135+
IsFrameworkField, // isFramework
136+
IsForceLoadField // forceLoad
137+
>;
138+
139+
using SourceLocationLayout =
140+
BCRecordLayout<LINK_LIBRARY_NODE, // ID
141+
IdentifierIDField, // bufferIdentifier
142+
LineNumberField, // lineNumber
143+
ColumnNumberField // columnNumber
144+
>;
145+
146+
using ImportStatementLayout =
147+
BCRecordLayout<LINK_LIBRARY_NODE, // ID
148+
IdentifierIDField, // importIdentifier
149+
SourceLocationIDArrayIDField // importLocations
150+
>;
151+
120152
// After the array records, we have a sequence of Module info
121153
// records, each of which is followed by one of:
122154
// - SwiftInterfaceModuleDetails
@@ -130,7 +162,14 @@ using ModuleInfoLayout =
130162
ContextHashIDField, // contextHash
131163
ImportArrayIDField, // moduleImports
132164
ImportArrayIDField, // optionalModuleImports
133-
DependencyIDArrayIDField // resolvedDirectModuleDependencies
165+
// ACTODO: LinkLibrariesArrayIDField, // linkLibraries
166+
DependencyIDArrayIDField, // importedSwiftModules
167+
DependencyIDArrayIDField, // importedClangModules
168+
DependencyIDArrayIDField, // crossImportOverlayModules
169+
DependencyIDArrayIDField, // swiftOverlayDependencies
170+
ModuleCacheKeyIDField, // moduleCacheKey
171+
AuxiliaryFilesArrayIDField // auxiliaryFiles
172+
// ACTODO: MacroDependenciesArrayIDField, // macroDependencies
134173
>;
135174

136175
using SwiftInterfaceModuleDetailsLayout =
@@ -147,7 +186,6 @@ using SwiftInterfaceModuleDetailsLayout =
147186
FileIDArrayIDField, // sourceFiles
148187
FileIDArrayIDField, // bridgingSourceFiles
149188
IdentifierIDField, // bridgingModuleDependencies
150-
DependencyIDArrayIDField, // swiftOverlayDependencies
151189
IdentifierIDField, // CASFileSystemRootID
152190
IdentifierIDField, // bridgingHeaderIncludeTree
153191
IdentifierIDField, // moduleCacheKey
@@ -161,7 +199,6 @@ using SwiftSourceModuleDetailsLayout =
161199
FileIDArrayIDField, // sourceFiles
162200
FileIDArrayIDField, // bridgingSourceFiles
163201
FileIDArrayIDField, // bridgingModuleDependencies
164-
DependencyIDArrayIDField, // swiftOverlayDependencies
165202
IdentifierIDField, // CASFileSystemRootID
166203
IdentifierIDField, // bridgingHeaderIncludeTree
167204
FlagIDArrayIDField, // buildCommandLine
@@ -173,7 +210,6 @@ using SwiftBinaryModuleDetailsLayout =
173210
FileIDField, // compiledModulePath
174211
FileIDField, // moduleDocPath
175212
FileIDField, // moduleSourceInfoPath
176-
DependencyIDArrayIDField, // swiftOverlayDependencies
177213
FileIDField, // headerImport
178214
IdentifierIDField, // headerModuleDependencies
179215
FileIDArrayIDField, // headerSourceFiles
@@ -220,7 +256,7 @@ bool readInterModuleDependenciesCache(llvm::StringRef path,
220256
/// Returns true if there was an error.
221257
bool writeInterModuleDependenciesCache(DiagnosticEngine &diags,
222258
llvm::vfs::OutputBackend &backend,
223-
llvm::StringRef path,
259+
llvm::StringRef outputPath,
224260
const ModuleDependenciesCache &cache);
225261

226262
/// Tries to write out the given dependency cache with the given

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,6 @@ DependencyScanningTool::getDependencies(
356356
return BatchScanResults;
357357
}
358358

359-
void DependencyScanningTool::resetCache() {
360-
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
361-
ScanningService.reset(new SwiftDependencyScanningService());
362-
}
363-
364359
std::vector<
365360
DependencyScanDiagnosticCollector::ScannerDiagnosticInfo>
366361
DependencyScanningTool::getDiagnostics() {

0 commit comments

Comments
 (0)