Skip to content

Commit 4250a7d

Browse files
authored
Migrated to Swift 6.0 (#225)
## Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Migrated the code base to Swift 6.1 ## Type of change <!--- Please delete options that are not relevant. --> - [x] New feature (non-breaking change which adds functionality) --------- Co-authored-by: brennobemoura <[email protected]>
1 parent 8076c95 commit 4250a7d

File tree

86 files changed

+913
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+913
-625
lines changed

.github/workflows/code-coverage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
platform: ${{ matrix.platform }}
3535
name: ${{ matrix.name }}
3636
coverage-enabled: true
37+
swift-version: "6.1"
3738
secrets: inherit
3839

3940
apple-tests:

.github/workflows/no-breaking-changes.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ concurrency:
1515
jobs:
1616
breaking-changes:
1717
uses: request-dl/.github/.github/workflows/no-breaking-changes.yml@main
18+
with:
19+
swift-version: "6.1"
1820
secrets: inherit

Package.resolved

Lines changed: 3 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.10
1+
// swift-tools-version: 6.1
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -23,27 +23,23 @@ let package = Package(
2323
from: "1.27.0"
2424
),
2525
.package(
26-
url: "https://github.com/apple/swift-docc-plugin.git",
27-
from: "1.4.5"
28-
),
29-
.package(
30-
url: "https://github.com/apple/swift-nio.git",
26+
url: "https://github.com/apple/swift-nio",
3127
from: "2.86.0"
3228
),
3329
.package(
34-
url: "https://github.com/apple/swift-nio-extras.git",
30+
url: "https://github.com/apple/swift-nio-extras",
3531
from: "1.29.0"
3632
),
3733
.package(
38-
url: "https://github.com/apple/swift-nio-ssl.git",
39-
from: "2.33.0"
34+
url: "https://github.com/apple/swift-nio-ssl",
35+
from: "2.34.0"
4036
),
4137
.package(
42-
url: "https://github.com/apple/swift-nio-transport-services.git",
38+
url: "https://github.com/apple/swift-nio-transport-services",
4339
from: "1.25.1"
4440
),
4541
.package(
46-
url: "https://github.com/apple/swift-log.git",
42+
url: "https://github.com/apple/swift-log",
4743
from: "1.6.4"
4844
)
4945
],
@@ -66,16 +62,8 @@ let package = Package(
6662

6763
.testTarget(
6864
name: "RequestDLTests",
69-
dependencies: [
70-
"RequestDL",
71-
.product(name: "AsyncHTTPClient", package: "async-http-client"),
72-
.product(name: "NIO", package: "swift-nio"),
73-
.product(name: "NIOPosix", package: "swift-nio"),
74-
.product(name: "NIOSSL", package: "swift-nio-ssl"),
75-
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
76-
.product(name: "Logging", package: "swift-log")
77-
],
65+
dependencies: ["RequestDL"],
7866
resources: [.process("Resources")]
7967
)
8068
]
81-
)
69+
)

