Skip to content

Commit 84a62fc

Browse files
committed
[Frontend/Serialization] Narrow -swift-compiler-version to -interface-compiler-version
It might be unexpected to future users that `-swift-compiler-version` would produce a version aligned to .swiftinterface instead of one used to build the .swiftmodule file. To avoid this possible confusion, let's scope down the version to `-interface-compiler-version` flag and `SWIFT_INTERFACE_COMPILER_VERSION` option in the module.
1 parent 83995f2 commit 84a62fc

18 files changed

+55
-58
lines changed

include/swift/AST/FileUnit.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
345345
return {};
346346
}
347347

348-
/// Returns the version of the Swift compiler used to create this module.
349-
virtual llvm::VersionTuple getSwiftCompilerVersion() const {
348+
/// Returns the version of the Swift compiler used to create generate
349+
/// .swiftinterface file if this file is produced from one.
350+
virtual llvm::VersionTuple getSwiftInterfaceCompilerVersion() const {
350351
return {};
351352
}
352353

include/swift/AST/Module.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ class ModuleDecl
254254

255255
mutable Identifier PublicModuleName;
256256

257-
/// Indicates that version of the Swift compiler this module was built with.
258-
mutable llvm::VersionTuple SwiftCompilerVersion;
257+
/// Indicates a version of the Swift compiler used to generate
258+
/// .swiftinterface file that this module was produced from (if any).
259+
mutable llvm::VersionTuple InterfaceCompilerVersion;
259260

260261
public:
261262
/// Produces the components of a given module's full name in reverse order.
@@ -521,13 +522,13 @@ class ModuleDecl
521522
PublicModuleName = name;
522523
}
523524

