Skip to content

Commit ac2379b

Browse files
committed
[stdlib] SE-0472: Rename Task and*TaskGroup APIs to match the proposal
`Task.startSynchronously` -> `Task.immediate` `*TaskGroup.startTaskSynchronously{UnlessCancelled}` -> `*TaskGroup.addImmediateTask{UnlessCancelled}`
1 parent 024dbd0 commit ac2379b

File tree

12 files changed

+116
-116
lines changed

12 files changed

+116
-116
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_subdirectory(InternalShims)
22

33
gyb_expand(TaskGroup+addTask.swift.gyb TaskGroup+addTask.swift)
4-
gyb_expand(Task+startSynchronously.swift.gyb Task+startSynchronously.swift)
4+
gyb_expand(Task+immediate.swift.gyb Task+immediate.swift)
55

66
add_library(swift_Concurrency
77
Actor.cpp
@@ -97,7 +97,7 @@ add_library(swift_Concurrency
9797
TaskSleep.swift
9898
TaskSleepDuration.swift
9999
"${CMAKE_CURRENT_BINARY_DIR}/TaskGroup+addTask.swift"
100-
"${CMAKE_CURRENT_BINARY_DIR}/Task+startSynchronously.swift")
100+
"${CMAKE_CURRENT_BINARY_DIR}/Task+immediate.swift")
101101

102102
include(${SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR}.cmake)
103103
target_compile_definitions(swift_Concurrency PRIVATE

include/swift/ABI/Executor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class SerialExecutorRef {
7777
/// Executor that may need to participate in complex "same context" checks,
7878
/// by invoking `isSameExclusiveExecutionContext` when comparing execution contexts.
7979
ComplexEquality = 0b01,
80-
/// Mark this executor as the one used by `Task.startSynchronously`,
80+
/// Mark this executor as the one used by `Task.immediate`,
8181
/// It cannot participate in switching.
8282
// TODO: Perhaps make this a generic "cannot switch" rather than start synchronously specific.
83-
StartSynchronously = 0b10,
83+
Immediate = 0b10,
8484
};
8585

8686
static_assert(static_cast<uintptr_t>(ExecutorKind::Ordinary) == 0);
@@ -107,12 +107,12 @@ class SerialExecutorRef {
107107

108108
static SerialExecutorRef forSynchronousStart() {
109109
auto wtable = reinterpret_cast<uintptr_t>(nullptr) |
110-
static_cast<uintptr_t>(ExecutorKind::StartSynchronously);
110+
static_cast<uintptr_t>(ExecutorKind::Immediate);
111111
return SerialExecutorRef(nullptr, wtable);
112112
}
113113
bool isForSynchronousStart() const {
114114
return getIdentity() == nullptr &&
115-
getExecutorKind() == ExecutorKind::StartSynchronously;
115+
getExecutorKind() == ExecutorKind::Immediate;
116116
}
117117

118118
/// Given a pointer to a serial executor and its SerialExecutor

include/swift/ABI/MetadataValues.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,7 @@ class TaskCreateFlags : public FlagSet<size_t> {
27462746
///
27472747
/// Supported starting in Swift 6.1.
27482748
Task_IsTaskFunctionConsumed = 15,
2749-
Task_IsStartSynchronouslyTask = 16,
2749+
Task_IsImmediateTask = 16,
27502750
};
27512751

27522752
explicit constexpr TaskCreateFlags(size_t bits) : FlagSet(bits) {}
@@ -2779,9 +2779,9 @@ class TaskCreateFlags : public FlagSet<size_t> {
27792779
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsTaskFunctionConsumed,
27802780
isTaskFunctionConsumed,
27812781
setIsTaskFunctionConsumed)
2782-
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsStartSynchronouslyTask,
2783-
isSynchronousStartTask,
2784-
setIsSYnchronousStartTask)
2782+
FLAGSET_DEFINE_FLAG_ACCESSORS(Task_IsImmediateTask,
2783+
isImmediateTask,
2784+
setIsImmediateTask)
27852785
};
27862786

27872787
/// Flags for schedulable jobs.

include/swift/Runtime/Concurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
10631063
void swift_task_startOnMainActor(AsyncTask* job);
10641064

10651065
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
1066-
void swift_task_startSynchronously(AsyncTask* job, SerialExecutorRef targetExecutor);
1066+
void swift_task_immediate(AsyncTask* job, SerialExecutorRef targetExecutor);
10671067

10681068
/// Donate this thread to the global executor until either the
10691069
/// given condition returns true or we've run out of cooperative

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ OVERRIDE_TASK(task_startOnMainActor, void,
439439
swift::, (AsyncTask *task), (task))
440440

