@@ -456,6 +456,8 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
456456// Initializes into the preallocated _group an actual TaskGroupImpl.
457457SWIFT_CC (swift)
458458static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
459+ SWIFT_TASK_DEBUG_LOG (" creating task group = %p" , group);
460+
459461 TaskGroupImpl *impl = new (group) TaskGroupImpl (T);
460462 auto record = impl->getTaskRecord ();
461463 assert (impl == record && " the group IS the task record" );
@@ -474,8 +476,7 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
474476SWIFT_CC (swift)
475477static void swift_taskGroup_attachChildImpl(TaskGroup *group,
476478 AsyncTask *child) {
477- SWIFT_TASK_DEBUG_LOG (" attach child task = %p to group = %p\n " ,
478- child, group);
479+ SWIFT_TASK_DEBUG_LOG (" attach child task = %p to group = %p" , child, group);
479480
480481 // The counterpart of this (detachChild) is performed by the group itself,
481482 // when it offers the completed (child) task's value to a waiting task -
@@ -492,11 +493,17 @@ static void swift_taskGroup_destroyImpl(TaskGroup *group) {
492493}
493494
494495void TaskGroupImpl::destroy () {
496+ SWIFT_TASK_DEBUG_LOG (" destroying task group = %p" , this );
497+
495498 // First, remove the group from the task and deallocate the record
496499 swift_task_removeStatusRecord (getTaskRecord ());
497500
498- // By the time we call destroy, all tasks inside the group must have been
499- // awaited on already; We handle this on the swift side.
501+ // No need to drain our queue here, as by the time we call destroy,
502+ // all tasks inside the group must have been awaited on already.
503+ // This is done in Swift's withTaskGroup function explicitly.
504+
505+ // destroy the group's storage
506+ this ->~TaskGroupImpl ();
500507}
501508
502509// =============================================================================
@@ -568,7 +575,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
568575 bool hadErrorResult = false ;
569576 auto errorObject = asyncContextPrefix->errorResult ;
570577 if (errorObject) {
571- // instead we need to enqueue this result:
578+ // instead, we need to enqueue this result:
572579 hadErrorResult = true ;
573580 }
574581
0 commit comments