Skip to content

Commit a69c0ea

Browse files
gwynne0xTim
andauthored
Update minimum Swift version to 6.0 (vapor#3365)
* Update package minimum Swift version to 6.0. Update source code accordingly, and add theming to API docs. * Brutally hack around SymmetricKey not being Sendable in SwiftCrypto * Update dependabot.yml * Sendable stinks. * There, that should do it * Update ServerTests.swift * Update URITests.swift --------- Co-authored-by: Tim Condon <[email protected]>
1 parent 1757359 commit a69c0ea

40 files changed

+239
-201
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: 2
2-
enable-beta-ecosystems: true
32
updates:
43
- package-ecosystem: "github-actions"
54
directory: "/"
@@ -11,14 +10,3 @@ updates:
1110
dependencies:
1211
patterns:
1312
- "*"
14-
- package-ecosystem: "swift"
15-
directory: "/"
16-
schedule:
17-
interval: "daily"
18-
open-pull-requests-limit: 6
19-
allow:
20-
- dependency-type: all
21-
groups:
22-
all-dependencies:
23-
patterns:
24-
- "*"

Package.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22
import PackageDescription
3-
import Foundation
43

54
let package = Package(
65
name: "vapor",
@@ -102,7 +101,7 @@ let package = Package(
102101
.product(name: "_NIOFileSystem", package: "swift-nio"),
103102
.product(name: "_NIOFileSystemFoundationCompat", package: "swift-nio"),
104103
],
105-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
104+
swiftSettings: swiftSettings
106105
),
107106

108107
// Development
@@ -112,7 +111,7 @@ let package = Package(
112111
.target(name: "Vapor"),
113112
],
114113
resources: [.copy("Resources")],
115-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
114+
swiftSettings: swiftSettings
116115
),
117116

