-
Notifications
You must be signed in to change notification settings - Fork 651
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
Enforce Sendability in EventLoopFuture
and EventLoopPromise
methods
#2501
base: main
Are you sure you want to change the base?
Conversation
} | ||
return next.futureResult | ||
public func flatMapWithEventLoop<NewValue: Sendable>(_ callback: @escaping @Sendable (Value, EventLoop) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue> { | ||
// Is this the same thing and still fast? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this one. Probably the previous implementation was faster but I wasn't really sure here
# Motivation With apple#2496 we fixed a Sendability checking hole by removing the unconditional conformance of `EventLoopFuture/Promise` to `Sendable`. This was the correct thing to do; however, it has the fallout that a couple of methods are now rightly complaining that their values are send across isolation domains. # Modification This PR requires values on some `ELF/P` methods to be `Sendable` when we might potentially transfer the values across isolation domains/ELs. We have to be overly aggressive here because we do not know that some `ELF` method are staying on the same EL. For example `flatMap` gets a new `ELF` from the closure provided to it. If the `ELF` is on the same EL we do not need to hop; however, we can not guarantee this right now from a type level so we have to stay on the safe side and actually require the `NewValue` to be `Sendable`. # Result This PR makes us more correct from a Sendability perspective but produces warnings for some safe patterns that are currently in use.
05ec0a9
to
9d9ac1c
Compare
let eventLoop = self.eventLoop | ||
return self.flatMap { | ||
callback($0, eventLoop) | ||
}.hop(to: self.eventLoop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can delete the .hop(to:)
. self.flatMap
will return a future on self.eventLoop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the previous implementation probably also allocates less, depends on the optimiser a bit. Why not just revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Well this method became a lot easier then :D
Motivation
With #2496 we fixed a Sendability checking hole by removing the unconditional conformance of
EventLoopFuture/Promise
toSendable
. This was the correct thing to do; however, it has the fallout that a couple of methods are now rightly complaining that their values are send across isolation domains.Modification
This PR requires values on some
ELF/P
methods to beSendable
when we might potentially transfer the values across isolation domains/ELs. We have to be overly aggressive here because we do not know that someELF
method are staying on the same EL. For exampleflatMap
gets a newELF
from the closure provided to it. If theELF
is on the same EL we do not need to hop; however, we can not guarantee this right now from a type level so we have to stay on the safe side and actually require theNewValue
to beSendable
.Result
This PR makes us more correct from a Sendability perspective but produces warnings for some safe patterns that are currently in use.