"-swift-version 3" means Swift 3.1, not 3.0. (#7883)

Put in a general mechanism for mapping user-specified "compatibility
versions" to proper "effective versions" (what #if and @available
checking should respect). This may still be different from the
intrinsic "language version"; right now master is considered a "3.1"
compiler with a "Swift 4 mode", and we plan to ship a "4.0" compiler
with a "Swift 3 mode" that will have a version number of something
like "3.2".

rdar://problem/29884401 / SR-3791
This commit is contained in:
Jordan Rose
2017-03-03 13:28:01 -08:00
committed by GitHub
parent bc6ea5b00f
commit 3456d04925
7 changed files with 130 additions and 42 deletions

View File

@@ -52,13 +52,16 @@ namespace version {
/// a: [0 - 999]
/// b: [0 - 999]
class Version {
SmallVector<uint64_t, 5> Components;
SmallVector<unsigned, 5> Components;
public:
/// Create the empty compiler version - this always compares greater
/// or equal to any other CompilerVersion, as in the case of building Swift
/// from latest sources outside of a build/integration/release context.
Version() = default;
/// Create a literal version from a list of components.
Version(std::initializer_list<unsigned> Values) : Components(Values) {}
/// Create a version from a string in source code.
///
/// Must include only groups of digits separated by a dot.
@@ -94,11 +97,15 @@ public:
/// away any 5th component that might be in this version.
operator clang::VersionTuple() const;
/// Return whether this version is a valid Swift language version number
/// to set the compiler to using -swift-version; this is not the same as
/// the set of Swift versions that have ever existed, just those that we
/// are attempting to maintain backward-compatibility support for.
bool isValidEffectiveLanguageVersion() const;
/// Returns the concrete version to use when \e this version is provided as
/// an argument to -swift-version.
///
/// This is not the same as the set of Swift versions that have ever existed,
/// just those that we are attempting to maintain backward-compatibility
/// support for. It's also common for valid versions to produce a different
/// result; for example "-swift-version 3" at one point instructed the
/// compiler to act as if it is version 3.1.
Optional<Version> getEffectiveLanguageVersion() const;
/// Whether this version is in the Swift 3 family
bool isVersion3() const { return !empty() && Components[0] == 3; }
@@ -141,6 +148,10 @@ bool operator==(const Version &lhs, const Version &rhs);
raw_ostream &operator<<(raw_ostream &os, const Version &version);
/// Retrieves the numeric {major, minor} Swift version.
///
/// Note that this is the underlying version of the language, ignoring any
/// -swift-version flags that may have been used in a particular invocation of
/// the compiler.
std::pair<unsigned, unsigned> getSwiftNumericVersion();
/// Retrieves a string representing the complete Swift version, which includes