Skip to content

Commit d24aa09

Browse files
committed
Disable conformance isolation inference for @preconcurrency conformances
1 parent e4e141f commit d24aa09

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7958,6 +7958,10 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
79587958
if (getActorIsolation(rootNormal->getProtocol()).isActorIsolated())
79597959
return ActorIsolation::forNonisolated(false);
79607960

7961+
// @preconcurrency disables isolation inference.
7962+
if (rootNormal->isPreconcurrency())
7963+
return ActorIsolation::forNonisolated(false);
7964+
79617965
// Isolation inference rules follow. If we aren't inferring isolated conformances,
79627966
// we're done.
79637967
if (!ctx.LangOpts.hasFeature(Feature::InferIsolatedConformances))

test/Concurrency/isolated_conformance_inference.swift

+17-1
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)