Skip to content

Commit

Permalink
Swift 5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Mar 10, 2024
1 parent 73f0374 commit d2c6607
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 40 deletions.
36 changes: 31 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ on:
workflow_dispatch:

jobs:
xcode_14_3:
runs-on: macos-13
xcode_15_2:
runs-on: macos-14
env:
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -26,10 +26,10 @@ jobs:
with:
files: ./coverage_report.lcov

xcode_14_2:
xcode_14_3_1:
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -65,3 +65,29 @@ jobs:
run: swift build --build-tests
- name: Test
run: swift test --skip-build

linux_swift_5_9:
runs-on: ubuntu-latest
container: swift:5.9
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
- name: Test
run: swift test --skip-build

linux_swift_5_10:
runs-on: ubuntu-latest
container: swift:5.10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
- name: Test
run: swift test --skip-build
18 changes: 15 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8

import PackageDescription

Expand All @@ -16,12 +16,24 @@ let package = Package(
targets: [
.target(
name: "IdentifiableContinuation",
path: "Sources"
path: "Sources",
swiftSettings: .upcomingFeatures
),
.testTarget(
name: "IdentifiableContinuationTests",
dependencies: ["IdentifiableContinuation"],
path: "Tests"
path: "Tests",
swiftSettings: .upcomingFeatures
)
]
)

extension Array where Element == SwiftSetting {

static var upcomingFeatures: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("StrictConcurrency")
]
}
}
27 changes: 27 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.7

import PackageDescription

