Skip to content

Commit d822288

Browse files
authored
add any to protocol (#223)
* add any to protocol * add .enableUpcomingFeature("ExistentialAny") to Package.swift * Fixup CI
1 parent f4ac198 commit d822288

File tree

7 files changed

+33
-46
lines changed

7 files changed

+33
-46
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
push: { branches: [ main ] }
88
env:
99
LOG_LEVEL: info
10-
SWIFT_DETERMINISTIC_HASHING: 1
1110
REDIS_HOSTNAME: redis
1211
REDIS_PORT: 6379
1312
REDIS_HOSTNAME_2: redis-2
@@ -17,47 +16,27 @@ jobs:
1716
api-breakage:
1817
if: ${{ !(github.event.pull_request.draft || false) }}
1918
runs-on: ubuntu-latest
20-
container: swift:jammy
19+
container: swift
2120
steps:
2221
- name: Check out code
23-
uses: actions/checkout@v4
22+
uses: actions/checkout@v5
2423
with: { 'fetch-depth': 0 }
2524
- name: Run API breakage check
2625
run: |
2726
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
2827
swift package diagnose-api-breaking-changes origin/main
2928
30-
# gh-codeql:
31-
# if: ${{ !(github.event.pull_request.draft || false) }}
32-
# runs-on: ubuntu-latest
33-
# permissions: { actions: write, contents: read, security-events: write }
34-
# timeout-minutes: 30
35-
# steps:
36-
# - name: Install latest Swift toolchain
37-
# uses: vapor/[email protected]
38-
# with: { toolchain: latest }
39-
# - name: Check out code
40-
# uses: actions/checkout@v4
41-
# - name: Fix Git configuration
42-
# run: 'git config --global --add safe.directory "${GITHUB_WORKSPACE}"'
43-
# - name: Initialize CodeQL
44-
# uses: github/codeql-action/init@v3
45-
# with: { languages: swift }
46-
# - name: Perform build
47-
# run: swift build
48-
# - name: Run CodeQL analyze
49-
# uses: github/codeql-action/analyze@v3
50-
5129
linux-unit:
5230
if: ${{ !(github.event.pull_request.draft || false) }}
5331
strategy:
5432
fail-fast: false
5533
matrix:
5634
container:
5735
- swift:5.10-jammy
58-
- swift:6.0-jammy
59-
- swift:6.1-jammy
60-
- swiftlang/swift:nightly-main-jammy
36+
- swift:6.0-noble
37+
- swift:6.1-noble
38+
- swiftlang/swift:nightly-6.2-noble
39+
- swiftlang/swift:nightly-main-noble
6140
redis:
6241
- redis:6
6342
- redis:7
@@ -69,8 +48,10 @@ jobs:
6948
redis-2:
7049
image: ${{ matrix.redis }}
7150
steps:
51+
- name: Install curl
52+
run: apt-get update -yq && apt-get install -y curl
7253
- name: Check out package
73-
uses: actions/checkout@v4
54+
uses: actions/checkout@v5
7455
- name: Run unit tests with Thread Sanitizer and coverage
7556
run: swift test --sanitize=thread --enable-code-coverage
7657
- name: Upload coverage data

Package.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ let package = Package(
2323
.product(name: "RediStack", package: "RediStack"),
2424
.product(name: "Vapor", package: "vapor"),
2525
],
26-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
26+
swiftSettings: [
27+
.enableExperimentalFeature("StrictConcurrency=complete"),
28+
.enableUpcomingFeature("ExistentialAny"),
29+
]
2730
),
2831
.testTarget(
2932
name: "RedisTests",
3033
dependencies: [
3134
.target(name: "Redis"),
3235
.product(name: "XCTVapor", package: "vapor"),
3336
],
34-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
35-
)
37+
swiftSettings: [
38+
.enableExperimentalFeature("StrictConcurrency=complete"),
39+
.enableUpcomingFeature("ExistentialAny"),
40+
]
41+
),
3642
]
3743
)

Sources/Redis/Application+Redis.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ extension Application {
1616
}
1717

1818
@usableFromInline
19-
internal func pool(for eventLoop: EventLoop) -> RedisConnectionPool {
19+
internal func pool(for eventLoop: any EventLoop) -> RedisConnectionPool {
2020
self.application.redisStorage.pool(for: eventLoop, id: self.id)
2121
}
2222
}
2323
}
2424

