Files
swift-mirror/test/Concurrency/transfernonsendable_warning_until_swift6.swift
Michael Gottesman 88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00

65 lines
2.5 KiB
Swift

// RUN: %target-swift-frontend -emit-sil -strict-concurrency=complete -disable-availability-checking -verify %s -o /dev/null -swift-version 6
// REQUIRES: concurrency
// This test makes sure that all of our warnings are errors in swift6 mode.
////////////////////////
// MARK: Declarations //
////////////////////////
class NonSendableType {}
@MainActor func transferToMain<T>(_ t: T) async {}
func useValue<T>(_ t: T) {}
func transferValue<T>(_ t: sending T) {}
/////////////////
// MARK: Tests //
/////////////////
func testIsolationError() async {
let x = NonSendableType()
await transferToMain(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{sending 'x' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
useValue(x) // expected-note {{access can happen concurrently}}
}
func testTransferArgumentError(_ x: NonSendableType) async {
await transferToMain(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{sending task-isolated 'x' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and task-isolated uses}}
}
func testPassArgumentAsTransferringParameter(_ x: NonSendableType) async {
transferValue(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{task-isolated 'x' is passed as a 'sending' parameter; Uses in callee may race with later task-isolated uses}}
}
func testAssignmentIntoTransferringParameter(_ x: sending NonSendableType) async {
let y = NonSendableType()
await transferToMain(x)
x = y
useValue(y)
}
func testAssigningParameterIntoTransferringParameter(_ x: sending NonSendableType, _ y: NonSendableType) async {
x = y
}
func testIsolationCrossingDueToCapture() async {
let x = NonSendableType()
let _ = { @MainActor in
print(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{'x' is captured by a main actor-isolated closure. main actor-isolated uses in closure may race against later nonisolated uses}}
}
useValue(x) // expected-note {{access can happen concurrently}}
}
func testIsolationCrossingDueToCaptureParameter(_ x: NonSendableType) async {
let _ = { @MainActor in
print(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{task-isolated 'x' is captured by a main actor-isolated closure. main actor-isolated uses in closure may race against later nonisolated uses}}
}
useValue(x)
}