Skip to content

Commit 98f4ad8

Browse files
committed
DependenciesScanner: report user module version for textual Swift interfaces
1 parent 370bcec commit 98f4ad8

File tree

14 files changed

+60
-16
lines changed

14 files changed

+60
-16
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
217217
swiftscan_swift_textual_detail_get_module_cache_key(
218218
swiftscan_module_details_t details);
219219

220+
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
221+
swiftscan_swift_textual_detail_get_user_module_version(
222+
swiftscan_module_details_t details);
223+
220224
//=== Swift Binary Module Details query APIs ------------------------------===//
221225

222226
SWIFTSCAN_PUBLIC swiftscan_string_ref_t

include/swift/AST/ModuleDependencies.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,25 @@ class SwiftInterfaceModuleDependenciesStorage
294294
/// Details common to Swift textual (interface or source) modules
295295
CommonSwiftTextualModuleDependencyDetails textualModuleDetails;
296296

297+
/// The user module version of this textual module interface.
298+
const std::string userModuleVersion;
299+
297300
SwiftInterfaceModuleDependenciesStorage(
298301
StringRef moduleOutputPath, StringRef swiftInterfaceFile,
299302
ArrayRef<StringRef> compiledModuleCandidates,
300303
ArrayRef<StringRef> buildCommandLine, ArrayRef<LinkLibrary> linkLibraries,
301304
ArrayRef<StringRef> extraPCMArgs, StringRef contextHash, bool isFramework,
302-
bool isStatic, StringRef RootID, StringRef moduleCacheKey)
305+
bool isStatic, StringRef RootID, StringRef moduleCacheKey,
306+
StringRef userModuleVersion)
303307
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
304308
linkLibraries, moduleCacheKey),
305309
moduleOutputPath(moduleOutputPath),
306310
swiftInterfaceFile(swiftInterfaceFile),
307311
compiledModuleCandidates(compiledModuleCandidates.begin(),
308312
compiledModuleCandidates.end()),
309313
contextHash(contextHash), isFramework(isFramework), isStatic(isStatic),
310-
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID) {}
314+
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
315+
userModuleVersion(userModuleVersion) {}
311316

312317
ModuleDependencyInfoStorageBase *clone() const override {
313318
return new SwiftInterfaceModuleDependenciesStorage(*this);
@@ -592,12 +597,14 @@ class ModuleDependencyInfo {
592597
ArrayRef<StringRef> compiledCandidates, ArrayRef<StringRef> buildCommands,
593598
ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> extraPCMArgs,
594599
StringRef contextHash, bool isFramework, bool isStatic,
595-
StringRef CASFileSystemRootID, StringRef moduleCacheKey) {
600+
StringRef CASFileSystemRootID, StringRef moduleCacheKey,
601+
StringRef userModuleVersion) {
596602
return ModuleDependencyInfo(
597603
std::make_unique<SwiftInterfaceModuleDependenciesStorage>(
598604
moduleOutputPath, swiftInterfaceFile, compiledCandidates,
599605
buildCommands, linkLibraries, extraPCMArgs, contextHash,
600-
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey));
606+
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey,
607+
userModuleVersion));
601608
}
602609

603610
/// Describe the module dependencies for a serialized or parsed Swift module.

include/swift/AST/ModuleLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ struct InterfaceSubContextDelegate {
214214
SourceLoc diagLoc,
215215
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
216216
ArrayRef<StringRef>,
217-
ArrayRef<StringRef>, StringRef)> action) = 0;
217+
ArrayRef<StringRef>, StringRef,
218+
StringRef)> action) = 0;
218219
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
219220
StringRef interfacePath,
220221
StringRef sdkPath,

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ typedef struct {
132132

133133
/// Macro dependecies.
134134
swiftscan_macro_dependency_set_t *macro_dependencies;
135+
136+
/// User module version
137+
swiftscan_string_ref_t user_module_version;
135138
} swiftscan_swift_textual_details_t;
136139

137140
/// Swift modules with only a binary module file.

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ using SwiftInterfaceModuleDetailsLayout =
150150
DependencyIDArrayIDField, // swiftOverlayDependencies
151151
IdentifierIDField, // CASFileSystemRootID
152152
IdentifierIDField, // bridgingHeaderIncludeTree
153-
IdentifierIDField // moduleCacheKey
153+
IdentifierIDField, // moduleCacheKey
154+
IdentifierIDField // UserModuleVersion
154155
>;
155156

