|
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" |
@@ -8614,6 +8615,41 @@ void ClassDecl::setSuperclass(Type superclass) { |
8614 | 8615 | true); |
8615 | 8616 | } |
8616 | 8617 |
|
| 8618 | +bool VarDecl::isSelfParamCaptureIsolated() const { |
| 8619 | + assert(isSelfParamCapture()); |
| 8620 | + |
| 8621 | + // Find the "self" parameter that we captured and determine whether |
| 8622 | + // it is potentially isolated. |
| 8623 | + for (auto dc = getDeclContext(); dc; dc = dc->getParent()) { |
| 8624 | + if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) { |
| 8625 | + if (auto selfDecl = func->getImplicitSelfDecl()) { |
| 8626 | + return selfDecl->isIsolated(); |
| 8627 | + } |
| 8628 | + |
| 8629 | + if (auto capture = func->getCaptureInfo().getIsolatedParamCapture()) |
| 8630 | + return capture->isSelfParameter() || capture->isSelfParamCapture(); |
| 8631 | + } |
| 8632 | + |
| 8633 | + if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) { |
| 8634 | + switch (auto isolation = closure->getActorIsolation()) { |
| 8635 | + case ClosureActorIsolation::Independent: |
| 8636 | + case ClosureActorIsolation::GlobalActor: |
| 8637 | + return false; |
| 8638 | + |
| 8639 | + case ClosureActorIsolation::ActorInstance: |
| 8640 | + auto isolatedVar = isolation.getActorInstance(); |
| 8641 | + return isolatedVar->isSelfParameter() || |
| 8642 | + isolatedVar-isSelfParamCapture(); |
| 8643 | + } |
| 8644 | + } |
| 8645 | + |
| 8646 | + if (dc->isModuleScopeContext() || dc->isTypeContext()) |
| 8647 | + break; |
| 8648 | + } |
| 8649 | + |
| 8650 | + return false; |
| 8651 | +} |
| 8652 | + |
8617 | 8653 | ActorIsolation swift::getActorIsolation(ValueDecl *value) { |
8618 | 8654 | auto &ctx = value->getASTContext(); |
8619 | 8655 | return evaluateOrDefault( |
@@ -8643,7 +8679,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) { |
8643 | 8679 |
|
8644 | 8680 | case ClosureActorIsolation::ActorInstance: { |
8645 | 8681 | auto selfDecl = isolation.getActorInstance(); |
8646 | | - auto actorClass = selfDecl->getType()->getRValueType() |
| 8682 | + auto actorClass = selfDecl->getType()->getReferenceStorageReferent() |
8647 | 8683 | ->getClassOrBoundGenericClass(); |
8648 | 8684 | // FIXME: Doesn't work properly with generics |
8649 | 8685 | assert(actorClass && "Bad closure actor isolation?"); |
|
0 commit comments