Skip to content

Commit f4c5a26

Browse files
committed
@concurrent functions are actor-independent
Concurrent functions need to be actor-independent because they wouldn't ever be safe to run concurrently while isolated on an actor. This allows us to elimate the "may execute concurrently with" check related to actor isolation, which is a cleaner overall story.
1 parent 8eae527 commit f4c5a26

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,10 +4257,6 @@ WARNING(concurrent_access_local,none,
42574257
"local %0 %1 is unsafe to reference in code that may execute "
42584258
"concurrently",
42594259
(DescriptiveDeclKind, DeclName))
4260-
ERROR(actor_isolated_concurrent_access,none,
4261-
"actor-isolated %0 %1 is unsafe to reference in code "
4262-
"that may execute concurrently",
4263-
(DescriptiveDeclKind, DeclName))
42644260
ERROR(actor_isolated_from_concurrent_closure,none,
42654261
"actor-isolated %0 %1 cannot be referenced from a concurrent closure",
42664262
(DescriptiveDeclKind, DeclName))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,17 +1372,6 @@ namespace {
13721372
return true;
13731373
}
13741374

1375-
// Check whether we are in a context that will not execute concurrently
1376-
// with the context of 'self'.
1377-
if (mayExecuteConcurrentlyWith(
1378-
getDeclContext(), selfVar->getDeclContext())) {
1379-
ctx.Diags.diagnose(
1380-
memberLoc, diag::actor_isolated_concurrent_access,
1381-
member->getDescriptiveKind(), member->getName());
1382-
noteIsolatedActorMember(member);
1383-
return true;
1384-
}
1385-
13861375
// It's fine.
13871376
return false;
13881377
}
@@ -1809,6 +1798,14 @@ ActorIsolation ActorIsolationRequest::evaluate(
18091798
// overridden by other inference rules.
18101799
ActorIsolation defaultIsolation = ActorIsolation::forUnspecified();
18111800

1801+
// A @concurrent function is assumed to be actor-independent.
1802+
if (auto func = dyn_cast<AbstractFunctionDecl>(value)) {
1803+
if (func->isConcurrent()) {
1804+
defaultIsolation = ActorIsolation::forIndependent(
1805+
ActorIndependentKind::Safe);
1806+
}
1807+
}
1808+
18121809
// Check for instance members of actor classes, which are part of
18131810
// actor-isolated state.
18141811
auto classDecl = value->getDeclContext()->getSelfClassDecl();

test/Concurrency/actor_isolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ extension MyActor {
156156

157157
// Local functions might run concurrently.
158158
@concurrent func localFn1() {
159-
_ = self.text[0] // expected-error{{actor-isolated property 'text' is unsafe to reference in code that may execute concurrently}}
160-
_ = self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' is unsafe to reference in code that may execute concurrently}}
159+
_ = self.text[0] // expected-error{{actor-isolated property 'text' cannot be referenced from a concurrent function}}
160+
_ = self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' cannot be referenced from a concurrent function}}
161161
_ = localVar // expected-warning{{local var 'localVar' is unsafe to reference in code that may execute concurrently}}
162162
_ = localConstant
163163
}

0 commit comments

Comments
 (0)