Skip to content

Updating compiler versions (4.1, 3.3, able to do swift-version 5) #11507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ set_property(CACHE SWIFT_ANALYZE_CODE_COVERAGE PROPERTY
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
# can be reused when a new version of Swift comes out (assuming the user hasn't
# manually set it as part of their own CMake configuration).
set(SWIFT_VERSION "4.0")
set(SWIFT_VERSION "4.1")

set(SWIFT_VENDOR "" CACHE STRING
"The vendor name of the Swift compiler")
Expand Down
2 changes: 1 addition & 1 deletion docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ FIXME: full list.

* ``optimized_stdlib_<CPUNAME>``: an optimized stdlib plus cpu configuration.

* ``SWIFT_VERSION=<MAJOR>``: restricts a test to Swift 3 or Swift 4. If you
* ``SWIFT_VERSION=<MAJOR>``: restricts a test to Swift 3, Swift 4, Swift 5. If you
need to use this, make sure to add a test for the other version as well
unless you are specifically testing ``-swift-version``-related functionality.

Expand Down
4 changes: 2 additions & 2 deletions include/swift/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class Version {

// Whitelist of backward-compatibility versions that we permit passing as
// -swift-version <vers>
static std::array<StringRef, 2> getValidEffectiveVersions() {
return {{"3", "4"}};
static std::array<StringRef, 3> getValidEffectiveVersions() {
return {{"3", "4", "5"}};
};
};

Expand Down
6 changes: 4 additions & 2 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,16 @@ Optional<Version> Version::getEffectiveLanguageVersion() const {
switch (Components[0]) {
case 3:
#ifdef SWIFT_VERSION_PATCHLEVEL
return Version{3, 2, SWIFT_VERSION_PATCHLEVEL};
return Version{3, 3, SWIFT_VERSION_PATCHLEVEL};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple expressed some concern about moving this to 3.3 because comparisons on version ranges of being greater than 3.2 will encompass 4.0, 5.0, etc. It's something we likely need to handle, but if people are using "> 3.2" to check if it is Swift 4 then bumping the Swift 3 version to "3.3.x" will cause problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Since that part means means rethinking our design of #if swift, I was planning on doing that separately. If folks need to have separate code between 4 and 4.1, they can conditionalize those separately as a workaround. It could lead to some duplication of code and that's why a rethink of #if swift or an introduction of another mechanism might be desirable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this up, Ted. I think I agree with Ewa that it's better to have something in place that we can modify later. We certainly don't want to continue advertising ourselves as Swift 3.2.

(Further information: we only allow >= checks, so the concern isn't about 3.2 but about 3.3. There's no way to check for "3.3 or 4.1 but not 4.0". This could also be a problem if we do any patch releases of 4.0.)

#else
return Version{3, 2};
return Version{3, 3};
#endif
case 4:
static_assert(SWIFT_VERSION_MAJOR == 4,
"getCurrentLanguageVersion is no longer correct here");
return Version::getCurrentLanguageVersion();
case 5:
return Version{5, 0};
default:
return None;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ importer::nameVersionFromOptions(const LangOptions &langOpts) {
return ImportNameVersion::Swift2;
case 3:
return ImportNameVersion::Swift3;
// Fixme: Figure out the importing story for 5 instead of falling back to 4.
case 4:
case 5:
return ImportNameVersion::Swift4;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/swift-version-default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ htn
#endif

#if swift(>=4.1)
aoeu
aoeu // expected-error {{use of unresolved identifier}}
#else
htn // expected-error {{use of unresolved identifier}}
htn
#endif

#if swift(>=5)
Expand Down
15 changes: 12 additions & 3 deletions test/Driver/swift-version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
// RUN: not %target-swiftc_driver -swift-version 3.0 %s 2>&1 | %FileCheck --check-prefix FIXIT_3 %s
// RUN: not %target-swiftc_driver -swift-version 3.3 %s 2>&1 | %FileCheck --check-prefix FIXIT_3 %s
// RUN: not %target-swiftc_driver -swift-version 4.3 %s 2>&1 | %FileCheck --check-prefix FIXIT_4 %s
// RUN: not %target-swiftc_driver -swift-version 5.1 %s 2>&1 | %FileCheck --check-prefix FIXIT_5 %s

// RUN: not %target-swiftc_driver -swift-version 3 -typecheck %s 2>&1 | %FileCheck --check-prefix ERROR_3 %s
// RUN: not %target-swiftc_driver -swift-version 4 -typecheck %s 2>&1 | %FileCheck --check-prefix ERROR_4 %s
// RUN: not %target-swiftc_driver -swift-version 5 -typecheck %s 2>&1 | %FileCheck --check-prefix ERROR_5 %s

// BAD: invalid value
// BAD: note: valid arguments to '-swift-version' are '3', '4'
// BAD: note: valid arguments to '-swift-version' are '3', '4', '5'

// FIXIT_3: use major version, as in '-swift-version 3'
// FIXIT_4: use major version, as in '-swift-version 4'
// FIXIT_5: use major version, as in '-swift-version 5'


#if swift(>=3)
asdf
// ERROR_3: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_4: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-3]]:1: error: {{use of unresolved identifier}}
#else
jkl
#endif
Expand All @@ -30,26 +34,31 @@ jkl
asdf
// ERROR_3: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_4: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-3]]:1: error: {{use of unresolved identifier}}
#else
jkl
#endif

#if swift(>=4)
asdf // ERROR_4: [[@LINE]]:1: error: {{use of unresolved identifier}}
asdf
// ERROR_4: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#else
jkl // ERROR_3: [[@LINE]]:1: error: {{use of unresolved identifier}}
#endif

#if swift(>=4.1)
asdf
// ERROR_4: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#else
jkl
// ERROR_3: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_4: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#endif

#if swift(>=5)
asdf
// ERROR_5: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
#else
jkl
// ERROR_3: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#endif

#if swift(>=4.0.1)
let z = 1
#else
// This shouldn't emit any diagnostics.
asdf asdf asdf asdf
#else
let z = 1
#endif

2 changes: 1 addition & 1 deletion test/Serialization/Recovery/crash-recovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Sub: Base {

// CHECK-CRASH: error: fatal error encountered while reading from module 'Lib'; please file a bug report with your project and the crash log
// CHECK-CRASH-3-NOT: note
// CHECK-CRASH-4: note: compiling as Swift 4.0, with 'Lib' built as Swift 3.2
// CHECK-CRASH-4: note: compiling as Swift 4.1, with 'Lib' built as Swift 3.3
// CHECK-CRASH-LABEL: *** DESERIALIZATION FAILURE (please include this section in any bug report) ***
// CHECK-CRASH: could not find 'disappearingMethod()' in parent class
// CHECK-CRASH: While loading members for 'Sub' in module 'Lib'
4 changes: 2 additions & 2 deletions test/Serialization/Recovery/types-4-to-3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import Lib
func requiresConformance(_: B_RequiresConformance<B_ConformsToProto>) {}
func requiresConformance(_: B_RequiresConformance<C_RelyOnConformanceImpl.Assoc>) {}

class Sub: Base {} // expected-error {{cannot inherit from class 'Base' (compiled with Swift 4.0) because it has overridable members that could not be loaded in Swift 3.2}}
class Impl: Proto {} // expected-error {{type 'Impl' cannot conform to protocol 'Proto' (compiled with Swift 4.0) because it has requirements that could not be loaded in Swift 3.2}}
class Sub: Base {} // expected-error {{cannot inherit from class 'Base' (compiled with Swift 4.1) because it has overridable members that could not be loaded in Swift 3.3}}
class Impl: Proto {} // expected-error {{type 'Impl' cannot conform to protocol 'Proto' (compiled with Swift 4.1) because it has requirements that could not be loaded in Swift 3.3}}

#else // TEST

Expand Down
2 changes: 1 addition & 1 deletion utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ iterations with -O",
"--swift-user-visible-version",
help="User-visible version of the embedded Swift compiler",
type=arguments.type.swift_compiler_version,
default="4.0",
default="4.1",
metavar="MAJOR.MINOR")

parser.add_argument(
Expand Down