Skip to content

Commit 567afb8

Browse files
committed
SILGen: Consistently use the buildMainActorExecutorRef built-in.
SILGen and IRGen would disagree on the return type of the `swift_task_getMainExecutor()` runtime function if `SILGenModule::getGetMainExecutor()` had ever been called. To address this, consistently use the `buildMainActorExecutorRef` built-in and get rid of `SILGenModule::getGetMainExecutor()`. Resolves rdar://116472583
1 parent 482c0d2 commit 567afb8

File tree

5 files changed

+11
-46
lines changed

5 files changed

+11
-46
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) {

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)