-
Notifications
You must be signed in to change notification settings - Fork 238
[cxx-interop] Document guarantees and assumptions for SWIFT_SHARED_REFERENCE
types passed to a C++ API as a parameter from Swift
#816
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
base: main
Are you sure you want to change the base?
Conversation
@swift-ci test |
@egorzhdan @fahadnayyar Is this PR ready to be merged? |
@shahmishal no, not yet. |
Do we still plan to merge this? |
SWIFT_SHARED_REFERENCE
types passed to a C++ API from Swift
…hared references passed to a C++ API from Swift
9e29267
to
21f224f
Compare
Yes @hnrklssn. We believe these are crucial aspects to document. After Swift 6.2, documenting assumptions about |
@Xazax-hun @j-hui can you also please take a look at this? |
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.
A few small editorial nits, but haven't had time to closely the language yet
SWIFT_SHARED_REFERENCE
types passed to a C++ API from SwiftSWIFT_SHARED_REFERENCE
types passed to a C++ API from Swift
SWIFT_SHARED_REFERENCE
types passed to a C++ API from SwiftSWIFT_SHARED_REFERENCE
types passed to a C++ API as a parameter from Swift
|
||
The C++ function can overwrite the value of the argument with the new value. | ||
However, the C++ function is responsible for releasing the old value, and ensuring that the new value is properly retained so that the Swift caller has ownership of the new value when the function returns. | ||
Adhering to these rules is necessary to safely and correctly pass around `SWIFT_SHARED_REFERENCE` between Swift and C++. |
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.
@j-hui these 2 last lines are good, but I am not sure about their placement. Any suggestions?
Since we are editing this document with multiple calling conventions and rules about safely using SWIFT_SHARED_REFERENCE types and passing across the boundaries, I am not sure where to place these 2 lines.
Or maybe we can do such minor palcement edits later in a follow up patch?
These assumptions and guarantees are important to be documented to make sure that when C++ Shared Reference Types are passed as a non-const parameter to a C++ function or method from swift, then user's don't make wrong assumptions about the default behaviour supported in the Swift compiler.