Skip to content

Commit e37b998

Browse files
committed
implement simple rethrowing logic, however body throw always wins
1 parent 2eaaf35 commit e37b998

File tree

7 files changed

+251
-43
lines changed

7 files changed

+251
-43
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ bool swift_taskGroup_isDiscardingResults(TaskGroup *group);
307307
/// \code
308308
/// func swift_taskGroup_waitAll(
309309
/// waitingTask: Builtin.NativeObject, // current task
310-
/// group: Builtin.RawPointer
310+
/// group: Builtin.RawPointer,
311+
/// bodyError: Swift.Error?
311312
/// ) async throws
312313
/// \endcode
313314
SWIFT_EXPORT_FROM(swift_Concurrency)
@@ -316,6 +317,7 @@ bool swift_taskGroup_isDiscardingResults(TaskGroup *group);
316317
OpaqueValue *resultPointer,
317318
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
318319
TaskGroup *group,
320+
SwiftError *bodyError,
319321
ThrowingTaskFutureWaitContinuationFunction *resumeFn,
320322
AsyncContext *callContext);
321323

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,10 @@ OVERRIDE_TASK_GROUP(taskGroup_waitAll, void,
326326
(OpaqueValue *resultPointer,
327327
SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
328328
TaskGroup *_group,
329+
SwiftError *bodyError,
329330
ThrowingTaskFutureWaitContinuationFunction *resumeFn,
330331
AsyncContext *callContext),
331-
(resultPointer, callerContext, _group,
332+
(resultPointer, callerContext, _group, bodyError,
332333
resumeFn, callContext))
333334

334335
OVERRIDE_TASK_LOCAL(task_reportIllegalTaskLocalBindingWithinWithTaskGroup, void,

stdlib/public/Concurrency/DiscardingTaskGroup.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public struct DiscardingTaskGroup {
154154
/// - Throws: The first error that was encountered by this group.
155155
@usableFromInline
156156
internal mutating func awaitAllRemainingTasks() async throws {
157-
let _: Void? = try await _taskGroupWaitAll(group: _group)
157+
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: nil)
158158
}
159159

160160
@_alwaysEmitIntoClient
@@ -393,12 +393,12 @@ public func withThrowingDiscardingTaskGroup<GroupResult>(
393393
} catch {
394394
group.cancelAll()
395395

396-
try await group.awaitAllRemainingTasks()
396+
try await group.awaitAllRemainingTasks(bodyError: error)
397397

398398
throw error
399399
}
400400

401-
try await group.awaitAllRemainingTasks()
401+
try await group.awaitAllRemainingTasks(bodyError: nil)
402402

403403
return result
404404
#else
@@ -466,8 +466,8 @@ public struct ThrowingDiscardingTaskGroup<Failure: Error> {
466466

467467
/// Await all the remaining tasks on this group.
468468
@usableFromInline
469-
internal mutating func awaitAllRemainingTasks() async throws {
470-
let _: Void? = try await _taskGroupWaitAll(group: _group)
469+
internal mutating func awaitAllRemainingTasks(bodyError: Error?) async throws {
470+
let _: Void? = try await _taskGroupWaitAll(group: _group, bodyError: bodyError)
471471
}
472472

473473
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@@ -549,7 +549,8 @@ extension ThrowingDiscardingTaskGroup: Sendable { }
549549
@discardableResult
550550
@_silgen_name("swift_taskGroup_waitAll")
551551
func _taskGroupWaitAll<T>(
552-
group: Builtin.RawPointer
552+
group: Builtin.RawPointer,
553+
bodyError: Error?
553554
) async throws -> T?
554555

555556
@available(SwiftStdlib 5.8, *) // FIXME: remove

0 commit comments

Comments
 (0)