Skip to content

Commit 09b8de0

Browse files
authored
Merge pull request #41042 from xymus/restrict-all-modules-by-tag
[Serialization] Restrict loading all swiftmodules by compiler tag
2 parents 4df4f97 + 39c3fc0 commit 09b8de0

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ static ValidationInfo validateControlBlock(
308308
break;
309309
}
310310
case control_block::REVISION: {
311-
// Tagged compilers should load only resilient modules if they were
312-
// produced by the exact same version.
311+
// Tagged compilers should only load modules if they were
312+
// produced by the exact same compiler tag.
313313

314314
// Disable this restriction for compiler testing by setting this
315315
// env var to any value.
@@ -328,7 +328,7 @@ static ValidationInfo validateControlBlock(
328328
!version::Version::getCurrentCompilerVersion().empty();
329329

330330
StringRef moduleRevision = blobData;
331-
if (isCompilerTagged && !moduleRevision.empty()) {
331+
if (isCompilerTagged) {
332332
StringRef compilerRevision = forcedDebugRevision ?
333333
forcedDebugRevision : version::getSwiftRevision();
334334
if (moduleRevision != compilerRevision)

lib/Serialization/Serialization.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,17 +1007,12 @@ void Serializer::writeHeader(const SerializationOptions &options) {
10071007

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

1010-
// Write the producer's Swift revision only for resilient modules.
1011-
if (M->getResilienceStrategy() != ResilienceStrategy::Default) {
1012-
auto revision = version::getSwiftRevision();
1013-
1014-
static const char* forcedDebugRevision =
1015-
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION");
1016-
if (forcedDebugRevision)
1017-
revision = forcedDebugRevision;
1018-
1019-
Revision.emit(ScratchRecord, revision);
1020-
}
1010+
// Write the producer's Swift revision.
1011+
static const char* forcedDebugRevision =
1012+
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION");
1013+
auto revision = forcedDebugRevision ?
1014+
forcedDebugRevision : version::getSwiftRevision();
1015+
Revision.emit(ScratchRecord, revision);
10211016

10221017
IsOSSA.emit(ScratchRecord, options.IsOSSA);
10231018

test/Serialization/restrict-swiftmodule-to-revision.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ public func foo() {}
88

99
/// Build Lib as a resilient and non-resilient swiftmodule
1010
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -o %t/build -parse-stdlib -module-cache-path %t/cache -module-name ResilientLib -enable-library-evolution
11-
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -o %t/build -parse-stdlib -module-cache-path %t/cache -module-name NonresilientLib
11+
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -o %t/build -parse-stdlib -module-cache-path %t/cache -module-name NonResilientLib
1212
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION=my-revision \
1313
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -swift-version 5 -o %t/build -parse-stdlib -module-cache-path %t/cache -module-name TaggedLib -enable-library-evolution
1414

1515

1616
/// 2. Test importing the non-resilient untagged library
17-
// BEGIN NonresilientClient.swift
18-
import NonresilientLib
17+
// BEGIN NonResilientClient.swift
18+
import NonResilientLib
1919
foo()
2020

21-
/// Building a NonresilientLib client should always succeed
22-
// RUN: %target-swift-frontend -typecheck %t/NonresilientClient.swift -swift-version 5 -I %t/build -parse-stdlib -module-cache-path %t/cache
21+
/// Building a NonResilientLib client should reject the import for a tagged compiler
2322
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION=my-revision \
24-
// RUN: %target-swift-frontend -typecheck %t/NonresilientClient.swift -swift-version 5 -I %t/build -parse-stdlib -module-cache-path %t/cache
23+
// RUN: not %target-swift-frontend -typecheck %t/NonResilientClient.swift -swift-version 5 -I %t/build -parse-stdlib -module-cache-path %t/cache 2>&1 | %FileCheck -check-prefix=CHECK-NON-RESILIENT %s
24+
// CHECK-NON-RESILIENT: compiled module was created by a different version of the compiler; rebuild 'NonResilientLib' and try again: {{.*}}NonResilientLib.swiftmodule
2525

2626

2727
/// 3. Test importing the resilient untagged library
@@ -47,7 +47,7 @@ foo()
4747
import TaggedLib
4848
foo()
4949

50-
/// Importing TaggedLib should success with the same tag or a dev compiler
50+
/// Importing TaggedLib should succeed with the same tag or a dev compiler
5151
// RUN: env SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION=my-revision \
5252
// RUN: %target-swift-frontend -typecheck %t/TaggedClient.swift -swift-version 5 -I %t/build -parse-stdlib -module-cache-path %t/cache
5353
// RUN: %target-swift-frontend -typecheck %t/TaggedClient.swift -swift-version 5 -I %t/build -parse-stdlib -module-cache-path %t/cache

0 commit comments

Comments
 (0)