Skip to content

Commit 80b9386

Browse files
authored
[Concurrency] Rename Job to ExecutorJob, ease transition with typealias (#65006)
1 parent 4de53fc commit 80b9386

File tree

7 files changed

+44
-30
lines changed

7 files changed

+44
-30
lines changed

include/swift/AST/KnownSDKTypes.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ KNOWN_SDK_TYPE_DECL(ObjectiveC, ObjCBool, StructDecl, 0)
3939
// standardized
4040
KNOWN_SDK_TYPE_DECL(Concurrency, UnsafeContinuation, NominalTypeDecl, 2)
4141
KNOWN_SDK_TYPE_DECL(Concurrency, MainActor, NominalTypeDecl, 0)
42-
KNOWN_SDK_TYPE_DECL(Concurrency, Job, StructDecl, 0)
42+
KNOWN_SDK_TYPE_DECL(Concurrency, Job, StructDecl, 0) // TODO: remove in favor of ExecutorJob
43+
KNOWN_SDK_TYPE_DECL(Concurrency, ExecutorJob, StructDecl, 0)
4344
KNOWN_SDK_TYPE_DECL(Concurrency, UnownedJob, StructDecl, 0)
4445
KNOWN_SDK_TYPE_DECL(Concurrency, Executor, NominalTypeDecl, 0)
4546
KNOWN_SDK_TYPE_DECL(Concurrency, SerialExecutor, NominalTypeDecl, 0)

lib/Sema/TypeCheckConcurrency.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
12661266
auto module = nominal->getParentModule();
12671267
Type nominalTy = nominal->getDeclaredInterfaceType();
12681268

1269-
// enqueue(_: UnownedJob)
1269+
// enqueue(_:)
12701270
auto enqueueDeclName = DeclName(C, DeclBaseName(C.Id_enqueue), { Identifier() });
12711271

12721272
FuncDecl *unownedEnqueueRequirement = nullptr;
@@ -1283,8 +1283,16 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
12831283
if (funcDecl->getParameters()->size() != 1)
12841284
continue;
12851285
if (auto param = funcDecl->getParameters()->front()) {
1286-
if (C.getJobDecl() &&
1287-
param->getType()->isEqual(C.getJobDecl()->getDeclaredInterfaceType())) {
1286+
StructDecl* jobDecl;
1287+
if (auto decl = C.getExecutorJobDecl()) {
1288+
jobDecl = decl;
1289+
} else if (auto decl = C.getJobDecl()) {
1290+
// old standard library, before we introduced the `typealias Job = ExecutorJob`
1291+
jobDecl = decl;
1292+
}
1293+
1294+
if (jobDecl &&
1295+
param->getType()->isEqual(jobDecl->getDeclaredInterfaceType())) {
12881296
assert(moveOnlyEnqueueRequirement == nullptr);
12891297
moveOnlyEnqueueRequirement = funcDecl;
12901298
} else if (param->getType()->isEqual(C.getUnownedJobDecl()->getDeclaredInterfaceType())) {

stdlib/public/Concurrency/Executor.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ import Swift
1717
public protocol Executor: AnyObject, Sendable {
1818

1919
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
20-
@available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
21-
@available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
22-
@available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
23-
@available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
20+
@available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
21+
@available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
22+
@available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
23+
@available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
2424
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
2525
func enqueue(_ job: UnownedJob)
2626

2727
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
2828
@available(SwiftStdlib 5.9, *)
29-
func enqueue(_ job: __owned Job)
29+
func enqueue(_ job: __owned ExecutorJob)
3030
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
3131
}
3232

@@ -39,10 +39,10 @@ public protocol SerialExecutor: Executor {
3939
// work-scheduling operation.
4040
@_nonoverride
4141
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
42-
@available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
43-
@available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
44-
@available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
45-
@available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
42+
@available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
43+
@available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
44+
@available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
45+
@available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned ExecutorJob)' instead")
4646
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4747
func enqueue(_ job: UnownedJob)
4848

@@ -53,7 +53,7 @@ public protocol SerialExecutor: Executor {
5353
// work-scheduling operation.
5454
@_nonoverride
5555
@available(SwiftStdlib 5.9, *)
56-
func enqueue(_ job: __owned Job)
56+
func enqueue(_ job: __owned ExecutorJob)
5757
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
5858

5959
/// Convert this executor value to the optimized form of borrowed
@@ -87,10 +87,10 @@ public protocol SerialExecutor: Executor {
8787
@available(SwiftStdlib 5.9, *)
8888
extension Executor {
8989
public func enqueue(_ job: UnownedJob) {
90-
self.enqueue(Job(job))
90+
self.enqueue(ExecutorJob(job))
9191
}
9292

93-
public func enqueue(_ job: __owned Job) {
93+
public func enqueue(_ job: __owned ExecutorJob) {
9494
self.enqueue(UnownedJob(job))
9595
}
9696
}
@@ -219,10 +219,10 @@ func _checkExpectedExecutor(_filenameStart: Builtin.RawPointer,
219219

220220
/// Primarily a debug utility.
221221
///
222-
/// If the passed in Job is a Task, returns the complete 64bit TaskId,
222+
/// If the passed in ExecutorJob is a Task, returns the complete 64bit TaskId,
223223
/// otherwise returns only the job's 32bit Id.
224224
///
225-
/// - Returns: the Id stored in this Job or Task, for purposes of debug printing
225+
/// - Returns: the Id stored in this ExecutorJob or Task, for purposes of debug printing
226226
@available(SwiftStdlib 5.9, *)
227227
@_silgen_name("swift_task_getJobTaskId")
228228
internal func _getJobTaskId(_ job: UnownedJob) -> UInt64
@@ -250,7 +250,7 @@ internal func _enqueueOnExecutor<E>(job unownedJob: UnownedJob, executor: E)
250250
where E: SerialExecutor {
251251
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
252252
if #available(SwiftStdlib 5.9, *) {
253-
executor.enqueue(Job(context: unownedJob._context))
253+
executor.enqueue(ExecutorJob(context: unownedJob._context))
254254
} else {
255255
executor.enqueue(unownedJob)
256256
}

stdlib/public/Concurrency/PartialAsyncTask.swift

+11-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414
@_implementationOnly import _SwiftConcurrencyShims
1515

16-
// TODO(swift): rename the file to Job.swift eventually, we don't use PartialTask terminology anymore
16+
// TODO(swift): rename the file to ExecutorJob.swift eventually, we don't use PartialTask terminology anymore
1717

1818
@available(SwiftStdlib 5.1, *)
1919
@_silgen_name("swift_job_run")
@@ -65,7 +65,7 @@ public struct UnownedJob: Sendable {
6565
/// Deprecated API to run a job on a specific executor.
6666
@_alwaysEmitIntoClient
6767
@inlinable
68-
@available(*, deprecated, renamed: "Job.runSynchronously(on:)")
68+
@available(*, deprecated, renamed: "ExecutorJob.runSynchronously(on:)")
6969
public func _runSynchronously(on executor: UnownedSerialExecutor) {
7070
_swiftJobRun(self, executor)
7171
}
@@ -105,14 +105,19 @@ extension UnownedJob: CustomStringConvertible {
105105
}
106106

107107
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
108+
109+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
110+
@available(*, deprecated, renamed: "ExecutorJob")
111+
public typealias Job = ExecutorJob
112+
108113
/// A unit of scheduleable work.
109114
///
110115
/// Unless you're implementing a scheduler,
111116
/// you don't generally interact with jobs directly.
112117
@available(SwiftStdlib 5.9, *)
113118
@frozen
114119
@_moveOnly
115-
public struct Job: Sendable {
120+
public struct ExecutorJob: Sendable {
116121
internal var context: Builtin.Job
117122

118123
@usableFromInline
@@ -145,7 +150,7 @@ public struct Job: Sendable {
145150
}
146151

147152
@available(SwiftStdlib 5.9, *)
148-
extension Job {
153+
extension ExecutorJob {
149154

150155
/// Run this job on the passed in executor.
151156
///
@@ -158,7 +163,7 @@ extension Job {
158163
///
159164
/// This operation consumes the job, preventing it accidental use after it has ben run.
160165
///
161-
/// Converting a `Job` to an ``UnownedJob`` and invoking ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior,
166+
/// Converting a `ExecutorJob` to an ``UnownedJob`` and invoking ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior,
162167
/// as a job can only ever be run once, and must not be accessed after it has been run.
163168
///
164169
/// - Parameter executor: the executor this job will be semantically running on.
@@ -182,7 +187,7 @@ extension Job {
182187
/// However, the semantics of how priority is treated are left up to each
183188
/// platform and `Executor` implementation.
184189
///
185-
/// A Job's priority is roughly equivalent to a `TaskPriority`,
190+
/// A ExecutorJob's priority is roughly equivalent to a `TaskPriority`,
186191
/// however, since not all jobs are tasks, represented as separate type.
187192
///
188193
/// Conversions between the two priorities are available as initializers on the respective types.

stdlib/public/Distributed/DistributedDefaultExecutor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal final class DistributedRemoteActorReferenceExecutor: SerialExecutor {
2626
@inlinable
2727
public func enqueue(_ job: __owned Job) {
2828
let jobDescription = job.description
29-
fatalError("Attempted to enqueue \(Job.self) (\(jobDescription)) on executor of remote distributed actor reference!")
29+
fatalError("Attempted to enqueue \(ExecutorJob.self) (\(jobDescription)) on executor of remote distributed actor reference!")
3030
}
3131

3232
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
@@ -50,4 +50,4 @@ public func buildDefaultDistributedRemoteActorExecutor<Act>(
5050
_ actor: Act
5151
) -> UnownedSerialExecutor where Act: DistributedActor {
5252
return DistributedRemoteActorReferenceExecutor.sharedUnownedExecutor
53-
}
53+
}

test/Concurrency/custom_executor_enqueue_impls.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class OldExecutor: SerialExecutor {
2525
/// That's why we do log the deprecation warning, people should use the move-only version.
2626
final class BothExecutor: SerialExecutor {
2727
func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'BothExecutor' to 'Executor' by implementing 'func enqueue(Job)' instead}}
28-
func enqueue(_ job: __owned Job) {}
28+
func enqueue(_ job: __owned ExecutorJob) {}
2929

3030
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
3131
UnownedSerialExecutor(ordinary: self)
@@ -45,7 +45,7 @@ final class NoneExecutor: SerialExecutor { // expected-error{{type 'NoneExecutor
4545

4646
/// Just implementing the new signature causes no warnings, good.
4747
final class NewExecutor: SerialExecutor {
48-
func enqueue(_ job: __owned Job) {} // no warnings
48+
func enqueue(_ job: __owned ExecutorJob) {} // no warnings
4949

5050
func asUnownedSerialExecutor() -> UnownedSerialExecutor {
5151
UnownedSerialExecutor(ordinary: self)

test/Distributed/Runtime/distributed_actor_executor_asserts.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ actor EnqueueTest {
8383
}
8484

8585
tests.test("remote actor reference should have crash-on-enqueue executor") {
86-
expectCrashLater(withMessage: "Attempted to enqueue Job (Job(id: 1)) on executor of remote distributed actor reference!")
86+
expectCrashLater(withMessage: "Attempted to enqueue ExecutorJob (ExecutorJob(id: 1)) on executor of remote distributed actor reference!")
8787
// we do the bad idea of taking an executor from a remote worker
8888
// and then force another actor to run on it; this will cause an enqueue on the "crash on enqueue" executor.
8989
let wrongUse = EnqueueTest(unownedExecutor: normalRemoteWorker.unownedExecutor)

0 commit comments

Comments
 (0)