Skip to content

Commit bf62690

Browse files
author
Greg Parker
authored
Merge branch 'swift-5.0-branch' into is-swift-bit-5
2 parents cae3421 + 2911f7a commit bf62690

File tree

368 files changed

+10786
-5116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

368 files changed

+10786
-5116
lines changed

CHANGELOG.md

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,109 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27+
* Swift 3 mode has been removed. Supported values for the `-swift-version`
28+
flag are `4`, `4.2`, and `5`.
29+
30+
* [SE-0228][]:
31+
32+
String interpolation has been overhauled to improve its performance,
33+
clarity, and efficiency.
34+
35+
Note that the old `_ExpressibleByStringInterpolation` protocol has been
36+
removed; any code making use of this protocol will need to be updated
37+
for the new design. An `#if compiler` block can be used to conditionalize
38+
code between 4.2 and 5.0, for example:
39+
40+
```swift
41+
#if compiler(<5.0)
42+
extension MyType : _ExpressibleByStringInterpolation { ... }
43+
#else
44+
extension MyType : ExpressibleByStringInterpolation { ... }
45+
#endif
46+
```
47+
48+
* [SE-0213][]:
49+
50+
If `T` conforms to one of the `ExpressibleBy*` protocols and `literal` is a
51+
literal expression, then `T(literal)` will construct a literal of type `T`
52+
using the corresponding protocol, rather than calling a constructor member
53+
of `T` with a value of the protocol's default literal type.
54+
55+
For example, expressions like `UInt64(0xffff_ffff_ffff_ffff)` are now valid,
56+
where previously they would overflow the default integer literal type of `Int`.
57+
58+
* [SE-0230][]:
59+
60+
In Swift 5 mode, `try?` with an expression of Optional type will flatten the
61+
resulting Optional, instead of returning an Optional of an Optional.
62+
63+
* [SR-5719][]:
64+
65+
In Swift 5 mode, `@autoclosure` parameters can no longer be forwarded to
66+
`@autoclosure` arguments in another function call. Instead, you must explicitly
67+
call the function value with `()`; the call itself is wrapped inside an
68+
implicit closure, guaranteeing the same behavior as in Swift 4 mode.
69+
70+
Example:
71+
72+
```swift
73+
func foo(_ fn: @autoclosure () -> Int) {}
74+
func bar(_ fn: @autoclosure () -> Int) {
75+
foo(fn) // Incorrect, `fn` can't be forwarded and has to be called
76+
foo(fn()) // Ok
77+
}
78+
```
79+
80+
* [SR-8109][]:
81+
82+
Single-element labeled tuple expressions, for example `(label: 123)`, were
83+
allowed in some contexts but often resulted in surprising, inconsistent
84+
behavior that varied across compiler releases. They are now completely
85+
disallowed.
86+
87+
Note that single-element labeled _types_, for example `var x: (label: Int)`,
88+
have already been prohibited since Swift 3.
89+
90+
* [SR-695][]:
91+
92+
In Swift 5 mode, a class method returning `Self` can no longer be overridden
93+
with a method returning a non-final concrete class type. Such code is not
94+
type safe and will need to be updated.
95+
96+
For example,
97+
98+
```swift
99+
class Base {
100+
class func factory() -> Self { ... }
101+
}
102+
103+
class Derived : Base {
104+
class override func factory() -> Derived { ... }
105+
}
106+
```
107+
108+
* In Swift 5 mode, the type of `self` in a convenience initializer of a non-final
109+
class is now the dynamic `Self` type, and not the concrete class type.
110+
111+
* [SR-5581][]:
112+
113+
Protocols can now constrain their conforming types to those that subclasses a
114+
given class. Two equivalent forms are supported:
115+
116+
```swift
117+
protocol MyView : UIView { ... }
118+
protocol MyView where Self : UIView { ... }
119+
```
120+
121+
Note that Swift 4.2 accepted the second form, but it was not fully implemented
122+
and could sometimes crash at compile time or run time.
123+
124+
* [SR-631][]:
125+
126+
Extension binding now supports extensions of nested types which themselves are
127+
defined inside extensions. Previously this could fail with some declaration orders,
128+
producing spurious "undeclared type" errors.
129+
27130
* [SR-7139][]:
28131

