Skip to content

Commit 1f1f703

Browse files
committed
Drop @Concurrent from parameter to @asyncHandler entry point.
The async handler code doesn't really run concurrently with where it is launched, despite the implementation currently using `runDetached` internally. Drop the @Concurrent and bitcase it back on when needed.
1 parent f4c5a26 commit 1f1f703

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ extension Task {
281281

282282
}
283283

284-
public func _runAsyncHandler(operation: @concurrent @escaping () async -> ()) {
285-
_ = Task.runDetached(operation: operation)
284+
public func _runAsyncHandler(operation: @escaping () async -> ()) {
285+
typealias ConcurrentFunctionType = @concurrent () async -> ()
286+
_ = Task.runDetached(
287+
operation: unsafeBitCast(operation, to: ConcurrentFunctionType.self)
288+
)
286289
}
287290

288291
// ==== Voluntary Suspension -----------------------------------------------------

test/SILGen/async_handler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func take<T>(_ t: T) async {
88
// CHECK-LABEL: sil [ossa] @$s4test13simpleHandleryySiF : $@convention(thin) (Int) -> () {
99
// CHECK: [[BODYFN:%[0-9]+]] = function_ref @$s4test13simpleHandleryySiYF : $@convention(thin) @async (Int) -> ()
1010
// CHECK: [[FN:%[0-9]+]] = partial_apply [callee_guaranteed] [[BODYFN]](%0) : $@convention(thin) @async (Int) -> ()
11-
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
11+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
1212
// CHECK: {{.*}} = apply [[INTRINSIC]]([[FN]]) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
1313
// CHECK: destroy_value [[FN]] : $@async @callee_guaranteed () -> ()
1414
// CHECK: } // end sil function '$s4test13simpleHandleryySiF'
@@ -21,7 +21,7 @@ public func simpleHandler(_ i: Int) {
2121
// CHECK: [[COPY:%[0-9]+]] = copy_value %0 : $String
2222
// CHECK: [[BODYFN:%[0-9]+]] = function_ref @$s4test20nonTrivialArgHandleryySSYF : $@convention(thin) @async (@guaranteed String) -> ()
2323
// CHECK: [[FN:%[0-9]+]] = partial_apply [callee_guaranteed] [[BODYFN]]([[COPY]]) : $@convention(thin) @async (@guaranteed String) -> ()
24-
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
24+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
2525
// CHECK: {{.*}} = apply [[INTRINSIC]]([[FN]]) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
2626
// CHECK: destroy_value [[FN]] : $@async @callee_guaranteed () -> ()
2727
// CHECK: } // end sil function '$s4test20nonTrivialArgHandleryySSF'
@@ -35,7 +35,7 @@ public func nonTrivialArgHandler(_ s: String) {
3535
// CHECK: copy_addr %0 to [initialization] [[TMP]] : $*T
3636
// CHECK: [[BODYFN:%[0-9]+]] = function_ref @$s4test14genericHandleryyxYlF : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
3737
// CHECK: [[FN:%[0-9]+]] = partial_apply [callee_guaranteed] [[BODYFN]]<T>([[TMP]]) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
38-
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
38+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
3939
// CHECK: {{.*}} = apply [[INTRINSIC]]([[FN]]) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
4040
// CHECK: destroy_value [[FN]] : $@async @callee_guaranteed () -> ()
4141
// CHECK: } // end sil function '$s4test14genericHandleryyxlF'
@@ -48,7 +48,7 @@ public struct Mystruct {
4848
// CHECK-LABEL: sil [ossa] @$s4test8MystructV13memberHandleryySiF : $@convention(method) (Int, Mystruct) -> () {
4949
// CHECK: [[BODYFN:%[0-9]+]] = function_ref @$s4test8MystructV13memberHandleryySiYF : $@convention(method) @async (Int, Mystruct) -> ()
5050
// CHECK: [[FN:%[0-9]+]] = partial_apply [callee_guaranteed] [[BODYFN]](%0, %1) : $@convention(method) @async (Int, Mystruct) -> ()
51-
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
51+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
5252
// CHECK: {{.*}} = apply [[INTRINSIC]]([[FN]]) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
5353
// CHECK: destroy_value [[FN]] : $@async @callee_guaranteed () -> ()
5454
// CHECK: } // end sil function '$s4test8MystructV13memberHandleryySiF'

0 commit comments

Comments
 (0)