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

ICE compiling with futures compat #61986

Closed
SephVelut opened this issue Jun 20, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@SephVelut
Copy link

commented Jun 20, 2019

Attempting to shim futures-preview Stream to a tokio futures 0.1 Stream results in ICE when done this way. Most minimal example I can give

#![feature(async_await)]
use std::io;
use futures::StreamExt;
use futures::executor;
use hyper::{Body, Request, Response};
use hyper::service::service_fn_ok;
use romio::TcpListener;
use futures::compat::Compat;

fn req_res(_: Request<Body>) -> Response<Body> {
    Response::new(Body::from(""))
}

async fn listen() -> io::Result<()> {
    let mut listener = TcpListener::bind(&"127.0.0.1:8080".parse().unwrap())?;
    let mut streams = listener.incoming();

    let http = hyper::server::conn::Http::new();
    while let Some(stream) = streams.next().await {
        let stream = stream?;

        let mut compat_stream = Compat::new(stream);
        
        // Comment out = No ICE
        http.serve_connection(compat_stream, service_fn_ok(req_res));
    }

    Ok(())
}

fn main() {
    // Comment out = No ICE
    executor::block_on(listen());
}
[dependencies]
romio = { git = "https://github.com/withoutboats/romio.git" }
futures-preview = { version = "0.3.0-alpha.16", features = ["compat", "io-compat"] }
hyper = "0.12.30"
futures01 = { package = "futures", version = "0.1", optional = true }
error: internal compiler error: src/librustc_mir/transform/generator.rs:715: Broken MIR: generator contains type hyper::server::conn::Connection<futures_util::compat::compat03as01::Compat<romio::tcp::stream::TcpStream>, hyper::service::service::ServiceFnOk<fn(http::request::Request<hyper::body::body::Body>) -> http::response::Response<hyper::body::body::Body> {req_res}, hyper::body::body::Body>> in MIR, but typeck only knows about for<'r, 's, 't0> {romio::tcp::listener::TcpListener, romio::tcp::listener::Incoming<'r>, hyper::server::conn::Http, futures_util::stream::next::Next<'s, romio::tcp::listener::Incoming<'t0>>, ()}
  --> src/main.rs:14:37
   |
14 |   async fn listen() -> io::Result<()> {
   |  _____________________________________^
15 | |     let mut listener = TcpListener::bind(&"127.0.0.1:8080".parse().unwrap())?;
16 | |     let mut streams = listener.incoming();
17 | |
...  |
28 | |     Ok(())
29 | | }
   | |_^

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:578:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.37.0-nightly (04a3dd8a8 2019-06-18) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `myproject`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name websocket_rs src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e69ebbb05677b9bb -C extra-filename=-e69ebbb05677b9bb --out-dir /Users/seph/projects/concepts/ICE/target/debug/deps -C incremental=/Users/seph/projects/concepts/ICE/target/debug/incremental -L dependency=/Users/seph/projects/concepts/ICE/target/debug/deps --extern futures=/Users/seph/projects/concepts/ICE/target/debug/deps/libfutures-29c76c5a0da920d2.rlib --extern hyper=/Users/seph/projects/concepts/ICE/target/debug/deps/libhyper-5f049508aea1fff3.rlib --extern romio=/Users/seph/projects/concepts/ICE/target/debug/deps/libromio-11cb8940271f8e7a.rlib --extern tokio_io=/Users/seph/projects/concepts/ICE/target/debug/deps/libtokio_io-90f842baf63df0eb.rlib` (exit code: 101)
@Aaron1011

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

Minimized:

#![feature(async_await)]

async fn bar() -> Option<()> {
    Some(())
}

async fn listen() {
    while let Some(_) = bar().await {
        String::new();
    }
}

fn main() {
    listen();
}
@Aaron1011

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

The ICE goes away if you assign String::new() (or whatever type you create in the loop body) to a variable. Looking at the generated MIR, it seems that we never emit StorageDead/StorageLive statements for the temporary created by the statement, leading later analysis to incorrectly conclude that it lives across a yield point.

@Aaron1011

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2019

I believe this will be fixed by #61872

@cramertj

This comment has been minimized.

Copy link
Member

commented Jun 26, 2019

This is indeed fixed-- I've opened #62155 with a regression test.

cramertj added a commit to cramertj/rust that referenced this issue Jun 26, 2019

Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019

Rollup merge of rust-lang#62155 - cramertj:61872, r=centril
Add regression test for MIR drop generation in async loops

Fixes rust-lang#61986.

r? @Centril

Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019

Rollup merge of rust-lang#62155 - cramertj:61872, r=centril
Add regression test for MIR drop generation in async loops

Fixes rust-lang#61986.

r? @Centril

Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019

Rollup merge of rust-lang#62155 - cramertj:61872, r=centril
Add regression test for MIR drop generation in async loops

Fixes rust-lang#61986.

r? @Centril

Centril added a commit to Centril/rust that referenced this issue Jun 27, 2019

Rollup merge of rust-lang#62155 - cramertj:61872, r=centril
Add regression test for MIR drop generation in async loops

Fixes rust-lang#61986.

r? @Centril

@bors bors closed this in #62155 Jun 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.