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

Make NIOLoopBoundBox off-EL with sending #3091

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

Conversation

natikgadzhi
Copy link
Contributor

Motivation:

This closes #2754. It's a follow-up for #2753 that adds a way to makeLoopBoundBox by sending a value, leaning into Swift 6 concurrency!

/cc @weissi and @FranzBusch.

Modifications:

  • Adds makeBoxSendingValue. Can't take the credit, @weissi wrote it in the issue.
  • Adds a test for it.

Result:

Nice NIOLoopBoundBox API for Swift 6.

Motivation:

This closes apple#2754. It's a follow-up for apple#2753 that adds a way to `makeLoopBoundBox` by sendin a value,
leaning into Swift 6 concurrency!

Modifications:

- Adds `makeBoxSendingValue`. Can't take the credit, @weissi wrote it in the issue.
- Adds a test for it.

Result:

Nice NIOLoopBoundBox API for Swift 6.
@natikgadzhi natikgadzhi marked this pull request as ready for review January 26, 2025 20:36
@@ -17,7 +17,7 @@
///
/// ``NIOLoopBound`` is useful to transport a value of a non-`Sendable` type that needs to go from one place in
/// your code to another where you (but not the compiler) know is on one and the same ``EventLoop``. Usually this
/// involves `@Sendable` closures. This type is safe because it verifies (using ``EventLoop/preconditionInEventLoop(file:line:)-2fxvb``)
/// involves `@Sendable` or `sending` closures. This type is safe because it verifies (using ``EventLoop/preconditionInEventLoop(file:line:)-2fxvb``)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated, but thought this would be more precise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related: should I add more explicit documentation outlining that there are a bunch of functions to make a NIOLoopBoundBox off the event loop called make*, and outline the use cases for them at a high level? Separate PR?

as: Value.Type = Value.self,
eventLoop: EventLoop
) -> NIOLoopBoundBox<Value> {
// Here, we -- possibly surprisingly -- do not precondition being on the EventLoop. This is okay for a few
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is a copy-pasta from the other off-EL initializers, but I think it's fair to keep this for consistency.

Tests/NIOPosixTests/NIOLoopBoundTests.swift Outdated Show resolved Hide resolved
@@ -75,6 +75,43 @@ final class NIOLoopBoundTests: XCTestCase {
)
}

#if compiler(>=6.0)
class NonSendableThingy {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be an overkill. Also, should I explicitly mark this fileprivate?

Tests/NIOPosixTests/NIOLoopBoundTests.swift Outdated Show resolved Hide resolved
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.

I'm actually a bit nervous about merging this.

We have a number of places where our Sendable constraints can be relaxed to sending, but I don't think we should actually do that yet. Many projects that depend on NIO support multiple Swift versions, just as we do, and it makes life quite a bit harder when doing implementation to have the APIs be different between those Swift versions.

In some cases this is acceptable, but in this instance I'm inclined to suggest we should wait, and do this work when we drop all compilers below 6.0. That would be at the release of Swift 6.2 (presuming no new Swift language versions).

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.

Give NIOLoopBoundBox a sending off-EL initialiser once compiler is ready
2 participants