Skip to content

Fix SILOptimizer crash for top-level async code #41187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,8 +1980,11 @@ class SourceFileScope {
// emitAsyncMainThreadStart will create argc and argv.
// Just set the main actor as the expected executor; we should
// already be running on it.
SILValue executor = sgm.TopLevelSGF->emitMainExecutor(prologueLoc);
sgm.TopLevelSGF->ExpectedExecutor =
sgm.TopLevelSGF->emitMainExecutor(prologueLoc);
sgm.TopLevelSGF->B.createOptionalSome(
prologueLoc, executor,
SILType::getOptionalType(executor->getType()));
} else {
// Create the argc and argv arguments.
auto entry = sgm.TopLevelSGF->B.getInsertionBB();
Expand Down
5 changes: 3 additions & 2 deletions test/SILGen/toplevel_globalactorvars.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// CHECK-NEXT: // function_ref
// CHECK-NEXT: [[GET_MAIN:%.*]] = function_ref @swift_task_getMainExecutor
// CHECK-NEXT: [[MAIN:%.*]] = apply [[GET_MAIN]]()
// CHECK-NEXT: [[MAIN_OPTIONAL:%[0-9]+]] = enum $Optional<Builtin.Executor>, #Optional.some!enumelt, [[MAIN]]

actor MyActorImpl {}

Expand Down Expand Up @@ -67,7 +68,7 @@ await printFromMyActor(value: a)
// CHECK: [[ACTORREF:%[0-9]+]] = begin_borrow {{%[0-9]+}} : $MyActorImpl
// CHECK: hop_to_executor [[ACTORREF]] : $MyActorImpl
// CHECK: {{%[0-9]+}} = apply [[PRINTFROMMYACTOR_FUNC]]([[AGLOBAL]])
// CHECK: hop_to_executor [[MAIN]]
// CHECK: hop_to_executor [[MAIN_OPTIONAL]]
// CHECK: end_borrow [[ACTORREF]]

if a < 10 {
Expand Down Expand Up @@ -121,6 +122,6 @@ if a < 10 {
// CHECK: [[ACTORREF:%[0-9]+]] = begin_borrow {{%[0-9]+}} : $MyActorImpl
// CHECK: hop_to_executor [[ACTORREF]] : $MyActorImpl
// CHECK: {{%[0-9]+}} = apply [[PRINTFROMMYACTOR_FUNC]]([[AGLOBAL]])
// CHECK: hop_to_executor [[MAIN]]
// CHECK: hop_to_executor [[MAIN_OPTIONAL]]
// CHECK: end_borrow [[ACTORREF]]
}