Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Copy link
Copy Markdown
Owner

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(swift_repr = "struct")]
struct AsyncRustFnReturnStruct {
field: u8,
}

But we'll still eventually want to replace all of these @unchecked Sendable with proper swift-bridge support for emitting Sendable impls as described in #269


extension ResultTestOpaqueRustType: @unchecked Sendable {}
extension ResultTestOpaqueRustType: Error {}

Expand All @@ -41,5 +47,7 @@ extension ResultTransparentStruct: Error {}
extension SameEnum: @unchecked Sendable {}
extension SameEnum: Error {}

extension AsyncResultOkEnum: @unchecked Sendable {}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hmm we'll want to move away from these @unchecked Sendable {}s in favor of enabling swift-bridge to emit Sendable extension.

In the meantime, you can make this @unchecked Sendable safe by replacing the inner String with a primitive such as u32.

enum AsyncResultOkEnum {
NoFields,
UnnamedFields(i32, String),
NamedFields { value: u8 },
}

Let's also leave a TODO in this file to ditch @unchecked Sendable in favor of proper Sendable support. Can link to #269

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 {}
4 changes: 3 additions & 1 deletion crates/swift-integration-tests/src/async_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ 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>;

async fn rust_async_reflect_string(string: String) -> String;
}

extern "Rust" {
Expand Down
Loading