[Dependency Scanning] Add import statement source locations to the dependency scanner cache serialization format

This commit is contained in:
Artem Chikin
2024-12-05 10:41:30 -08:00
parent 8399267785
commit 25d32fc7a3
5 changed files with 577 additions and 307 deletions

View File

@@ -176,13 +176,6 @@ class ModuleDependencyInfoStorageBase {
public: public:
const ModuleDependencyKind dependencyKind; const ModuleDependencyKind dependencyKind;
ModuleDependencyInfoStorageBase(ModuleDependencyKind dependencyKind,
ArrayRef<LinkLibrary> linkLibraries,
StringRef moduleCacheKey = "")
: dependencyKind(dependencyKind), linkLibraries(linkLibraries),
moduleCacheKey(moduleCacheKey.str()),
finalized(false) {}
ModuleDependencyInfoStorageBase( ModuleDependencyInfoStorageBase(
ModuleDependencyKind dependencyKind, ModuleDependencyKind dependencyKind,
ArrayRef<ScannerImportStatementInfo> moduleImports, ArrayRef<ScannerImportStatementInfo> moduleImports,
@@ -303,11 +296,14 @@ public:
SwiftInterfaceModuleDependenciesStorage( SwiftInterfaceModuleDependenciesStorage(
StringRef moduleOutputPath, StringRef swiftInterfaceFile, StringRef moduleOutputPath, StringRef swiftInterfaceFile,
ArrayRef<StringRef> compiledModuleCandidates, ArrayRef<StringRef> compiledModuleCandidates,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<StringRef> buildCommandLine, ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> buildCommandLine, ArrayRef<LinkLibrary> linkLibraries,
ArrayRef<StringRef> extraPCMArgs, StringRef contextHash, bool isFramework, ArrayRef<StringRef> extraPCMArgs, StringRef contextHash, bool isFramework,
bool isStatic, StringRef RootID, StringRef moduleCacheKey, bool isStatic, StringRef RootID, StringRef moduleCacheKey,
StringRef userModuleVersion) StringRef userModuleVersion)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface, : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
moduleImports, optionalModuleImports,
linkLibraries, moduleCacheKey), linkLibraries, moduleCacheKey),
moduleOutputPath(moduleOutputPath), moduleOutputPath(moduleOutputPath),
swiftInterfaceFile(swiftInterfaceFile), swiftInterfaceFile(swiftInterfaceFile),
@@ -350,9 +346,12 @@ public:
SwiftSourceModuleDependenciesStorage( SwiftSourceModuleDependenciesStorage(
StringRef RootID, ArrayRef<StringRef> buildCommandLine, StringRef RootID, ArrayRef<StringRef> buildCommandLine,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<StringRef> bridgingHeaderBuildCommandLine, ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
ArrayRef<StringRef> extraPCMArgs) ArrayRef<StringRef> extraPCMArgs)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource, {}), : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource,
moduleImports, optionalModuleImports, {}),
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID), textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
testableImports(llvm::StringSet<>()), testableImports(llvm::StringSet<>()),
bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(), bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
@@ -500,6 +499,7 @@ public:
StringRef clangIncludeTreeRoot, StringRef clangIncludeTreeRoot,
StringRef moduleCacheKey, bool IsSystem) StringRef moduleCacheKey, bool IsSystem)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang, : ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang,
{}, {},
linkLibraries, moduleCacheKey), linkLibraries, moduleCacheKey),
pcmOutputPath(pcmOutputPath), mappedPCMPath(mappedPCMPath), pcmOutputPath(pcmOutputPath), mappedPCMPath(mappedPCMPath),
moduleMapFile(moduleMapFile), contextHash(contextHash), moduleMapFile(moduleMapFile), contextHash(contextHash),
@@ -531,7 +531,7 @@ public:
SwiftPlaceholderModuleDependencyStorage(StringRef compiledModulePath, SwiftPlaceholderModuleDependencyStorage(StringRef compiledModulePath,
StringRef moduleDocPath, StringRef moduleDocPath,
StringRef sourceInfoPath) StringRef sourceInfoPath)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder, : ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder, {}, {},
{}), {}),
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath), compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
sourceInfoPath(sourceInfoPath) {} sourceInfoPath(sourceInfoPath) {}
@@ -586,6 +586,8 @@ public:
static ModuleDependencyInfo forSwiftInterfaceModule( static ModuleDependencyInfo forSwiftInterfaceModule(
StringRef moduleOutputPath, StringRef swiftInterfaceFile, StringRef moduleOutputPath, StringRef swiftInterfaceFile,
ArrayRef<StringRef> compiledCandidates, ArrayRef<StringRef> buildCommands, ArrayRef<StringRef> compiledCandidates, ArrayRef<StringRef> buildCommands,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> extraPCMArgs, ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> extraPCMArgs,
StringRef contextHash, bool isFramework, bool isStatic, StringRef contextHash, bool isFramework, bool isStatic,
StringRef CASFileSystemRootID, StringRef moduleCacheKey, StringRef CASFileSystemRootID, StringRef moduleCacheKey,
@@ -593,6 +595,7 @@ public:
return ModuleDependencyInfo( return ModuleDependencyInfo(
std::make_unique<SwiftInterfaceModuleDependenciesStorage>( std::make_unique<SwiftInterfaceModuleDependenciesStorage>(
moduleOutputPath, swiftInterfaceFile, compiledCandidates, moduleOutputPath, swiftInterfaceFile, compiledCandidates,
moduleImports, optionalModuleImports,
buildCommands, linkLibraries, extraPCMArgs, contextHash, buildCommands, linkLibraries, extraPCMArgs, contextHash,
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey, isFramework, isStatic, CASFileSystemRootID, moduleCacheKey,
userModuleVersion)); userModuleVersion));
@@ -619,11 +622,14 @@ public:
static ModuleDependencyInfo static ModuleDependencyInfo
forSwiftSourceModule(const std::string &CASFileSystemRootID, forSwiftSourceModule(const std::string &CASFileSystemRootID,
ArrayRef<StringRef> buildCommands, ArrayRef<StringRef> buildCommands,
ArrayRef<ScannerImportStatementInfo> moduleImports,
ArrayRef<ScannerImportStatementInfo> optionalModuleImports,
ArrayRef<StringRef> bridgingHeaderBuildCommands, ArrayRef<StringRef> bridgingHeaderBuildCommands,
ArrayRef<StringRef> extraPCMArgs) { ArrayRef<StringRef> extraPCMArgs) {
return ModuleDependencyInfo( return ModuleDependencyInfo(
std::make_unique<SwiftSourceModuleDependenciesStorage>( std::make_unique<SwiftSourceModuleDependenciesStorage>(
CASFileSystemRootID, buildCommands, bridgingHeaderBuildCommands, CASFileSystemRootID, buildCommands, moduleImports,
optionalModuleImports, bridgingHeaderBuildCommands,
extraPCMArgs)); extraPCMArgs));
} }

View File

@@ -58,6 +58,8 @@ using IsSystemField = BCFixed<1>;
using IsStaticField = BCFixed<1>; using IsStaticField = BCFixed<1>;
/// A bit taht indicates whether or not a link library is a force-load one /// A bit taht indicates whether or not a link library is a force-load one
using IsForceLoadField = BCFixed<1>; using IsForceLoadField = BCFixed<1>;
/// A bit taht indicates whether or not an import statement is optional
using IsOptionalImport = BCFixed<1>;
/// Source location fields /// Source location fields
using LineNumberField = BCFixed<32>; using LineNumberField = BCFixed<32>;
@@ -97,8 +99,9 @@ enum {
LINK_LIBRARY_ARRAY_NODE, LINK_LIBRARY_ARRAY_NODE,
MACRO_DEPENDENCY_NODE, MACRO_DEPENDENCY_NODE,
MACRO_DEPENDENCY_ARRAY_NODE, MACRO_DEPENDENCY_ARRAY_NODE,
SOURCE_LOCATION_NODE,
IMPORT_STATEMENT_NODE, IMPORT_STATEMENT_NODE,
IMPORT_STATEMENT_ARRAY_NODE,
OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE,
SWIFT_INTERFACE_MODULE_DETAILS_NODE, SWIFT_INTERFACE_MODULE_DETAILS_NODE,
SWIFT_SOURCE_MODULE_DETAILS_NODE, SWIFT_SOURCE_MODULE_DETAILS_NODE,
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE, SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
@@ -158,19 +161,19 @@ using MacroDependencyArrayLayout =
BCRecordLayout<MACRO_DEPENDENCY_ARRAY_NODE, IdentifierIDArryField>; BCRecordLayout<MACRO_DEPENDENCY_ARRAY_NODE, IdentifierIDArryField>;
// ACTODO: Comment // ACTODO: Comment
using SourceLocationLayout = using ImportStatementLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID BCRecordLayout<IMPORT_STATEMENT_NODE, // ID
IdentifierIDField, // importIdentifier
IdentifierIDField, // bufferIdentifier IdentifierIDField, // bufferIdentifier
LineNumberField, // lineNumber LineNumberField, // lineNumber
ColumnNumberField // columnNumber ColumnNumberField, // columnNumber
IsOptionalImport // isOptional
>; >;
// ACTODO: Comment // ACTODO: Comment
using ImportStatementLayout = using ImportStatementArrayLayout =
BCRecordLayout<LINK_LIBRARY_NODE, // ID BCRecordLayout<IMPORT_STATEMENT_ARRAY_NODE, IdentifierIDArryField>;
IdentifierIDField, // importIdentifier using OptionalImportStatementArrayLayout =
SourceLocationIDArrayIDField // importLocations BCRecordLayout<OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE, IdentifierIDArryField>;
>;
// After the array records, we have a sequence of Module info // After the array records, we have a sequence of Module info
// records, each of which is followed by one of: // records, each of which is followed by one of:
@@ -182,8 +185,8 @@ using ImportStatementLayout =
using ModuleInfoLayout = using ModuleInfoLayout =
BCRecordLayout<MODULE_NODE, // ID BCRecordLayout<MODULE_NODE, // ID
IdentifierIDField, // moduleName IdentifierIDField, // moduleName
ImportArrayIDField, // moduleImports ImportArrayIDField, // imports
ImportArrayIDField, // optionalModuleImports ImportArrayIDField, // optionalImports
LinkLibrariesArrayIDField, // linkLibraries LinkLibrariesArrayIDField, // linkLibraries
MacroDependenciesArrayIDField, // macroDependencies MacroDependenciesArrayIDField, // macroDependencies
DependencyIDArrayIDField, // importedSwiftModules DependencyIDArrayIDField, // importedSwiftModules

File diff suppressed because it is too large Load Diff

View File

@@ -355,7 +355,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
}); });
auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule( auto mainDependencies = ModuleDependencyInfo::forSwiftSourceModule(
{}, buildCommands, {}, ExtraPCMArgs); {}, buildCommands, {}, {}, {}, ExtraPCMArgs);
if (ScanASTContext.CASOpts.EnableCaching) { if (ScanASTContext.CASOpts.EnableCaching) {
std::vector<std::string> clangDependencyFiles; std::vector<std::string> clangDependencyFiles;
@@ -1166,7 +1166,7 @@ void ModuleDependencyScanner::discoverCrossImportOverlayDependencies(
auto actualMainID = ModuleDependencyID{mainModuleName.str(), auto actualMainID = ModuleDependencyID{mainModuleName.str(),
ModuleDependencyKind::SwiftSource}; ModuleDependencyKind::SwiftSource};
auto dummyMainDependencies = auto dummyMainDependencies =
ModuleDependencyInfo::forSwiftSourceModule({}, {}, {}, {}); ModuleDependencyInfo::forSwiftSourceModule({}, {}, {}, {}, {}, {});
std::for_each(newOverlays.begin(), newOverlays.end(), std::for_each(newOverlays.begin(), newOverlays.end(),
[&](Identifier modName) { [&](Identifier modName) {
dummyMainDependencies.addModuleImport(modName.str()); dummyMainDependencies.addModuleImport(modName.str());

View File

@@ -246,8 +246,8 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
Result = ModuleDependencyInfo::forSwiftInterfaceModule( Result = ModuleDependencyInfo::forSwiftInterfaceModule(
outputPathBase.str().str(), InPath, compiledCandidatesRefs, outputPathBase.str().str(), InPath, compiledCandidatesRefs,
ArgsRefs, linkLibraries, PCMArgs, Hash, isFramework, isStatic, {}, ArgsRefs, {}, {}, linkLibraries, PCMArgs, Hash, isFramework,
/*module-cache-key*/ "", UserModVer); isStatic, {}, /*module-cache-key*/ "", UserModVer);
if (Ctx.CASOpts.EnableCaching) { if (Ctx.CASOpts.EnableCaching) {
std::vector<std::string> clangDependencyFiles; std::vector<std::string> clangDependencyFiles;