-
Notifications
You must be signed in to change notification settings - Fork 232
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] Async functions results in compile errors about data races #2274
Comments
We do have a few issues about swift 6 support, but don't really have any swift experts as regular contributors. So I think it's safe to say that we would consider this an issue because it should really be impossible for uniffi to generate code which causes a compile error, but it's not something any of the regular contributors are either working on or even understand in detail. |
I've been working on a work-around and managed to remove the compiler error by using a Swift wrapper making it But as long as you aren't mutating state in the Rust implementations you should be good with this wrapper solution in Swift: struct UncheckedSendableRustClass<T>: @unchecked Sendable {
private let instance: T
init(_ instance: T) {
self.instance = instance
}
func callAsFunction() -> T {
instance
}
} It allows me to refactor the original example into this: let storeHandler: UncheckedSendableRustClass<StoreHandlerProtocol>
...
private func updateSelectedStore(from selectedStoreId: SelectedStoreIdStorageDTO) async {
var stores: [Store] = []
do {
stores = try await self.storeHandler().stores() // ✅
...
} catch {
...
}
} |
Adding |
The Like this example: public protocol RustGeneratedProtocol: Sendable {
...
}
public class RustGenerated: RustGeneratedProtocol, @unchecked Sendable {
...
} That should make it work. Let me know if it doesn't 😊 |
I tried that before I asked. |
I am currently upgrading my project to Swift 6 and have solved a lot of the concurrency warnings with the
experimental_sendable_value_types = true
for values-types.I have a couple of struct implementations with async functions, which is exported with
#[derive(uniffi::Object)]
, so they are generated as aclass
in Swift.When awaiting those async functions in Swift I get this error:
This is the generated Swift code for the protocol:
And this is how I call the
StoreHandler
class implementation:I believe the compile-error would disappear if the
StoreHandlerProtocol
implementedSendable
and theStoreHandler
class-implementation would be defined as@unchecked Sendable
. But I am not sure that is the right solution, though.Is there any way I can work around this problem and are you even considering this as a issue that should be solved in uniffi?
The text was updated successfully, but these errors were encountered: