Skip to content

Bump compiler version to Swift 5. #20374

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 9 commits into from
Nov 16, 2018
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 @@ -128,7 +128,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.2")
set(SWIFT_VERSION "5.0")

set(SWIFT_VENDOR "" CACHE STRING
"The vendor name of the Swift compiler")
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 @@ -152,8 +152,8 @@ class Version {

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

Expand Down
16 changes: 6 additions & 10 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,17 @@ Optional<Version> Version::getEffectiveLanguageVersion() const {
// set apply it to the "3" case, so that Swift 4.0.1 will automatically
// have a compatibility mode of 3.2.1.
switch (Components[0]) {
case 3:
#ifdef SWIFT_VERSION_PATCHLEVEL
return Version{3, 4, SWIFT_VERSION_PATCHLEVEL};
#else
return Version{3, 4};
#endif
case 4:
static_assert(SWIFT_VERSION_MAJOR == 4,
"getCurrentLanguageVersion is no longer correct here");
// Version '4' on its own implies '4.1.50'.
if (size() == 1)
return Version{4, 1, 50};
return Version::getCurrentLanguageVersion();
// This should be true because of the check up above.
assert(size() == 2 && Components[0] == 4 && Components[1] == 2);
return Version{4, 2};
case 5:
return Version{5, 0};
static_assert(SWIFT_VERSION_MAJOR == 5,
"getCurrentLanguageVersion is no longer correct here");
return Version::getCurrentLanguageVersion();
default:
return None;
}
Expand Down
25 changes: 0 additions & 25 deletions lib/ClangImporter/ImportEnumInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ STATISTIC(EnumInfoNumCacheMisses, "# of times the enum info cache was missed");
using namespace swift;
using namespace importer;

static void rememberToChangeThisBehaviorInSwift5() {
// Note: Once the compiler starts advertising itself as Swift 5, even
// Swift 4 mode is supposed to treat C enums as non-exhaustive. Because
// it's Swift 4 mode, failing to switch over the whole enum will only
// produce a warning, not an error.
//
// This is an assertion rather than a condition because we /want/ to be
// reminded to take it out when we're ready for the Swift 5 release.
assert(version::getSwiftNumericVersion().first < 5 &&
"When the compiler starts advertising itself as Swift 5, even "
"Swift 4 mode is supposed to treat C enums as non-exhaustive.");
}

/// Find the last extensibility attribute on \p decl as arranged by source
/// location...unless there's an API note, in which case that one wins.
///
Expand All @@ -61,18 +48,6 @@ getBestExtensibilityAttr(clang::Preprocessor &pp, const clang::EnumDecl *decl) {
return next;
}

// Temporarily ignore enum_extensibility attributes inside CF_ENUM and
// similar. In the Swift 5 release we can start respecting this annotation,
// meaning this entire block can be dropped.
{
rememberToChangeThisBehaviorInSwift5();
auto loc = next->getLocation();
if (loc.isMacroID() &&
pp.getImmediateMacroName(loc) == "__CF_ENUM_ATTRIBUTES") {
continue;
}
}

if (!bestSoFar ||
sourceMgr.isBeforeInTranslationUnit(bestSoFar->getLocation(),
next->getLocation())) {
Expand Down
12 changes: 12 additions & 0 deletions test/Driver/swift-version-default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ aoeu // expected-error {{use of unresolved identifier}}
htn
#endif

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

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

#if swift(>=6)
aoeu
#else
htn // expected-error {{use of unresolved identifier}}
Expand Down
24 changes: 9 additions & 15 deletions test/Driver/swift-version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,33 @@
// RUN: not %target-swiftc_driver -swift-version 2.3 %s 2>&1 | %FileCheck --check-prefix BAD %s
// RUN: not %target-swiftc_driver -swift-version 7 %s 2>&1 | %FileCheck --check-prefix BAD %s
// RUN: not %target-swiftc_driver -swift-version 7.2 %s 2>&1 | %FileCheck --check-prefix BAD %s
// 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 3.0 %s 2>&1 | %FileCheck --check-prefix BAD %s
// RUN: not %target-swiftc_driver -swift-version 3.3 %s 2>&1 | %FileCheck --check-prefix BAD %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', '4.2', '5'
// BAD: note: valid arguments to '-swift-version' are '4', '4.2', '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}}
// ERROR_4: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#else
jkl
#endif

#if swift(>=3.1)
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}}
// ERROR_4: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
// ERROR_5: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#else
jkl
#endif
Expand All @@ -44,7 +40,7 @@ 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}}
jkl
#endif

