Skip to content
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

[6.0] Add isolation argument to functions taking non-sendable async closures. #643

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 26, 2024

Explanation: Fixes concurrency issues using confirmation {}, withKnownIssue {}, and #expect(throws:) {} with actor-isolated code.
Scope: 6.0 branch (6.0.1)
Issue: https://github.com/swiftlang/swift-testing/issue/622
Original PR: #624
Risk: Moderate—involves changing the signatures of a number of functions which will break ABI for them as well as potential source breakage if somebody explicitly refers to these functions by name.
Testing: New unit test coverage.
Reviewer: @briancroom

…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.
@grynspan grynspan added bug Something isn't working concurrency Swift concurrency/sendability issues labels Aug 26, 2024
@grynspan grynspan self-assigned this Aug 26, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan changed the title Add isolation argument to functions taking non-sendable async closures. [6.0] Add isolation argument to functions taking non-sendable async closures. Aug 26, 2024
@grynspan
Copy link
Contributor Author

Linux CI failure is just due to duelling PRs.

@grynspan
Copy link
Contributor Author

@swift-ci test Linux

@grynspan grynspan merged commit 7865c39 into release/6.0 Aug 27, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/add-isolation-argument-to-various-functions-6.0 branch August 27, 2024 00:11
@grynspan grynspan added this to the Swift 6.0.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working concurrency Swift concurrency/sendability issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants