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

Add ChannelPipeline.SynchronousOperations.Position #3065

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

0xTim
Copy link
Contributor

@0xTim 0xTim commented Jan 16, 2025

Adds a new ChannelPipeline.SynchronousOperations.Position type to fill a hole in the API that prevented non-sendable Channel handlers being added at a position to the pipeline via the synchronous operations.

@0xTim
Copy link
Contributor Author

0xTim commented Jan 16, 2025

@Lukasa I've updated the existing public APIs to use the new type to avoid confusing the compiler since the APIs are not usable in their current form. It you'd prefer all the existing APIs to be deprecated and add @_disfavoredOverload instead I can do that

@Lukasa
Copy link
Contributor

Lukasa commented Jan 17, 2025

Thanks Tim. Yeah, can we use overloads and @_disfavoredOverload? I think it would also be enough to deprecate the old APIs: you can easily test that by omitting the disfavored overload keyword and confirming everything still compiles without warnings.

@0xTim
Copy link
Contributor Author

0xTim commented Jan 17, 2025

Updated - I was getting compiler errors due to "ambiguous references..." without the disfavoured overloads so added them in

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I've left a few notes in the diff.

@@ -175,11 +175,12 @@ public final class ChannelPipeline: ChannelInvoker {
) -> EventLoopFuture<Void> {
let future: EventLoopFuture<Void>

let syncPosition = ChannelPipeline.SynchronousOperations.Position(position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion isn't right: we can't create the synchronous position object until we're on the loop.

extension ChannelPipeline.SynchronousOperations {
/// A `Position` within the `ChannelPipeline`'s `SynchronousOperations` used to insert non-sendable handlers
/// into the `ChannelPipeline` at a certain position.
@preconcurrency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a preconcurrency annotation here, we should get this right the first time.

/// A `Position` within the `ChannelPipeline`'s `SynchronousOperations` used to insert non-sendable handlers
/// into the `ChannelPipeline` at a certain position.
@preconcurrency
public enum Position {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mark this type explicitly non-Sendable

/// After the given `ChannelHandler`.
case after(ChannelHandler)

package init(_ position: ChannelPipeline.Position) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really see any reason to not make this public: we may need this conversion logic in other places.

@@ -83,10 +83,11 @@ extension ChannelPipeline {
) -> EventLoopFuture<Void> {
let future: EventLoopFuture<Void>

let syncPosition = ChannelPipeline.SynchronousOperations.Position(position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be created on the EL.

@@ -126,10 +127,11 @@ extension ChannelPipeline {
) -> EventLoopFuture<Void> {
let future: EventLoopFuture<Void>

let syncPosition = ChannelPipeline.SynchronousOperations.Position(position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be created on the EL.

@@ -173,10 +175,11 @@ extension ChannelPipeline {
) -> EventLoopFuture<Void> {
let future: EventLoopFuture<Void>

let syncPosition = ChannelPipeline.SynchronousOperations.Position(position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be created on the EL.

@@ -342,10 +345,11 @@ extension ChannelPipeline {
) -> EventLoopFuture<Void> {
let future: EventLoopFuture<Void>

let syncPosition = ChannelPipeline.SynchronousOperations.Position(position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be created on the EL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants