Skip to content

Commit 1cb3000

Browse files
committed
[TaskGroup] group is not NativeObject, just an opqeue value
1 parent 2ab160e commit 1cb3000

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

include/swift/ABI/TaskGroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef SWIFT_ABI_TASK_GROUP_H
1818
#define SWIFT_ABI_TASK_GROUP_H
1919

20-
#include "swift/Runtime/Concurrency.h"
2120
#include "swift/ABI/Task.h"
21+
#include "swift/Runtime/Concurrency.h"
2222
#include "swift/Basic/RelativePointer.h"
2323
#include "swift/ABI/HeapObject.h"
2424
#include "swift/Runtime/Config.h"

include/swift/AST/Builtins.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTaskFuture,
767767
/// createAsyncTaskGroupFuture(): (
768768
/// Int, // flags
769769
/// Builtin.NativeObject?, // parent
770-
/// Builtin.NativeObject?, // group
770+
/// Builtin.RawPointer?, // group
771771
/// @escaping () async throws -> T
772772
/// ) -> Builtin.NativeObject
773773
///

include/swift/Runtime/Concurrency.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ using TaskGroupFutureWaitThrowingSignature =
176176
/// \code
177177
/// func swift_task_group_wait_next_throwing(
178178
/// waitingTask: Builtin.NativeObject, // current task
179-
/// group: Builtin.NativeObject,
179+
/// group: UnsafeRawPointer,
180180
/// ) async -> T
181181
/// \endcode
182182
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swiftasync)
@@ -202,7 +202,7 @@ swift::TaskGroup* swift_task_group_create(AsyncTask *task);
202202
///
203203
/// \code
204204
/// func swift_task_group_attachChild(
205-
/// group: Builtin.NativeObject,
205+
/// group: UnsafeRawPointer,
206206
/// parent: Builtin.NativeObject,
207207
/// child: Builtin.NativeObject
208208
/// )
@@ -216,7 +216,7 @@ void swift_task_group_attachChild(TaskGroup *group,
216216
/// \code
217217
/// func swift_task_group_destroy(
218218
/// _ task: Builtin.NativeObject,
219-
/// _ group: Builtin.NativeObject
219+
/// _ group: UnsafeRawPointer
220220
/// )
221221
/// \endcode
222222
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
@@ -229,7 +229,7 @@ void swift_task_group_destroy(AsyncTask *task, TaskGroup *group);
229229
///
230230
/// \code
231231
/// func swift_task_group_add_pending(
232-
/// group: Builtin.NativeObject
232+
/// group: UnsafeRawPointer
233233
/// ) -> Bool
234234
/// \endcode
235235
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
@@ -243,7 +243,7 @@ bool swift_task_group_add_pending(TaskGroup *group);
243243
/// \code
244244
/// func swift_task_group_cancel_all(
245245
/// task: Builtin.NativeObject,
246-
/// group: Builtin.NativeObject
246+
/// group: UnsafeRawPointer
247247
/// )
248248
/// \endcode
249249
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
@@ -259,7 +259,7 @@ void swift_task_group_cancel_all(AsyncTask *task, TaskGroup *group);
259259
/// \code
260260
/// func swift_task_group_is_cancelled(
261261
/// task: Builtin.NativeObject,
262-
/// group: Builtin.NativeObject
262+
/// group: UnsafeRawPointer
263263
/// )
264264
/// \endcode
265265
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
@@ -271,7 +271,7 @@ bool swift_task_group_is_cancelled(AsyncTask *task, TaskGroup *group);
271271
///
272272
/// \code
273273
/// func swift_task_group_is_empty(
274-
/// _ group: Builtin.NativeObject
274+
/// _ group: UnsafeRawPointer
275275
/// ) -> Bool
276276
/// \endcode
277277
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)

lib/AST/Builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ static ValueDecl *getCreateAsyncTaskGroupFuture(ASTContext &ctx, Identifier id)
13791379
builder.addParameter(
13801380
makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); // parent
13811381
builder.addParameter(
1382-
makeConcrete(OptionalType::get(ctx.TheNativeObjectType))); // group
1382+
makeConcrete(OptionalType::get(ctx.TheRawPointerType))); // group
13831383
auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build();
13841384
builder.addParameter(
13851385
makeConcrete(FunctionType::get({ }, genericParam, extInfo)));

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,6 @@ static ManagedValue emitBuiltinCreateAsyncTaskFuture(
14271427
return SGF.emitManagedRValueWithCleanup(apply);
14281428
}
14291429

