Skip to content

Commit 76ae1e4

Browse files
authored
Fix warnings from nightly Swift builds (#1600)
Motivation: Nightly swift builds produce a few warnings: mostly around shadowing generics from an outer scope. Modifications: - Fix warnings. Result: Fewer warnings.
1 parent 4ab02e1 commit 76ae1e4

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

Sources/GRPC/ClientConnection.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
#if os(Linux)
1617
@preconcurrency import Foundation
18+
#else
19+
import Foundation
20+
#endif
1721

1822
import Logging
1923
import NIOCore

Sources/GRPC/Interceptor/ClientTransportFactory.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import protocol SwiftProtobuf.Message
2121
@usableFromInline
2222
internal struct ClientTransportFactory<Request, Response> {
2323
/// The underlying transport factory.
24-
private var factory: Factory<Request, Response>
24+
private var factory: Factory
2525

2626
@usableFromInline
27-
internal enum Factory<Request, Response> {
27+
internal enum Factory {
2828
case http2(HTTP2ClientTransportFactory<Request, Response>)
2929
case fake(FakeClientTransportFactory<Request, Response>)
3030
}
@@ -45,13 +45,14 @@ internal struct ClientTransportFactory<Request, Response> {
4545
/// - errorDelegate: A client error delegate.
4646
/// - Returns: A factory for making and configuring HTTP/2 based transport.
4747
@usableFromInline
48-
internal static func http2<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>(
48+
internal static func http2(
4949
channel: EventLoopFuture<Channel>,
5050
authority: String,
5151
scheme: String,
5252
maximumReceiveMessageLength: Int,
5353
errorDelegate: ClientErrorDelegate?
54-
) -> ClientTransportFactory<Request, Response> {
54+
) -> ClientTransportFactory<Request, Response> where Request: SwiftProtobuf.Message,
55+
Response: SwiftProtobuf.Message {
5556
let http2 = HTTP2ClientTransportFactory<Request, Response>(
5657
streamChannel: channel,
5758
scheme: scheme,
@@ -72,13 +73,13 @@ internal struct ClientTransportFactory<Request, Response> {
7273
/// - errorDelegate: A client error delegate.
7374
/// - Returns: A factory for making and configuring HTTP/2 based transport.
7475
@usableFromInline
75-
internal static func http2<Request: GRPCPayload, Response: GRPCPayload>(
76+
internal static func http2(
7677
channel: EventLoopFuture<Channel>,
7778
authority: String,
7879
scheme: String,
7980
maximumReceiveMessageLength: Int,
8081
errorDelegate: ClientErrorDelegate?
81-
) -> ClientTransportFactory<Request, Response> {
82+
) -> ClientTransportFactory<Request, Response> where Request: GRPCPayload, Response: GRPCPayload {
8283
let http2 = HTTP2ClientTransportFactory<Request, Response>(
8384
streamChannel: channel,
8485
scheme: scheme,
@@ -95,9 +96,10 @@ internal struct ClientTransportFactory<Request, Response> {
9596
/// - Parameter fakeResponse: The fake response stream.
9697
/// - Returns: A factory for making and configuring fake transport.
9798
@usableFromInline
98-
internal static func fake<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>(
99+
internal static func fake(
99100
_ fakeResponse: _FakeResponseStream<Request, Response>?
100-
) -> ClientTransportFactory<Request, Response> {
101+
) -> ClientTransportFactory<Request, Response> where Request: SwiftProtobuf.Message,
102+
Response: SwiftProtobuf.Message {
101103
let factory = FakeClientTransportFactory(
102104
fakeResponse,
103105
requestSerializer: ProtobufSerializer(),
@@ -112,9 +114,9 @@ internal struct ClientTransportFactory<Request, Response> {
112114
/// - Parameter fakeResponse: The fake response stream.
113115
/// - Returns: A factory for making and configuring fake transport.
114116
@usableFromInline
115-
internal static func fake<Request: GRPCPayload, Response: GRPCPayload>(
117+
internal static func fake(
116118
_ fakeResponse: _FakeResponseStream<Request, Response>?
117-
) -> ClientTransportFactory<Request, Response> {
119+
) -> ClientTransportFactory<Request, Response> where Request: GRPCPayload, Response: GRPCPayload {
118120
let factory = FakeClientTransportFactory(
119121
fakeResponse,
120122
requestSerializer: GRPCPayloadSerializer(),
@@ -239,7 +241,7 @@ internal struct HTTP2ClientTransportFactory<Request, Response> {
239241
)
240242
}
241243

242-
fileprivate func configure<Request, Response>(_ transport: ClientTransport<Request, Response>) {
244+
fileprivate func configure(_ transport: ClientTransport<Request, Response>) {
243245
transport.configure { _ in
244246
self.streamChannel.flatMapThrowing { channel in
245247
// This initializer will always occur on the appropriate event loop, sync operations are
@@ -342,7 +344,7 @@ internal struct FakeClientTransportFactory<Request, Response> {
342344
)
343345
}
344346

345-
fileprivate func configure<Request, Response>(_ transport: ClientTransport<Request, Response>) {
347+
fileprivate func configure(_ transport: ClientTransport<Request, Response>) {
346348
transport.configure { handler in
347349
if let fakeResponse = self.fakeResponseStream {
348350
return fakeResponse.channel.pipeline.addHandlers(self.codec, handler).always { result in

Sources/GRPCInteroperabilityTestsImplementation/GRPCTestingConvenienceMethods.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import SwiftProtobuf
2121
// MARK: - Payload creation
2222

2323
extension Grpc_Testing_Payload {
24-
static func bytes<T>(of body: inout T) -> Grpc_Testing_Payload {
24+
static func bytes(of value: UInt64) -> Grpc_Testing_Payload {
2525
return Grpc_Testing_Payload.with { payload in
26-
payload.body = Data(bytes: &body, count: MemoryLayout.size(ofValue: body))
26+
withUnsafeBytes(of: value) { bytes in
27+
payload.body = Data(bytes)
28+
}
2729
}
2830
}
2931

Sources/GRPCInteroperabilityTestsImplementation/InteroperabilityTestCases.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class CacheableUnary: InteroperabilityTest {
6767
func run(using connection: ClientConnection) throws {
6868
let client = Grpc_Testing_TestServiceNIOClient(channel: connection)
6969

70-
var timestamp = DispatchTime.now().rawValue
71-
let request = Grpc_Testing_SimpleRequest.withPayload(of: .bytes(of: &timestamp))
70+
let timestamp = DispatchTime.now().uptimeNanoseconds
71+
let request = Grpc_Testing_SimpleRequest.withPayload(of: .bytes(of: timestamp))
7272

7373
let headers: HPACKHeaders = ["x-user-ip": "1.2.3.4"]
7474
let callOptions = CallOptions(customMetadata: headers, cacheable: true)

Tests/GRPCTests/XCTestHelpers.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,24 @@ struct Matcher<Value> {
100100
// MARK: Sugar
101101

102102
/// Just returns the provided matcher.
103-
static func `is`<Value>(_ matcher: Matcher<Value>) -> Matcher<Value> {
103+
static func `is`<V>(_ matcher: Matcher<V>) -> Matcher<V> {
104104
return matcher
105105
}
106106

107107
/// Just returns the provided matcher.
108-
static func and<Value>(_ matcher: Matcher<Value>) -> Matcher<Value> {
108+
static func and<V>(_ matcher: Matcher<V>) -> Matcher<V> {
109109
return matcher
110110
}
111111

112112
// MARK: Equality
113113

114114
/// Checks the equality of the actual value against the provided value. See `equalTo(_:)`.
115-
static func `is`<Value: Equatable>(_ value: Value) -> Matcher<Value> {
115+
static func `is`<V: Equatable>(_ value: V) -> Matcher<V> {
116116
return .equalTo(value)
117117
}
118118

119119
/// Checks the equality of the actual value against the provided value.
120-
static func equalTo<Value: Equatable>(_ expected: Value) -> Matcher<Value> {
120+
static func equalTo<V: Equatable>(_ expected: V) -> Matcher<V> {
121121
return .init { actual in
122122
actual == expected
123123
? .match
@@ -133,7 +133,7 @@ struct Matcher<Value> {
133133
}
134134

135135
/// Matches if the value is `nil`.
136-
static func `nil`<Value>() -> Matcher<Value?> {
136+
static func `nil`<V>() -> Matcher<V?> {
137137
return .init { actual in
138138
actual == nil
139139
? .match
@@ -142,7 +142,7 @@ struct Matcher<Value> {
142142
}
143143

144144
/// Matches if the value is not `nil`.
145-
static func notNil<Value>(_ matcher: Matcher<Value>? = nil) -> Matcher<Value?> {
145+
static func notNil<V>(_ matcher: Matcher<V>? = nil) -> Matcher<V?> {
146146
return .init { actual in
147147
if let actual = actual {
148148
return matcher?.evaluate(actual) ?? .match
@@ -154,7 +154,7 @@ struct Matcher<Value> {
154154

155155
// MARK: Result
156156

157-
static func success<Value>(_ matcher: Matcher<Value>? = nil) -> Matcher<Result<Value, Error>> {
157+
static func success<V>(_ matcher: Matcher<V>? = nil) -> Matcher<Result<V, Error>> {
158158
return .init { actual in
159159
switch actual {
160160
case let .success(value):
@@ -191,7 +191,7 @@ struct Matcher<Value> {
191191

192192
// MARK: Utility
193193

194-
static func all<Value>(_ matchers: Matcher<Value>...) -> Matcher<Value> {
194+
static func all<V>(_ matchers: Matcher<V>...) -> Matcher<V> {
195195
return .init { actual in
196196
for matcher in matchers {
197197
let result = matcher.evaluate(actual)
@@ -209,7 +209,7 @@ struct Matcher<Value> {
209209
// MARK: Type
210210

211211
/// Checks that the actual value is an instance of the given type.
212-
static func instanceOf<Value, Expected>(_: Expected.Type) -> Matcher<Value> {
212+
static func instanceOf<V, Expected>(_: Expected.Type) -> Matcher<V> {
213213
return .init { actual in
214214
if actual is Expected {
215215
return .match
@@ -635,7 +635,7 @@ struct ExpressionMatcher<Value> {
635635

636636
/// Asserts that the expression does not throw and error. Returns the result of any provided
637637
/// matcher on the result of the expression.
638-
static func doesNotThrow<Value>(_ matcher: Matcher<Value>? = nil) -> ExpressionMatcher<Value> {
638+
static func doesNotThrow<V>(_ matcher: Matcher<V>? = nil) -> ExpressionMatcher<V> {
639639
return .init { expression in
640640
do {
641641
let value = try expression()
@@ -648,7 +648,7 @@ struct ExpressionMatcher<Value> {
648648

649649
/// Asserts that the expression throws and error. Returns the result of any provided matcher
650650
/// on the error thrown by the expression.
651-
static func `throws`<Value>(_ matcher: Matcher<Error>? = nil) -> ExpressionMatcher<Value> {
651+
static func `throws`<V>(_ matcher: Matcher<Error>? = nil) -> ExpressionMatcher<V> {
652652
return .init { expression in
653653
do {
654654
let value = try expression()

0 commit comments

Comments
 (0)