Skip to content

🍒 [6.2] [APINotes] Add support for SWIFT_RETURED_AS_UNRETAINED_BY_DEFAULT #10640

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 1 commit into
base: swift/release/6.2
Choose a base branch
from

Conversation

fahadnayyar
Copy link

This patch adds support in APINotes for annotating C++ user-defined types with: swift_attr("returned_as_unretained_by_default") This attribute allows to specify a default ownership convention for return values of SWIFT_SHARED_REFERENCE c++ types. Specifically, it marks all unannotated return values of this type as unretained (+0) by default, unless explicitly overridden at the API level using swift_attr("returns_retained") or swift_attr("returns_unretained").

The corresponding Swift compiler support for this annotation enables developers to suppress warnings about unannotated return ownership in large codebases while maintaining safe and predictable ownership semantics. By enabling this in APINotes, library authors can define this behavior externally without needing to modify C++ source headers directly.

- Name: RefCountedTypeWithDefaultConvention
  SwiftImportAs: reference
  SwiftDefaultOwnership: unretained

rdar://150764491

(cherry picked from commit 62a2f0f)

…vm#138699)

This patch adds support in APINotes for annotating C++ user-defined
types with: `swift_attr("returned_as_unretained_by_default")`
This attribute allows to specify a default ownership convention for
return values of `SWIFT_SHARED_REFERENCE` c++ types. Specifically, it
marks all unannotated return values of this type as `unretained` (`+0`)
by default, unless explicitly overridden at the API level using
`swift_attr("returns_retained")` or `swift_attr("returns_unretained")`.

The corresponding Swift compiler support for this annotation enables
developers to suppress warnings about unannotated return ownership in
large codebases while maintaining safe and predictable ownership
semantics. By enabling this in APINotes, library authors can define this
behavior externally without needing to modify C++ source headers
directly.

```
- Name: RefCountedTypeWithDefaultConvention
  SwiftImportAs: reference
  SwiftDefaultOwnership: unretained

```
rdar://150764491
@fahadnayyar fahadnayyar requested a review from a team as a code owner May 8, 2025 02:19
@fahadnayyar
Copy link
Author

@swift-ci please test

@fahadnayyar fahadnayyar requested a review from DougGregor May 8, 2025 02:23
@fahadnayyar
Copy link
Author

@swift-ci please test windows

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