mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
**Description**: This adds "task name" parameter to all task creating functions. This is done in a few ways, e.g. we can backdeploy this to 5.1 in APIs which do not accept the `TaskExecutor` but it they do we provide a version for 6.0+ etc. This was requested in the SE acceptable of this proposal [Acceptance post SE-0469](https://forums.swift.org/t/accepted-with-modifications-se-0469-task-naming/79438). This moves all these declarations to gyb since going through them one by one has become unmaintainable otherwise. **Scope/Impact**: All task creation APIs now gain a new task name parameter. **Risk:** Medium, changes existing APIs rather than adding "even more overloads" though this risk was discussed in the team and accepted. This has a potential to be source breaking it someone used Task.init and friends as function. **Testing**: CI testing, source compatibility suite testing **Reviewed by**: **Original PR:** - https://github.com/swiftlang/swift/pull/81107 build changes required for this - https://github.com/swiftlang/swift/pull/80984 **Radar:** --------- Co-authored-by: Kuba Mracek <mracek@apple.com>
74 lines
1.6 KiB
Swift
74 lines
1.6 KiB
Swift
// RUN: %target-swift-frontend -emit-sil -verify -o /dev/null -verify %s
|
|
|
|
struct Boom: Error {}
|
|
|
|
@available(SwiftStdlib 6.2, *)
|
|
func testName() {
|
|
_ = Task.name
|
|
}
|
|
|
|
@available(SwiftStdlib 6.0, *)
|
|
func taskExecutor() async {
|
|
Task(name: "name", executorPreference: nil) { }
|
|
Task(name: "name", executorPreference: nil) { throw Boom() }
|
|
|
|
Task.detached(name: "name", executorPreference: nil) { throw Boom() }
|
|
|
|
await withTaskGroup(of: Void.self) { group in
|
|
group.addTask(name: "name", executorPreference: nil) {
|
|
()
|
|
}
|
|
}
|
|
await withThrowingTaskGroup(of: Void.self) { group in
|
|
group.addTask(name: "name", executorPreference: nil) {
|
|
()
|
|
}
|
|
}
|
|
|
|
await withDiscardingTaskGroup { group in
|
|
group.addTask(name: "name", executorPreference: nil) {
|
|
()
|
|
}
|
|
}
|
|
try! await withThrowingDiscardingTaskGroup { group in
|
|
group.addTask(name: "name", executorPreference: nil) {
|
|
()
|
|
}
|
|
}
|
|
}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
func backDeployedNames() async {
|
|
Task(name: "name") { }
|
|
Task(name: "name") { throw Boom() }
|
|
|
|
Task.detached(name: "name") { }
|
|
Task.detached(name: "name") { throw Boom() }
|
|
|
|
await withTaskGroup(of: Void.self) { group in
|
|
group.addTask(name: "name") {
|
|
()
|
|
}
|
|
}
|
|
await withThrowingTaskGroup(of: Void.self) { group in
|
|
group.addTask(name: "name") {
|
|
()
|
|
}
|
|
}
|
|
}
|
|
|
|
@available(SwiftStdlib 5.9, *)
|
|
func backDeployedDiscarding() async {
|
|
await withDiscardingTaskGroup { group in
|
|
group.addTask(name: "name") {
|
|
()
|
|
}
|
|
}
|
|
try! await withThrowingDiscardingTaskGroup { group in
|
|
group.addTask(name: "name") {
|
|
()
|
|
}
|
|
}
|
|
}
|
|
|