Skip to content

Commit 0ae3d47

Browse files
committed
[AST] Move conversion of ClosureActorIsolation to ActorIsolation to its own function
Just a little bit of cleanup because this logic is really quite general and doesn't need to live in `getActorIsolationOfContext`.
1 parent e7d55b2 commit 0ae3d47

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

include/swift/AST/Expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,8 @@ class ClosureActorIsolation {
36583658
bool preconcurrency() const {
36593659
return storage.getInt();
36603660
}
3661+
3662+
ActorIsolation getActorIsolation() const;
36613663
};
36623664

36633665
/// A base class for closure expressions.

lib/AST/Decl.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9225,28 +9225,8 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
92259225
if (auto *var = dcToUse->getNonLocalVarDecl())
92269226
return getActorIsolation(var);
92279227

9228-
if (auto *closure = dyn_cast<AbstractClosureExpr>(dcToUse)) {
9229-
switch (auto isolation = closure->getActorIsolation()) {
9230-
case ClosureActorIsolation::Independent:
9231-
return ActorIsolation::forIndependent()
9232-
.withPreconcurrency(isolation.preconcurrency());
9233-
9234-
case ClosureActorIsolation::GlobalActor: {
9235-
return ActorIsolation::forGlobalActor(
9236-
isolation.getGlobalActor(), /*unsafe=*/false)
9237-
.withPreconcurrency(isolation.preconcurrency());
9238-
}
9239-
9240-
case ClosureActorIsolation::ActorInstance: {
9241-
auto selfDecl = isolation.getActorInstance();
9242-
auto actor = selfDecl->getType()->getReferenceStorageReferent()
9243-
->getAnyActor();
9244-
assert(actor && "Bad closure actor isolation?");
9245-
// FIXME: This could be a parameter... or a capture... hmmm.
9246-
return ActorIsolation::forActorInstanceSelf(actor)
9247-
.withPreconcurrency(isolation.preconcurrency());
9248-
}
9249-
}
9228+
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
9229+
return closure->getActorIsolation().getActorIsolation();
92509230
}
92519231

92529232
if (auto *tld = dyn_cast<TopLevelCodeDecl>(dcToUse)) {

lib/AST/Expr.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,29 @@ RebindSelfInConstructorExpr::getCalledConstructor(bool &isChainToSuper) const {
17791779
return otherCtorRef;
17801780
}
17811781

1782+
ActorIsolation ClosureActorIsolation::getActorIsolation() const {
1783+
switch (getKind()) {
1784+
case ClosureActorIsolation::Independent:
1785+
return ActorIsolation::forIndependent().withPreconcurrency(
1786+
preconcurrency());
1787+
1788+
case ClosureActorIsolation::GlobalActor: {
1789+
return ActorIsolation::forGlobalActor(getGlobalActor(), /*unsafe=*/false)
1790+
.withPreconcurrency(preconcurrency());
1791+
}
1792+
1793+
case ClosureActorIsolation::ActorInstance: {
1794+
auto selfDecl = getActorInstance();
1795+
auto actor =
1796+
selfDecl->getType()->getReferenceStorageReferent()->getAnyActor();
1797+
assert(actor && "Bad closure actor isolation?");
1798+
// FIXME: This could be a parameter... or a capture... hmmm.
1799+
return ActorIsolation::forActorInstanceSelf(actor).withPreconcurrency(
1800+
preconcurrency());
1801+
}
1802+
}
1803+
}
1804+
17821805
void AbstractClosureExpr::setParameterList(ParameterList *P) {
17831806
parameterList = P;
17841807
// Change the DeclContext of any parameters to be this closure.

0 commit comments

Comments
 (0)