llvm-project
62a2f0fd - [APINotes] Add support for SWIFT_RETURED_AS_UNRETAINED_BY_DEFAULT (#138699)

Commit
1 year ago
[APINotes] Add support for SWIFT_RETURED_AS_UNRETAINED_BY_DEFAULT (#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. ### Example usage in APINotes: ``` - Name: RefCountedTypeWithDefaultConvention SwiftImportAs: reference SwiftDefaultOwnership: unretained ``` rdar://150764491
Author
Parents
Loading