Skip to content

Commit 3945ce0

Browse files
committed
Remove now-unused "unsafe sendable" and "unsafe main actor" closure bits.
1 parent 913650d commit 3945ce0

File tree

4 files changed

+11
-88
lines changed

4 files changed

+11
-88
lines changed

include/swift/AST/Expr.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,12 +3683,6 @@ class ClosureExpr : public AbstractClosureExpr {
36833683
SeparatelyTypeChecked,
36843684
};
36853685

3686-
/// Bits used to indicate contextual information that is concurrency-specific.
3687-
enum UnsafeConcurrencyBits {
3688-
Sendable = 1 << 0,
3689-
MainActor = 1 << 1
3690-
};
3691-
36923686
private:
36933687
/// The attributes attached to the closure.
36943688
DeclAttributes Attributes;
@@ -3703,10 +3697,7 @@ class ClosureExpr : public AbstractClosureExpr {
37033697
/// the CaptureListExpr which would normally maintain this sort of
37043698
/// information about captured variables), we need to have some way to access
37053699
/// this information directly on the ClosureExpr.
3706-
///
3707-
/// The integer indicates how the closure is contextually concurrent.
3708-
llvm::PointerIntPair<VarDecl *, 2, uint8_t>
3709-
CapturedSelfDeclAndUnsafeConcurrent;
3700+
VarDecl *CapturedSelfDecl;
37103701

37113702
/// The location of the "async", if present.
37123703
SourceLoc AsyncLoc;
@@ -3736,7 +3727,7 @@ class ClosureExpr : public AbstractClosureExpr {
37363727
: AbstractClosureExpr(ExprKind::Closure, Type(), /*Implicit=*/false,
37373728
discriminator, parent),
37383729
Attributes(attributes), BracketRange(bracketRange),
3739-
CapturedSelfDeclAndUnsafeConcurrent(capturedSelfDecl, 0),
3730+
CapturedSelfDecl(capturedSelfDecl),
37403731
AsyncLoc(asyncLoc), ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc),
37413732
InLoc(inLoc),
37423733
ExplicitResultTypeAndBodyState(explicitResultType, BodyState::Parsed),
@@ -3864,27 +3855,7 @@ class ClosureExpr : public AbstractClosureExpr {
38643855

38653856
/// VarDecl captured by this closure under the literal name \c self , if any.
38663857
VarDecl *getCapturedSelfDecl() const {
3867-
return CapturedSelfDeclAndUnsafeConcurrent.getPointer();
3868-
}
3869-
3870-
bool isUnsafeSendable() const {
3871-
return CapturedSelfDeclAndUnsafeConcurrent.getInt() &
3872-
UnsafeConcurrencyBits::Sendable;
3873-
}
3874-
3875-
bool isUnsafeMainActor() const {
3876-
return CapturedSelfDeclAndUnsafeConcurrent.getInt() &
3877-
UnsafeConcurrencyBits::MainActor;
3878-
}
3879-
3880-
void setUnsafeConcurrent(bool sendable, bool forMainActor) {
3881-
uint8_t bits = 0;
3882-
if (sendable)
3883-
bits |= UnsafeConcurrencyBits::Sendable;
3884-
if (forMainActor)
3885-
bits |= UnsafeConcurrencyBits::MainActor;
3886-
3887-
CapturedSelfDeclAndUnsafeConcurrent.setInt(bits);
3858+
return CapturedSelfDecl;
38883859
}
38893860

38903861
/// Get the type checking state of this closure's body.

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,7 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
583583
break;
584584
}
585585
} else if (auto *closureExpr = dyn_cast<AbstractClosureExpr>(FunctionDC)) {
586-
bool wantExecutor = F.isAsync() ||
587-
(wantDataRaceChecks &&
588-
!(isa<ClosureExpr>(closureExpr) &&
589-
cast<ClosureExpr>(closureExpr)->isUnsafeMainActor()));
586+
bool wantExecutor = F.isAsync() || wantDataRaceChecks;
590587
auto actorIsolation = closureExpr->getActorIsolation();
591588
switch (actorIsolation.getKind()) {
592589
case ClosureActorIsolation::Independent:

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5631,59 +5631,25 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
56315631

56325632
/// Apply the contextually Sendable flag to the given expression,
56335633
static void applyContextualClosureFlags(
5634-
Expr *expr, bool sendable, bool forMainActor, bool implicitSelfCapture,
5635-
bool inheritActorContext) {
5634+
Expr *expr, bool implicitSelfCapture, bool inheritActorContext) {
56365635
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
5637-
closure->setUnsafeConcurrent(sendable, forMainActor);
56385636
closure->setAllowsImplicitSelfCapture(implicitSelfCapture);
56395637
closure->setInheritsActorContext(inheritActorContext);
56405638
return;
56415639
}
56425640

56435641
if (auto captureList = dyn_cast<CaptureListExpr>(expr)) {
56445642
applyContextualClosureFlags(
5645-
captureList->getClosureBody(), sendable, forMainActor,
5646-
implicitSelfCapture, inheritActorContext);
5643+
captureList->getClosureBody(), implicitSelfCapture,
5644+
inheritActorContext);
56475645
}
56485646

56495647
if (auto identity = dyn_cast<IdentityExpr>(expr)) {
56505648
applyContextualClosureFlags(
5651-
identity->getSubExpr(), sendable, forMainActor,
5652-
implicitSelfCapture, inheritActorContext);
5649+
identity->getSubExpr(), implicitSelfCapture, inheritActorContext);
56535650
}
56545651
}
56555652