29132
Exclusive memory access is now enforced at runtime by default in
@@ -113,16 +216,24 @@ Swift 5.0
113216

114217
* [SE-0214][]:
115218

116-
Renamed the `DictionaryLiteral` type to `KeyValuePairs`.
219+
The `DictionaryLiteral` type has been renamed to `KeyValuePairs`.
117220
A typealias preserves the old name for compatibility.
118221

119222
* [SR-2608][]
120223

121224
Default arguments are now printed in SourceKit-generated interfaces for Swift
122225
modules, instead of just using a placeholder `default`.
123226

124-
* Notable bug fix: unowned and unowned(unsafe) variables now support optional
125-
types.
227+
* `unowned` and `unowned(unsafe)` variables now support Optional types.
228+
229+
* Designated initializers with variadic parameters are now correctly inherited
230+
in subclasses.
231+
232+
* Extensions of concrete subclasses of generic classes can now contain
233+
`@objc` members.
234+
235+
* Complex recursive type definitions involving classes and generics that would
236+
previously cause deadlocks at run time are now fully supported.
126237

127238
* [SR-419][]
128239

@@ -7293,9 +7404,13 @@ Swift 1.0
72937404
[SE-0225]: <https://github.com/apple/swift-evolution/blob/master/proposals/0225-binaryinteger-iseven-isodd-ismultiple.md>
72947405
[SE-0226]: <https://github.com/apple/swift-evolution/blob/master/proposals/0226-package-manager-target-based-dep-resolution.md>
72957406
[SE-0227]: <https://github.com/apple/swift-evolution/blob/master/proposals/0227-identity-keypath.md>
7407+
[SE-0228]: <https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
7408+
[SE-0230]: <https://github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
72967409

72977410
[SR-106]: <https://bugs.swift.org/browse/SR-106>
72987411
[SR-419]: <https://bugs.swift.org/browse/SR-419>
7412+
[SR-631]: <https://bugs.swift.org/browse/SR-631>
7413+
[SR-695]: <https://bugs.swift.org/browse/SR-695>
72997414
[SR-1009]: <https://bugs.swift.org/browse/SR-1009>
73007415
[SR-1446]: <https://bugs.swift.org/browse/SR-1446>
73017416
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
@@ -7304,5 +7419,8 @@ Swift 1.0
73047419
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
73057420
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
73067421
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
7422+
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
7423+
[SR-5719]: <https://bugs.swift.org/browse/SR-5719>
73077424
[SR-7139]: <https://bugs.swift.org/browse/SR-7139>
73087425
[SR-7251]: <https://bugs.swift.org/browse/SR-7251>
7426+
[SR-8109]: <https://bugs.swift.org/browse/SR-8109>

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ endif()
912912
# https://bugs.swift.org/browse/SR-5975
913913
add_subdirectory(stdlib)
914914

915+
add_subdirectory(include)
916+
915917
if(SWIFT_INCLUDE_TOOLS)
916-
add_subdirectory(include)
917918
add_subdirectory(lib)
918919

919920
# Always include this after including stdlib/!

