-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add Sendable to all async return types in tests #312
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,23 +6,29 @@ | |||||||||||
// | ||||||||||||
|
||||||||||||
func swift_func_takes_callback_with_result_arg( | ||||||||||||
arg: (RustResult<CallbackTestOpaqueRustType, String>) -> () | ||||||||||||
arg: (RustResult<CallbackTestOpaqueRustType, String>) -> Void | ||||||||||||
) { | ||||||||||||
arg(.Ok(CallbackTestOpaqueRustType(555))) | ||||||||||||
arg(.Ok(CallbackTestOpaqueRustType(555))) | ||||||||||||
} | ||||||||||||
|
||||||||||||
public class ResultTestOpaqueSwiftType { | ||||||||||||
var num: UInt32 | ||||||||||||
init(val: UInt32) { | ||||||||||||
self.num = val | ||||||||||||
} | ||||||||||||
func val() -> UInt32 { | ||||||||||||
self.num | ||||||||||||
} | ||||||||||||
var num: UInt32 | ||||||||||||
|
||||||||||||
init(val: UInt32) { | ||||||||||||
self.num = val | ||||||||||||
} | ||||||||||||
|
||||||||||||
func val() -> UInt32 { | ||||||||||||
self.num | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// TODO: we can delete these type assertions once we correctly generate Sendable | ||||||||||||
// types. See the following issue: | ||||||||||||
// https://github.com/chinedufn/swift-bridge/issues/150 | ||||||||||||
|
||||||||||||
extension AsyncRustFnReturnStruct: @unchecked Sendable {} | ||||||||||||
|
||||||||||||
extension ResultTestOpaqueRustType: @unchecked Sendable {} | ||||||||||||
extension ResultTestOpaqueRustType: Error {} | ||||||||||||
|
||||||||||||
|
@@ -41,5 +47,7 @@ extension ResultTransparentStruct: Error {} | |||||||||||
extension SameEnum: @unchecked Sendable {} | ||||||||||||
extension SameEnum: Error {} | ||||||||||||
|
||||||||||||
extension AsyncResultOkEnum: @unchecked Sendable {} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm we'll want to move away from these In the meantime, you can make this swift-bridge/crates/swift-integration-tests/src/async_function.rs Lines 50 to 54 in 636fa27
Let's also leave a TODO in this file to ditch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference, I think you linked the wrong issue by accident - the relevant one is #150. |
||||||||||||
|
||||||||||||
extension AsyncResultErrEnum: @unchecked Sendable {} | ||||||||||||
extension AsyncResultErrEnum: Error {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,19 @@ mod ffi { | |
extern "Rust" { | ||
async fn rust_async_return_null(); | ||
async fn rust_async_reflect_u8(arg: u8) -> u8; | ||
async fn rust_async_reflect_string(string: String) -> String; | ||
|
||
async fn rust_async_return_struct() -> AsyncRustFnReturnStruct; | ||
async fn rust_async_func_reflect_result_opaque_rust( | ||
arg: Result<AsyncResultOpaqueRustType1, AsyncResultOpaqueRustType2>, | ||
) -> Result<AsyncResultOpaqueRustType1, AsyncResultOpaqueRustType2>; | ||
async fn rust_async_func_return_result_null_opaque_rust( | ||
succeed: bool, | ||
) -> Result<(), AsyncResultOpaqueRustType2>; | ||
|
||
// TODO: this is broken because RustString is not Sendable. | ||
// Work around making String and other opaque types Sendable is tracked | ||
// here: https://github.com/chinedufn/swift-bridge/issues/150 | ||
// async fn rust_async_reflect_string(string: String) -> String; | ||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It will be fully safe once we start using So, this code can be added back. Safety claims are here #309 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncommenting this line makes it fail to compile on Swift 6, and I think changing core code in this PR would be out of scope, no? |
||
} | ||
|
||
extern "Rust" { | ||
|
@@ -49,7 +54,7 @@ mod ffi { | |
|
||
enum AsyncResultOkEnum { | ||
NoFields, | ||
UnnamedFields(i32, String), | ||
UnnamedFields(i32, u32), | ||
NamedFields { value: u8 }, | ||
} | ||
|
||
|
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.
Currently safe since this struct only contains a primitive
swift-bridge/crates/swift-integration-tests/src/async_function.rs
Lines 8 to 11 in 636fa27
But we'll still eventually want to replace all of these
@unchecked Sendable
with properswift-bridge
support for emittingSendable
impls as described in #269