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: generator contains type impl std::future::Future in MIR, but typeck only knows about {impl std::future::Future, ()} #61834

Closed
KamilaBorowska opened this issue Jun 14, 2019 · 5 comments · Fixed by #61872
Assignees
Labels
A-async-await Area: Async & Await 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 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

@KamilaBorowska
Copy link
Contributor

KamilaBorowska commented Jun 14, 2019

I tried this code with edition 2018:

#![feature(async_await)]
async fn a() {}
async fn b() {}
async fn start() {
    a();
    b().await;
}
fn main() {
    start();
}

This happened:

error: internal compiler error: src/librustc_mir/transform/generator.rs:714: Broken MIR: generator contains type impl std::future::Future in MIR, but typeck only knows about {impl std::future::Future, ()}
 --> src/main.rs:4:18
  |
4 |   async fn start() {
  |  __________________^
5 | |     a();
6 | |     b().await;
7 | | }
  | |_^

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 (0e4a56b4b 2019-06-13) running on x86_64-unknown-linux-gnu

Meta

rustc --version --verbose:

rustc 1.37.0-nightly (0e4a56b4b 2019-06-13)
binary: rustc
commit-hash: 0e4a56b4b04ea98bb16caada30cb2418dd06e250
commit-date: 2019-06-13
host: x86_64-unknown-linux-gnu
release: 1.37.0-nightly
LLVM version: 8.0

