Skip to content

Commit 4fb5f05

Browse files
committed
[Concurrency] More cleanups for futures
1 parent ab932db commit 4fb5f05

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

include/swift/ABI/Task.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,16 @@ class AsyncTask : public HeapObject, public Job {
326326
/// fragment.
327327
static size_t storageOffset(const Metadata *resultType) {
328328
size_t offset = sizeof(FutureFragment);
329-
size_t alignment = std::max(resultType->vw_alignment(), alignof(void *));
329+
size_t alignment =
330+
std::max(resultType->vw_alignment(), alignof(SwiftError *));
330331
return (offset + alignment - 1) & ~(alignment - 1);
331332
}
332333

333334
/// Determine the size of the future fragment given a particular future
334335
/// result type.
335336
static size_t fragmentSize(const Metadata *resultType) {
336337
return storageOffset(resultType) +
337-
std::max(resultType->vw_size(), sizeof(void *));
338+
std::max(resultType->vw_size(), sizeof(SwiftError *));
338339
}
339340
};
340341

@@ -463,7 +464,8 @@ class YieldingAsyncContext : public AsyncContext {
463464
/// task.
464465
///
465466
/// This type matches the ABI of a function `<T> () async throws -> T`, which
466-
/// is used to describe futures.
467+
/// is the type used by `Task.runDetached` and `Task.group.add` to create
468+
/// futures.
467469
class FutureAsyncContext : public AsyncContext {
468470
public:
469471
SwiftError *errorResult = nullptr;

stdlib/public/Concurrency/Task.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ void AsyncTask::completeFuture(AsyncContext *context, ExecutorRef executor) {
103103
// Find the next waiting task.
104104
auto nextWaitingTask = waitingTask->getNextWaitingTask();
105105

106-
// Remove this task from the list.
107-
waitingTask->getNextWaitingTask() = nullptr;
108-
109106
// TODO: schedule this task on the executor rather than running it
110107
// directly.
111108
waitingTask->run(executor);
@@ -198,7 +195,8 @@ AsyncTaskAndContext swift::swift_task_create_future_f(
198195
JobFlags flags, AsyncTask *parent, const Metadata *futureResultType,
199196
AsyncFunctionType<void()> *function, size_t initialContextSize) {
200197
assert((futureResultType != nullptr) == flags.task_isFuture());
201-
assert((futureResultType != nullptr) == flags.task_isFuture());
198+
assert(!flags.task_isFuture() ||
199+
initialContextSize >= sizeof(FutureAsyncContext));
202200
assert((parent != nullptr) == flags.task_isChildTask());
203201

204202
// Figure out the size of the header.

0 commit comments

Comments
 (0)