Skip to content

Commit 25d32fc

Browse files
committed
[Dependency Scanning] Add import statement source locations to the dependency scanner cache serialization format
1 parent 8399267 commit 25d32fc

File tree

5 files changed

+582
-312
lines changed

5 files changed

+582
-312
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,6 @@ class ModuleDependencyInfoStorageBase {
176176
public:
177177
const ModuleDependencyKind dependencyKind;
178178

179-
ModuleDependencyInfoStorageBase(ModuleDependencyKind dependencyKind,
180-
ArrayRef<LinkLibrary> linkLibraries,
181-
StringRef moduleCacheKey = "")
182-
: dependencyKind(dependencyKind), linkLibraries(linkLibraries),
183-
moduleCacheKey(moduleCacheKey.str()),
184-
finalized(false) {}
185-
186179
ModuleDependencyInfoStorageBase(
187180
ModuleDependencyKind dependencyKind,
188181
ArrayRef<ScannerImportStatementInfo> moduleImports,
@@ -303,11 +296,14 @@ class SwiftInterfaceModuleDependenciesStorage
303296
SwiftInterfaceModuleDependenciesStorage(
304297
StringRef moduleOutputPath, StringRef swiftInterfaceFile,
305298
ArrayRef<StringRef> compiledModuleCandidates,
299+
ArrayRef<ScannerImportStatementInfo> moduleImports,
300+
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
306301
ArrayRef<StringRef> buildCommandLine, ArrayRef<LinkLibrary> linkLibraries,
307302
ArrayRef<StringRef> extraPCMArgs, StringRef contextHash, bool isFramework,
308303
bool isStatic, StringRef RootID, StringRef moduleCacheKey,
309304
StringRef userModuleVersion)
310305
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
306+
moduleImports, optionalModuleImports,
311307
linkLibraries, moduleCacheKey),
312308
moduleOutputPath(moduleOutputPath),
313309
swiftInterfaceFile(swiftInterfaceFile),
@@ -350,9 +346,12 @@ class SwiftSourceModuleDependenciesStorage
350346

351347
SwiftSourceModuleDependenciesStorage(
352348
StringRef RootID, ArrayRef<StringRef> buildCommandLine,
349+
ArrayRef<ScannerImportStatementInfo> moduleImports,
350+
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
353351
ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
354352
ArrayRef<StringRef> extraPCMArgs)
355-
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource, {}),
353+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource,
354+
moduleImports, optionalModuleImports, {}),
356355
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
357356
testableImports(llvm::StringSet<>()),
358357
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
@@ -500,6 +499,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
500499
StringRef clangIncludeTreeRoot,
501500
StringRef moduleCacheKey, bool IsSystem)
502501
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang,
502+
{}, {},
503503
linkLibraries, moduleCacheKey),
504504
pcmOutputPath(pcmOutputPath), mappedPCMPath(mappedPCMPath),
505505
moduleMapFile(moduleMapFile), contextHash(contextHash),
@@ -531,7 +531,7 @@ class SwiftPlaceholderModuleDependencyStorage
531531
SwiftPlaceholderModuleDependencyStorage(StringRef compiledModulePath,
532532
StringRef moduleDocPath,
533533
StringRef sourceInfoPath)
534-
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder,
534+
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder, {}, {},
535535
{}),
536536
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
537537
sourceInfoPath(sourceInfoPath) {}
@@ -586,13 +586,16 @@ class ModuleDependencyInfo {
586586
static ModuleDependencyInfo forSwiftInterfaceModule(
587587
StringRef moduleOutputPath, StringRef swiftInterfaceFile,
588588
ArrayRef<StringRef> compiledCandidates, ArrayRef<StringRef> buildCommands,
589+
ArrayRef<ScannerImportStatementInfo> moduleImports,
590+
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
589591
ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> extraPCMArgs,
590592
StringRef contextHash, bool isFramework, bool isStatic,
591593
StringRef CASFileSystemRootID, StringRef moduleCacheKey,
592594
StringRef userModuleVersion) {
593595
return ModuleDependencyInfo(
594596
std::make_unique<SwiftInterfaceModuleDependenciesStorage>(
595597
moduleOutputPath, swiftInterfaceFile, compiledCandidates,
598+
moduleImports, optionalModuleImports,
596599
buildCommands, linkLibraries, extraPCMArgs, contextHash,
597600
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey,
598601
userModuleVersion));
@@ -619,11 +622,14 @@ class ModuleDependencyInfo {
619622
static ModuleDependencyInfo
620623
forSwiftSourceModule(const std::string &CASFileSystemRootID,
621624
ArrayRef<StringRef> buildCommands,
625+
ArrayRef<ScannerImportStatementInfo> moduleImports,
626+
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
622627
ArrayRef<StringRef> bridgingHeaderBuildCommands,
623628
ArrayRef<StringRef> extraPCMArgs) {
624629
return ModuleDependencyInfo(
625630
std::make_unique<SwiftSourceModuleDependenciesStorage>(
626-
CASFileSystemRootID, buildCommands, bridgingHeaderBuildCommands,
631+
CASFileSystemRootID, buildCommands, moduleImports,
632+
optionalModuleImports, bridgingHeaderBuildCommands,
627633
extraPCMArgs));
628634
}
629635

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ using IsSystemField = BCFixed<1>;
5858
using IsStaticField = BCFixed<1>;
5959
/// A bit taht indicates whether or not a link library is a force-load one
6060
using IsForceLoadField = BCFixed<1>;
61+
/// A bit taht indicates whether or not an import statement is optional
62+
using IsOptionalImport = BCFixed<1>;
6163

6264
/// Source location fields
6365
using LineNumberField = BCFixed<32>;
@@ -97,8 +99,9 @@ enum {
9799
LINK_LIBRARY_ARRAY_NODE,
98100
MACRO_DEPENDENCY_NODE,
99101
MACRO_DEPENDENCY_ARRAY_NODE,
100-
SOURCE_LOCATION_NODE,
101102
IMPORT_STATEMENT_NODE,
103+
IMPORT_STATEMENT_ARRAY_NODE,
104+
OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE,
102105
SWIFT_INTERFACE_MODULE_DETAILS_NODE,
103106
SWIFT_SOURCE_MODULE_DETAILS_NODE,
104107
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
@@ -158,19 +161,19 @@ using MacroDependencyArrayLayout =
158161
BCRecordLayout<MACRO_DEPENDENCY_ARRAY_NODE, IdentifierIDArryField>;
159162

160163
// ACTODO: Comment
161-
using SourceLocationLayout =
162-
BCRecordLayout<LINK_LIBRARY_NODE, // ID
164+
using ImportStatementLayout =
165+
BCRecordLayout<IMPORT_STATEMENT_NODE, // ID
166+
IdentifierIDField, // importIdentifier
163167
IdentifierIDField, // bufferIdentifier
164168
LineNumberField, // lineNumber
165-
ColumnNumberField // columnNumber
169+
ColumnNumberField, // columnNumber
170+
IsOptionalImport // isOptional
166171
>;
167-
168172
// ACTODO: Comment
169-
using ImportStatementLayout =
170-
BCRecordLayout<LINK_LIBRARY_NODE, // ID
171-
IdentifierIDField, // importIdentifier
172-
SourceLocationIDArrayIDField // importLocations
173-
>;
173+
using ImportStatementArrayLayout =
174+
BCRecordLayout<IMPORT_STATEMENT_ARRAY_NODE, IdentifierIDArryField>;
175+
using OptionalImportStatementArrayLayout =
176+
BCRecordLayout<OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE, IdentifierIDArryField>;
174177

175178
// After the array records, we have a sequence of Module info
176179
// records, each of which is followed by one of:
@@ -182,8 +185,8 @@ using ImportStatementLayout =
182185
using ModuleInfoLayout =
183186
BCRecordLayout<MODULE_NODE, // ID
184187
IdentifierIDField, // moduleName
185-
ImportArrayIDField, // moduleImports
186-
ImportArrayIDField, // optionalModuleImports
188+
ImportArrayIDField, // imports
189+
ImportArrayIDField, // optionalImports
187190
LinkLibrariesArrayIDField, // linkLibraries
188191
MacroDependenciesArrayIDField, // macroDependencies
189192
DependencyIDArrayIDField, // importedSwiftModules

0 commit comments

Comments
 (0)