Backtrace:

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:578:9
stack backtrace:
   0:     0x7ff89049918b - backtrace::backtrace::libunwind::trace::h41595b2657878dbc
                               at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1:     0x7ff89049918b - backtrace::backtrace::trace_unsynchronized::h4efe511900bf5e12
                               at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2:     0x7ff89049918b - std::sys_common::backtrace::_print::h7275b63687b21f98
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7ff89049918b - std::sys_common::backtrace::print::h790c12384440cac4
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7ff89049918b - std::panicking::default_hook::{{closure}}::he6cba1bdf748f1c3
                               at src/libstd/panicking.rs:198
   5:     0x7ff890498e8c - std::panicking::default_hook::h1296d9a476e7a9c2
                               at src/libstd/panicking.rs:212
   6:     0x7ff88e1d33f1 - rustc::util::common::panic_hook::ha2e96a0b919e5a1a
   7:     0x7ff8904999e9 - std::panicking::rust_panic_with_hook::h8d2408723e9a2bd4
                               at src/libstd/panicking.rs:479
   8:     0x7ff88f733b51 - std::panicking::begin_panic::h99404a5a8c9393e6
   9:     0x7ff88f731a56 - rustc_errors::Handler::span_bug::h490e1671e2e515c8
  10:     0x7ff88f4eeb52 - rustc::util::bug::opt_span_bug_fmt::{{closure}}::hdb0241a0d138b557
  11:     0x7ff88f4ec61a - rustc::ty::context::tls::with_opt::{{closure}}::hc463290490e6bd93
  12:     0x7ff88f4ec580 - rustc::ty::context::tls::with_context_opt::h864c92ca64bcd209
  13:     0x7ff88f4ec5c7 - rustc::ty::context::tls::with_opt::h0139b8ed23799d5b
  14:     0x7ff88f4eea48 - rustc::util::bug::opt_span_bug_fmt::he42ee4c44975fb76
  15:     0x7ff88f4ee9fa - rustc::util::bug::span_bug_fmt::hc2a12a0744cb6581
  16:     0x7ff88f64c420 - rustc_mir::transform::generator::compute_layout::h59cccf9a051dc6e9
  17:     0x7ff88f64e7f2 - <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass::h5455abb94d103444
  18:     0x7ff88f3e8c1d - rustc_mir::transform::run_passes::{{closure}}::hc5896914630654b8
  19:     0x7ff88f3e88c4 - rustc_mir::transform::run_passes::h31e820477fdcc7cc
  20:     0x7ff88f3e982f - rustc_mir::transform::optimized_mir::hcdb77108b4828931
  21:     0x7ff88e166e7d - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::ha863b92e11001b35
  22:     0x7ff88dd1ad08 - rustc::dep_graph::graph::DepGraph::with_task_impl::h3c249e1459ce4cf0
  23:     0x7ff88dfeb98c - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h6f6a4849e78cab89
  24:     0x7ff88e24a178 - rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::h51deb19f7091cba9
  25:     0x7ff88e247473 - rustc::ty::layout::layout_raw::hcd1f01e2c83e8363
  26:     0x7ff88ddcae79 - rustc::ty::query::__query_compute::layout_raw::hab67f82b3fd58a77
  27:     0x7ff88e167d4a - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute::hbd5a4cb7a97851aa
  28:     0x7ff88dd13118 - rustc::dep_graph::graph::DepGraph::with_task_impl::h177648ace895bb06
  29:     0x7ff88e032a3b - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::ha2dbb73f32e739a7
  30:     0x7ff88e252764 - <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of::h08b5157be6aa3f2e
  31:     0x7ff88f447ead - <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement::h8a138fa6e5e7dc0e
  32:     0x7ff88f43f849 - <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass::ha6e576a0006a7da8
  33:     0x7ff88f3e8c1d - rustc_mir::transform::run_passes::{{closure}}::hc5896914630654b8
  34:     0x7ff88f3e88c4 - rustc_mir::transform::run_passes::h31e820477fdcc7cc
  35:     0x7ff88f3e982f - rustc_mir::transform::optimized_mir::hcdb77108b4828931
  36:     0x7ff88e166e7d - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::ha863b92e11001b35
  37:     0x7ff88dd1ad08 - rustc::dep_graph::graph::DepGraph::with_task_impl::h3c249e1459ce4cf0
  38:     0x7ff88dfeb98c - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h6f6a4849e78cab89
  39:     0x7ff88f5f54fd - rustc_mir::monomorphize::collector::collect_items_rec::h706317fcd2797400
  40:     0x7ff88f5f61f1 - rustc_mir::monomorphize::collector::collect_items_rec::h706317fcd2797400
  41:     0x7ff88f4985cd - rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}::h13f4d3024d161e1e
  42:     0x7ff88f473447 - rustc::util::common::time::h48c2bfe2820c85e9
  43:     0x7ff88f5f47ea - rustc_mir::monomorphize::collector::collect_crate_mono_items::ha257437826f5d63f
  44:     0x7ff88f47382d - rustc::util::common::time::hdc18f22e136943a2
  45:     0x7ff88f657d59 - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h75572e8d5100e04f
  46:     0x7ff88634635a - rustc::ty::query::__query_compute::collect_and_partition_mono_items::h6384799bc0dd81e7
  47:     0x7ff886374889 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute::hdcf5909d894cd534
  48:     0x7ff88630edfa - rustc::dep_graph::graph::DepGraph::with_task_impl::h18e4d6354f7571f6
  49:     0x7ff88638176b - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h27044e0b5cb11e01
  50:     0x7ff88641f6cf - rustc_codegen_ssa::base::codegen_crate::h74b58a2ac9b23913
  51:     0x7ff88641cc8a - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate::h50e9412946ee1e63
  52:     0x7ff88feb3d67 - rustc::util::common::time::haa32cafeeb3d54cb
  53:     0x7ff88fe5f13b - rustc_interface::passes::start_codegen::hcdb1e9299570ccd1
  54:     0x7ff88fe46317 - rustc::ty::context::tls::enter_global::h5d834d2634f7fc92
  55:     0x7ff88fe5f941 - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h10a967fa77f2b087
  56:     0x7ff88febbb05 - rustc_interface::passes::create_global_ctxt::{{closure}}::h7a059b6cf199597d
  57:     0x7ff88fe5e496 - rustc_interface::passes::BoxedGlobalCtxt::enter::h4a247e90412a9579
  58:     0x7ff88fe48740 - rustc_interface::queries::Query<T>::compute::h595d6a8dccab9742
  59:     0x7ff88ff327e4 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen::h93f94310b1d268e6
  60:     0x7ff89078d840 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h35eddbfcfbbe0eb4
  61:     0x7ff8907ff5f6 - std::thread::local::LocalKey<T>::with::hea85159711765771
  62:     0x7ff890797fb5 - scoped_tls::ScopedKey<T>::set::he08d6211f459724f
  63:     0x7ff8907caad4 - syntax::with_globals::h2c63be024f0c1f38
  64:     0x7ff8907e989d - std::sys_common::backtrace::__rust_begin_short_backtrace::hfc7fb053a9ed90ec
  65:     0x7ff8904aa8da - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:82
  66:     0x7ff8907756d9 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0cd7d8fc1b0a39a3
  67:     0x7ff89047ceef - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::he71721d2d956d451
                               at /rustc/0e4a56b4b04ea98bb16caada30cb2418dd06e250/src/liballoc/boxed.rs:746
  68:     0x7ff8904a95b0 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::he520045b8d28ce5c
                               at /rustc/0e4a56b4b04ea98bb16caada30cb2418dd06e250/src/liballoc/boxed.rs:746
  69:     0x7ff8904a95b0 - std::sys_common::thread::start_thread::h2e98d1272dc6d74b
                               at src/libstd/sys_common/thread.rs:13
  70:     0x7ff8904a95b0 - std::sys::unix::thread::Thread::new::thread_start::h18485805666ccd3c
                               at src/libstd/sys/unix/thread.rs:79
  71:     0x7ff8903d4a92 - start_thread
  72:     0x7ff8902f3cd3 - __clone
  73:                0x0 - <unknown>