1430-
// TODO: very duplicated with emitBuiltinCreateAsyncTaskFuture, we pass the additional group param
14311430
// Emit SIL for the named builtin: createAsyncTaskGroupFuture.
14321431
static ManagedValue emitBuiltinCreateAsyncTaskGroupFuture(
14331432
SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "swift/ABI/TaskGroup.h"
1718
#include "swift/Runtime/Concurrency.h"
1819
#include "swift/ABI/Task.h"
19-
#include "swift/ABI/TaskGroup.h"
2020
#include "swift/ABI/Metadata.h"
2121
#include "swift/Runtime/Mutex.h"
2222
#include "swift/Runtime/HeapObject.h"

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,17 @@ extension Task {
8888
/// A task group serves as storage for dynamically started tasks.
8989
///
9090
/// Its intended use is with the `Task.withGroup` function.
91-
/* @unmoveable */
9291
public struct Group<TaskResult>: AsyncSequence {
9392
public typealias AsyncIterator = GroupIterator
9493
public typealias Element = TaskResult
9594

9695
private let _task: Builtin.NativeObject
9796
/// Group task into which child tasks offer their results,
9897
/// and the `next()` function polls those results from.
99-
private let _group: Builtin.NativeObject
98+
private let _group: Builtin.RawPointer
10099

101100
/// No public initializers
102-
init(task: Builtin.NativeObject, group: Builtin.NativeObject) {
101+
init(task: Builtin.NativeObject, group: Builtin.RawPointer) {
103102
// TODO: this feels slightly off, any other way to avoid the task being too eagerly released?
104103
_swiftRetain(task) // to avoid the task being destroyed when the group is destroyed
105104

@@ -339,45 +338,45 @@ func _swiftRelease(
339338
@_silgen_name("swift_task_group_create")
340339
func _taskGroupCreate(
341340
task: Builtin.NativeObject
342-
) -> Builtin.NativeObject
341+
) -> Builtin.RawPointer
343342

344343
/// Attach task group child to the group group to the task.
345344
@_silgen_name("swift_task_group_attachChild")
346345
func _taskGroupAttachChild(
347-
group: Builtin.NativeObject,
346+
group: Builtin.RawPointer,
348347
parent: Builtin.NativeObject,
349348
child: Builtin.NativeObject
350349
) -> UnsafeRawPointer /*ChildTaskStatusRecord*/
351350

352351
@_silgen_name("swift_task_group_destroy")
353352
func _taskGroupDestroy(
354353
task: Builtin.NativeObject,
355-
group: __owned Builtin.NativeObject
354+
group: __owned Builtin.RawPointer
356355
)
357356

358357
@_silgen_name("swift_task_group_add_pending")
359358
func _taskGroupAddPendingTask(
360-
group: Builtin.NativeObject
359+
group: Builtin.RawPointer
361360
) -> Bool
362361

363362
@_silgen_name("swift_task_group_cancel_all")
364363
func _taskGroupCancelAll(
365364
task: Builtin.NativeObject,
366-
group: Builtin.NativeObject
365+
group: Builtin.RawPointer
367366
)
368367

369368
/// Checks ONLY if the group was specifically cancelled.
370369
/// The task itself being cancelled must be checked separately.
371370
@_silgen_name("swift_task_group_is_cancelled")
372371
func _taskGroupIsCancelled(
373372
task: Builtin.NativeObject,
374-
group: Builtin.NativeObject
373+
group: Builtin.RawPointer
375374
) -> Bool
376375

377376
@_silgen_name("swift_task_group_wait_next_throwing")
378377
func _taskGroupWaitNext<T>(
379378
waitingTask: Builtin.NativeObject,
380-
group: Builtin.NativeObject
379+
group: Builtin.RawPointer
381380
) async throws -> T?
382381

383382
enum PollStatus: Int {
@@ -389,5 +388,5 @@ enum PollStatus: Int {
389388

390389
@_silgen_name("swift_task_group_is_empty")
391390
func _taskGroupIsEmpty(
392-
_ group: Builtin.NativeObject
391+
_ group: Builtin.RawPointer
393392
) -> Bool

test/SILGen/async_builtins.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public struct X {
3434
}
3535
}
3636

37-
// TODO: test for the createAsyncTaskGroupFuture?
37+
// CHECK-LABEL: sil hidden [ossa] @$s4test1XV16launchGroupChildyyxlF : $@convention(method) <T> (@in_guaranteed T, X) -> () {
38+
func launchGroupChild<T>(_ value: T) {
39+
// 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)
40+
let task = Builtin.createAsyncTaskGroupFuture(0, nil, nil) { () async throws -> T in
41+
return value
42+
}
43+
}
3844

3945
public func launchRocker<T>(closure: @escaping () async throws -> T) {
4046
_ = Builtin.createAsyncTaskFuture(0, nil, closure)

0 commit comments

Comments
 (0)