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
}

0 commit comments

Comments
 (0)