-
Notifications
You must be signed in to change notification settings - Fork 62
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
Support Option<OpaqueSwiftType> #272
Conversation
@@ -15,34 +15,34 @@ class OptionTests: XCTestCase { | |||
func testSwiftCallRustOptionPrimitive() throws { |
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.
Autoformatting did something to the spacing in this whole file... I'll leave a comment where I actually made changes
|
||
XCTAssertNil(rust_reflect_option_opaque_swift_type(nil)) | ||
} | ||
|
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.
Actual changes are here
@@ -65,3 +65,121 @@ func __swift_bridge__some_function (_ arg: UnsafeMutableRawPointer) { | |||
.test(); | |||
} | |||
} | |||
|
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.
Moved here from extern_swift_function_opaque_swift_type_return_codegen_tests.rs
... the original issue mentioned moving those tests
@@ -1,3 +1,5 @@ | |||
#![allow(dead_code)] |
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.
I faced the same issue as #270 - tests wouldn't even compile without this, since -D warnings
is enabled for them. I also had to make this change to result.rs
below. Maybe there's a better solution, this was just what I did to get tests running
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.
Please document:
- why we're allowing dead code
- what needs to happen to remove this allow dead code
- link to the issue
Seems like this can be deleted once #270 is closed. So, yeah just mention that.
This will make it easier for us to eventually stop allowing dead code.
Please also apply this feedback to result.rs
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.
Nice work. Just one small bit of feedback.
@@ -1,3 +1,5 @@ | |||
#![allow(dead_code)] |
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.
Please document:
- why we're allowing dead code
- what needs to happen to remove this allow dead code
- link to the issue
Seems like this can be deleted once #270 is closed. So, yeah just mention that.
This will make it easier for us to eventually stop allowing dead code.
Please also apply this feedback to result.rs
Looks like tests are failing: error[E0412]: cannot find type `OptTestOpaqueSwiftType` in module `super`
--> crates/swift-integration-tests/src/option.rs:128:14
|
128 | type OptTestOpaqueSwiftType;
| ^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `OptTestOpaqueRustType`
...
202 | pub struct OptTestOpaqueRustType {
| -------------------------------- similarly named struct `OptTestOpaqueRustType` defined here
For more information about this error, try `rustc --explain E0412`.
error: could not compile `swift-integration-tests` (lib) due to 1 previous error |
That's embarrassing... I'd removed a I commented on #270 with the output but on nightly some of the |
Hmm, not sure what happened. Paths should work swift-bridge/crates/swift-integration-tests/src/option.rs Lines 326 to 330 in 58f4a40
Cool. Looks good. I'll merge once tests pass. |
Thanks! |
Published as |
Replaced the Explained here b4ba1a7 |
When I was working on b4ba1a7 I noticed that when returning Swift types from swift-bridge/crates/swift-bridge-ir/src/codegen/codegen_tests/opaque_swift_type_codegen_tests.rs Lines 26 to 33 in 636fa27
It looks like this #272 PR was avoiding that Drop by incrementing the Swift type's retain count twice instead of once. This means that we were leaking memory. My apologies for not thinking of this during review. Fixed #273 |
That makes a lot more sense... I'd assumed for some reason it wasn't automatically incrementing the retain count, and thought I was just doing it once. |
Got it. 0.1.55 has been released https://crates.io/crates/swift-bridge/0.1.55 |
This adds support for bridging
Option<OpaqueSwiftType>
inextern "Rust"
functions. This fixes #268, and makes the following now possible: