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

"Broken MIR" ICE when using runtime crate #61731

Closed
msizanoen opened this issue Jun 11, 2019 · 6 comments · Fixed by #61872
Closed

"Broken MIR" ICE when using runtime crate #61731

msizanoen opened this issue Jun 11, 2019 · 6 comments · Fixed by #61872
Assignees
Labels
A-async-await Area: Async & Await A-coroutines Area: Coroutines A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html AsyncAwait-Polish Async-await issues that are part of the "polish" area C-bug Category: This is a bug. 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

@msizanoen
Copy link

Fail-to-compile code:

#![feature(async_await)]

use futures::prelude::*;
use runtime::net::TcpListener;
use std::io;

#[runtime::main]
async fn main() -> io::Result<()> {
    let mut listener = TcpListener::bind("127.0.0.1:12345")?;
    let mut incoming = listener.incoming();
    while let Some(stream) = incoming.next().await {
        runtime::spawn(async move {
            let stream = stream?;
            let (mut rd, mut wr) = stream.split();
            rd.copy_into(&mut wr).await?;
            Ok::<_, std::io::Error>(())
        });
    }

    Ok(())
}

Error message:

   Compiling rtecho v0.1.0 (/home/sirius/rtecho)
error: internal compiler error: src/librustc_mir/transform/generator.rs:540: Broken MIR: generator contains type runtime::task::JoinHandle<std::result::Result<(), std::io::Error>> in MIR, but typeck only knows about for<'r, 's, 't0> {runtime::net::tcp::TcpListener, runtime::net::tcp::Incoming<'r>, futures_util::stream::next::Next<'s, runtime::net::tcp::Incoming<'t0>>, ()}
 --> src/main.rs:7:1
  |
7 | #[runtime::main]
  | ^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:572:9
stack backtrace:
   0: 0xb571f638 - backtrace::backtrace::libunwind::trace::h2d31d29820972887
                       at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: 0xb571f638 - backtrace::backtrace::trace_unsynchronized::h9ca3ecbe3c54ada5
                       at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: 0xb571f638 - std::sys_common::backtrace::_print::hb41a9429afcb2ffa
                       at src/libstd/sys_common/backtrace.rs:47
   3: 0xb571f638 - std::sys_common::backtrace::print::hcaa481e2ae622640
                       at src/libstd/sys_common/backtrace.rs:36
   4: 0xb571f638 - std::panicking::default_hook::{{closure}}::h2af0ce3430227ffd
                       at src/libstd/panicking.rs:198
   5: 0xb571f244 - std::panicking::default_hook::hc047f542655530b6
                       at src/libstd/panicking.rs:212
   6: 0xb475d074 - rustc::util::common::panic_hook::h7347d59a0792e813
   7: 0xb571fddc - std::panicking::rust_panic_with_hook::h07d0f4dd4c8050d6
                       at src/libstd/panicking.rs:479
   8: 0xb519c6a0 - std::panicking::begin_panic::h2c922964066c85f9
   9: 0xb51ea02c - rustc_errors::Handler::span_bug::h2c1c0a8ab667fab8
  10: 0xb4f71378 - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h1500601a36607631
  11: 0xb4f6fb40 - rustc::ty::context::tls::with_opt::{{closure}}::h8aac2f2ae7c9fd12
  12: 0xb4f6fad4 - rustc::ty::context::tls::with_context_opt::h0dcdd93b89d72608
  13: 0xb4f6fb00 - rustc::ty::context::tls::with_opt::hf19eba58424f6994
  14: 0xb4f71288 - rustc::util::bug::opt_span_bug_fmt::hd64cf9a90a48134b
  15: 0xb4f71254 - rustc::util::bug::span_bug_fmt::h96da24e0ca1951e6
  16: 0xb5196d90 - <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass::hec8dbebf6b131272
  17: 0xb4ef2dbc - rustc_mir::transform::run_passes::{{closure}}::hc6795771803246b4
  18: 0xb4ef2a94 - rustc_mir::transform::run_passes::hb7f85c17f2ad6ed4
  19: 0xb4ef3768 - rustc_mir::transform::optimized_mir::hb4c1147cf3c6a714
  20: 0xb46f8a0c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::ha478417c36b9a96b
  21: 0xb42fa008 - rustc::dep_graph::graph::DepGraph::with_task_impl::heb9fba9bb55b1ebc
  22: 0xb45e3720 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hc3c5b89b47d3aa20
  23: 0xb427df38 - rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::h92929fb5f59c11d3
  24: 0xb427c610 - rustc::ty::layout::layout_raw::hc4f829bf7a84bee3
  25: 0xb4377e20 - rustc::ty::query::__query_compute::layout_raw::haaa4b7bfd54b916f
  26: 0xb46f93a0 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute::h912efc661325f36b
  27: 0xb42c26fc - rustc::dep_graph::graph::DepGraph::with_task_impl::h08bc5ac169eb8885
  28: 0xb4583abc - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h683eebb3c25a9f7d
  29: 0xb4285fac - <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::h6fe5b876700cc14c
  30: 0xb47a68b8 - <&mut I as core::iter::traits::iterator::Iterator>::next::he00b2dc4a819971c
  31: 0xb48829e8 - <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter::hae6e8ef7c1bc1857
  32: 0xb4226604 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once::h586d2178388ba51d
  33: 0xb4883ad0 - <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter::hb39bad92b705fc8f
  34: 0xb427ce9c - rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::h92929fb5f59c11d3
  35: 0xb427c610 - rustc::ty::layout::layout_raw::hc4f829bf7a84bee3
  36: 0xb4377e20 - rustc::ty::query::__query_compute::layout_raw::haaa4b7bfd54b916f
  37: 0xb46f93a0 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute::h912efc661325f36b
  38: 0xb42c26fc - rustc::dep_graph::graph::DepGraph::with_task_impl::h08bc5ac169eb8885
  39: 0xb4583abc - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h683eebb3c25a9f7d
  40: 0xb4285fac - <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::h6fe5b876700cc14c
  41: 0xb47a5c74 - <&mut I as core::iter::traits::iterator::Iterator>::next::h80abf7a3121e3e5e
  42: 0xb4861bac - <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter::h05d6962c084de4a0
  43: 0xb4227024 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once::ha22cc4109fa256b1
  44: 0xb47a4b2c - <&mut I as core::iter::traits::iterator::Iterator>::next::h2a270222e2a891ba
  45: 0xb4864c14 - <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter::h13ec37d27edc3501
  46: 0xb427dfb4 - rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::h92929fb5f59c11d3
  47: 0xb427c610 - rustc::ty::layout::layout_raw::hc4f829bf7a84bee3
  48: 0xb4377e20 - rustc::ty::query::__query_compute::layout_raw::haaa4b7bfd54b916f
  49: 0xb46f93a0 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute::h912efc661325f36b
  50: 0xb42c26fc - rustc::dep_graph::graph::DepGraph::with_task_impl::h08bc5ac169eb8885
  51: 0xb4583abc - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h683eebb3c25a9f7d
  52: 0xb4285fac - <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::h6fe5b876700cc14c
  53: 0xb4f4bd7c - <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement::h4ba189d0f6dc4b28
  54: 0xb4f46238 - <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass::h4538fb6fc0235ad9
  55: 0xb4ef2dbc - rustc_mir::transform::run_passes::{{closure}}::hc6795771803246b4
  56: 0xb4ef2a94 - rustc_mir::transform::run_passes::hb7f85c17f2ad6ed4
  57: 0xb4ef3768 - rustc_mir::transform::optimized_mir::hb4c1147cf3c6a714
  58: 0xb46f8a0c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::ha478417c36b9a96b
  59: 0xb42fa008 - rustc::dep_graph::graph::DepGraph::with_task_impl::heb9fba9bb55b1ebc
  60: 0xb45e3720 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hc3c5b89b47d3aa20
  61: 0xb46f6ec0 - rustc::ty::<impl rustc::ty::context::TyCtxt>::instance_mir::h00c0987817843de4
  62: 0xb50d005c - rustc_mir::monomorphize::collector::collect_items_rec::h265dcd4773bf226d
  63: 0xb4f977b0 - rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}::h159ef937882f4ccc
  64: 0xb4f71578 - rustc::util::common::time::hd3e121facb2973e9
  65: 0xb50cf04c - rustc_mir::monomorphize::collector::collect_crate_mono_items::h6916cdd741d72378
  66: 0xb4f716d8 - rustc::util::common::time::he613f5bfbad8e9af
  67: 0xb5128674 - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::hf8d93c82ad4f69fe
  68: 0xae8a8ba4 - rustc::ty::query::__query_compute::collect_and_partition_mono_items::h48322cdde7675cad
  69: 0xae8d1da0 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute::h47a73497b0993177
  70: 0xae877ad8 - rustc::dep_graph::graph::DepGraph::with_task_impl::h728173ffa2354de8
  71: 0xae8f3054 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h3633be2d1d873f29
  72: 0xae974444 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate::he7b69e00b681143d
  73: 0xb549609c - rustc::util::common::time::h3ffe0cff42c88246
  74: 0xb5446c38 - rustc_interface::passes::start_codegen::h4929930da55d1f72
  75: 0xb542f120 - rustc::ty::context::tls::enter_global::h1c6e1b52096b5554
  76: 0xb5447370 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h8902cc3e445118fe
  77: 0xb549eaf4 - rustc_interface::passes::create_global_ctxt::{{closure}}::hb8061a2e0a037d21
  78: 0xb5446058 - rustc_interface::passes::BoxedGlobalCtxt::enter::ha8a4bcdb5d2f590e
  79: 0xb5432358 - rustc_interface::queries::Query<T>::compute::h3faf0584888fd7ff
  80: 0xb5510a6c - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen::h9a837d64e2a19dab
  81: 0xb57fc290 - rustc_interface::interface::run_compiler_in_existing_thread_pool::hd45106de8a079b95
  82: 0xb58641d4 - std::thread::local::LocalKey<T>::with::h4a4be7732992048e
  83: 0xb580e960 - scoped_tls::ScopedKey<T>::set::ha8f389698324989a
  84: 0xb5832fec - syntax::with_globals::h288536884bfffbbd
  85: 0xb5851410 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb95161392c0e9f23
  86: 0xb572e2b8 - __rust_maybe_catch_panic
                       at src/libpanic_unwind/lib.rs:85
  87: 0xb57e59f8 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h7095b5af77598ff4
  88: 0xb5703e34 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h951a9152f4cb3a2e
                       at /rustc/02564de47b40e953b5144dfd37450c16a84672f1/src/liballoc/boxed.rs:746
  89: 0xb572d05c - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::he7a53fc66a9b3bba
                       at /rustc/02564de47b40e953b5144dfd37450c16a84672f1/src/liballoc/boxed.rs:746
  90: 0xb572d05c - std::sys_common::thread::start_thread::hf1bbbc97dcb37476
                       at src/libstd/sys_common/thread.rs:13
  91: 0xb572d05c - std::sys::unix::thread::Thread::new::thread_start::hd4d8de3151a7cbb4
                       at src/libstd/sys/unix/thread.rs:79
