@@ -1025,6 +1025,7 @@ namespace {
1025
1025
ASTContext &ctx;
1026
1026
SmallVector<const DeclContext *, 4 > contextStack;
1027
1027
SmallVector<ApplyExpr*, 4 > applyStack;
1028
+ SmallVector<std::pair<OpaqueValueExpr *, Expr *>, 4 > opaqueValues;
1028
1029
1029
1030
// / Keeps track of the capture context of variables that have been
1030
1031
// / explicitly captured in closures.
@@ -1244,6 +1245,13 @@ namespace {
1244
1245
}
1245
1246
1246
1247
std::pair<bool , Expr *> walkToExprPre (Expr *expr) override {
1248
+ if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
1249
+ opaqueValues.push_back ({
1250
+ openExistential->getOpaqueValue (),
1251
+ openExistential->getExistentialValue ()});
1252
+ return { true , expr };
1253
+ }
1254
+
1247
1255
if (auto *closure = dyn_cast<AbstractClosureExpr>(expr)) {
1248
1256
closure->setActorIsolation (determineClosureIsolation (closure));
1249
1257
contextStack.push_back (closure);
@@ -1363,6 +1371,12 @@ namespace {
1363
1371
}
1364
1372
1365
1373
Expr *walkToExprPost (Expr *expr) override {
1374
+ if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
1375
+ assert (opaqueValues.back ().first == openExistential->getOpaqueValue ());
1376
+ opaqueValues.pop_back ();
1377
+ return expr;
1378
+ }
1379
+
1366
1380
if (auto *closure = dyn_cast<AbstractClosureExpr>(expr)) {
1367
1381
assert (contextStack.back () == closure);
1368
1382
contextStack.pop_back ();
@@ -1398,7 +1412,7 @@ namespace {
1398
1412
private:
1399
1413
// / Find the directly-referenced parameter or capture of a parameter for
1400
1414
// / for the given expression.
1401
- static VarDecl *getReferencedParamOrCapture (Expr *expr) {
1415
+ VarDecl *getReferencedParamOrCapture (Expr *expr) {
1402
1416
// Look through identity expressions and implicit conversions.
1403
1417
Expr *prior;
1404
1418
do {
@@ -1408,6 +1422,16 @@ namespace {
1408
1422
1409
1423
if (auto conversion = dyn_cast<ImplicitConversionExpr>(expr))
1410
1424
expr = conversion->getSubExpr ();
1425
+
1426
+ // Map opaque values.
1427
+ if (auto opaqueValue = dyn_cast<OpaqueValueExpr>(expr)) {
1428
+ for (const auto &known : opaqueValues) {
1429
+ if (known.first == opaqueValue) {
1430
+ expr = known.second ;
1431
+ break ;
1432
+ }
1433
+ }
1434
+ }
1411
1435
} while (prior != expr);
1412
1436
1413
1437
// 'super' references always act on a 'self' variable.
@@ -1550,7 +1574,7 @@ namespace {
1550
1574
}
1551
1575
1552
1576
// / If the expression is a reference to `self`, the `self` declaration.
1553
- static VarDecl *getReferencedSelf (Expr *expr) {
1577
+ VarDecl *getReferencedSelf (Expr *expr) {
1554
1578
if (auto selfVar = getReferencedParamOrCapture (expr))
1555
1579
if (selfVar->isSelfParameter () || selfVar->isSelfParamCapture ())
1556
1580
return selfVar;
@@ -1593,8 +1617,8 @@ namespace {
1593
1617
// detect if it is a distributed actor, to provide better isolation notes
1594
1618
1595
1619
auto isDistributedActor = false ;
1596
- if (auto dc = dyn_cast<ClassDecl>( decl->getDeclContext ()))
1597
- isDistributedActor = dc ->isDistributedActor ();
1620
+ if (auto nominal = decl->getDeclContext ()-> getSelfNominalTypeDecl ( ))
1621
+ isDistributedActor = nominal ->isDistributedActor ();
1598
1622
1599
1623
// FIXME: Make this diagnostic more sensitive to the isolation context of
1600
1624
// the declaration.
@@ -2538,8 +2562,8 @@ namespace {
2538
2562
case ActorIsolationRestriction::Unsafe:
2539
2563
// This case is hit when passing actor state inout to functions in some
2540
2564
// cases. The error is emitted by diagnoseInOutArg.
2541
- auto classDecl = dyn_cast<ClassDecl>( member->getDeclContext ());
2542
- if (classDecl && classDecl ->isDistributedActor ()) {
2565
+ auto nominal = member->getDeclContext ()-> getSelfNominalTypeDecl ( );
2566
+ if (nominal && nominal ->isDistributedActor ()) {
2543
2567
auto funcDecl = dyn_cast<AbstractFunctionDecl>(member);
2544
2568
if (funcDecl && !funcDecl->isStatic ()) {
2545
2569
member->diagnose (diag::distributed_actor_isolated_method);
0 commit comments