Skip to content

Broken MIR after compiler update when indexing statics with async values #66695

Closed
@unneon

Description

@unneon

I have some code which asynchronously computes an integer, and selects an item from a static slice in the same expression. This used to work (it does on stable), but after a nightly update the compiler ICEs when computing generator layout.

The bug stops reproducing if I change the static to a local variable, or extract the index into a separate variable.

static CODEGEN: &[()] = &[];

async fn manual() {
	CODEGEN[async { 0 }.await];
}
    Checking icie v0.6.4 (/home/matcegla/Projects/icie)
warning: static item is never used: `CODEGEN`
 --> src/lib.rs:1:1
  |
1 | static CODEGEN: &[()] = &[];
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function is never used: `manual`
 --> src/lib.rs:3:10
  |
3 | async fn manual() {
  |          ^^^^^^

error: internal compiler error: src/librustc_mir/transform/generator.rs:783: Broken MIR: generator contains type &&[()] in MIR, but typeck only knows about for<'r, 's> {&'r [()], &'s [()], [static generator@src/lib.rs:4:16: 4:21 {}], impl std::future::Future, impl std::future::Future, ()}
 --> src/lib.rs:3:19
  |
3 |   async fn manual() {
  |  ___________________^
4 | |     CODEGEN[async { 0 }.await];
5 | | }
  | |_^

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:851:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:84
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:468
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::span_bug_fmt
  20: rustc_mir::transform::generator::compute_layout
  21: <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass
  22: rustc_mir::transform::run_passes
  23: rustc_mir::transform::run_optimization_passes
  24: rustc_mir::transform::optimized_mir
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: rustc::ty::<impl rustc::ty::context::TyCtxt>::generator_layout
  29: <rustc_metadata::rmeta::encoder::EncodeContext as rustc::hir::intravisit::Visitor>::visit_expr
  30: rustc::hir::intravisit::walk_expr
  31: <rustc_metadata::rmeta::encoder::EncodeContext as rustc::hir::intravisit::Visitor>::visit_expr
  32: rustc::hir::intravisit::walk_item
  33: <rustc_metadata::rmeta::encoder::EncodeContext as rustc::hir::intravisit::Visitor>::visit_item
  34: rustc::hir::Crate::visit_all_item_likes
  35: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
  36: rustc::ty::context::tls::with_context::{{closure}}
  37: rustc_metadata::rmeta::encoder::encode_metadata
  38: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
  39: rustc::ty::context::TyCtxt::encode_metadata
  40: rustc_interface::passes::start_codegen::{{closure}}
  41: rustc_interface::passes::start_codegen
  42: rustc::ty::context::tls::enter_global
  43: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  44: rustc_interface::passes::create_global_ctxt::{{closure}}
  45: rustc_interface::passes::BoxedGlobalCtxt::enter
  46: rustc_interface::queries::Query<T>::compute
  47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: std::thread::local::LocalKey<T>::with
  50: scoped_tls::ScopedKey<T>::set
  51: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.41.0-nightly (0c987c5c0 2019-11-23) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [optimized_mir] processing `manual::{{closure}}#0`
end of query stack
error: aborting due to previous error

error: could not compile `icie`.

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

rustc 1.41.0-nightly (0c987c5 2019-11-23)
binary: rustc
commit-hash: 0c987c5
commit-date: 2019-11-23
host: x86_64-unknown-linux-gnu
release: 1.41.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions