Skip to content

Commit f85eb97

Browse files
committed
ConformanceChecker: Make actor_isolated_witness call out the protocol
1 parent 1573344 commit f85eb97

12 files changed

+43
-40
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5665,9 +5665,10 @@ NOTE(shared_state_make_immutable,none,
56655665
NOTE(shared_state_nonisolated_unsafe,none,
56665666
"disable concurrency-safety checks if accesses are protected by an external synchronization mechanism", (const ValueDecl *))
56675667
ERROR(actor_isolated_witness,none,
5668-
"%select{|distributed }0%1 %kind2 cannot be used to satisfy %3 protocol "
5669-
"requirement",
5670-
(bool, ActorIsolation, const ValueDecl *, ActorIsolation))
5668+
"%select{|distributed }0%1 %kind2 cannot be used to satisfy %3 "
5669+
"requirement from protocol %base4",
5670+
(bool, ActorIsolation, const ValueDecl *, ActorIsolation,
5671+
const ValueDecl *))
56715672
ERROR(actor_cannot_conform_to_global_actor_protocol,none,
56725673
"actor %0 cannot conform to global actor isolated protocol %1",
56735674
(Type, Type))

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,10 +3444,12 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
34443444

34453445
// Complain that this witness cannot conform to the requirement due to
34463446
// actor isolation.
3447-
witness->diagnose(diag::actor_isolated_witness,
3448-
isDistributed && !isDistributedDecl(witness),
3449-
refResult.isolation, witness, requirementIsolation)
3450-
.limitBehaviorUntilSwiftVersion(behavior, 6);
3447+
witness
3448+
->diagnose(diag::actor_isolated_witness,
3449+
isDistributed && !isDistributedDecl(witness),
3450+
refResult.isolation, witness, requirementIsolation,
3451+
Conformance->getProtocol())
3452+
.limitBehaviorUntilSwiftVersion(behavior, 6);
34513453

