Skip to content

Commit fac06ab

Browse files
authored
Merge pull request #73679 from xymus/serial-sdk-version
Serialization: Write the target SDK in the binary swiftmodule
2 parents 9874915 + 074df70 commit fac06ab

File tree

8 files changed

+28
-4
lines changed

8 files changed

+28
-4
lines changed

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace swift {
4242
llvm::VersionTuple UserModuleVersion;
4343
std::set<std::string> AllowableClients;
4444
std::string SDKName;
45+
std::string SDKVersion;
4546

4647
StringRef GroupInfoPath;
4748
StringRef ImportedHeader;

include/swift/Serialization/Validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct ValidationInfo {
103103
version::Version compatibilityVersion = {};
104104
llvm::VersionTuple userModuleVersion;
105105
StringRef sdkName = {};
106+
StringRef sdkVersion = {};
106107
StringRef problematicRevision = {};
107108
StringRef problematicChannel = {};
108109
size_t bytes = 0;

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/PluginLoader.h"
2626
#include "swift/AST/TypeCheckRequests.h"
2727
#include "swift/Basic/FileTypes.h"
28+
#include "swift/Basic/Platform.h"
2829
#include "swift/Basic/SourceManager.h"
2930
#include "swift/Basic/Statistic.h"
3031
#include "swift/Frontend/CachingUtils.h"
@@ -202,6 +203,8 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
202203
serializationOpts.PublicDependentLibraries =
203204
getIRGenOptions().PublicLinkLibraries;
204205
serializationOpts.SDKName = getLangOptions().SDKName;
206+
serializationOpts.SDKVersion = swift::getSDKBuildVersion(
207+
getSearchPathOptions().getSDKPath());
205208
serializationOpts.ABIDescriptorPath = outs.ABIDescriptorOutputPath.c_str();
206209
serializationOpts.emptyABIDescriptor = opts.emptyABIDescriptor;
207210

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ static ValidationInfo validateControlBlock(
354354
case control_block::ALLOWABLE_CLIENT_NAME:
355355
result.allowableClients.push_back(blobData);
356356
break;
357+
case control_block::SDK_VERSION:
358+
result.sdkVersion = blobData;
359+
break;
357360
case control_block::SDK_NAME: {
358361
result.sdkName = blobData;
359362

@@ -690,6 +693,7 @@ void ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream &os) const {
690693
<< "', builder version '" << MiscVersion
691694
<< "', built from "
692695
<< (Bits.IsBuiltFromInterface? "swiftinterface": "source")
696+
<< " against SDK " << SDKVersion
693697
<< ", " << (resilient? "resilient": "non-resilient");
694698
if (Bits.AllowNonResilientAccess)
695699
os << ", built with -experimental-allow-non-resilient-access";
@@ -1453,6 +1457,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
14531457
Bits.AllowNonResilientAccess = extInfo.allowNonResilientAccess();
14541458
Bits.SerializePackageEnabled = extInfo.serializePackageEnabled();
14551459
MiscVersion = info.miscVersion;
1460+
SDKVersion = info.sdkVersion;
14561461
ModuleABIName = extInfo.getModuleABIName();
14571462
ModulePackageName = extInfo.getModulePackageName();
14581463
ModuleExportAsName = extInfo.getExportAsName();

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class ModuleFileSharedCore {
6666
/// The canonical name of the SDK the module was built with.
6767
StringRef SDKName;
6868

69+
/// Version string of the SDK against which the module was built.
70+
StringRef SDKVersion;
71+
6972
/// The name of the module interface this module was compiled from.
7073
///
7174
/// Empty if this module didn't come from an interface file.

lib/Serialization/ModuleFormat.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 873; // [serialized_for_package] for SILFunctionLayout
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 874; // SDKVersion
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -861,6 +861,7 @@ namespace control_block {
861861
MODULE_NAME,
862862
TARGET,
863863
SDK_NAME,
864+
SDK_VERSION,
864865
REVISION,
865866
CHANNEL,
866867
IS_OSSA,
@@ -895,6 +896,11 @@ namespace control_block {
895896
BCBlob
896897
>;
897898

899+
using SDKVersionLayout = BCRecordLayout<
900+
SDK_VERSION,
901+
BCBlob
902+
>;
903+
898904
using RevisionLayout = BCRecordLayout<
899905
REVISION,
900906
BCBlob

lib/Serialization/Serialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ void Serializer::writeBlockInfoBlock() {
834834
BLOCK_RECORD(control_block, MODULE_NAME);
835835
BLOCK_RECORD(control_block, TARGET);
836836
BLOCK_RECORD(control_block, SDK_NAME);
837+
BLOCK_RECORD(control_block, SDK_VERSION);
837838
BLOCK_RECORD(control_block, REVISION);
838839
BLOCK_RECORD(control_block, CHANNEL);
839840
BLOCK_RECORD(control_block, IS_OSSA);
@@ -984,6 +985,7 @@ void Serializer::writeHeader() {
984985
control_block::MetadataLayout Metadata(Out);
985986
control_block::TargetLayout Target(Out);
986987
control_block::SDKNameLayout SDKName(Out);
988+
control_block::SDKVersionLayout SDKVersion(Out);
987989
control_block::RevisionLayout Revision(Out);
988990
control_block::ChannelLayout Channel(Out);
989991
control_block::IsOSSALayout IsOSSA(Out);
@@ -1026,6 +1028,9 @@ void Serializer::writeHeader() {
10261028
if (!Options.SDKName.empty())
10271029
SDKName.emit(ScratchRecord, Options.SDKName);
10281030

1031+
if (!Options.SDKVersion.empty())
1032+
SDKVersion.emit(ScratchRecord, Options.SDKVersion);
1033+
10291034
for (auto &name : Options.AllowableClients) {
10301035
Allowable.emit(ScratchRecord, name);
10311036
}

test/Serialization/Recovery/crash-xref.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// NORMALFAILURE-LABEL: *** DESERIALIZATION FAILURE ***
3434
// NORMALFAILURE-LABEL: *** If any module named here was modified in the SDK, please delete the ***
3535
// NORMALFAILURE-LABEL: *** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
36-
// NORMALFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source, resilient, loaded from
36+
// NORMALFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source against SDK {{.*}}, resilient, loaded from
3737
// NORMALFAILURE-NEXT: Could not deserialize type for 'foo()'
3838
// NORMALFAILURE-NEXT: Caused by: modularization issue on 'SomeType', reference from 'Client' not resolvable: expected in 'A' but found in 'B'
3939
// NORMALFAILURE-NEXT: Cross-reference to module 'A'
@@ -43,7 +43,7 @@
4343
// ALLOWFAILURE-LABEL: *** DESERIALIZATION FAILURE ***
4444
// ALLOWFAILURE-LABEL: *** If any module named here was modified in the SDK, please delete the ***
4545
// ALLOWFAILURE-LABEL: *** new swiftmodule files from the SDK and keep only swiftinterfaces. ***
46-
// ALLOWFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source, non-resilient, built with -experimental-allow-module-with-compiler-errors, loaded from
46+
// ALLOWFAILURE-NEXT: module 'Client', builder version {{.*}}', built from source against SDK {{.*}}, non-resilient, built with -experimental-allow-module-with-compiler-errors, loaded from
4747
// ALLOWFAILURE-NEXT: Could not deserialize type for 'foo()'
4848
// ALLOWFAILURE-NEXT: Caused by: modularization issue on 'SomeType', reference from 'Client' not resolvable: expected in 'A' but found in 'B'
4949
// ALLOWFAILURE-NEXT: Cross-reference to module 'A'
@@ -52,7 +52,7 @@
5252
/// Test a swiftmodule rebuilt from the swiftinterface.
5353
// RUN: not --crash %target-swift-frontend -emit-sil %t/cache/Client-*.swiftmodule -module-name Client -I %t/partials -disable-deserialization-recovery 2> %t/cache_stderr
5454
// RUN: cat %t/cache_stderr | %FileCheck %s -check-prefixes=CACHEFAILURE
55-
// CACHEFAILURE: module 'Client', builder version {{.*}}', built from swiftinterface, resilient
55+
// CACHEFAILURE: module 'Client', builder version {{.*}}', built from swiftinterface against SDK {{.*}}, resilient
5656

5757
#if LIB
5858
public struct SomeType {

0 commit comments

Comments
 (0)