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

JSON/PropertyList coders userInfo should require Sendable values #764

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

jmschonfeld
Copy link
Contributor

This requires that the userInfo values are Sendable since they are stored in Sendable types. The @preconcurrency attribute ensures that this is not an ABI breaking change or a source breaking change for projects using the Swift 5 language mode.

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

Marking as draft at the moment while we wait on this one - we need to wait for a compiler fix to ensure this isn't source breaking to clients

@jmschonfeld jmschonfeld marked this pull request as draft July 25, 2024 23:27
@jmschonfeld jmschonfeld force-pushed the coder-sendable-ui-value branch from 1238718 to c93635f Compare August 21, 2024 18:46
@jmschonfeld jmschonfeld marked this pull request as ready for review August 21, 2024 18:46
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld marked this pull request as draft August 22, 2024 16:24
@jmschonfeld jmschonfeld force-pushed the coder-sendable-ui-value branch from c93635f to 17427b6 Compare February 12, 2025 17:21
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld marked this pull request as ready for review February 12, 2025 17:22
@jmschonfeld
Copy link
Contributor Author

Compiler issues have been addressed so we're ready to land this now. Rebased on main

@jmschonfeld jmschonfeld merged commit c5bacdf into swiftlang:main Feb 12, 2025
2 of 3 checks passed
@jmschonfeld jmschonfeld deleted the coder-sendable-ui-value branch February 12, 2025 17:57
stmontgomery added a commit to swiftlang/swift-testing that referenced this pull request Feb 12, 2025
…#955)

swift-foundation recently landed a change (in
swiftlang/swift-foundation#764) which requires
`any Sendable` values in `JSONEncoder.userInfo`. This causes a build
failure in swift-testing:

```
JSON.swift:44:28: error: type 'Any' does not conform to the 'Sendable' protocol 
42 | 
43 |     // Set user info keys that clients want to use during encoding.
44 |     encoder.userInfo.merge(userInfo, uniquingKeysWith: { _, rhs in rhs})
   |                            `- error: type 'Any' does not conform to the 'Sendable' protocol
```

This PR adjusts our `userInfo:` parameter require `any Sendable` values.
The values we were passing to this utility were already sendable,
luckily.

### 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.
bnbarham added a commit to bnbarham/sourcekit-lsp that referenced this pull request Feb 13, 2025
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 (the decoding here is already guarded by a
queue).
bnbarham added a commit to bnbarham/sourcekit-lsp that referenced this pull request Feb 13, 2025
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 (the decoding here is already guarded by a
queue).
bnbarham added a commit to bnbarham/sourcekit-lsp that referenced this pull request Feb 13, 2025
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 (the decoding here is already guarded by a
queue).
@tshortli
Copy link
Contributor

Reverted in #1167 because it broke Swift CI.

bnbarham added a commit to bnbarham/sourcekit-lsp that referenced this pull request Feb 13, 2025
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants