Skip to content

Commit e8a61b9

Browse files
committed
futher ABI safeguarding
1 parent 64473f6 commit e8a61b9

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,16 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
566566
/// that method can't be called from a concurrent execution context like a child task.
567567
///
568568
/// - Returns: The value returned by the next child task that completes.
569+
@available(SwiftStdlib 5.1, *)
570+
@backDeployed(before: SwiftStdlib 6.0)
569571
public mutating func next(isolation: isolated (any Actor)? = #isolation) async -> ChildTaskResult? {
570572
// try!-safe because this function only exists for Failure == Never,
571573
// and as such, it is impossible to spawn a throwing child task.
572574
return try! await _taskGroupWaitNext(group: _group) // !-safe cannot throw, we're a non-throwing TaskGroup
573575
}
574576

575577
@usableFromInline
578+
@available(SwiftStdlib 5.1, *)
576579
@_silgen_name("$sScG4nextxSgyYaF")
577580
internal mutating func __abi_next() async -> ChildTaskResult? {
578581
// try!-safe because this function only exists for Failure == Never,
@@ -582,12 +585,16 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
582585

583586
/// Await all of the pending tasks added this group.
584587
@usableFromInline
588+
@available(SwiftStdlib 5.1, *)
589+
@backDeployed(before: SwiftStdlib 6.0)
585590
internal mutating func awaitAllRemainingTasks(isolation: isolated (any Actor)? = #isolation) async {
586591
while let _ = await next(isolation: isolation) {}
587592
}
593+
588594
@usableFromInline
595+
@available(SwiftStdlib 5.1, *)
589596
@_silgen_name("$sScG22awaitAllRemainingTasksyyYaF")
590-
internal mutating func __abi_awaitAllRemainingTasks() async {
597+
internal mutating func awaitAllRemainingTasks() async {
591598
while let _ = await next(isolation: nil) {}
592599
}
593600

@@ -719,6 +726,8 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
719726

720727
/// Await all the remaining tasks on this group.
721728
@usableFromInline
729+
@available(SwiftStdlib 5.1, *)
730+
@backDeployed(before: SwiftStdlib 6.0)
722731
internal mutating func awaitAllRemainingTasks(isolation: isolated (any Actor)? = #isolation) async {
723732
while true {
724733
do {
@@ -728,7 +737,9 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
728737
} catch {}
729738
}
730739
}
740+
731741
@usableFromInline
742+
@available(SwiftStdlib 5.1, *)
732743
internal mutating func awaitAllRemainingTasks() async {
733744
await awaitAllRemainingTasks(isolation: nil)
734745
}
@@ -1019,16 +1030,33 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
10191030
/// - Throws: The error thrown by the next child task that completes.
10201031
///
10211032
/// - SeeAlso: `nextResult()`
1033+
@available(SwiftStdlib 5.1, *)
1034+
@backDeployed(before: SwiftStdlib 6.0)
10221035
public mutating func next(isolation: isolated (any Actor)? = #isolation) async throws -> ChildTaskResult? {
10231036
return try await _taskGroupWaitNext(group: _group)
10241037
}
10251038

10261039
@usableFromInline
1040+
@available(SwiftStdlib 5.1, *)
10271041
@_silgen_name("$sScg4nextxSgyYaKF")
10281042
internal mutating func __abi_next() async throws -> ChildTaskResult? {
10291043
return try await _taskGroupWaitNext(group: _group)
10301044
}
10311045

1046+
@_silgen_name("$sScg10nextResults0B0Oyxq_GSgyYaKF")
1047+
@usableFromInline
1048+
mutating func nextResultForABI() async throws -> Result<ChildTaskResult, Failure>? {
1049+
do {
1050+
guard let success: ChildTaskResult = try await _taskGroupWaitNext(group: _group) else {
1051+
return nil
1052+
}
1053+
1054+
return .success(success)
1055+
} catch {
1056+
return .failure(error as! Failure) // as!-safe, because we are only allowed to throw Failure (Error)
1057+
}
1058+
}
1059+
10321060
/// Wait for the next child task to complete,
10331061
/// and return a result containing either
10341062
/// the value that the child task returned or the error that it threw.
@@ -1065,22 +1093,9 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
10651093
/// - SeeAlso: `next()`
10661094
@_alwaysEmitIntoClient
10671095
public mutating func nextResult(isolation: isolated (any Actor)? = #isolation) async -> Result<ChildTaskResult, Failure>? {
1068-
return try! await __abi_nextResult()
1096+
return try! await nextResultForABI()
10691097
}
10701098

1071-
@_silgen_name("$sScg10nextResults0B0Oyxq_GSgyYaKF")
1072-
@usableFromInline
1073-
mutating func __abi_nextResult() async throws -> Result<ChildTaskResult, Failure>? {
1074-
do {
1075-
guard let success: ChildTaskResult = try await _taskGroupWaitNext(group: _group) else {
1076-
return nil
1077-
}
1078-
1079-
return .success(success)
1080-
} catch {
1081-
return .failure(error as! Failure) // as!-safe, because we are only allowed to throw Failure (Error)
1082-
}
1083-
}
10841099
/// A Boolean value that indicates whether the group has any remaining tasks.
10851100
///
10861101
/// At the start of the body of a `withThrowingTaskGroup(of:returning:body:)` call,
@@ -1357,7 +1372,7 @@ func _taskGroupIsCancelled(group: Builtin.RawPointer) -> Bool
13571372

13581373
@available(SwiftStdlib 5.1, *)
13591374
@_silgen_name("swift_taskGroup_wait_next_throwing")
1360-
func _taskGroupWaitNext<T>(group: Builtin.RawPointer) async throws -> T?
1375+
public func _taskGroupWaitNext<T>(group: Builtin.RawPointer) async throws -> T?
13611376

13621377
@available(SwiftStdlib 5.1, *)
13631378
@_silgen_name("swift_task_hasTaskGroupStatusRecord")

test/api-digester/stability-concurrency-abi.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ Func Executor.enqueue(_:) is a new API without @available attribute
9090
// This function correctly inherits its availability from the TaskLocal struct.
9191
Func TaskLocal.withValueImpl(_:operation:file:line:) is a new API without @available attribute
9292

93+
// The method is actually still there: '__abi_next' silgen_name("$sScG4nextxSgyYaF")
94+
Func TaskGroup.next() has been renamed to Func next(isolation:)
95+
Func TaskGroup.next() has mangled name changing from 'Swift.TaskGroup.next() async -> Swift.Optional<A>' to 'Swift.TaskGroup.next(isolation: isolated Swift.Optional<Swift.Actor>) async -> Swift.Optional<A>'
96+
97+
// The method is actually still there: '__abi_next' silgen_name("$sScg4nextxSgyYaKF")
98+
Func ThrowingTaskGroup.next() has been renamed to Func next(isolation:)
99+
Func ThrowingTaskGroup.next() has mangled name changing from 'Swift.ThrowingTaskGroup.next() async throws -> Swift.Optional<A>' to 'Swift.ThrowingTaskGroup.next(isolation: isolated Swift.Optional<Swift.Actor>) async throws -> Swift.Optional<A>'
100+
93101
// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment above.)
94102

95103

0 commit comments

Comments
 (0)