Skip to content

[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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fahadnayyar
Copy link

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.

@fahadnayyar
Copy link
Author

@swift-ci test

@shahmishal
Copy link
Member

@egorzhdan @fahadnayyar Is this PR ready to be merged?

@egorzhdan
Copy link
Contributor

@shahmishal no, not yet.

@hnrklssn
Copy link

hnrklssn commented Jun 4, 2025

Do we still plan to merge this?

@fahadnayyar fahadnayyar changed the title [cxx-interop] Document guarantees and assumptions for non-const C++ s… [cxx-interop] Document guarantees and assumptions for non-const SWIFT_SHARED_REFERENCE types passed to a C++ API from Swift Jun 10, 2025
@fahadnayyar fahadnayyar force-pushed the cxx-frt-param-from-swift-to-cxx branch from 9e29267 to 21f224f Compare July 2, 2025 14:06
@fahadnayyar fahadnayyar requested a review from davelester as a code owner July 2, 2025 14:06
@fahadnayyar
Copy link
Author

Do we still plan to merge this?

Yes @hnrklssn. We believe these are crucial aspects to document. After Swift 6.2, documenting assumptions about SWIFT_SHARED_REFERENCE types becomes even more important, especially considering the recent changes we've made to this feature. Additionally, the adoption of this feature has increased significantly in recent times.

@fahadnayyar
Copy link
Author

fahadnayyar commented Jul 2, 2025

@Xazax-hun @j-hui can you also please take a look at this?

Copy link
Contributor

@j-hui j-hui left a 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

@fahadnayyar fahadnayyar changed the title [cxx-interop] Document guarantees and assumptions for non-const SWIFT_SHARED_REFERENCE types passed to a C++ API from Swift [cxx-interop] Document guarantees and assumptions for SWIFT_SHARED_REFERENCE types passed to a C++ API from Swift Jul 3, 2025
@fahadnayyar fahadnayyar changed the title [cxx-interop] Document guarantees and assumptions for SWIFT_SHARED_REFERENCE types passed to a C++ API from Swift [cxx-interop] Document guarantees and assumptions for SWIFT_SHARED_REFERENCE types passed to a C++ API as a parameter from Swift Jul 4, 2025

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++.
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants