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/NNNN-nonisolated-for-global-actor-cutoff.md
+57-11Lines changed: 57 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -127,10 +127,27 @@ struct A: Refined {
127
127
}
128
128
```
129
129
130
-
In the above code, the protocol `Refined` is refining the `GloballyIsolated` protocol, but is declared non-isolated. This means that the `Refined` still has the same requirements as `GloballyIsolated`, but they are not isolated. Therefore, a struct `A` conforming to it is also non-isolated, which allows the programmer for more flexibility when implementing the requirements of a protocol.
130
+
In the above code, the protocol `Refined` is refining the `GloballyIsolated` protocol, but is declared non-isolated. This means that the `Refined` still has the same requirements as `GloballyIsolated`, but they are not isolated. Therefore, a struct `A` conforming to it is also non-isolated, which allows the programmer for more flexibility when implementing the requirements of a protocol.
131
131
132
132
#### Extensions
133
133
134
+
Today, it is possible for extensions to be globally-isolated:
135
+
136
+
```swift
137
+
structX {}
138
+
139
+
@MainActorextensionX {
140
+
funcf() {} // implicitly globally-isolated
141
+
var x: Int { get { 1 } } // implicitly globally-isolated
142
+
}
143
+
```
144
+
145
+
In the above code, `X` is a non-isolated struct, and extension members
146
+
`f()` and `x` are globally-isolated.
147
+
148
+
However, if `X` was globally-isolated, before this proposal, the only way to stop extension members from inferring the global actor would be to mark every extension member with
149
+
`nonisolated`.
150
+
134
151
This proposal allows for `nonisolated` attribute to be applied on extension declarations:
135
152
136
153
```swift
@@ -147,7 +164,7 @@ struct C: GloballyIsolated {
147
164
}
148
165
```
149
166
150
-
In the code above, the `nonisolated` attribute is applied to an extension declaration for a `GloballyIsolated` protocol. When applied to an extension, `nonisolated` applies to all of its members. In this case, `implicitlyNonisolated` method and the computed property `x` are both nonisolated, and therefore are able to be accessed from a nonisolated context in the body of `explicitlyNonisolated` method of a globally-isolated struct `C`.
167
+
In the code above, the `nonisolated` attribute is applied to an extension declaration for a `GloballyIsolated` protocol. When applied to an extension, `nonisolated` applies to all of its members. In this case, `implicitlyNonisolated` method and the computed property `x` are both nonisolated, and therefore are able to be accessed from a nonisolated context in the body of `explicitlyNonisolated` method of a globally-isolated struct `C`.
151
168
152
169
#### Classes, structs, and enums
153
170
@@ -222,14 +239,16 @@ For global-actor-isolated value types, [SE-0434: Usability of global-actor-isola
222
239
223
240
```swift
224
241
protocolP {
225
-
@MainActorvarx: Int { get }
242
+
@MainActorvary: Int { get }
226
243
}
227
244
228
245
structS: P {
229
-
var x: Int// 'nonisolated' is inferred within the module
246
+
var y: Int// 'nonisolated' is inferred within the module
0 commit comments