Skip to content

Bring back TaskGroup.next() and ThrowingTaskGroup.next() as public API #73425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions stdlib/public/Concurrency/TaskGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,9 @@ public struct TaskGroup<ChildTaskResult: Sendable> {
return try! await _taskGroupWaitNext(group: _group) // !-safe cannot throw, we're a non-throwing TaskGroup
}

@usableFromInline
@available(SwiftStdlib 5.1, *)
@_silgen_name("$sScG4nextxSgyYaF")
internal mutating func __abi_next() async -> ChildTaskResult? {
@_disfavoredOverload
public mutating func next() async -> ChildTaskResult? {
// try!-safe because this function only exists for Failure == Never,
// and as such, it is impossible to spawn a throwing child task.
return try! await _taskGroupWaitNext(group: _group) // !-safe cannot throw, we're a non-throwing TaskGroup
Expand Down Expand Up @@ -1035,10 +1034,9 @@ public struct ThrowingTaskGroup<ChildTaskResult: Sendable, Failure: Error> {
return try await _taskGroupWaitNext(group: _group)
}

@usableFromInline
@available(SwiftStdlib 5.1, *)
@_silgen_name("$sScg4nextxSgyYaKF")
internal mutating func __abi_next() async throws -> ChildTaskResult? {
@_disfavoredOverload
public mutating func next() async throws -> ChildTaskResult? {
return try await _taskGroupWaitNext(group: _group)
}

Expand Down
22 changes: 22 additions & 0 deletions test/Concurrency/async_task_groups_as_sequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-swift-frontend -disable-availability-checking %s -emit-sil -o /dev/null -verify
// RUN: %target-swift-frontend -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted
// RUN: %target-swift-frontend -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete
// RUN: %target-swift-frontend -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation

// REQUIRES: concurrency
// REQUIRES: asserts
// REQUIRES: libdispatch

@available(SwiftStdlib 5.1, *)
@rethrows
protocol TGP: AsyncSequence, AsyncIteratorProtocol { }

@available(SwiftStdlib 5.1, *)
extension TaskGroup: TGP { }
// expected-warning@-1{{extension declares a conformance of imported type 'TaskGroup' to imported protocol 'AsyncIteratorProtocol'}}
// expected-note@-2{{add '@retroactive' to silence this warning}}

@available(SwiftStdlib 5.1, *)
extension ThrowingTaskGroup: TGP { }
// expected-warning@-1{{extension declares a conformance of imported type 'ThrowingTaskGroup' to imported protocol 'AsyncIteratorProtocol'}}
// expected-note@-2{{add '@retroactive' to silence this warning}}
8 changes: 0 additions & 8 deletions test/api-digester/stability-concurrency-abi.test
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ Func TaskLocal.withValue(_:operation:file:line:) has parameter 1 type change fro
Func TaskLocal.withValue(_:operation:file:line:) has parameter 2 type change from Swift.String to (any _Concurrency.Actor)?
Func TaskLocal.withValue(_:operation:file:line:) has parameter 3 type change from Swift.UInt to Swift.String

// The method is actually still there: '__abi_next' silgen_name("$sScG4nextxSgyYaF")
Func TaskGroup.next() has been renamed to Func next(isolation:)
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>'

// The method is actually still there: '__abi_next' silgen_name("$sScg4nextxSgyYaKF")
Func ThrowingTaskGroup.next() has been renamed to Func next(isolation:)
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>'

// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment above.)


Expand Down