mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[TaskGroup] group is not NativeObject, just an opqeue value
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
#ifndef SWIFT_ABI_TASK_GROUP_H
|
||||
#define SWIFT_ABI_TASK_GROUP_H
|
||||
|
||||
#include "swift/Runtime/Concurrency.h"
|
||||
#include "swift/ABI/Task.h"
|
||||
#include "swift/Runtime/Concurrency.h"
|
||||
#include "swift/Basic/RelativePointer.h"
|
||||
#include "swift/ABI/HeapObject.h"
|
||||
#include "swift/Runtime/Config.h"
|
||||
|
||||
@@ -767,7 +767,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTaskFuture,
|
||||
/// createAsyncTaskGroupFuture(): (
|
||||
/// Int, // flags
|
||||
/// Builtin.NativeObject?, // parent
|
||||
/// Builtin.NativeObject?, // group
|
||||
/// Builtin.RawPointer?, // group
|
||||
/// @escaping () async throws -> T
|
||||
/// ) -> Builtin.NativeObject
|
||||
///
|
||||
|
||||
@@ -176,7 +176,7 @@ using TaskGroupFutureWaitThrowingSignature =
|
||||
/// \code
|
||||
/// func swift_task_group_wait_next_throwing(
|
||||
/// waitingTask: Builtin.NativeObject, // current task
|
||||
/// group: Builtin.NativeObject,
|
||||
/// group: UnsafeRawPointer,
|
||||
/// ) async -> T
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
|
||||
@@ -202,7 +202,7 @@ swift::TaskGroup* swift_task_group_create(AsyncTask *task);
|
||||
///
|
||||
/// \code
|
||||
/// func swift_task_group_attachChild(
|
||||
/// group: Builtin.NativeObject,
|
||||
/// group: UnsafeRawPointer,
|
||||
/// parent: Builtin.NativeObject,
|
||||
/// child: Builtin.NativeObject
|
||||
/// )
|
||||
@@ -216,7 +216,7 @@ void swift_task_group_attachChild(TaskGroup *group,
|
||||
/// \code
|
||||
/// func swift_task_group_destroy(
|
||||
/// _ task: Builtin.NativeObject,
|
||||
/// _ group: Builtin.NativeObject
|
||||
/// _ group: UnsafeRawPointer
|
||||
/// )
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
||||
@@ -229,7 +229,7 @@ void swift_task_group_destroy(AsyncTask *task, TaskGroup *group);
|
||||
///
|
||||
/// \code
|
||||
/// func swift_task_group_add_pending(
|
||||
/// group: Builtin.NativeObject
|
||||
/// group: UnsafeRawPointer
|
||||
/// ) -> Bool
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
||||
@@ -243,7 +243,7 @@ bool swift_task_group_add_pending(TaskGroup *group);
|
||||
/// \code
|
||||
/// func swift_task_group_cancel_all(
|
||||
/// task: Builtin.NativeObject,
|
||||
/// group: Builtin.NativeObject
|
||||
/// group: UnsafeRawPointer
|
||||
/// )
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
||||
@@ -259,7 +259,7 @@ void swift_task_group_cancel_all(AsyncTask *task, TaskGroup *group);
|
||||
/// \code
|
||||
/// func swift_task_group_is_cancelled(
|
||||
/// task: Builtin.NativeObject,
|
||||
/// group: Builtin.NativeObject
|
||||
/// group: UnsafeRawPointer
|
||||
/// )
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
||||
@@ -271,7 +271,7 @@ bool swift_task_group_is_cancelled(AsyncTask *task, TaskGroup *group);
|
||||
///
|
||||
/// \code
|
||||
/// func swift_task_group_is_empty(
|
||||
/// _ group: Builtin.NativeObject
|
||||
/// _ group: UnsafeRawPointer
|
||||
/// ) -> Bool
|
||||
/// \endcode
|
||||
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
|
||||
|
||||
@@ -1379,7 +1379,7 @@ static ValueDecl *getCreateAsyncTaskGroupFuture(ASTContext &ctx, Identifier id)
|
||||
builder.addParameter(
|
||||
makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); // parent
|
||||
builder.addParameter(
|
||||
makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); // group
|
||||
makeConcrete(OptionalType::get(ctx.TheRawPointerType))); // group
|
||||
auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build();
|
||||
builder.addParameter(
|
||||
makeConcrete(FunctionType::get({ }, genericParam, extInfo)));
|
||||
|
||||
@@ -1427,7 +1427,6 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
|
||||
return SGF.emitManagedRValueWithCleanup(apply);
|
||||
}
|
||||
|
||||
// TODO: very duplicated with emitBuiltinCreateAsyncTaskFuture, we pass the additional group param
|
||||
// Emit SIL for the named builtin: createAsyncTaskGroupFuture.
|
||||
static ManagedValue emitBuiltinCreateAsyncTaskGroupFuture(
|
||||
SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/ABI/TaskGroup.h"
|
||||
#include "swift/Runtime/Concurrency.h"
|
||||
#include "swift/ABI/Task.h"
|
||||
#include "swift/ABI/TaskGroup.h"
|
||||
#include "swift/ABI/Metadata.h"
|
||||
#include "swift/Runtime/Mutex.h"
|
||||
#include "swift/Runtime/HeapObject.h"
|
||||
|
||||
@@ -88,7 +88,6 @@ extension Task {
|
||||
/// A task group serves as storage for dynamically started tasks.
|
||||
///
|
||||
/// Its intended use is with the `Task.withGroup` function.
|
||||
/* @unmoveable */
|
||||
public struct Group<TaskResult>: AsyncSequence {
|
||||
public typealias AsyncIterator = GroupIterator
|
||||
public typealias Element = TaskResult
|
||||
@@ -96,10 +95,10 @@ extension Task {
|
||||
private let _task: Builtin.NativeObject
|
||||
/// Group task into which child tasks offer their results,
|
||||
/// and the `next()` function polls those results from.
|
||||
private let _group: Builtin.NativeObject
|
||||
private let _group: Builtin.RawPointer
|
||||
|
||||
/// No public initializers
|
||||
init(task: Builtin.NativeObject, group: Builtin.NativeObject) {
|
||||
init(task: Builtin.NativeObject, group: Builtin.RawPointer) {
|
||||
// TODO: this feels slightly off, any other way to avoid the task being too eagerly released?
|
||||
_swiftRetain(task) // to avoid the task being destroyed when the group is destroyed
|
||||
|
||||
@@ -339,12 +338,12 @@ func _swiftRelease(
|
||||
@_silgen_name("swift_task_group_create")
|
||||
func _taskGroupCreate(
|
||||
task: Builtin.NativeObject
|
||||
) -> Builtin.NativeObject
|
||||
) -> Builtin.RawPointer
|
||||
|
||||
/// Attach task group child to the group group to the task.
|
||||
@_silgen_name("swift_task_group_attachChild")
|
||||
func _taskGroupAttachChild(
|
||||
group: Builtin.NativeObject,
|
||||
group: Builtin.RawPointer,
|
||||
parent: Builtin.NativeObject,
|
||||
child: Builtin.NativeObject
|
||||
) -> UnsafeRawPointer /*ChildTaskStatusRecord*/
|
||||
@@ -352,18 +351,18 @@ func _taskGroupAttachChild(
|
||||
@_silgen_name("swift_task_group_destroy")
|
||||
func _taskGroupDestroy(
|
||||
task: Builtin.NativeObject,
|
||||
group: __owned Builtin.NativeObject
|
||||
group: __owned Builtin.RawPointer
|
||||
)
|
||||
|
||||
@_silgen_name("swift_task_group_add_pending")
|
||||
func _taskGroupAddPendingTask(
|
||||
group: Builtin.NativeObject
|
||||
group: Builtin.RawPointer
|
||||
) -> Bool
|
||||
|
||||
@_silgen_name("swift_task_group_cancel_all")
|
||||
func _taskGroupCancelAll(
|
||||
task: Builtin.NativeObject,
|
||||
group: Builtin.NativeObject
|
||||
group: Builtin.RawPointer
|
||||
)
|
||||
|
||||
/// Checks ONLY if the group was specifically cancelled.
|
||||
@@ -371,13 +370,13 @@ func _taskGroupCancelAll(
|
||||
@_silgen_name("swift_task_group_is_cancelled")
|
||||
func _taskGroupIsCancelled(
|
||||
task: Builtin.NativeObject,
|
||||
group: Builtin.NativeObject
|
||||
group: Builtin.RawPointer
|
||||
) -> Bool
|
||||
|
||||
@_silgen_name("swift_task_group_wait_next_throwing")
|
||||
func _taskGroupWaitNext<T>(
|
||||
waitingTask: Builtin.NativeObject,
|
||||
group: Builtin.NativeObject
|
||||
group: Builtin.RawPointer
|
||||
) async throws -> T?
|
||||
|
||||
enum PollStatus: Int {
|
||||
@@ -389,5 +388,5 @@ enum PollStatus: Int {
|
||||
|
||||
@_silgen_name("swift_task_group_is_empty")
|
||||
func _taskGroupIsEmpty(
|
||||
_ group: Builtin.NativeObject
|
||||
_ group: Builtin.RawPointer
|
||||
) -> Bool
|
||||
|
||||
@@ -34,7 +34,13 @@ public struct X {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test for the createAsyncTaskGroupFuture?
|
||||
// CHECK-LABEL: sil hidden [ossa] @$s4test1XV16launchGroupChildyyxlF : $@convention(method) <T> (@in_guaranteed T, X) -> () {
|
||||
func launchGroupChild<T>(_ value: T) {
|
||||
// CHECK: builtin "createAsyncTaskGroupFuture"<T>([[ZERO:%.*]] : $Int, [[NIL:%.*]] : $Optional<Builtin.NativeObject>, [[NIL:%.*]] : $Optional<Builtin.RawPointer>, [[FN:%.*]] : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
|
||||
let task = Builtin.createAsyncTaskGroupFuture(0, nil, nil) { () async throws -> T in
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
public func launchRocker<T>(closure: @escaping () async throws -> T) {
|
||||
_ = Builtin.createAsyncTaskFuture(0, nil, closure)
|
||||
|
||||
Reference in New Issue
Block a user