Skip to content

Commit c4b8470

Browse files
committed
fix adding pending count in gyb
1 parent fc544df commit c4b8470

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,8 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
739739
case TaskOptionRecordKind::InitialTaskExecutorUnowned:
740740
taskExecutor = cast<InitialTaskExecutorRefPreferenceTaskOptionRecord>(option)
741741
->getExecutorRef();
742-
if (taskExecutor.isDefined()) {
743-
jobFlags.task_setHasInitialTaskExecutorPreference(true);
744-
taskExecutorIsOwned = false;
745-
}
742+
taskExecutorIsOwned = false;
743+
jobFlags.task_setHasInitialTaskExecutorPreference(true);
746744
break;
747745

748746
case TaskOptionRecordKind::InitialTaskExecutorOwned:
@@ -751,10 +749,8 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
751749
#else
752750
taskExecutor = cast<InitialTaskExecutorOwnedPreferenceTaskOptionRecord>(option)
753751
->getExecutorRefFromUnownedTaskExecutor();
754-
if (taskExecutor.isDefined()) {
755-
taskExecutorIsOwned = true;
756-
jobFlags.task_setHasInitialTaskExecutorPreference(true);
757-
}
752+
taskExecutorIsOwned = true;
753+
jobFlags.task_setHasInitialTaskExecutorPreference(true);
758754
#endif
759755
break;
760756

@@ -1136,7 +1132,6 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
11361132
task->_private().Local.initializeLinkParent(task, parent);
11371133
}
11381134

1139-
// FIXME: add discarding flag
11401135
concurrency::trace::task_create(
11411136
task, parent, group, asyncLet,
11421137
static_cast<uint8_t>(task->Flags.getPriority()),

stdlib/public/Concurrency/TaskGroup+addTask.swift.gyb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
import Swift
1414

15-
// In the task-to-thread model we don't enqueue tasks created using addTask
16-
// to the global pool, but will run them inline instead.
17-
#if SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
18-
@usableFromInline
19-
let __addTaskMustEnqueueJobOnCreate = false
20-
#else
21-
@usableFromInline
22-
let __addTaskMustEnqueueJobOnCreate = true
23-
#endif
24-
2515
// ==== addTask / addTaskUnlessCancelled ---------------------------------------
2616
% # Generate:
2717
% # - both method kinds (2)
@@ -137,6 +127,7 @@ let __addTaskMustEnqueueJobOnCreate = true
137127
%
138128
% IS_ADD_UNLESS_CANCELLED = METHOD_NAME == "addTaskUnlessCancelled"
139129
% IS_IMPL_UNAVAILABLE = any('Unavailable in task-to-thread' in av for av in ALL_AVAILABILITY)
130+
% IS_TASK_TO_THREAD_MODEL = 'SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY' == IFDEF
140131
%
141132
% HAS_TASK_PRIORITY = any('priority:' in param for param in PARAMS)
142133
% HAS_TASK_NAME = any('name:' in param for param in PARAMS)
@@ -205,8 +196,14 @@ extension ${TYPE} {
205196
isChildTask: true,
206197
copyTaskLocals: false,
207198
inheritContext: false,
208-
enqueueJob: true,
209-
addPendingGroupTaskUnconditionally: ${str(not IS_ADD_UNLESS_CANCELLED).lower()}, // FIXME: just always true?
199+
enqueueJob: ${'false' if IS_TASK_TO_THREAD_MODEL else 'true'},
200+
% if IS_ADD_UNLESS_CANCELLED:
201+
% # In this case, we already added the pending task count before we create the task
202+
% # so we must not add to the pending counter again.
203+
addPendingGroupTaskUnconditionally: false,
204+
% else:
205+
addPendingGroupTaskUnconditionally: true,
206+
% end
210207
isDiscardingTask: ${str(IS_DISCARDING).lower()}
211208
)
212209

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,12 @@ struct AsyncTask::PrivateStorage {
796796
// here, before the task-local storage elements are destroyed; in order to
797797
// respect stack-discipline of the task-local allocator.
798798
{
799-
800-
if (task->hasInitialTaskExecutorPreferenceRecord()) {
801-
task->dropInitialTaskExecutorPreferenceRecord();
802-
}
803-
804799
if (task->hasInitialTaskNameRecord()) {
805800
task->dropInitialTaskNameRecord();
806801
}
802+
if (task->hasInitialTaskExecutorPreferenceRecord()) {
803+
task->dropInitialTaskExecutorPreferenceRecord();
804+
}
807805
}
808806

809807
// Drain unlock the task and remove any overrides on thread as a

test/Concurrency/async_main.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ func asyncFunc() async {
7171
// CHECK-SIL-NEXT: [[GROUP:%.*]] = enum $Optional<Builtin.RawPointer>, #Optional.none
7272
// CHECK-SIL-NEXT: [[TASK_EXECUTOR_UNOWNED:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none
7373
// CHECK-SIL-NEXT: [[TASK_EXECUTOR_OWNED:%.*]] = enum $Optional<any TaskExecutor>, #Optional.none
74+
// CHECK-SIL-NEXT: [[TASK_NAME:%.*]] = enum $Optional<Builtin.RawPointer>, #Optional.none
7475
// CHECK-SIL-NEXT: // function_ref thunk for @escaping @convention(thin) @async () -> ()
7576
// CHECK-SIL-NEXT: [[THUNK_FN:%.*]] = function_ref @$sIetH_yts5Error_pIegHrzo_TR : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error)
7677
// CHECK-SIL-NEXT: [[THUNK:%.*]] = partial_apply [callee_guaranteed] [[THUNK_FN]]([[ASYNC_MAIN_FN]]) : $@convention(thin) @async (@convention(thin) @async () -> ()) -> (@out (), @error any Error)
7778
// CHECK-SIL-NEXT: [[CONVERTED_THUNK:%.*]] = convert_function [[THUNK]] : $@async @callee_guaranteed () -> (@out (), @error any Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>
78-
// CHECK-SIL-NEXT: [[TASK_RESULT:%.*]] = builtin "createAsyncTask"<()>([[FLAGS]] : $Int, [[OPT_SERIAL_EXECUTOR]] : $Optional<Builtin.Executor>, [[GROUP]] : $Optional<Builtin.RawPointer>, [[TASK_EXECUTOR_UNOWNED]] : $Optional<Builtin.Executor>, [[TASK_EXECUTOR_OWNED]] : $Optional<any TaskExecutor>, [[CONVERTED_THUNK]] : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
79+
// CHECK-SIL-NEXT: [[TASK_RESULT:%.*]] = builtin "createAsyncTask"<()>([[FLAGS]] : $Int, [[OPT_SERIAL_EXECUTOR]] : $Optional<Builtin.Executor>, [[GROUP]] : $Optional<Builtin.RawPointer>, [[TASK_EXECUTOR_UNOWNED]] : $Optional<Builtin.Executor>, [[TASK_EXECUTOR_OWNED]] : $Optional<any TaskExecutor>, [[TASK_NAME]] : $Optional<Builtin.RawPointer>, [[CONVERTED_THUNK]] : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
7980
// CHECK-SIL-NEXT: [[TASK:%.*]] = tuple_extract [[TASK_RESULT]] : $(Builtin.NativeObject, Builtin.RawPointer), 0
8081
// CHECK-SIL-NEXT: // function_ref swift_job_run
8182
// CHECK-SIL-NEXT: [[RUN_FN:%.*]] = function_ref @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()

0 commit comments

Comments
 (0)