441441
// In ACTOR since we need ExecutorTracking info
442-
OVERRIDE_ACTOR(task_startSynchronously, void,
442+
OVERRIDE_ACTOR(task_immediate, void,
443443
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
444444
swift::, (AsyncTask *task, SerialExecutorRef targetExecutor),
445445
(task, targetExecutor))

stdlib/public/Concurrency/Actor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,8 +2511,8 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
25112511

25122512
SWIFT_CC(swift)
25132513
static void
2514-
swift_task_startSynchronouslyImpl(AsyncTask *task,
2515-
SerialExecutorRef targetExecutor) {
2514+
swift_task_immediateImpl(AsyncTask *task,
2515+
SerialExecutorRef targetExecutor) {
25162516
swift_retain(task);
25172517
if (targetExecutor.isGeneric()) {
25182518
// If the target is generic, it means that the closure did not specify
@@ -2526,7 +2526,7 @@ swift_task_startSynchronouslyImpl(AsyncTask *task,
25262526
_swift_task_setCurrent(originalTask);
25272527
} else {
25282528
assert(swift_task_isCurrentExecutor(targetExecutor) &&
2529-
"startSynchronously must only be invoked when it is correctly in "
2529+
"'immediate' must only be invoked when it is correctly in "
25302530
"the same isolation already, but wasn't!");
25312531

25322532
// We can run synchronously, we're on the expected executor so running in

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
223223

224224
GYB_SOURCES
225225
TaskGroup+addTask.swift.gyb
226-
Task+startSynchronously.swift.gyb
226+
Task+immediate.swift.gyb
227227

228228
SWIFT_MODULE_DEPENDS ${SWIFT_CONCURRENCY_DEPENDENCIES}
229229
SWIFT_MODULE_DEPENDS_ANDROID Android

stdlib/public/Concurrency/Task+startSynchronously.swift.gyb renamed to stdlib/public/Concurrency/Task+immediate.swift.gyb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414
@_implementationOnly import SwiftConcurrencyInternalShims
1515

16-
// ==== Task.startSynchronously ------------------------------------------------
16+
// ==== Task.immediate ---------------------------------------------------------
1717

1818
% METHOD_VARIANTS = [
1919
% 'THROWING',
@@ -56,11 +56,11 @@ extension Task where Failure == ${FAILURE_TYPE} {
5656
/// - Returns: A reference to the unstructured task which may be awaited on.
5757
@available(SwiftStdlib 6.2, *)
5858
@discardableResult
59-
public static func startSynchronously(
59+
public static func immediate(
6060
name: String? = nil,
6161
priority: TaskPriority? = nil,
6262
% # NOTE: This closure cannot be 'sending' because we'll trigger ' pattern that the region based isolation checker does not understand how to check'
63-
% # In this case: `func syncOnMyGlobalActor() { Task.startSynchronously { @MyGlobalActor in } }`
63+
% # In this case: `func syncOnMyGlobalActor() { Task.immediate { @MyGlobalActor in } }`
6464
@_implicitSelfCapture _ operation: __owned @isolated(any) @escaping () async throws -> Success
6565
) -> Task<Success, ${FAILURE_TYPE}> {
6666

@@ -109,7 +109,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
109109
}
110110

111111
if canRunSynchronously {
112-
_startTaskSynchronously(task!, targetExecutor: builtinSerialExecutor)
112+
_startTaskImmediately(task!, targetExecutor: builtinSerialExecutor)
113113
}
114114
return Task<Success, ${FAILURE_TYPE}>(task!)
115115
}
@@ -121,35 +121,35 @@ GROUP_AND_OP_INFO = [
121121
(
122122
'TaskGroup',
123123
[
124-
'startTaskSynchronously',
125-
'startTaskSynchronouslyUnlessCancelled'
124+
'addImmediateTask',
125+
'addImmediateTaskUnlessCancelled'
126126
],
127127
'',
128128
'ChildTaskResult'
129129
),
130130
(
131131
'ThrowingTaskGroup',
132132
[
133-
'startTaskSynchronously',
134-
'startTaskSynchronouslyUnlessCancelled'
133+
'addImmediateTask',
134+
'addImmediateTaskUnlessCancelled'
135135
],
136136
'throws ',
137137
'ChildTaskResult'
138138
),
139139
(
140140
'DiscardingTaskGroup',
141141
[
142-
'startTaskSynchronously',
143-
'startTaskSynchronouslyUnlessCancelled'
142+
'addImmediateTask',
143+
'addImmediateTaskUnlessCancelled'
144144
],
145145
'',
146146
'Void'
147147
),
148148
(
149149
'ThrowingDiscardingTaskGroup',
150150
[
151-
'startTaskSynchronously',
152-
'startTaskSynchronouslyUnlessCancelled'
151+
'addImmediateTask',
152+
'addImmediateTaskUnlessCancelled'
153153
],
154154
'throws ',
155155
'Void'
@@ -204,7 +204,7 @@ extension ${GROUP_TYPE} {
204204
taskGroup: self._group,
205205
operation: operation
206206
)
207-
_startTaskSynchronously(task, targetExecutor: builtinSerialExecutor)
207+
_startTaskImmediately(task, targetExecutor: builtinSerialExecutor)
208208
}
209209
}
210210
% end # METHOD_NAMES
@@ -264,5 +264,5 @@ extension Task where Failure == ${FAILURE_TYPE} {
264264
@_silgen_name("swift_task_startOnMainActor")
265265
internal func _startTaskOnMainActor(_ task: Builtin.NativeObject)
266266

267-
@_silgen_name("swift_task_startSynchronously")
268-
internal func _startTaskSynchronously(_ task: Builtin.NativeObject, targetExecutor: Builtin.Executor?)
267+
@_silgen_name("swift_task_immediate")
268+
internal func _startTaskImmediately(_ task: Builtin.NativeObject, targetExecutor: Builtin.Executor?)

0 commit comments

Comments
 (0)