Skip to content

Commit 1d78bae

Browse files
DougGregortshortli
authored andcommitted
[SE-0392] Back-deploy assertIsolation/assumeIsolation
The assertIsolation/assumeIsolation operations on actors are back-deployable back to the introduction of concurrency. Do so. Resolves rdar://111880539
1 parent 567afb8 commit 1d78bae

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftShims
1818
// ==== -----------------------------------------------------------------------
1919
// MARK: Precondition executors
2020

21-
@available(SwiftStdlib 5.9, *)
21+
@available(SwiftStdlib 5.1, *)
2222
extension SerialExecutor {
2323
/// Unconditionally if the current task is executing on the expected serial executor,
2424
/// and if not crash the program offering information about the executor mismatch.
@@ -35,7 +35,8 @@ extension SerialExecutor {
3535
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
3636
/// never called. Failure to satisfy that assumption is a serious
3737
/// programming error.
38-
@available(SwiftStdlib 5.9, *)
38+
@available(SwiftStdlib 5.1, *)
39+
@backDeployed(before: SwiftStdlib 5.9)
3940
public func preconditionIsolated(
4041
_ message: @autoclosure () -> String = String(),
4142
file: StaticString = #fileID, line: UInt = #line
@@ -54,7 +55,7 @@ extension SerialExecutor {
5455
}
5556
}
5657

57-
@available(SwiftStdlib 5.9, *)
58+
@available(SwiftStdlib 5.1, *)
5859
extension Actor {
5960
/// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
6061
/// and if not crash the program offering information about the executor mismatch.
@@ -71,7 +72,8 @@ extension Actor {
7172
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
7273
/// never called. Failure to satisfy that assumption is a serious
7374
/// programming error.
74-
@available(SwiftStdlib 5.9, *)
75+
@available(SwiftStdlib 5.1, *)
76+
@backDeployed(before: SwiftStdlib 5.9)
7577
public nonisolated func preconditionIsolated(
7678
_ message: @autoclosure () -> String = String(),
7779
file: StaticString = #fileID, line: UInt = #line
@@ -90,7 +92,7 @@ extension Actor {
9092
}
9193
}
9294

93-
@available(SwiftStdlib 5.9, *)
95+
@available(SwiftStdlib 5.1, *)
9496
extension GlobalActor {
9597
/// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
9698
/// and if not crash the program offering information about the executor mismatch.
@@ -107,7 +109,8 @@ extension GlobalActor {
107109
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
108110
/// never called. Failure to satisfy that assumption is a serious
109111
/// programming error.
110-
@available(SwiftStdlib 5.9, *)
112+
@available(SwiftStdlib 5.1, *)
113+
@backDeployed(before: SwiftStdlib 5.9)
111114
public static func preconditionIsolated(
112115
_ message: @autoclosure () -> String = String(),
113116
file: StaticString = #fileID, line: UInt = #line
@@ -119,7 +122,7 @@ extension GlobalActor {
119122
// ==== -----------------------------------------------------------------------
120123
// MARK: Assert executors
121124

122-
@available(SwiftStdlib 5.9, *)
125+
@available(SwiftStdlib 5.1, *)
123126
extension SerialExecutor {
124127
/// Performs an executor check in debug builds.
125128
///
@@ -133,7 +136,8 @@ extension SerialExecutor {
133136
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
134137
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
135138
/// assumption is a serious programming error.
136-
@available(SwiftStdlib 5.9, *)
139+
@available(SwiftStdlib 5.1, *)
140+
@backDeployed(before: SwiftStdlib 5.9)
137141
public func assertIsolated(
138142
_ message: @autoclosure () -> String = String(),
139143
file: StaticString = #fileID, line: UInt = #line
@@ -152,7 +156,7 @@ extension SerialExecutor {
152156
}
153157
}
154158

155-
@available(SwiftStdlib 5.9, *)
159+
@available(SwiftStdlib 5.1, *)
156160
extension Actor {
157161
/// Performs an executor check in debug builds.
158162
///
@@ -166,7 +170,8 @@ extension Actor {
166170
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
167171
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
168172
/// assumption is a serious programming error.
169-
@available(SwiftStdlib 5.9, *)
173+
@available(SwiftStdlib 5.1, *)
174+
@backDeployed(before: SwiftStdlib 5.9)
170175
public nonisolated func assertIsolated(
171176
_ message: @autoclosure () -> String = String(),
172177
file: StaticString = #fileID, line: UInt = #line
@@ -186,7 +191,7 @@ extension Actor {
186191
}
187192
}
188193

189-
@available(SwiftStdlib 5.9, *)
194+
@available(SwiftStdlib 5.1, *)
190195
extension GlobalActor {
191196
/// Performs an executor check in debug builds.
192197
///
@@ -200,7 +205,8 @@ extension GlobalActor {
200205
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
201206
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
202207
/// assumption is a serious programming error.
203-
@available(SwiftStdlib 5.9, *)
208+
@available(SwiftStdlib 5.1, *)
209+
@backDeployed(before: SwiftStdlib 5.9)
204210
public static func assertIsolated(
205211
_ message: @autoclosure () -> String = String(),
206212
file: StaticString = #fileID, line: UInt = #line
@@ -212,7 +218,7 @@ extension GlobalActor {
212218
// ==== -----------------------------------------------------------------------
213219
// MARK: Assume Executor
214220

215-
@available(SwiftStdlib 5.9, *)
221+
@available(SwiftStdlib 5.1, *)
216222
extension Actor {
217223
/// A safe way to synchronously assume that the current execution context belongs to the passed in actor.
218224
///
@@ -227,7 +233,8 @@ extension Actor {
227233
/// if another actor uses the same serial executor--by using that actor's ``Actor/unownedExecutor``
228234
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
229235
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
230-
@available(SwiftStdlib 5.9, *)
236+
@available(SwiftStdlib 5.1, *)
237+
@backDeployed(before: SwiftStdlib 5.9)
231238
@_unavailableFromAsync(message: "express the closure as an explicit function declared on the specified 'actor' instead")
232239
public nonisolated func assumeIsolated<T>(
233240
_ operation: (isolated Self) throws -> T,
@@ -253,4 +260,4 @@ extension Actor {
253260
}
254261
}
255262

256-
#endif // not SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
263+
#endif // not SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY

stdlib/public/Concurrency/MainActor.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ extension MainActor {
9999
}
100100
}
101101

102-
@available(SwiftStdlib 5.9, *)
102+
@available(SwiftStdlib 5.1, *)
103103
extension MainActor {
104104
/// A safe way to synchronously assume that the current execution context belongs to the MainActor.
105105
///
@@ -114,7 +114,8 @@ extension MainActor {
114114
/// if another actor uses the same serial executor--by using ``MainActor/sharedUnownedExecutor``
115115
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
116116
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
117-
@available(SwiftStdlib 5.9, *)
117+
@available(SwiftStdlib 5.1, *)
118+
@backDeployed(before: SwiftStdlib 5.9)
118119
@_unavailableFromAsync(message: "await the call to the @MainActor closure directly")
119120
public static func assumeIsolated<T>(
120121
_ operation: @MainActor () throws -> T,

test/Concurrency/Runtime/actor_assume_executor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ final class MainActorEcho {
100100

101101
let echo = MainActorEcho()
102102

103-
if #available(SwiftStdlib 5.9, *) {
103+
if #available(SwiftStdlib 5.1, *) {
104104
// === MainActor --------------------------------------------------------
105105

106106
tests.test("MainActor.assumeIsolated: assume the main executor, from 'main() async'") {

0 commit comments

Comments
 (0)