@@ -239,25 +239,16 @@ public struct TaskGroup<ChildTaskResult> {
239
239
priority: TaskPriority ? = nil ,
240
240
operation: __owned @Sendable @escaping ( ) async -> ChildTaskResult
241
241
) {
242
- _ = _taskGroupAddPendingTask ( group: _group, unconditionally: true )
243
-
244
- // Set up the job flags for a new task.
245
- var flags = JobFlags ( )
246
- flags. kind = . task
242
+ var flags = TaskCreateFlags ( )
247
243
flags. priority = priority
248
- flags. isFuture = true
249
244
flags. isChildTask = true
250
- flags. isGroupChildTask = true
251
-
252
- // Create the asynchronous task future.
253
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
254
- Int ( flags. bits) , _group, /*options*/nil , operation)
245
+ flags. enqueueJob = true
246
+ flags. addPendingGroupTaskUnconditionally = true
255
247
256
- // Attach it to the group's task record in the current task.
257
- _taskGroupAttachChild ( group: _group, child: childTask)
248
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
258
249
259
- // Enqueue the resulting job .
260
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask ) )
250
+ // Create the asynchronous task future .
251
+ _ = Builtin . createAsyncTask ( flags . bits , UnsafeRawPointer ( & groupOption ) . _rawValue , operation )
261
252
}
262
253
263
254
/// Add a child task to the group.
@@ -286,23 +277,15 @@ public struct TaskGroup<ChildTaskResult> {
286
277
return false
287
278
}
288
279
289
- // Set up the job flags for a new task.
290
- var flags = JobFlags ( )
291
- flags. kind = . task
280
+ var flags = TaskCreateFlags ( )
292
281
flags. priority = priority
293
- flags. isFuture = true
294
282
flags. isChildTask = true
295
- flags. isGroupChildTask = true
283
+ flags. enqueueJob = true
296
284
297
- // Create the asynchronous task future.
298
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
299
- Int ( flags. bits) , _group, /*options*/nil , operation)
285
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
300
286
301
- // Attach it to the group's task record in the current task.
302
- _taskGroupAttachChild ( group: _group, child: childTask)
303
-
304
- // Enqueue the resulting job.
305
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask) )
287
+ // Create the asynchronous task future.
288
+ _ = Builtin . createAsyncTask ( flags. bits, UnsafeRawPointer ( & groupOption) . _rawValue, operation)
306
289
307
290
return true
308
291
}
@@ -473,26 +456,16 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
473
456
priority: TaskPriority ? = nil ,
474
457
operation: __owned @Sendable @escaping ( ) async throws -> ChildTaskResult
475
458
) {
476
- // we always add, so no need to check if group was cancelled
477
- _ = _taskGroupAddPendingTask ( group: _group, unconditionally: true )
478
-
479
- // Set up the job flags for a new task.
480
- var flags = JobFlags ( )
481
- flags. kind = . task
459
+ var flags = TaskCreateFlags ( )
482
460
flags. priority = priority
483
- flags. isFuture = true
484
461
flags. isChildTask = true
485
- flags. isGroupChildTask = true
462
+ flags. enqueueJob = true
463
+ flags. addPendingGroupTaskUnconditionally = true
486
464
487
- // Create the asynchronous task future.
488
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
489
- Int ( flags. bits) , _group, /*options*/nil , operation)
465
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
490
466
491
- // Attach it to the group's task record in the current task.
492
- _taskGroupAttachChild ( group: _group, child: childTask)
493
-
494
- // Enqueue the resulting job.
495
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask) )
467
+ // Create the asynchronous task future.
468
+ _ = Builtin . createAsyncTask ( flags. bits, UnsafeRawPointer ( & groupOption) . _rawValue, operation)
496
469
}
497
470
498
471
/// Add a child task to the group.
@@ -521,23 +494,15 @@ public struct ThrowingTaskGroup<ChildTaskResult, Failure: Error> {
521
494
return false
522
495
}
523
496
524
- // Set up the job flags for a new task.
525
- var flags = JobFlags ( )
526
- flags. kind = . task
497
+ var flags = TaskCreateFlags ( )
527
498
flags. priority = priority
528
- flags. isFuture = true
529
499
flags. isChildTask = true
530
- flags. isGroupChildTask = true
531
-
532
- // Create the asynchronous task future.
533
- let ( childTask, _) = Builtin . createAsyncTaskGroupFuture (
534
- Int ( flags. bits) , _group, /*options*/nil , operation)
500
+ flags. enqueueJob = true
535
501
536
- // Attach it to the group's task record in the current task.
537
- _taskGroupAttachChild ( group: _group, child: childTask)
502
+ var groupOption = TaskOptionRecord . TaskGroup ( group: _group)
538
503
539
- // Enqueue the resulting job .
540
- _enqueueJobGlobal ( Builtin . convertTaskToJob ( childTask ) )
504
+ // Create the asynchronous task future .
505
+ _ = Builtin . createAsyncTask ( flags . bits , UnsafeRawPointer ( & groupOption ) . _rawValue , operation )
541
506
542
507
return true
543
508
}
@@ -841,14 +806,6 @@ extension ThrowingTaskGroup: AsyncSequence {
841
806
842
807
/// ==== -----------------------------------------------------------------------
843
808
844
- /// Attach task group child to the group group to the task.
845
- @available ( SwiftStdlib 5 . 5 , * )
846
- @_silgen_name ( " swift_taskGroup_attachChild " )
847
- func _taskGroupAttachChild(
848
- group: Builtin . RawPointer ,
849
- child: Builtin . NativeObject
850
- )
851
-
852
809
@available ( SwiftStdlib 5 . 5 , * )
853
810
@_silgen_name ( " swift_taskGroup_destroy " )
854
811
func _taskGroupDestroy( group: __owned Builtin. RawPointer )
0 commit comments