query stack during panic:
#0 [optimized_mir] processing `main::main::{{closure}}#0`
#1 [layout_raw] computing layout of `[static generator@src/main.rs:7:1: 7:17 for<'r, 's, 't0> {runtime::net::tcp::TcpListener, runtime::net::tcp::Incoming<'r>, futures_util::stream::next::Next<'s, runtime::net::tcp::Incoming<'t0>>, ()}]`
#2 [layout_raw] computing layout of `std::future::GenFuture<[static generator@src/main.rs:7:1: 7:17 for<'r, 's, 't0> {runtime::net::tcp::TcpListener, runtime::net::tcp::Incoming<'r>, futures_util::stream::next::Next<'s, runtime::net::tcp::Incoming<'t0>>, ()}]>`
#3 [layout_raw] computing layout of `[static generator@src/main.rs:7:1: 7:17 {std::future::GenFuture<[static generator@src/main.rs:7:1: 7:17 for<'r, 's, 't0> {runtime::net::tcp::TcpListener, runtime::net::tcp::Incoming<'r>, futures_util::stream::next::Next<'s, runtime::net::tcp::Incoming<'t0>>, ()}]>, ()}]`
#4 [optimized_mir] processing `main`
#5 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
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 (02564de47 2019-06-10) running on armv7-unknown-linux-gnueabihf

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 `rtecho`.

