Skip to content

Commit 77aaa4f

Browse files
committed
Add some changelog entries for 5.1 changes
1 parent 844d4df commit 77aaa4f

File tree

1 file changed

+111
-6
lines changed

1 file changed

+111
-6
lines changed

CHANGELOG.md

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,91 @@ 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+
28113
* [SE-0242][]:
29114

30115
The memberwise initializer for structures now provide default values for variables that hold default expressions.
@@ -43,7 +128,22 @@ Swift 5.1
43128

44129
* [SE-0068][]:
45130

46-
`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.
47147

48148
* [SR-7799][]:
49149

@@ -62,12 +162,12 @@ Swift 5.1
62162
}
63163
```
64164

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

68168
* [SR-2688][]:
69169

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

72172
```swift
73173
class Foo {
@@ -78,10 +178,12 @@ Swift 5.1
78178

79179
* [SR-7601][]:
80180

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

83183
```swift
84-
@objc func returnDynamicSelf() -> Self { return self }
184+
class MyClass : NSObject {
185+
@objc func clone() -> Self { return self }
186+
}
85187
```
86188

87189
* [SR-2176][]:
@@ -7542,6 +7644,7 @@ Swift 1.0
75427644
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
75437645
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
75447646
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7647+
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
75457648
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
75467649
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
75477650
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
@@ -7551,3 +7654,5 @@ Swift 1.0
75517654
[SR-7601]: <https://bugs.swift.org/browse/SR-7601>
75527655
[SR-7799]: <https://bugs.swift.org/browse/SR-7799>
75537656
[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)