File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -304,7 +304,12 @@ bool ArgsToFrontendOptionsConverter::convert(
304304 Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
305305 A->getAsString (Args), A->getValue ());
306306 }
307- } else {
307+ // If swiftinterface doesn't have a flag, let's not set the version
308+ // to the current compiler version here. This helps us to identify
309+ // swiftmodules built from swiftinterface generated before introduction
310+ // of `-swift-compiler-version` flag.
311+ } else if (Opts.InputMode !=
312+ FrontendOptions::ParseInputMode::SwiftModuleInterface) {
308313 Opts.SwiftCompilerVersion .tryParse (version::getCompilerVersion ());
309314 }
310315
Original file line number Diff line number Diff line change @@ -1489,8 +1489,10 @@ ModuleDecl *CompilerInstance::getMainModule() const {
14891489 if (Invocation.getSILOptions ().EnableSerializePackage )
14901490 MainModule->setSerializePackageEnabled ();
14911491
1492- MainModule->setSwiftCompilerVersion (
1493- Invocation.getFrontendOptions ().SwiftCompilerVersion );
1492+ if (auto compilerVersion =
1493+ Invocation.getFrontendOptions ().SwiftCompilerVersion ) {
1494+ MainModule->setSwiftCompilerVersion (compilerVersion);
1495+ }
14941496
14951497 // Register the main module with the AST context.
14961498 Context->addLoadedModule (MainModule);
Original file line number Diff line number Diff line change @@ -1141,8 +1141,10 @@ void Serializer::writeHeader() {
11411141 }
11421142
11431143 llvm::VersionTuple compilerVersion = M->getSwiftCompilerVersion ();
1144- options_block::SwiftCompilerVersionLayout SwiftCompilerVersion (Out);
1145- SwiftCompilerVersion.emit (ScratchRecord, compilerVersion.getAsString ());
1144+ if (compilerVersion) {
1145+ options_block::SwiftCompilerVersionLayout SwiftCompilerVersion (Out);
1146+ SwiftCompilerVersion.emit (ScratchRecord, compilerVersion.getAsString ());
1147+ }
11461148
11471149 if (M->isConcurrencyChecked ()) {
11481150 options_block::IsConcurrencyCheckedLayout IsConcurrencyChecked (Out);
Original file line number Diff line number Diff line change 22
33/// Build the libraries.
44// RUN: %target-swift-frontend %s \
5+ // RUN: -module-name Lib \
56// RUN: -emit-module-path %t/Lib.swiftmodule \
67// RUN: -emit-module-interface-path %t/Lib.swiftinterface \
78// RUN: -enable-library-evolution \
2021// CHECK-MODULE-OPTION: <SWIFT_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
2122// CHECK-MODULE-OPTION: </OPTIONS_BLOCK>
2223
24+ // Drop and rebuilt swiftmodule to make sure that the version is inferred from the interface file.
25+ // RUN: rm %t/Lib.swiftmodule
26+ // RUN: %target-swift-frontend -compile-module-from-interface %t/Lib.swiftinterface -o %t/Lib.swiftmodule -module-name Lib
27+
28+ /// Check option in swiftmodule
29+ // RUN: llvm-bcanalyzer --dump %t/Lib.swiftmodule | %FileCheck --check-prefix=CHECK-REBUILT-MODULE-OPTION %s
30+ // CHECK-REBUILT-MODULE-OPTION: <OPTIONS_BLOCK
31+ // CHECK-REBUILT-MODULE-OPTION: <SWIFT_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
32+ // CHECK-REBUILT-MODULE-OPTION: </OPTIONS_BLOCK>
33+
2334public struct S {
2435 public var test : Int = 42
2536}
You can’t perform that action at this time.
0 commit comments