Skip to content

Commit 9d44bcd

Browse files
authored
Swift 6 language mode (#619)
* Swift 6 mode * Fix AsyncHTTPClient deprecation
1 parent ba5f22a commit 9d44bcd

File tree

16 files changed

+99
-64
lines changed

16 files changed

+99
-64
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let package = Package(
4242
.package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"),
4343
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.7.2"),
4444
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.13.1"),
45-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.21.0"),
45+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
4646
.package(url: "https://github.com/adam-fowler/jmespath.swift.git", from: "1.0.2"),
4747
],
4848
targets: [
@@ -117,5 +117,6 @@ let package = Package(
117117
.testTarget(name: "INIParserTests", dependencies: [
118118
.byName(name: "INIParser"),
119119
]),
120-
]
120+
],
121+
swiftLanguageVersions: [.v5, .version("6")]
121122
)

Sources/SotoCore/Encoder/CodableProperties/DateCoders.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,21 @@ public struct ISO8601DateCoder: CustomDecoder, CustomEncoder {
8888
self.dateFormatters[0].string(from: value)
8989
}
9090

91+
#if compiler(>=5.10)
92+
nonisolated(unsafe) static let dateFormatters: [ISO8601DateFormatter] = {
93+
let dateFormatters: [ISO8601DateFormatter] = [ISO8601DateFormatter(), ISO8601DateFormatter()]
94+
dateFormatters[0].formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
95+
dateFormatters[1].formatOptions = [.withFullDate, .withFullTime]
96+
return dateFormatters
97+
}()
98+
#else
9199
static let dateFormatters: [ISO8601DateFormatter] = {
92100
let dateFormatters: [ISO8601DateFormatter] = [ISO8601DateFormatter(), ISO8601DateFormatter()]
93101
dateFormatters[0].formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
94102
dateFormatters[1].formatOptions = [.withFullDate, .withFullTime]
95103
return dateFormatters
96104
}()
105+
#endif
97106
}
98107

99108
/// Date coder for HTTP header format

Sources/SotoCore/Encoder/QueryEncoder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,19 @@ extension _QueryEncoder {
392392
}
393393
}
394394

395+
#if compiler(>=5.10)
396+
nonisolated(unsafe) static let dateFormatter: ISO8601DateFormatter = {
397+
let dateFormatter = ISO8601DateFormatter()
398+
dateFormatter.formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
399+
return dateFormatter
400+
}()
401+
#else
395402
static let dateFormatter: ISO8601DateFormatter = {
396403
let dateFormatter = ISO8601DateFormatter()
397404
dateFormatter.formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
398405
return dateFormatter
399406
}()
407+
#endif
400408
}
401409

402410
//===----------------------------------------------------------------------===//

Sources/SotoCore/HTTP/AWSHTTPRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal import SotoXML
2828
#endif
2929

