Skip to content

Commit 9efb44f

Browse files
committed
Adopt @Concurrent in Task APIs
1 parent 6d086d4 commit 9efb44f

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ extension Task {
262262
/// throw the error the operation has thrown when awaited on.
263263
public static func runDetached<T>(
264264
priority: Priority = .default,
265-
operation: @escaping () async throws -> T
265+
operation: @concurrent @escaping () async throws -> T
266266
) -> Handle<T> {
267267
// Set up the job flags for a new task.
268268
var flags = JobFlags()
@@ -281,7 +281,7 @@ extension Task {
281281

282282
}
283283

284-
public func _runAsyncHandler(operation: @escaping () async -> ()) {
284+
public func _runAsyncHandler(operation: @concurrent @escaping () async -> ()) {
285285
_ = Task.runDetached(operation: operation)
286286
}
287287

@@ -368,7 +368,7 @@ public func _taskFutureGetThrowing<T>(
368368
}
369369

370370
public func _runChildTask<T>(
371-
operation: @escaping () async throws -> T
371+
operation: @concurrent @escaping () async throws -> T
372372
) async -> Builtin.NativeObject {
373373
let currentTask = Builtin.getCurrentAsyncTask()
374374

@@ -391,7 +391,7 @@ public func _runChildTask<T>(
391391

392392
public func _runGroupChildTask<T>(
393393
overridingPriority priorityOverride: Task.Priority? = nil,
394-
operation: @escaping () async throws -> T
394+
operation: @concurrent @escaping () async throws -> T
395395
) async -> Builtin.NativeObject {
396396
let currentTask = Builtin.getCurrentAsyncTask()
397397

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extension Task {
6363
public static func withGroup<TaskResult, BodyResult>(
6464
resultType: TaskResult.Type,
6565
returning returnType: BodyResult.Type = BodyResult.self,
66-
body: @escaping ((inout Task.Group<TaskResult>) async throws -> BodyResult)
66+
body: @concurrent @escaping (inout Task.Group<TaskResult>) async throws -> BodyResult
6767
) async throws -> BodyResult {
6868
let parent = Builtin.getCurrentAsyncTask()
6969

@@ -134,7 +134,7 @@ extension Task {
134134
@discardableResult
135135
public mutating func add(
136136
overridingPriority priorityOverride: Priority? = nil,
137-
operation: @escaping () async throws -> TaskResult
137+
operation: @concurrent @escaping () async throws -> TaskResult
138138
) async -> Task.Handle<TaskResult> {
139139
// Increment the number of pending tasks immediately;
140140
// We don't need to know which specific task is pending, just that pending

test/Concurrency/Runtime/mainactor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ actor class A {
7474
exitTest(success: ok)
7575
}
7676

77-
func someFunc() async {
77+
@concurrent func someFunc() async {
7878
guard checkIfMainQueue(expectedAnswer: false) else {
7979
print("ERROR: did not expect detatched task to run on main queue!")
8080
exit(EXIT_FAILURE)

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_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
11+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_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_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
24+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_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_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
38+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_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_runAsyncHandler9operationyyyYc_tF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> ()) -> ()
51+
// CHECK: [[INTRINSIC:%[0-9]+]] = function_ref @$s12_Concurrency16_runAsyncHandler9operationyyyYJc_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'

test/SILGen/async_let.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func testAsyncLetInt() async -> Int {
2121
// CHECK: [[REABSTRACT_THUNK:%.*]] = function_ref @$sSiIegHd_Sis5Error_pIegHrzo_TR : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> Int) -> (@out Int, @error Error)
2222
// CHECK: [[REABSTRACT_CLOSURE:%.*]] = partial_apply [callee_guaranteed] [[REABSTRACT_THUNK]]([[THICK_CLOSURE]]) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> Int) -> (@out Int, @error Error)
2323
// CHECK: [[CLOSURE_ARG:%.*]] = convert_function [[REABSTRACT_CLOSURE]] : $@async @callee_guaranteed () -> (@out Int, @error Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <Int>
24-
// CHECK: [[RUN_CHILD_TASK:%.*]] = function_ref @$s12_Concurrency13_runChildTask9operationBoxyYKc_tYlF : $@convention(thin) @async <τ_0_0> (@guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <τ_0_0>) -> @owned Builtin.NativeObject
24+
// CHECK: [[RUN_CHILD_TASK:%.*]] = function_ref @$s12_Concurrency13_runChildTask9operationBoxyYJKc_tYlF : $@convention(thin) @async <τ_0_0> (@guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <τ_0_0>) -> @owned Builtin.NativeObject
2525
// CHECK: [[CHILD_TASK:%.*]] = apply [[RUN_CHILD_TASK]]<Int>([[CLOSURE_ARG]]) : $@convention(thin) @async <τ_0_0> (@guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <τ_0_0>) -> @owned Builtin.NativeObject
2626
async let i = await getInt()
2727

0 commit comments

Comments
 (0)