Skip to content

Commit 0fbbc6a

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 9b6b4b9 commit 0fbbc6a

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 35 additions & 14 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,10 @@ 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+
#if !$Embedded
40+
@backDeployed(before: SwiftStdlib 5.9)
41+
#endif
3942
@_unavailableInEmbedded
4043
public func preconditionIsolated(
4144
_ message: @autoclosure () -> String = String(),
@@ -55,7 +58,7 @@ extension SerialExecutor {
5558
}
5659
}
5760

58-
@available(SwiftStdlib 5.9, *)
61+
@available(SwiftStdlib 5.1, *)
5962
extension Actor {
6063
/// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
6164
/// and if not crash the program offering information about the executor mismatch.
@@ -72,7 +75,10 @@ extension Actor {
7275
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
7376
/// never called. Failure to satisfy that assumption is a serious
7477
/// programming error.
75-
@available(SwiftStdlib 5.9, *)
78+
@available(SwiftStdlib 5.1, *)
79+
#if !$Embedded
80+
@backDeployed(before: SwiftStdlib 5.9)
81+
#endif
7682
@_unavailableInEmbedded
7783
public nonisolated func preconditionIsolated(
7884
_ message: @autoclosure () -> String = String(),
@@ -92,7 +98,7 @@ extension Actor {
9298
}
9399
}
94100

95-
@available(SwiftStdlib 5.9, *)
101+
@available(SwiftStdlib 5.1, *)
96102
extension GlobalActor {
97103
/// Unconditionally if the current task is executing on the serial executor of the passed in `actor`,
98104
/// and if not crash the program offering information about the executor mismatch.
@@ -109,7 +115,10 @@ extension GlobalActor {
109115
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
110116
/// never called. Failure to satisfy that assumption is a serious
111117
/// programming error.
112-
@available(SwiftStdlib 5.9, *)
118+
@available(SwiftStdlib 5.1, *)
119+
#if !$Embedded
120+
@backDeployed(before: SwiftStdlib 5.9)
121+
#endif
113122
@_unavailableInEmbedded
114123
public static func preconditionIsolated(
115124
_ message: @autoclosure () -> String = String(),
@@ -122,7 +131,7 @@ extension GlobalActor {
122131
// ==== -----------------------------------------------------------------------
123132
// MARK: Assert executors
124133

125-
@available(SwiftStdlib 5.9, *)
134+
@available(SwiftStdlib 5.1, *)
126135
extension SerialExecutor {
127136
/// Performs an executor check in debug builds.
128137
///
@@ -136,7 +145,10 @@ extension SerialExecutor {
136145
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
137146
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
138147
/// assumption is a serious programming error.
139-
@available(SwiftStdlib 5.9, *)
148+
@available(SwiftStdlib 5.1, *)
149+
#if !$Embedded
150+
@backDeployed(before: SwiftStdlib 5.9)
151+
#endif
140152
@_unavailableInEmbedded
141153
public func assertIsolated(
142154
_ message: @autoclosure () -> String = String(),
@@ -156,7 +168,7 @@ extension SerialExecutor {
156168
}
157169
}
158170

159-
@available(SwiftStdlib 5.9, *)
171+
@available(SwiftStdlib 5.1, *)
160172
extension Actor {
161173
/// Performs an executor check in debug builds.
162174
///
@@ -170,7 +182,10 @@ extension Actor {
170182
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
171183
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
172184
/// assumption is a serious programming error.
173-
@available(SwiftStdlib 5.9, *)
185+
@available(SwiftStdlib 5.1, *)
186+
#if !$Embedded
187+
@backDeployed(before: SwiftStdlib 5.9)
188+
#endif
174189
@_unavailableInEmbedded
175190
public nonisolated func assertIsolated(
176191
_ message: @autoclosure () -> String = String(),
@@ -191,7 +206,7 @@ extension Actor {
191206
}
192207
}
193208

194-
@available(SwiftStdlib 5.9, *)
209+
@available(SwiftStdlib 5.1, *)
195210
extension GlobalActor {
196211
/// Performs an executor check in debug builds.
197212
///
@@ -205,7 +220,10 @@ extension GlobalActor {
205220
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
206221
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
207222
/// assumption is a serious programming error.
208-
@available(SwiftStdlib 5.9, *)
223+
@available(SwiftStdlib 5.1, *)
224+
#if !$Embedded
225+
@backDeployed(before: SwiftStdlib 5.9)
226+
#endif
209227
@_unavailableInEmbedded
210228
public static func assertIsolated(
211229
_ message: @autoclosure () -> String = String(),
@@ -218,7 +236,7 @@ extension GlobalActor {
218236
// ==== -----------------------------------------------------------------------
219237
// MARK: Assume Executor
220238

221-
@available(SwiftStdlib 5.9, *)
239+
@available(SwiftStdlib 5.1, *)
222240
extension Actor {
223241
/// A safe way to synchronously assume that the current execution context belongs to the passed in actor.
224242
///
@@ -233,7 +251,10 @@ extension Actor {
233251
/// if another actor uses the same serial executor--by using that actor's ``Actor/unownedExecutor``
234252
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
235253
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
236-
@available(SwiftStdlib 5.9, *)
254+
@available(SwiftStdlib 5.1, *)
255+
#if !$Embedded
256+
@backDeployed(before: SwiftStdlib 5.9)
257+
#endif
237258
@_unavailableFromAsync(message: "express the closure as an explicit function declared on the specified 'actor' instead")
238259
@_unavailableInEmbedded
239260
public nonisolated func assumeIsolated<T>(

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)