Skip to content

Commit c3419a6

Browse files
committed
[Concurrency] move isAsyncTask into flags of task creation
1 parent 799975a commit c3419a6

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,10 +2036,11 @@ class JobFlags : public FlagSet<uint32_t> {
20362036

20372037
// Kind-specific flags.
20382038

2039-
Task_IsChildTask = 24,
2040-
Task_IsFuture = 25,
2041-
Task_IsGroupChildTask = 26,
2042-
Task_IsContinuingAsyncTask = 27,
2039+
Task_IsChildTask = 24,
2040+
Task_IsFuture = 25,
2041+
Task_IsGroupChildTask = 26,
2042+
Task_IsContinuingAsyncTask = 27,
2043+
Task_IsAsyncLetTask = 28,
20432044
};
20442045

20452046
explicit JobFlags(uint32_t bits) : FlagSet(bits) {}
@@ -2072,6 +2073,9 @@ class JobFlags : public FlagSet<uint32_t> {
20722073
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsContinuingAsyncTask,
20732074
task_isContinuingAsyncTask,
20742075
task_setIsContinuingAsyncTask)
2076+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsAsyncLetTask,
2077+
task_isAsyncLetTask,
2078+
task_setIsAsyncLetTask)
20752079
};
20762080

20772081
/// Kinds of task status record.
@@ -2104,7 +2108,9 @@ enum class TaskStatusRecordKind : uint8_t {
21042108
/// Kinds of option records that can be passed to creating asynchronous tasks.
21052109
enum class TaskOptionRecordKind : uint8_t {
21062110
/// Request a task to be kicked off, or resumed, on a specific executor.
2107-
Executor = 0,
2111+
Executor = 0,
2112+
/// Request a child task to be part of a specific task group.
2113+
TaskGroup = 1,
21082114
};
21092115

21102116
/// Flags for cancellation records.

include/swift/ABI/TaskOptions.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ class TaskOptionRecord {
5656

5757
};
5858

59+
/******************************************************************************/
60+
/****************************** TASK OPTIONS **********************************/
61+
/******************************************************************************/
62+
63+
class TaskGroupTaskOptionRecord : public TaskOptionRecord {
64+
TaskGroup *Group;
65+
66+
public:
67+
TaskGroupTaskOptionRecord(TaskGroup *group)
68+
: TaskOptionRecord(TaskOptionRecordKind::TaskGroup),
69+
Group(group) {}
70+
71+
TaskGroup *getGroup() const {
72+
return Group;
73+
}
74+
};
75+
76+
5977
/// Task option to specify on what executor the task should be executed.
6078
///
6179
/// Not passing this option implies that that a "best guess" or good default

include/swift/Runtime/Concurrency.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ struct AsyncTaskAndContext {
3636
AsyncContext *InitialContext;
3737
};
3838

39-
/// Create a task object with no future which will run the given
40-
/// function.
39+
/// Create a task object with no future which will run the given function.
4140
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
4241
AsyncTaskAndContext swift_task_create_f(
4342
size_t flags,
@@ -49,17 +48,15 @@ AsyncTaskAndContext swift_task_create_f(
4948
using FutureAsyncSignature =
5049
AsyncSignature<void(void*), /*throws*/ true>;
5150

52-
/// Create a task object with a future which will run the given
53-
/// closure.
51+
/// Create a task object with a future which will run the given closure.
5452
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
5553
AsyncTaskAndContext swift_task_create_future(
5654
size_t flags,
5755
TaskOptionRecord *options,
5856
const Metadata *futureResultType,
5957
void *closureEntryPoint, HeapObject * /* +1 */ closureContext);
6058

61-
/// Create a task object with a future which will run the given
62-
/// function.
59+
/// Create a task object with a future which will run the given function.
6360
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
6461
AsyncTaskAndContext swift_task_create_future_f(
6562
size_t flags,

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ OVERRIDE_TASK(task_create_group_future_common, AsyncTaskAndContext, , , ,
103103
const Metadata *futureResultType,
104104
FutureAsyncSignature::FunctionType *function,
105105
void *closureContext,
106-
bool isAsyncLetTask,
107106
size_t initialContextSize),
108107
(flags, group, options, futureResultType, function, closureContext,
109-
isAsyncLetTask, initialContextSize))
108+
initialContextSize))
110109

111110
OVERRIDE_TASK(task_future_wait, void, SWIFT_EXPORT_FROM(swift_Concurrency),
112111
SWIFT_CC(swiftasync), swift::,

stdlib/public/Concurrency/Task.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *
388388
SWIFT_CC(swiftasync)
389389
static void
390390
task_future_wait_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
391-
392391
return _context->ResumeParent(_context->Parent);
393392
}
394393

@@ -404,10 +403,11 @@ static AsyncTaskAndContext swift_task_create_group_future_commonImpl(
404403
TaskOptionRecord *options,
405404
const Metadata *futureResultType,
406405
FutureAsyncSignature::FunctionType *function, void *closureContext,
407-
bool isAsyncLetTask, // TODO: express as a bit in the rawFlags? -- ktoso
408406
size_t initialContextSize) {
409407
JobFlags flags(rawFlags);
408+
bool isAsyncLetTask = flags.task_isAsyncLetTask();
410409
assert((futureResultType != nullptr) == flags.task_isFuture());
410+
assert(!isAsyncLetTask || isAsyncLetTask == flags.task_isChildTask());
411411
assert(!flags.task_isFuture() ||
412412
initialContextSize >= sizeof(FutureAsyncContext));
413413
assert((group != nullptr) == flags.task_isGroupChildTask());
@@ -585,7 +585,6 @@ static AsyncTaskAndContext swift_task_create_group_future_common(
585585
TaskOptionRecord *options,
586586
const Metadata *futureResultType,
587587
FutureAsyncSignature::FunctionType *function, void *closureContext,
588-
bool isAsyncLetTask,
589588
size_t initialContextSize);
590589

591590
AsyncTaskAndContext
@@ -624,7 +623,6 @@ AsyncTaskAndContext swift::swift_task_create_group_future_f(
624623
options,
625624
futureResultType,
626625
function, /*closureContext=*/nullptr,
627-
/*isAsyncLetTask=*/false,
628626
initialContextSize);
629627
}
630628

@@ -664,12 +662,11 @@ AsyncTaskAndContext swift::swift_task_create_future(
664662
options,
665663
futureResultType,
666664
taskEntry, closureContext,
667-
/*isAsyncLetTask*/false,
668665
initialContextSize);
669666
}
670667

671668
AsyncTaskAndContext swift::swift_task_create_async_let_future(
672-
size_t flags,
669+
size_t rawFlags,
673670
TaskOptionRecord *options,
674671
const Metadata *futureResultType,
675672
void *closureEntry, void *closureContext) {
@@ -681,13 +678,14 @@ AsyncTaskAndContext swift::swift_task_create_async_let_future(
681678
SpecialPointerAuthDiscriminators::AsyncFutureFunction
682679
>(closureEntry, (HeapObject *)closureContext);
683680

681+
JobFlags flags(rawFlags);
682+
flags.task_setIsAsyncLetTask(true);
684683
return swift_task_create_group_future_common(
685-
flags,
684+
flags.getOpaqueValue(),
686685
/*group*/nullptr,
687686
options,
688687
futureResultType,
689688
taskEntry, closureContext,
690-
/*isAsyncLetTask*/true,
691689
initialContextSize);
692690
}
693691

@@ -712,7 +710,6 @@ swift::swift_task_create_group_future(
712710
options,
713711
futureResultType,
714712
taskEntry, closureContext,
715-
/*isAsyncLetTask*/false,
716713
initialContextSize);
717714
}
718715

0 commit comments

Comments
 (0)