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-global-actor-isolated-types-usability.md
-40Lines changed: 0 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,6 @@ We propose that:
103
103
- Stored properties of `Sendable` type in a global-actor-isolated value type are treated as `nonisolated` when used within the module or if the value type is `frozen`.
104
104
-`@Sendable` is inferred for global-actor-isolated functions and closures.
105
105
- Global-actor-isolated closures are allowed to capture non-`Sendable` values despite being `@Sendable`.
106
-
- The programmer would be able to suppress the automatic conformance inferred via the above rule using the new `@~Sendable` attribute. By analogy, introduce a new `~Sendable` protocol to indicate that a nominal type is not `Sendable`.
107
106
- A global-actor-isolated subclass of a non-isolated, non-`Sendable` class is allowed, but it must be non-`Sendable`.
108
107
109
108
@@ -174,45 +173,6 @@ The above code is data-race safe, since a globally isolated closure will never o
174
173
Note that under region isolation in SE-0414, capturing a non-`Sendable` value in an actor-isolated closure will transfer the region into the actor, so it is impossible to have concurrent access on non-`Sendable` captures even if the isolated closure is formed outside the actor.
175
174
176
175
177
-
### `@~Sendable` and `~Sendable`
178
-
179
-
This proposal also adds a way to "opt-out" of the implicit `@Sendable` inference introduced by the above change by using the new `@~Sendable` attribute:
180
-
181
-
```swift
182
-
functest() {
183
-
let closure: @~Sendable @MainActor () ->Void= {
184
-
print("hmmmm")
185
-
}
186
-
187
-
Task {
188
-
awaitclosure() // error
189
-
}
190
-
}
191
-
```
192
-
193
-
In the above code, we use `@~Sendable` to explicitly indicate that the closure is not `Sendable` and suppress the implicit `@Sendable`. This change will mostly help with possible ABI compatibility issues, but will not necessarily improve usability.
194
-
195
-
By analogy, this proposal inroduces the new `~Sendable` syntax for explicitly suppressing a conformance to `Sendable`:
196
-
197
-
```swift
198
-
classC { ... }
199
-
200
-
@available(*, unavailable)
201
-
extensionC: @unchecked Sendable {}
202
-
203
-
// instead
204
-
205
-
classC: ~Sendable {}
206
-
```
207
-
208
-
In the above code, we use `~Sendable` instead of an unavailable `Sendable` conformance to indicate that the type `C` is not `Sendable`. Suppressing a `Sendable` conformance in a superclass still allows a conformance to be added in subclasses:
209
-
210
-
```swift
211
-
classSub: C, @unchecked Sendable { ... }
212
-
```
213
-
214
-
Previously, an unavailable `Sendable` conformance would prevent `@unchecked Sendable` conformances from being added to subclasses because types can only conform to protocols in one way, and the unavailable `Sendable` conformance was inherited in all subclasses.
215
-
216
176
### Global actor isolation and inheritance
217
177
218
178
Subclasses may add global actor isolation when inheriting from a nonisolated, non-`Sendable` superclass. In this case, an implicit conformance to `Sendable` will not be added, and explicitly specifying a `Sendable` conformance is an error:
0 commit comments