Sources/RequestDL/Internals/Extensions/Override/Internals.Override.FatalError.swift

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,44 @@ extension Internals.Override {
99
#if DEBUG
1010
enum FatalError {
1111

12-
typealias Closure = (String, StaticString, UInt) -> Never
12+
typealias Closure = @Sendable (String, StaticString, UInt) -> Never
1313

14-
fileprivate static var closure: Closure = defaultClosure
14+
fileprivate final class State: @unchecked Sendable {
15+
16+
var closure: Closure {
17+
get { lock.withLock { _closure } }
18+
set { lock.withLock { _closure = newValue } }
19+
}
20+
21+
private let lock = Lock()
22+
private var _closure: Closure = defaultClosure
23+
24+
init() {}
25+
}
26+
27+
fileprivate static let state = State()
1528

1629
private static let defaultClosure: Closure = {
1730
Swift.fatalError($0, file: $1, line: $2)
1831
}
1932

2033
static func replace(with closure: @escaping Closure) {
21-
self.closure = closure
34+
self.state.closure = closure
2235
}
2336

2437
static func restore() {
25-
closure = defaultClosure
38+
state.closure = defaultClosure
2639
}
2740
}
2841
#endif
2942

3043
static func fatalError(
31-
_ message: @autoclosure () -> String = String(),
44+
_ message: @Sendable @autoclosure () -> String = String(),
3245
file: StaticString = #file,
3346
line: UInt = #line
3447
) -> Never {
3548
#if DEBUG
36-
FatalError.closure(message(), file, line)
49+
FatalError.state.closure(message(), file, line)
3750
#else
3851
Swift.fatalError(
3952
message(),

Sources/RequestDL/Internals/Extensions/Override/Internals.Override.Print.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,41 @@ import Foundation
77
extension Internals.Override {
88

99
#if DEBUG
10-
enum Print {
11-
typealias Closure = (String, String, Any...) -> Void
10+
enum Print: Sendable {
11+
typealias Closure = @Sendable (String, String, Sendable...) -> Void
1212

13-
fileprivate static var closure: Closure = defaultClosure
13+
fileprivate final class State: @unchecked Sendable {
14+
15+
var closure: Closure {
16+
get { lock.withLock { _closure } }
17+
set { lock.withLock { _closure = newValue } }
18+
}
19+
20+
private let lock = Lock()
21+
private var _closure: Closure = defaultClosure
22+
23+
init() {}
24+
}
25+
26+
fileprivate static let state = State()
1427

1528
private static let defaultClosure: Closure = {
1629
Swift.print($2, separator: $0, terminator: $1)
1730
}
1831

1932
static func replace(with closure: @escaping Closure) {
20-
self.closure = closure
33+
self.state.closure = closure
2134
}
2235

2336
static func restore() {
24-
closure = defaultClosure
37+
state.closure = defaultClosure
2538
}
2639
}
2740
#endif
2841

29-
static func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
42+
static func print(_ items: Sendable..., separator: String = " ", terminator: String = "\n") {
3043
#if DEBUG
31-
Print.closure(separator, terminator, items)
44+
Print.state.closure(separator, terminator, items)
3245
#else
3346
Swift.print(items, separator: separator, terminator: terminator)
3447
#endif

Sources/RequestDL/Internals/Extensions/Override/Internals.Override.Raise.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,41 @@ extension Internals.Override {
88

99
#if DEBUG
1010
enum Raise {
11-
typealias Closure = (Int32) -> Int32
11+
typealias Closure = @Sendable (Int32) -> Int32
1212

13-
fileprivate static var closure: Closure = defaultClosure
13+
fileprivate final class State: @unchecked Sendable {
14+
15+
var closure: Closure {
16+
get { lock.withLock { _closure } }
17+
set { lock.withLock { _closure = newValue } }
18+
}
19+
20+
private let lock = Lock()
21+
private var _closure: Closure = defaultClosure
22+
23+
init() {}
24+
}
25+
26+
fileprivate static let state = State()
1427

1528
private static let defaultClosure: Closure = {
1629
Foundation.raise($0)
1730
}
1831

1932
static func replace(with closure: @escaping Closure) {
20-
self.closure = closure
33+
self.state.closure = closure
2134
}
2235

2336
static func restore() {
24-
closure = defaultClosure
37+
state.closure = defaultClosure
2538
}
2639
}
2740
#endif
2841

2942
@discardableResult
3043
static func raise(_ value: Int32) -> Int32 {
3144
#if DEBUG
32-
Raise.closure(value)
45+
Raise.state.closure(value)
3346
#else
3447
Foundation.raise(value)
3548
#endif

Sources/RequestDL/Internals/Sources/Body/Internals.Body.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension Internals {
6666
return writer.write(.byteBuffer(.init()))
6767
}
6868

69-
return first.flatMapWithEventLoop {
69+
return first.flatMapWithEventLoop { [sequence] in
7070
consume(iterator: sequence, eventLoop: $1)
7171
}
7272
}

Sources/RequestDL/Internals/Sources/Client/Client/Models/Internals.UnsafeTask.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AsyncHTTPClient
88

99
extension Internals {
1010

11-
struct UnsafeTask<Element>: Sendable, Hashable {
11+
struct UnsafeTask<Element: Sendable>: Sendable, Hashable {
1212

1313
fileprivate final class RunningState: @unchecked Sendable {
1414
var isRunning = true
@@ -23,7 +23,7 @@ extension Internals {
2323

2424
init(
2525
_ task: HTTPClient.Task<Element>,
26-
completion: @escaping () -> Void
26+
completion: @Sendable @escaping () -> Void
2727
) {
2828
let lock = Lock()
2929
let runningState = RunningState()

0 commit comments

Comments
 (0)