Skip to content

Commit 4715a34

Browse files
authored
Merge pull request #40413 from DougGregor/remove-sendable-nonisolated-check
2 parents 632c5ca + 7033944 commit 4715a34

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,19 @@ ActorIsolationRestriction ActorIsolationRestriction::forDeclaration(
428428
// nonisolated, they need cross-actor restrictions (e.g., for Sendable).
429429
if (auto *ctor = dyn_cast<ConstructorDecl>(decl))
430430
if (!ctor->isConvenienceInit())
431-
if (auto *parent = dyn_cast<ClassDecl>(ctor->getParent()))
432-
if (parent->isAnyActor())
433-
return forActorSelf(parent, /*isCrossActor=*/true);
431+
if (auto *parent = ctor->getParent()->getSelfClassDecl())
432+
if (parent->isAnyActor())
433+
return forActorSelf(parent, /*isCrossActor=*/true);
434+
435+
// `nonisolated let` members are cross-actor as well.
436+
if (auto var = dyn_cast<VarDecl>(decl)) {
437+
if (var->isInstanceMember() && var->isLet()) {
438+
if (auto parent = var->getDeclContext()->getSelfClassDecl()) {
439+
if (parent->isActor() && !parent->isDistributedActor())
440+
return forActorSelf(parent, /*isCrossActor=*/true);
441+
}
442+
}
443+
}
434444

435445
return forUnrestricted();
436446

@@ -3214,18 +3224,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
32143224
// If this declaration has one of the actor isolation attributes, report
32153225
// that.
32163226
if (isolationFromAttr) {
3217-
// Nonisolated declarations must involve Sendable types.
3218-
if (*isolationFromAttr == ActorIsolation::Independent) {
3219-
SubstitutionMap subs;
3220-
if (auto genericEnv = value->getInnermostDeclContext()
3221-
->getGenericEnvironmentOfContext()) {
3222-
subs = genericEnv->getForwardingSubstitutionMap();
3223-
}
3224-
diagnoseNonSendableTypesInReference(
3225-
ConcreteDeclRef(value, subs), value->getDeclContext(),
3226-
value->getLoc(), ConcurrentReferenceKind::Nonisolated);
3227-
}
3228-
32293227
// Classes with global actors have additional rules regarding inheritance.
32303228
if (isolationFromAttr->isGlobalActor()) {
32313229
if (auto classDecl = dyn_cast<ClassDecl>(value))

test/Concurrency/concurrent_value_checking.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func testUnsafeSendableInAsync() async {
157157
// ----------------------------------------------------------------------
158158
// Sendable restriction on key paths.
159159
// ----------------------------------------------------------------------
160-
class NC: Hashable { // expected-note 3{{class 'NC' does not conform to the 'Sendable' protocol}}
160+
class NC: Hashable { // expected-note 2{{class 'NC' does not conform to the 'Sendable' protocol}}
161161
func hash(into: inout Hasher) { }
162162
static func==(_: NC, _: NC) -> Bool { true }
163163
}
@@ -174,9 +174,12 @@ func testKeyPaths(dict: [NC: Int], nc: NC) {
174174
// Sendable restriction on nonisolated declarations.
175175
// ----------------------------------------------------------------------
176176
actor ANI {
177-
// FIXME: improve diagnostics to talk about nonisolated
178-
nonisolated let nc = NC() // expected-warning{{cannot use property 'nc' with a non-sendable type 'NC' across actors}}
179-
nonisolated func f() -> NC? { nil } // expected-warning{{cannot call function returning non-sendable type 'NC?' across actors}}
177+
nonisolated let nc = NC()
178+
nonisolated func f() -> NC? { nil }
179+
}
180+
181+
func testANI(ani: ANI) async {
182+
_ = ani.nc // expected-warning{{cannot use property 'nc' with a non-sendable type 'NC' across actors}}
180183
}
181184

182185
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)