Skip to content

Commit 9b6b4b9

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 b4a3fbe commit 9b6b4b9

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
@@ -583,8 +583,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
583583

584584
/// Retrieve the _Concurrency._asyncMainDrainQueue intrinsic.
585585
FuncDecl *getAsyncMainDrainQueue();
586-
/// Retrieve the _Concurrency._getMainExecutor intrinsic.
587-
FuncDecl *getGetMainExecutor();
588586
/// Retrieve the _Concurrency._swiftJobRun intrinsic.
589587
FuncDecl *getSwiftJobRun();
590588
// Retrieve the _SwiftConcurrencyShims.exit intrinsic.

lib/SILGen/SILGenProlog.cpp

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

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

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

14841460
SILValue SILGenFunction::emitGenericExecutor(SILLocation loc) {

test/Concurrency/async_main.swift

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