2525
// MARK: RedisClient
2626
extension Application.Redis: RedisClient {
27-
public var eventLoop: EventLoop {
27+
public var eventLoop: any EventLoop {
2828
self.application.eventLoopGroup.next()
2929
}
3030

31-
public func logging(to logger: Logger) -> RedisClient {
31+
public func logging(to logger: Logger) -> any RedisClient {
3232
self.application.redis(self.id)
3333
.pool(for: self.eventLoop)
3434
.logging(to: logger)
@@ -87,7 +87,7 @@ extension Application.Redis {
8787
/// See `RedisConnectionPool.leaseConnection(_:)` for more details.
8888
@inlinable
8989
public func withBorrowedConnection<Result>(
90-
_ operation: @escaping (RedisClient) -> EventLoopFuture<Result>
90+
_ operation: @escaping (any RedisClient) -> EventLoopFuture<Result>
9191
) -> EventLoopFuture<Result> {
9292
return self.application.redis(self.id)
9393
.pool(for: self.eventLoop)

Sources/Redis/Application.Redis+PubSub.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import Vapor
33

44
extension Application.Redis {
55
private struct PubSubKey: StorageKey, LockKey {
6-
typealias Value = [RedisID: RedisClient & Sendable]
6+
typealias Value = [RedisID: any RedisClient & Sendable]
77
}
88

9-
var pubsubClient: RedisClient {
9+
var pubsubClient: any RedisClient {
1010
if let existing = self.application.storage[PubSubKey.self]?[self.id] {
1111
return existing
1212
} else {

Sources/Redis/Redis+Cache.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ extension PropertyListDecoder: RedisCacheDecoder { public typealias Input = Data
2929

3030
extension Application.Caches {
3131
/// A cache configured for the default Redis ID and the default coders.
32-
public var redis: Cache {
32+
public var redis: any Cache {
3333
self.redis(.default)
3434
}
3535

3636
/// A cache configured for a given Redis ID and the default coders.
37-
public func redis(_ id: RedisID, jsonEncoder: JSONEncoder = JSONEncoder(), jsonDecoder: JSONDecoder = JSONDecoder()) -> Cache {
37+
public func redis(_ id: RedisID, jsonEncoder: JSONEncoder = JSONEncoder(), jsonDecoder: JSONDecoder = JSONDecoder()) -> any Cache {
3838
self.redis(id, encoder: jsonEncoder, decoder: jsonDecoder)
3939
}
4040

4141
/// A cache configured for a given Redis ID and using the provided encoder and decoder.
42-
public func redis<E: RedisCacheEncoder, D: RedisCacheDecoder>(_ id: RedisID = .default, encoder: E, decoder: D) -> Cache {
42+
public func redis<E: RedisCacheEncoder, D: RedisCacheDecoder>(_ id: RedisID = .default, encoder: E, decoder: D) -> any Cache {
4343
RedisCache(encoder: FakeSendable(value: encoder), decoder: FakeSendable(value: decoder), client: self.application.redis(id))
4444
}
4545

4646
/// A cache configured for a given Redis ID and using the provided encoder and decoder wrapped as FakeSendable.
47-
func redis(_ id: RedisID = .default, encoder: FakeSendable<some RedisCacheEncoder>, decoder: FakeSendable<some RedisCacheDecoder>) -> Cache {
47+
func redis(_ id: RedisID = .default, encoder: FakeSendable<some RedisCacheEncoder>, decoder: FakeSendable<some RedisCacheDecoder>) -> any Cache {
4848
RedisCache(encoder: encoder, decoder: decoder, client: self.application.redis(id))
4949
}
5050
}
@@ -79,7 +79,7 @@ struct FakeSendable<T>: @unchecked Sendable { let value: T }
7979
private struct RedisCache<CacheEncoder: RedisCacheEncoder, CacheDecoder: RedisCacheDecoder>: Cache, Sendable {
8080
let encoder: FakeSendable<CacheEncoder>
8181
let decoder: FakeSendable<CacheDecoder>
82-
let client: RedisClient
82+
let client: any RedisClient
8383

8484
func get<T: Decodable>(_ key: String, as type: T.Type) -> EventLoopFuture<T?> {
8585
self.client.get(RedisKey(key), as: CacheDecoder.Input.self).optionalFlatMapThrowing { try self.decoder.value.decode(T.self, from: $0) }

Sources/Redis/RedisStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ final class RedisStorage: Sendable {
5050
Set(self.box.withLockedValue { $0.configurations.keys })
5151
}
5252

53-
func pool(for eventLoop: EventLoop, id redisID: RedisID) -> RedisConnectionPool {
53+
func pool(for eventLoop: any EventLoop, id redisID: RedisID) -> RedisConnectionPool {
5454
let key = PoolKey(eventLoopKey: eventLoop.key, redisID: redisID)
5555
guard let pool = self.box.withLockedValue({ $0.pools[key] }) else {
5656
fatalError("No redis found for id \(redisID), or the app may not have finished booting. Also, the eventLoop must be from Application's EventLoopGroup.")

Sources/Redis/Request+Redis.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ extension Request {
1919

2020
// MARK: RedisClient
2121
extension Request.Redis: RedisClient {
22-
public var eventLoop: EventLoop {
22+
public var eventLoop: any EventLoop {
2323
self.request.eventLoop
2424
}
2525

26-
public func logging(to logger: Logger) -> RedisClient {
26+
public func logging(to logger: Logger) -> any RedisClient {
2727
self.request.application.redis(self.id)
2828
.pool(for: self.eventLoop)
2929
.logging(to: logger)
@@ -82,7 +82,7 @@ extension Request.Redis {
8282
/// See `RedisConnectionPool.leaseConnection(_:)` for more details.
8383
@inlinable
8484
public func withBorrowedClient<Result>(
85-
_ operation: @escaping (RedisClient) -> EventLoopFuture<Result>
85+
_ operation: @escaping (any RedisClient) -> EventLoopFuture<Result>
8686
) -> EventLoopFuture<Result> {
8787
return self.request.application.redis(self.id)
8888
.pool(for: self.eventLoop)

0 commit comments

Comments
 (0)