Ver código fonte

Enable `InternalImportsByDefault` in v2 modules (#2003)

Starting with Swift 5.10, `InternalImportsByDefault` is an optional feature flag to make all `import` statements be `internal` by default, instead of `public`, which has been the default since the beginning in Swift.
With a future language mode, this will become the new default, and all imports will be `internal` unless otherwise specified. The main reason for this change is to minimise dependency creep.

This PR enables the feature flag on v2 modules, and adds `public`/`package` access modifiers to `import`s where required.

Note that sadly, `@usableFromInline` has not been implemented for `import` statements, so in `@inlinable`/`@usableFromInline` contexts where non-publicly-imported types are used, the only workaround for now is to import the module as `public`. I've left a comment next to these imports.
Gustavo Cairo 1 ano atrás
pai
commit
b58173627f
36 arquivos alterados com 80 adições e 79 exclusões
  1. 2 2
      Sources/GRPCHTTP2Core/Client/Connection/ClientConnectionHandler.swift
  2. 4 4
      Sources/GRPCHTTP2Core/Client/Connection/Connection.swift
  3. 3 3
      Sources/GRPCHTTP2Core/Client/Connection/ConnectionFactory.swift
  4. 3 3
      Sources/GRPCHTTP2Core/Client/Connection/GRPCChannel.swift
  5. 1 1
      Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/PickFirstLoadBalancer.swift
  6. 1 1
      Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/RoundRobinLoadBalancer.swift
  7. 2 2
      Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/Subchannel.swift
  8. 1 1
      Sources/GRPCHTTP2Core/Client/Connection/RequestQueue.swift
  9. 3 3
      Sources/GRPCHTTP2Core/Client/GRPCClientStreamHandler.swift
  10. 1 1
      Sources/GRPCHTTP2Core/Client/HTTP2ClientTransport.swift
  11. 1 1
      Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv4.swift
  12. 1 1
      Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv6.swift
  13. 1 1
      Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+UDS.swift
  14. 1 1
      Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+VSOCK.swift
  15. 1 1
      Sources/GRPCHTTP2Core/Client/Resolver/NameResolver.swift
  16. 1 1
      Sources/GRPCHTTP2Core/Compression/CompressionAlgorithm.swift
  17. 3 3
      Sources/GRPCHTTP2Core/Compression/Zlib.swift
  18. 2 2
      Sources/GRPCHTTP2Core/GRPCMessageDecoder.swift
  19. 2 2
      Sources/GRPCHTTP2Core/GRPCMessageFramer.swift
  20. 4 4
      Sources/GRPCHTTP2Core/GRPCStreamStateMachine.swift
  21. 1 1
      Sources/GRPCHTTP2Core/Internal/ConstantAsyncSequence.swift
  22. 4 4
      Sources/GRPCHTTP2Core/Internal/NIOChannelPipeline+GRPC.swift
  23. 1 1
      Sources/GRPCHTTP2Core/Internal/NIOSocketAddress+GRPCSocketAddress.swift
  24. 1 1
      Sources/GRPCHTTP2Core/Internal/ProcessUniqueID.swift
  25. 1 1
      Sources/GRPCHTTP2Core/Internal/Timer.swift
  26. 1 1
      Sources/GRPCHTTP2Core/OneOrManyQueue.swift
  27. 1 1
      Sources/GRPCHTTP2Core/Server/Connection/GRPCServerFlushNotificationHandler.swift
  28. 2 2
      Sources/GRPCHTTP2Core/Server/Connection/ServerConnection.swift
  29. 2 2
      Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler+StateMachine.swift
  30. 2 2
      Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler.swift
  31. 3 3
      Sources/GRPCHTTP2Core/Server/GRPCServerStreamHandler.swift
  32. 2 2
      Sources/GRPCHTTP2Core/Server/HTTP2ServerTransport.swift
  33. 4 4
      Sources/GRPCHTTP2TransportNIOPosix/HTTP2ClientTransport+Posix.swift
  34. 6 6
      Sources/GRPCHTTP2TransportNIOPosix/HTTP2ServerTransport+Posix.swift
  35. 4 4
      Sources/GRPCHTTP2TransportNIOPosix/NIOClientBootstrap+SocketAddress.swift
  36. 7 6
      Sources/GRPCHTTP2TransportNIOTransportServices/HTTP2ServerTransport+TransportServices.swift

+ 2 - 2
Sources/GRPCHTTP2Core/Client/Connection/ClientConnectionHandler.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import NIOCore
-import NIOHTTP2
+package import NIOCore
+package import NIOHTTP2
 
 /// An event which happens on a client's HTTP/2 connection.
 package enum ClientConnectionEvent: Sendable {

+ 4 - 4
Sources/GRPCHTTP2Core/Client/Connection/Connection.swift

@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOConcurrencyHelpers
-import NIOCore
-import NIOHTTP2
+package import GRPCCore
+internal import NIOConcurrencyHelpers
+package import NIOCore
+package import NIOHTTP2
 
 /// A `Connection` provides communication to a single remote peer.
 ///

+ 3 - 3
Sources/GRPCHTTP2Core/Client/Connection/ConnectionFactory.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import NIOCore
-import NIOHTTP2
-import NIOPosix
+package import NIOCore
+package import NIOHTTP2
+internal import NIOPosix
 
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
 package protocol HTTP2Connector: Sendable {

+ 3 - 3
Sources/GRPCHTTP2Core/Client/Connection/GRPCChannel.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import Atomics
-import DequeModule
-import GRPCCore
+internal import Atomics
+internal import DequeModule
+package import GRPCCore
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 package struct GRPCChannel: ClientTransport {

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/PickFirstLoadBalancer.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+package import GRPCCore
 
 /// A load-balancer which has a single subchannel.
 ///

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/RoundRobinLoadBalancer.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+package import GRPCCore
 
 /// A load-balancer which maintains to a set of subchannels and uses round-robin to pick a
 /// subchannel when picking a subchannel to use.

+ 2 - 2
Sources/GRPCHTTP2Core/Client/Connection/LoadBalancers/Subchannel.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOConcurrencyHelpers
+package import GRPCCore
+internal import NIOConcurrencyHelpers
 
 /// A ``Subchannel`` provides communication to a single ``Endpoint``.
 ///

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Connection/RequestQueue.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import DequeModule
+internal import DequeModule
 
 @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
 struct RequestQueue {

+ 3 - 3
Sources/GRPCHTTP2Core/Client/GRPCClientStreamHandler.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
-import NIOHTTP2
+internal import GRPCCore
+internal import NIOCore
+internal import NIOHTTP2
 
 @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
 final class GRPCClientStreamHandler: ChannelDuplexHandler {

+ 1 - 1
Sources/GRPCHTTP2Core/Client/HTTP2ClientTransport.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+public import GRPCCore
 
 /// A namespace for the HTTP/2 client transport.
 public enum HTTP2ClientTransport {}

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv4.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 extension ResolvableTargets {
   /// A resolvable target for IPv4 addresses.

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+IPv6.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 extension ResolvableTargets {
   /// A resolvable target for IPv4 addresses.

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+UDS.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 extension ResolvableTargets {
   /// A resolvable target for Unix Domain Socket address.

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver+VSOCK.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 extension ResolvableTargets {
   /// A resolvable target for Virtual Socket addresses.

+ 1 - 1
Sources/GRPCHTTP2Core/Client/Resolver/NameResolver.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+public import GRPCCore
 
 /// A name resolver can provide resolved addresses and service configuration values over time.
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)

+ 1 - 1
Sources/GRPCHTTP2Core/Compression/CompressionAlgorithm.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 extension CompressionAlgorithm {
   init?(name: String) {

+ 3 - 3
Sources/GRPCHTTP2Core/Compression/Zlib.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import CGRPCZlib
-import GRPCCore
-import NIOCore
+internal import CGRPCZlib
+internal import GRPCCore
+internal import NIOCore
 
 enum Zlib {
   enum Method {

+ 2 - 2
Sources/GRPCHTTP2Core/GRPCMessageDecoder.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
+internal import GRPCCore
+package import NIOCore
 
 /// A ``GRPCMessageDecoder`` helps with the deframing of gRPC data frames:
 /// - It reads the frame's metadata to know whether the message payload is compressed or not, and its length

+ 2 - 2
Sources/GRPCHTTP2Core/GRPCMessageFramer.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
+internal import GRPCCore
+internal import NIOCore
 
 /// A ``GRPCMessageFramer`` helps with the framing of gRPC data frames:
 /// - It prepends data with the required metadata (compression flag and message length).

+ 4 - 4
Sources/GRPCHTTP2Core/GRPCStreamStateMachine.swift

@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
-import NIOHPACK
-import NIOHTTP1
+internal import GRPCCore
+internal import NIOCore
+internal import NIOHPACK
+internal import NIOHTTP1
 
 package enum Scheme: String {
   case http

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/ConstantAsyncSequence.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import GRPCCore
+internal import GRPCCore
 
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
 private struct ConstantAsyncSequence<Element: Sendable>: AsyncSequence, Sendable {

+ 4 - 4
Sources/GRPCHTTP2Core/Internal/NIOChannelPipeline+GRPC.swift

@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
-import NIOHPACK
-import NIOHTTP2
+package import GRPCCore
+package import NIOCore
+internal import NIOHPACK
+package import NIOHTTP2
 
 @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
 extension ChannelPipeline.SynchronousOperations {

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/NIOSocketAddress+GRPCSocketAddress.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import NIOCore
+package import NIOCore
 
 extension GRPCHTTP2Core.SocketAddress {
   package init(_ nioSocketAddress: NIOCore.SocketAddress) {

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/ProcessUniqueID.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import Atomics
+internal import Atomics
 
 /// An ID which is unique within this process.
 struct ProcessUniqueID: Hashable, Sendable, CustomStringConvertible {

+ 1 - 1
Sources/GRPCHTTP2Core/Internal/Timer.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import NIOCore
+package import NIOCore
 
 package struct Timer {
   /// The delay to wait before running the task.

+ 1 - 1
Sources/GRPCHTTP2Core/OneOrManyQueue.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import DequeModule
+internal import DequeModule
 
 /// A FIFO-queue which allows for a single element to be stored on the stack and defers to a
 /// heap-implementation if further elements are added.

+ 1 - 1
Sources/GRPCHTTP2Core/Server/Connection/GRPCServerFlushNotificationHandler.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-import NIOCore
+internal import NIOCore
 
 @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
 final class GRPCServerFlushNotificationHandler: ChannelOutboundHandler {

+ 2 - 2
Sources/GRPCHTTP2Core/Server/Connection/ServerConnection.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
+package import GRPCCore
+package import NIOCore
 
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
 public enum ServerConnection {

+ 2 - 2
Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler+StateMachine.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import NIOCore
-import NIOHTTP2
+internal import NIOCore
+internal import NIOHTTP2
 
 extension ServerConnectionManagementHandler {
   /// Tracks the state of TCP connections at the server.

+ 2 - 2
Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import NIOCore
-import NIOHTTP2
+internal import NIOCore
+internal import NIOHTTP2
 
 /// A `ChannelHandler` which manages the lifecycle of a gRPC connection over HTTP/2.
 ///

+ 3 - 3
Sources/GRPCHTTP2Core/Server/GRPCServerStreamHandler.swift

@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOCore
-import NIOHTTP2
+package import GRPCCore
+package import NIOCore
+package import NIOHTTP2
 
 @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
 package final class GRPCServerStreamHandler: ChannelDuplexHandler, RemovableChannelHandler {

+ 2 - 2
Sources/GRPCHTTP2Core/Server/HTTP2ServerTransport.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import NIOHTTP2
+public import GRPCCore
+internal import NIOHTTP2
 
 /// A namespace for the HTTP/2 server transport.
 public enum HTTP2ServerTransport {}

+ 4 - 4
Sources/GRPCHTTP2TransportNIOPosix/HTTP2ClientTransport+Posix.swift

@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import GRPCHTTP2Core
-import NIOCore
-import NIOPosix
+public import GRPCCore
+public import GRPCHTTP2Core  // should be @usableFromInline
+public import NIOCore
+public import NIOPosix  // has to be public because of default argument value in init
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 extension HTTP2ClientTransport {

+ 6 - 6
Sources/GRPCHTTP2TransportNIOPosix/HTTP2ServerTransport+Posix.swift

@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import GRPCHTTP2Core
-import NIOCore
-import NIOExtras
-import NIOHTTP2
-import NIOPosix
+public import GRPCCore
+public import GRPCHTTP2Core
+internal import NIOCore
+internal import NIOExtras
+internal import NIOHTTP2
+public import NIOPosix  // has to be public because of default argument value in init
 
 extension HTTP2ServerTransport {
   /// A NIOPosix-backed implementation of a server transport.

+ 4 - 4
Sources/GRPCHTTP2TransportNIOPosix/NIOClientBootstrap+SocketAddress.swift

@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
-import GRPCCore
-import GRPCHTTP2Core
-import NIOCore
-import NIOPosix
+internal import GRPCCore
+internal import GRPCHTTP2Core
+internal import NIOCore
+internal import NIOPosix
 
 extension ClientBootstrap {
   @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)

+ 7 - 6
Sources/GRPCHTTP2TransportNIOTransportServices/HTTP2ServerTransport+TransportServices.swift

@@ -15,12 +15,13 @@
  */
 
 #if canImport(Network)
-import GRPCCore
-import GRPCHTTP2Core
-import NIOCore
-import NIOExtras
-import NIOHTTP2
-import NIOTransportServices
+public import GRPCCore
+public import NIOTransportServices  // has to be public because of default argument value in init
+public import GRPCHTTP2Core
+
+internal import NIOCore
+internal import NIOExtras
+internal import NIOHTTP2
 
 extension HTTP2ServerTransport {
   /// A NIO Transport Services-backed implementation of a server transport.