Skip to content

[Concurrency] Loosen constraints on @actorIndependent placement. #35274

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
merged 1 commit into from
Jan 6, 2021
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
5 changes: 3 additions & 2 deletions include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(actor, Actor,
102)

DECL_ATTR(actorIndependent, ActorIndependent,
OnFunc | OnVar | OnSubscript | ConcurrencyOnly |
OnClass | OnStruct | OnEnum | OnExtension | OnFunc | OnConstructor |
OnVar | OnSubscript | ConcurrencyOnly |
ABIStableToAdd | ABIStableToRemove |
APIStableToAdd | APIBreakingToRemove,
APIBreakingToAdd | APIBreakingToRemove,
103)

SIMPLE_DECL_ATTR(globalActor, GlobalActor,
Expand Down
7 changes: 0 additions & 7 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4281,13 +4281,6 @@ ERROR(actorindependent_mutable_storage,none,
ERROR(actorindependent_local_var,none,
"'@actorIndependent' can not be applied to local variables",
())
ERROR(actorindependent_not_actor_member,none,
"'@actorIndependent' can only be applied to actor members and "
"global/static variables",
())
ERROR(actorindependent_not_actor_instance_member,none,
"'@actorIndependent' can only be applied to instance members of actors",
())

ERROR(concurrency_lib_missing,none,
"missing '%0' declaration, probably because the '_Concurrency' "
Expand Down
21 changes: 3 additions & 18 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
case ActorIndependentKind::Safe:
diagnoseAndRemoveAttr(attr, diag::actorindependent_mutable_storage);
return;

case ActorIndependentKind::Unsafe:
break;
}
Expand All @@ -315,26 +315,11 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
(dc->isTypeContext() && var->isStatic())) {
return;
}

// Otherwise, fall through to make sure we're in an appropriate
// context.
}

// @actorIndependent only makes sense on an actor instance member.
if (!dc->getSelfClassDecl() ||
!dc->getSelfClassDecl()->isActor()) {
diagnoseAndRemoveAttr(attr, diag::actorindependent_not_actor_member);
return;
if (auto VD = dyn_cast<ValueDecl>(D)) {
(void)getActorIsolation(VD);
}

auto VD = cast<ValueDecl>(D);
if (!VD->isInstanceMember()) {
diagnoseAndRemoveAttr(
attr, diag::actorindependent_not_actor_instance_member);
return;
}

(void)getActorIsolation(VD);
}

void visitGlobalActorAttr(GlobalActorAttr *attr) {
Expand Down
12 changes: 8 additions & 4 deletions test/attr/actorindependent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

// REQUIRES: concurrency

// expected-error@+1{{'@actorIndependent' can only be applied to actor members and global/static variables}}
@actorIndependent func globalFunction() { }

@actorIndependent var globalComputedProperty1: Int { 17 }
Expand Down Expand Up @@ -33,9 +32,11 @@ struct X {
}

class C {
// expected-error@+1{{'@actorIndependent' can only be applied to actor members and global/static variables}}
@actorIndependent
var property3: Int { 5 }

@actorIndependent
func f() { }
}

actor class A {
Expand Down Expand Up @@ -65,6 +66,8 @@ actor class A {
set { }
}

@actorIndependent init() { }

@actorIndependent
func synchronousFunc() { }

Expand All @@ -74,7 +77,6 @@ actor class A {
@actorIndependent
subscript(index: Int) -> String { "\(index)" }

// expected-error@+1{{'@actorIndependent' can only be applied to instance members of actors}}
@actorIndependent static func staticFunc() { }
}

Expand All @@ -95,4 +97,6 @@ actor class FromProperty {
// expected-error@+1{{actor-isolated property 'counter' can not be referenced from an '@actorIndependent' context}}
set { counter = newValue }
}
}
}

@actorIndependent extension FromProperty { }