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

port futures 0.3 to std futures #1034

Merged
merged 9 commits into from
Jun 19, 2018
Merged

port futures 0.3 to std futures #1034

merged 9 commits into from
Jun 19, 2018

Conversation

tinaun
Copy link
Contributor

@tinaun tinaun commented Jun 7, 2018

No description provided.

@tinaun tinaun force-pushed the 0.3 branch 2 times, most recently from 04fbfd5 to d87e9e3 Compare June 8, 2018 04:53
@tinaun tinaun changed the title port 0.3 to std futures [wip] port futures-core 0.3 to std futures Jun 8, 2018
@tinaun
Copy link
Contributor Author

tinaun commented Jun 8, 2018

this won't compile until a nightly with futures in it is built, but i think its ready to be looked at - theres a whole lot of extension traits which im kinda ambivalent about - i could just add more inherent methods in rust-lang/rust#51442 instead

@tinaun tinaun changed the title port futures-core 0.3 to std futures port futures 0.3 to std futures Jun 9, 2018
@tinaun
Copy link
Contributor Author

tinaun commented Jun 9, 2018

i have no idea whats causing those doc errors. a missing path in a link maybe?

@aturon aturon requested a review from cramertj June 11, 2018 15:41
// }
// }
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Contributor Author

@tinaun tinaun Jun 12, 2018

Choose a reason for hiding this comment

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

since either is defined in https://github.com/bluss/either and Future in std it can't exist here because of orphan rules - i might write a pr moving this to the either crate as an unstable feature

Choose a reason for hiding this comment

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

I'd gently suggest removing the commented code, if it is, in fact, going away

fn is_ready(&self) -> bool;
/// Returns whether this is `Poll::Pending`
fn is_pending(&self) -> bool {
!self.is_ready()
Copy link
Contributor

Choose a reason for hiding this comment

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

Your PR to core has been merged rust-lang/rust#51442 These methods are now not required

@@ -63,7 +64,7 @@ macro_rules! unsafe_unpinned {
}

mod poll;
pub use poll::Poll;
pub use poll::{Poll, PollExt, PollResultExt};
Copy link
Contributor

@MajorBreakfast MajorBreakfast Jun 12, 2018

Choose a reason for hiding this comment

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

Also not required because core PR has been merged

@tinaun
Copy link
Contributor Author

tinaun commented Jun 12, 2018

rebased to latest nightly

type Output = F::Output;
impl<T: ?Sized> CoreFutureExt for T where T: Future {}

// should be in std
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed now, right?

fn drop(&mut self) {
unsafe {
(self.drop)(self.ptr)
impl TaskObjExt for TaskObj {
Copy link
Member

Choose a reason for hiding this comment

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

This implements the trait for dyn TaskObj-- did you mean to implement TaskObjExt for T: TaskObj?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't TaskObj a struct that pretends to be a trait object currently?

(self.poll)(self.ptr, cx)
}
/// Extension trait for `TaskObj`, adding methods that require allocation.
pub trait TaskObjExt {
Copy link
Member

@cramertj cramertj Jun 12, 2018

Choose a reason for hiding this comment

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

What's the purpose of this trait? Since the method doesn't take self, it's not actually callable using method syntax, so it might as well be a free function. IMO users should either call TaskObj::from_poll_task directly or call the spawn method on the ContextExt trait.

impl<'a> ContextExt for Context<'a> {
fn spawn<F>(&mut self, f: F) where F: Future<Output = ()> + 'static + Send {
self.executor()
.spawn_obj(TaskObj::new(f)).unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned above, I'd change this to call from_poll_task directly.

@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jun 17, 2018

About reexports: I'm not sure whether we should offer reexports at all. Normally reexports are used for compatibility. However futures 0.3 can't be compatible with 0.2 in any meaningful way because nearly all signatures change a little bit. Therefore should there be reexports at all? I think we shouldn't offer reexports and instead encourage to either import the prelude or import from core directly. What do you think?

@Terkwood
Copy link

Terkwood commented Jun 17, 2018

How hard is it to preserve the re-export capability? It seems useful in the case where one isn't facing a compatibility issue.

@MajorBreakfast
Copy link
Contributor

It seems useful in the case where one isn't facing a compatibility issue.

@Terkwood Please elaborate

The reason I propose to remove the reexports is for consistency. It seems inconsistent to import core::mem::PinMut directly, but not do the same for core::future::Future. And to offer reexports for core::future::Future, but not for core::mem::PinMut.

@Terkwood
Copy link

Just to make sure I'm speaking coherently:

About reexports: I'm not sure whether we should offer reexports at all. Normally reexports are used for compatibility.

You're talking about removing reexports from the language entirely, right? If that's right: I think they're a mildly useful feature (in theory). Coming from a background in other languages, I liked the idea of having this facility available for use in lieu of writing boilerplate wrapper code.

I don't want to express too much enthusiasm for the reexport feature in rust. Futures are a big deal.

Your statement in favor of consistency is good. If the only way that reexports can be kept in the language will involve introducing a confusing inconsistency in their use, then... meh? That's not very appealing, when you put it that way, no.

Thanks for your time and effort!

Copy link

@Terkwood Terkwood left a comment

Choose a reason for hiding this comment

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

Thank you!

// }
// }
// }
// }

Choose a reason for hiding this comment

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

I'd gently suggest removing the commented code, if it is, in fact, going away

/// the `fuse` adaptor which defines the behavior of `poll`, but comes with
/// a little bit of extra cost.
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output>;
pub use core::future::Future;

Choose a reason for hiding this comment

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

🎉

@MajorBreakfast
Copy link
Contributor

You're talking about removing reexports from the language entirely, right?

@Terkwood No no ^^' I merely suggest to remove the reexport statements in futures-core. In other words: Only export the stuff that is actually defined in futures-core (e.g. Stream)

@Terkwood
Copy link

Terkwood commented Jun 17, 2018 via email

@withoutboats
Copy link

The re-export is important for getting futures 0.3 on stable faster. As soon as arbitrary_self_types is stable, the new Future API can be implemented in futures on stable. We can cfg nightly vs stable to re-export or define it here, before the futures_api feature is stable. Then every library written against futures, without depending on std::future::Future directly, will compile on stable.

@MajorBreakfast
Copy link
Contributor

@withoutboats That requires:

  • Not removing the definitions of Future, Executor, etc. from futures-core. Instead, they need to be updated so that they're identical to their counterparts in core.
  • PinMut needs a polyfill/dummy impl

@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jun 19, 2018

It was decided in a quick discussion on the wg-net Discord channel to leave the reexports in, because they give us the possibility to maybe do the "stable shim dance" later

@aturon aturon merged commit 6676c2d into rust-lang:0.3 Jun 19, 2018
@aturon
Copy link
Member

aturon commented Jun 19, 2018

Merged, thanks much @tinaun!

There are a couple of minor things I will clean up in a follow-up PR.

@tinaun tinaun deleted the 0.3 branch June 20, 2018 13:18
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.

6 participants