Skip to content

Commit b26a575

Browse files
authored
Merge pull request #41187 from etcwilde/ewilde/fix-toplevel-async
Fix SILOptimizer crash for top-level async code
2 parents f0c96b1 + b08016a commit b26a575

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,8 +1980,11 @@ class SourceFileScope {
19801980
// emitAsyncMainThreadStart will create argc and argv.
19811981
// Just set the main actor as the expected executor; we should
19821982
// already be running on it.
1983+
SILValue executor = sgm.TopLevelSGF->emitMainExecutor(prologueLoc);
19831984
sgm.TopLevelSGF->ExpectedExecutor =
1984-
sgm.TopLevelSGF->emitMainExecutor(prologueLoc);
1985+
sgm.TopLevelSGF->B.createOptionalSome(
1986+
prologueLoc, executor,
1987+
SILType::getOptionalType(executor->getType()));
19851988
} else {
19861989
// Create the argc and argv arguments.
19871990
auto entry = sgm.TopLevelSGF->B.getInsertionBB();

test/SILGen/toplevel_globalactorvars.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// CHECK-NEXT: // function_ref
99
// CHECK-NEXT: [[GET_MAIN:%.*]] = function_ref @swift_task_getMainExecutor
1010
// CHECK-NEXT: [[MAIN:%.*]] = apply [[GET_MAIN]]()
11+
// CHECK-NEXT: [[MAIN_OPTIONAL:%[0-9]+]] = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, [[MAIN]]
1112

1213
actor MyActorImpl {}
1314

@@ -67,7 +68,7 @@ await printFromMyActor(value: a)
6768
// CHECK: [[ACTORREF:%[0-9]+]] = begin_borrow {{%[0-9]+}} : $MyActorImpl
6869
// CHECK: hop_to_executor [[ACTORREF]] : $MyActorImpl
6970
// CHECK: {{%[0-9]+}} = apply [[PRINTFROMMYACTOR_FUNC]]([[AGLOBAL]])
70-
// CHECK: hop_to_executor [[MAIN]]
71+
// CHECK: hop_to_executor [[MAIN_OPTIONAL]]
7172
// CHECK: end_borrow [[ACTORREF]]
7273

7374
if a < 10 {
@@ -121,6 +122,6 @@ if a < 10 {
121122
// CHECK: [[ACTORREF:%[0-9]+]] = begin_borrow {{%[0-9]+}} : $MyActorImpl
122123
// CHECK: hop_to_executor [[ACTORREF]] : $MyActorImpl
123124
// CHECK: {{%[0-9]+}} = apply [[PRINTFROMMYACTOR_FUNC]]([[AGLOBAL]])
124-
// CHECK: hop_to_executor [[MAIN]]
125+
// CHECK: hop_to_executor [[MAIN_OPTIONAL]]
125126
// CHECK: end_borrow [[ACTORREF]]
126127
}

0 commit comments

Comments
 (0)