-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isolation
argument to functions taking non-sendable async closures.
#624
Add isolation
argument to functions taking non-sendable async closures.
#624
Conversation
…res. This PR adds an `isolation` parameter to several API functions that take `async` closures that are not required to be sendable. As well, it adds `sending` to those closures' return types where appropriate. This change is necessary in Swift 6 because a non-sendable async closure could be called in the wrong isolation domain otherwise. In particular, if the caller is `@MainActor`-isolated, the closure will not be called on the main actor and will therefore always hop, and a concurrency error occurs: ```swift @mainactor func f() async { await confirmation { // this inner closure is not actor-isolated, but can't be sent across // isolation domains. } } ``` `withKnownIssue()` and `confirmation()` are affected, as are several async overloads of the internal-but-public `__check()` function family. This change is necessary for correctness, but is potentially source-breaking if calling code directly references the modified functions by full name. Resolves #622.
@swift-ci test |
@swift-ci test |
@swift-ci test |
I'm really not an expert on this, but I just stumbled across As far as I understand, the following change should provide the same behavior to clients, with the benefit of not adding an additional argument to the signature: func confirmation<R>(
_ comment: Testing.Comment? = nil,
expectedCount: Int = 1,
sourceLocation: Testing.SourceLocation = #_sourceLocation,
@_inheritActorContext _ body: (Testing.Confirmation) async throws -> R
) async rethrows -> R Then again, |
|
@swift-ci test |
…res. (#624) This PR adds an `isolation` parameter to several API functions that take `async` closures that are not required to be sendable. As well, it adds `sending` to those closures' return types where appropriate. This change is necessary in Swift 6 because a non-sendable async closure could be called in the wrong isolation domain otherwise. In particular, if the caller is `@MainActor`-isolated, the closure will not be called on the main actor and will therefore always hop, and a concurrency error occurs: ```swift @mainactor func f() async { await confirmation { // this inner closure is not actor-isolated, but can't be sent across // isolation domains. } } ``` `withKnownIssue()` and `confirmation()` are affected, as are several async overloads of the internal-but-public `__check()` function family. This change is necessary for correctness, but is potentially source-breaking if calling code directly references the modified functions by full name. Resolves #622. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
- Initial migration of model types that use `@MainActor` - There's a few issues in the Swift Testing library surrounding global actors ([see here](swiftlang/swift-testing#624)), so we will likely wait for Swift 6.1 before migrating most of the code in `VaultFeedTests` and `VaultiOSTests`, the only 2 packages left that have XCTests in them. - Resolves #330
This PR adds an
isolation
parameter to several API functions that takeasync
closures that are not required to be sendable. As well, it addssending
to those closures' return types where appropriate.This change is necessary in Swift 6 because a non-sendable async closure could be called in the wrong isolation domain otherwise. In particular, if the caller is
@MainActor
-isolated, the closure will not be called on the main actor and will therefore always hop, and a concurrency error occurs:withKnownIssue()
andconfirmation()
are affected, as are several async overloads of the internal-but-public__check()
function family.This change is necessary for correctness, but is potentially source-breaking if calling code directly references the modified functions by full name.
Resolves #622.
Checklist: