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

For Swift 5.10, mark Message/Enum _protobuf_nameMap nonisolated(unsafe) #1564

Closed

Conversation

thomasvl
Copy link
Collaborator

I think this is the rest of the issues in #1560

…fe)`

To cut down on the generate code, only conditional the decls, and declare a new
static function do the the actual construction.
p.print("\(visibility)static let _protobuf_nameMap: \(namer.swiftProtobufModulePrefix)_NameMap = [")
p.print("""
#if swift(>=5.10)
\(visibility)static nonisolated(unsafe) let _protobuf_nameMap: \(namer.swiftProtobufModulePrefix)_NameMap = _makeNameMap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that these might be public makes me a touch nervous. Why are these public again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Since they are public we cannot use nonisolated(unsafe) here since anybody could grab those; however, from looking at _NameMap this appears to be an immutable struct and the only reason that it isn't Sendable right now is due to the storage of a few UnsafeRawBufferPointer. We really should make the underlying type Sendable here by either coming up with an implementation that is Sendable by default or by double-checking that this is indeed immutable and then adding an @unchecked Sendable to the type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think revisiting the impl given how String has changed since the Swift 3 days (which is where I believe @tbkka _NameMap work goes back to) is likely a good idea, that's why I opened #1561.

If we push ahead with that in the coming weeks, this would likely just be sorter lived.

As for why they are public, it's because they are an api point that the Runtime needs to be able to invoke, and I don't believe we ever found a better way to handle that – i.e. - generated protocol conformance that the core runtime can call things on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that the need for these to satisfy a protocol witness forces them to be public. Ideally these conformances would be on a type that didn't need to be public, though I understand why they are.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until then I would recommend using @unchecked Sendable on the type instead of nonisolated(unsafe) let on the global

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until then I would recommend using @unchecked Sendable on the type instead of nonisolated(unsafe) let on the global

Is that likely to have to ripple through the support types also? i.e. - Name, InternPool?

I'm doing this somewhat blind (need to do Xcode updates to locally test), so this PR might have to sit a little while until so I can look at switching it over.

thomasvl added a commit to thomasvl/swift-protobuf that referenced this pull request Mar 15, 2024
I think this is the rest of the issues in apple#1560

This is the different approach discussed in apple#1564.
@thomasvl
Copy link
Collaborator Author

Closing this as I believe #1577 is the desired direction now.

@thomasvl thomasvl closed this Mar 15, 2024
@thomasvl thomasvl deleted the protobuf_nameMap_isolated_unsafe branch March 15, 2024 14:37
thomasvl added a commit to thomasvl/swift-protobuf that referenced this pull request Mar 18, 2024
I think this is the rest of the issues in apple#1560

This is the different approach discussed in apple#1564.
thomasvl added a commit that referenced this pull request Mar 19, 2024
I think this is the rest of the issues in #1560

This is the different approach discussed in #1564.
thomasvl added a commit to thomasvl/swift-protobuf that referenced this pull request Mar 19, 2024
I think this is the rest of the issues in apple#1560

This is the different approach discussed in apple#1564.
thomasvl added a commit to thomasvl/swift-protobuf that referenced this pull request Mar 19, 2024
I think this is the rest of the issues in apple#1560

This is the different approach discussed in apple#1564.
thomasvl added a commit that referenced this pull request Mar 25, 2024
I think this is the rest of the issues in #1560

This is the different approach discussed in #1564.
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