524-
/// The version of the Swift compiler this module was built with.
525-
llvm::VersionTuple getSwiftCompilerVersion() const {
526-
return SwiftCompilerVersion;
525+
/// See \c InterfaceCompilerVersion
526+
llvm::VersionTuple getSwiftInterfaceCompilerVersion() const {
527+
return InterfaceCompilerVersion;
527528
}
528529

529-
void setSwiftCompilerVersion(llvm::VersionTuple version) {
530-
SwiftCompilerVersion = version;
530+
void setSwiftInterfaceCompilerVersion(llvm::VersionTuple version) {
531+
InterfaceCompilerVersion = version;
531532
}
532533

533534
/// Retrieve the actual module name of an alias used for this module (if any).

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class FrontendOptions {
111111
llvm::VersionTuple UserModuleVersion;
112112

113113
/// The Swift compiler version number that would be used to synthesize
114-
/// swiftinterface files and subsequently swiftmodules.
115-
llvm::VersionTuple SwiftCompilerVersion;
114+
/// swiftinterface files and subsequently their swiftmodules.
115+
llvm::VersionTuple SwiftInterfaceCompilerVersion;
116116

117117
/// A set of modules allowed to import this module.
118118
std::set<std::string> AllowableClients;

include/swift/Option/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ def package_description_version: Separate<["-"], "package-description-version">,
303303
HelpText<"The version number to be applied on the input for the PackageDescription availability kind">,
304304
MetaVarName<"<vers>">;
305305

306-
def swift_compiler_version : Separate<["-"], "swift-compiler-version">,
306+
def swiftinterface_compiler_version : Separate<["-"], "interface-compiler-version">,
307307
Flags<[FrontendOption, HelpHidden]>,
308-
HelpText<"The version of the Swift compiler used to build swift interface and module">,
309-
MetaVarName<"<compvers>">;
308+
HelpText<"The version of the Swift compiler used to generate a .swiftinterface file">,
309+
MetaVarName<"<intcvers>">;
310310

311311
def tools_directory : Separate<["-"], "tools-directory">,
312312
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class SerializedASTFile final : public LoadedFile {
539539

540540
virtual StringRef getPublicModuleName() const override;
541541

542-
virtual llvm::VersionTuple getSwiftCompilerVersion() const override;
542+
virtual llvm::VersionTuple getSwiftInterfaceCompilerVersion() const override;
543543

544544
ValueDecl *getMainDecl() const override;
545545

include/swift/Serialization/Validation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ExtendedValidationInfo {
131131
StringRef ExportAsName;
132132
StringRef PublicModuleName;
133133
CXXStdlibKind CXXStdlib;
134-
llvm::VersionTuple SwiftCompilerVersion;
134+
llvm::VersionTuple SwiftInterfaceCompilerVersion;
135135
struct {
136136
unsigned ArePrivateImportsEnabled : 1;
137137
unsigned IsSIB : 1;
@@ -252,14 +252,14 @@ class ExtendedValidationInfo {
252252
CXXStdlibKind getCXXStdlibKind() const { return CXXStdlib; }
253253
void setCXXStdlibKind(CXXStdlibKind kind) { CXXStdlib = kind; }
254254

255-
llvm::VersionTuple getSwiftCompilerVersion() const {
256-
return SwiftCompilerVersion;
255+
llvm::VersionTuple getSwiftInterfaceCompilerVersion() const {
256+
return SwiftInterfaceCompilerVersion;
257257
}
258-
void setSwiftCompilerVersion(StringRef version) {
258+
void setSwiftInterfaceCompilerVersion(StringRef version) {
259259
llvm::VersionTuple compilerVersion;
260260
if (compilerVersion.tryParse(version))
261261
return;
262-
SwiftCompilerVersion = compilerVersion;
262+
SwiftInterfaceCompilerVersion = compilerVersion;
263263
}
264264
};
265265

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,11 @@ bool ArgsToFrontendOptionsConverter::convert(
299299
if (const Arg *A = Args.getLastArg(OPT_public_module_name))
300300
Opts.PublicModuleName = A->getValue();
301301

302-
if (auto A = Args.getLastArg(OPT_swift_compiler_version)) {
303-
if (Opts.SwiftCompilerVersion.tryParse(A->getValue())) {
302+
if (auto A = Args.getLastArg(OPT_swiftinterface_compiler_version)) {
303+
if (Opts.SwiftInterfaceCompilerVersion.tryParse(A->getValue())) {
304304
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
305305
A->getAsString(Args), A->getValue());
306306
}
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) {
313-
Opts.SwiftCompilerVersion.tryParse(version::getCompilerVersion());
314307
}
315308

316309
// This must be called after computing module name, module abi name,

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,8 +1490,8 @@ ModuleDecl *CompilerInstance::getMainModule() const {
14901490
MainModule->setSerializePackageEnabled();
14911491

14921492
if (auto compilerVersion =
1493-
Invocation.getFrontendOptions().SwiftCompilerVersion) {
1494-
MainModule->setSwiftCompilerVersion(compilerVersion);
1493+
Invocation.getFrontendOptions().SwiftInterfaceCompilerVersion) {
1494+
MainModule->setSwiftInterfaceCompilerVersion(compilerVersion);
14951495
}
14961496

14971497
// Register the main module with the AST context.

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
124124
!Opts.PackageFlags.IgnorableFlags.empty())
125125
ignorableFlags.push_back(Opts.PackageFlags.IgnorableFlags);
126126

127-
ignorableFlags.push_back("-swift-compiler-version");
127+
ignorableFlags.push_back("-interface-compiler-version");
128128
ignorableFlags.push_back(version::getCompilerVersion());
129129

130130
if (!ignorableFlags.empty()) {

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,6 @@ StringRef SerializedASTFile::getPublicModuleName() const {
14101410
return File.getPublicModuleName();
14111411
}
14121412

1413-
llvm::VersionTuple SerializedASTFile::getSwiftCompilerVersion() const {
1414-
return File.getSwiftCompilerVersion();
1413+
llvm::VersionTuple SerializedASTFile::getSwiftInterfaceCompilerVersion() const {
1414+
return File.getSwiftInterfaceCompilerVersion();
14151415
}

lib/Serialization/ModuleFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ class ModuleFile
603603
return Core->UserModuleVersion;
604604
}
605605

606-
llvm::VersionTuple getSwiftCompilerVersion() const {
607-
return Core->SwiftCompilerVersion;
606+
llvm::VersionTuple getSwiftInterfaceCompilerVersion() const {
607+
return Core->SwiftInterfaceCompilerVersion;
608608
}
609609

610610
ArrayRef<StringRef> getAllowableClientNames() const {

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
214214
case options_block::PUBLIC_MODULE_NAME:
215215
extendedInfo.setPublicModuleName(blobData);
216216
break;
217-
case options_block::SWIFT_COMPILER_VERSION:
218-
extendedInfo.setSwiftCompilerVersion(blobData);
217+
case options_block::SWIFT_INTERFACE_COMPILER_VERSION:
218+
extendedInfo.setSwiftInterfaceCompilerVersion(blobData);
219219
break;
220220
default:
221221
// Unknown options record, possibly for use by a future version of the
@@ -1499,7 +1499,8 @@ ModuleFileSharedCore::ModuleFileSharedCore(
14991499
ModulePackageName = extInfo.getModulePackageName();
15001500
ModuleExportAsName = extInfo.getExportAsName();
15011501
PublicModuleName = extInfo.getPublicModuleName();
1502-
SwiftCompilerVersion = extInfo.getSwiftCompilerVersion();
1502+
SwiftInterfaceCompilerVersion =
1503+
extInfo.getSwiftInterfaceCompilerVersion();
15031504

15041505
hasValidControlBlock = true;
15051506
break;

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,9 @@ class ModuleFileSharedCore {
104104
StringRef PublicModuleName;
105105

106106
/// The version of the Swift compiler used to produce swiftinterface
107-
/// this module is based on or build the module itself. This is
108-
/// the most precise version possible - a compiler tag or version
109-
/// if this is a development compiler.
110-
llvm::VersionTuple SwiftCompilerVersion;
107+
/// this module is based on. This is the most precise version possible
108+
/// - a compiler tag or version if this is a development compiler.
109+
llvm::VersionTuple SwiftInterfaceCompilerVersion;
111110

112111
/// \c true if this module has incremental dependency information.
113112
bool HasIncrementalInfo = false;

lib/Serialization/ModuleFormat.h

Lines changed: 4 additions & 4 deletions
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 = 898; // swift-compiler-version
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 898; // interface-compiler-version
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -966,7 +966,7 @@ namespace options_block {
966966
SERIALIZE_PACKAGE_ENABLED,
967967
CXX_STDLIB_KIND,
968968
PUBLIC_MODULE_NAME,
969-
SWIFT_COMPILER_VERSION,
969+
SWIFT_INTERFACE_COMPILER_VERSION,
970970
};
971971

972972
using SDKPathLayout = BCRecordLayout<
@@ -1068,8 +1068,8 @@ namespace options_block {
10681068
BCBlob
10691069
>;
10701070

1071-
using SwiftCompilerVersionLayout = BCRecordLayout<
1072-
SWIFT_COMPILER_VERSION,
1071+
using SwiftInterfaceCompilerVersionLayout = BCRecordLayout<
1072+
SWIFT_INTERFACE_COMPILER_VERSION,
10731073
BCBlob // version tuple
10741074
>;
10751075
}

lib/Serialization/Serialization.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ void Serializer::writeBlockInfoBlock() {
864864
BLOCK_RECORD(options_block, SERIALIZE_PACKAGE_ENABLED);
865865
BLOCK_RECORD(options_block, CXX_STDLIB_KIND);
866866
BLOCK_RECORD(options_block, PUBLIC_MODULE_NAME);
867-
BLOCK_RECORD(options_block, SWIFT_COMPILER_VERSION);
867+
BLOCK_RECORD(options_block, SWIFT_INTERFACE_COMPILER_VERSION);
868868

869869
BLOCK(INPUT_BLOCK);
870870
BLOCK_RECORD(input_block, IMPORTED_MODULE);
@@ -1140,10 +1140,11 @@ void Serializer::writeHeader() {
11401140
PublicModuleName.emit(ScratchRecord, publicModuleName.str());
11411141
}
11421142

1143-
llvm::VersionTuple compilerVersion = M->getSwiftCompilerVersion();
1143+
llvm::VersionTuple compilerVersion =
1144+
M->getSwiftInterfaceCompilerVersion();
11441145
if (compilerVersion) {
1145-
options_block::SwiftCompilerVersionLayout SwiftCompilerVersion(Out);
1146-
SwiftCompilerVersion.emit(ScratchRecord, compilerVersion.getAsString());
1146+
options_block::SwiftInterfaceCompilerVersionLayout Version(Out);
1147+
Version.emit(ScratchRecord, compilerVersion.getAsString());
11471148
}
11481149

11491150
if (M->isConcurrencyChecked()) {

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
10351035
M.setPackageName(Ctx.getIdentifier(loadedModuleFile->getModulePackageName()));
10361036
}
10371037
M.setUserModuleVersion(loadedModuleFile->getUserModuleVersion());
1038-
M.setSwiftCompilerVersion(loadedModuleFile->getSwiftCompilerVersion());
1038+
M.setSwiftInterfaceCompilerVersion(
1039+
loadedModuleFile->getSwiftInterfaceCompilerVersion());
10391040
for (auto name: loadedModuleFile->getAllowableClientNames()) {
10401041
M.addAllowableClientName(Ctx.getIdentifier(name));
10411042
}

test/CAS/embedded-Xcc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
// RUN: llvm-bcanalyzer --dump %t/Test.swiftmodule | %FileCheck %s
2222

23-
// CHECK: <XCC abbrevid=7/> blob data = '-cc1'
24-
// CHECK: <XCC abbrevid=7/> blob data = '-D'
25-
// CHECK: <XCC abbrevid=7/> blob data = 'TEST=1'
26-
// CHECK-NOT: <XCC abbrevid=7/> blob data = '--target=
23+
// CHECK: <XCC abbrevid=6/> blob data = '-cc1'
24+
// CHECK: <XCC abbrevid=6/> blob data = '-D'
25+
// CHECK: <XCC abbrevid=6/> blob data = 'TEST=1'
26+
// CHECK-NOT: <XCC abbrevid=6/> blob data = '--target=
2727

2828
//--- main.swift
2929
public func test() {}

test/ModuleInterface/swift-compiler-version-option.swift renamed to test/ModuleInterface/swiftinterface-compiler-version-option.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// Check option in swiftmodule
1919
// RUN: llvm-bcanalyzer --dump %t/Lib.swiftmodule | %FileCheck --check-prefix=CHECK-MODULE-OPTION %s
2020
// CHECK-MODULE-OPTION: <OPTIONS_BLOCK
21-
// CHECK-MODULE-OPTION: <SWIFT_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
21+
// CHECK-NOT-MODULE-OPTION: <SWIFT_INTERFACE_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
2222
// CHECK-MODULE-OPTION: </OPTIONS_BLOCK>
2323

2424
// Drop and rebuilt swiftmodule to make sure that the version is inferred from the interface file.
@@ -28,7 +28,7 @@
2828
/// Check option in swiftmodule
2929
// RUN: llvm-bcanalyzer --dump %t/Lib.swiftmodule | %FileCheck --check-prefix=CHECK-REBUILT-MODULE-OPTION %s
3030
// CHECK-REBUILT-MODULE-OPTION: <OPTIONS_BLOCK
31-
// CHECK-REBUILT-MODULE-OPTION: <SWIFT_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
31+
// CHECK-REBUILT-MODULE-OPTION: <SWIFT_INTERFACE_COMPILER_VERSION abbrevid={{.*}}/> blob data = '{{.*}}'
3232
// CHECK-REBUILT-MODULE-OPTION: </OPTIONS_BLOCK>
3333

3434
public struct S {

0 commit comments

Comments
 (0)