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
Adopt Sendable throughout API to support -strict-concurrency=complete (#22)
### Motivation
When using `-strict-concurrency=targeted`, `ClientMiddleware` will emit
warnings if an actor is conformed to it:
```swift
import OpenAPIRuntime
import Foundation
actor Middleware: ClientMiddleware {
func intercept(
_ request: Request,
baseURL: URL,
operationID: String,
/// Need to add `@Sendable` or the warnings don't go away even with this PR. Code-completion won't add it.
next: @sendable (Request, URL) async throws -> Response
) async throws -> Response {
try await next(request, baseURL)
}
}
```
The `intercept` function will emit the following warning with the
current implementation:
> Sendability of function types in instance method
'intercept(_:baseURL:operationID:next:)' does not match requirement in
protocol 'ClientMiddleware'
Repro package: https://github.com/MahdiBM/OAPIRClientWarningsRepro
You can change between this PR and the main branch by commenting out the
dependency declarations i've already put in the `Package.swift`.
Then observe there are no warnings with this PR, unlike with the main
branch.
### Modifications
Generally adopt Sendable throughout the whole API to support
-strict-concurrency=complete.
For the most part, this means using @sendable for closures, and using
`any Sendable` instead of `Any`.
As an example for closures, currently we have:
```swift
public protocol ClientMiddleware: Sendable {
func intercept(
_ request: Request,
baseURL: URL,
operationID: String,
next: (Request, URL) async throws -> Response
) async throws -> Response
}
```
With this PR we'll have:
```swift
public protocol ClientMiddleware: Sendable {
func intercept(
_ request: Request,
baseURL: URL,
operationID: String,
next: @sendable (Request, URL) async throws -> Response
/// ~~~^ notice `@Sendable`
) async throws -> Response
}
```
### Result
Safer Sendable code + being more ready for Swift 6 + no more warnings
when using `-strict-concurrency=targeted` then conforming an actor to
`ClientMiddleware`.
### Test Plan
Adopted all tests to the changes and added the strict-concurrency flag
to CI.
---------
Co-authored-by: Si Beaumont <simonjbeaumont@gmail.com>
Co-authored-by: Si Beaumont <beaumont@apple.com>
0 commit comments