34523454
// If we need 'distributed' on the witness, add it.
34533455
if (missingOptions.contains(MissingFlags::WitnessDistributed)) {

test/Concurrency/actor_isolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ protocol SGA_Proto {
15101510
// try to override a MA method with inferred isolation from a protocol requirement
15111511
class SGA_MA: MA, SGA_Proto {
15121512
// expected-error@+2 {{call to global actor 'SomeGlobalActor'-isolated global function 'onions_sga()' in a synchronous main actor-isolated context}}
1513-
// expected-warning@+1 {{main actor-isolated instance method 'method()' cannot be used to satisfy global actor 'SomeGlobalActor'-isolated protocol requirement}}
1513+
// expected-warning@+1 {{main actor-isolated instance method 'method()' cannot be used to satisfy global actor 'SomeGlobalActor'-isolated requirement from protocol 'SGA_Proto'}}
15141514
override func method() { onions_sga() }
15151515
// expected-note@-1{{add 'nonisolated' to 'method()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
15161516
}
@@ -1620,7 +1620,7 @@ protocol NonisolatedProtocol {
16201620
actor ActorWithNonSendableLet: NonisolatedProtocol {
16211621
// expected-note@-1{{add '@preconcurrency' to the 'NonisolatedProtocol' conformance to defer isolation checking to run time}}{{32-32=@preconcurrency }}
16221622

1623-
// expected-warning@+1 {{actor-isolated property 'ns' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode}}
1623+
// expected-warning@+1 {{actor-isolated property 'ns' cannot be used to satisfy nonisolated requirement from protocol 'NonisolatedProtocol'; this is an error in the Swift 6 language mode}}
16241624
let ns = NonSendable()
16251625
}
16261626

test/Concurrency/actor_isolation_unsafe.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ struct S3_P1: P1 {
4040

4141
struct S4_P1_not_quietly: P1 {
4242
@SomeGlobalActor func onMainActor() { }
43-
// expected-warning @-1 {{global actor 'SomeGlobalActor'-isolated instance method 'onMainActor()' cannot be used to satisfy main actor-isolated protocol requirement}}
43+
// expected-warning @-1 {{global actor 'SomeGlobalActor'-isolated instance method 'onMainActor()' cannot be used to satisfy main actor-isolated requirement from protocol 'P1'}}
4444
}
4545

4646
@SomeGlobalActor
4747
struct S4_P1: P1 {
48-
@SomeGlobalActor func onMainActor() { } // expected-warning{{global actor 'SomeGlobalActor'-isolated instance method 'onMainActor()' cannot be used to satisfy main actor-isolated protocol requirement}}
48+
@SomeGlobalActor func onMainActor() { } // expected-warning{{global actor 'SomeGlobalActor'-isolated instance method 'onMainActor()' cannot be used to satisfy main actor-isolated requirement from protocol 'P1'}}
4949
}
5050

5151
// expected-warning@+1 {{'(unsafe)' global actors are deprecated; use '@preconcurrency' instead}}

test/Concurrency/global_actor_inference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protocol Interface {
127127
class Object: Interface {
128128
// expected-note@-1{{add '@preconcurrency' to the 'Interface' conformance to defer isolation checking to run time}}{{15-15=@preconcurrency }}
129129

130-
var baz: Int = 42 // expected-warning{{main actor-isolated property 'baz' cannot be used to satisfy nonisolated protocol requirement}}
130+
var baz: Int = 42 // expected-warning{{main actor-isolated property 'baz' cannot be used to satisfy nonisolated requirement from protocol 'Interface'}}
131131
}
132132

133133

test/Concurrency/global_actor_inference_swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct S3: InferenceConflict {
176176

177177
extension S3 {
178178
func f() { }
179-
// expected-error@-1{{global actor 'SomeGlobalActor'-isolated instance method 'f()' cannot be used to satisfy main actor-isolated protocol requirement}}
179+
// expected-error@-1{{global actor 'SomeGlobalActor'-isolated instance method 'f()' cannot be used to satisfy main actor-isolated requirement from protocol 'InferMainActorInherited'}}
180180
//expected-note@-2{{add 'nonisolated' to 'f()' to make this instance method not isolated to the actor}}
181181
}
182182

@@ -208,7 +208,7 @@ class C2: MainActorSuperclass, InferenceConflictWithSuperclass {
208208
func f() {}
209209

210210
func g() {}
211-
// expected-error@-1 {{main actor-isolated instance method 'g()' cannot be used to satisfy nonisolated protocol requirement}}
211+
// expected-error@-1 {{main actor-isolated instance method 'g()' cannot be used to satisfy nonisolated requirement from protocol 'InferenceConflictWithSuperclass'}}
212212
// expected-note@-2 {{add 'nonisolated' to 'g()' to make this instance method not isolated to the actor}}
213213
}
214214

test/Concurrency/preconcurrency_conformances.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ final class K : @preconcurrency Initializable {
107107
@MainActor
108108
final class MainActorK: Initializable {
109109
// expected-note@-1{{add '@preconcurrency' to the 'Initializable' conformance to defer isolation checking to run time}}{{25-25=@preconcurrency }}
110-
init() { } // expected-warning{{main actor-isolated initializer 'init()' cannot be used to satisfy nonisolated protocol requirement}}
110+
init() { } // expected-warning{{main actor-isolated initializer 'init()' cannot be used to satisfy nonisolated requirement from protocol 'Initializable'}}
111111
// expected-note@-1{{add 'nonisolated' to 'init()' to make this initializer not isolated to the actor}}
112112
}
113113

@@ -144,13 +144,13 @@ do {
144144
var a: Int = 42
145145

146146
@MainActor var b: Int {
147-
// expected-warning@-1 {{main actor-isolated property 'b' cannot be used to satisfy global actor 'GlobalActor'-isolated protocol requirement}}
147+
// expected-warning@-1 {{main actor-isolated property 'b' cannot be used to satisfy global actor 'GlobalActor'-isolated requirement from protocol 'WithIndividuallyIsolatedRequirements'}}
148148
get { 0 }
149149
set {}
150150
}
151151

152152
@MainActor func test() {
153-
// expected-warning@-1 {{main actor-isolated instance method 'test()' cannot be used to satisfy global actor 'GlobalActor'-isolated protocol requirement}}
153+
// expected-warning@-1 {{main actor-isolated instance method 'test()' cannot be used to satisfy global actor 'GlobalActor'-isolated requirement from protocol 'WithIndividuallyIsolatedRequirements'}}
154154
}
155155
}
156156
}
@@ -168,10 +168,10 @@ do {
168168
// expected-warning@-1 {{@preconcurrency attribute on conformance to 'WithNonIsolated' has no effect}}{{38-54=}}
169169

170170
@GlobalActor var prop: Int = 42
171-
// expected-warning@-1 {{global actor 'GlobalActor'-isolated property 'prop' cannot be used to satisfy main actor-isolated protocol requirement}}
171+
// expected-warning@-1 {{global actor 'GlobalActor'-isolated property 'prop' cannot be used to satisfy main actor-isolated requirement from protocol 'WithNonIsolated'}}
172172

173173
@MainActor func test() {}
174-
// expected-warning@-1 {{main actor-isolated instance method 'test()' cannot be used to satisfy nonisolated protocol requirement}}
174+
// expected-warning@-1 {{main actor-isolated instance method 'test()' cannot be used to satisfy nonisolated requirement from protocol 'WithNonIsolated'}}
175175
}
176176
}
177177

test/Concurrency/predates_concurrency.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension MainActorPreconcurrency: NotIsolated {
235235
// expected-complete-tns-note@-2{{add '@preconcurrency' to the 'NotIsolated' conformance to defer isolation checking to run time}}{{36-36=@preconcurrency }}
236236

237237
func requirement() {}
238-
// expected-complete-tns-warning@-1 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated protocol requirement}}
238+
// expected-complete-tns-warning@-1 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated requirement from protocol 'NotIsolated'}}
239239
// expected-complete-tns-note@-2 {{add 'nonisolated' to 'requirement()' to make this instance method not isolated to the actor}}
240240
// expected-complete-tns-note@-3 {{calls to instance method 'requirement()' from outside of its actor context are implicitly asynchronous}}
241241

test/Distributed/distributed_protocol_isolation.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,22 @@ distributed actor Nope1_StrictlyLocal: StrictlyLocal {
109109
// expected-note@-1{{add '@preconcurrency' to the 'StrictlyLocal' conformance to defer isolation checking to run time}}
110110

111111
func local() {}
112-
// expected-error@-1{{distributed actor-isolated instance method 'local()' cannot be used to satisfy nonisolated protocol requirement}}
112+
// expected-error@-1{{distributed actor-isolated instance method 'local()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
113113
// expected-note@-2{{add 'nonisolated' to 'local()' to make this instance method not isolated to the actor}}
114114
func localThrows() throws {}
115-
// expected-error@-1{{distributed actor-isolated instance method 'localThrows()' cannot be used to satisfy nonisolated protocol requirement}}
115+
// expected-error@-1{{distributed actor-isolated instance method 'localThrows()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
116116
// expected-note@-2{{add 'nonisolated' to 'localThrows()' to make this instance method not isolated to the actor}}
117117
func localAsync() async {}
118-
// expected-error@-1{{distributed actor-isolated instance method 'localAsync()' cannot be used to satisfy nonisolated protocol requirement}}
118+
// expected-error@-1{{distributed actor-isolated instance method 'localAsync()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
119119
// expected-note@-2{{add 'nonisolated' to 'localAsync()' to make this instance method not isolated to the actor}}
120120
}
121121
distributed actor Nope2_StrictlyLocal: StrictlyLocal {
122122
distributed func local() {}
123-
// expected-error@-1{{actor-isolated distributed instance method 'local()' cannot be used to satisfy nonisolated protocol requirement}}
123+
// expected-error@-1{{actor-isolated distributed instance method 'local()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
124124
distributed func localThrows() throws {}
125-
// expected-error@-1{{actor-isolated distributed instance method 'localThrows()' cannot be used to satisfy nonisolated protocol requirement}}
125+
// expected-error@-1{{actor-isolated distributed instance method 'localThrows()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
126126
distributed func localAsync() async {}
127-
// expected-error@-1{{actor-isolated distributed instance method 'localAsync()' cannot be used to satisfy nonisolated protocol requirement}}
127+
// expected-error@-1{{actor-isolated distributed instance method 'localAsync()' cannot be used to satisfy nonisolated requirement from protocol 'StrictlyLocal'}}
128128
}
129129
distributed actor OK_StrictlyLocal: StrictlyLocal {
130130
nonisolated func local() {}
@@ -162,7 +162,7 @@ distributed actor Nope1_AsyncThrowsAll: AsyncThrowsAll {
162162
// expected-note@-1{{add '@preconcurrency' to the 'AsyncThrowsAll' conformance to defer isolation checking to run time}}
163163

164164
func maybe(param: String, int: Int) async throws -> Int { 111 }
165-
// expected-error@-1{{distributed actor-isolated instance method 'maybe(param:int:)' cannot be used to satisfy nonisolated protocol requirement}}
165+
// expected-error@-1{{distributed actor-isolated instance method 'maybe(param:int:)' cannot be used to satisfy nonisolated requirement from protocol 'AsyncThrowsAll'}}
166166
// expected-note@-2{{add 'nonisolated' to 'maybe(param:int:)' to make this instance method not isolated to the actor}}
167167
// expected-note@-3{{add 'distributed' to 'maybe(param:int:)' to make this instance method satisfy the protocol requirement}}
168168
}
@@ -209,7 +209,7 @@ distributed actor DA_TerminationWatchingA: TerminationWatchingA {
209209
// expected-note@-1{{add '@preconcurrency' to the 'TerminationWatchingA' conformance to defer isolation checking to run time}}
210210

211211
func terminated(a: String) { }
212-
// expected-error@-1{{distributed actor-isolated instance method 'terminated(a:)' cannot be used to satisfy nonisolated protocol requirement}}
212+
// expected-error@-1{{distributed actor-isolated instance method 'terminated(a:)' cannot be used to satisfy nonisolated requirement from protocol 'TerminationWatchingA'}}
213213
// expected-note@-2{{add 'nonisolated' to 'terminated(a:)' to make this instance method not isolated to the actor}}
214214
}
215215

test/decl/class/actor/conformance.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,33 @@ actor OtherActor: SyncProtocol {
3939
// expected-note@-1{{add '@preconcurrency' to the 'SyncProtocol' conformance to defer isolation checking to run time}}{{19-19=@preconcurrency }}
4040

4141
var propertyB: Int = 17
42-
// expected-error@-1{{actor-isolated property 'propertyB' cannot be used to satisfy nonisolated protocol requirement}}
42+
// expected-error@-1{{actor-isolated property 'propertyB' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
4343

4444
var propertyA: Int { 17 }
45-
// expected-error@-1{{actor-isolated property 'propertyA' cannot be used to satisfy nonisolated protocol requirement}}
45+
// expected-error@-1{{actor-isolated property 'propertyA' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
4646

4747
func syncMethodA() { }
48-
// expected-error@-1{{actor-isolated instance method 'syncMethodA()' cannot be used to satisfy nonisolated protocol requirement}}
48+
// expected-error@-1{{actor-isolated instance method 'syncMethodA()' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
4949
// expected-note@-2{{add 'nonisolated' to 'syncMethodA()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
5050

5151
// nonisolated methods are okay.
5252
// FIXME: Consider suggesting nonisolated if this didn't match.
5353
nonisolated func syncMethodC() -> Int { 5 }
5454

5555
func syncMethodE() -> Void { }
56-
// expected-error@-1{{actor-isolated instance method 'syncMethodE()' cannot be used to satisfy nonisolated protocol requirement}}
56+
// expected-error@-1{{actor-isolated instance method 'syncMethodE()' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
5757
// expected-note@-2{{add 'nonisolated' to 'syncMethodE()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
5858

5959
func syncMethodF(param: String) -> Int { 5 }
60-
// expected-error@-1{{actor-isolated instance method 'syncMethodF(param:)' cannot be used to satisfy nonisolated protocol requirement}}
60+
// expected-error@-1{{actor-isolated instance method 'syncMethodF(param:)' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
6161
// expected-note@-2{{add 'nonisolated' to 'syncMethodF(param:)' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
6262

6363
func syncMethodG() { }
64-
// expected-error@-1{{actor-isolated instance method 'syncMethodG()' cannot be used to satisfy nonisolated protocol requirement}}
64+
// expected-error@-1{{actor-isolated instance method 'syncMethodG()' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
6565
// expected-note@-2{{add 'nonisolated' to 'syncMethodG()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
6666

6767
subscript (index: Int) -> String { "\(index)" }
68-
// expected-error@-1{{actor-isolated subscript 'subscript(_:)' cannot be used to satisfy nonisolated protocol requirement}}
68+
// expected-error@-1{{actor-isolated subscript 'subscript(_:)' cannot be used to satisfy nonisolated requirement from protocol 'SyncProtocol'}}
6969
// expected-note@-2{{add 'nonisolated' to 'subscript(_:)' to make this subscript not isolated to the actor}}{{3-3=nonisolated }}
7070

7171
// Static methods and properties are okay.

test/decl/class/actor/global_actor_conformance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class C1 : P1, P2 {
3636

3737
func method1() { }
3838

39-
@GenericGlobalActor<String> func method2() { } // expected-warning{{global actor 'GenericGlobalActor<String>'-isolated instance method 'method2()' cannot be used to satisfy global actor 'GenericGlobalActor<Int>'-isolated protocol requirement}}
39+
@GenericGlobalActor<String> func method2() { } // expected-warning{{global actor 'GenericGlobalActor<String>'-isolated instance method 'method2()' cannot be used to satisfy global actor 'GenericGlobalActor<Int>'-isolated requirement from protocol 'P1'}}
4040
@GenericGlobalActor<String >func method3() { }
41-
@GlobalActor func method4() { } // expected-warning{{global actor 'GlobalActor'-isolated instance method 'method4()' cannot be used to satisfy nonisolated protocol requirement}}
41+
@GlobalActor func method4() { } // expected-warning{{global actor 'GlobalActor'-isolated instance method 'method4()' cannot be used to satisfy nonisolated requirement from protocol 'P1'}}
4242

4343
// Okay: we can ignore the mismatch in global actor types for 'async' methods.
4444
func asyncMethod1() async { }
@@ -56,7 +56,7 @@ protocol NonIsolatedRequirement {
5656
extension OnMain: NonIsolatedRequirement {
5757
// expected-note@-1{{add '@preconcurrency' to the 'NonIsolatedRequirement' conformance to defer isolation checking to run time}}
5858

59-
// expected-warning@+2 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated protocol requirement}}
59+
// expected-warning@+2 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated requirement from protocol 'NonIsolatedRequirement'}}
6060
// expected-note@+1 {{add 'nonisolated' to 'requirement()' to make this instance method not isolated to the actor}}
6161
func requirement() {}
6262
}

test/decl/protocol/special/DistributedActor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protocol P1: DistributedActor {
6060

6161
distributed actor D5: P1 {
6262
func dist() -> String { "" }
63-
// expected-error@-1{{distributed actor-isolated instance method 'dist()' cannot be used to satisfy actor-isolated protocol requirement}}
63+
// expected-error@-1{{distributed actor-isolated instance method 'dist()' cannot be used to satisfy actor-isolated requirement from protocol 'P1'}}
6464
// expected-note@-2{{add 'distributed' to 'dist()' to make this instance method satisfy the protocol requirement}}{{3-3=distributed }}
6565
}
6666

@@ -84,6 +84,6 @@ protocol P {
8484
distributed actor A: P {
8585
typealias ActorSystem = LocalTestingDistributedActorSystem
8686
distributed func foo() { }
87-
// expected-error@-1{{actor-isolated distributed instance method 'foo()' cannot be used to satisfy nonisolated protocol requirement}}
87+
// expected-error@-1{{actor-isolated distributed instance method 'foo()' cannot be used to satisfy nonisolated requirement from protocol 'P'}}
8888
}
8989
// ---

0 commit comments

Comments
 (0)