From 0253725a2546c39fdc06fd987528bc2492f331b9 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 16:21:52 -0700 Subject: [PATCH 1/3] [Interop] Make example in doc comment more idiomatic Inheriting some class named `NonCopyable` is not what makes a type noncopyable. Explicitly use SWIFT_NONCOPYABLE in the example instead. --- lib/ClangImporter/SwiftBridging/swift/bridging | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ClangImporter/SwiftBridging/swift/bridging b/lib/ClangImporter/SwiftBridging/swift/bridging index 4c8e97d4a8e80..532f2c35c0913 100644 --- a/lib/ClangImporter/SwiftBridging/swift/bridging +++ b/lib/ClangImporter/SwiftBridging/swift/bridging @@ -53,8 +53,8 @@ /// This example shows how to use this macro to let Swift know that /// a non-copyable reference counted C++ class can be imported as a reference counted type in Swift: /// ```c++ -/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject) -/// SharedObject : NonCopyable, IntrusiveReferenceCounted { +/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject) SWIFT_NONCOPYABLE +/// SharedObject : IntrusiveReferenceCounted { /// public: /// static SharedObject* create(); /// void doSomething(); @@ -84,8 +84,8 @@ /// This example shows how to use this macro to let Swift know that /// a non-copyable singleton C++ class can be imported as a reference type in Swift: /// ```c++ -/// class SWIFT_IMMORTAL_REFERENCE -/// LoggerSingleton : NonCopyable { +/// class SWIFT_IMMORTAL_REFERENCE SWIFT_NONCOPYABLE +/// LoggerSingleton { /// public: /// static LoggerSingleton &getInstance(); /// void log(int x); From e2f0cef76f334c7ceafe4a7bff6a82bfae9dde1f Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 25 Sep 2025 17:32:37 -0700 Subject: [PATCH 2/3] [Interop] replace unnecessary uses of _CXX_INTEROP_STRINGIFY --- lib/ClangImporter/SwiftBridging/swift/bridging | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ClangImporter/SwiftBridging/swift/bridging b/lib/ClangImporter/SwiftBridging/swift/bridging index 532f2c35c0913..3857dceb67034 100644 --- a/lib/ClangImporter/SwiftBridging/swift/bridging +++ b/lib/ClangImporter/SwiftBridging/swift/bridging @@ -71,7 +71,7 @@ /// object.doSomething() /// // The Swift compiler will release object here. /// ``` -#define SWIFT_SHARED_REFERENCE(_retain, _release) \ +#define SWIFT_SHARED_REFERENCE(_retain, _release) \ __attribute__((swift_attr("import_reference"))) \ __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \ __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release)))) @@ -98,18 +98,18 @@ /// let logger = LoggerSingleton.getInstance() /// logger.log(123) /// ``` -#define SWIFT_IMMORTAL_REFERENCE \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:immortal)))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:immortal)))) +#define SWIFT_IMMORTAL_REFERENCE \ + __attribute__((swift_attr("import_reference"))) \ + __attribute__((swift_attr("retain:immortal")))) \ + __attribute__((swift_attr("release:immortal")))) /// Specifies that a `class` or `struct` is a reference type whose lifetime /// is not managed automatically. The programmer must validate that any reference /// to such object is valid themselves. This annotation lets Swift import such a type as a reference type in Swift. -#define SWIFT_UNSAFE_REFERENCE \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:immortal)))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:immortal)))) \ +#define SWIFT_UNSAFE_REFERENCE \ + __attribute__((swift_attr("import_reference"))) \ + __attribute__((swift_attr("retain:immortal")))) \ + __attribute__((swift_attr("release:immortal")))) \ __attribute__((swift_attr("unsafe"))) /// Specifies a name that will be used in Swift for this declaration instead of its original name. From 75768435498f6b880504b9e8a52299b0bbf2910d Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 26 Sep 2025 10:40:09 -0700 Subject: [PATCH 3/3] more cleanup --- lib/ClangImporter/SwiftBridging/swift/bridging | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/ClangImporter/SwiftBridging/swift/bridging b/lib/ClangImporter/SwiftBridging/swift/bridging index 3857dceb67034..e8d1e193fe109 100644 --- a/lib/ClangImporter/SwiftBridging/swift/bridging +++ b/lib/ClangImporter/SwiftBridging/swift/bridging @@ -51,9 +51,9 @@ /// automatic reference counting. /// /// This example shows how to use this macro to let Swift know that -/// a non-copyable reference counted C++ class can be imported as a reference counted type in Swift: +/// a reference counted C++ class can be imported as a reference counted type in Swift: /// ```c++ -/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject) SWIFT_NONCOPYABLE +/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject) /// SharedObject : IntrusiveReferenceCounted { /// public: /// static SharedObject* create(); @@ -82,10 +82,9 @@ /// type in Swift. //// /// This example shows how to use this macro to let Swift know that -/// a non-copyable singleton C++ class can be imported as a reference type in Swift: +/// a singleton C++ class can be imported as a reference type in Swift: /// ```c++ -/// class SWIFT_IMMORTAL_REFERENCE SWIFT_NONCOPYABLE -/// LoggerSingleton { +/// class SWIFT_IMMORTAL_REFERENCE LoggerSingleton { /// public: /// static LoggerSingleton &getInstance(); /// void log(int x); @@ -100,16 +99,16 @@ /// ``` #define SWIFT_IMMORTAL_REFERENCE \ __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr("retain:immortal")))) \ - __attribute__((swift_attr("release:immortal")))) + __attribute__((swift_attr("retain:immortal"))) \ + __attribute__((swift_attr("release:immortal"))) /// Specifies that a `class` or `struct` is a reference type whose lifetime /// is not managed automatically. The programmer must validate that any reference /// to such object is valid themselves. This annotation lets Swift import such a type as a reference type in Swift. #define SWIFT_UNSAFE_REFERENCE \ __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr("retain:immortal")))) \ - __attribute__((swift_attr("release:immortal")))) \ + __attribute__((swift_attr("retain:immortal"))) \ + __attribute__((swift_attr("release:immortal"))) \ __attribute__((swift_attr("unsafe"))) /// Specifies a name that will be used in Swift for this declaration instead of its original name.