Skip to content

Commit f26e326

Browse files
authored
Merge branch 'swift-5.1-branch' into fix/SR-10084
2 parents 4270f3f + 7937bbb commit f26e326

File tree

1,877 files changed

+360366
-281167
lines changed

Some content is hidden

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

1,877 files changed

+360366
-281167
lines changed

CHANGELOG.md

Lines changed: 236 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,223 @@ CHANGELOG
2525
Swift 5.1
2626
---------
2727

28+
* [SR-8974][]:
29+
30+
Duplicate tuple element labels are no longer allowed, because it leads
31+
to incorrect behavior. For example:
32+
33+
```
34+
let dupLabels: (foo: Int, foo: Int) = (foo: 1, foo: 2)
35+
36+
enum Foo { case bar(x: Int, x: Int) }
37+
let f: Foo = .bar(x: 0, x: 1)
38+
```
39+
40+
will now be diagnosed as an error.
41+
42+
Note: You can still use duplicate labels when declaring functions and
43+
subscripts, as long as the internal labels are different. For example:
44+
45+
```
46+
func foo(bar x: Int, bar y: Int) {}
47+
subscript(a x: Int, a y: Int) -> Int {}
48+
```
49+
50+
* [SE-0244][]:
51+
52+
Functions can now hide their concrete return type by declaring what protocols
53+
it conforms to instead of specifying the exact return type:
54+
55+
```
56+
func makeMeACollection() -> some Collection {
57+
return [1, 2, 3]
58+
}
59+
```
60+
61+
Code that calls the function can use the interface of the protocol, but
62+
does not have visibility into the underlying type.
63+
64+
* [SE-0254][]:
65+
66+
Subscripts can now be declared `static` or (inside classes) `class`.
67+
68+
* [SE-0252][]:
69+
70+
The existing `@dynamicMemberLookup` attribute has been extended with a
71+
support for strongly-typed keypath implementations:
72+
73+
```swift
74+
@dynamicMemberLookup
75+
struct Lens<T> {
76+
let getter: () -> T
77+
let setter: (T) -> Void
78+
79+
var value: T {
80+
get {
81+
return getter()
82+
}
83+
set {
84+
setter(newValue)
85+
}
86+
}
87+
88+
subscript<U>(dynamicMember keyPath: WritableKeyPath<T, U>) -> Lens<U> {
89+
return Lens<U>(
90+
getter: { self.value[keyPath: keyPath] },
91+
setter: { self.value[keyPath: keyPath] = $0 })
92+
}
93+
}
94+
```
95+
96+
* [SR-8546][], [SR-9043][]:
97+
98+
More thorough checking has been implemented for restrictions around
99+
escaping closures capturing `inout` parameters or values of noescape type.
100+
While most code should not be affected, there are edge cases where
101+
the Swift 5.0 compiler would accept code violating these restrictions.
102+
This could result in runtime crashes or silent data corruption.
103+
104+
An example of invalid code which was incorrectly accepted by the Swift 5.0
105+
compiler is an `@escaping` closure calling a local function which
106+
references an `inout` parameter from an outer scope:
107+
108+
```swift
109+
struct BadCaptureExample {
110+
var escapingClosure: () -> ()
111+
112+
mutating func takesInOut(_ x: inout Int) {
113+
func localFunction() {
114+
x += 1
115+
}
116+
117+
escapingClosure = { localFunction() }
118+
}
119+
}
120+
```
121+
122+
The compiler now correctly diagnoses the above code by pointing out that
123+
the capture of `x` by `localFunction()` is invalid, since `localFunction()`
124+
is referenced from an `@escaping` closure.
125+
126+
This also addresses certain cases where the compiler incorrectly diagnosed
127+
certain code as invalid, when in fact no violation of restrictions had
128+
taken place. For example,
129+
130+
```swift
131+
func takesNoEscape(_ fn: () -> ()) {
132+
func localFunction() {
133+
fn()
134+
}
135+
136+
{ localFunction() }()
137+
}
138+
```
139+
140+
* [SR-2672][]:
141+
142+
Conversions between tuple types are now fully implemented.
143+
Previously, the following would diagnose an error:
144+
145+
```swift
146+
let values: (Int, Int) = (10, 15)
147+
let converted: (Int?, Any) = values
148+
149+
* [SE-0242][]:
150+
151+
The memberwise initializer for structures now provide default values for variables that hold default expressions.
152+
153+
```swift
154+
struct Dog {
155+
var name = "Generic dog name"
156+
var age = 0
157+
158+
// The synthesized memberwise initializer
159+
init(name: String = "Generic dog name", age: Int = 0)
160+
}
161+
162+
let sparky = Dog(name: "Sparky") // Dog(name: "Sparky", age: 0)
163+
```
164+
165+
* [SE-0068][]:
166+
167+
It is now possible to use `Self` to refer to the innermost nominal
168+
type inside struct, enum and class declarations. For example, the
169+
two method declarations inside this struct are equivalent:
170+
171+
```swift
172+
struct Box<Value> {
173+
func transform1() -> Self { return self }
174+
func transform2() -> Box<Value> { return self }
175+
}
176+
```
177+
178+
In classes, `Self` is the dynamic type of the `self` value, as before.
179+
Existing restrictions on `Self` in declaration types still apply;
180+
that is, `Self` can only appear as the return type of a method.
181+
However, `Self` can now be used inside the body of a method
182+
without limitation.
183+
184+
* [SR-7799][]:
185+
186+
Enum cases can now be matched against an optional enum without
187+
requiring a '?' at the end of the pattern.
188+
189+
```swift
190+
enum Foo { case zero, one }
191+
192+
let foo: Foo? = .zero
193+
194+
switch foo {
195+
case .zero: break
196+
case .one: break
197+
case .none: break
198+
}
199+
```
200+
201+
* `weak` and `unowned` stored properties no longer inhibit the
202+
automatic synthesis of `Equatable` or `Hashable` conformance.
203+
204+
* [SR-2688][]:
205+
206+
An `@autoclosure` parameter can now be declared with a typealias type.
207+
208+
```swift
209+
class Foo {
210+
typealias FooClosure = () -> String
211+
func fooFunction(closure: @autoclosure FooClosure) {}
212+
}
213+
```
214+
215+
* [SR-7601][]:
216+
217+
Methods declared `@objc` inside a class can now return `Self`:
218+
219+
```swift
220+
class MyClass : NSObject {
221+
@objc func clone() -> Self { return self }
222+
}
223+
```
224+
225+
* [SR-2176][]:
226+
227+
Assigning '.none' to an optional enum which also has a 'none' case
228+
or comparing such an enum with '.none' will now warn. Such expressions
229+
create an ambiguity because the compiler chooses Optional.none
230+
over Foo.none.
231+
232+
```swift
233+
enum Foo { case none }
234+
235+
// Assigned Optional.none instead of Foo.none
236+
let foo: Foo? = .none
237+
// Comparing with Optional.none instead of Foo.none
238+
let isEqual = foo == .none
239+
```
240+
241+
The compiler will provide a warning along with a fix-it to
242+
replace '.none' with 'Optional.none' or 'Foo.none' to resolve
243+
the ambiguity.
244+
28245
* Key path expressions can now include references to tuple elements.
29246

30247
* Single-parameter functions accepting values of type `Any` are no
@@ -36,11 +253,18 @@ Swift 5.1
36253
foo(0) // prints "Any" in Swift < 5.1, "T" in Swift 5.1
37254
```
38255