#if swift(>=4.1)
Expand All @@ -53,14 +49,12 @@ asdf
// ERROR_5: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
#else
jkl
// ERROR_3: [[@LINE-1]]: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}}
// ERROR_4: [[@LINE-2]]:1: error: {{use of unresolved identifier}}
// ERROR_4: [[@LINE-1]]:1: error: {{use of unresolved identifier}}
#endif
2 changes: 1 addition & 1 deletion test/Migrator/no_ast_passes_after_swift4.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
// RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
// RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result

Expand Down
2 changes: 1 addition & 1 deletion test/Migrator/no_ast_passes_after_swift4.swift.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
// RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
// RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result

Expand Down
2 changes: 1 addition & 1 deletion test/Migrator/no_double_edit_ast_pass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// REQUIRES: objc_interop
// RUN: %target-swift-frontend -typecheck %s -F %S/mock-sdk
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -c -F %S/mock-sdk -api-diff-data-file %S/DoubleEditAPI.json -update-code -primary-file %s -emit-migrated-file-path %t/no_double_edit_ast_pass.result -o /dev/null
// RUN: %target-swift-frontend -c -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -update-code -primary-file %s -emit-migrated-file-path %t/no_double_edit_ast_pass.result -o /dev/null
// RUN: diff -u %s.expected %t/no_double_edit_ast_pass.result

import Bar
Expand Down
2 changes: 1 addition & 1 deletion test/Migrator/no_double_edit_ast_pass.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// REQUIRES: objc_interop
// RUN: %target-swift-frontend -typecheck %s -F %S/mock-sdk
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -c -F %S/mock-sdk -api-diff-data-file %S/DoubleEditAPI.json -update-code -primary-file %s -emit-migrated-file-path %t/no_double_edit_ast_pass.result -o /dev/null
// RUN: %target-swift-frontend -c -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -update-code -primary-file %s -emit-migrated-file-path %t/no_double_edit_ast_pass.result -o /dev/null
// RUN: diff -u %s.expected %t/no_double_edit_ast_pass.result

import Bar
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/loweraggregateinstrs_expandall.sil
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct S {
}

enum E {
case NoElement()
case NoElement(Void)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: this one should probably go to case NoElement instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @jrose-apple, but I don't quite understand. This change is needed or else the test fails. The compiler now complains about the missing Void.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's unclear whether the test is supposed to be testing a case with no payload or a case with a zero-sized payload, but given the name of the enum case I'm guessing it's the former.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's the latter. @CodaFi banned enums with an empty tuple payload so that we can stage in the 'normalize enum cases' proposal later without breaking source compatibility, and I recall discussing the intent behind this test case at the time.

case TrivialElement(Builtin.Int64)
case ReferenceElement(C1)
case StructNonTrivialElt(S)
Expand Down
2 changes: 1 addition & 1 deletion test/Serialization/version-mismatches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Library
// TOO-NEW: :[[@LINE-2]]:8: error: module file was created by a newer version of the compiler: {{.*}}too-new/Library.swiftmodule{{$}}

// Update this line when the compiler version changes.
// LANGUAGE: :[[@LINE-5]]:8: error: module compiled with Swift X.Y cannot be imported by the Swift 4.{{.+}} compiler: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}
// LANGUAGE: :[[@LINE-5]]:8: error: module compiled with Swift X.Y cannot be imported by the Swift 5.{{.+}} compiler: {{.*}}too-{{old|new}}-language/Library.swiftmodule{{$}}

// Compiler thinks that the module is empty in all cases.
// CHECK: :[[@LINE+1]]:1: error: module 'Library' has no member named 'foo'
Expand Down
Loading