Commit Graph

5 Commits

Author SHA1 Message Date
Doug Gregor
73687c9f5f [Interop] Test APINotes support for noncopyable types with SwiftDestroyOp. 2025-08-12 10:12:38 -07:00
Doug Gregor
8909f24440 Add SWIFT_NONCOPYABLE_WITH_DESTROY to swift/bridging header
This packages up the ~Copyable and "destroy" attributes in a macro.
2025-07-28 15:51:44 -07:00
Doug Gregor
63135e8929 [Clang importer] Diagnose various issues with the new "destroy:"
When we cannot respect the "destroy:" annotation, mark the type as
deprecated with a message thst says why there is a problem. There are
various potential problems:

* Multiple conflicting destroy functions
* Destroy functions that don't meet the pattern
* Type isn't imported as a move-only type
* Type has a non-trivial destructor (in C++)
2025-07-28 13:52:50 -07:00
Doug Gregor
6ba560fb4b [Clang importer] Allow noncopyable C structs to define "destroy" operation
A C struct can be imported as noncopyable, but C doesn't have
destructors, so there is no way to provide user-defined logic to
perform the destruction. Introduce a new swift_attr that applies to
imported noncopyable types and which provides such a "destroy"
operation. It can be used like this:

    typedef struct __attribute__((swift_attr("~Copyable")))
                   __attribute__((swift_attr("destroy:wgpuAdapterInfoFreeMembers")))
      WGPUAdapterInfo { /*...*/ } WGPUAdapterInfo;

    void wgpuAdapterInfoFreeMembers(WGPUAdapterInfo adapterInfo);

This will bring the WGPUAdapterInfo struct in as a noncopyable type
that will be cleaned up by calling wgpuAdapterInfoFreeMembers once it
is no longer in use.

Implements rdar://156889370.
2025-07-28 00:02:31 -07:00
Doug Gregor
21b9b9f713 [Clang importer] Allow C structs to be noncopyable, too
In C interoperability mode, respect the ~Copyable annotation on C
structs to import them as ~Copyable types.

Fixes rdar://156877772.
2025-07-27 20:06:48 -07:00