256+
* [SE-0245][]:
257+
258+
`Array` and `ContiguousArray` now have `init(unsafeUninitializedCapacity:initializingWith:)`,
259+
which provides access to the array's uninitialized storage.
260+
39261
**Add new entries to the top of this section, not here!**
40262

41263
Swift 5.0
42264
---------
43265

266+
### 2019-03-25 (Xcode 10.2)
267+
44268
* [SE-0235][]:
45269

46270
The standard library now contains a `Result` type for manually propagating errors.
@@ -301,8 +525,6 @@ Swift 5.0
301525
}
302526
```
303527

304-
**Add new entries to the top of this section, not here!**
305-
306528
Swift 4.2
307529
---------
308530

@@ -7443,6 +7665,10 @@ Swift 1.0
74437665
[SE-0228]: <https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
74447666
[SE-0230]: <https://github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
74457667
[SE-0235]: <https://github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md>
7668+
[SE-0242]: <https://github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md>
7669+
[SE-0245]: <https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
7670+
[SE-0252]: <https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md>
7671+
[SE-0254]: <https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
74467672

74477673
[SR-106]: <https://bugs.swift.org/browse/SR-106>
74487674
[SR-419]: <https://bugs.swift.org/browse/SR-419>
@@ -7452,12 +7678,20 @@ Swift 1.0
74527678
[SR-1446]: <https://bugs.swift.org/browse/SR-1446>
74537679
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
74547680
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
7681+
[SR-2176]: <https://bugs.swift.org/browse/SR-2176>
74557682
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
74567683
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
74577684
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7685+
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
7686+
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
74587687
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
74597688
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
74607689
[SR-5719]: <https://bugs.swift.org/browse/SR-5719>
74617690
[SR-7139]: <https://bugs.swift.org/browse/SR-7139>
74627691
[SR-7251]: <https://bugs.swift.org/browse/SR-7251>
7692+
[SR-7601]: <https://bugs.swift.org/browse/SR-7601>
7693+
[SR-7799]: <https://bugs.swift.org/browse/SR-7799>
74637694
[SR-8109]: <https://bugs.swift.org/browse/SR-8109>
7695+
[SR-8546]: <https://bugs.swift.org/browse/SR-8546>
7696+
[SR-8974]: <https://bugs.swift.org/browse/SR-8974>
7697+
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>

0 commit comments

Comments
 (0)