156157
using SwiftSourceModuleDetailsLayout =

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
688688
SourceLoc diagLoc,
689689
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
690690
ArrayRef<StringRef>, ArrayRef<StringRef>,
691-
StringRef)> action) override;
691+
StringRef, StringRef)> action) override;
692692
std::error_code runInSubCompilerInstance(StringRef moduleName,
693693
StringRef interfacePath,
694694
StringRef sdkPath,

lib/DependencyScan/DependencyScanJSON.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ void writeJSON(llvm::raw_ostream &out,
456456
swiftTextualDeps->module_cache_key, 5,
457457
/*trailingComma=*/true);
458458
}
459+
writeJSONSingleField(out, "userModuleVersion",
460+
swiftTextualDeps->user_module_version, 5,
461+
/*trailingComma=*/true);
459462
writeMacroDependencies(out, swiftTextualDeps->macro_dependencies, 5,
460463
/*trailingComma=*/true);
461464
writeJSONSingleField(out, "isFramework", swiftTextualDeps->is_framework,

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
255255
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
256256
sourceFilesArrayID, bridgingSourceFilesArrayID,
257257
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
258-
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID;
258+
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID,
259+
userModuleVersionID;
259260
SwiftInterfaceModuleDetailsLayout::readRecord(
260261
Scratch, outputPathFileID, interfaceFileID,
261262
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
262263
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
263264
sourceFilesArrayID, bridgingSourceFilesArrayID,
264265
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
265-
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID);
266+
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID, userModuleVersionID);
266267

267268
auto outputModulePath = getIdentifier(outputPathFileID);
268269
if (!outputModulePath)
@@ -304,13 +305,17 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
304305
auto moduleCacheKey = getIdentifier(moduleCacheKeyID);
305306
if (!moduleCacheKeyID)
306307
llvm::report_fatal_error("Bad moduleCacheKey");
308+
auto userModuleVersion = getIdentifier(userModuleVersionID);
309+
if (!userModuleVersion)
310+
llvm::report_fatal_error("Bad userModuleVersion");
307311

308312
// TODO: LinkLibraries, MacroDependencies
309313
// Form the dependencies storage object
310314
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
311315
outputModulePath.value(), optionalSwiftInterfaceFile.value(),
312316
compiledCandidatesRefs, buildCommandRefs, {}, extraPCMRefs,
313-
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey);
317+
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey,
318+
*userModuleVersion);
314319

315320
// Add imports of this module
316321
for (const auto &moduleName : currentModuleImports)
@@ -1007,7 +1012,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
10071012
getIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID),
10081013
getIdentifier(swiftTextDeps->textualModuleDetails
10091014
.CASBridgingHeaderIncludeTreeRootID),
1010-
getIdentifier(swiftTextDeps->moduleCacheKey));
1015+
getIdentifier(swiftTextDeps->moduleCacheKey),
1016+
getIdentifier(swiftTextDeps->userModuleVersion));
10111017
break;
10121018
}
10131019
case swift::ModuleDependencyKind::SwiftSource: {

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ generateFullDependencyGraph(const CompilerInstance &instance,
701701
.CASBridgingHeaderIncludeTreeRootID.c_str()),
702702
create_clone(swiftTextualDeps->moduleCacheKey.c_str()),
703703
createMacroDependencySet(
704-
swiftTextualDeps->textualModuleDetails.macroDependencies)};
704+
swiftTextualDeps->textualModuleDetails.macroDependencies),
705+
create_clone(swiftTextualDeps->userModuleVersion.c_str())};
705706
} else if (swiftSourceDeps) {
706707
swiftscan_string_ref_t moduleInterfacePath = create_null();
707708
swiftscan_string_ref_t bridgingHeaderPath =

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,15 +2135,18 @@ InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
21352135
StringRef outputPath,
21362136
SourceLoc diagLoc,
21372137
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
2138-
ArrayRef<StringRef>, StringRef)> action) {
2138+
ArrayRef<StringRef>, StringRef, StringRef)> action) {
21392139
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
21402140
diagLoc, /*silenceErrors=*/false,
21412141
[&](SubCompilerInstanceInfo &info){
2142+
std::string UserModuleVer = info.Instance->getInvocation().getFrontendOptions()
2143+
.UserModuleVersion.getAsString();
21422144
return action(info.Instance->getASTContext(),
21432145
info.Instance->getMainModule(),
21442146
info.BuildArguments,
21452147
info.ExtraPCMArgs,
2146-
info.Hash);
2148+
info.Hash,
2149+
UserModuleVer);
21472150
});
21482151
}
21492152

0 commit comments

Comments
 (0)