@@ -606,10 +606,14 @@ static std::pair<size_t, size_t> amountToAllocateForHeaderAndTask(
606
606
if (group) {
607
607
headerSize += sizeof (AsyncTask::GroupChildFragment);
608
608
}
609
-
610
- headerSize += FutureFragment::fragmentSize (headerSize, futureResultType);
611
- // Add the future async context prefix.
612
- headerSize += sizeof (FutureAsyncContextPrefix);
609
+ if (!futureResultType.isNull ()) {
610
+ headerSize += FutureFragment::fragmentSize (headerSize, futureResultType);
611
+ // Add the future async context prefix.
612
+ headerSize += sizeof (FutureAsyncContextPrefix);
613
+ } else {
614
+ // Add the async context prefix.
615
+ headerSize += sizeof (AsyncContextPrefix);
616
+ }
613
617
614
618
headerSize = llvm::alignTo (headerSize, llvm::Align (alignof (AsyncContext)));
615
619
// Allocate the initial context together with the job.
@@ -636,9 +640,6 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
636
640
// Propagate task-creation flags to job flags as appropriate.
637
641
jobFlags.task_setIsChildTask (taskCreateFlags.isChildTask ());
638
642
639
- jobFlags.task_setIsFuture (true );
640
- assert (initialContextSize >= sizeof (FutureAsyncContext));
641
-
642
643
ResultTypeInfo futureResultType;
643
644
#if !SWIFT_CONCURRENCY_EMBEDDED
644
645
futureResultType.metadata = futureResultTypeMetadata;
@@ -705,6 +706,15 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
705
706
}
706
707
}
707
708
709
+ #if SWIFT_CONCURRENCY_EMBEDDED
710
+ assert (!futureResultType.isNull ());
711
+ #endif
712
+
713
+ if (!futureResultType.isNull ()) {
714
+ jobFlags.task_setIsFuture (true );
715
+ assert (initialContextSize >= sizeof (FutureAsyncContext));
716
+ }
717
+
708
718
// Add to the task group, if requested.
709
719
if (taskCreateFlags.addPendingGroupTaskUnconditionally ()) {
710
720
assert (group && " Missing group" );
@@ -853,7 +863,7 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
853
863
// the async context to get at the parameters.
854
864
// See e.g. FutureAsyncContextPrefix.
855
865
856
- if (taskCreateFlags.isDiscardingTask ()) {
866
+ if (futureResultType. isNull () || taskCreateFlags.isDiscardingTask ()) {
857
867
auto asyncContextPrefix = reinterpret_cast <AsyncContextPrefix *>(
858
868
reinterpret_cast <char *>(allocation) + headerSize -
859
869
sizeof (AsyncContextPrefix));
@@ -903,17 +913,19 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
903
913
}
904
914
905
915
// Initialize the future fragment if applicable.
906
- assert (task->isFuture ());
907
- auto futureFragment = task->futureFragment ();
908
- ::new (futureFragment) FutureFragment (futureResultType);
909
-
910
- // Set up the context for the future so there is no error, and a successful
911
- // result will be written into the future fragment's storage.
912
- auto futureAsyncContextPrefix =
913
- reinterpret_cast <FutureAsyncContextPrefix *>(
914
- reinterpret_cast <char *>(allocation) + headerSize -
915
- sizeof (FutureAsyncContextPrefix));
916
- futureAsyncContextPrefix->indirectResult = futureFragment->getStoragePtr ();
916
+ if (!futureResultType.isNull ()) {
917
+ assert (task->isFuture ());
918
+ auto futureFragment = task->futureFragment ();
919
+ ::new (futureFragment) FutureFragment (futureResultType);
920
+
921
+ // Set up the context for the future so there is no error, and a successful
922
+ // result will be written into the future fragment's storage.
923
+ auto futureAsyncContextPrefix =
924
+ reinterpret_cast <FutureAsyncContextPrefix *>(
925
+ reinterpret_cast <char *>(allocation) + headerSize -
926
+ sizeof (FutureAsyncContextPrefix));
927
+ futureAsyncContextPrefix->indirectResult = futureFragment->getStoragePtr ();
928
+ }
917
929
918
930
SWIFT_TASK_DEBUG_LOG (" creating task %p ID %" PRIu64
919
931
" with parent %p at base pri %zu" ,
0 commit comments