|
20 | 20 | #include "swift/AST/ASTContext.h" |
21 | 21 | #include "swift/AST/ASTWalker.h" |
22 | 22 | #include "swift/AST/ASTMangler.h" |
| 23 | +#include "swift/AST/CaptureInfo.h" |
23 | 24 | #include "swift/AST/DiagnosticEngine.h" |
24 | 25 | #include "swift/AST/DiagnosticsSema.h" |
25 | 26 | #include "swift/AST/ExistentialLayout.h" |
@@ -8609,6 +8610,41 @@ void ClassDecl::setSuperclass(Type superclass) { |
8609 | 8610 | true); |
8610 | 8611 | } |
8611 | 8612 |
|
| 8613 | +bool VarDecl::isSelfParamCaptureIsolated() const { |
| 8614 | + assert(isSelfParamCapture()); |
| 8615 | + |
| 8616 | + // Find the "self" parameter that we captured and determine whether |
| 8617 | + // it is potentially isolated. |
| 8618 | + for (auto dc = getDeclContext(); dc; dc = dc->getParent()) { |
| 8619 | + if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) { |
| 8620 | + if (auto selfDecl = func->getImplicitSelfDecl()) { |
| 8621 | + return selfDecl->isIsolated(); |
| 8622 | + } |
| 8623 | + |
| 8624 | + if (auto capture = func->getCaptureInfo().getIsolatedParamCapture()) |
| 8625 | + return capture->isSelfParameter() || capture->isSelfParamCapture(); |
| 8626 | + } |
| 8627 | + |
| 8628 | + if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) { |
| 8629 | + switch (auto isolation = closure->getActorIsolation()) { |
| 8630 | + case ClosureActorIsolation::Independent: |
| 8631 | + case ClosureActorIsolation::GlobalActor: |
| 8632 | + return false; |
| 8633 | + |
| 8634 | + case ClosureActorIsolation::ActorInstance: |
| 8635 | + auto isolatedVar = isolation.getActorInstance(); |
| 8636 | + return isolatedVar->isSelfParameter() || |
| 8637 | + isolatedVar-isSelfParamCapture(); |
| 8638 | + } |
| 8639 | + } |
| 8640 | + |
| 8641 | + if (dc->isModuleScopeContext() || dc->isTypeContext()) |
| 8642 | + break; |
| 8643 | + } |
| 8644 | + |
| 8645 | + return false; |
| 8646 | +} |
| 8647 | + |
8612 | 8648 | ActorIsolation swift::getActorIsolation(ValueDecl *value) { |
8613 | 8649 | auto &ctx = value->getASTContext(); |
8614 | 8650 | return evaluateOrDefault( |
@@ -8638,7 +8674,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) { |
8638 | 8674 |
|
8639 | 8675 | case ClosureActorIsolation::ActorInstance: { |
8640 | 8676 | auto selfDecl = isolation.getActorInstance(); |
8641 | | - auto actorClass = selfDecl->getType()->getRValueType() |
| 8677 | + auto actorClass = selfDecl->getType()->getReferenceStorageReferent() |
8642 | 8678 | ->getClassOrBoundGenericClass(); |
8643 | 8679 | // FIXME: Doesn't work properly with generics |
8644 | 8680 | assert(actorClass && "Bad closure actor isolation?"); |
|
0 commit comments