@@ -852,8 +852,9 @@ namespace {
852
852
}
853
853
854
854
private:
855
- // / If the expression is a reference to `self`, return the 'self' parameter.
856
- static VarDecl *getSelfReference (Expr *expr) {
855
+ // / If the expression is a reference to `self`, return the context of
856
+ // / the 'self' parameter.
857
+ static DeclContext *getSelfReferenceContext (Expr *expr) {
857
858
// Look through identity expressions and implicit conversions.
858
859
Expr *prior;
859
860
do {
@@ -867,13 +868,25 @@ namespace {
867
868
868
869
// 'super' references always act on self.
869
870
if (auto super = dyn_cast<SuperRefExpr>(expr))
870
- return super->getSelf ();
871
+ return super->getSelf ()-> getDeclContext () ;
871
872
872
873
// Declaration references to 'self'.
873
874
if (auto declRef = dyn_cast<DeclRefExpr>(expr)) {
874
- if (auto var = dyn_cast<VarDecl>(declRef->getDecl ()))
875
+ if (auto var = dyn_cast<VarDecl>(declRef->getDecl ())) {
875
876
if (var->isSelfParameter ())
876
- return var;
877
+ return var->getDeclContext ();
878
+
879
+ // If this is a 'self' capture in a capture list, recurse through
880
+ // the capture list entry's initializer to find the original 'self'.
881
+ if (var->isSelfParamCapture ()) {
882
+ for (auto capture : var->getParentCaptureList ()->getCaptureList ()) {
883
+ if (capture.Var == var) {
884
+ expr = capture.Init ->getInit (0 );
885
+ return getSelfReferenceContext (expr);
886
+ }
887
+ }
888
+ }
889
+ }
877
890
}
878
891
879
892
// Not a self reference.
@@ -1250,8 +1263,8 @@ namespace {
1250
1263
1251
1264
case ActorIsolationRestriction::ActorSelf: {
1252
1265
// Must reference actor-isolated state on 'self'.
1253
- auto selfVar = getSelfReference (base);
1254
- if (!selfVar ) {
1266
+ auto *selfDC = getSelfReferenceContext (base);
1267
+ if (!selfDC ) {
1255
1268
// actor-isolated non-self calls are implicitly async and thus OK.
1256
1269
if (maybeImplicitAsync && isa<AbstractFunctionDecl>(member)) {
1257
1270
markNearestCallAsImplicitlyAsync ();
@@ -1268,8 +1281,7 @@ namespace {
1268
1281
}
1269
1282
1270
1283
// Check whether the context of 'self' is actor-isolated.
1271
- switch (auto contextIsolation = getActorIsolation (
1272
- cast<ValueDecl>(selfVar->getDeclContext ()->getAsDecl ()))) {
1284
+ switch (auto contextIsolation = getActorIsolationOfContext (selfDC)) {
1273
1285
case ActorIsolation::ActorInstance:
1274
1286
// An escaping partial application of something that is part of
1275
1287
// the actor's isolated state is never permitted.
@@ -1312,8 +1324,7 @@ namespace {
1312
1324
1313
1325
// Check whether we are in a context that will not execute concurrently
1314
1326
// with the context of 'self'.
1315
- if (mayExecuteConcurrentlyWith (
1316
- getDeclContext (), selfVar->getDeclContext ())) {
1327
+ if (mayExecuteConcurrentlyWith (getDeclContext (), selfDC)) {
1317
1328
ctx.Diags .diagnose (
1318
1329
memberLoc, diag::actor_isolated_concurrent_access,
1319
1330
member->getDescriptiveKind (), member->getName ());
@@ -1886,13 +1897,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
1886
1897
return defaultIsolation;
1887
1898
}
1888
1899
1889
- ActorIsolation swift::getActorIsolation (ValueDecl *value) {
1890
- auto &ctx = value->getASTContext ();
1891
- return evaluateOrDefault (
1892
- ctx.evaluator , ActorIsolationRequest{value},
1893
- ActorIsolation::forUnspecified ());
1894
- }
1895
-
1896
1900
void swift::checkOverrideActorIsolation (ValueDecl *value) {
1897
1901
if (isa<TypeDecl>(value))
1898
1902
return ;
0 commit comments