Skip to content

Commit baf06a1

Browse files
authored
Merge pull request swiftlang#69548 from Genaro-Chris/main
Import custom c++ types as unchecked sendable types
2 parents 933c388 + f715d99 commit baf06a1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/ClangImporter/bridging

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@
140140
#define SWIFT_MUTATING \
141141
__attribute__((swift_attr("mutating")))
142142

143+
/// Specifies that a specific c++ type such class or struct should be imported as type marked
144+
/// as `@unchecked Sendable` type in swift. If this annotation is used, the type is therefore allowed to
145+
/// use safely across async contexts.
146+
///
147+
/// For example
148+
/// ```
149+
/// class SWIFT_UNCHECKED_SENDABLE CustomUserType
150+
/// { ... }
151+
/// ```
152+
/// Will be imported as `struct CustomUserType: @unchecked Sendable`
153+
#define SWIFT_UNCHECKED_SENDABLE \
154+
__attribute__((swift_attr("@Sendable")))
155+
143156
#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
144157

145158
// Empty defines for compilers that don't support `attribute(swift_attr)`.
@@ -151,7 +164,8 @@
151164
#define SWIFT_NAME(_name)
152165
#define SWIFT_CONFORMS_TO_PROTOCOL(_moduleName_protocolName)
153166
#define SWIFT_COMPUTED_PROPERTY
154-
#define SWIFT_MUTATING
167+
#define SWIFT_MUTATING
168+
#define SWIFT_UNCHECKED_SENDABLE
155169

156170
#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
157171

test/Interop/Cxx/ergonomics/swift-bridging-annotations.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class SWIFT_CONFORMS_TO_PROTOCOL(SwiftMod.Proto) ConformsTo {
8080
public:
8181
};
8282

83+
class SWIFT_UNCHECKED_SENDABLE UnsafeSendable {
84+
public:
85+
};
86+
8387

8488
// CHECK: struct SelfContained {
8589

@@ -101,3 +105,4 @@ public:
101105

102106
// CHECK: struct ConformsTo : Proto {
103107

108+
// CHECK: struct UnsafeSendable : @unchecked Sendable {

0 commit comments

Comments
 (0)