DiscardingTaskGroup now shares some implementation with "Accumulating" TaskGroup

This commit is contained in:
Konrad `ktoso` Malawski
2023-01-07 12:11:10 +09:00
parent e37b998c56
commit 6f38910058
9 changed files with 992 additions and 454 deletions

View File

@@ -54,6 +54,14 @@ public:
// Provide accessor for task group's status record
TaskGroupTaskStatusRecord *getTaskRecord();
/// The group is a `TaskGroup` that accumulates results.
bool isAccumulatingResults() {
return !isDiscardingResults();
}
/// The group is a `DiscardingTaskGroup` that discards results.
bool isDiscardingResults();
};
} // end namespace swift

View File

@@ -289,16 +289,6 @@ void swift_taskGroup_cancelAll(TaskGroup *group);
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
bool swift_taskGroup_isCancelled(TaskGroup *group);
/// Check if the task group is discarding results or not.
///
/// This can be called from any thread. Its Swift signature is
///
/// \code
/// func swift_taskGroup_isDiscardingResults(group: Builtin.RawPointer)
/// \endcode
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
bool swift_taskGroup_isDiscardingResults(TaskGroup *group);
/// Wait until all pending tasks from the task group have completed.
/// If this task group is accumulating results, this also discards all those results.
///

View File

@@ -273,10 +273,6 @@ OVERRIDE_TASK_GROUP(taskGroup_isCancelled, bool,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
swift::, (TaskGroup *group), (group))
OVERRIDE_TASK_GROUP(taskGroup_isDiscardingResults, bool,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
swift::, (TaskGroup *group), (group))
OVERRIDE_TASK_GROUP(taskGroup_wait_all, void,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swiftasync),
swift::,

View File

@@ -465,7 +465,7 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
return reinterpret_cast<TaskGroup*>(group);
}
TaskGroupTaskStatusRecord * TaskGroup::getTaskRecord() {
TaskGroupTaskStatusRecord *TaskGroup::getTaskRecord() {
return asImpl(this)->getTaskRecord();
}

View File

@@ -307,10 +307,6 @@ OVERRIDE_TASK_GROUP(taskGroup_isCancelled, bool,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
swift::, (TaskGroup *group), (group))
OVERRIDE_TASK_GROUP(taskGroup_isDiscardingResults, bool,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
swift::, (TaskGroup *group), (group))
OVERRIDE_TASK_GROUP(taskGroup_cancelAll, void,
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
swift::, (TaskGroup *group), (group))

View File

@@ -552,7 +552,3 @@ func _taskGroupWaitAll<T>(
group: Builtin.RawPointer,
bodyError: Error?
) async throws -> T?
@available(SwiftStdlib 5.8, *) // FIXME: remove
@_silgen_name("swift_taskGroup_isDiscardingResults")
func _taskGroupIsDiscardingResults(group: Builtin.RawPointer) -> Bool

File diff suppressed because it is too large Load Diff

View File

@@ -140,7 +140,7 @@ func test_discardingTaskGroup_automaticallyRethrows_first_withThrowingBodyFirst(
throw bodyError
}
print("Expected error to be thrown")
fatalError("Expected error to be thrown")
} catch {
// CHECK: Throwing: Boom(id: "body, first, isCancelled:false
// CHECK: Throwing: Boom(id: "task, second, isCancelled:true
@@ -167,7 +167,7 @@ func test_discardingTaskGroup_automaticallyRethrows_first_withThrowingBodySecond
throw bodyError
}
print("Expected error to be thrown")
fatalError("Expected error to be thrown")
} catch {
// CHECK: Throwing: Boom(id: "task, first, isCancelled:false
// CHECK: Throwing: Boom(id: "body, second, isCancelled:true

View File

@@ -219,10 +219,6 @@ TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_taskGroup_waitAll) {
swift_taskGroup_waitAll(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
}
TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_taskGroup_isDiscardingResults) {
swift_taskGroup_isDiscardingResults(nullptr);
}
TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_taskGroup_addPending) {
swift_taskGroup_addPending(nullptr, true);
}