-
Notifications
You must be signed in to change notification settings - Fork 304
Add sendable annotation to userInfo
closure
#1979
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
Conversation
@swift-ci please test Windows platform |
(note: completely untested, just running Windows since Linux will fail with docc first) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking the closure as Sendable implies that JSONDecoder should be able to invoke it multiple times concurrently when deserializing the JSON at which point we would get concurrent accesses to outstandingRequests
. I think that should be fine because they are all just reading, which should be fine (StackOverflow seems to imply so https://stackoverflow.com/questions/45666181/is-it-safe-to-access-not-modify-a-swift-dictionary-from-multiple-threads) because the lock on queue
guarantees that there are no concurrent writes.
I think it would be good to include that rationale in a comment so that we don't accidentally start modifying outstandingRequests
in that closure in the future.
2589db2
to
db0a67b
Compare
@swift-ci please test |
@swift-ci please test Windows |
@swift-ci please test Windows platform |
swift-foundation recently landed a change (in swiftlang/swift-foundation#764) which requires `any Sendable` values in `JSONEncoder.userInfo`. This causes a build failure: ``` JSONRPCConnection.swift:370:50: error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol 368 | 369 | // Setup callback for response type. 370 | decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in | |- error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol | `- note: a function type must be marked '@sendable' to conform to 'Sendable' 371 | guard let outstanding = self.outstandingRequests[id] else { 372 | logger.error("Unknown request for \(id, privacy: .public)") ``` Make the closure sendable, which is safe as we're only reading from `outstandingRequests` (where all our writes are guarded by the same queue that the decoding is on).
db0a67b
to
96247c0
Compare
@swift-ci please test |
@swift-ci please test Windows platform |
1 similar comment
@swift-ci please test Windows platform |
@swift-ci please test macOS platform |
swift-foundation recently landed a change (in
swiftlang/swift-foundation#764) which requires
any Sendable
values inJSONEncoder.userInfo
. This causes a build failure:Make the closure sendable, which is safe as we're only reading from
outstandingRequests
(where all our writes are guarded by the same queue that the decoding is on).