You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,6 +5,88 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
5
5
6
6
## Swift 5.7
7
7
8
+
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
9
+
10
+
```swift
11
+
classObject {
12
+
@objcfuncgetTag() ->Int
13
+
}
14
+
15
+
@objcprotocolP {
16
+
@objcoptionalfuncdidUpdateObject(withTagtag: Int)
17
+
}
18
+
19
+
let getTag: (AnyObject) -> (() ->Int)?=AnyObject.getTag
20
+
21
+
let didUpdateObject: (any P) -> ((Int) ->Void)?= P.didUpdateObject
22
+
```
23
+
24
+
*[SE-0349][]:
25
+
26
+
Loading data from raw memory represented by `UnsafeRawPointer`,
27
+
`UnsafeRawBufferPointer` and their mutable counterparts now supports unaligned
28
+
accesses. This previously required a workaround involving an intermediate
29
+
copy:
30
+
31
+
```swift
32
+
let result = unalignedData.withUnsafeBytes { buffer ->UInt32in
- It is now possible to use a pointer to `struct` to obtain a pointer to one
63
+
of its stored properties:
64
+
65
+
```swift
66
+
withUnsafeMutablePointer(to: &myStruct) {
67
+
let interiorPointer =$0.pointer(to: \.myProperty)!
68
+
returnmyCFunction(interiorPointer)
69
+
}
70
+
```
71
+
- Comparisons between pointers have been simplified by being more permissive.
72
+
Since pointers are representations of memory locations within a single pool of
73
+
underlying memory, Swift now allows comparing pointers without requiring type
74
+
conversions with the `==`, `!=`, `<`,`<=`,`>`, and `>=` operators.
75
+
76
+
* [SE-0333][]:
77
+
78
+
It is now possible to use the `withMemoryRebound<T>()` method on raw memory,
79
+
that is `UnsafeRawPointer` , `UnsafeRawBufferPointer` and their mutable
80
+
counterparts. Additionally, we clarified the semantics of
81
+
`withMemoryRebound<T>()` when used on typed memory (`UnsafePointer<Pointee>`,
82
+
`UnsafeBufferPointer<Pointee>` and their mutable counterparts). Whereas
83
+
`Pointee` and `T` were previously required to have the same stride, you can
84
+
now rebind in cases where `Pointee` is an aggregate of `T` or vice-versa. For
85
+
example, given an `UnsafeMutableBufferPointer<CGPoint>`, you can now use
86
+
`withMemoryRebound` to operate temporarily on a
87
+
`UnsafeMutableBufferPointer<CGFloat>`, because `CGPoint` is an aggregate of
88
+
`CGFloat`.
89
+
8
90
* [SE-0352][]:
9
91
10
92
It's now possible to call a generic function with a value of protocoltype
@@ -32,7 +114,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
32
114
It's now possible to use a default value expression with a generic parameter type
33
115
to default the argument and its type:
34
116
35
-
```
117
+
```swift
36
118
funccompute<C: Collection>(_values: C = [0, 1, 2]) {
37
119
...
38
120
}
@@ -107,54 +189,54 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
107
189
108
190
*[SE-0343][]:
109
191
110
-
Top-level scripts support asynchronous calls.
192
+
Top-level scripts support asynchronous calls.
111
193
112
-
Using an `await` by calling an asynchronous function or accessing an isolated
113
-
variable transitions the top-level to an asynchronous context. As an
114
-
asynchronous context, top-level variables are `@MainActor`-isolated and the
115
-
top-level is run on the `@MainActor`.
194
+
Using an `await` by calling an asynchronous function or accessing an isolated
195
+
variable transitions the top-level to an asynchronous context. As an
196
+
asynchronous context, top-level variables are `@MainActor`-isolated and the
197
+
top-level is run on the `@MainActor`.
116
198
117
-
Note that the transition affects function overload resolution and starts an
118
-
implicit run loop to drive the concurrency machinery.
199
+
Note that the transition affects function overload resolution and starts an
200
+
implicit run loop to drive the concurrency machinery.
119
201
120
-
Unmodified scripts are not affected by this change unless `-warn-concurrency` is
121
-
passed to the compiler invocation. With `-warn-concurrency`, variables in the
122
-
top-level are isolated to the main actor and the top-level context is isolated
123
-
to the main actor, but is not an asynchronous context.
202
+
Unmodified scripts are not affected by this change unless `-warn-concurrency` is
203
+
passed to the compiler invocation. With `-warn-concurrency`, variables in the
204
+
top-level are isolated to the main actor and the top-level context is isolated
205
+
to the main actor, but is not an asynchronous context.
124
206
125
207
*[SE-0336][]:
126
208
127
-
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
128
-
129
-
Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations.
130
-
131
-
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
209
+
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
132
210
133
-
```swift
134
-
distributedactorGreeter {
135
-
var greetingsSent =0
211
+
Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations.
136
212
137
-
distributedfuncgreet(name: String) ->String {
138
-
greetingsSent +=1
139
-
return"Hello, \(name)!"
213
+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfill the role of providing those implementations.
214
+
215
+
```swift
216
+
distributedactorGreeter {
217
+
var greetingsSent =0
218
+
219
+
distributedfuncgreet(name: String) ->String {
220
+
greetingsSent +=1
221
+
return"Hello, \(name)!"
222
+
}
140
223
}
141
-
}
142
-
143
-
functalkTo(greeter: Greeter) asyncthrows {
144
-
// isolation of distributed actors is stronger, it is impossible to refer to
145
-
// any stored properties of distributed actors from outside of them:
146
-
greeter.greetingsSent// distributed actor-isolated property 'name' can not be accessed from a non-isolated context
147
224
148
-
// remote calls are implicitly throwing and async,
149
-
// to account for the potential networking involved:
150
-
let greeting =tryawait greeter.greet(name: "Alice")
151
-
print(greeting) // Hello, Alice!
152
-
}
153
-
```
225
+
functalkTo(greeter: Greeter) asyncthrows {
226
+
// isolation of distributed actors is stronger, it is impossible to refer to
227
+
// any stored properties of distributed actors from outside of them:
228
+
greeter.greetingsSent// distributed actor-isolated property 'name' can not be accessed from a non-isolated context
229
+
230
+
// remote calls are implicitly throwing and async,
231
+
// to account for the potential networking involved:
232
+
let greeting =tryawait greeter.greet(name: "Alice")
233
+
print(greeting) // Hello, Alice!
234
+
}
235
+
```
154
236
155
237
* The compiler now emits a warning when a non-final class conforms to a protocol that imposes a same-type requirement between `Self` and an associated type. This is because such a requirement makes the conformance unsound for subclasses.
156
238
157
-
For example, Swift 5.6 would allow the following code, which at runtime would construct an instance of `C` and not `SubC` as expected:
239
+
For example, Swift 5.6 would allow the following code, which at runtime would construct an instance of `C` and not `SubC` as expected:
158
240
159
241
```swift
160
242
protocolP {
@@ -257,29 +339,32 @@ For example, Swift 5.6 would allow the following code, which at runtime would co
257
339
return [ 1:"One", 2:"Two" ]
258
340
}
259
341
```
342
+
260
343
Swift 5.6
261
344
---------
262
345
263
-
*[SE-0327][]:
264
-
265
-
In Swift 5 mode, a warning is now emitted if the default-value expression of an
266
-
instance-member property requires global-actor isolation. For example:
0 commit comments