Skip to content

Commit 7334319

Browse files
committed
Merge branch 'master' into static-min-max
2 parents 4b94685 + c388946 commit 7334319

File tree

376 files changed

+36956
-5727
lines changed

Some content is hidden

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

376 files changed

+36956
-5727
lines changed

CHANGELOG.md

Lines changed: 169 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
| Contents |
88
| :--------------------- |
9+
| [Swift Next](#swift-next) |
910
| [Swift 5.1](#swift-51) |
1011
| [Swift 5.0](#swift-50) |
1112
| [Swift 4.2](#swift-42) |
@@ -22,12 +23,162 @@ CHANGELOG
2223

2324
</details>
2425

26+
Swift Next
27+
----------
28+
29+
* [SR-6118][]:
30+
31+
Subscripts can now declare default arguments:
32+
33+
```swift
34+
struct Subscriptable {
35+
subscript(x: Int, y: Int = 0) {
36+
...
37+
}
38+
}
39+
40+
let s = Subscriptable()
41+
print(s[0])
42+
```
43+
44+
**Add new entries to the top of this section, not here!**
45+
2546
Swift 5.1
2647
---------
2748

49+
* [SE-0244][]:
50+
51+
Functions can now hide their concrete return type by declaring what protocols
52+
it conforms to instead of specifying the exact return type:
53+
54+
```
55+
func makeMeACollection() -> some Collection {
56+
return [1, 2, 3]
57+
}
58+
```
59+
60+
Code that calls the function can use the interface of the protocol, but
61+
does not have visibility into the underlying type.
62+
63+
* [SE-0254][]:
64+
65+
Subscripts can now be declared `static` or (inside classes) `class`.
66+
67+
* [SE-0252][]:
68+
69+
The existing `@dynamicMemberLookup` attribute has been extended with a
70+
support for strongly-typed keypath implementations:
71+
72+
```swift
73+
@dynamicMemberLookup
74+
struct Lens<T> {
75+
let getter: () -> T
76+
let setter: (T) -> Void
77+
78+
var value: T {
79+
get {
80+
return getter()
81+
}
82+
set {
83+
setter(newValue)
84+
}
85+
}
86+
87+
subscript<U>(dynamicMember keyPath: WritableKeyPath<T, U>) -> Lens<U> {
88+
return Lens<U>(
89+
getter: { self.value[keyPath: keyPath] },
90+
setter: { self.value[keyPath: keyPath] = $0 })
91+
}
92+
}
93+
```
94+
95+
* [SR-8546][], [SR-9043][]:
96+
97+
More thorough checking has been implemented for restrictions around
98+
escaping closures capturing `inout` parameters or values of noescape type.
99+
While most code should not be affected, there are edge cases where
100+
the Swift 5.0 compiler would accept code violating these restrictions.
101+
This could result in runtime crashes or silent data corruption.
102+
103+
An example of invalid code which was incorrectly accepted by the Swift 5.0
104+
compiler is an `@escaping` closure calling a local function which
105+
references an `inout` parameter from an outer scope:
106+
107+
```swift
108+
struct BadCaptureExample {
109+
var escapingClosure: () -> ()
110+
111+
mutating func takesInOut(_ x: inout Int) {
112+
func localFunction() {
113+
x += 1
114+
}
115+
116+
escapingClosure = { localFunction() }
117+
}
118+
}
119+
```
120+
121+
The compiler now correctly diagnoses the above code by pointing out that
122+
the capture of `x` by `localFunction()` is invalid, since `localFunction()`
123+
is referenced from an `@escaping` closure.
124+
125+
This also addresses certain cases where the compiler incorrectly diagnosed
126+
certain code as invalid, when in fact no violation of restrictions had
127+
taken place. For example,
128+
129+
```swift
130+
func takesNoEscape(_ fn: () -> ()) {
131+
func localFunction() {
132+
fn()
133+
}
134+
135+
{ localFunction() }()
136+
}
137+
```
138+
139+
* [SR-2672][]:
140+
141+
Conversions between tuple types are now fully implemented.
142+
Previously, the following would diagnose an error:
143+
144+
```swift
145+
let values: (Int, Int) = (10, 15)
146+
let converted: (Int?, Any) = values
147+
148+
* [SE-0242][]:
149+
150+
The memberwise initializer for structures now provide default values for variables that hold default expressions.
151+
152+
```swift
153+
struct Dog {
154+
var name = "Generic dog name"
155+
var age = 0
156+
157+
// The synthesized memberwise initializer
158+
init(name: String = "Generic dog name", age: Int = 0)
159+
}
160+
161+
let sparky = Dog(name: "Sparky") // Dog(name: "Sparky", age: 0)
162+
```
163+
28164
* [SE-0068][]:
29165

30-
`Self` can now be used inside member functions and for function arguments of structs and enums to refer to the containing type.
166+
It is now possible to use `Self` to refer to the innermost nominal
167+
type inside struct, enum and class declarations. For example, the
168+
two method declarations inside this struct are equivalent:
169+
170+
```swift
171+
struct Box<Value> {
172+
func transform1() -> Self { return self }
173+
func transform2() -> Box<Value> { return self }
174+
}
175+
```
176+
177+
In classes, `Self` is the dynamic type of the `self` value, as before.
178+
Existing restrictions on `Self` in declaration types still apply;
179+
that is, `Self` can only appear as the return type of a method.
180+
However, `Self` can now be used inside the body of a method
181+
without limitation.
31182

32183
* [SR-7799][]:
33184

@@ -46,12 +197,12 @@ Swift 5.1
46197
}
47198
```
48199

49-
* `weak` and `unowned` variables can now be used inside types that
50-
declare `Equatable` or `Hashable` conformance.
200+
* `weak` and `unowned` stored properties no longer inhibit the
201+
automatic synthesis of `Equatable` or `Hashable` conformance.
51202

52203
* [SR-2688][]:
53204

54-
An `@autoclosure` closure can now be a typealias.
205+
An `@autoclosure` parameter can now be declared with a typealias type.
55206

56207
```swift
57208
class Foo {
@@ -62,10 +213,12 @@ Swift 5.1
62213

63214
* [SR-7601][]:
64215

65-
Functions marked with `@objc` can now return `Self`
216+
Methods declared `@objc` inside a class can now return `Self`:
66217

67218
```swift
68-
@objc func returnDynamicSelf() -> Self { return self }
219+
class MyClass : NSObject {
220+
@objc func clone() -> Self { return self }
221+
}
69222
```
70223

71224
* [SR-2176][]:
@@ -109,6 +262,8 @@ Swift 5.1
109262
Swift 5.0
110263
---------
111264

265+
### 2019-03-25 (Xcode 10.2)
266+
112267
* [SE-0235][]:
113268

114269
The standard library now contains a `Result` type for manually propagating errors.
@@ -369,8 +524,6 @@ Swift 5.0
369524
}
370525
```
371526

372-
**Add new entries to the top of this section, not here!**
373-
374527
Swift 4.2
375528
---------
376529

@@ -7511,7 +7664,11 @@ Swift 1.0
75117664
[SE-0228]: <https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
75127665
[SE-0230]: <https://github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
75137666
[SE-0235]: <https://github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md>
7667+
[SE-0242]: <https://github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md>
7668+
[SE-0244]: <https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md>
75147669
[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>
75157672

75167673
[SR-106]: <https://bugs.swift.org/browse/SR-106>
75177674
[SR-419]: <https://bugs.swift.org/browse/SR-419>
@@ -7525,12 +7682,16 @@ Swift 1.0
75257682
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
75267683
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
75277684
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7685+
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
75287686
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
75297687
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
75307688
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
75317689
[SR-5719]: <https://bugs.swift.org/browse/SR-5719>
7690+
[SR-6118]: <https://bugs.swift.org/browse/SR-6118>
75327691
[SR-7139]: <https://bugs.swift.org/browse/SR-7139>
75337692
[SR-7251]: <https://bugs.swift.org/browse/SR-7251>
75347693
[SR-7601]: <https://bugs.swift.org/browse/SR-7601>
75357694
[SR-7799]: <https://bugs.swift.org/browse/SR-7799>
75367695
[SR-8109]: <https://bugs.swift.org/browse/SR-8109>
7696+
[SR-8546]: <https://bugs.swift.org/browse/SR-8546>
7697+
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>

0 commit comments

Comments
 (0)