Skip to content

Commit f4e93bd

Browse files
committed
Top-level code is executed on the main actor
This patch sets the actor isolation of the top-level code contexts to be on the main actor. This holds since the implicit `async_Main` function generated is executed on the main actor executor.
1 parent 9eb9df8 commit f4e93bd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8949,6 +8949,14 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
89498949
}
89508950
}
89518951

8952+
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dc)) {
8953+
ASTContext &ctx = dc->getASTContext();
8954+
if (ctx.LangOpts.EnableExperimentalAsyncTopLevel) {
8955+
if (Type mainActor = ctx.getMainActorType())
8956+
return ActorIsolation::forGlobalActor(mainActor, /*unsafe=*/false);
8957+
}
8958+
}
8959+
89528960
return ActorIsolation::forUnspecified();
89538961
}
89548962

lib/Sema/TypeCheckConcurrency.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class ActorIsolationRestriction {
199199
}
200200

201201
/// Determine the isolation rules for a given declaration.
202+
/// The isolation restriction represents the isolation requirement of the
203+
/// using context.
202204
///
203205
/// \param fromExpression Indicates that the reference is coming from an
204206
/// expression.

0 commit comments

Comments
 (0)