Skip to content

Commit 53407f5

Browse files
committed
Mark asynchronous blocks in Csourcekitd as Sendable
We don’t have any guarantees which thread these blocks will be called on by sourcekitd, so we shouldn’t make any assumptions about it in Swift. We should thus mark them as Sendable.
1 parent 5882eae commit 53407f5

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

Sources/Csourcekitd/include/plugin.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ typedef const void *_Null_unspecified (*sourcekitd_api_variant_functions_data_ge
114114
typedef bool (^sourcekitd_api_cancellable_request_handler_t)(
115115
_Null_unspecified sourcekitd_api_object_t,
116116
_Null_unspecified sourcekitd_api_request_handle_t,
117-
void (^_Null_unspecified __attribute__((swift_attr("@Sendable"))))(_Null_unspecified sourcekitd_api_response_t)
117+
void (^_Null_unspecified SWIFT_SENDABLE)(_Null_unspecified sourcekitd_api_response_t)
118118
);
119119
typedef void (^sourcekitd_api_cancellation_handler_t)(_Null_unspecified sourcekitd_api_request_handle_t);
120120
typedef _Null_unspecified sourcekitd_api_uid_t (*sourcekitd_api_uid_get_from_cstr_t)(const char *_Null_unspecified string);
@@ -233,11 +233,11 @@ typedef struct {
233233
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
234234
);
235235

236-
_Null_unspecified sourcekitd_api_uid_get_from_cstr_t (*_Nonnull plugin_initialize_uid_get_from_cstr)(
236+
_Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_from_cstr_t (*_Nonnull plugin_initialize_uid_get_from_cstr)(
237237
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
238238
);
239239

240-
_Null_unspecified sourcekitd_api_uid_get_string_ptr_t (*_Nonnull plugin_initialize_uid_get_string_ptr)(
240+
_Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_string_ptr_t (*_Nonnull plugin_initialize_uid_get_string_ptr)(
241241
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
242242
);
243243

@@ -251,7 +251,7 @@ typedef struct {
251251
typedef struct {
252252
void (*_Nonnull plugin_initialize_register_cancellable_request_handler)(
253253
_Nonnull sourcekitd_api_plugin_initialize_params_t,
254-
_Nonnull sourcekitd_api_cancellable_request_handler_t
254+
_Nonnull SWIFT_SENDABLE sourcekitd_api_cancellable_request_handler_t
255255
);
256256

257257
/// Adds a function that will be called when a request is cancelled.
@@ -260,7 +260,7 @@ typedef struct {
260260
/// handle to be cancelled, it should ignore the cancellation request.
261261
void (*_Nonnull plugin_initialize_register_cancellation_handler)(
262262
_Nonnull sourcekitd_api_plugin_initialize_params_t,
263-
_Nonnull sourcekitd_api_cancellation_handler_t
263+
_Nonnull SWIFT_SENDABLE sourcekitd_api_cancellation_handler_t
264264
);
265265

266266
void *_Null_unspecified(*_Nonnull plugin_initialize_get_swift_ide_inspection_instance)(

Sources/Csourcekitd/include/sourcekitd_functions.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <stddef.h>
1818
#include <stdint.h>
1919

20+
#define SWIFT_SENDABLE __attribute__((__swift_attr__("@Sendable")))
21+
2022
// Avoid including <sourcekitd/sourcekitd.h> to make sure we don't call the
2123
// functions directly. But we need the types to form the function pointers.
2224
// These are supposed to stay stable across toolchains.
@@ -315,17 +317,17 @@ typedef struct {
315317
void (*_Nonnull send_request)(
316318
sourcekitd_api_object_t _Nonnull req,
317319
_Nullable sourcekitd_api_request_handle_t *_Nullable out_handle,
318-
_Nullable sourcekitd_api_response_receiver_t receiver
320+
_Nullable SWIFT_SENDABLE sourcekitd_api_response_receiver_t receiver
319321
);
320322
void (*_Nonnull cancel_request)(
321323
_Nullable sourcekitd_api_request_handle_t handle
322324
);
323325
void (*_Nonnull set_notification_handler)(
324-
_Nullable sourcekitd_api_response_receiver_t receiver
326+
_Nullable SWIFT_SENDABLE sourcekitd_api_response_receiver_t receiver
325327
);
326328
void (*_Nonnull set_uid_handlers)(
327-
_Nullable sourcekitd_api_uid_from_str_handler_t uid_from_str,
328-
_Nullable sourcekitd_api_str_from_uid_handler_t str_from_uid
329+
_Nullable SWIFT_SENDABLE sourcekitd_api_uid_from_str_handler_t uid_from_str,
330+
_Nullable SWIFT_SENDABLE sourcekitd_api_str_from_uid_handler_t str_from_uid
329331
);
330332
} sourcekitd_api_functions_t;
331333

Sources/SourceKitD/SourceKitD.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ package actor SourceKitD {
103103
package let path: URL
104104

105105
/// The handle to the dylib.
106-
let dylib: DLHandle
106+
private let dylib: DLHandle
107107

108108
/// The sourcekitd API functions.
109109
nonisolated package let api: sourcekitd_api_functions_t

0 commit comments

Comments
 (0)