Skip to content

Commit e8b3065

Browse files
committed
[SE-0470] Downgrade some isolated conformance-related errors to warnings in Swift 5
1 parent 92774e0 commit e8b3065

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
@@ -7995,7 +7995,8 @@ namespace {
79957995
firstConformance->getIsolation(),
79967996
firstConformance->getType(),
79977997
firstConformance->getProtocol()->getName(),
7998-
getContextIsolation());
7998+
getContextIsolation())
7999+
.warnUntilSwiftVersion(6);
79998000
return true;
80008001
}
80018002
};

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4963,6 +4963,9 @@ static void diagnoseConformanceIsolationErrors(
49634963
hasIsolatedConformances = true;
49644964
}
49654965

4966+
// Take the least-restrictive behavior.
4967+
behavior = behavior.merge(assocConformanceError.behavior);
4968+
49664969
anyNonDistributedIssues = true;
49674970
}
49684971

@@ -5419,9 +5422,19 @@ static void ensureRequirementsAreSatisfied(ASTContext &ctx,
54195422
// If the isolation doesn't match, record an error.
54205423
if (!outerIsolation.isGlobalActor() ||
54215424
outerIsolation != innerIsolation) {
5425+
DiagnosticBehavior behavior = DiagnosticBehavior::Unspecified;
5426+
// If we're working with requirements imported from Clang, or with
5427+
// global actor isolation in general, use the default diagnostic
5428+
// behavior based on the conformance context.
5429+
if (proto->hasClangNode() ||
5430+
outerIsolation.isGlobalActor() ||
5431+
innerIsolation.isGlobalActor())
5432+
behavior = SendableCheckContext(dc).defaultDiagnosticBehavior();
5433+
54225434
ctx.getGlobalCache().conformanceIsolationErrors[conformance]
54235435
.push_back(
5424-
AssociatedConformanceIsolationError{isolatedConformance});
5436+
AssociatedConformanceIsolationError{
5437+
isolatedConformance, behavior});
54255438
return true;
54265439
}
54275440

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)