Skip to content

Commit 210a3e0

Browse files
committed
[Concurrency] lower availability reqs of addTask apis with names
1 parent e94adde commit 210a3e0

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

stdlib/public/Concurrency/TaskGroup+addTask.swift.gyb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Swift
3131
% 'ThrowingDiscardingTaskGroup'
3232
% ],
3333
% [
34-
% '@available(SwiftStdlib 6.2, *)',
34+
% '@available(SwiftStdlib 6.0, *)', # because task executor
3535
% '@_unavailableInEmbedded', # since TaskExecutor is not available on embedded
3636
% ],
3737
% ['addTask', 'addTaskUnlessCancelled'],
@@ -43,6 +43,26 @@ import Swift
4343
% 'operation: sending @escaping @isolated(any) () async throws -> ChildTaskResult'
4444
% ],
4545
% ),
46+
% (
47+
% '', # no #if condition
48+
% [
49+
% 'TaskGroup',
50+
% 'ThrowingTaskGroup',
51+
% 'DiscardingTaskGroup',
52+
% 'ThrowingDiscardingTaskGroup'
53+
% ],
54+
% [
55+
% # use availability of task group we're declaring within since decl is @AEIC
56+
% '@_unavailableInEmbedded', # since TaskExecutor is not available on embedded
57+
% ],
58+
% ['addTask', 'addTaskUnlessCancelled'],
59+
% [
60+
% 'name: String?',
61+
% 'priority: TaskPriority? = nil',
62+
% # throws and ChildTaskResult will be adjusted per task group type
63+
% 'operation: sending @escaping @isolated(any) () async throws -> ChildTaskResult'
64+
% ],
65+
% ),
4666
% # -----------------------------------------------------------------------
4767
% # === Added TaskExecutor
4868
% (
@@ -266,7 +286,9 @@ extension ${TYPE} {
266286
flags: flags,
267287
initialSerialExecutor: builtinSerialExecutor,
268288
taskGroup: _group,
289+
% if HAS_TASK_EXECUTOR:
269290
initialTaskExecutorConsuming: taskExecutor,
291+
% end
270292
taskName: nameBytes.baseAddress!._rawValue,
271293
operation: operation).0
272294
}
@@ -282,7 +304,9 @@ extension ${TYPE} {
282304
flags: flags,
283305
initialSerialExecutor: builtinSerialExecutor,
284306
taskGroup: _group,
307+
% if HAS_TASK_EXECUTOR:
285308
initialTaskExecutorConsuming: taskExecutor,
309+
% end
286310
operation: operation).0
287311
#else
288312
// legacy branch for the non-consuming task executor
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify -o /dev/null -verify %s
2+
3+
4+
5+
struct Boom: Error {}
6+
7+
@available(SwiftStdlib 6.2, *)
8+
func testName() {
9+
_ = Task.name
10+
}
11+
12+
@available(SwiftStdlib 6.0, *)
13+
func taskExecutor() async {
14+
Task(name: "name", executorPreference: nil) { }
15+
Task(name: "name", executorPreference: nil) { throw Boom() }
16+
17+
Task.detached(name: "name", executorPreference: nil) { throw Boom() }
18+
19+
await withTaskGroup(of: Void.self) { group in
20+
group.addTask(name: "name", executorPreference: nil) {
21+
()
22+
}
23+
}
24+
await withThrowingTaskGroup(of: Void.self) { group in
25+
group.addTask(name: "name", executorPreference: nil) {
26+
()
27+
}
28+
}
29+
30+
await withDiscardingTaskGroup { group in
31+
group.addTask(name: "name", executorPreference: nil) {
32+
()
33+
}
34+
}
35+
try! await withThrowingDiscardingTaskGroup { group in
36+
group.addTask(name: "name", executorPreference: nil) {
37+
()
38+
}
39+
}
40+
}
41+
42+
@available(SwiftStdlib 5.1, *)
43+
func backDeployedNames() async {
44+
Task(name: "name") { }
45+
Task(name: "name") { throw Boom() }
46+
47+
Task.detached(name: "name") { }
48+
Task.detached(name: "name") { throw Boom() }
49+
50+
await withTaskGroup(of: Void.self) { group in
51+
group.addTask(name: "name") {
52+
()
53+
}
54+
}
55+
await withThrowingTaskGroup(of: Void.self) { group in
56+
group.addTask(name: "name") {
57+
()
58+
}
59+
}
60+
}
61+
62+
@available(SwiftStdlib 5.9, *)
63+
func backDeployedDiscarding() async {
64+
await withDiscardingTaskGroup { group in
65+
group.addTask(name: "name") {
66+
()
67+
}
68+
}
69+
try! await withThrowingDiscardingTaskGroup { group in
70+
group.addTask(name: "name") {
71+
()
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)