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 · Fixed by #62155
Closed

ICE compiling with futures compat #61986

SephVelut opened this issue Jun 20, 2019 · 4 comments · Fixed by #62155
Assignees
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SephVelut
Copy link

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)
@Centril Centril added A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2019
@Aaron1011
Copy link
Member

Minimized:

#![feature(async_await)]

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

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

fn main() {
    listen();
}

@Aaron1011
Copy link
Member

Aaron1011 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
Copy link
Member

I believe this will be fixed by #61872

@cramertj
Copy link
Member

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
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
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
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
Add regression test for MIR drop generation in async loops

Fixes rust-lang#61986.

r? @Centril
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants