Skip to content

Commit 23739ef

Browse files
committed
[Concurrency] Converting from @execution(concurrent) to actor-isolated crosses an isolation boundary
1 parent 1a42c15 commit 23739ef

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2804,8 +2804,21 @@ namespace {
28042804
}
28052805
break;
28062806

2807+
case FunctionTypeIsolation::Kind::NonIsolated: {
2808+
// Since @execution(concurrent) as an asynchronous
2809+
// function it would mean that without Sendable
2810+
// check it would be possible for non-Sendable state
2811+
// to escape from actor isolation.
2812+
if (fromFnType->isAsync()) {
2813+
diagnoseNonSendableParametersAndResult(
2814+
toFnType, /*downgradeToWarning=*/true);
2815+
break;
2816+
}
2817+
// Runs on the actor.
2818+
break;
2819+
}
2820+
28072821
// Runs on the actor.
2808-
case FunctionTypeIsolation::Kind::NonIsolated:
28092822
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
28102823
break;
28112824
}

test/Concurrency/attr_execution_conversions.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ func testNonSendableDiagnostics(
123123
// expected-warning@-1 {{cannot convert '@execution(caller) @Sendable () async -> NonSendable' to '() async -> NonSendable' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol}}
124124

125125
let _: @MainActor (NonSendable) async -> Void = nonIsolated1 // Ok
126-
let _: @MainActor (NonSendable) async -> Void = nonIsolated2 // Ok
126+
let _: @MainActor (NonSendable) async -> Void = nonIsolated2 // expected-note {{type 'NonSendable' does not conform to 'Sendable' protocol}}
127+
// expected-warning@-1 {{cannot convert '@Sendable (NonSendable) async -> Void' to '@MainActor (NonSendable) async -> Void' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol}}
127128

128129
let _: @MainActor () async -> NonSendable = nonIsolated3 // Ok
129-
let _: @MainActor () async -> NonSendable = nonIsolated4 // Ok
130+
let _: @MainActor () async -> NonSendable = nonIsolated4 // expected-note {{type 'NonSendable' does not conform to 'Sendable' protocol}}
131+
// expected-warning@-1 {{cannot convert '@Sendable () async -> NonSendable' to '@MainActor () async -> NonSendable' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol}}
130132

131133
let _: @MainActor (NonSendable) async -> Void = caller1 // Ok
132134
let _: @MainActor () async -> NonSendable = caller2 // Ok

0 commit comments

Comments
 (0)