To learn more, run the command again with --verbose.

Output of cargo-expand, if useful:

#![feature(prelude_import)]
#![no_std]
#![feature(async_await)]
#[prelude_import]
use ::std::prelude::v1::*;
#[macro_use]
extern crate std as std;
use futures::prelude::*;
use runtime::net::TcpListener;
use std::io;
fn main() -> io::Result<()> {
    async fn main() -> io::Result<()> {
        {
            let mut listener = TcpListener::bind("127.0.0.1:12345")?;
            let mut incoming = listener.incoming();
            while let Some(stream) = incoming.next().await {
                runtime::spawn(async move {
                    let stream = stream?;
                    let (mut rd, mut wr) = stream.split();
                    rd.copy_into(&mut wr).await?;
                    Ok::<_, std::io::Error>(())
                });
            }
            Ok(())
        }
    }
    runtime::raw::enter(runtime::native::Native, async { main().await })
}
@eddyb
Copy link
Member

eddyb commented Jun 11, 2019

cc @Zoxc @tmandry

@msizanoen
Copy link
Author

There's a workaround:

let _ = runtime::spawn(...);

@msizanoen
Copy link
Author

This looks similar to #61579

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-coroutines Area: Coroutines A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. 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 11, 2019
@Centril Centril added the AsyncAwait-Polish Async-await issues that are part of the "polish" area label Jun 11, 2019
@kpp
Copy link
Contributor

kpp commented Jun 11, 2019

I got the same issue with https://github.com/kpp/futures-async-combinators/ using rustc 1.37.0-nightly (02564de 2019-06-10)

@msizanoen
Copy link
Author

msizanoen commented Jun 13, 2019

Additionally, this works:

drop(runtime::spawn(...));

Also see #61579 (comment)

@tmandry
Copy link
Member

tmandry commented Jun 14, 2019

I bisected this issue, and it appeared in the 2019-06-06 nightly.

I believe it is due to:

  • MIR StorageLive/StorageDead not being generated at all for the JoinHandle returned by runtime::spawn, requiring the MIR generator pass to assume it is always storage-live
  • rustdoc: Automatic light/dark theme #61079, which marks drop as borrowing, along with the fact that the generator transform pass conservatively assumes vars are always live after they've been borrowed

Together, we have both conditions required for the MIR generator pass to think it needs to save our JoinHandle in the generator: it is both storage-live and live across a suspend point. This is the same problem as @Zoxc mentioned in #61579 (comment) and also seems to be the cause of that issue.

bors added a commit that referenced this issue Jun 26, 2019
…sakis

Clean up MIR drop generation

* Don't assign twice to the destination of a `while` loop containing a `break` expression
* Use `as_temp` to evaluate statement expression
* Avoid consecutive `StorageLive`s for the condition of a `while` loop
* Unify `return`, `break` and `continue` handling, and move it to `scopes.rs`
* Make some of the `scopes.rs` internals private
* Don't use `Place`s that are always `Local`s in MIR drop generation

Closes #42371
Closes #61579
Closes #61731
Closes #61834
Closes #61910
Closes #62115
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 A-coroutines Area: Coroutines A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html AsyncAwait-Polish Async-await issues that are part of the "polish" area C-bug Category: This is a bug. 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.

7 participants