Skip to content

Commit e0b8de4

Browse files
authored
Merge pull request swiftlang#37455 from nkcsgexi/user-module-subminor
Serialization: embed subminor and build version in the user module version entry
2 parents 1f005e1 + 5c5715f commit e0b8de4

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,21 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
255255
switch (scratch.size()) {
256256
default:
257257
// Add new cases here, in descending order.
258+
case 8:
259+
case 7:
258260
case 6:
259261
case 5: {
260-
result.userModuleVersion = llvm::VersionTuple(scratch[4], scratch[5]);
262+
auto subMinor = 0;
263+
auto build = 0;
264+
// case 7 and 8 were added after case 5 and 6, so we need to have this
265+
// special handling to make sure we can still load the module without
266+
// case 7 and case 8 successfully.
267+
if (scratch.size() >= 8) {
268+
subMinor = scratch[6];
269+
build = scratch[7];
270+
}
271+
result.userModuleVersion = llvm::VersionTuple(scratch[4], scratch[5],
272+
subMinor, build);
261273
LLVM_FALLTHROUGH;
262274
}
263275
case 4:

lib/Serialization/ModuleFormat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 613; // isStaticLibrary option
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 614; // add subminor and build in user module version
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -765,6 +765,8 @@ namespace control_block {
765765
BCVBR<8>, // length of "short compatibility version string" in the blob
766766
BCVBR<17>, // User module format major version
767767
BCVBR<17>, // User module format minor version
768+
BCVBR<17>, // User module format sub-minor version
769+
BCVBR<17>, // User module format build version
768770
BCBlob // misc. version information
769771
>;
770772

lib/Serialization/Serialization.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,20 @@ void Serializer::writeHeader(const SerializationOptions &options) {
966966
if (auto minor = options.UserModuleVersion.getMinor()) {
967967
userModuleMinor = *minor;
968968
}
969+
auto userModuleSubminor = 0;
970+
if (auto subMinor = options.UserModuleVersion.getSubminor()) {
971+
userModuleSubminor = *subMinor;
972+
}
973+
auto userModuleBuild = 0;
974+
if (auto build = options.UserModuleVersion.getBuild()) {
975+
userModuleBuild = *build;
976+
}
969977
Metadata.emit(ScratchRecord,
970978
SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR,
971979
shortVersionStringLength,
972980
compatibilityVersionStringLength,
973981
userModuleMajor, userModuleMinor,
982+
userModuleSubminor, userModuleBuild,
974983
versionString.str());
975984

976985
Target.emit(ScratchRecord, M->getASTContext().LangOpts.Target.str());

lib/Serialization/SerializeDoc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ void DocSerializer::writeDocHeader() {
493493
Metadata.emit(ScratchRecord, SWIFTDOC_VERSION_MAJOR, SWIFTDOC_VERSION_MINOR,
494494
/*short version string length*/0, /*compatibility length*/0,
495495
/*user module version major*/0,
496-
/*user module version minor*/0, verText);
496+
/*user module version minor*/0,
497+
/*user module version subminor*/0,
498+
/*user module version build*/0,
499+
verText);
497500

498501
ModuleName.emit(ScratchRecord, M->getName().str());
499502
Target.emit(ScratchRecord, LangOpts.Target.str());
@@ -878,7 +881,10 @@ class SourceInfoSerializer : public SerializerBase {
878881
SWIFTSOURCEINFO_VERSION_MINOR,
879882
/*short version string length*/0, /*compatibility length*/0,
880883
/*user module version major*/0,
881-
/*user module version minor*/0, verText);
884+
/*user module version minor*/0,
885+
/*user module version sub-minor*/0,
886+
/*user module version build*/0,
887+
verText);
882888

883889
ModuleName.emit(ScratchRecord, M->getName().str());
884890
Target.emit(ScratchRecord, LangOpts.Target.str());

test/ModuleInterface/user-module-version.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %empty-directory(%t/binary)
44
// RUN: %empty-directory(%t/module-cache)
55

6-
// RUN: %target-swift-frontend -emit-module %s -module-name Foo -swift-version 5 -disable-implicit-concurrency-module-import -user-module-version 113.33 -emit-module-interface-path %t/textual/Foo.swiftinterface -enable-library-evolution -emit-module-path %t/binary/Foo.swiftmodule
6+
// RUN: %target-swift-frontend -emit-module %s -module-name Foo -swift-version 5 -disable-implicit-concurrency-module-import -user-module-version 113.33.44.55 -emit-module-interface-path %t/textual/Foo.swiftinterface -enable-library-evolution -emit-module-path %t/binary/Foo.swiftmodule
77

88
// RUN: %FileCheck %s --check-prefix=INTERFACE-FLAG < %t/textual/Foo.swiftinterface
99

@@ -15,6 +15,6 @@
1515
// RUN: %target-swift-frontend -compile-module-from-interface %t/textual/Foo.swiftinterface -o %t/binary/Foo.swiftmodule
1616
// RUN: %target-swift-ide-test -print-module-metadata -module-to-print Foo -I %t/binary -source-filename %s | %FileCheck %s --check-prefix=USER-MODULE-PRINT
1717

18-
// INTERFACE-FLAG: -user-module-version 113.33
18+
// INTERFACE-FLAG: -user-module-version 113.33.44.55
1919

20-
// USER-MODULE-PRINT: user module version: 113.33
20+
// USER-MODULE-PRINT: user module version: 113.33.44.55

0 commit comments

Comments
 (0)