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

Compat implementation #1119

Merged
merged 7 commits into from
Aug 2, 2018
Merged

Compat implementation #1119

merged 7 commits into from
Aug 2, 2018

Conversation

tinaun
Copy link
Contributor

@tinaun tinaun commented Jul 25, 2018

based on @MajorBreakfast's approach here rustasync/team#26 (comment)

issues:

impl<Fut, T> Future for NeverError<Fut>
where Fut: Future<Output = T>,
{
type Output = Result<T, ()>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know that Never was introduced only in 0.2 when I proposed the name NeverError. I think we should come up with another name for this type. Maybe UnitError?

That said, I continue to believe that this combinator is useful. .map(|x| Ok::<_, ()>(x)) would be damn annoying to type.

type Output = Result<T, ()>;

fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Result<T, ()>> {
match self.future().poll(cx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

self.future().poll(cx).map(|x| Ok(x)) is shorter :)

Copy link
Member

Choose a reason for hiding this comment

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

Or even .map(Ok) 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

@Nemo157 Yeah ^^'
@tinaun I just noticed something funny: You added the Poll::map method to libcore yourself 😁

@@ -83,6 +86,8 @@ if_std! {

mod shared;
pub use self::shared::Shared;

use std::boxed::PinBox;
Copy link
Contributor

Choose a reason for hiding this comment

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

Best placed right underneath if_std! {. We usually have the imports on top


pub trait ExecCompat: Executor01<
Compat<FutureObj<'static, ()>, BoxedExecutor>
> + Clone + Send + 'static
Copy link
Contributor

@MajorBreakfast MajorBreakfast Jul 25, 2018

Choose a reason for hiding this comment

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

pub trait ExecCompat: Executor01<Fut> + Clone + Send + 'static
where Fut: Compat<FutureObj<'static, ()>, BoxedExecutor>
{

The multiline <...> reminds me of C++ xD

Edit: Meh we would need to create this type param... Ignore that then (I tested it, but it compiled because this file was never mentioned in a mod statement)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename the trait to Executor01CompatExt?

}

#[derive(Clone)]
pub struct ExecutorCompat<E> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to CompatExecutor

impl<E> Executor03 for ExecutorCompat<E>
where E: Executor01<
Compat<FutureObj<'static, ()>, Box<Executor03>>
>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Fits on single line (or if you prefer to split it use a type param)

@@ -29,6 +30,7 @@ futures-io-preview = { path = "../futures-io", version = "0.3.0-alpha.1", defaul
futures-sink-preview = { path = "../futures-sink", version = "0.3.0-alpha.1", default-features = false}
either = { version = "1.4", default-features = false }
slab = { version = "0.4", optional = true }
futures = { version = "0.1", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

I’m surprised this plus the dev-dependency below don’t cause issues for the tests (both have a lib name of futures). Again here’s a place where having crate renaming for the edition would be super useful to make this futures01 or something.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, it does:

→ cargo test --features compat --manifest-path futures-util/Cargo.toml
 Downloading futures v0.1.23
   Compiling futures v0.1.23
   Compiling futures-util-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures-util)
   Compiling futures-executor-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures-executor)
   Compiling futures-preview v0.3.0-alpha.1 (file:///home/wim/sources/github.com/Nemo157/futures-rs/futures)
    Finished dev [unoptimized + debuginfo] target(s) in 13.43s
     Running target/debug/deps/futures_util-0b0ee17c1f6f37a3

running 1 test
test sink::fanout::tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests futures_util
error[E0465]: multiple rlib candidates for `futures` found
 --> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
  |
6 | use futures::Future as Future01;
  |     ^^^^^^^
  |
note: candidate #1: /home/wim/sources/github.com/Nemo157/futures-rs/target/debug/deps/libfutures-e0fcc61a6ffa167e.rlib
 --> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
  |
6 | use futures::Future as Future01;
  |     ^^^^^^^
note: candidate #2: /home/wim/sources/github.com/Nemo157/futures-rs/target/debug/deps/libfutures-6ebec9b92185abd2.rlib
 --> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
  |
6 | use futures::Future as Future01;
  |     ^^^^^^^

error[E0463]: can't find crate for `futures`
 --> /home/wim/sources/github.com/Nemo157/futures-rs/futures-util/src/compat/mod.rs:6:5
  |
6 | use futures::Future as Future01;
  |     ^^^^^^^ can't find crate

And unfortunately renaming dependencies has issues that block it being used for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should convene the council of elders

One temporary solution could be to fully rename our libraries to futures-preview. Long term though, we'll need crate renaming because both crates will share a name in the end.

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 we get away with moving Compat into its own futures-compat sub crate?

Copy link
Member

Choose a reason for hiding this comment

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

I think that'll work for now, since it doesn't need to import the 0.3 futures facade it won't run into the name conflict. Once renaming is working then it could be merged back into futures-util.

Copy link
Member

@Nemo157 Nemo157 Jul 25, 2018

Choose a reason for hiding this comment

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

Alright, testing with a locally built cargo including rust-lang/cargo#5794 using futures01 = { version = "0.1", optional = true, package = "futures" } (and adjusting all the uses) appears to run the tests fine. (EDIT: here's the commit I tested with)

So, if you're willing to wait for a new cargo to be released to nightly that's one option.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Nemo157 How long do you think will this take? If it's just a day or two, then we should wait. @tinaun requires some time to tweak this PR anyway

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what the Cargo release cycle is like, my current nightly toolchain has rustc from 2018-07-23 but cargo from 2018-07-17, so I don't think it's always the latest master.

Copy link
Contributor Author

@tinaun tinaun Jul 25, 2018

Choose a reason for hiding this comment

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

this pr requires a new nightly anyway for the Executor stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tinaun Wouldn't the newtype approach be more lightweight?

>,
E: Clone + Send + 'static,
{
fn spawn_obj(&mut self, obj: FutureObj<'static, ()>) -> Result<(), task::SpawnObjError> {
Copy link
Contributor

@MajorBreakfast MajorBreakfast Jul 25, 2018

Choose a reason for hiding this comment

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

Long line

fn spawn_obj(
    &mut self,
    future: FutureObj<'static, ()>,
) -> Result<(), task::SpawnObjError> {

Note: Trailing comma, renamed obj to future (This is the thing that I and Aaron want to call future, currently it is called "task")


use core::mem::PinMut;
use core::marker::Unpin;
use std::sync::Arc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use std instead of core (we do that elsewhere as well)

use core::mem::PinMut;
use core::marker::Unpin;
use std::sync::Arc;

Copy link
Contributor

Choose a reason for hiding this comment

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

mod executor;
pub use self::executor::*;

(But list individual exports instead of *)

@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jul 25, 2018

@tinaun Brilliant work!

ATM it doesn't compile because the mod executor statement was missing. I'll comment more later once you've fixed that. (Doesn't make sense to fix it myself if you do it anyway 🙂)

  • Add to all 01 imports the suffix 01 and no suffix for 03. Or, alternatively (if you prefer) add suffixes to everything. Currently it's a bit mixed.
  • Try if extern crate futures as futures01 in lib.rs can be used for referring to the futures 0.1 crate as futures01 in use statements

@Nemo157
Copy link
Member

Nemo157 commented Jul 25, 2018

@tinaun are you planning on working on adaptors for Stream, Sink, or the io traits as well? If not I can build off this for some of those.

@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jul 25, 2018

where should 0.1 -> 0.3 combinators live?

@tinaun I think your approach to pack everything related to compatibility into futures_util::compat is the right solution.

Additionally to the stuff you mentioned above, futures-preview, our facade, needs to reexport everything if the feature is enabled

@Nemo157
Copy link
Member

Nemo157 commented Jul 25, 2018

Since I need them for a project I want to use as a test case for this I've got Stream and (uni-directional) Sink compat implementations ready. Once the executor stuff is sorted I'll hopefully have a small ported project to show. (Although, it's really not the nicest codebase to start with).

@tinaun
Copy link
Contributor Author

tinaun commented Jul 26, 2018

besides the NeverError bikeshed and the cargo renamings this should be about done

@MajorBreakfast MajorBreakfast mentioned this pull request Jul 30, 2018
@tinaun tinaun force-pushed the compat branch 2 times, most recently from 0b78491 to 8bdff6b Compare August 1, 2018 04:34
@Nemo157
Copy link
Member

Nemo157 commented Aug 2, 2018

IMO the cargo renaming can wait. This compiles and works currently, we just can’t run the tests with the feature active until renaming is supported.

@MajorBreakfast
Copy link
Contributor

I'm going to merge this now. We still need need to document it (I think cargo doc ignores it ATM) and add some further polish. However that can be done in follow-up PRs :)

Big thanks to @tinaun !

@Nemo157
Copy link
Member

Nemo157 commented Aug 2, 2018

Guess that means I should get onto doing the rebase of my changes I'd planned 😄

let fut = exec_err.into_future().into_inner().unwrap_or_else(|_| ());
SpawnObjError {
kind: SpawnErrorKind::shutdown(),
task: Box::new(fut).into(),
Copy link
Member

Choose a reason for hiding this comment

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

This field is now future.

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.

3 participants