@@ -211,25 +211,16 @@ public struct TaskGroup<ChildTaskResult> {
211
211
priority: TaskPriority ? = nil ,
212
212
operation: __owned @Sendable @escaping ( ) async -> ChildTaskResult
213
213
) {
214
- _ = _taskGroupAddPendingTask ( group: _group, unconditionally: true )
215
-
216
- // Set up the job flags for a new task.
217
- var flags = JobFlags ( )
218
- flags. kind = . task
214
+ var flags = TaskCreateFlags ( )
219
215
flags. priority = priority
220
- flags. isFuture = true
221
216
flags. isChildTask = true
222
- flags. isGroupChildTask = true
223
-
224
- // Create the asynchronous task future.
225
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
226
- Int ( flags. bits) , _group, /*options*/nil , operation)
217
+ flags. enqueueJob = true
218
+ flags. addPendingGroupTaskUnconditionally = true
227
219
228
- // Attach it to the group's task record in the current task.
229
- _taskGroupAttachChild ( group: _group, child: childTask)
220
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
230
221
231
- // Enqueue the resulting job .
232
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask ) )
222
+ // Create the asynchronous task future .
223
+ _ = Builtin . createAsyncTask ( flags . bits , UnsafeRawPointer ( & groupOption ) . _rawValue , operation )
233
224
}
234
225
235
226
/// Add a child task to the group.
@@ -258,23 +249,15 @@ public struct TaskGroup<ChildTaskResult> {
258
249
return false
259
250
}
260
251
261
- // Set up the job flags for a new task.
262
- var flags = JobFlags ( )
263
- flags. kind = . task
252
+ var flags = TaskCreateFlags ( )
264
253
flags. priority = priority
265
- flags. isFuture = true
266
254
flags. isChildTask = true
267
- flags. isGroupChildTask = true
255
+ flags. enqueueJob = true
268
256
269
- // Create the asynchronous task future.
270
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
271
- Int ( flags. bits) , _group, /*options*/nil , operation)
257
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
272
258
273
- // Attach it to the group's task record in the current task.
274
- _taskGroupAttachChild ( group: _group, child: childTask)
275
-
276
- // Enqueue the resulting job.
277
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask) )
259
+ // Create the asynchronous task future.
260
+ _ = Builtin . createAsyncTask ( flags. bits, UnsafeRawPointer ( & groupOption) . _rawValue, operation)
278
261
279
262
return true
280
263
}
@@ -453,26 +436,16 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
453
436
priority: TaskPriority ? = nil ,
454
437
operation: __owned @Sendable @escaping ( ) async throws -> ChildTaskResult
455
438
) {
456
- // we always add, so no need to check if group was cancelled
457
- _ = _taskGroupAddPendingTask ( group: _group, unconditionally: true )
458
-
459
- // Set up the job flags for a new task.
460
- var flags = JobFlags ( )
461
- flags. kind = . task
439
+ var flags = TaskCreateFlags ( )
462
440
flags. priority = priority
463
- flags. isFuture = true
464
441
flags. isChildTask = true
465
- flags. isGroupChildTask = true
442
+ flags. enqueueJob = true
443
+ flags. addPendingGroupTaskUnconditionally = true
466
444
467
- // Create the asynchronous task future.
468
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
469
- Int ( flags. bits) , _group, /*options*/nil , operation)
445
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
470
446
471
- // Attach it to the group's task record in the current task.
472
- _taskGroupAttachChild ( group: _group, child: childTask)
473
-
474
- // Enqueue the resulting job.
475
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask) )
447
+ // Create the asynchronous task future.
448
+ _ = Builtin . createAsyncTask ( flags. bits, UnsafeRawPointer ( & groupOption) . _rawValue, operation)
476
449
}
477
450
478
451
/// Add a child task to the group.
@@ -501,23 +474,15 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
501
474
return false
502
475
}
503
476
504
- // Set up the job flags for a new task.
505
- var flags = JobFlags ( )
506
- flags. kind = . task
477
+ var flags = TaskCreateFlags ( )
507
478
flags. priority = priority
508
- flags. isFuture = true
509
479
flags. isChildTask = true
510
- flags. isGroupChildTask = true
511
-
512
- // Create the asynchronous task future.
513
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
514
- Int ( flags. bits) , _group, /*options*/nil , operation)
480
+ flags. enqueueJob = true
515
481
516
- // Attach it to the group's task record in the current task.
517
- _taskGroupAttachChild ( group: _group, child: childTask)
482
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
518
483
519
- // Enqueue the resulting job .
520
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask ) )
484
+ // Create the asynchronous task future .
485
+ _ = Builtin . createAsyncTask ( flags . bits , UnsafeRawPointer ( & groupOption ) . _rawValue , operation )
521
486
522
487
return true
523
488
}
@@ -746,14 +711,6 @@ extension ThrowingTaskGroup: AsyncSequence {
746
711
747
712
/// ==== -----------------------------------------------------------------------
748
713
749
- /// Attach task group child to the group group to the task.
750
- @available ( SwiftStdlib 5 . 5 , * )
751
- @_silgen_name ( " swift_taskGroup_attachChild " )
752
- func _taskGroupAttachChild(
753
- group: Builtin . RawPointer ,
754
- child: Builtin . NativeObject
755
- )
756
-
757
714
@available ( SwiftStdlib 5 . 5 , * )
758
715
@_silgen_name ( " swift_taskGroup_destroy " )
759
716
func _taskGroupDestroy( group: __owned Builtin. RawPointer )
0 commit comments