Skip to content

Commit

Permalink
Update compiler guards for concurrency (#1277)
Browse files Browse the repository at this point in the history
Motivation:

The 'right' way to check if Swift concurrency is available is to use
`#if compiler(>=5.5) && canImport(_Concurrency)`. We are missing
currently missing the `canImport` check.

Modifications:

Add check for `canImport(_Concurrency)`.

Results:

We more correctly check whether concurrency is available.
  • Loading branch information
glbrntt committed Nov 26, 2021
1 parent 46b0270 commit b17f653
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Sources/Examples/Echo/Implementation/EchoAsyncProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)
import EchoModel
import GRPC

Expand Down Expand Up @@ -69,4 +69,4 @@ public final class EchoAsyncProvider: Echo_EchoAsyncProvider {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
8 changes: 4 additions & 4 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public final class Echo_EchoClient: Echo_EchoClientProtocol {
}
}

#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public protocol Echo_EchoAsyncClientProtocol: GRPCClient {
var serviceName: String { get }
Expand Down Expand Up @@ -334,7 +334,7 @@ public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)

public final class Echo_EchoTestClient: Echo_EchoClientProtocol {
private let fakeChannel: FakeChannel
Expand Down Expand Up @@ -542,7 +542,7 @@ public protocol Echo_EchoServerInterceptorFactoryProtocol {
func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
}

#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// To implement a server, implement an object which conforms to this protocol.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
Expand Down Expand Up @@ -633,5 +633,5 @@ extension Echo_EchoAsyncProvider {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)

4 changes: 2 additions & 2 deletions Sources/GRPC/AsyncAwaitSupport/AsyncWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)
import NIOCore

/// An asynchronous writer which forwards messages to a delegate.
Expand Down Expand Up @@ -334,4 +334,4 @@ internal protocol AsyncWriterDelegate: AnyObject {
func writeEnd(_ end: End)
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension Call {
Expand All @@ -30,4 +30,4 @@ extension Call {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension CancellationError: GRPCStatusTransformable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import NIOHPACK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import NIOHPACK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// This is currently a wrapper around AsyncThrowingStream because we want to be
/// able to swap out the implementation for something else in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// An object allowing the holder -- a client -- to send requests on an RPC.
///
Expand Down Expand Up @@ -124,4 +124,4 @@ extension GRPCAsyncRequestStreamWriter {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// This is currently a wrapper around AsyncThrowingStream because we want to be
/// able to swap out the implementation for something else in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// Writer for server-streaming RPC handlers to provide responses.
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import Logging
import NIOConcurrencyHelpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import _NIOConcurrency
import NIOCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import NIOHPACK

Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPC/AsyncAwaitSupport/GRPCAsyncUnaryCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import NIOHPACK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import SwiftProtobuf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

import SwiftProtobuf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)

/// An ``AsyncSequence`` adapter for a ``PassthroughMessageSource``.`
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
Expand Down Expand Up @@ -55,4 +55,4 @@ internal struct PassthroughMessageSequence<Element, Failure: Error>: AsyncSequen
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
4 changes: 2 additions & 2 deletions Sources/GRPC/AsyncAwaitSupport/PassthroughMessageSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if compiler(>=5.5)
#if compiler(>=5.5) && canImport(_Concurrency)
import NIOConcurrencyHelpers
import NIOCore

Expand Down Expand Up @@ -160,4 +160,4 @@ internal final class PassthroughMessageSource<Element, Failure: Error> {
}
}

#endif // compiler(>=5.5)
#endif // compiler(>=5.5) && canImport(_Concurrency)
4 changes: 2 additions & 2 deletions Sources/protoc-gen-grpc-swift/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ class Generator {
}

func printIfCompilerGuardForAsyncAwait() {
self.println("#if compiler(>=5.5)")
self.println("#if compiler(>=5.5) && canImport(_Concurrency)")
}

func printEndCompilerGuardForAsyncAwait() {
self.println("#endif // compiler(>=5.5)")
self.println("#endif // compiler(>=5.5) && canImport(_Concurrency)")
}
}

0 comments on commit b17f653

Please sign in to comment.