@@ -48,16 +48,16 @@ class alignas(Alignment_AsyncLet) AsyncLetImpl: public ChildTaskStatusRecord {
48
48
HasResult = 1 << 0 ,
49
49
DidAllocateFromParentTask = 1 << 1 ,
50
50
};
51
-
51
+
52
52
// / The task that was kicked off to initialize this `async let`,
53
53
// / and flags.
54
54
llvm::PointerIntPair<AsyncTask *, 2 , unsigned > taskAndFlags;
55
-
55
+
56
56
// / Reserved space for a future_wait context frame, used during suspensions
57
57
// / on the child task future.
58
58
std::aligned_storage<sizeof (TaskFutureWaitAsyncContext),
59
59
alignof (TaskFutureWaitAsyncContext)>::type futureWaitContextStorage;
60
-
60
+
61
61
friend class ::swift::AsyncTask;
62
62
63
63
public:
@@ -77,43 +77,43 @@ class alignas(Alignment_AsyncLet) AsyncLetImpl: public ChildTaskStatusRecord {
77
77
AsyncTask *getTask () const {
78
78
return taskAndFlags.getPointer ();
79
79
}
80
-
80
+
81
81
bool hasResultInBuffer () const {
82
82
return taskAndFlags.getInt () & HasResult;
83
83
}
84
-
84
+
85
85
void setHasResultInBuffer (bool value = true ) {
86
86
if (value)
87
87
taskAndFlags.setInt (taskAndFlags.getInt () | HasResult);
88
88
else
89
89
taskAndFlags.setInt (taskAndFlags.getInt () & ~HasResult);
90
90
}
91
-
91
+
92
92
bool didAllocateFromParentTask () const {
93
93
return taskAndFlags.getInt () & DidAllocateFromParentTask;
94
94
}
95
-
95
+
96
96
void setDidAllocateFromParentTask (bool value = true ) {
97
97
if (value)
98
98
taskAndFlags.setInt (taskAndFlags.getInt () | DidAllocateFromParentTask);
99
99
else
100
100
taskAndFlags.setInt (taskAndFlags.getInt () & ~DidAllocateFromParentTask);
101
101
}
102
-
102
+
103
103
// The compiler preallocates a large fixed space for the `async let`, with the
104
104
// intent that most of it be used for the child task context. The next two
105
105
// methods return the address and size of that space.
106
-
106
+
107
107
// / Return a pointer to the unused space within the async let block.
108
108
void *getPreallocatedSpace () {
109
109
return (void *)(this + 1 );
110
110
}
111
-
111
+
112
112
// / Return the size of the unused space within the async let block.
113
113
static constexpr size_t getSizeOfPreallocatedSpace () {
114
114
return sizeof (AsyncLet) - sizeof (AsyncLetImpl);
115
115
}
116
-
116
+
117
117
TaskFutureWaitAsyncContext *getFutureContext () {
118
118
return reinterpret_cast <TaskFutureWaitAsyncContext*>(&futureWaitContextStorage);
119
119
}
@@ -149,11 +149,11 @@ void swift::asyncLet_addImpl(AsyncTask *task, AsyncLet *asyncLet,
149
149
150
150
// ok, now that the async let task actually is initialized: attach it to the
151
151
// current task
152
- bool addedRecord =
153
- addStatusRecord (record, [&](ActiveTaskStatus parentStatus, ActiveTaskStatus& newStatus) {
154
- updateNewChildWithParentAndGroupState (task, parentStatus, NULL );
155
- return true ;
156
- });
152
+ bool addedRecord = addStatusRecordToSelf (record,
153
+ [&](ActiveTaskStatus parentStatus, ActiveTaskStatus& newStatus) {
154
+ updateNewChildWithParentAndGroupState (task, parentStatus, NULL );
155
+ return true ;
156
+ });
157
157
(void )addedRecord;
158
158
assert (addedRecord);
159
159
}
@@ -279,13 +279,13 @@ static void _asyncLet_get_throwing_continuation(
279
279
SWIFT_CONTEXT void *error) {
280
280
auto continuationContext = static_cast <AsyncLetContinuationContext*>(callContext);
281
281
auto alet = continuationContext->alet ;
282
-
282
+
283
283
// If the future completed successfully, its result is now in the async let
284
284
// buffer.
285
285
if (!error) {
286
286
asImpl (alet)->setHasResultInBuffer ();
287
287
}
288
-
288
+
289
289
// Continue the caller's execution.
290
290
auto throwingResume
291
291
= reinterpret_cast <ThrowingTaskFutureWaitContinuationFunction*>(callContext->ResumeParent );
@@ -303,14 +303,14 @@ static void swift_asyncLet_get_throwingImpl(
303
303
if (asImpl (alet)->hasResultInBuffer ()) {
304
304
return resumeFunction (callerContext, nullptr );
305
305
}
306
-
306
+
307
307
auto aletContext = static_cast <AsyncLetContinuationContext*>(callContext);
308
308
aletContext->ResumeParent
309
309
= reinterpret_cast <TaskContinuationFunction*>(resumeFunction);
310
310
aletContext->Parent = callerContext;
311
311
aletContext->alet = alet;
312
312
auto futureContext = asImpl (alet)->getFutureContext ();
313
-
313
+
314
314
// Unlike the non-throwing variant, whether we end up with a result depends
315
315
// on the success of the task. If we raise an error, then the result buffer
316
316
// will not be populated. Save the async let binding so we can fetch it
@@ -375,7 +375,7 @@ static void asyncLet_finish_after_task_completion(SWIFT_ASYNC_CONTEXT AsyncConte
375
375
if (alet->didAllocateFromParentTask ()) {
376
376
swift_task_dealloc (task);
377
377
}
378
-
378
+
379
379
return reinterpret_cast <ThrowingTaskFutureWaitContinuationFunction*>(resumeFunction)
380
380
(callerContext, error);
381
381
}
@@ -390,7 +390,7 @@ static void _asyncLet_finish_continuation(
390
390
= reinterpret_cast <AsyncLetContinuationContext*>(callContext);
391
391
auto alet = continuationContext->alet ;
392
392
auto resultBuffer = continuationContext->resultBuffer ;
393
-
393
+
394
394
// Destroy the error, or the result that was stored to the buffer.
395
395
if (error) {
396
396
swift_errorRelease ((SwiftError*)error);
@@ -436,7 +436,7 @@ static void swift_asyncLet_finishImpl(SWIFT_ASYNC_CONTEXT AsyncContext *callerCo
436
436
aletContext->alet = alet;
437
437
aletContext->resultBuffer = reinterpret_cast <OpaqueValue*>(resultBuffer);
438
438
auto futureContext = asImpl (alet)->getFutureContext ();
439
-
439
+
440
440
// TODO: It would be nice if we could await the future without having to
441
441
// provide a buffer to store the value to, since we're going to dispose of
442
442
// it anyway.
@@ -504,7 +504,7 @@ static void _asyncLet_consume_throwing_continuation(
504
504
// Get the async let pointer so we can destroy the task.
505
505
auto continuationContext = static_cast <AsyncLetContinuationContext*>(callContext);
506
506
auto alet = continuationContext->alet ;
507
-
507
+
508
508
return asyncLet_finish_after_task_completion (callContext->Parent ,
509
509
alet,
510
510
callContext->ResumeParent ,
@@ -528,14 +528,14 @@ static void swift_asyncLet_consume_throwingImpl(
528
528
callContext,
529
529
nullptr );
530
530
}
531
-
531
+
532
532
auto aletContext = static_cast <AsyncLetContinuationContext*>(callContext);
533
533
aletContext->ResumeParent
534
534
= reinterpret_cast <TaskContinuationFunction*>(resumeFunction);
535
535
aletContext->Parent = callerContext;
536
536
aletContext->alet = alet;
537
537
auto futureContext = asImpl (alet)->getFutureContext ();
538
-
538
+
539
539
// Unlike the non-throwing variant, whether we end up with a result depends
540
540
// on the success of the task. If we raise an error, then the result buffer
541
541
// will not be populated. Save the async let binding so we can fetch it
0 commit comments