Skip to content

Commit 9d8fde8

Browse files
committed
[Concurrency] Remove actorIndependent(unsafe) isolation.
Don't treat `actorIndependent(unsafe)` as its own kind of isolation. It was only really used as a bring-up hack to break the isolation model, but shouldn't be in the user model of the language and causes complications to the implementation.
1 parent d7b2887 commit 9d8fde8

11 files changed

+8
-294
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ class ActorIsolation {
5151
/// meaning that it can be used from any actor but is also unable to
5252
/// refer to the isolated state of any given actor.
5353
Independent,
54-
/// The declaration is explicitly specified to be independent of any actor,
55-
/// but the programmer promises to protect the declaration from concurrent
56-
/// accesses manually. Thus, it is okay if this declaration is a mutable
57-
/// variable that creates storage.
58-
IndependentUnsafe,
5954
/// The declaration is isolated to a global actor. It can refer to other
6055
/// entities with the same global actor.
6156
GlobalActor,
@@ -84,18 +79,8 @@ class ActorIsolation {
8479
return ActorIsolation(Unspecified, nullptr);
8580
}
8681

87-
static ActorIsolation forIndependent(ActorIndependentKind indepKind) {
88-
ActorIsolation::Kind isoKind;
89-
switch (indepKind) {
90-
case ActorIndependentKind::Safe:
91-
isoKind = Independent;
92-
break;
93-
94-
case ActorIndependentKind::Unsafe:
95-
isoKind = IndependentUnsafe;
96-
break;
97-
}
98-
return ActorIsolation(isoKind, nullptr);
82+
static ActorIsolation forIndependent() {
83+
return ActorIsolation(Independent, nullptr);
9984
}
10085

10186
static ActorIsolation forActorInstance(NominalTypeDecl *actor) {
@@ -141,7 +126,6 @@ class ActorIsolation {
141126

142127
switch (lhs.kind) {
143128
case Independent:
144-
case IndependentUnsafe:
145129
case Unspecified:
146130
return true;
147131

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(actor, Actor,
580580
DECL_ATTR(actorIndependent, ActorIndependent,
581581
OnClass | OnStruct | OnEnum | OnExtension | OnFunc | OnConstructor |
582582
OnVar | OnSubscript | ConcurrencyOnly |
583-
ABIStableToAdd | ABIStableToRemove |
583+
ABIBreakingToAdd | ABIBreakingToRemove |
584584
APIBreakingToAdd | APIBreakingToRemove,
585585
103)
586586

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8034,7 +8034,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
80348034
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
80358035
switch (auto isolation = closure->getActorIsolation()) {
80368036
case ClosureActorIsolation::Independent:
8037-
return ActorIsolation::forIndependent(ActorIndependentKind::Safe);
8037+
return ActorIsolation::forIndependent();
80388038

80398039
case ClosureActorIsolation::GlobalActor: {
80408040
return ActorIsolation::forGlobalActor(

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,8 @@ static void formatDiagnosticArgument(StringRef Modifier,
706706
Out << "actor-independent";
707707
break;
708708

709-
case ActorIsolation::IndependentUnsafe:
710-
Out << "actor-independent-unsafe";
711-
break;
712-
713709
case ActorIsolation::Unspecified:
714-
Out << "non-actor-isolated";
710+
Out << "unspecified";
715711
break;
716712
}
717713
}

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,6 @@ bool ActorIsolation::requiresSubstitution() const {
15261526
switch (kind) {
15271527
case ActorInstance:
15281528
case Independent:
1529-
case IndependentUnsafe:
15301529
case Unspecified:
15311530
return false;
15321531

@@ -1541,7 +1540,6 @@ ActorIsolation ActorIsolation::subst(SubstitutionMap subs) const {
15411540
switch (kind) {
15421541
case ActorInstance:
15431542
case Independent:
1544-
case IndependentUnsafe:
15451543
case Unspecified:
15461544
return *this;
15471545

@@ -1564,10 +1562,6 @@ void swift::simple_display(
15641562
out << "actor-independent";
15651563
break;
15661564

1567-
case ActorIsolation::IndependentUnsafe:
1568-
out << "actor-independent (unsafe)";
1569-
break;
1570-
15711565
case ActorIsolation::Unspecified:
15721566
out << "unspecified actor isolation";
15731567
break;

lib/IDE/CodeCompletion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25352535
break;
25362536
case ActorIsolation::Unspecified:
25372537
case ActorIsolation::Independent:
2538-
case ActorIsolation::IndependentUnsafe:
25392538
return;
25402539
}
25412540

lib/SILGen/SILGenProlog.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
473473
switch (actorIsolation.getKind()) {
474474
case ActorIsolation::Unspecified:
475475
case ActorIsolation::Independent:
476-
case ActorIsolation::IndependentUnsafe:
477476
case ActorIsolation::GlobalActorUnsafe:
478477
break;
479478

@@ -566,7 +565,6 @@ ExecutorBreadcrumb SILGenFunction::emitHopToTargetActor(SILLocation loc,
566565
switch (actorIso.getKind()) {
567566
case ActorIsolation::Unspecified:
568567
case ActorIsolation::Independent:
569-
case ActorIsolation::IndependentUnsafe:
570568
break;
571569

572570
case ActorIsolation::ActorInstance: {

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ ActorIsolationRestriction ActorIsolationRestriction::forDeclaration(
668668
}
669669

670670
case ActorIsolation::Independent:
671-
case ActorIsolation::IndependentUnsafe:
672671
// Actor-independent have no restrictions on their access.
673672
return forUnrestricted();
674673

@@ -1549,7 +1548,6 @@ namespace {
15491548
switch (auto isolation = getActorIsolationOfContext(dc)) {
15501549
case ActorIsolation::ActorInstance:
15511550
case ActorIsolation::Independent:
1552-
case ActorIsolation::IndependentUnsafe:
15531551
case ActorIsolation::Unspecified:
15541552
return isolation;
15551553

@@ -1725,10 +1723,6 @@ namespace {
17251723
return true;
17261724
}
17271725

1728-
case ActorIsolation::IndependentUnsafe:
1729-
// Allow unrestricted use of something in a global actor.
1730-
return false;
1731-
17321726
case ActorIsolation::Independent: {
17331727
auto result = tryMarkImplicitlyAsync(loc, valueRef, context);
17341728
if (result == AsyncMarkingResult::FoundAsync)
@@ -2099,7 +2093,6 @@ namespace {
20992093

21002094
return false;
21012095

2102-
case ActorIsolation::IndependentUnsafe:
21032096
case ActorIsolation::Unspecified:
21042097
return false;
21052098

@@ -2212,7 +2205,6 @@ namespace {
22122205
// We must have parent isolation determined to get here.
22132206
switch (parentIsolation) {
22142207
case ActorIsolation::Independent:
2215-
case ActorIsolation::IndependentUnsafe:
22162208
case ActorIsolation::Unspecified:
22172209
return ClosureActorIsolation::forIndependent();
22182210

@@ -2364,13 +2356,13 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
23642356
// If the declaration is explicitly marked 'nonisolated', report it as
23652357
// independent.
23662358
if (nonisolatedAttr) {
2367-
return ActorIsolation::forIndependent(ActorIndependentKind::Safe);
2359+
return ActorIsolation::forIndependent();
23682360
}
23692361

23702362
// If the declaration is explicitly marked @actorIndependent, report it as
23712363
// independent.
23722364
if (independentAttr) {
2373-
return ActorIsolation::forIndependent(independentAttr->getKind());
2365+
return ActorIsolation::forIndependent();
23742366
}
23752367

23762368
// If the declaration is marked with a global actor, report it as being
@@ -2438,7 +2430,6 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
24382430
case ActorIsolation::GlobalActor:
24392431
case ActorIsolation::GlobalActorUnsafe:
24402432
case ActorIsolation::Independent:
2441-
case ActorIsolation::IndependentUnsafe:
24422433
break;
24432434
}
24442435

@@ -2463,7 +2454,6 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
24632454
llvm_unreachable("protocol requirements cannot be actor instances");
24642455

24652456
case ActorIsolation::Independent:
2466-
case ActorIsolation::IndependentUnsafe:
24672457
// We only need one @actorIndependent.
24682458
if (sawActorIndependent)
24692459
return true;
@@ -2525,8 +2515,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
25252515
// A @Sendable function is assumed to be actor-independent.
25262516
if (auto func = dyn_cast<AbstractFunctionDecl>(value)) {
25272517
if (func->isSendable()) {
2528-
defaultIsolation = ActorIsolation::forIndependent(
2529-
ActorIndependentKind::Safe);
2518+
defaultIsolation = ActorIsolation::forIndependent();
25302519
}
25312520
}
25322521

@@ -2545,8 +2534,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
25452534
// inferred, so that (e.g.) it will be printed and serialized.
25462535
ASTContext &ctx = value->getASTContext();
25472536
switch (inferred) {
2548-
// FIXME: if the context is 'unsafe', is it fine to infer the 'safe' one?
2549-
case ActorIsolation::IndependentUnsafe:
25502537
case ActorIsolation::Independent:
25512538
value->getAttrs().add(new (ctx) ActorIndependentAttr(
25522539
ActorIndependentKind::Safe, /*IsImplicit=*/true));
@@ -2719,12 +2706,6 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
27192706
if (isolation == overriddenIsolation)
27202707
return;
27212708

2722-
// If the overridden declaration is @actorIndependent(unsafe) and the
2723-
// overriding declaration has been placed in a global actor, allow it.
2724-
if (overriddenIsolation.getKind() == ActorIsolation::IndependentUnsafe &&
2725-
isolation.isGlobalActor())
2726-
return;
2727-
27282709
// If the overridden declaration is from Objective-C with no actor annotation,
27292710
// and the overriding declaration has been placed in a global actor, allow it.
27302711
if (overridden->hasClangNode() && !overriddenIsolation &&
@@ -2736,7 +2717,6 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
27362717
if (overriddenIsolation == ActorIsolation::GlobalActorUnsafe) {
27372718
switch (isolation) {
27382719
case ActorIsolation::Independent:
2739-
case ActorIsolation::IndependentUnsafe:
27402720
case ActorIsolation::Unspecified:
27412721
return;
27422722

@@ -2765,7 +2745,6 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
27652745

27662746
case ActorIsolation::ActorInstance:
27672747
case ActorIsolation::Independent:
2768-
case ActorIsolation::IndependentUnsafe:
27692748
// Diagnose below.
27702749
break;
27712750

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
9393
case ActorIsolation::GlobalActor:
9494
case ActorIsolation::GlobalActorUnsafe:
9595
case ActorIsolation::Independent:
96-
case ActorIsolation::IndependentUnsafe:
9796
case ActorIsolation::Unspecified:
9897
break;
9998
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,10 +2807,6 @@ bool ConformanceChecker::checkActorIsolation(
28072807
break;
28082808
}
28092809

2810-
case ActorIsolation::IndependentUnsafe:
2811-
// The requirement is explicitly unsafe; allow it.
2812-
return false;
2813-
28142810
case ActorIsolation::Independent:
28152811
case ActorIsolation::Unspecified:
28162812
break;

0 commit comments

Comments
 (0)