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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+101-2Lines changed: 101 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,83 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
5
5
6
6
## Swift 5.7
7
7
8
+
*[SE-0338][]:
9
+
10
+
Non-isolated async functions now always execute on the global concurrent pool,
11
+
so calling a non-isolated async function from actor-isolated code will leave
12
+
the actor. For example:
13
+
14
+
```swift
15
+
classC { }
16
+
17
+
funcf(_: C) async { /* always executes on the global concurrent pool */ }
18
+
19
+
actorA {
20
+
funcg(c: C) async {
21
+
/* always executes on the actor */
22
+
print("on the actor")
23
+
24
+
awaitf(c)
25
+
}
26
+
}
27
+
```
28
+
29
+
Prior to this change, the call from `f` to `g` might have started execution of
30
+
`g` on the actor, which could lead to actors being busy longer than strictly
31
+
necessary. Now, the non-isolated async function will always hop to the global
32
+
cooperative pool, not run on the actor. This can result in a behavior change
33
+
for programs that assumed that a non-isolated async function called from a
34
+
`@MainActor` context will be executed on the main actor, although such
35
+
programs were already technically incorrect.
36
+
37
+
Additionally, when leaving an actor to execution on the global cooperative
38
+
pool, `Sendable` checking will be performed, so the compiler will emit a
39
+
diagnostic in the call to `f` if `c` is not of `Sendable` type.
40
+
41
+
*[SE-0350][]:
42
+
43
+
The standard library has a new `Regex<Output>` type.
44
+
45
+
This type represents an _extended regular expression_, allowing more fluent
46
+
string processing operations. A `Regex` may be created by
47
+
[initialization from a string][SE-0355]:
48
+
```
49
+
let pattern = "a[bc]+" // matches "a" followed by one or more instances
50
+
// of either "b" or "c"
51
+
let regex = try! Regex(pattern)
52
+
```
53
+
Or via a [regex literal][SE-0354]:
54
+
```
55
+
let regex = #/a[bc]+/#
56
+
```
57
+
In Swift 6, `/` will also be supported as a delimiter for `Regex` literals.
58
+
You can enable this mode in Swift 5.7 with the `-enable-bare-slash-regex`
59
+
flag. Doing so will cause some existing expressions that use `/` as an
60
+
operator to no longer compile; you can add parentheses or line breaks as a
61
+
workaround.
62
+
63
+
There are [new string-processing algorithms][SE-0357] that support
64
+
`String`, `Regex` and arbitrary `Collection` types.
65
+
66
+
*[SE-0329][]:
67
+
New types representing time and clocks were introduced. This includes a protocol `Clock` defining clocks which allow for defining a concept of now and a way to wake up after a given instant. Additionally a new protocol `InstantProtocol` for defining instants in time was added. Furthermore a new protocol `DurationProtocol` was added to define an elapsed duration between two given `InstantProtocol` types. Most commonly the `Clock` types for general use are the `SuspendingClock` and `ContinuousClock` which represent the most fundamental clocks for the system. The `SuspendingClock` type does not progress while the machine is suspended whereas the `ContinuousClock` progresses no matter the state of the machine.
`Clock` also has methods to measure the elapsed duration of the execution of work. In the case of the `SuspendingClock` and `ContinuousClock` this measures with high resolution and is suitable for benchmarks.
77
+
78
+
```swift
79
+
let clock =ContinuousClock()
80
+
let elapsed = clock.measure {
81
+
someLongRunningWork()
82
+
}
83
+
```
84
+
8
85
*[SE-0309][]:
9
86
10
87
Protocols with associated types and `Self` requirements can now be used as the
@@ -72,10 +149,26 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
72
149
73
150
*[SE-0353][]:
74
151
75
-
Further generalizing the above, protocol-constrained types can also be used with `any`:
152
+
Protocols with primary associated types can now be used in existential types,
153
+
enabling same-type constraints on those associated types.
154
+
155
+
```
156
+
let strings: any Collection<String> = [ "Hello" ]
157
+
```
158
+
159
+
Note that language features requiring runtime support like dynamic casts
160
+
(`is`, `as?`, `as!`), as well as generic usages of parameterized existentials
161
+
in generic types (e.g. `Array<any Collection<Int>>`) involve additional
162
+
availability checks to use. Back-deploying usages in generic position can be
163
+
worked around with a generic type-erasing wrapper struct, which is now much
0 commit comments