let package = Package(
name: "IdentifiableContinuation",
platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
],
products: [
.library(
name: "IdentifiableContinuation",
targets: ["IdentifiableContinuation"]
)
],
targets: [
.target(
name: "IdentifiableContinuation",
path: "Sources"
),
.testTarget(
name: "IdentifiableContinuationTests",
dependencies: ["IdentifiableContinuation"],
path: "Tests"
)
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build](https://github.com/swhitty/IdentifiableContinuation/actions/workflows/build.yml/badge.svg)](https://github.com/swhitty/IdentifiableContinuation/actions/workflows/build.yml)
[![Codecov](https://codecov.io/gh/swhitty/IdentifiableContinuation/graphs/badge.svg)](https://codecov.io/gh/swhitty/IdentifiableContinuation)
[![Platforms](https://img.shields.io/badge/platforms-iOS%20|%20Mac%20|%20tvOS%20|%20Linux%20|%20Windows-lightgray.svg)](https://github.com/swhitty/IdentifiableContinuation/blob/main/Package.swift)
[![Swift 5.8](https://img.shields.io/badge/swift-5.7%20–%205.8-red.svg?style=flat)](https://developer.apple.com/swift)
[![Swift 5.10](https://img.shields.io/badge/swift-5.7%20–%205.10-red.svg?style=flat)](https://developer.apple.com/swift)
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT)
[![Twitter](https://img.shields.io/badge/[email protected])](http://twitter.com/simonwhitty)

Expand Down
28 changes: 14 additions & 14 deletions Sources/IdentifiableContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public func withIdentifiableContinuation<T>(
@inlinable
public func withThrowingIdentifiableContinuation<T>(
function: String = #function,
body: (IdentifiableContinuation<T, Error>) -> Void
body: (IdentifiableContinuation<T, any Error>) -> Void
) async throws -> T {
try await withCheckedThrowingContinuation(function: function) {
body(IdentifiableContinuation(storage: .checked($0)))
Expand All @@ -62,7 +62,7 @@ public func withIdentifiableUnsafeContinuation<T>(

@inlinable
public func withThrowingIdentifiableUnsafeContinuation<T>(
body: (IdentifiableContinuation<T, Error>) -> Void
body: (IdentifiableContinuation<T, any Error>) -> Void
) async throws -> T {
try await withUnsafeThrowingContinuation {
body(IdentifiableContinuation(storage: .unsafe($0)))
Expand Down Expand Up @@ -104,10 +104,10 @@ public func withIdentifiableContinuation<T>(
@inlinable
public func withThrowingIdentifiableContinuation<T>(
function: String = #function,
body: (IdentifiableContinuation<T, Error>) -> Void,
onCancel: (IdentifiableContinuation<T, Error>.ID) -> Void
body: (IdentifiableContinuation<T, any Error>) -> Void,
onCancel: (IdentifiableContinuation<T, any Error>.ID) -> Void
) async throws -> T {
let id = IdentifiableContinuation<T, Error>.ID()
let id = IdentifiableContinuation<T, any Error>.ID()
return try await withoutActuallyEscaping(body, onCancel, result: T.self) {
let state = LockedState(body: $0, onCancel: $1)
return try await withTaskCancellationHandler {
Expand All @@ -124,8 +124,8 @@ public func withThrowingIdentifiableContinuation<T>(
@inlinable
public func withThrowingIdentifiableContinuation<T>(
function: String = #function,
body: (IdentifiableContinuation<T, Error>) async -> Void,
onCancel: (IdentifiableContinuation<T, Error>.ID) async -> Void
body: (IdentifiableContinuation<T, any Error>) async -> Void,
onCancel: (IdentifiableContinuation<T, any Error>.ID) async -> Void
) async throws -> T {
try await withoutActuallyEscaping(body, onCancel, result: T.self) {
let state = AsyncLockedState(body: $0, onCancel: $1)
Expand Down Expand Up @@ -165,10 +165,10 @@ public func withIdentifiableUnsafeContinuation<T>(

@inlinable
public func withThrowingIdentifiableUnsafeContinuation<T>(
body: (IdentifiableContinuation<T, Error>) -> Void,
onCancel: (IdentifiableContinuation<T, Error>.ID) -> Void
body: (IdentifiableContinuation<T, any Error>) -> Void,
onCancel: (IdentifiableContinuation<T, any Error>.ID) -> Void
) async throws -> T {
let id = IdentifiableContinuation<T, Error>.ID()
let id = IdentifiableContinuation<T, any Error>.ID()
return try await withoutActuallyEscaping(body, onCancel, result: T.self) {
let state = LockedState(body: $0, onCancel: $1)
return try await withTaskCancellationHandler {
Expand All @@ -184,8 +184,8 @@ public func withThrowingIdentifiableUnsafeContinuation<T>(

@inlinable
public func withThrowingIdentifiableUnsafeContinuation<T>(
body: (IdentifiableContinuation<T, Error>) async -> Void,
onCancel: (IdentifiableContinuation<T, Error>.ID) async -> Void
body: (IdentifiableContinuation<T, any Error>) async -> Void,
onCancel: (IdentifiableContinuation<T, any Error>.ID) async -> Void
) async throws -> T {
try await withoutActuallyEscaping(body, onCancel, result: T.self) {
let state = AsyncLockedState(body: $0, onCancel: $1)
Expand Down Expand Up @@ -352,7 +352,7 @@ final class AsyncLockedState<T, Failure: Error>: @unchecked Sendable {
}

@usableFromInline
func startCheckedThrowingContinuation(function: String) async throws -> T where Failure == Error {
func startCheckedThrowingContinuation(function: String) async throws -> T where Failure == any Error {
let id = IdentifiableContinuation<T, Failure>.ID()
return try await withTaskCancellationHandler {
do {
Expand Down Expand Up @@ -387,7 +387,7 @@ final class AsyncLockedState<T, Failure: Error>: @unchecked Sendable {
}

@usableFromInline
func startUnsafeThrowingContinuation() async throws -> T where Failure == Error {
func startUnsafeThrowingContinuation() async throws -> T where Failure == any Error {
let id = IdentifiableContinuation<T, Failure>.ID()
return try await withTaskCancellationHandler {
do {
Expand Down
16 changes: 8 additions & 8 deletions Tests/IdentifiableContinuationAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ final class IdentifiableContinuationAsyncTests: XCTestCase {
}

func testThrowingCancels_After_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
try await withThrowingIdentifiableContinuation {
await waiter.addContinuation($0)
} onCancel: {
Expand All @@ -116,9 +116,9 @@ final class IdentifiableContinuationAsyncTests: XCTestCase {
}

func testThrowingCancels_Before_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
await Task.sleep(seconds: 0.1)
return try await withThrowingIdentifiableContinuation {
await waiter.addContinuation($0)
Expand Down Expand Up @@ -176,9 +176,9 @@ final class IdentifiableContinuationAsyncTests: XCTestCase {
}

func testUnsafeThrowingCancels_After_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
try await withThrowingIdentifiableUnsafeContinuation {
await waiter.addContinuation($0)
} onCancel: {
Expand All @@ -196,9 +196,9 @@ final class IdentifiableContinuationAsyncTests: XCTestCase {
}

func testUnsafeThrowingCancels_Before_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
await Task.sleep(seconds: 0.1)
return try await withThrowingIdentifiableUnsafeContinuation {
await waiter.addContinuation($0)
Expand Down
18 changes: 9 additions & 9 deletions Tests/IdentifiableContinuationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ final class IdentifiableContinuationTests: XCTestCase {
}

func testThrowingCancels_After_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
try await withThrowingIdentifiableContinuation {
waiter.addContinuation($0)
} onCancel: {
Expand All @@ -118,9 +118,9 @@ final class IdentifiableContinuationTests: XCTestCase {
}

func testThrowingCancels_Before_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
await Task.sleep(seconds: 0.1)
return try await withThrowingIdentifiableContinuation {
waiter.addContinuation($0)
Expand Down Expand Up @@ -201,9 +201,9 @@ final class IdentifiableContinuationTests: XCTestCase {


func testUnsafeThrowingCancels_After_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
try await withThrowingIdentifiableUnsafeContinuation {
waiter.addContinuation($0)
} onCancel: {
Expand All @@ -220,9 +220,9 @@ final class IdentifiableContinuationTests: XCTestCase {
}

func testUnsafeThrowingCancels_Before_Created() async {
let waiter = Waiter<String, Error>()
let waiter = Waiter<String, any Error>()

let task = Task<String?, Error> {
let task = Task<String?, any Error> {
await Task.sleep(seconds: 0.1)
return try await withThrowingIdentifiableUnsafeContinuation {
waiter.addContinuation($0)
Expand All @@ -239,7 +239,7 @@ final class IdentifiableContinuationTests: XCTestCase {
}
}

private final class Waiter<T, E: Error> {
private final class Waiter<T, E: Error>: @unchecked Sendable {
typealias Continuation = IdentifiableContinuation<T, E>

private var waiting = [Continuation.ID: Continuation]()
Expand Down
9 changes: 9 additions & 0 deletions docker-run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -eu

docker run -it \
--rm \
--mount src="$(pwd)",target=/package,type=bind \
swift:5.10-jammy \
/usr/bin/swift test --package-path /package

0 comments on commit d2c6607

Please sign in to comment.