5656-
/// Whether this is a reference to a method on the main dispatch queue.
5657-
static bool isMainDispatchQueue(Expr *arg) {
5658-
auto call = dyn_cast<DotSyntaxCallExpr>(arg);
5659-
if (!call)
5660-
return false;
5661-
5662-
auto memberRef = dyn_cast<MemberRefExpr>(
5663-
call->getBase()->getValueProvidingExpr());
5664-
if (!memberRef)
5665-
return false;
5666-
5667-
auto member = memberRef->getMember();
5668-
if (member.getDecl()->getName().getBaseName().userFacingName() != "main")
5669-
return false;
5670-
5671-
auto typeExpr = dyn_cast<TypeExpr>(
5672-
memberRef->getBase()->getValueProvidingExpr());
5673-
if (!typeExpr)
5674-
return false;
5675-
5676-
Type baseType = typeExpr->getInstanceType();
5677-
if (!baseType)
5678-
return false;
5679-
5680-
auto baseNominal = baseType->getAnyNominal();
5681-
if (!baseNominal)
5682-
return false;
5683-
5684-
return baseNominal->getName().str() == "DispatchQueue";
5685-
}
5686-
56875653
ArgumentList *ExprRewriter::coerceCallArguments(
56885654
ArgumentList *args, AnyFunctionType *funcType, ConcreteDeclRef callee,
56895655
ApplyExpr *apply, ConstraintLocatorBuilder locator,
@@ -5825,14 +5791,12 @@ ArgumentList *ExprRewriter::coerceCallArguments(
58255791
// for things like trailing closures and args to property wrapper params.
58265792
arg.setLabel(param.getLabel());
58275793

5828-
// Determine whether the closure argument should be treated as being on
5829-
// the main actor, having implicit self capture, or inheriting actor
5830-
// context.
5794+
// Determine whether the closure argument should be treated as having
5795+
// implicit self capture or inheriting actor context.
58315796
bool isImplicitSelfCapture = paramInfo.isImplicitSelfCapture(paramIdx);
58325797
bool inheritsActorContext = paramInfo.inheritsActorContext(paramIdx);
58335798
applyContextualClosureFlags(
5834-
argExpr, false,
5835-
false, isImplicitSelfCapture, inheritsActorContext);
5799+
argExpr, isImplicitSelfCapture, inheritsActorContext);
58365800

58375801
// If the types exactly match, this is easy.
58385802
auto paramType = param.getOldType();

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,6 @@ static bool isSendableClosure(
521521
if (forActorIsolation && explicitClosure->inheritsActorContext()) {
522522
return false;
523523
}
524-
525-
if (explicitClosure->isUnsafeSendable())
526-
return true;
527524
}
528525

529526
if (auto type = closure->getType()) {
@@ -2578,12 +2575,6 @@ namespace {
25782575
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
25792576
if (Type globalActorType = resolveGlobalActorType(explicitClosure))
25802577
return ClosureActorIsolation::forGlobalActor(globalActorType);
2581-
2582-
if (explicitClosure->isUnsafeMainActor()) {
2583-
ASTContext &ctx = closure->getASTContext();
2584-
if (Type mainActor = ctx.getMainActorType())
2585-
return ClosureActorIsolation::forGlobalActor(mainActor);
2586-
}
25872578
}
25882579

25892580
// Sendable closures are actor-independent unless the closure has

0 commit comments

Comments
 (0)