Skip to content

Commit 549b452

Browse files
committed
[Concurrency] Remove ClosureActorIsolation.
1 parent 97f1e61 commit 549b452

File tree

6 files changed

+18
-145
lines changed

6 files changed

+18
-145
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,92 +3777,6 @@ class SequenceExpr final : public Expr,
37773777
}
37783778
};
37793779

3780-
/// Actor isolation for a closure.
3781-
class ClosureActorIsolation {
3782-
public:
3783-
enum Kind {
3784-
/// The closure is not isolated to any actor.
3785-
Nonisolated,
3786-
3787-
/// The closure is tied to the actor instance described by the given
3788-
/// \c VarDecl*, which is the (captured) `self` of an actor.
3789-
ActorInstance,
3790-
3791-
/// The closure is tied to the global actor described by the given type.
3792-
GlobalActor,
3793-
};
3794-
3795-
private:
3796-
/// The actor to which this closure is isolated, plus a bit indicating
3797-
/// whether the isolation was imposed by a preconcurrency declaration.
3798-
///
3799-
/// There are three possible states for the pointer:
3800-
/// - NULL: The closure is independent of any actor.
3801-
/// - VarDecl*: The 'self' variable for the actor instance to which
3802-
/// this closure is isolated. It will always have a type that conforms
3803-
/// to the \c Actor protocol.
3804-
/// - Type: The type of the global actor on which
3805-
llvm::PointerIntPair<llvm::PointerUnion<VarDecl *, Type>, 1, bool> storage;
3806-
3807-
ClosureActorIsolation(VarDecl *selfDecl, bool preconcurrency)
3808-
: storage(selfDecl, preconcurrency) { }
3809-
ClosureActorIsolation(Type globalActorType, bool preconcurrency)
3810-
: storage(globalActorType, preconcurrency) { }
3811-
3812-
public:
3813-
ClosureActorIsolation(bool preconcurrency = false)
3814-
: storage(nullptr, preconcurrency) { }
3815-
3816-
static ClosureActorIsolation forNonisolated(bool preconcurrency) {
3817-
return ClosureActorIsolation(preconcurrency);
3818-
}
3819-
3820-
static ClosureActorIsolation forActorInstance(VarDecl *selfDecl,
3821-
bool preconcurrency) {
3822-
return ClosureActorIsolation(selfDecl, preconcurrency);
3823-
}
3824-
3825-
static ClosureActorIsolation forGlobalActor(Type globalActorType,
3826-
bool preconcurrency) {
3827-
return ClosureActorIsolation(globalActorType, preconcurrency);
3828-
}
3829-
3830-
/// Determine the kind of isolation.
3831-
Kind getKind() const {
3832-
if (storage.getPointer().isNull())
3833-
return Kind::Nonisolated;
3834-
3835-
if (storage.getPointer().is<VarDecl *>())
3836-
return Kind::ActorInstance;
3837-
3838-
return Kind::GlobalActor;
3839-
}
3840-
3841-
/// Whether the closure is isolated at all.
3842-
explicit operator bool() const {
3843-
return getKind() != Kind::Nonisolated;
3844-
}
3845-
3846-
/// Whether the closure is isolated at all.
3847-
operator Kind() const {
3848-
return getKind();
3849-
}
3850-
3851-
VarDecl *getActorInstance() const {
3852-
return storage.getPointer().dyn_cast<VarDecl *>();
3853-
}
3854-
3855-
Type getGlobalActor() const {
3856-
return storage.getPointer().dyn_cast<Type>();
3857-
}
3858-
3859-
bool preconcurrency() const {
3860-
return storage.getInt();
3861-
}
3862-
3863-
ActorIsolation getActorIsolation() const;
3864-
};
3865-
38663780
/// A base class for closure expressions.
38673781
class AbstractClosureExpr : public DeclContext, public Expr {
38683782
CaptureInfo Captures;
@@ -3960,29 +3874,6 @@ class AbstractClosureExpr : public DeclContext, public Expr {
39603874
this->actorIsolation = actorIsolation;
39613875
}
39623876

3963-
ClosureActorIsolation getClosureActorIsolation() const {
3964-
bool preconcurrency = actorIsolation.preconcurrency();
3965-
3966-
switch (actorIsolation) {
3967-
case ActorIsolation::Unspecified:
3968-
case ActorIsolation::Nonisolated:
3969-
return ClosureActorIsolation::forNonisolated(preconcurrency);
3970-
3971-
case ActorIsolation::ActorInstance:
3972-
return ClosureActorIsolation::forActorInstance(
3973-
actorIsolation.getActorInstance(), preconcurrency);
3974-
3975-
case ActorIsolation::GlobalActor:
3976-
case ActorIsolation::GlobalActorUnsafe:
3977-
return ClosureActorIsolation::forGlobalActor(
3978-
actorIsolation.getGlobalActor(), preconcurrency);
3979-
}
3980-
}
3981-
3982-
void setActorIsolation(ClosureActorIsolation closureIsolation) {
3983-
this->actorIsolation = closureIsolation.getActorIsolation();
3984-
}
3985-
39863877
static bool classof(const Expr *E) {
39873878
return E->getKind() >= ExprKind::First_AbstractClosureExpr &&
39883879
E->getKind() <= ExprKind::Last_AbstractClosureExpr;

lib/AST/ASTDumper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,16 +2687,18 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
26872687

26882688
printField(E->getRawDiscriminator(), "discriminator", DiscriminatorColor);
26892689

2690-
switch (auto isolation = E->getClosureActorIsolation()) {
2691-
case ClosureActorIsolation::Nonisolated:
2690+
switch (auto isolation = E->getActorIsolation()) {
2691+
case ActorIsolation::Unspecified:
2692+
case ActorIsolation::Nonisolated:
26922693
break;
26932694

2694-
case ClosureActorIsolation::ActorInstance:
2695+
case ActorIsolation::ActorInstance:
26952696
printFieldQuoted(isolation.getActorInstance()->printRef(),
26962697
"actor_isolated", CapturesColor);
26972698
break;
26982699

2699-
case ClosureActorIsolation::GlobalActor:
2700+
case ActorIsolation::GlobalActor:
2701+
case ActorIsolation::GlobalActorUnsafe:
27002702
printFieldQuoted(isolation.getGlobalActor().getString(),
27012703
"global_actor_isolated", CapturesColor);
27022704
break;

lib/AST/Decl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10305,12 +10305,14 @@ bool VarDecl::isSelfParamCaptureIsolated() const {
1030510305
}
1030610306

1030710307
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
10308-
switch (auto isolation = closure->getClosureActorIsolation()) {
10309-
case ClosureActorIsolation::Nonisolated:
10310-
case ClosureActorIsolation::GlobalActor:
10308+
switch (auto isolation = closure->getActorIsolation()) {
10309+
case ActorIsolation::Unspecified:
10310+
case ActorIsolation::Nonisolated:
10311+
case ActorIsolation::GlobalActor:
10312+
case ActorIsolation::GlobalActorUnsafe:
1031110313
return false;
1031210314

10313-
case ClosureActorIsolation::ActorInstance:
10315+
case ActorIsolation::ActorInstance:
1031410316
auto isolatedVar = isolation.getActorInstance();
1031510317
return isolatedVar->isSelfParameter() ||
1031610318
isolatedVar-isSelfParamCapture();

lib/AST/Expr.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,29 +1878,6 @@ RebindSelfInConstructorExpr::getCalledConstructor(bool &isChainToSuper) const {
18781878
return otherCtorRef;
18791879
}
18801880

1881-
ActorIsolation ClosureActorIsolation::getActorIsolation() const {
1882-
switch (getKind()) {
1883-
case ClosureActorIsolation::Nonisolated:
1884-
return ActorIsolation::forNonisolated().withPreconcurrency(
1885-
preconcurrency());
1886-
1887-
case ClosureActorIsolation::GlobalActor: {
1888-
return ActorIsolation::forGlobalActor(getGlobalActor(), /*unsafe=*/false)
1889-
.withPreconcurrency(preconcurrency());
1890-
}
1891-
1892-
case ClosureActorIsolation::ActorInstance: {
1893-
auto selfDecl = getActorInstance();
1894-
auto actor =
1895-
selfDecl->getTypeInContext()->getReferenceStorageReferent()->getAnyActor();
1896-
assert(actor && "Bad closure actor isolation?");
1897-
// FIXME: This could be a parameter... or a capture... hmmm.
1898-
return ActorIsolation::forActorInstanceCapture(
1899-
getActorInstance()).withPreconcurrency(preconcurrency());
1900-
}
1901-
}
1902-
}
1903-
19041881
unsigned AbstractClosureExpr::getDiscriminator() const {
19051882
auto raw = getRawDiscriminator();
19061883
if (raw != InvalidDiscriminator)

lib/SILGen/SILGenProlog.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,19 +1380,21 @@ void SILGenFunction::emitProlog(
13801380
}
13811381
} else if (auto *closureExpr = dyn_cast<AbstractClosureExpr>(FunctionDC)) {
13821382
bool wantExecutor = F.isAsync() || wantDataRaceChecks;
1383-
auto actorIsolation = closureExpr->getClosureActorIsolation();
1383+
auto actorIsolation = closureExpr->getActorIsolation();
13841384
switch (actorIsolation.getKind()) {
1385-
case ClosureActorIsolation::Nonisolated:
1385+
case ActorIsolation::Unspecified:
1386+
case ActorIsolation::Nonisolated:
13861387
break;
13871388

1388-
case ClosureActorIsolation::ActorInstance: {
1389+
case ActorIsolation::ActorInstance: {
13891390
if (wantExecutor) {
13901391
loadExpectedExecutorForLocalVar(actorIsolation.getActorInstance());
13911392
}
13921393
break;
13931394
}
13941395

1395-
case ClosureActorIsolation::GlobalActor:
1396+
case ActorIsolation::GlobalActor:
1397+
case ActorIsolation::GlobalActorUnsafe:
13961398
if (wantExecutor) {
13971399
ExpectedExecutor =
13981400
emitLoadGlobalActorExecutor(actorIsolation.getGlobalActor());

lib/Sema/TypeCheckConcurrency.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ActorIsolation;
3333
class AnyFunctionType;
3434
class ASTContext;
3535
class ClassDecl;
36-
class ClosureActorIsolation;
3736
class ClosureExpr;
3837
class ConcreteDeclRef;
3938
class CustomAttr;

0 commit comments

Comments
 (0)