3030
/// Object encapsulating all the information needed to generate a raw HTTP request to AWS
31-
public struct AWSHTTPRequest {
31+
public struct AWSHTTPRequest: Sendable {
3232
/// request URL
3333
public var url: URL
3434
/// request HTTP method

Sources/SotoCore/HTTP/AsyncHTTPClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension AsyncHTTPClient.HTTPClient: AWSHTTPClient {
3737
case .asyncSequence(let sequence, let length):
3838
requestBody = .stream(
3939
sequence,
40-
length: length.map { .known($0) } ?? .unknown
40+
length: length.map { .known(Int64($0)) } ?? .unknown
4141
)
4242
}
4343
var httpRequest = HTTPClientRequest(url: request.url.absoluteString)

Sources/SotoTestUtils/TestServer.swift

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import SotoXML
2222
import XCTest
2323

2424
/// Test server for AWSClient. Input and Output shapes are defined by process function
25-
public class AWSTestServer {
25+
public final class AWSTestServer: Sendable {
2626
public enum Error: Swift.Error {
2727
case notHead
2828
case notBody
@@ -33,14 +33,14 @@ public class AWSTestServer {
3333
}
3434

3535
// what are we returning
36-
public enum ServiceProtocol {
36+
public enum ServiceProtocol: Sendable {
3737
case restjson
3838
case json
3939
case xml
4040
}
4141

4242
// http incoming request
43-
public struct Request {
43+
public struct Request: Sendable {
4444
public let method: HTTPMethod
4545
public let uri: String
4646
public let headers: [String: String]
@@ -55,7 +55,7 @@ public class AWSTestServer {
5555
}
5656

5757
// http outgoing response
58-
public struct Response {
58+
public struct Response: Sendable {
5959
public let httpStatus: HTTPResponseStatus
6060
public let headers: [String: String]
6161
public let body: ByteBuffer?
@@ -66,30 +66,30 @@ public class AWSTestServer {
6666
self.body = body
6767
}
6868

69-
public static let ok = Response(httpStatus: .ok)
69+
public static var ok: Response { Response(httpStatus: .ok) }
7070
}
7171

7272
/// Error type
73-
public struct ErrorType {
73+
public struct ErrorType: Sendable {
7474
public let status: Int
7575
public let errorCode: String
7676
public let message: String
7777

7878
public var json: String { return "{\"__type\":\"\(self.errorCode)\", \"message\": \"\(self.message)\"}" }
7979
public var xml: String { return "<Error><Code>\(self.errorCode)</Code><Message>\(self.message)</Message></Error>" }
8080

81-
public static let badRequest = ErrorType(status: 400, errorCode: "BadRequest", message: "AWSTestServer_ErrorType_BadRequest")
82-
public static let accessDenied = ErrorType(status: 401, errorCode: "AccessDenied", message: "AWSTestServer_ErrorType_AccessDenied")
83-
public static let notFound = ErrorType(status: 404, errorCode: "NotFound", message: "AWSTestServer_ErrorType_NotFound")
84-
public static let tooManyRequests = ErrorType(status: 429, errorCode: "TooManyRequests", message: "AWSTestServer_ErrorType_TooManyRequests")
81+
public static var badRequest: ErrorType { ErrorType(status: 400, errorCode: "BadRequest", message: "AWSTestServer_ErrorType_BadRequest") }
82+
public static var accessDenied: ErrorType { ErrorType(status: 401, errorCode: "AccessDenied", message: "AWSTestServer_ErrorType_AccessDenied") }
83+
public static var notFound: ErrorType { ErrorType(status: 404, errorCode: "NotFound", message: "AWSTestServer_ErrorType_NotFound") }
84+
public static var tooManyRequests: ErrorType { ErrorType(status: 429, errorCode: "TooManyRequests", message: "AWSTestServer_ErrorType_TooManyRequests") }
8585

86-
public static let `internal` = ErrorType(status: 500, errorCode: "InternalFailure", message: "AWSTestServer_ErrorType_InternalFailure")
87-
public static let notImplemented = ErrorType(status: 501, errorCode: "NotImplemented", message: "AWSTestServer_ErrorType_NotImplemented")
88-
public static let serviceUnavailable = ErrorType(status: 503, errorCode: "ServiceUnavailable", message: "AWSTestServer_ErrorType_ServiceUnavailable")
86+
public static var `internal`: ErrorType { ErrorType(status: 500, errorCode: "InternalFailure", message: "AWSTestServer_ErrorType_InternalFailure") }
87+
public static var notImplemented: ErrorType { ErrorType(status: 501, errorCode: "NotImplemented", message: "AWSTestServer_ErrorType_NotImplemented") }
88+
public static var serviceUnavailable: ErrorType { ErrorType(status: 503, errorCode: "ServiceUnavailable", message: "AWSTestServer_ErrorType_ServiceUnavailable") }
8989
}
9090

9191
/// result from process
92-
public enum Result<Output> {
92+
public enum Result<Output: Sendable>: Sendable {
9393
case result(Output, continueProcessing: Bool = false)
9494
case error(ErrorType, continueProcessing: Bool = false)
9595
}
@@ -174,15 +174,17 @@ extension AWSTestServer {
174174
public let lastUpdated: Date
175175
public let type: String
176176

177-
public static let `default` = EC2InstanceMetaData(
178-
accessKeyId: "EC2ACCESSKEYID",
179-
secretAccessKey: "EC2SECRETACCESSKEY",
180-
token: "EC2SESSIONTOKEN",
181-
expiration: Date(timeIntervalSinceNow: 3600),
182-
code: "ec2-test-role",
183-
lastUpdated: Date(timeIntervalSinceReferenceDate: 0),
184-
type: "type"
185-
)
177+
public static var `default`: EC2InstanceMetaData {
178+
.init(
179+
accessKeyId: "EC2ACCESSKEYID",
180+
secretAccessKey: "EC2SECRETACCESSKEY",
181+
token: "EC2SESSIONTOKEN",
182+
expiration: Date(timeIntervalSinceNow: 3600),
183+
code: "ec2-test-role",
184+
lastUpdated: Date(timeIntervalSinceReferenceDate: 0),
185+
type: "type"
186+
)
187+
}
186188

187189
enum CodingKeys: String, CodingKey {
188190
case accessKeyId = "AccessKeyId"
@@ -202,13 +204,15 @@ extension AWSTestServer {
202204
public let expiration: Date
203205
public let roleArn: String
204206

205-
public static let `default` = ECSMetaData(
206-
accessKeyId: "ECSACCESSKEYID",
207-
secretAccessKey: "ECSSECRETACCESSKEY",
208-
token: "ECSSESSIONTOKEN",
209-
expiration: Date(timeIntervalSinceNow: 3600),
210-
roleArn: "arn:aws:iam:000000000000:role/ecs-test-role"
211-
)
207+
public static var `default`: ECSMetaData {
208+
.init(
209+
accessKeyId: "ECSACCESSKEYID",
210+
secretAccessKey: "ECSSECRETACCESSKEY",
211+
token: "ECSSESSIONTOKEN",
212+
expiration: Date(timeIntervalSinceNow: 3600),
213+
roleArn: "arn:aws:iam:000000000000:role/ecs-test-role"
214+
)
215+
}
212216

213217
enum CodingKeys: String, CodingKey {
214218
case accessKeyId = "AccessKeyId"

Sources/SotoXML/XMLDecoder.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,21 @@ private class _XMLDecoder: Decoder {
658658
}
659659
}
660660

661+
#if compiler(>=5.10)
662+
nonisolated(unsafe) static let dateFormatters: [ISO8601DateFormatter] = {
663+
let dateFormatters: [ISO8601DateFormatter] = [ISO8601DateFormatter(), ISO8601DateFormatter()]
664+
dateFormatters[0].formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
665+
dateFormatters[1].formatOptions = [.withFullDate, .withFullTime]
666+
return dateFormatters
667+
}()
668+
#else
661669
static let dateFormatters: [ISO8601DateFormatter] = {
662670
let dateFormatters: [ISO8601DateFormatter] = [ISO8601DateFormatter(), ISO8601DateFormatter()]
663671
dateFormatters[0].formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
664672
dateFormatters[1].formatOptions = [.withFullDate, .withFullTime]
665673
return dateFormatters
666674
}()
675+
#endif
667676
}
668677

669678
//===----------------------------------------------------------------------===//

Sources/SotoXML/XMLEncoder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,19 @@ extension _XMLEncoder {
560560
}
561561
}
562562

563+
#if compiler(>=5.10)
564+
nonisolated(unsafe) static let dateFormatter: ISO8601DateFormatter = {
565+
let dateFormatter = ISO8601DateFormatter()
566+
dateFormatter.formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
567+
return dateFormatter
568+
}()
569+
#else
563570
static let dateFormatter: ISO8601DateFormatter = {
564571
let dateFormatter = ISO8601DateFormatter()
565572
dateFormatter.formatOptions = [.withFullDate, .withFullTime, .withFractionalSeconds]
566573
return dateFormatter
567574
}()
575+
#endif
568576
}
569577

570578
// MARK: - _XMLReferencingEncoder

Tests/INIParserTests/INIParserTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,4 @@ class INIParserTests: XCTestCase {
5353
XCTAssertEqual(ini?.sections["汉化"]?["变量2"] ?? "", "加拿大。")
5454
XCTAssertNotNil(ini?.sections[" 乱死了 "])
5555
}
56-
57-
static var allTests = [
58-
("testExample", testExample),
59-
]
6056
}

Tests/SotoCoreTests/AWSClientTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class AWSClientTests: XCTestCase {
243243

244244
func testRequestStreaming(config: AWSServiceConfig, client: AWSClient, server: AWSTestServer, bufferSize: Int, blockSize: Int) async throws {
245245
struct Input: AWSEncodableShape {
246-
static var _options: AWSShapeOptions = [.allowStreaming]
246+
static var _options: AWSShapeOptions { [.allowStreaming] }
247247
let payload: AWSHTTPBody
248248
func encode(to encoder: Encoder) throws {
249249
try self.payload.encode(to: encoder)
@@ -309,7 +309,7 @@ class AWSClientTests: XCTestCase {
309309

310310
func testRequestStreamingWithPayload(_ payload: AWSHTTPBody) async throws {
311311
struct Input: AWSEncodableShape {
312-
static var _options: AWSShapeOptions = [.allowStreaming]
312+
static var _options: AWSShapeOptions { [.allowStreaming] }
313313
let payload: AWSHTTPBody
314314
func encode(to encoder: Encoder) throws {
315315
try self.payload.encode(to: encoder)
@@ -359,7 +359,7 @@ class AWSClientTests: XCTestCase {
359359

360360
func testRequestChunkedStreaming() async throws {
361361
struct Input: AWSEncodableShape {
362-
static var _options: AWSShapeOptions = [.allowStreaming, .allowChunkedStreaming, .rawPayload]
362+
static let _options: AWSShapeOptions = [.allowStreaming, .allowChunkedStreaming, .rawPayload]
363363
let payload: AWSHTTPBody
364364
func encode(to encoder: Encoder) throws {
365365
try self.payload.encode(to: encoder)

Tests/SotoCoreTests/AWSRequestTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class AWSRequestTests: XCTestCase {
562562
let number: Int
563563
}
564564
struct Input: AWSEncodableShape {
565-
static var _xmlRootNodeName: String? = "Payload"
565+
static let _xmlRootNodeName: String? = "Payload"
566566
let payload: Payload
567567

568568
func encode(to encoder: Encoder) throws {

Tests/SotoCoreTests/LoggingTests.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,20 @@ struct LoggingCollector: LogHandler {
243243
var logs: Logs
244244
var internalHandler: LogHandler
245245

246-
class Logs {
246+
struct Logs {
247247
struct Entry {
248248
var level: Logger.Level
249249
var message: String
250250
var metadata: [String: String]
251251
}
252252

253-
private var lock = NIOLock()
254-
private var logs: [Entry] = []
253+
private let logs: NIOLockedValueBox<[Entry]> = .init([])
255254

256-
var allEntries: [Entry] { return self.lock.withLock { self.logs } }
255+
var allEntries: [Entry] { return self.logs.withLockedValue { $0 } }
257256

258257
func append(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?) {
259-
self.lock.withLock {
260-
self.logs.append(Entry(
258+
self.logs.withLockedValue {
259+
$0.append(Entry(
261260
level: level,
262261
message: message.description,
263262
metadata: metadata?.mapValues { $0.description } ?? [:]

Tests/SotoCoreTests/QueryEncoderTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import SotoTestUtils
1717
import XCTest
1818

1919
class QueryEncoderTests: XCTestCase {
20-
@EnvironmentVariable("ENABLE_TIMING_TESTS", default: true) static var enableTimingTests: Bool
21-
2220
func testQuery(_ value: some Encodable, query: String) {
2321
do {
2422
let query2 = try QueryEncoder().encode(value)

Tests/SotoCoreTests/TracingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final class TracingTests: XCTestCase {
8686
private func XCTAssertSpanAttributesEqual(
8787
_ lhs: @autoclosure () -> SpanAttributes,
8888
_ rhs: @autoclosure () -> [String: SpanAttribute],
89-
file: StaticString = #file,
89+
file: StaticString = #filePath,
9090
line: UInt = #line
9191
) {
9292
var rhs = rhs()

0 commit comments

Comments
 (0)