118117
// Testing
@@ -121,23 +120,23 @@ let package = Package(
121120
dependencies: [
122121
.target(name: "Vapor"),
123122
],
124-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
123+
swiftSettings: swiftSettings
125124
),
126125
.target(
127126
name: "VaporTesting",
128127
dependencies: [
129128
.target(name: "VaporTestUtils"),
130129
.target(name: "Vapor"),
131130
],
132-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
131+
swiftSettings: swiftSettings
133132
),
134133
.target(
135134
name: "XCTVapor",
136135
dependencies: [
137136
.target(name: "VaporTestUtils"),
138137
.target(name: "Vapor"),
139138
],
140-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
139+
swiftSettings: swiftSettings
141140
),
142141
.testTarget(
143142
name: "VaporTests",
@@ -158,10 +157,16 @@ let package = Package(
158157
.copy("Utilities/expired.key"),
159158
.copy("Utilities/long-test-file.txt"),
160159
],
161-
swiftSettings: [
162-
.enableUpcomingFeature("BareSlashRegexLiterals"),
163-
.enableExperimentalFeature("StrictConcurrency=complete"),
164-
]
160+
swiftSettings: swiftSettings
165161
),
166162
]
167163
)
164+
165+
var swiftSettings: [SwiftSetting] { [
166+
//.enableUpcomingFeature("ExistentialAny"),
167+
//.enableUpcomingFeature("InternalImportsByDefault"),
168+
.enableUpcomingFeature("MemberImportVisibility"),
169+
.enableUpcomingFeature("InferIsolatedConformances"),
170+
//.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
171+
.enableUpcomingFeature("ImmutableWeakCaptures"),
172+
] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<img src="https://img.shields.io/codecov/c/github/vapor/vapor?style=plastic&logo=codecov&label=codecov" alt="Code Coverage">
2222
</a>
2323
<a href="https://swift.org">
24-
<img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+">
24+
<img src="https://design.vapor.codes/images/swift60up.svg" alt="Swift 6.0+">
2525
</a>
2626
<a href="https://hachyderm.io/@codevapor">
2727
<img src="https://img.shields.io/badge/%[email protected]?style=plastic&logo=mastodon&labelColor=gray&logoColor=%239394ff" alt="Mastodon">

Sources/Vapor/Content/JSONCoders+Content.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import Foundation
22
import NIOCore
3+
import NIOFoundationCompat
34
import NIOHTTP1
45

5-
#if swift(<6.0)
6-
extension Foundation.JSONEncoder: @unchecked Swift.Sendable {}
7-
extension Foundation.JSONDecoder: @unchecked Swift.Sendable {}
6+
#if canImport(Darwin)
7+
extension JSONEncoder: @retroactive @unchecked Sendable {} // JSONEncoder Sendable conformance is not available before macOS 13.0/iOS 16.0/watchOS 9.0/tvOS 16.0
8+
extension JSONDecoder: @retroactive @unchecked Sendable {} // JSONDecoder Sendable conformance is not available before macOS 13.0/iOS 16.0/watchOS 9.0/tvOS 16.0
89
#endif
910

1011
extension JSONEncoder: ContentEncoder {
@@ -18,16 +19,17 @@ extension JSONEncoder: ContentEncoder {
1819
where E: Encodable
1920
{
2021
headers.contentType = .json
21-
22+
2223
if !userInfo.isEmpty { // Changing a coder's userInfo is a thread-unsafe mutation, operate on a copy
23-
try body.writeBytes(JSONEncoder.custom(
24+
let encoder = JSONEncoder.custom(
2425
dates: self.dateEncodingStrategy,
2526
data: self.dataEncodingStrategy,
2627
keys: self.keyEncodingStrategy,
2728
format: self.outputFormatting,
28-
floats: self.nonConformingFloatEncodingStrategy,
29-
userInfo: self.userInfo.merging(userInfo) { $1 }
30-
).encode(encodable))
29+
floats: self.nonConformingFloatEncodingStrategy
30+
) // don't use userInfo parameter of `JSONEncoder.custom()` until Swift 6.2 is required
31+
encoder.userInfo = self.userInfo.merging(userInfo) { $1 }
32+
try body.writeBytes(encoder.encode(encodable))
3133
} else {
3234
try body.writeBytes(self.encode(encodable))
3335
}

Sources/Vapor/Content/PlaintextEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private final class _PlaintextEncoder: Encoder, SingleValueEncodingContainer {
7373
func encode<T>(_ value: T) throws where T: Encodable {
7474
if let data = value as? Data {
7575
// special case for data
76-
let utf8Maybe = data.withUnsafeBytes({ $0.withMemoryRebound(to: CChar.self, { String(validatingUTF8: $0.baseAddress!) }) })
76+
let utf8Maybe = data.withUnsafeBytes({ $0.withMemoryRebound(to: CChar.self, { String(validatingCString: $0.baseAddress!) }) })
7777
if let utf8 = utf8Maybe {
7878
self.plaintext = utf8
7979
} else {
Lines changed: 26 additions & 0 deletions
Loading

Sources/Vapor/HTTP/HTTPStatus.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ extension HTTPStatus: ResponseEncodable {
1212
}
1313
}
1414

15-
#if compiler(>=6.1)
1615
extension HTTPStatus: @retroactive Decodable {}
1716
extension HTTPStatus: @retroactive Encodable {}
18-
#else
19-
extension HTTPStatus: Codable {}
20-
#endif
2117

2218
extension HTTPStatus {
2319
public init(from decoder: Decoder) throws {

Sources/Vapor/HTTP/Headers/HTTPHeaderCacheControl.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,4 @@ extension HTTPHeaders {
211211
}
212212
}
213213

214-
#if !$InferSendableFromCaptures
215-
extension Swift.WritableKeyPath: @unchecked Swift.Sendable {}
216-
#endif
214+
extension WritableKeyPath: @retroactive @unchecked Sendable {}

Sources/Vapor/HTTP/Headers/HTTPHeaders.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ extension HTTPHeaders {
3434
}
3535
}
3636

37-
#if compiler(>=6.1)
3837
extension HTTPHeaders: @retroactive Decodable {}
3938
extension HTTPHeaders: @retroactive Encodable {}
40-
#else
41-
extension HTTPHeaders: Codable {}
42-
#endif
4339

4440
extension HTTPHeaders {
4541
private enum CodingKeys: String, CodingKey { case name, value }

Sources/Vapor/Logging/LoggingSystem+Environment.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ extension LoggingSystem {
2020
}
2121
}
2222

23-
#if compiler(>=6.1)
24-
extension Logging.Logger.Level: @retroactive CustomStringConvertible {}
25-
extension Logging.Logger.Level: @retroactive Swift.LosslessStringConvertible {}
26-
#else
27-
extension Logging.Logger.Level: Swift.LosslessStringConvertible {}
28-
#endif
23+
extension Logger.Level: @retroactive CustomStringConvertible {}
24+
extension Logger.Level: @retroactive LosslessStringConvertible {}
2925

3026
extension Logging.Logger.Level {
3127
public init?(_ description: String) { self.init(rawValue: description.lowercased()) }

0 commit comments

Comments
 (0)