Skip to content

Commit 69758f6

Browse files
committed
[SE-0470] Downgrade some isolated conformance-related errors to warnings in Swift 5
(cherry picked from commit e8b3065)
1 parent 49ebfcb commit 69758f6

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

include/swift/AST/ASTContextGlobalCache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct WitnessIsolationError {
5555
/// Describes an isolation error involving an associated conformance.
5656
struct AssociatedConformanceIsolationError {
5757
ProtocolConformance *isolatedConformance;
58+
DiagnosticBehavior behavior = DiagnosticBehavior::Unspecified;
5859

5960
/// Diagnose this associated conformance isolation error.
6061
void diagnose(const NormalProtocolConformance *conformance) const;

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8009,7 +8009,8 @@ namespace {
80098009
firstConformance->getIsolation(),
80108010
firstConformance->getType(),
80118011
firstConformance->getProtocol()->getName(),
8012-
getContextIsolation());
8012+
getContextIsolation())
8013+
.warnUntilSwiftVersion(6);
80138014
return true;
80148015
}
80158016
};

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4947,6 +4947,9 @@ static void diagnoseConformanceIsolationErrors(
49474947
hasIsolatedConformances = true;
49484948
}
49494949

4950+
// Take the least-restrictive behavior.
4951+
behavior = behavior.merge(assocConformanceError.behavior);
4952+
49504953
anyNonDistributedIssues = true;
49514954
}
49524955

@@ -5405,9 +5408,19 @@ static void ensureRequirementsAreSatisfied(ASTContext &ctx,
54055408
// If the isolation doesn't match, record an error.
54065409
if (!outerIsolation.isGlobalActor() ||
54075410
outerIsolation != innerIsolation) {
5411+
DiagnosticBehavior behavior = DiagnosticBehavior::Unspecified;
5412+
// If we're working with requirements imported from Clang, or with
5413+
// global actor isolation in general, use the default diagnostic
5414+
// behavior based on the conformance context.
5415+
if (proto->hasClangNode() ||
5416+
outerIsolation.isGlobalActor() ||
5417+
innerIsolation.isGlobalActor())
5418+
behavior = SendableCheckContext(dc).defaultDiagnosticBehavior();
5419+
54085420
ctx.getGlobalCache().conformanceIsolationErrors[conformance]
54095421
.push_back(
5410-
AssociatedConformanceIsolationError{isolatedConformance});
5422+
AssociatedConformanceIsolationError{
5423+
isolatedConformance, behavior});
54115424
return true;
54125425
}
54135426

test/Concurrency/isolated_conformance.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 6 -enable-experimental-feature IsolatedConformances %s
1+
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 5 -strict-concurrency=complete -enable-experimental-feature IsolatedConformances %s
22

33
// REQUIRES: swift_feature_IsolatedConformances
44
// REQUIRES: concurrency
@@ -11,7 +11,7 @@ protocol P {
1111
// Definition of isolated conformances
1212
// ----------------------------------------------------------------------------
1313

14-
// expected-error@+4{{conformance of 'CWithNonIsolated' to protocol 'P' crosses into main actor-isolated code and can cause data races}}
14+
// expected-warning@+4{{conformance of 'CWithNonIsolated' to protocol 'P' crosses into main actor-isolated code and can cause data races}}
1515
// expected-note@+3{{mark all declarations used in the conformance 'nonisolated'}}
1616
// expected-note@+2{{isolate this conformance to the main actor with '@MainActor'}}{{25-25=@MainActor }}
1717
@MainActor
@@ -54,7 +54,7 @@ protocol Q {
5454
associatedtype A: P
5555
}
5656

57-
// expected-error@+2{{conformance of 'SMissingIsolation' to protocol 'Q' crosses into main actor-isolated code and can cause data races}}
57+
// expected-warning@+2{{conformance of 'SMissingIsolation' to protocol 'Q' crosses into main actor-isolated code and can cause data races}}
5858
@MainActor
5959
struct SMissingIsolation: Q {
6060
// expected-note@-1{{conformance depends on main actor-isolated conformance of 'C' to protocol 'P'}}
@@ -66,7 +66,7 @@ struct PWrapper<T: P>: P {
6666
func f() { }
6767
}
6868

69-
// expected-error@+2{{conformance of 'SMissingIsolationViaWrapper' to protocol 'Q' crosses into main actor-isolated code and can cause data races}}
69+
// expected-warning@+2{{conformance of 'SMissingIsolationViaWrapper' to protocol 'Q' crosses into main actor-isolated code and can cause data races}}
7070
@MainActor
7171
struct SMissingIsolationViaWrapper: Q {
7272
// expected-note@-1{{conformance depends on main actor-isolated conformance of 'C' to protocol 'P'}}
@@ -84,7 +84,7 @@ struct S: @MainActor Q {
8484
typealias A = C
8585
}
8686

87-
// expected-error@+3{{conformance of 'SMismatchedActors' to protocol 'Q' crosses into global actor 'SomeGlobalActor'-isolated code and can cause data races}}
87+
// expected-warning@+3{{conformance of 'SMismatchedActors' to protocol 'Q' crosses into global actor 'SomeGlobalActor'-isolated code and can cause data races}}
8888
// expected-note@+2{{conformance depends on global actor 'SomeGlobalActor'-isolated conformance of 'C2' to protocol 'P'}}
8989
@MainActor
9090
struct SMismatchedActors: @MainActor Q {
@@ -149,9 +149,9 @@ func testIsolatedConformancesOfOtherGlobalActor(c: CMismatchedIsolation) {
149149
}
150150

151151
func testIsolationConformancesFromOutside(c: C) {
152-
acceptP(c) // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
153-
let _: any P = c // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
154-
let _ = PWrapper<C>() // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
152+
acceptP(c) // expected-warning{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
153+
let _: any P = c // expected-warning{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
154+
let _ = PWrapper<C>() // expected-warning{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
155155
}
156156

157157
protocol HasAssociatedType {

0 commit comments

Comments
 (0)