Skip to content

Commit a3a17d0

Browse files
committed
Disable conformance isolation inference for @preconcurrency conformances
1 parent 91eda51 commit a3a17d0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7994,6 +7994,10 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
79947994
if (getActorIsolation(rootNormal->getProtocol()).isActorIsolated())
79957995
return ActorIsolation::forNonisolated(false);
79967996

7997+
// @preconcurrency disables isolation inference.
7998+
if (rootNormal->isPreconcurrency())
7999+
return ActorIsolation::forNonisolated(false);
8000+
79978001
// Isolation inference rules follow. If we aren't inferring isolated conformances,
79988002
// we're done.
79998003
if (!ctx.LangOpts.hasFeature(Feature::InferIsolatedConformances))

test/Concurrency/isolated_conformance_inference.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,21 @@ nonisolated class CNonIsolated: P {
4747
func acceptSendablePMeta<T: Sendable & P>(_: T.Type) { }
4848
func acceptSendableQMeta<T: Sendable & Q>(_: T.Type) { }
4949

50-
nonisolated func testConformancesFromNonisolated() {
50+
// @preconcurrency suppresses actor isolation inference
51+
struct NotSendable: Equatable, Hashable {
52+
}
53+
54+
@available(*, unavailable)
55+
extension NotSendable: Sendable {}
56+
57+
extension NotSendable : Codable {}
58+
59+
@MainActor
60+
struct TestDerivedCodable : @preconcurrency Codable {
61+
var x: NotSendable
62+
}
63+
64+
nonisolated func testConformancesFromNonisolated(tdc: TestDerivedCodable) {
5165
let _: any P = CExplicit() // expected-error{{global actor 'SomeGlobalActor'-isolated conformance of 'CExplicit' to 'P' cannot be used in nonisolated context}}
5266

5367
let _: any P = CNonIsolated()
@@ -56,4 +70,6 @@ nonisolated func testConformancesFromNonisolated() {
5670
let _: any Q = CExplicit()
5771

5872
let _: any P = CViaNonisolatedWitness()
73+
74+
let _: any Codable = tdc
5975
}

0 commit comments

Comments
 (0)