Skip to content

Commit 4ca8a66

Browse files
authored
Merge pull request swiftlang#36590 from jckarter/task-cancellation-handler-abi
Fix calling convention for withCompletionHandler runtime calls.
2 parents 5565a76 + 4150b31 commit 4ca8a66

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

include/swift/ABI/TaskStatus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
254254
/// subsequently used.
255255
class CancellationNotificationStatusRecord : public TaskStatusRecord {
256256
public:
257-
using FunctionType = void (void *);
257+
using FunctionType = SWIFT_CC(swift) void (SWIFT_CONTEXT void *);
258258

259259
private:
260260
FunctionType * __ptrauth_swift_cancellation_notification_function Function;

include/swift/Runtime/Concurrency.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ bool swift_task_isCancelled(AsyncTask* task);
338338
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
339339
CancellationNotificationStatusRecord*
340340
swift_task_addCancellationHandler(
341-
CancellationNotificationStatusRecord::FunctionType handler);
341+
CancellationNotificationStatusRecord::FunctionType handler,
342+
void *handlerContext);
342343

343344
/// Remove the passed cancellation record from the task.
344345
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ OVERRIDE_TASK(continuation_throwingResumeWithError, void,
132132
OVERRIDE_TASK(task_addCancellationHandler,
133133
CancellationNotificationStatusRecord *,
134134
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,
135-
(CancellationNotificationStatusRecord::FunctionType handler),
136-
(handler))
135+
(CancellationNotificationStatusRecord::FunctionType handler,
136+
void *context),
137+
(handler, context))
137138

138139
OVERRIDE_TASK(task_removeCancellationHandler, void,
139140
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift), swift::,

stdlib/public/Concurrency/Task.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,13 @@ bool swift::swift_task_isCancelled(AsyncTask *task) {
789789
SWIFT_CC(swift)
790790
static CancellationNotificationStatusRecord*
791791
swift_task_addCancellationHandlerImpl(
792-
CancellationNotificationStatusRecord::FunctionType handler) {
792+
CancellationNotificationStatusRecord::FunctionType handler,
793+
void *context) {
793794
void *allocation =
794795
swift_task_alloc(sizeof(CancellationNotificationStatusRecord));
795796
auto *record =
796797
new (allocation) CancellationNotificationStatusRecord(
797-
handler, /*arg=*/nullptr);
798+
handler, context);
798799

799800
swift_task_addStatusRecord(record);
800801
return record;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch)
2+
3+
class Canary {
4+
deinit {
5+
print("canary died")
6+
}
7+
}
8+
9+
do {
10+
let task = Task.runDetached {
11+
let canary = Canary()
12+
_ = await Task.withCancellationHandler {
13+
print(canary)
14+
} operation: {
15+
await Task.sleep(1_000_000)
16+
}
17+
}
18+
task.cancel()
19+
}
20+
// CHECK: Canary
21+
// CHECK-NEXT: canary died

0 commit comments

Comments
 (0)