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: proposals/0411-isolated-default-values.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ The current actor isolation rules for default argument values do not admit data
47
47
48
48
I propose allowing default value expressions to have the same isolation as the enclosing function or the corresponding stored property. As usual, if the caller is not already in the isolation domain of the callee, then the call must be made asynchronously and must be explicitly marked with `await`. For isolated default values of stored properties, the implicit initialization only happens in the body of an `init` with the same isolation.
49
49
50
-
These rule makes the stored property example above invalid at the `nonisolated` initializer:
50
+
These rules make the stored property example above invalid at the `nonisolated` initializer:
51
51
52
52
```swift
53
53
@MainActorfuncrequiresMainActor() ->Int { ... }
@@ -107,7 +107,7 @@ Evaluating a closure literal itself can happen in any isolation domain; the acto
107
107
108
108
The above `useDefaultClosure` function has a default argument value that is a closure literal. The closure body calls a `@MainActor`-isolated function synchronously, therefore the closure itself must be `@MainActor` isolated.
109
109
110
-
Note that the only way for a closure literal in a default argument to be isolated to an actor instance is for the isolation be written explicitly with an isolated parameter. The inference algorithm will never determine the isolation to be an actor instance based on the following two properties:
110
+
Note that the only way for a closure literal in a default argument to be isolated to an actor instance is for the isolation to be written explicitly with an isolated parameter. The inference algorithm will never determine the isolation to be an actor instance based on the following two properties:
111
111
112
112
1. To be isolated to an actor instance, a closure must either have its own (explicit) isolated parameter or capture an isolated parameter from its enclosing context.
113
113
2. Closure literals in default arguments cannot capture values.
@@ -145,7 +145,7 @@ In the above example, `useDefault` has default arguments that are isolated to `@
145
145
146
146
For a given call, argument evaluation happens in the following order:
147
147
148
-
1. Left-to-right evalution of explicit r-value arguments
148
+
1. Left-to-right evaluation of explicit r-value arguments
149
149
2. Left-to-right evaluation of default arguments and formal access arguments
150
150
151
151
For example:
@@ -173,7 +173,7 @@ explicitFormalVal
173
173
174
174
Unlike the explicit argument list, isolated default arguments must be evaluated in the isolation domain of the callee. As such, if any of the argument values require the isolation of the callee, argument evaluation happens in the following order:
175
175
176
-
1. Left-to-right evalution of explicit r-value arguments
176
+
1. Left-to-right evaluation of explicit r-value arguments
177
177
2. Left-to-right evaluation of formal access arguments
178
178
3. Hop to the callee's isolation domain
179
179
4. Left-to-right evaluation of default arguments
@@ -255,7 +255,7 @@ Note that this rule is not specific to default values, but it's necessary to spe
255
255
256
256
#### Default value isolation in synthesized initializers
257
257
258
-
For structs, default initializer expressions for stored properties are used as default argument values to the compiler-generated memberwise initializer. For structs and classes that have a compiler-generated no-parameter initializer, the default initializer expressions are also used in the syntheszied`init()` body.
258
+
For structs, default initializer expressions for stored properties are used as default argument values to the compiler-generated memberwise initializer. For structs and classes that have a compiler-generated no-parameter initializer, the default initializer expressions are also used in the synthesized`init()` body.
259
259
260
260
If any of the type's stored properties with non-`Sendable` type are actor isolated, or if any of the isolated default initializer expressions are actor isolated, then the compiler-synthesized initializer(s) must also be actor isolated. For example:
261
261
@@ -327,4 +327,4 @@ Thank you to Kavon Farvardin for implementing the default initializer expression
327
327
* Changes from the first pitch
328
328
* Require that isolated default arguments share the same isolation as their enclosing function or type.
329
329
* Specify the semantic restrictions on initializing actor isolated properties from across isolation boundaries.
330
-
* Enable using isolated default arguments from across isolation boundaries by changing the argument evaluation between formal access and default arguments.
330
+
* Enable using isolated default arguments from across isolation boundaries by changing the argument evaluation between formal access and default arguments.
0 commit comments