Skip to content

Commit 4606c9f

Browse files
authored
Merge pull request swiftlang#59424 from DougGregor/sendable-actor-isolated-functions
2 parents 35355af + fe26d15 commit 4606c9f

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,6 +4563,9 @@ ERROR(effectful_keypath_component,none,
45634563
ERROR(local_function_executed_concurrently,none,
45644564
"concurrently-executed %0 %1 must be marked as '@Sendable'",
45654565
(DescriptiveDeclKind, DeclName))
4566+
ERROR(sendable_isolated_sync_function,none,
4567+
"%0 synchronous %1 %2 cannot be marked as '@Sendable'",
4568+
(ActorIsolation, DescriptiveDeclKind, DeclName))
45664569
ERROR(concurrent_access_of_local_capture,none,
45674570
"%select{mutation of|reference to}0 captured %1 %2 in "
45684571
"concurrently-executing code",

lib/Sema/TypeCheckAttr.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
149149
IGNORED_ATTR(OriginallyDefinedIn)
150150
IGNORED_ATTR(NoDerivative)
151151
IGNORED_ATTR(SpecializeExtension)
152-
IGNORED_ATTR(Sendable)
153152
IGNORED_ATTR(NonSendable)
154153
IGNORED_ATTR(AtRethrows)
155154
IGNORED_ATTR(AtReasync)
@@ -321,6 +320,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
321320
void checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs);
322321

323322
void visitKnownToBeLocalAttr(KnownToBeLocalAttr *attr);
323+
324+
void visitSendableAttr(SendableAttr *attr);
324325
};
325326

326327
} // end anonymous namespace
@@ -5842,6 +5843,21 @@ void AttributeChecker::visitKnownToBeLocalAttr(KnownToBeLocalAttr *attr) {
58425843
}
58435844
}
58445845

5846+
void AttributeChecker::visitSendableAttr(SendableAttr *attr) {
5847+
5848+
if ((isa<AbstractFunctionDecl>(D) || isa<AbstractStorageDecl>(D)) &&
5849+
!isAsyncDecl(cast<ValueDecl>(D))) {
5850+
auto value = cast<ValueDecl>(D);
5851+
ActorIsolation isolation = getActorIsolation(value);
5852+
if (isolation.isActorIsolated()) {
5853+
diagnoseAndRemoveAttr(
5854+
attr, diag::sendable_isolated_sync_function,
5855+
isolation, value->getDescriptiveKind(), value->getName())
5856+
.warnUntilSwiftVersion(6);
5857+
}
5858+
}
5859+
}
5860+
58455861
void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
58465862
// 'nonisolated' can be applied to global and static/class variables
58475863
// that do not have storage.

test/Concurrency/Backdeploy/mangling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 %s -o %t/test_mangling -Xfrontend -disable-availability-checking
1313
// RUN: %target-run %t/test_mangling
1414

15-
// REQUIRESx: CPU=x86_64
1615
// REQUIRES: OS=macosx
1716
// REQUIRES: executable_test
1817
// REQUIRES: concurrency_runtime
18+
// UNSUPPORTED: back_deployment_runtime
1919

2020
actor MyActor { }
2121

test/Concurrency/Backdeploy/objc_actor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// REQUIRES: OS=macosx
66
// REQUIRES: executable_test
77
// REQUIRES: concurrency_runtime
8+
// UNSUPPORTED: back_deployment_runtime
89

910
import Foundation
1011

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// REQUIRES: concurrency
3+
4+
5+
@Sendable func globalFunc() { }
6+
7+
@available(SwiftStdlib 5.1, *)
8+
actor A {
9+
var state: Bool = false
10+
11+
@Sendable func f() { // expected-warning{{actor-isolated synchronous instance method 'f()' cannot be marked as '@Sendable'}}
12+
state = true
13+
}
14+
15+
@Sendable nonisolated func g() { }
16+
17+
@Sendable func fAsync() async {
18+
state = true
19+
}
20+
}
21+
22+
@available(SwiftStdlib 5.1, *)
23+
@MainActor @Sendable func globalActorFunc() { } // expected-warning{{main actor-isolated synchronous global function 'globalActorFunc()' cannot be marked as '@Sendable'}}
24+
25+
@available(SwiftStdlib 5.1, *)
26+
@MainActor @Sendable func globalActorFuncAsync() async { }

0 commit comments

Comments
 (0)