query stack during panic:
#0 [optimized_mir] processing `start::{{closure}}#0`
#1 [layout_raw] computing layout of `[static generator@a.rs:4:22: 7:2 {std::future::GenFuture<[static generator@a.rs:3:14: 3:16 {}]>, ()}]`
#2 [optimized_mir] processing `start`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
@Centril Centril added A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Jun 14, 2019
@theduke
Copy link
Contributor

theduke commented Jun 22, 2019

I also stumbled over this error.

Adding a simplified reproduction as an additional test case / data point.

(rustc 1.37.0-nightly (929b48ec9 2019-06-21))

#![feature(async_await)]

use futures::compat::Future01CompatExt;
use reqwest::r#async::Client;
use serde_json::Value;

type Map = serde_json::Map<String, Value>;

async fn get<'a, D, Q>(client: &'a Client, path: &'a str, query: Q) -> Result<D, String>
where
    Q: serde::Serialize,
    D: serde::de::DeserializeOwned,
{
    let value = serde_json::to_value(query).map_err(|e| e.to_string())?;

    let query_map = match value {
        serde_json::Value::Object(obj) => obj,
        _ => Err(format!(
            "Invalid query data: type must serialize into a object"
        ))?,
    };
    let mut clean_map: Map = query_map
        .into_iter()
        .filter(|(_key, value)| !value.is_null())
        .collect();
    clean_map.insert("key".into(), "value".into());

    let url = "".to_string();
    let mut res = client
        .get(&url)
        .query(&clean_map)
        .send()
        .compat()
        .await
        .map_err(|e| e.to_string());

    Err("err".to_string())
}

@Aaron1011
Copy link
Member

@theduke Could you provide your Cargo.toml?

@theduke
Copy link
Contributor

theduke commented Jun 23, 2019

Some redundant deps in there, I didn't create a minimal reproduction due to the multiple existing issues.

[package]
name = "repro"
version = "0.1.0"
edition = "2018"

[dependencies]
failure = "0.1.5"
serde = { version = "1.0.92", features = ["derive"] }
serde_json = "1.0.39"
chrono = { version = "0.4.6", features = ["serde"] }
tokio = "0.1.21"
reqwest = "0.9.18"
futures-preview = { version = "0.3.0-alpha.16", features = ["nightly", "async-await", "compat"] }
url = "1.7.2"
url_serde = "0.2.0"

PS: the code works when the map transformation (everything before client.get()) is factored out to a helper function.

@Aaron1011
Copy link
Member

Aaron1011 commented Jun 23, 2019

It looks like this will be fixed by #61872 - it's another case of generator analysis getting confused by the lack of StorageDead/StorageLive for statement temporaries.

@theduke
Copy link
Contributor

theduke commented Jun 23, 2019

Thanks for investigating!

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

5 participants