@@ -108,25 +108,39 @@ concurrency checking.
108108
109109* [ SE-0411] [ ] :
110110
111- Default value expressions can now have the same isolation as the enclosing
112- function or the corresponding stored property:
111+ Swift 5.10 closes a data-race safety hole that previously permitted isolated
112+ default stored property values to be synchronously evaluated from outside the
113+ actor. For example, the following code compiles warning-free under
114+ ` -strict-concurrency=complete ` in Swift 5.9, but it will crash at runtime at
115+ the call to ` MainActor.assertIsolated() ` :
113116
114117 ``` swift
115- @MainActor
116- func requiresMainActor () -> Int { ... }
118+ @MainActor func requiresMainActor () -> Int {
119+ MainActor.assertIsolated ()
120+ return 0
121+ }
117122
118- class C {
119- @MainActor
120- var x : Int = requiresMainActor ()
123+ @MainActor struct S {
124+ var x = requiresMainActor ()
125+ var y : Int
121126 }
122127
123- @MainActor func defaultArg (value : Int = requiresMainActor ()) { ... }
128+ nonisolated func call () async {
129+ let s = await S (y : 10 )
130+ }
131+
132+ await call ()
124133 ```
125134
126- For isolated default values of stored properties, the implicit initialization
127- only happens in the body of an ` init ` with the same isolation. This closes
128- an important data-race safety hole where global-actor-isolated default values
129- could inadvertently run synchronously from outside the actor.
135+ This happens because ` requiresMainActor() ` is used as a default argument to
136+ the member-wise initializer of ` S ` , but default arguments are always
137+ evaluated in the caller. In this case, the caller runs on the generic
138+ executor, so the default argument evaluation crashes.
139+
140+ Under ` -strict-concurrency=complete ` in Swift 5.10, default argument values
141+ can safely share the same isolation as the enclosing function or stored
142+ property. The above code is still valid, but the isolated default argument is
143+ guaranteed to be evaluated in the callee's isolation domain.
130144
131145## Swift 5.9.2
132146
0 commit comments