Skip to content

Commit ac27cf7

Browse files
authored
Merge pull request swiftlang#24081 from slavapestov/update-changelog-md-5.1
Update CHANGELOG.md [5.1]
2 parents 5aa28f0 + 1d48c0d commit ac27cf7

File tree

1 file changed

+128
-6
lines changed

1 file changed

+128
-6
lines changed

CHANGELOG.md

Lines changed: 128 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,125 @@ CHANGELOG
2525
Swift 5.1
2626
---------
2727

28+
* [SE-0256][]:
29+
30+
Subscripts can now be declared `static` or (inside classes) `class`.
31+
32+
* [SE-0252][]:
33+
34+
The existing `@dynamicMemberLookup` attribute has been extended with a
35+
support for strongly-typed keypath implementations:
36+
37+
```swift
38+
@dynamicMemberLookup
39+
struct Lens<T> {
40+
let getter: () -> T
41+
let setter: (T) -> Void
42+
43+
var value: T {
44+
get {
45+
return getter()
46+
}
47+
set {
48+
setter(newValue)
49+
}
50+
}
51+
52+
subscript<U>(dynamicMember keyPath: WritableKeyPath<T, U>) -> Lens<U> {
53+
return Lens<U>(
54+
getter: { self.value[keyPath: keyPath] },
55+
setter: { self.value[keyPath: keyPath] = $0 })
56+
}
57+
}
58+
```
59+
60+
* [SR-8546][], [SR-9043][]:
61+
62+
More thorough checking has been implemented for restrictions around
63+
escaping closures capturing `inout` parameters or values of noescape type.
64+
While most code should not be affected, there are edge cases where
65+
the Swift 5.0 compiler would accept code violating these restrictions.
66+
This could result in runtime crashes or silent data corruption.
67+
68+
An example of invalid code which was incorrectly accepted by the Swift 5.0
69+
compiler is an `@escaping` closure calling a local function which
70+
references an `inout` parameter from an outer scope:
71+
72+
```swift
73+
struct BadCaptureExample {
74+
var escapingClosure: () -> ()
75+
76+
mutating func takesInOut(_ x: inout Int) {
77+
func localFunction() {
78+
x += 1
79+
}
80+
81+
escapingClosure = { localFunction() }
82+
}
83+
}
84+
```
85+
86+
The compiler now correctly diagnoses the above code by pointing out that
87+
the capture of `x` by `localFunction()` is invalid, since `localFunction()`
88+
is referenced from an `@escaping` closure.
89+
90+
This also addresses certain cases where the compiler incorrectly diagnosed
91+
certain code as invalid, when in fact no violation of restrictions had
92+
taken place. For example,
93+
94+
```swift
95+
func takesNoEscape(_ fn: () -> ()) {
96+
func localFunction() {
97+
fn()
98+
}
99+
100+
{ localFunction() }()
101+
}
102+
```
103+
104+
* [SR-2672][]:
105+
106+
Conversions between tuple types are now fully implemented.
107+
Previously, the following would diagnose an error:
108+
109+
```swift
110+
let values: (Int, Int) = (10, 15)
111+
let converted: (Int?, Any) = values
112+
113+
* [SE-0242][]:
114+
115+
The memberwise initializer for structures now provide default values for variables that hold default expressions.
116+
117+
```swift
118+
struct Dog {
119+
var name = "Generic dog name"
120+
var age = 0
121+
122+
// The synthesized memberwise initializer
123+
init(name: String = "Generic dog name", age: Int = 0)
124+
}
125+
126+
let sparky = Dog(name: "Sparky") // Dog(name: "Sparky", age: 0)
127+
```
128+
28129
* [SE-0068][]:
29130

30-
`Self` can now be used inside member functions and for function arguments of structs and enums to refer to the containing type.
131+
It is now possible to use `Self` to refer to the innermost nominal
132+
type inside struct, enum and class declarations. For example, the
133+
two method declarations inside this struct are equivalent:
134+
135+
```swift
136+
struct Box<Value> {
137+
func transform1() -> Self { return self }
138+
func transform2() -> Box<Value> { return self }
139+
}
140+
```
141+
142+
In classes, `Self` is the dynamic type of the `self` value, as before.
143+
Existing restrictions on `Self` in declaration types still apply;
144+
that is, `Self` can only appear as the return type of a method.
145+
However, `Self` can now be used inside the body of a method
146+
without limitation.
31147

32148
* [SR-7799][]:
33149

@@ -46,12 +162,12 @@ Swift 5.1
46162
}
47163
```
48164

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

52168
* [SR-2688][]:
53169

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

56172
```swift
57173
class Foo {
@@ -62,10 +178,12 @@ Swift 5.1
62178

63179
* [SR-7601][]:
64180

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

67183
```swift
68-
@objc func returnDynamicSelf() -> Self { return self }
184+
class MyClass : NSObject {
185+
@objc func clone() -> Self { return self }
186+
}
69187
```
70188

71189
* [SR-2176][]:
@@ -7511,6 +7629,7 @@ Swift 1.0
75117629
[SE-0228]: <https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
75127630
[SE-0230]: <https://github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
75137631
[SE-0235]: <https://github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md>
7632+
[SE-0242]: <https://github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md>
75147633
[SE-0245]: <https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
75157634

75167635
[SR-106]: <https://bugs.swift.org/browse/SR-106>
@@ -7525,6 +7644,7 @@ Swift 1.0
75257644
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
75267645
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
75277646
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7647+
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
75287648
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
75297649
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
75307650
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
@@ -7534,3 +7654,5 @@ Swift 1.0
75347654
[SR-7601]: <https://bugs.swift.org/browse/SR-7601>
75357655
[SR-7799]: <https://bugs.swift.org/browse/SR-7799>
75367656
[SR-8109]: <https://bugs.swift.org/browse/SR-8109>
7657+
[SR-8546]: <https://bugs.swift.org/browse/SR-8546>
7658+
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>

0 commit comments

Comments
 (0)