Skip to content

Commit

Permalink
Soft-deprecate UncheckedSendable on Swift 5.10 (#24)
Browse files Browse the repository at this point in the history
* Soft-deprecate `UncheckedSendable` on Swift 5.10

5.10's `nonisolated(unsafe) let` is a replacement for
`UncheckedSendable`.

* Remove from README
  • Loading branch information
stephencelis authored Jun 18, 2024
1 parent ccb410b commit 18a375c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
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

0 comments on commit 18a375c

Please sign in to comment.