Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft-deprecate UncheckedSendable on Swift 5.10 #24

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Reliably testable Swift concurrency.
* [`ActorIsolated` and `LockIsolated`](#actorisolated-and-lockisolated)
* [Streams](#streams)
* [Tasks](#tasks)
* [`UncheckedSendable`](#uncheckedsendable)
* [Serial execution](#serial-execution)
* [Documentation](#documentation)
* [Other libraries](#other-libraries)
Expand Down Expand Up @@ -141,17 +140,6 @@ The library enhances the `Task` type with new functionality.
enough time to start. Prefer the reliability of [serial execution](#serial-execution) instead
where possible.

### `UncheckedSendable`

A wrapper type that can make any type `Sendable`, but in an unsafe and unchecked way. This type
should only be used as an alternative to `@preconcurrency import`, which turns off concurrency
checks for everything in the library. Whereas `UncheckedSendable` allows you to turn off concurrency
warnings for just one single usage of a particular type.

While [SE-0302][se-0302] mentions future work of ["Adaptor Types for Legacy
Codebases"][se-0302-unsafetransfer], including an `UnsafeTransfer` type that serves the same
purpose, it has not landed in Swift.

### Serial execution

Some asynchronous code is [notoriously difficult][reliably-testing-swift-concurrency] to test in
Expand Down
31 changes: 31 additions & 0 deletions Sources/ConcurrencyExtras/UncheckedSendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
///
/// To synchronously isolate a value with a lock, see ``LockIsolated``. To asynchronously isolated a
/// value on an actor, see ``ActorIsolated``.
#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(tvOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(watchOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
#endif
@dynamicMemberLookup
@propertyWrapper
public struct UncheckedSendable<Value>: @unchecked Sendable {
Expand Down Expand Up @@ -49,9 +55,28 @@ public struct UncheckedSendable<Value>: @unchecked Sendable {
}
}

#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(tvOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(watchOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
#endif
extension UncheckedSendable: Equatable where Value: Equatable {}

#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(tvOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(watchOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
#endif
extension UncheckedSendable: Hashable where Value: Hashable {}

#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(tvOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(watchOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
#endif
extension UncheckedSendable: Decodable where Value: Decodable {
public init(from decoder: Decoder) throws {
do {
Expand All @@ -63,6 +88,12 @@ extension UncheckedSendable: Decodable where Value: Decodable {
}
}

#if swift(>=5.10)
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(tvOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
@available(watchOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")
#endif
extension UncheckedSendable: Encodable where Value: Encodable {
public func encode(to encoder: Encoder) throws {
do {
Expand Down
Loading