@@ -6125,28 +6125,40 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
6125
6125
auto globalActorHelper = [&](Type globalActor)
6126
6126
-> std::optional<std::tuple<InferredActorIsolation, ValueDecl *,
6127
6127
std::optional<ActorIsolation>>> {
6128
- // Default global actor isolation does not apply to any declarations
6129
- // within actors and distributed actors, nor does it apply in a
6130
- // nonisolated type.
6128
+ // Default main actor only applies to top-level declarations and
6129
+ // in contexts that are also main actor isolated. It does not apply
6130
+ // in {distributed} actor-isolated contexts nor in nonisolated
6131
+ // contexts.
6132
+
6133
+ if (value->getDeclContext ()->isLocalContext ()) {
6134
+ // Local storage is always nonisolated; region isolation computes
6135
+ // whether the value is in an actor-isolated region based on
6136
+ // the initializer expression.
6137
+ auto *var = dyn_cast<VarDecl>(value);
6138
+ if (var && var->hasStorage ())
6139
+ return {};
6140
+
6141
+ // Other local declarations must check the isolation of their
6142
+ // decl context.
6143
+ auto contextIsolation =
6144
+ getActorIsolationOfContext (value->getDeclContext ());
6145
+ if (!contextIsolation.isMainActor ())
6146
+ return {};
6147
+ }
6148
+
6149
+ // Members and nested types must check the isolation of the enclosing
6150
+ // nominal type.
6131
6151
auto *dc = value->getInnermostDeclContext ();
6132
6152
while (dc) {
6133
6153
if (auto *nominal = dc->getSelfNominalTypeDecl ()) {
6134
6154
if (nominal->isAnyActor ())
6135
6155
return {};
6136
6156
6137
6157
if (dc != dyn_cast<DeclContext>(value)) {
6138
- switch (getActorIsolation (nominal)) {
6139
- case ActorIsolation::Unspecified:
6140
- case ActorIsolation::ActorInstance:
6141
- case ActorIsolation::Nonisolated:
6142
- case ActorIsolation::NonisolatedUnsafe:
6143
- case ActorIsolation::Erased:
6144
- case ActorIsolation::CallerIsolationInheriting:
6145
- return {};
6146
-
6147
- case ActorIsolation::GlobalActor:
6158
+ if (getActorIsolation (nominal).isMainActor ())
6148
6159
break ;
6149
- }
6160
+
6161
+ return {};
6150
6162
}
6151
6163
}
6152
6164
dc = dc->getParent ();
0 commit comments