Skip to content

Commit 3854e61

Browse files
authored
Merge pull request #81428 from xedin/rename-some-task-apis
[stdlib] SE-0472: Rename `Task` and`*TaskGroup` APIs to match the pro…
2 parents d1adc24 + 99d810a commit 3854e61

File tree

14 files changed

+151
-140
lines changed

14 files changed

+151
-140
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: 26 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',
@@ -32,6 +32,17 @@ import Swift
3232
@available(SwiftStdlib 6.2, *)
3333
extension Task where Failure == ${FAILURE_TYPE} {
3434

35+
@available(SwiftStdlib 6.2, *)
36+
@available(*, deprecated, renamed: "immediate")
37+
@discardableResult
38+
public static func startSynchronously(
39+
name: String? = nil,
40+
priority: TaskPriority? = nil,
41+
@_implicitSelfCapture _ operation: __owned @isolated(any) @escaping () async throws -> Success
42+
) -> Task<Success, ${FAILURE_TYPE}> {
43+
immediate(name: name, priority: priority, operation)
44+
}
45+
3546
/// Create and immediately start running a new task in the context of the calling thread/task.
3647
///
3748
/// This function _starts_ the created task on the calling context.
@@ -56,11 +67,11 @@ extension Task where Failure == ${FAILURE_TYPE} {
5667
/// - Returns: A reference to the unstructured task which may be awaited on.
5768
@available(SwiftStdlib 6.2, *)
5869
@discardableResult
59-
public static func startSynchronously(
70+
public static func immediate(
6071
name: String? = nil,
6172
priority: TaskPriority? = nil,
6273
% # 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 } }`
74+
% # In this case: `func syncOnMyGlobalActor() { Task.immediate { @MyGlobalActor in } }`
6475
@_implicitSelfCapture _ operation: __owned @isolated(any) @escaping () async throws -> Success
6576
) -> Task<Success, ${FAILURE_TYPE}> {
6677

@@ -109,7 +120,7 @@ extension Task where Failure == ${FAILURE_TYPE} {
109120
}
110121

111122
if canRunSynchronously {
112-
_startTaskSynchronously(task!, targetExecutor: builtinSerialExecutor)
123+
_startTaskImmediately(task!, targetExecutor: builtinSerialExecutor)
113124
}
114125
return Task<Success, ${FAILURE_TYPE}>(task!)
115126
}
@@ -121,35 +132,35 @@ GROUP_AND_OP_INFO = [
121132
(
122133
'TaskGroup',
123134
[
124-
'startTaskSynchronously',
125-
'startTaskSynchronouslyUnlessCancelled'
135+
'addImmediateTask',
136+
'addImmediateTaskUnlessCancelled'
126137
],
127138
'',
128139
'ChildTaskResult'
129140
),
130141
(
131142
'ThrowingTaskGroup',
132143
[
133-
'startTaskSynchronously',
134-
'startTaskSynchronouslyUnlessCancelled'
144+
'addImmediateTask',
145+
'addImmediateTaskUnlessCancelled'
135146
],
136147
'throws ',
137148
'ChildTaskResult'
138149
),
139150
(
140151
'DiscardingTaskGroup',
141152
[
142-
'startTaskSynchronously',
143-
'startTaskSynchronouslyUnlessCancelled'
153+
'addImmediateTask',
154+
'addImmediateTaskUnlessCancelled'
144155
],
145156
'',
146157
'Void'
147158
),
148159
(
149160
'ThrowingDiscardingTaskGroup',
150161
[
151-
'startTaskSynchronously',
152-
'startTaskSynchronouslyUnlessCancelled'
162+
'addImmediateTask',
163+
'addImmediateTaskUnlessCancelled'
153164
],
154165
'throws ',
155166
'Void'
@@ -204,7 +215,7 @@ extension ${GROUP_TYPE} {
204215
taskGroup: self._group,
205216
operation: operation
206217
)
207-
_startTaskSynchronously(task, targetExecutor: builtinSerialExecutor)
218+
_startTaskImmediately(task, targetExecutor: builtinSerialExecutor)
208219
}
209220
}
210221
% end # METHOD_NAMES
@@ -264,5 +275,5 @@ extension Task where Failure == ${FAILURE_TYPE} {
264275
@_silgen_name("swift_task_startOnMainActor")
265276
internal func _startTaskOnMainActor(_ task: Builtin.NativeObject)
266277

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

0 commit comments

Comments
 (0)