Skip to content

Commit 95a420a

Browse files
committed
cleanup
1 parent efa6495 commit 95a420a

15 files changed

+87
-226
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ function(add_swift_target_library name)
18101810
if (SWIFTLIB_IS_STDLIB)
18111811
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-warn-implicit-overrides")
18121812
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-ossa-modules")
1813-
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-lexical-lifetimes=true") # FIXME: undo this
1813+
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-lexical-lifetimes=false")
18141814
endif()
18151815

18161816
if(NOT SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER AND NOT BUILD_STANDALONE AND

stdlib/public/BackDeployConcurrency/Actor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ JobPriority swift::swift_task_getCurrentThreadPriority() {
285285
SWIFT_CC(swift)
286286
static bool swift_task_isCurrentExecutorImpl(ExecutorRef executor) {
287287
if (auto currentTracking = ExecutorTrackingInfo::current()) {
288-
currentTracking->getActiveExecutor().getIdentity(),
289-
currentTracking->getActiveExecutor().isMainExecutor() ? "y" : "n",
290-
currentTracking->getActiveExecutor().isDefaultActor() ? "y" : "n");
291288
return currentTracking->getActiveExecutor() == executor;
292289
}
293290

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static bool swift_task_isCurrentExecutorImpl(ExecutorRef executor) {
301301
return currentTracking->getActiveExecutor() == executor;
302302
}
303303

304-
// TODO(ktoso): checking the "is main thread" is not correct, main executor can be not main thread
304+
// TODO(ktoso): checking the "is main thread" is not correct, main executor can be not main thread, relates to rdar://106188692
305305
return executor.isMainExecutor() && isExecutingOnMainThread();
306306
}
307307

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
107107
UncheckedContinuation.swift
108108
GlobalActor.swift
109109
MainActor.swift
110-
Job.swift
110+
PartialAsyncTask.swift
111111
SourceCompatibilityShims.swift
112112
Task.cpp
113113
Task.swift
@@ -150,7 +150,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
150150
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
151151
-parse-stdlib
152152
-Xfrontend -enable-experimental-concurrency
153-
-Xfrontend -enable-experimental-move-only # FIXME: REMOVE THIS
154153
-diagnostic-style swift
155154
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
156155
${swift_concurrency_options}

stdlib/public/Concurrency/Executor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import Swift
1515
/// A service that can execute jobs.
1616
@available(SwiftStdlib 5.1, *)
1717
public protocol Executor: AnyObject, Sendable {
18+
1819
@available(*, deprecated, message: "Implement 'enqueue(_: __owned Job)' instead")
20+
@available(SwiftStdlib 5.1, *)
1921
func enqueue(_ job: UnownedJob)
2022

2123
@available(SwiftStdlib 5.9, *)
@@ -43,6 +45,7 @@ public protocol SerialExecutor: Executor {
4345

4446
/// Convert this executor value to the optimized form of borrowed
4547
/// executor references.
48+
@available(SwiftStdlib 5.9, *)
4649
func asUnownedSerialExecutor() -> UnownedSerialExecutor
4750
}
4851

@@ -59,6 +62,7 @@ extension Executor {
5962

6063
@available(SwiftStdlib 5.9, *)
6164
extension SerialExecutor {
65+
@available(SwiftStdlib 5.9, *)
6266
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
6367
UnownedSerialExecutor(ordinary: self)
6468
}
@@ -116,7 +120,7 @@ internal func _getJobTaskId(_ job: UnownedJob) -> UInt64
116120
internal func _enqueueOnExecutor<E>(job unownedJob: UnownedJob, executor: E)
117121
where E: SerialExecutor {
118122
if #available(SwiftStdlib 5.9, *) {
119-
executor.enqueue(Job(context: unownedJob.context))
123+
executor.enqueue(Job(context: unownedJob._context))
120124
} else {
121125
executor.enqueue(unownedJob)
122126
}

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import SwiftShims
3434
/// programming error.
3535
///
3636
/// - Parameter executor: the expected current executor
37-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
37+
@available(SwiftStdlib 5.9, *)
3838
public
3939
func preconditionTaskOnExecutor(
4040
_ executor: some SerialExecutor,
@@ -71,7 +71,7 @@ func preconditionTaskOnExecutor(
7171
/// programming error.
7272
///
7373
/// - Parameter actor: the actor whose serial executor we expect to be the current executor
74-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
74+
@available(SwiftStdlib 5.9, *)
7575
public
7676
func preconditionTaskOnActorExecutor(
7777
_ actor: some Actor,
@@ -108,7 +108,7 @@ func preconditionTaskOnActorExecutor(
108108
/// assumption is a serious programming error.
109109
///
110110
/// - Parameter executor: the expected current executor
111-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
111+
@available(SwiftStdlib 5.9, *)
112112
public
113113
func assertTaskOnExecutor(
114114
_ executor: some SerialExecutor,
@@ -143,7 +143,7 @@ func assertTaskOnExecutor(
143143
///
144144
///
145145
/// - Parameter actor: the actor whose serial executor we expect to be the current executor
146-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
146+
@available(SwiftStdlib 5.9, *)
147147
public
148148
func assertTaskOnActorExecutor(
149149
_ actor: some Actor,
@@ -180,7 +180,7 @@ func assertTaskOnActorExecutor(
180180
/// if another actor uses the same serial executor--by using ``MainActor/sharedUnownedExecutor``
181181
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
182182
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
183-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
183+
@available(SwiftStdlib 5.9, *)
184184
@_unavailableFromAsync(message: "await the call to the @MainActor closure directly")
185185
public
186186
func assumeOnMainActorExecutor<T>(
@@ -218,7 +218,7 @@ func assumeOnMainActorExecutor<T>(
218218
/// if another actor uses the same serial executor--by using that actor's ``Actor/unownedExecutor``
219219
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
220220
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
221-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
221+
@available(SwiftStdlib 5.9, *)
222222
@_unavailableFromAsync(message: "express the closure as an explicit function declared on the specified 'actor' instead")
223223
public
224224
func assumeOnActorExecutor<Act: Actor, T>(

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ internal func _swiftJobRun(_ job: UnownedJob,
2828
///
2929
/// Unless you're implementing a scheduler,
3030
/// you don't generally interact with jobs directly.
31+
///
32+
/// An `UnownedJob` must be eventually run *exactly once* using ``runSynchronously(on:)``.
33+
/// Not doing so is effectively going to leak and "hang" the work that the job represents (e.g. a ``Task``).
3134
@available(SwiftStdlib 5.1, *)
3235
@frozen
3336
public struct UnownedJob: Sendable {
34-
internal var context: Builtin.Job
37+
private var context: Builtin.Job
3538

3639
@usableFromInline
40+
@available(SwiftStdlib 5.9, *)
3741
internal init(context: Builtin.Job) {
3842
self.context = context
3943
}
4044

45+
/// Create an `UnownedJob` whose lifetime must be managed carefully until it is run exactly once.
4146
@available(SwiftStdlib 5.9, *)
4247
public init(_ job: __owned Job) {
4348
self.context = job.context
@@ -50,14 +55,52 @@ public struct UnownedJob: Sendable {
5055
return JobPriority(rawValue: raw)
5156
}
5257

58+
@available(SwiftStdlib 5.9, *)
59+
internal var _context: Builtin.Job {
60+
context
61+
}
62+
63+
/// Deprecated API to run a job on a specific executor.
5364
@_alwaysEmitIntoClient
5465
@inlinable
5566
@available(*, deprecated, renamed: "Job.runSynchronously(on:)")
5667
public func _runSynchronously(on executor: UnownedSerialExecutor) {
57-
_swiftJobRun(self, executor)
68+
_swiftJobRun(self, executor)
69+
}
70+
71+
/// Run this job on the passed in executor.
72+
///
73+
/// This operation runs the job on the calling thread and *blocks* until the job completes.
74+
/// The intended use of this method is for an executor to determine when and where it
75+
/// wants to run the job and then call this method on it.
76+
///
77+
/// The passed in executor reference is used to establish the executor context for the job,
78+
/// and should be the same executor as the one semantically calling the `runSynchronously` method.
79+
///
80+
/// - Parameter executor: the executor this job will be semantically running on.
81+
@_alwaysEmitIntoClient
82+
@inlinable
83+
public func runSynchronously(on executor: UnownedSerialExecutor) {
84+
_swiftJobRun(self, executor)
5885
}
86+
5987
}
6088

89+
@available(SwiftStdlib 5.9, *)
90+
extension UnownedJob: CustomStringConvertible {
91+
@available(SwiftStdlib 5.9, *)
92+
public var description: String {
93+
let id = _getJobTaskId(self)
94+
/// Tasks are always assigned an unique ID, however some jobs may not have it set,
95+
/// and it appearing as 0 for _different_ jobs may lead to misunderstanding it as
96+
/// being "the same 0 id job", we specifically print 0 (id not set) as nil.
97+
if (id > 0) {
98+
return "\(Self.self)(id: \(id))"
99+
} else {
100+
return "\(Self.self)(id: nil)"
101+
}
102+
}
103+
}
61104

62105
/// A unit of scheduleable work.
63106
///
@@ -75,12 +118,11 @@ public struct Job: Sendable {
75118
}
76119

77120
public init(_ job: UnownedJob) {
78-
self.context = job.context
121+
self.context = job._context
79122
}
80123

81124
public var priority: JobPriority {
82-
// let raw = _swift_concurrency_jobPriority(UnownedJob(context: self.context)) // TODO: do we also surface this or the base priority?
83-
let raw = _taskCurrentPriority(context as! Builtin.NativeObject)
125+
let raw = _swift_concurrency_jobPriority(UnownedJob(context: self.context))
84126
return JobPriority(rawValue: raw)
85127
}
86128

@@ -102,24 +144,21 @@ public struct Job: Sendable {
102144
@available(SwiftStdlib 5.9, *)
103145
extension Job {
104146

105-
/// Run the job synchronously.
147+
/// Run this job on the passed in executor.
106148
///
107-
/// This operation consumes the job, preventing it accidental use after it has ben run.
149+
/// This operation runs the job on the calling thread and *blocks* until the job completes.
150+
/// The intended use of this method is for an executor to determine when and where it
151+
/// wants to run the job and then call this method on it.
108152
///
109-
/// Converting a `Job` to an `UnownedJob` and invoking `runSynchronously` on it multiple times is undefined behavior,
110-
/// as a job can only ever be run once, and must not be accessed after it has been run.
111-
@_alwaysEmitIntoClient
112-
@inlinable
113-
__consuming public func runSynchronously(on executor: some SerialExecutor) {
114-
_swiftJobRun(UnownedJob(self), UnownedSerialExecutor(ordinary: executor))
115-
}
116-
117-
/// Run the job synchronously.
153+
/// The passed in executor reference is used to establish the executor context for the job,
154+
/// and should be the same executor as the one semantically calling the `runSynchronously` method.
118155
///
119156
/// This operation consumes the job, preventing it accidental use after it has ben run.
120157
///
121-
/// Converting a `Job` to an `UnownedJob` and invoking `runSynchronously` on it multiple times is undefined behavior,
158+
/// Converting a `Job` to an ``UnownedJob`` and invoking ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior,
122159
/// as a job can only ever be run once, and must not be accessed after it has been run.
160+
///
161+
/// - Parameter executor: the executor this job will be semantically running on.
123162
@_alwaysEmitIntoClient
124163
@inlinable
125164
__consuming public func runSynchronously(on executor: UnownedSerialExecutor) {

test/Concurrency/Runtime/custom_executors_assume_main_asyncmain.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/Concurrency/Runtime/custom_executors_assume_main_asyncmain_crash.swift

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/Concurrency/Runtime/custom_executors_default.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift( -Xfrontend enable-experimental-move-only -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s
1+
// RUN: %target-run-simple-swift( -Xfrontend -enable-experimental-move-only -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library) | %FileCheck %s
22

33
// REQUIRES: concurrency
44
// REQUIRES: executable_test

0 commit comments

Comments
 (0)