Skip to content

[6.2] Infer nonisolated conformances from witnesses #81344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable conformance isolation inference for @preconcurrency conformances
  • Loading branch information
DougGregor committed May 6, 2025
commit a3a17d0405f5ebac43e1d638e705a1c5d4277687
4 changes: 4 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7994,6 +7994,10 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
if (getActorIsolation(rootNormal->getProtocol()).isActorIsolated())
return ActorIsolation::forNonisolated(false);

// @preconcurrency disables isolation inference.
if (rootNormal->isPreconcurrency())
return ActorIsolation::forNonisolated(false);

// Isolation inference rules follow. If we aren't inferring isolated conformances,
// we're done.
if (!ctx.LangOpts.hasFeature(Feature::InferIsolatedConformances))
Expand Down
18 changes: 17 additions & 1 deletion test/Concurrency/isolated_conformance_inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ nonisolated class CNonIsolated: P {
func acceptSendablePMeta<T: Sendable & P>(_: T.Type) { }
func acceptSendableQMeta<T: Sendable & Q>(_: T.Type) { }

nonisolated func testConformancesFromNonisolated() {
// @preconcurrency suppresses actor isolation inference
struct NotSendable: Equatable, Hashable {
}

@available(*, unavailable)
extension NotSendable: Sendable {}

extension NotSendable : Codable {}

@MainActor
struct TestDerivedCodable : @preconcurrency Codable {
var x: NotSendable
}

nonisolated func testConformancesFromNonisolated(tdc: TestDerivedCodable) {
let _: any P = CExplicit() // expected-error{{global actor 'SomeGlobalActor'-isolated conformance of 'CExplicit' to 'P' cannot be used in nonisolated context}}

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

let _: any P = CViaNonisolatedWitness()

let _: any Codable = tdc
}