-
Notifications
You must be signed in to change notification settings - Fork 240
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: Make it possible to mark value types as Sendable
with sendable_value_types
config
#2045
Conversation
a4623c9
to
630269f
Compare
Very interesting. I want to understand My first question is what's the difference between it and Rust's Second question: what's the interaction between |
I believe a good approximation of explaining Swift Unconditionally marking all value types as Sendable is better than not doing it - I just through letting it be opt it would make it more likely to get this PR in... I'm not convinced adding it unconditionally for reference types (Swift classes) is a good idea though, maybe that at least should be opt in. But I did not add impl of Sendable for reference types since implementation is trickier - and since personally I dont need it. Regarding
|
It seems to me that any type used with UniFFI should basically fit this description (although maybe
However, this makes a lot of sense to me. I certainly feel more comfortable approving this if it's behind a config value. What do you think about making it opt-in for
I think there's 2 cases here:
I'm speaking from a strictly conceptual perspective here though, I don't know how hard the implementation would be. |
We could even go a little further and name the config value with an |
Cool! I will rename flag with experimental_ prefix and update changelog in a couple of hours |
…of new config 'sendable_value_types' in uniffi.toml.
630269f
to
13c3fb3
Compare
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.
Looks great, thanks for updating the PR.
Do you folks think this could also be extended to uniffi objects? |
Sure - but see the conversation above, it's not clear to some of us if it makes sense to be unconditional etc - we'd welcome input into everything about this - ie, whether it should eventually be the default, whether it should be opt-in/opt-out per "broad type" (ie, enum, object), per "single type" (ie, Foo, Bar), etc. |
Noted. As far as I'm concerned, I'm okay with this being the default for all uniffi objects as well, since the underlying Rust objects are already |
Make it possible to mark Swift value types as
Sendable
- which is needed for Swift 6.sendable_value_types
(false by default)sendable_value_types: true
) will mark:[uniffi::Record]
) Swiftstruct
s which does not contain object references asSendable
[uniffi::Enum]
) Swiftenums
s which does not contain object references asSendable
This will make it possible for Swift devs to skip having to add
@unchecked Sendable
all over the placeI was unable to add a meaningful fixture though, since it is not possible to "unit test" this. The only way to "test" it is to ensure that compilation fails... which would be possible if:
strict-concurrency=complete
toswiftc
for bindgen test.Alternatives to consider
AND/OR we can add a different set of (Swift only) config flags:
frozen_struct
andfrozen_enum
(or simplyfrozen_value_types
) - because types marked@frozen
automatically becomesSendable
, but I think it valuable to not have to mark a value type as@frozen
just to getSendable
. I can do another PR for the@frozen
annotation if you'd like?