Skip to content

ICE in generator MIR generated by async/await #51995

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

Closed
cramertj opened this issue Jul 2, 2018 · 5 comments
Closed

ICE in generator MIR generated by async/await #51995

cramertj opened this issue Jul 2, 2018 · 5 comments
Labels
A-async-await Area: Async & Await A-coroutines Area: Coroutines

Comments

@cramertj
Copy link
Member

cramertj commented Jul 2, 2018

Attempting to get a minimal repro-- I'll update the issue when I've gotten one.

error: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type std::result::Result<(), futures::channel::mpsc::SendError> in MIR, but typeck only knows about for<'r, 's, 't0, 't1, 't2, 't3, 't4> {fn(std::iter::Rev<std::ops::RangeInclusive<u32>>) -> <std::iter::Rev<std::ops::RangeInclusive<u32>> as std::iter::IntoIterator>::IntoIter {<std::iter::Rev<std::ops::RangeInclusive<u32>> as std::iter::IntoIterator>::into_iter}, fn(u32, u32) -> std::ops::RangeInclusive<u32> {<std::ops::RangeInclusive<Idx>><u32>::new}, u32, std::ops::RangeInclusive<u32>, std::iter::Rev<std::ops::RangeInclusive<u32>>, futures::sink::Send<'r, futures::channel::mpsc::Sender<u32>>, std::mem::PinMut<'s, futures::sink::Send<'t0, futures::channel::mpsc::Sender<u32>>>, for<'t5, 't6> fn(&'t5 mut std::mem::PinMut<'t6, futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>>>) -> futures::Poll<<futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>> as futures::Future>::Output> {std::future::poll_in_task_cx::<futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>>>}, &'t2 mut std::mem::PinMut<'t3, futures::sink::Send<'t4, futures::channel::mpsc::Sender<u32>>>, futures::Poll<std::result::Result<(), futures::channel::mpsc::SendError>>, ()}
   --> futures-channel/tests/mpsc.rs:410:78
    |
410 |   async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
    |  ______________________________________________________________________________^
411 | |     for i in (1..=count).rev() {
412 | |         assert!(await!(sender.send(i)).is_ok());
413 | |     }
414 | | }
    | |_^

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:515
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::span_bug_fmt
  14: <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass
  15: rustc_mir::transform::optimized_mir::{{closure}}
  16: rustc_mir::transform::optimized_mir
  17: rustc::ty::query::__query_compute::optimized_mir
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::optimized_mir<'tcx>>::compute
  19: rustc::ty::context::tls::with_context
  20: rustc::dep_graph::graph::DepGraph::with_task_impl
  21: rustc::ty::context::tls::with_related_context
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_query
  24: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::optimized_mir
  25: rustc_mir::shim::make_shim
  26: rustc::ty::query::__query_compute::mir_shims
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_shims<'tcx>>::compute
  28: rustc::ty::context::tls::with_context
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir
  34: rustc_mir::monomorphize::collector::collect_items_rec
  35: rustc_mir::monomorphize::collector::collect_items_rec
  36: rustc_mir::monomorphize::collector::collect_items_rec
  37: rustc_mir::monomorphize::collector::collect_items_rec
  38: rustc_mir::monomorphize::collector::collect_items_rec
  39: rustc_mir::monomorphize::collector::collect_items_rec
  40: rustc_mir::monomorphize::collector::collect_items_rec
  41: rustc_mir::monomorphize::collector::collect_items_rec
  42: rustc_mir::monomorphize::collector::collect_items_rec
  43: rustc_mir::monomorphize::collector::collect_items_rec
  44: rustc_mir::monomorphize::collector::collect_items_rec
  45: rustc_mir::monomorphize::collector::collect_items_rec
  46: rustc_mir::monomorphize::collector::collect_items_rec
  47: rustc_mir::monomorphize::collector::collect_items_rec
  48: rustc_mir::monomorphize::collector::collect_items_rec
  49: rustc_mir::monomorphize::collector::collect_items_rec
  50: rustc_mir::monomorphize::collector::collect_items_rec
  51: rustc_mir::monomorphize::collector::collect_items_rec
  52: rustc_mir::monomorphize::collector::collect_items_rec
  53: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  54: rustc_mir::monomorphize::collector::collect_crate_mono_items
  55: rustc::util::common::time
  56: rustc_codegen_llvm::base::collect_and_partition_mono_items
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_and_partition_mono_items<'tcx>>::compute
  58: rustc::ty::context::tls::with_context
  59: rustc::dep_graph::graph::DepGraph::with_task_impl
  60: rustc::ty::context::tls::with_related_context
  61: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  62: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  63: rustc_codegen_llvm::base::codegen_crate
  64: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  65: rustc::util::common::time
  66: rustc_driver::driver::phase_4_codegen
  67: rustc_driver::driver::compile_input::{{closure}}
  68: rustc::ty::context::tls::enter_context
  69: <std::thread::local::LocalKey<T>>::with
  70: rustc::ty::context::TyCtxt::create_and_enter
  71: rustc_driver::driver::compile_input
  72: rustc_driver::run_compiler_with_pool
  73: <scoped_tls::ScopedKey<T>>::set
  74: syntax::with_globals
  75: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  76: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  77: rustc_driver::run
  78: rustc_driver::main
  79: std::rt::lang_start::{{closure}}
  80: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  81: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  82: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  83: main
  84: __libc_start_main
  85: <unknown>
