-
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 attribute for Swift ownership support #314
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces a new attribute that can be used to enable experimental support for Swift ownership. The new `__experimental_swift_ownership` can be used on an opaque Rust type. ```rust #[swift_bridge::bridge] mod foo { extern "Rust" { #[swift_bridge(__experimental_swift_ownership)] type SomeType; } } ``` This new attribute currently does nothing. In future commits, when `swift-bridge` sees that a type has the experimental ownership attribute it will generate code that takes advantage of Swift 6's ownership features. For instance, we will use Swift's `~Copyable` protocol to ensure that when Swift has ownership over an opaque Rust type it cannot copy that handle, which should make attempts to use-after-free a compile-time error instead of a runtime error.
chinedufn
changed the title
experimental swift ownership attribute
Add attribute for Swift ownership support
Feb 2, 2025
chinedufn
commented
Feb 2, 2025
@@ -805,158 +805,6 @@ mod tests { | |||
assert_eq!(parse_errors(tokens).len(), 0,); | |||
} | |||
|
|||
/// Verify that we can parse the `already_declared` attribute. |
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.
tests moved to another file
chinedufn
commented
Feb 2, 2025
Comment on lines
+262
to
+276
/// Verify that we parse a Rust opaque type's experimental Swift ownership attribute. | ||
#[test] | ||
fn parse_experimental_swift_ownership_attribute() { | ||
let tokens = quote! { | ||
mod foo { | ||
extern "Rust" { | ||
#[swift_bridge(__experimental_swift_ownership)] | ||
type SomeType; | ||
} | ||
} | ||
}; | ||
let attribs = unwrap_opaque_type_attributes(tokens, "SomeType"); | ||
|
||
assert_eq!(attribs.experimental_swift_ownership, true); | ||
} |
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.
This is the only new test case.
The rest were moved from another file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add attribute for Swift ownership support
This commit introduces a new attribute that can be used to enable
experimental support for Swift ownership.
The new
__experimental_swift_ownership
can be used on an opaque Rusttype.
This new attribute currently does nothing.
In future commits, when
swift-bridge
sees that a type has theexperimental ownership attribute it will generate code that takes
advantage of Swift 6's ownership features.
For instance, we will use Swift's
~Copyable
protocol to ensure thatwhen Swift has ownership over an opaque Rust type it cannot copy that
handle, which should make attempts to use-after-free a compile-time
error instead of a runtime error.