21 Commits

Author SHA1 Message Date
Doug Gregor
ae90b60fc8
[APINotes] Add SwiftDestroyOp API note to map to the "destroy" function (#153261)
Like retain/release for reference types, "destroy" lets us specify an
operation that is used to deinitialize an instance of a noncopyable
type.
2025-08-15 08:02:14 +01:00
Doug Gregor
2b37471f72
[API notes] Allow SwiftConformsTo on Typedefs
SwiftConformsTo specifies an additional conformance that should be
applied on import. Allow this on typedefs, because those can be imported
as wrapper types.
2025-08-12 19:57:43 +01:00
fahadnayyar
62a2f0fdc7
[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
2025-05-07 13:42:39 -07:00
fahadnayyar
48f7f63ac7
[APINotes] Add SWIFT_RETURNS_(UN)RETAINED support (#118938)
Adding support to APINotes to annotate C++ methods and functions with
`swift_attr("returns_retained")` and `swift_attr("returns_unretained")`

rdar://141007510
2024-12-09 15:37:09 -08:00
Gábor Horváth
d2db9bd708
[clang][APINotes] Add support for the SwiftEscapable attribute (#115866)
This is similar to SwiftCopyable. Also fix missing SwiftCopyable dump
for TagInfo.
2024-11-12 21:34:56 +00:00
Gábor Horváth
5f4e3a3ced
[clang] Support 'this' position for lifetimebound attribute (#115021)
This patch makes the position -1 interpreted as the position for 'this'.
Adds some basic infrastructure and support for lifetimebound attribute.
2024-11-07 17:54:04 +00:00
Gábor Horváth
7ac78f1342
[clang] Add preliminary lifetimebound support to APINotes (#114830) 2024-11-04 20:29:56 +00:00
Egor Zhdan
b81697718f
[APINotes] Support fields of C/C++ structs
This allows annotating fields of C/C++ structs using API Notes.

Previously API Notes supported Objective-C properties, but not fields.

rdar://131548377
2024-08-16 18:48:39 +01:00
Egor Zhdan
dc8c217db6
[APINotes] Support C++ tag conformances to Swift protocols
This allows adding a Clang attribute
`swift_attr("conforms_to:ModuleName.ProtocolName")` to C++ structs via
API Notes.

The Swift compiler respects this attribute when importing C++ types into
Swift by automatically declaring the C++ type as a conforming type to
the given Swift protocol.

rdar://131388824
2024-08-13 12:47:23 +01:00
Egor Zhdan
4d5f81cad5
[APINotes] Support nested tags
This allows annotating C/C++ structs declared within other structs using
API Notes.

rdar://132083354
2024-07-23 12:28:00 +01:00
Egor Zhdan
8a79dc7e6f
[APINotes] Support annotating C++ methods
This adds support for adding Clang attributes to C++ methods declared
within C++ records by using API Notes.

For instance:
```
Tags:
- Name: IntWrapper
  Methods:
  - Name: getIncremented
    Availability: none
```

This is the first instance of something within a C++ record being
annotated with API Notes, so it adds the necessary infra to make a C++
record an "API Notes context".

Notably this does not add support for nested C++ tags. That will be
added in a follow-up patch.

rdar://131387880
2024-07-19 13:35:13 +01:00
Egor Zhdan
c5f402f95d
[APINotes] Reduce memory footprint for Obj-C/C++ contexts
We were storing extraneous data for certain Objective-C/C++ entities.
Specifically, for declarations that can be nested in another context
(such as functions) we were storing the kind of the parent context in
addition to its ID. The ID is always sufficient.

This removes the logically incorrect usages of `ContextTableKey` that
don't actually describe a context, but rather describe a single
declaration. This introduces `SingleDeclTableKey` to store that kind of
entities in a more compact and reasonable way.
2024-07-18 13:27:24 +01:00
Egor Zhdan
82ee7ae3c9
[APINotes] Refactor: remove references to ObjCContext...
API Notes now support in C++. In preparation for supporting C++ methods
in API Notes, this change renames the remaining usages of
`ObjCContextABC` into `ContextABC` to make it clear that those contexts
might actually be C++, not Objective-C.

This is NFC-ish.
2024-07-10 15:07:09 +01:00
Egor Zhdan
b2098db248
[APINotes] Allow annotating a C++ type as non-copyable in Swift
Certain C++ types, such as `std::chrono::tzdb` in libstdc++, are
non-copyable, but don't explicitly delete their copy constructor.
Instead, they trigger template instantiation errors when trying to call
their implicit copy constructor. The Swift compiler inserts implicit
copies of value types in some cases, which trigger compiler errors for
such types.

This adds a Clang API Notes attribute that allows annotating C++ types
as non-copyable in Swift. This lets the Swift compiler know that it
should not try to instantiate the implicit copy constructor for a C++
struct.

rdar://127049438
2024-04-26 19:30:08 +01:00
Egor Zhdan
41021e8ef8
[APINotes] Upstream APINotes YAML compiler
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
2023-11-13 19:36:36 +00:00
Egor Zhdan
195cdfd9ec
[APINotes] Support SwiftImportAs for C++ structs
This upstreams a few Clang API Notes attributes that were recently added
downstream in the Apple fork
(https://github.com/apple/llvm-project/pull/7386).
2023-09-07 08:39:35 +01:00
Egor Zhdan
8dc789a226
[APINotes] Upstream APINotesWriter
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
2023-09-04 19:45:55 +01:00
Egor Zhdan
9939556625
[APINotes] Initial support for C++ namespaces
This upstreams a part of the C++ namespaces support in Clang API Notes.

The complete patch was recently merged downstream in the Apple fork: https://github.com/apple/llvm-project/pull/7230.

This patch only adds the parts of the namespace support that can be cleanly applied on top of the API Notes infrastructure that was upstreamed previously.

Differential Revision: https://reviews.llvm.org/D159092
2023-08-30 12:54:42 +01:00
Saleem Abdulrasool
f806be5eaa APINotes: add initial stub of APINotesWriter
This adds the skeleton for serializing out the APINotes data from the
APINotes. The writer uses a private implementation pattern to reduce
the exposed surface to just the programmatic representation of the
APINotes and not expose the details of the bitcode encoding. The format
itself is not considered stable and should only be accessed through the
APINotes Reader and Writer types.

Differential Revision: https://reviews.llvm.org/D92797
Reviewed By: martong
2023-08-17 08:49:35 -07:00
Evan Wilde
e4ad1f976d
[NFC] Remove extra semicolons in clang/lib/APINotes/APINotesFormat.h
There are some trailing semicolons on namespaces in
clang/lib/APINotes/APINotesFormat.h. These result in warnings while
building and don't need to be there.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D105049
2023-07-21 16:19:53 -07:00
Saleem Abdulrasool
b13f741511 APINotes: add bitcode format schema definitions
This adds the bitcode format schema required for serialization of the
YAML data to a binary format.  APINotes are pre-compiled and re-used in
the binary format from the frontend.  These definitions provide the data
layout representation enabling writing (and eventually) reading of the
data in bitcode format.

This is extracted from the code contributed by Apple at
https://github.com/llvm/llvm-project-staging/tree/staging/swift/apinotes.

Differential Revision: https://reviews.llvm.org/D91997
Reviewed By: Gabor Marton
2020-12-08 21:15:41 +00:00