cmake/modules/AddSwift.cmake

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,14 @@ function(_add_variant_link_flags)
432432
# we need to add the math library, which is linked implicitly by libc++.
433433
list(APPEND result "-nostdlib++" "-lm")
434434
if("${LFLAGS_ARCH}" MATCHES armv7)
435-
list(APPEND result "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so")
435+
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a")
436436
elseif("${LFLAGS_ARCH}" MATCHES aarch64)
437-
list(APPEND result "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so")
437+
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/arm64-v8a")
438438
else()
439439
message(SEND_ERROR "unknown architecture (${LFLAGS_ARCH}) for android")
440440
endif()
441+
list(APPEND link_libraries "${android_libcxx_path}/libc++abi.a")
442+
list(APPEND link_libraries "${android_libcxx_path}/libc++_shared.so")
441443
swift_android_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
442444
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
443445
list(APPEND library_search_directories ${path})
@@ -936,10 +938,15 @@ function(_add_swift_library_single target name)
936938
# target_sources(${target}
937939
# PRIVATE
938940
# $<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTLIB_SINGLE_ARCHITECTURE}>)
941+
if(SWIFTLIB_SINGLE_SDK STREQUAL WINDOWS)
942+
set(extension .obj)
943+
else()
944+
set(extension .o)
945+
endif()
939946
target_sources(${target}
940947
PRIVATE
941-
"${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}/swiftrt${CMAKE_C_OUTPUT_EXTENSION}")
942-
set_source_files_properties("${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}/swiftrt${CMAKE_C_OUTPUT_EXTENSION}"
948+
"${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}/swiftrt${extension}")
949+
set_source_files_properties("${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}/swiftrt${extension}"
943950
PROPERTIES
944951
GENERATED 1)
945952
endif()
@@ -2139,11 +2146,20 @@ function(_add_swift_executable_single name)
21392146
# Find the names of dependency library targets.
21402147
#
21412148
# We don't add the ${ARCH} to the target suffix because we want to link
2142-
# against fat libraries.
2143-
_list_add_string_suffix(
2144-
"${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES}"
2145-
"-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}"
2146-
SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS)
2149+
# against fat libraries. This only works for the Darwin targets as MachO is
2150+
# the only format with the fat libraries.
2151+
if(${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
2152+
_list_add_string_suffix(
2153+
"${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES}"
2154+
"-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}"
2155+
SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS)
2156+
else()
2157+
_list_add_string_suffix(
2158+
"${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES}"
2159+
"-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}"
2160+
SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS)
2161+
set(SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES ${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS})
2162+
endif()
21472163

21482164
handle_swift_sources(
21492165
dependency_target

cmake/modules/StandaloneOverlay.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ precondition(SWIFT_DEST_ROOT)
5858
precondition(SWIFT_HOST_VARIANT_SDK)
5959
precondition(TOOLCHAIN_DIR)
6060

61+
# Some overlays include the runtime's headers,
62+
# and some of those headers are generated at build time.
63+
add_subdirectory("${SWIFT_SOURCE_DIR}/include" "swift/include")
64+
6165
# Without this line, installing components is broken. This needs refactoring.
6266
swift_configure_components()
6367

docs/ABI/Mangling.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ Globals
146146
global ::= type protocol-conformance 'WL' // lazy protocol witness table cache variable
147147

148148
global ::= protocol-conformance identifier 'Wt' // associated type metadata accessor (HISTORICAL)
149-
global ::= protocol-conformance assoc-type-list nominal-type 'WT' // associated type witness table accessor
149+
global ::= protocol-conformance assoc-type-list protocol 'WT' // associated type witness table accessor
150+
global ::= protocol-conformance protocol 'Wb' // base protocol witness table accessor
150151
global ::= type protocol-conformance 'Wl' // lazy protocol witness table accessor
151152

152153
global ::= type 'WV' // value witness table
@@ -200,6 +201,7 @@ types where the metadata itself has unknown layout.)
200201
global ::= assoc-type-name 'TM' // default associated type witness accessor (HISTORICAL)
201202
global ::= type assoc-type-list protocol 'Tn' // associated conformance descriptor
202203
global ::= type assoc-type-list protocol 'TN' // default associated conformance witness accessor
204+
global ::= type protocol 'Tb' // base conformance descriptor
203205

204206
REABSTRACT-THUNK-TYPE ::= 'R' // reabstraction thunk helper function
205207
REABSTRACT-THUNK-TYPE ::= 'r' // reabstraction thunk
@@ -631,7 +633,7 @@ Property behaviors are implemented using private protocol conformances.
631633
::
632634

633635
concrete-protocol-conformance ::= type protocol-conformance-ref any-protocol-conformance-list 'HC'
634-
protocol-conformance-ref ::= protocol module?
636+
protocol-conformance-ref ::= protocol module? 'HP'
635637

636638
any-protocol-conformance ::= concrete-protocol-conformance
637639
any-protocol-conformance ::= dependent-protocol-conformance

docs/Runtime.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ optimization.
260260
0000000000023a40 T _swift_assignExistentialWithCopy
261261
000000000001dbf0 T _swift_copyPOD
262262
000000000001c560 T _swift_getEnumCaseMultiPayload
263-
000000000001be60 T _swift_getEnumCaseSinglePayload
264263
000000000001c400 T _swift_storeEnumTagMultiPayload
265-
000000000001bf90 T _swift_storeEnumTagSinglePayload
266264
```
267265

268266
## Type metadata lookup

include/swift/ABI/Metadata.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,9 @@ class TargetValueWitnessTypes {
295295
// Handle the data witnesses explicitly so we can use more specific
296296
// types for the flags enums.
297297
typedef size_t size;
298-
typedef ValueWitnessFlags flags;
299298
typedef size_t stride;
300-
typedef ExtraInhabitantFlags extraInhabitantFlags;
301-
299+
typedef ValueWitnessFlags flags;
300+
typedef uint32_t extraInhabitantCount;
302301
};
303302

304303
struct TypeLayout;
@@ -376,16 +375,9 @@ template <typename Runtime> struct TargetValueWitnessTable {
376375

377376
/// The number of extra inhabitants, that is, bit patterns that do not form
378377
/// valid values of the type, in this type's binary representation.
379-
unsigned getNumExtraInhabitants() const;
380-
381-
/// Assert that this value witness table is an extra-inhabitants
382-
/// value witness table and return it as such.
383-
///
384-
/// This has an awful name because it's supposed to be internal to
385-
/// this file. Code outside this file should use LLVM's cast/dyn_cast.
386-
/// We don't want to use those here because we need to avoid accidentally
387-
/// introducing ABI dependencies on LLVM structures.
388-
const struct ExtraInhabitantsValueWitnessTable *_asXIVWT() const;
378+
unsigned getNumExtraInhabitants() const {
379+
return extraInhabitantCount;
380+
}
389381

390382
/// Assert that this value witness table is an enum value witness table
391383
/// and return it as such.
@@ -608,13 +600,6 @@ struct TargetMetadata {
608600
#define DATA_VALUE_WITNESS(LOWER, UPPER, TYPE)
609601
#include "swift/ABI/ValueWitness.def"
610602

611-
int vw_getExtraInhabitantIndex(const OpaqueValue *value) const {
612-
return getValueWitnesses()->_asXIVWT()->getExtraInhabitantIndex(value, this);
613-
}
614-
void vw_storeExtraInhabitant(OpaqueValue *value, int index) const {
615-
getValueWitnesses()->_asXIVWT()->storeExtraInhabitant(value, index, this);
616-
}
617-
618603
unsigned vw_getEnumTag(const OpaqueValue *value) const {
619604
return getValueWitnesses()->_asEVWT()->getEnumTag(const_cast<OpaqueValue*>(value), this);
620605
}
@@ -637,6 +622,10 @@ struct TargetMetadata {
637622
return getValueWitnesses()->getStride();
638623
}
639624

625+
unsigned vw_getNumExtraInhabitants() const {
626+
return getValueWitnesses()->getNumExtraInhabitants();
627+
}
628+
640629
/// Allocate an out-of-line buffer if values of this type don't fit in the
641630
/// ValueBuffer.
642631
/// NOTE: This is not a box for copy-on-write existentials.

0 commit comments

Comments
 (0)