-
Notifications
You must be signed in to change notification settings - Fork 626
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
Refactor to reduce the amount of unsafe and duplicated code. #2128
Conversation
62d6656
to
81e2baf
Compare
Rebased to catch up with master. |
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.
This looks really great!
I've reviewed changes in most combinator implementation and public methods.
The following has not been reviewed yet:
- Whether the behavior of the delegated combinator has changed (i.e., removed files + details of fns.rs)
- Changes in trait bounds of the public struct definition and implementations
- Replace uses of `pin_utils` with the safer `pin_project` crate - Implement macros to allow building new combinators from existing ones more easily - Get rid of Chain as the building block for future combinators, and instead build from `Map` and `Flatten` primitives - Delete a lot of code which is no longer necessary.
Fixed an issue with the rebase and created a new commit with the changes as per review. |
if ready!(fut.poll(cx)) { | ||
pending_fut.set(None); |
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.
if ready!(fut.poll(cx)) { | |
pending_fut.set(None); | |
let yield_item = ready!(fut.poll(cx)); | |
pending_fut.set(None); | |
if yield_item { |
I mean "if fut.poll returns Ready", not "if ready!(fut.poll) returns true" (I'm sorry if the comment was hard to understand)
if ready!(fut.poll(cx)) { | ||
pending_fut.set(None); |
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.
if ready!(fut.poll(cx)) { | |
pending_fut.set(None); | |
let yield_item = ready!(fut.poll(cx)); | |
pending_fut.set(None); | |
if yield_item { |
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 noticed that some trivial trait implementations were added by delegate_all macro. I'd prefer to remove these implementations as they may inadvertently become valid when the internal type implementation changes.
Also, similarly, I'd prefer to remove stream/sink implementations on future combinators other than flatten-family and to remove future implementations to stream combinators. These are not intended uses and may prevent change for optimizations in the future.
Hmm... looks like CI says that the behavior of |
Ok, the error is due to the old future is no longer dropped before the closure is run. Specifically, it needs to change the #[project]
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
#[project]
let Map { mut future, f } = self.project();
let fut = future.as_mut().as_pin_mut().expect("Map polled after completion");
let output = ready!(fut.poll(cx));
future.set(None); // Drop the old futures before the closure runs.
let f = f.take().unwrap();
Poll::Ready(f.call_once(output))
} |
@taiki-e Yeah, I spotted that issue on the last CI run. I would like to avoid increasing the size of I had a look at what it would take to implement such a method in |
Eh, I'm being stupid - |
d7dc71b
to
208c281
Compare
@taiki-e I believe I have addressed all the issues and the tests are now passing. I introduced some |
Co-Authored-By: Taiki Endo <te316e89@gmail.com>
Also, this PR adds the following APIs:
I feel |
This is outstanding work! I took a quick read through and I'm really excited to get this in. Thanks for all your hard work, @Diggsey, and for the detailed review, @taiki-e! There is quite a bit of code change here, so I'll do a release later this week to start getting this out to folks and make sure that there isn't any accidental breakage lurking. |
Refactor to reduce the amount of unsafe and duplicated code.
pin_utils
with the saferpin_project
crateeasily
fns
module as a workaround untilimpl Trait
is usable in more places.build from
Map
andFlatten
primitivesThere should not be any breaking changes as I have endeavoured to keep all type signatures exactly the same.