mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This includes a bunch of fixes. It is not exhaustive but fit my time boxed time period I set aside to look at this today. A quick non-exhaustive list: 1. I removed unnecessary verify-additional-prefix lines. 2. Split tests with typechecker error and non-typechecker error components. 3. Removed complete- lines that we used when testing w/without send non sednable. 4. Translated complete-and-tns- lines to be just complete- since they are just testing strict-concurrency=complete and we are not testing complete without send non sendable anymore.
101 lines
2.9 KiB
Swift
101 lines
2.9 KiB
Swift
// RUN: %target-swift-frontend -verify -target %target-swift-5.1-abi-triple -strict-concurrency=complete -emit-sil -o /dev/null %s
|
|
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: asserts
|
|
|
|
@globalActor
|
|
actor MyActor {
|
|
static let shared = MyActor()
|
|
@MyActor static var ns: NotSendable?
|
|
@MyActor static func ohNo() { ns!.x += 1 }
|
|
}
|
|
|
|
@globalActor
|
|
actor YourActor {
|
|
static let shared = YourActor()
|
|
@YourActor static var ns: NotSendable?
|
|
@YourActor static func ohNo() { ns!.x += 1 }
|
|
}
|
|
|
|
// expected-complete-note@+1 3{{class 'NotSendable' does not conform to the 'Sendable' protocol}}
|
|
class NotSendable {
|
|
var x: Int = 0
|
|
|
|
@MyActor init() {
|
|
MyActor.ns = self
|
|
}
|
|
|
|
init(x: Int) {
|
|
self.x = x
|
|
}
|
|
|
|
@MyActor func stash() {
|
|
MyActor.ns = self
|
|
}
|
|
}
|
|
|
|
@MyActor func exhibitRace1() async {
|
|
let ns = NotSendable(x: 0)
|
|
MyActor.ns = ns
|
|
|
|
await { @YourActor in
|
|
// expected-warning @+3 {{sending 'ns' risks causing data races}}
|
|
// expected-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
|
|
// expected-complete-warning@+1 {{capture of 'ns' with non-Sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
|
|
YourActor.ns = ns
|
|
}()
|
|
|
|
await withTaskGroup(of: Void.self) {
|
|
$0.addTask {
|
|
await MyActor.ohNo()
|
|
}
|
|
|
|
$0.addTask {
|
|
await YourActor.ohNo()
|
|
}
|
|
}
|
|
}
|
|
|
|
@MyActor func exhibitRace2() async {
|
|
let ns = NotSendable(x: 0)
|
|
ns.stash()
|
|
|
|
await { @YourActor in
|
|
// expected-warning @+3 {{sending 'ns' risks causing data races}}
|
|
// expected-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
|
|
// expected-complete-warning@+1 {{capture of 'ns' with non-Sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
|
|
YourActor.ns = ns
|
|
}()
|
|
|
|
await withTaskGroup(of: Void.self) {
|
|
$0.addTask {
|
|
await MyActor.ohNo()
|
|
}
|
|
|
|
$0.addTask {
|
|
await YourActor.ohNo()
|
|
}
|
|
}
|
|
}
|
|
|
|
@MyActor func exhibitRace3() async {
|
|
let ns = NotSendable()
|
|
|
|
await { @YourActor in
|
|
// expected-warning @+3 {{sending 'ns' risks causing data races}}
|
|
// expected-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
|
|
// expected-complete-warning@+1 {{capture of 'ns' with non-Sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
|
|
YourActor.ns = ns
|
|
}()
|
|
|
|
await withTaskGroup(of: Void.self) {
|
|
$0.addTask {
|
|
await MyActor.ohNo()
|
|
}
|
|
|
|
$0.addTask {
|
|
await YourActor.ohNo()
|
|
}
|
|
}
|
|
}
|