4
4
* Authors: [ Holly Borla] ( https://github.com/hborla ) , [ John McCall] ( https://github.com/rjmccall )
5
5
* Review Manager: [ Xiaodi Wu] ( https://github.com/xwu )
6
6
* Status: ** Active review (February 20...March 2, 2025)**
7
- * Vision: [[ Prospective Vision ] Improving the approachability of data-race safety] ( https://forums.swift.org/t/prospective-vision-improving-the-approachability-of-data-race-safety/76183 )
7
+ * Vision: [ Improving the approachability of data-race safety] ( /visions/approachable-concurrency.md )
8
8
* Implementation: On ` main ` behind ` -enable-experimental-feature NonIsolatedAsyncInheritsIsolationFromContext `
9
9
* Upcoming Feature Flag: ` AsyncCallerExecution `
10
10
* Previous Proposal: [ SE-0338] ( 0338-clarify-execution-non-actor-async.md )
@@ -41,6 +41,8 @@ async function always switches off of an actor to run.
41
41
- [ Alternatives considered] ( #alternatives-considered )
42
42
- [ Changing isolation inference behavior to implicitly capture isolated parameters] ( #changing-isolation-inference-behavior-to-implicitly-capture-isolated-parameters )
43
43
- [ Use ` nonisolated ` instead of a separate ` @execution(concurrent) ` attribute] ( #use-nonisolated-instead-of-a-separate-executionconcurrent-attribute )
44
+ - [ Use "isolation" terminology instead of "execution"] ( #use-isolation-terminology-instead-of-execution )
45
+ - [ Deprecate ` nonisolated ` ] ( #deprecate-nonisolated )
44
46
- [ Don't introduce a type attribute for ` @execution ` ] ( #dont-introduce-a-type-attribute-for-execution )
45
47
- [ Revisions] ( #revisions )
46
48
@@ -241,7 +243,7 @@ The sections below will explicitly use `@execution(concurrent)` and
241
243
independent of upcoming features or language modes. However, note that the
242
244
end state under the ` AsyncCallerExecution ` upcoming feature will mean that
243
245
` @execution(caller) ` is not necessary to explicitly write, and
244
- ` @execution(caller ) ` will likely be used sparingly because it has far
246
+ ` @execution(concurrent ) ` will likely be used sparingly because it has far
245
247
stricter data-race safety requirements.
246
248
247
249
### The ` @execution ` attribute
@@ -259,8 +261,26 @@ in the following sections.
259
261
Only (implicitly or explicitly) ` nonisolated ` functions can be marked with the
260
262
` @execution ` attribute; it is an error to use the ` @execution ` attribute with
261
263
an isolation other than ` nonisolated ` , including global actors, isolated
262
- parameters, and ` @isolated(any) ` . The ` @execution ` attribute can be used
263
- together with ` @Sendable ` or ` sending ` .
264
+ parameters, and ` @isolated(any) ` :
265
+
266
+ ``` swift
267
+ actor MyActor {
268
+ var value = 0
269
+
270
+ // error: '@execution(caller)' can only be used with 'nonisolated' methods
271
+ @execution (caller)
272
+ func isolatedToSelf () async {
273
+ value += 1
274
+ }
275
+
276
+ @execution (caller)
277
+ nonisolated func canRunAnywhere () async {
278
+ // cannot access 'value' or other actor-isolated state
279
+ }
280
+ }
281
+ ```
282
+
283
+ The ` @execution ` attribute can be used together with ` @Sendable ` or ` sending ` .
264
284
265
285
The ` @execution ` attribute is preserved in the type system so that the execution
266
286
semantics can be distinguished for function vales.
@@ -892,12 +912,15 @@ reasons:
892
912
893
913
### Use "isolation" terminology instead of "execution"
894
914
895
- One other possibility is to use isolation terminology instead of ` @execution `
896
- for the syntax. This direction does not accomplish goal 1. in the previous
915
+ Another possibility is to use isolation terminology instead of ` @execution `
916
+ for the syntax. This direction does not accomplish the goal of having a
897
917
section to have a consistent meaning for ` nonisolated ` across synchronous and
898
918
async functions. If the attribute were spelled ` @isolated(caller) ` and
899
919
` @isolated(concurrent) ` , presumably that attribute would not work together with
900
920
` nonisolated ` ; it would instead be an alternative kind of actor isolation.
921
+ ` @isolated(concurrent) ` also doesn't make much sense because the concurrent
922
+ executor does not provide isolation at all - isolation is only provided by
923
+ actors and tasks.
901
924
902
925
Having ` @execution(caller) ` as an attribute that is used together with
903
926
` nonisolated ` leads to a simpler programming model because after the upcoming
@@ -907,6 +930,22 @@ functions. If we choose a different form of isolation like `@isolated(caller)`,
907
930
programmers have to learn a separate syntax for ` async ` functions that
908
931
accomplishes the same effect as a ` nonisolated ` synchronous function.
909
932
933
+ ### Deprecate ` nonisolated `
934
+
935
+ Going in the oppose direction, this proposal could effectively deprecate
936
+ ` nonisolated ` and allow you to use ` @execution(caller) ` everywhere that
937
+ ` nonisolated ` is currently supported, including synchronous methods, stored
938
+ properties, type declarations, and extensions. This direction was not chosen
939
+ for the following reasons:
940
+
941
+ 1 . This would lead to much more code churn than the current proposal. Part of
942
+ the goal of this proposal is to minimize the change to only what is absolutely
943
+ necessary to solve the major usability problem with async functions on
944
+ non-` Sendable ` types, because it's painful both to transition code and to
945
+ re-learn parts of the model that have already been internalized.
946
+ 2 . ` nonisolated ` is nicer to write than ` @execution(caller) ` ,
947
+ ` @isolated(caller) ` , or any other alternative attribute + argument syntax.
948
+
910
949
### Don't introduce a type attribute for ` @execution `
911
950
912
951
There are a lot of existing type attributes for concurrency and it's
0 commit comments