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

Swift 6 concurrency error on _StorageClass.defaultInstance #1729

Closed
rebello95 opened this issue Oct 3, 2024 · 12 comments
Closed

Swift 6 concurrency error on _StorageClass.defaultInstance #1729

rebello95 opened this issue Oct 3, 2024 · 12 comments

Comments

@rebello95
Copy link
Contributor

When building with Xcode 16.0 and the Swift 6 toolchain, the following error occurs with a generated _StorageClass type:

Static property 'defaultInstance' is not concurrency-safe because non-'Sendable' type

Screenshot 2024-10-03 at 10 42 56 AM

I read through #1560 which discussed this a bit, but based on this comment I opted to open a new issue.

This can reproduced on this Connect-Swift branch, but I think this is an issue with any generated _StorageClass when building with Swift 6.

@thomasvl
Copy link
Collaborator

thomasvl commented Oct 3, 2024

@FranzBusch @gjcairo fyi - since I think you all mentioned working on full Swift 6 language mode. I guess starting with generated code would unblock folks first.

While #1561 might be sorta large to pull off in a non breaking way, I do wonder if that resolves a lot of this since I think the name map could get a lot simpler (no need for interning, etc.)

@thomasvl
Copy link
Collaborator

thomasvl commented Oct 3, 2024

@tbkka fyi also

@FranzBusch
Copy link
Member

since I think you all mentioned working on full Swift 6 language mode. I guess starting with generated code would unblock folks first.

I agree tackling the generated code is the most important thing. I do think we need to do all of this in a non-breaking way for now. Right now we are working through our other repos to make sure they compile without errors in Swift 6.

rebello95 added a commit to connectrpc/connect-swift that referenced this issue Oct 9, 2024
We can upgrade to the Swift 6 toolchain separately; need some fixes in
SwiftProtobuf first (like
apple/swift-protobuf#1729).

---------

Signed-off-by: Michael Rebello <[email protected]>
@jhump
Copy link

jhump commented Oct 16, 2024

Do you have any idea of how soon this repo can be made compatible with Swift 6? We have a library that depends on this repo, and we're nearing a v1.0 release for it. We were hoping the v1.0 release could use Swift 6, but this issue is a blocker for that.

@Lukasa
Copy link
Contributor

Lukasa commented Nov 29, 2024

I think it'd be very helpful to get a complete list of Swift 6 issues you see. The specific concurrency issue here should be solveable using nonisolated(unsafe) on this static let, but I'd love to know if there were more.

@thomasvl
Copy link
Collaborator

Can someone that is seeing this issue see if they can recreated it by modifying #1737? I made attempt at ensuring the generate file had the Storage and also enabling v6 language mode on the packages, but I can't seem to get the warnings/errors in the new CI step.

@rebello95
Copy link
Contributor Author

I think it'd be very helpful to get a complete list of Swift 6 issues you see. The specific concurrency issue here should be solveable using nonisolated(unsafe) on this static let, but I'd love to know if there were more.

@Lukasa Manually changing that line to nonisolated(unsafe) static let defaultInstance = _StorageClass() allowed me to build without further errors/warnings in my case.

Can someone that is seeing this issue see if they can recreated it by modifying #1737? I made attempt at ensuring the generate file had the Storage and also enabling v6 language mode on the packages, but I can't seem to get the warnings/errors in the new CI step.

@thomasvl I wonder if this could be related to the fact that CI is running on ubuntu-latest 🤔 are you able to repro the issue locally?

@thomasvl
Copy link
Collaborator

thomasvl commented Jan 2, 2025

@thomasvl I wonder if this could be related to the fact that CI is running on ubuntu-latest 🤔 are you able to repro the issue locally?

On my Mac with Xcode 16.2 installed, using the github main branch, make test-spm-plugin SWIFT_BUILD_TEST_HOOK="-Xswiftc -warnings-as-errors" passes. So, no; I can't seem to repo it, so I'm hoping other folks that see the failure(s) can provide some insights so we can get something to repo it to track it going forward.

@thomasvl
Copy link
Collaborator

thomasvl commented Jan 2, 2025

@rebello95 skimming back through, I don't think it was said, what version of SwiftProtobuf are you pulling in? Are you maybe on an older release?

@rebello95
Copy link
Contributor Author

@rebello95 skimming back through, I don't think it was said, what version of SwiftProtobuf are you pulling in? Are you maybe on an older release?

I'm seeing this on 1.28.2. It's reproducible on this commit when trying to build the Connect-Swift project in Xcode 16.2.

@thomasvl
Copy link
Collaborator

thomasvl commented Jan 6, 2025

@rebello95 skimming back through, I don't think it was said, what version of SwiftProtobuf are you pulling in? Are you maybe on an older release?

I'm seeing this on 1.28.2. It's reproducible on this commit when trying to build the Connect-Swift project in Xcode 16.2.

That commit is changing the main Package.swift, so it is changing how the SwiftProtobuf runtime is compiled, it isn't just about the generated code, and I thought your original comment in opening this issue was just about the generated code. How are you getting the original error from generated code without changing out the SwiftProtobuf code itself is compiled? SwiftPM should be fine with this library compiled in Swift 5 Language Mode and your code (and the generated code for Protos) being compiled in the 6 mode. If you have a problem in that setup, we'd like to recreate that to ensure we keep that building at all times.

@rebello95
Copy link
Contributor Author

Ah, I dug through all the config files in the connect-swift project after reading your comment and noticed that one of them was still running on 1.25.2 instead of 1.28.2 🤦🏽 so importantly it was missing the changes from 3bc7630. I was able to get it working by updating that in connectrpc/connect-swift#331.

I apologize for the unnecessary concern. Thank you for your help with this @thomasvl 🙏🏽

rebello95 added a commit to connectrpc/connect-swift that referenced this issue Jan 9, 2025
After some discussion in
apple/swift-protobuf#1729, I noticed that the
compilation error when building with Swift 6 is actually an issue with
the config in `Tests/UnitTests/ConnectLibraryTests/buf.gen.yaml` which
was still running on `1.25.2` instead of `1.28.2` like other parts of
the project.

Changes in this PR:

- Updates that directory to run on `1.28.2` which includes
apple/swift-protobuf@3bc7630
and resolves the problem described in the aforementioned issue
- Switches CI to use Xcode 16.2 and macOS 15
- Switches our `Package.swift` to use Swift 6 when available via
`swiftLanguageVersions: [.version("6"), .v5]`
- Updates the Eliza SPM app to use Swift 6

This is related to
#310, but we will not
be able to actually implement those until we fully switch to using Swift
6 (a breaking change).

---------

Signed-off-by: Michael Rebello <[email protected]>
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

No branches or pull requests

5 participants