apple / swift-nio-http2

HTTP/2 support for SwiftNIO
https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2
Apache License 2.0
462 stars 82 forks source link

Sendability warnings #417

Closed rnro closed 10 months ago

rnro commented 1 year ago

Motivation:

To address warnings revealed with .enableExperimentalFeature("StrictConcurrency=complete"), in Swift 5.8

Modifications:

Result:

Better thread safety

rnro commented 1 year ago

I squashed all of the reviewed changes into one commit and merged the changes from main into this branch to try and highlight any new changes.

rnro commented 10 months ago

I believe that the discovered API breakages are okay, just to expand on that. Add sendable requirement to generic parameters:

  💔 API breakage: struct NIOHTTP2Handler.AsyncStreamMultiplexer has generic signature change from <InboundStreamOutput> to <InboundStreamOutput where InboundStreamOutput : Swift.Sendable>
  💔 API breakage: accessor NIOHTTP2Handler.AsyncStreamMultiplexer.inbound.Get() has generic signature change from <InboundStreamOutput> to <InboundStreamOutput where InboundStreamOutput : Swift.Sendable>
  💔 API breakage: func NIOHTTP2Handler.AsyncStreamMultiplexer.openStream(_:) has generic signature change from <InboundStreamOutput, Output where Output : Swift.Sendable> to <InboundStreamOutput, Output where InboundStreamOutput : Swift.Sendable, Output : Swift.Sendable>
  💔 API breakage: struct NIOHTTP2AsyncSequence has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: struct NIOHTTP2AsyncSequence.AsyncIterator has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: typealias NIOHTTP2AsyncSequence.AsyncIterator.Element has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: func NIOHTTP2AsyncSequence.AsyncIterator.next() has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: typealias NIOHTTP2AsyncSequence.Element has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: func NIOHTTP2AsyncSequence.makeAsyncIterator() has generic signature change from <Output> to <Output where Output : Swift.Sendable>
  💔 API breakage: protocol NIOHTTP2StreamDelegate has generic signature change from  to <Self : Swift.Sendable>

Add sendable requirement:

  💔 API breakage: protocol NIOHTTP2StreamDelegate has added inherited protocol Sendable

Change from explicit closure type to equivalent type alias:

  💔 API breakage: constructor HTTP2StreamMultiplexer.init(mode:channel:targetWindowSize:inboundStreamStateInitializer:) has parameter 3 type change from ((NIOCore.Channel, NIOHTTP2.HTTP2StreamID) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializerWithStreamID?
  💔 API breakage: constructor HTTP2StreamMultiplexer.init(mode:channel:targetWindowSize:outboundBufferSizeHighWatermark:outboundBufferSizeLowWatermark:inboundStreamStateInitializer:) has parameter 5 type change from ((NIOCore.Channel, NIOHTTP2.HTTP2StreamID) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializerWithStreamID?
  💔 API breakage: func Channel.configureHTTP2Pipeline(mode:initialLocalSettings:position:inboundStreamStateInitializer:) has parameter 3 type change from ((NIOCore.Channel, NIOHTTP2.HTTP2StreamID) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializerWithStreamID?
  💔 API breakage: func Channel.configureHTTP2Pipeline(mode:initialLocalSettings:position:targetWindowSize:inboundStreamStateInitializer:) has parameter 4 type change from ((NIOCore.Channel, NIOHTTP2.HTTP2StreamID) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializerWithStreamID?

Change from explicit closure type to equivalent type alias:

  💔 API breakage: constructor HTTP2StreamMultiplexer.init(mode:channel:targetWindowSize:outboundBufferSizeHighWatermark:outboundBufferSizeLowWatermark:inboundStreamInitializer:) has parameter 5 type change from ((NIOCore.Channel) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializer?
  💔 API breakage: func Channel.configureHTTP2Pipeline(mode:initialLocalSettings:position:targetWindowSize:inboundStreamInitializer:) has parameter 4 type change from ((NIOCore.Channel) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializer?
  💔 API breakage: func Channel.configureCommonHTTPServerPipeline(h2ConnectionChannelConfigurator:_:) has parameter 0 type change from ((NIOCore.Channel) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializer?
  💔 API breakage: func Channel.configureCommonHTTPServerPipeline(h2ConnectionChannelConfigurator:targetWindowSize:_:) has parameter 0 type change from ((NIOCore.Channel) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializer?
  💔 API breakage: func Channel.configureCommonHTTPServerPipeline(connectionConfiguration:streamConfiguration:streamDelegate:h2ConnectionChannelConfigurator:configurator:) has parameter 3 type change from ((NIOCore.Channel) -> NIOCore.EventLoopFuture<Swift.Void>)? to NIOHTTP2.NIOChannelInitializer?