Skip to content

[Concurrency] Remove actorIndependent(unsafe) isolation. #36606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ class ActorIsolation {
/// meaning that it can be used from any actor but is also unable to
/// refer to the isolated state of any given actor.
Independent,
/// The declaration is explicitly specified to be independent of any actor,
/// but the programmer promises to protect the declaration from concurrent
/// accesses manually. Thus, it is okay if this declaration is a mutable
/// variable that creates storage.
IndependentUnsafe,
/// The declaration is isolated to a global actor. It can refer to other
/// entities with the same global actor.
GlobalActor,
Expand Down Expand Up @@ -84,18 +79,8 @@ class ActorIsolation {
return ActorIsolation(Unspecified, nullptr);
}

static ActorIsolation forIndependent(ActorIndependentKind indepKind) {
ActorIsolation::Kind isoKind;
switch (indepKind) {
case ActorIndependentKind::Safe:
isoKind = Independent;
break;

case ActorIndependentKind::Unsafe:
isoKind = IndependentUnsafe;
break;
}
return ActorIsolation(isoKind, nullptr);
static ActorIsolation forIndependent() {
return ActorIsolation(Independent, nullptr);
}

static ActorIsolation forActorInstance(NominalTypeDecl *actor) {
Expand Down Expand Up @@ -141,7 +126,6 @@ class ActorIsolation {

switch (lhs.kind) {
case Independent:
case IndependentUnsafe:
case Unspecified:
return true;

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(actor, Actor,
DECL_ATTR(actorIndependent, ActorIndependent,
OnClass | OnStruct | OnEnum | OnExtension | OnFunc | OnConstructor |
OnVar | OnSubscript | ConcurrencyOnly |
ABIStableToAdd | ABIStableToRemove |
ABIBreakingToAdd | ABIBreakingToRemove |
APIBreakingToAdd | APIBreakingToRemove,
103)

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8034,7 +8034,7 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
switch (auto isolation = closure->getActorIsolation()) {
case ClosureActorIsolation::Independent:
return ActorIsolation::forIndependent(ActorIndependentKind::Safe);
return ActorIsolation::forIndependent();

case ClosureActorIsolation::GlobalActor: {
return ActorIsolation::forGlobalActor(
Expand Down
6 changes: 1 addition & 5 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,8 @@ static void formatDiagnosticArgument(StringRef Modifier,
Out << "actor-independent";
break;

case ActorIsolation::IndependentUnsafe:
Out << "actor-independent-unsafe";
break;

case ActorIsolation::Unspecified:
Out << "non-actor-isolated";
Out << "unspecified";
break;
}
}
Expand Down
6 changes: 0 additions & 6 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,6 @@ bool ActorIsolation::requiresSubstitution() const {
switch (kind) {
case ActorInstance:
case Independent:
case IndependentUnsafe:
case Unspecified:
return false;

Expand All @@ -1541,7 +1540,6 @@ ActorIsolation ActorIsolation::subst(SubstitutionMap subs) const {
switch (kind) {
case ActorInstance:
case Independent:
case IndependentUnsafe:
case Unspecified:
return *this;

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

case ActorIsolation::IndependentUnsafe:
out << "actor-independent (unsafe)";
break;

case ActorIsolation::Unspecified:
out << "unspecified actor isolation";
break;
Expand Down
1 change: 0 additions & 1 deletion lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
break;
case ActorIsolation::Unspecified:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
return;
}

Expand Down
2 changes: 0 additions & 2 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
switch (actorIsolation.getKind()) {
case ActorIsolation::Unspecified:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
case ActorIsolation::GlobalActorUnsafe:
break;

Expand Down Expand Up @@ -566,7 +565,6 @@ ExecutorBreadcrumb SILGenFunction::emitHopToTargetActor(SILLocation loc,
switch (actorIso.getKind()) {
case ActorIsolation::Unspecified:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
break;

case ActorIsolation::ActorInstance: {
Expand Down
27 changes: 3 additions & 24 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ ActorIsolationRestriction ActorIsolationRestriction::forDeclaration(
}

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

Expand Down Expand Up @@ -1549,7 +1548,6 @@ namespace {
switch (auto isolation = getActorIsolationOfContext(dc)) {
case ActorIsolation::ActorInstance:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
case ActorIsolation::Unspecified:
return isolation;

Expand Down Expand Up @@ -1725,10 +1723,6 @@ namespace {
return true;
}

case ActorIsolation::IndependentUnsafe:
// Allow unrestricted use of something in a global actor.
return false;

case ActorIsolation::Independent: {
auto result = tryMarkImplicitlyAsync(loc, valueRef, context);
if (result == AsyncMarkingResult::FoundAsync)
Expand Down Expand Up @@ -2099,7 +2093,6 @@ namespace {

return false;

case ActorIsolation::IndependentUnsafe:
case ActorIsolation::Unspecified:
return false;

Expand Down Expand Up @@ -2212,7 +2205,6 @@ namespace {
// We must have parent isolation determined to get here.
switch (parentIsolation) {
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
case ActorIsolation::Unspecified:
return ClosureActorIsolation::forIndependent();

Expand Down Expand Up @@ -2364,13 +2356,13 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
// If the declaration is explicitly marked 'nonisolated', report it as
// independent.
if (nonisolatedAttr) {
return ActorIsolation::forIndependent(ActorIndependentKind::Safe);
return ActorIsolation::forIndependent();
}

// If the declaration is explicitly marked @actorIndependent, report it as
// independent.
if (independentAttr) {
return ActorIsolation::forIndependent(independentAttr->getKind());
return ActorIsolation::forIndependent();
}

// If the declaration is marked with a global actor, report it as being
Expand Down Expand Up @@ -2438,7 +2430,6 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
case ActorIsolation::GlobalActor:
case ActorIsolation::GlobalActorUnsafe:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
break;
}

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

case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
// We only need one @actorIndependent.
if (sawActorIndependent)
return true;
Expand Down Expand Up @@ -2525,8 +2515,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
// A @Sendable function is assumed to be actor-independent.
if (auto func = dyn_cast<AbstractFunctionDecl>(value)) {
if (func->isSendable()) {
defaultIsolation = ActorIsolation::forIndependent(
ActorIndependentKind::Safe);
defaultIsolation = ActorIsolation::forIndependent();
}
}

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

// If the overridden declaration is @actorIndependent(unsafe) and the
// overriding declaration has been placed in a global actor, allow it.
if (overriddenIsolation.getKind() == ActorIsolation::IndependentUnsafe &&
isolation.isGlobalActor())
return;

// If the overridden declaration is from Objective-C with no actor annotation,
// and the overriding declaration has been placed in a global actor, allow it.
if (overridden->hasClangNode() && !overriddenIsolation &&
Expand All @@ -2736,7 +2717,6 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
if (overriddenIsolation == ActorIsolation::GlobalActorUnsafe) {
switch (isolation) {
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
case ActorIsolation::Unspecified:
return;

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

case ActorIsolation::ActorInstance:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
// Diagnose below.
break;

Expand Down
1 change: 0 additions & 1 deletion lib/Sema/TypeCheckPropertyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
case ActorIsolation::GlobalActor:
case ActorIsolation::GlobalActorUnsafe:
case ActorIsolation::Independent:
case ActorIsolation::IndependentUnsafe:
case ActorIsolation::Unspecified:
break;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2807,10 +2807,6 @@ bool ConformanceChecker::checkActorIsolation(
break;
}

case ActorIsolation::IndependentUnsafe:
// The requirement is explicitly unsafe; allow it.
return false;

case ActorIsolation::Independent:
case ActorIsolation::Unspecified:
break;
Expand Down
Loading