Skip to content

Commit f37ae3d

Browse files
committed
[Concurrency] move isAsyncTask into flags of task creation
1 parent 8536100 commit f37ae3d

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
@@ -393,7 +393,6 @@ static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *
393393
SWIFT_CC(swiftasync)
394394
static void
395395
task_future_wait_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
396-
397396
return _context->ResumeParent(_context->Parent);
398397
}
399398

@@ -409,10 +408,11 @@ static AsyncTaskAndContext swift_task_create_group_future_commonImpl(
409408
TaskOptionRecord *options,
410409
const Metadata *futureResultType,
411410
FutureAsyncSignature::FunctionType *function, void *closureContext,
412-
bool isAsyncLetTask, // TODO: express as a bit in the rawFlags? -- ktoso
413411
size_t initialContextSize) {
414412
JobFlags flags(rawFlags);
413+
bool isAsyncLetTask = flags.task_isAsyncLetTask();
415414
assert((futureResultType != nullptr) == flags.task_isFuture());
415+
assert(!isAsyncLetTask || isAsyncLetTask == flags.task_isChildTask());
416416
assert(!flags.task_isFuture() ||
417417
initialContextSize >= sizeof(FutureAsyncContext));
418418
assert((group != nullptr) == flags.task_isGroupChildTask());
@@ -591,7 +591,6 @@ static AsyncTaskAndContext swift_task_create_group_future_common(
591591
TaskOptionRecord *options,
592592
const Metadata *futureResultType,
593593
FutureAsyncSignature::FunctionType *function, void *closureContext,
594-
bool isAsyncLetTask,
595594
size_t initialContextSize);
596595

597596
AsyncTaskAndContext
@@ -630,7 +629,6 @@ AsyncTaskAndContext swift::swift_task_create_group_future_f(
630629
options,
631630
futureResultType,
632631
function, /*closureContext=*/nullptr,
633-
/*isAsyncLetTask=*/false,
634632
initialContextSize);
635633
}
636634

@@ -670,12 +668,11 @@ AsyncTaskAndContext swift::swift_task_create_future(
670668
options,
671669
futureResultType,
672670
taskEntry, closureContext,
673-
/*isAsyncLetTask*/false,
674671
initialContextSize);
675672
}
676673

677674
AsyncTaskAndContext swift::swift_task_create_async_let_future(
678-
size_t flags,
675+
size_t rawFlags,
679676
TaskOptionRecord *options,
680677
const Metadata *futureResultType,
681678
void *closureEntry, void *closureContext) {
@@ -687,13 +684,14 @@ AsyncTaskAndContext swift::swift_task_create_async_let_future(
687684
SpecialPointerAuthDiscriminators::AsyncFutureFunction
688685
>(closureEntry, (HeapObject *)closureContext);
689686

687+
JobFlags flags(rawFlags);
688+
flags.task_setIsAsyncLetTask(true);
690689
return swift_task_create_group_future_common(
691-
flags,
690+
flags.getOpaqueValue(),
692691
/*group*/nullptr,
693692
options,
694693
futureResultType,
695694
taskEntry, closureContext,
696-
/*isAsyncLetTask*/true,
697695
initialContextSize);
698696
}
699697

@@ -718,7 +716,6 @@ swift::swift_task_create_group_future(
718716
options,
719717
futureResultType,
720718
taskEntry, closureContext,
721-
/*isAsyncLetTask*/false,
722719
initialContextSize);
723720
}
724721

0 commit comments

Comments
 (0)