Skip to content

Commit 6e18ffe

Browse files
authored
Merge pull request #72231 from gottesmm/pr-1390a8c8ab469f02b49e34ee396ccfe604f2a8f7
[Concurrency] Change TypeBase::isSendable() to return false for unavailable conformances.
2 parents 177bbe6 + 8f149b4 commit 6e18ffe

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lib/AST/ConformanceLookup.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -834,16 +834,9 @@ bool TypeBase::isSendableType() {
834834
if (auto *fas = getAs<AnyFunctionType>())
835835
return fas->isSendable();
836836

837-
auto conformance = proto->getParentModule()->checkConformance(this, proto);
838-
if (conformance.isInvalid())
839-
return false;
840-
841-
// Look for missing Sendable conformances.
842-
return !conformance.forEachMissingConformance(
843-
[](BuiltinProtocolConformance *missing) {
844-
return missing->getProtocol()->isSpecificProtocol(
845-
KnownProtocolKind::Sendable);
846-
});
837+
auto conformance = proto->getParentModule()->checkConformance(
838+
this, proto, false /*allow missing*/);
839+
return conformance && !conformance.hasUnavailableConformance();
847840
}
848841

849842
///

test/Concurrency/sendable_checking.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public actor MyActor: MyProto {
9696

9797
func g(ns1: NS1) async {
9898
await nonisolatedAsyncFunc1(ns1) // expected-targeted-and-complete-warning{{passing argument of non-sendable type 'NS1' outside of actor-isolated context may introduce data races}}
99+
// expected-tns-warning @-1 {{transferring 'ns1' may cause a race}}
100+
// expected-tns-note @-2 {{transferring actor-isolated 'ns1' to nonisolated callee could cause races between nonisolated and actor-isolated uses}}
99101
_ = await nonisolatedAsyncFunc2() // expected-warning{{non-sendable type 'NS1' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary}}
100102
}
101103
}
@@ -352,13 +354,12 @@ func testPointersAreNotSendable() {
352354
extension SynthesizedConformances.NotSendable: Sendable {}
353355

354356
enum SynthesizedConformances {
355-
// expected-note@+1 2 {{consider making struct 'NotSendable' conform to the 'Sendable' protocol}}
356357
struct NotSendable: Equatable {}
357358

358-
// expected-warning@+2 2{{non-sendable type 'SynthesizedConformances.NotSendable' in asynchronous access to main actor-isolated property 'x' cannot cross actor boundary}}
359-
// expected-note@+1 2 {{in derived conformance to 'Equatable'}}
359+
// expected-warning@+2 2{{main actor-isolated property 'x' can not be referenced from a non-isolated context}}
360+
// expected-note@+1 2{{in static method '==' for derived conformance to 'Equatable'}}
360361
@MainActor struct Isolated: Equatable {
361-
let x: NotSendable
362+
let x: NotSendable // expected-note 2{{property declared here}}
362363
}
363364
}
364365

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend -emit-sil -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation -disable-availability-checking -verify %s -o /dev/null
2+
3+
// REQUIRES: concurrency
4+
// REQUIRES: asserts
5+
6+
// This test makes sure that we treat types with an unavailable Sendable
7+
// conformance as being non-Sendable.
8+
9+
public class NonSendable {
10+
func foo() {
11+
}
12+
}
13+
14+
@available(*, unavailable)
15+
extension NonSendable: Sendable {}
16+
17+
actor Bar {
18+
init(_ _: NonSendable) {
19+
}
20+
func bar() async {
21+
let ns = NonSendable() // expected-note {{variable defined here}}
22+
_ = Bar(ns) // expected-warning {{transferring 'ns' may cause a race}}
23+
// TODO: This needs to be:
24+
// disconnected 'ns' is transferred to actor-isolated callee. Later local uses could race with uses in callee.
25+
// expected-note @-3 {{'ns' is transferred from actor-isolated caller to actor-isolated callee. Later uses in caller could race with potential uses in callee}}
26+
ns.foo() // expected-note {{access here could race}}
27+
}
28+
}

0 commit comments

Comments
 (0)