query stack during panic:
#0 [optimized_mir] processing `stress_poll_ready_sender::{{closure}}`
#1 [mir_shims] generating MIR shim for `std::intrinsics::drop_in_place`
#2 [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.28.0-nightly (84804c387 2018-06-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental

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

error: Could not compile `futures-channel`.

Prettier:

Broken MIR: generator contains type
std::result::Result<(), futures::channel::mpsc::SendError> in MIR, but typeck only knows about
for<'r, 's, 't0, 't1, 't2, 't3, 't4> {
    fn(std::iter::Rev<std::ops::RangeInclusive<u32>>) -> <std::iter::Rev<std::ops::RangeInclusive<u32>> 
        as std::iter::IntoIterator>::IntoIter {
            <std::iter::Rev<std::ops::RangeInclusive<u32>> as std::iter::IntoIterator>::into_iter
        },
    fn(u32, u32) -> std::ops::RangeInclusive<u32> {
        <std::ops::RangeInclusive<Idx>><u32>::new
    },
    u32,
    std::ops::RangeInclusive<u32>,
    std::iter::Rev<std::ops::RangeInclusive<u32>>,
    futures::sink::Send<'r, futures::channel::mpsc::Sender<u32>>,
    std::mem::PinMut<'s, futures::sink::Send<'t0, futures::channel::mpsc::Sender<u32>>>,
    for<'t5, 't6> fn(
        &'t5 mut std::mem::PinMut<'t6, futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>>>) -> 
            futures::Poll<<futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>> as futures::Future>::Output> {
                std::future::poll_in_task_cx::<futures::sink::Send<'t1, futures::channel::mpsc::Sender<u32>>>
            }, &'t2 mut std::mem::PinMut<'t3, futures::sink::Send<'t4, futures::channel::mpsc::Sender<u32>>>,
            futures::Poll<std::result::Result<(), futures::channel::mpsc::SendError>>, ()
}

cc @Zoxc

@Zoxc Zoxc added the A-coroutines Area: Coroutines label Jul 2, 2018
@Zoxc
Copy link
Contributor

Zoxc commented Jul 2, 2018

Possibly related to #49232

@cramertj
Copy link
Member Author

cramertj commented Jul 2, 2018

Removing the outer assert!(....is_ok()) fixes the issue (just .is_ok() also triggers the ICE, as does assigning the result of the await! expression to a local variable), so it does seem to have something to do with the lifetimes of temporaries.

@DutchGhost
Copy link
Contributor

might also be related to #50878

@MajorBreakfast
Copy link
Contributor

I since added unwrap() after await!(), so that we don't get a warning. Surprisingly it compiles in that case.

https://github.com/rust-lang-nursery/futures-rs/blob/844a9202bf5f40a292dbc54cafe359666678f9f9/futures-channel/tests/mpsc.rs#L409-L415

@nikomatsakis nikomatsakis added the A-async-await Area: Async & Await label Feb 22, 2019
@nikomatsakis
Copy link
Contributor

@cramertj feels like they have not gotten this ICE in a long time. The original code no longer exists or at minimum is awkward to test now. We're going to close for now but maybe we'll see duplicates later on.

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
Projects
None yet
Development

No branches or pull requests

5 participants