@@ -12076,7 +12076,6 @@ ActorIsolation swift::getActorIsolationOfContext(
12076
12076
DeclContext *dc,
12077
12077
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
12078
12078
getClosureActorIsolation) {
12079
- auto &ctx = dc->getASTContext ();
12080
12079
auto dcToUse = dc;
12081
12080
12082
12081
// Defer bodies share the actor isolation of their enclosing context.
@@ -12091,44 +12090,79 @@ ActorIsolation swift::getActorIsolationOfContext(
12091
12090
if (auto *vd = dyn_cast_or_null<ValueDecl>(dcToUse->getAsDecl ()))
12092
12091
return getActorIsolation (vd);
12093
12092
12094
- // In the context of the initializing or default-value expression of a
12095
- // stored property:
12096
- // - For a static stored property, the isolation matches the VarDecl.
12097
- // Static properties are initialized upon first use, so the isolation
12098
- // of the initializer must match the isolation required to access the
12099
- // property.
12100
- // - For a field of a nominal type, the expression can require the same
12101
- // actor isolation as the field itself. That default expression may only
12102
- // be used from inits that meet the required isolation.
12103
- if (auto *var = dcToUse->getNonLocalVarDecl ()) {
12104
- // If IsolatedDefaultValues are enabled, treat this context as having
12105
- // unspecified isolation. We'll compute the required isolation for
12106
- // the initializer and validate that it matches the isolation of the
12107
- // var itself in the DefaultInitializerIsolation request.
12108
- if (ctx.LangOpts .hasFeature (Feature::IsolatedDefaultValues))
12109
- return ActorIsolation::forUnspecified ();
12110
-
12111
- return getActorIsolation (var);
12112
- }
12113
-
12114
12093
if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
12115
12094
return getClosureActorIsolation (closure);
12116
12095
}
12117
12096
12097
+ if (auto *init = dyn_cast<Initializer>(dcToUse)) {
12098
+ // FIXME: force default argument initializers to report a meaningless
12099
+ // isolation in order to break a bunch of cycles with the way that
12100
+ // isolation is computed for them.
12101
+ return getActorIsolation (init, /* ignoreDefaultArguments*/ true );
12102
+ }
12103
+
12118
12104
if (isa<TopLevelCodeDecl>(dcToUse)) {
12105
+ auto &ctx = dc->getASTContext ();
12119
12106
if (dcToUse->isAsyncContext () ||
12120
- dcToUse->getASTContext ().LangOpts .StrictConcurrencyLevel >=
12121
- StrictConcurrency::Complete) {
12122
- if (Type mainActor = dcToUse->getASTContext ().getMainActorType ())
12107
+ ctx.LangOpts .StrictConcurrencyLevel >= StrictConcurrency::Complete) {
12108
+ if (Type mainActor = ctx.getMainActorType ())
12123
12109
return ActorIsolation::forGlobalActor (mainActor)
12124
- .withPreconcurrency (
12125
- !dcToUse->getASTContext ().isSwiftVersionAtLeast (6 ));
12110
+ .withPreconcurrency (!ctx.isSwiftVersionAtLeast (6 ));
12126
12111
}
12127
12112
}
12128
12113
12129
12114
return ActorIsolation::forUnspecified ();
12130
12115
}
12131
12116
12117
+ ActorIsolation swift::getActorIsolation (Initializer *init,
12118
+ bool ignoreDefaultArguments) {
12119
+ switch (init->getInitializerKind ()) {
12120
+ case InitializerKind::PatternBinding:
12121
+ // In the context of the initializing or default-value expression of a
12122
+ // stored property:
12123
+ // - For a static stored property, the isolation matches the VarDecl.
12124
+ // Static properties are initialized upon first use, so the isolation
12125
+ // of the initializer must match the isolation required to access the
12126
+ // property.
12127
+ // - For a field of a nominal type, the expression can require the same
12128
+ // actor isolation as the field itself. That default expression may only
12129
+ // be used from inits that meet the required isolation.
12130
+ if (auto *var = init->getNonLocalVarDecl ()) {
12131
+ auto &ctx = var->getASTContext ();
12132
+
12133
+ // If IsolatedDefaultValues are enabled, treat this context as having
12134
+ // unspecified isolation. We'll compute the required isolation for
12135
+ // the initializer and validate that it matches the isolation of the
12136
+ // var itself in the DefaultInitializerIsolation request.
12137
+ if (ctx.LangOpts .hasFeature (Feature::IsolatedDefaultValues))
12138
+ return ActorIsolation::forUnspecified ();
12139
+
12140
+ return getActorIsolation (var);
12141
+ }
12142
+
12143
+ return ActorIsolation::forUnspecified ();
12144
+
12145
+ case InitializerKind::DefaultArgument: {
12146
+ auto defArgInit = cast<DefaultArgumentInitializer>(init);
12147
+
12148
+ // A hack when used from getActorIsolationOfContext to maintain the
12149
+ // current behavior and avoid request cycles.
12150
+ if (ignoreDefaultArguments)
12151
+ return ActorIsolation::forUnspecified ();
12152
+
12153
+ auto fn = cast<ValueDecl>(defArgInit->getParent ()->getAsDecl ());
12154
+ auto param = getParameterAt (fn, defArgInit->getIndex ());
12155
+ assert (param);
12156
+ return param->getInitializerIsolation ();
12157
+ }
12158
+
12159
+ case InitializerKind::PropertyWrapper:
12160
+ case InitializerKind::CustomAttribute:
12161
+ return ActorIsolation::forUnspecified ();
12162
+ }
12163
+ llvm_unreachable (" bad initializer kind" );
12164
+ }
12165
+
12132
12166
bool swift::isSameActorIsolated (ValueDecl *value, DeclContext *dc) {
12133
12167
auto valueIsolation = getActorIsolation (value);
12134
12168
auto dcIsolation = getActorIsolationOfContext (dc);
0 commit comments