Skip to content

Commit 766e653

Browse files
authored
Merge pull request #70474 from tshortli/back-deploy-assertassume-isolation-5.10
2 parents 479d84f + 1d78bae commit 766e653

File tree

8 files changed

+37
-64
lines changed

8 files changed

+37
-64
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,6 @@ FuncDecl *SILGenModule::getAsyncMainDrainQueue() {
503503
"_asyncMainDrainQueue");
504504
}
505505

506-
FuncDecl *SILGenModule::getGetMainExecutor() {
507-
return lookupConcurrencyIntrinsic(getASTContext(), GetMainExecutor,
508-
"_getMainExecutor");
509-
}
510-
511506
FuncDecl *SILGenModule::getSwiftJobRun() {
512507
return lookupConcurrencyIntrinsic(getASTContext(), SwiftJobRun,
513508
"_swiftJobRun");

lib/SILGen/SILGen.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
570570

571571
/// Retrieve the _Concurrency._asyncMainDrainQueue intrinsic.
572572
FuncDecl *getAsyncMainDrainQueue();
573-
/// Retrieve the _Concurrency._getMainExecutor intrinsic.
574-
FuncDecl *getGetMainExecutor();
575573
/// Retrieve the _Concurrency._swiftJobRun intrinsic.
576574
FuncDecl *getSwiftJobRun();
577575
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.

lib/SILGen/SILGenProlog.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,36 +1448,12 @@ void SILGenFunction::emitProlog(
14481448
}
14491449

14501450
SILValue SILGenFunction::emitMainExecutor(SILLocation loc) {
1451-
// Get main executor
1452-
FuncDecl *getMainExecutorFuncDecl = SGM.getGetMainExecutor();
1453-
if (!getMainExecutorFuncDecl) {
1454-
// If it doesn't exist due to an SDK-compiler mismatch, we can conjure one
1455-
// up instead of crashing:
1456-
// @available(SwiftStdlib 5.1, *)
1457-
// @_silgen_name("swift_task_getMainExecutor")
1458-
// internal func _getMainExecutor() -> Builtin.Executor
1459-
auto &ctx = getASTContext();
1460-
1461-
ParameterList *emptyParams = ParameterList::createEmpty(ctx);
1462-
getMainExecutorFuncDecl = FuncDecl::createImplicit(
1463-
ctx, StaticSpellingKind::None,
1464-
DeclName(
1465-
ctx,
1466-
DeclBaseName(ctx.getIdentifier("_getMainExecutor")),
1467-
/*Arguments*/ emptyParams),
1468-
{}, /*async*/ false, /*throws*/ false, {}, emptyParams,
1469-
ctx.TheExecutorType,
1470-
getModule().getSwiftModule());
1471-
getMainExecutorFuncDecl->getAttrs().add(
1472-
new (ctx) SILGenNameAttr("swift_task_getMainExecutor", /*raw*/ false,
1473-
/*implicit*/ true));
1474-
}
1451+
auto &ctx = getASTContext();
1452+
auto builtinName = ctx.getIdentifier(
1453+
getBuiltinName(BuiltinValueKind::BuildMainActorExecutorRef));
1454+
auto resultType = SILType::getPrimitiveObjectType(ctx.TheExecutorType);
14751455

1476-
auto fn = SGM.getFunction(
1477-
SILDeclRef(getMainExecutorFuncDecl, SILDeclRef::Kind::Func),
1478-
NotForDefinition);
1479-
SILValue fnRef = B.createFunctionRefFor(loc, fn);
1480-
return B.createApply(loc, fnRef, {}, {});
1456+
return B.createBuiltin(loc, builtinName, resultType, {}, {});
14811457
}
14821458

14831459
SILValue SILGenFunction::emitGenericExecutor(SILLocation loc) {

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'") {

test/Concurrency/async_main.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ func asyncFunc() async {
7979
// CHECK-SIL-NEXT: %12 = function_ref @swift_job_run : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
8080
// CHECK-SIL-NEXT: %13 = builtin "convertTaskToJob"(%11 : $Builtin.NativeObject) : $Builtin.Job
8181
// CHECK-SIL-NEXT: %14 = struct $UnownedJob (%13 : $Builtin.Job)
82-
// CHECK-SIL-NEXT: // function_ref swift_task_getMainExecutor
83-
// CHECK-SIL-NEXT: %15 = function_ref @swift_task_getMainExecutor : $@convention(thin) () -> Builtin.Executor
84-
// CHECK-SIL-NEXT: %16 = apply %15() : $@convention(thin) () -> Builtin.Executor
85-
// CHECK-SIL-NEXT: %17 = struct $UnownedSerialExecutor (%16 : $Builtin.Executor)
86-
// CHECK-SIL-NEXT: %18 = apply %12(%14, %17) : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
82+
// CHECK-SIL-NEXT: %15 = builtin "buildMainActorExecutorRef"() : $Builtin.Executor
83+
// CHECK-SIL-NEXT: %16 = struct $UnownedSerialExecutor (%15 : $Builtin.Executor)
84+
// CHECK-SIL-NEXT: %17 = apply %12(%14, %16) : $@convention(thin) (UnownedJob, UnownedSerialExecutor) -> ()
8785
// CHECK-SIL-NEXT: // function_ref swift_task_asyncMainDrainQueue
88-
// CHECK-SIL-NEXT: %19 = function_ref @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never
89-
// CHECK-SIL-NEXT: %20 = apply %19() : $@convention(thin) () -> Never
86+
// CHECK-SIL-NEXT: %18 = function_ref @swift_task_asyncMainDrainQueue : $@convention(thin) () -> Never
87+
// CHECK-SIL-NEXT: %19 = apply %18() : $@convention(thin) () -> Never
9088
// CHECK-SIL-NEXT: unreachable

test/SILGen/toplevel_globalactorvars.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
// CHECK-LABEL: sil private [ossa] @async_Main
77
// CHECK: bb0:
8-
// CHECK-NEXT: // function_ref
9-
// CHECK-NEXT: [[GET_MAIN:%.*]] = function_ref @swift_task_getMainExecutor
10-
// CHECK-NEXT: [[MAIN:%.*]] = apply [[GET_MAIN]]()
8+
// CHECK-NEXT: [[MAIN:%.*]] = builtin "buildMainActorExecutorRef"() : $Builtin.Executor
119
// CHECK-NEXT: [[MAIN_OPTIONAL:%[0-9]+]] = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, [[MAIN]]
1210

1311
actor MyActorImpl {}

0 commit comments

Comments
 (0)