Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation with Swift 5.5.0 and 5.5.1 #2234

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Sources/NIOCore/SocketAddresses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension SocketAddressError {
public enum SocketAddress: CustomStringConvertible, NIOSendable {

/// A single IPv4 address for `SocketAddress`.
public struct IPv4Address: NIOSendable {
public struct IPv4Address {
private let _storage: Box<(address: sockaddr_in, host: String)>

/// The libc socket address for an IPv4 address.
Expand All @@ -90,7 +90,7 @@ public enum SocketAddress: CustomStringConvertible, NIOSendable {
}

/// A single IPv6 address for `SocketAddress`.
public struct IPv6Address: NIOSendable {
public struct IPv6Address {
private let _storage: Box<(address: sockaddr_in6, host: String)>

/// The libc socket address for an IPv6 address.
Expand Down Expand Up @@ -560,6 +560,16 @@ extension SocketAddress: Equatable {
}
}

#if compiler(>=5.5.2)
extension SocketAddress.IPv4Address: Sendable {}
extension SocketAddress.IPv6Address: Sendable {}
#elseif compiler(>=5.5)
// Implicit conformance of tuples to Sendable interacts poorly with conditional conformance of Sendable in Swift <=5.5.1
// https://github.com/apple/swift/issues/57346
extension SocketAddress.IPv4Address: @unchecked Sendable {}
extension SocketAddress.IPv6Address: @unchecked Sendable {}
#endif

/// We define an extension on `SocketAddress` that gives it an elementwise hashable conformance, using
/// only the elements defined on the structure in their man pages (excluding lengths).
extension SocketAddress: Hashable {
Expand Down
10 changes: 9 additions & 1 deletion Sources/NIOHTTP1/HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ extension HTTPHeaders {
/// field when needed. It also supports recomposing headers to a maximally joined
/// or split representation, such that header fields that are able to be repeated
/// can be represented appropriately.
public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiteral, NIOSendable {
public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiteral {
@usableFromInline
internal var headers: [(String, String)]
internal var keepAliveState: KeepAliveState = .unknown
Expand Down Expand Up @@ -497,6 +497,14 @@ public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiter
}
}

#if compiler(>=5.5.2)
extension HTTPHeaders: Sendable {}
#elseif compiler(>=5.5)
// Implicit conformance of tuples to Sendable interacts poorly with conditional conformance of Sendable in Swift <=5.5.1
// https://github.com/apple/swift/issues/57346
extension HTTPHeaders: @unchecked Sendable {}
#endif

extension HTTPHeaders {

/// The total number of headers that can be contained without allocating new storage.
Expand Down